Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CobiGen CLI does not generate properly from non-build Java sources #1497

Closed
GuentherJulian opened this issue Mar 7, 2022 · 2 comments
Closed
Labels
app:cli bug prio:high Team_CobiGen_Templates These issues will be handeled by the team CobiGen_Templates
Milestone

Comments

@GuentherJulian
Copy link
Contributor

GuentherJulian commented Mar 7, 2022

Expected behavior

As a CobiGen CLI user, I want CobiGen to be able to generate from non-build Java sources.

Actual behavior

The CobiGen CLI is not able to generate all the Java files from non-build Java source files. After building the Java project the generation is working.

Steps to reproduce

  1. Install devonfw-ide and CobiGen CLI
  2. Create a devon4j Java project (devon java create com.example.application.cobigenexample)
  3. Create a package and an entity class
    package com.example.application.cobigenexample.customermanagement.dataaccess.api
package com.example.application.cobigenexample.customermanagement.dataaccess.api;

import java.sql.Timestamp;

import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "Customer")
public class CustomerEntity {

  private String firstname;

  private String lastname;

  private int age;

  /**
   * @return the firstname
   */
  public String getFirstname() {
    return firstname;
  }

  /**
   * @param firstname the firstname to set
   */
  public void setFirstname(String firstname) {
    this.firstname = firstname;
  }

  /**
   * @return the lastname
   */
  public String getLastname() {
    return lastname;
  }

  /**
   * @param lastname the lastname to set
   */
  public void setLastname(String lastname) {
    this.lastname = lastname;
  }

  /**
   * @return the age
   */
  public int getAge() {
    return age;
  }

  /**
   * @param age the age to set
   */
  public void setAge(int age) {
    this.age = age;
  }

}
  1. Run Cobigen:
    devon cobigen generate core/src/main/java/com/example/application/cobigenexample/customermanagement/dataaccess/api/CustomerEntity.java
    Select 1,3,5,6,8 as increments

The following error occurs:

[DEBUG] While reading the input core\src\main\java\com\example\application\cobigenexample\customermanagement\dataaccess\api\CustomerEntity.java with the inputreader com.devonfw.cobigen.javaplugin.JavaTriggerInterpreter@72c8e7b, an exception occured. Trying next input reader...
com.devonfw.cobigen.api.exception.CobiGenRuntimeException: Compiled class com.example.application.cobigenexample.customermanagement.dataaccess.api.CustomerEntity has not been found. Most probably you need to build project core.
        at com.devonfw.cobigen.javaplugin.inputreader.JavaParserUtil.getJavaContext(JavaParserUtil.java:145)
        at com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader.createParsedClassLoader(JavaInputReader.java:452)
        at com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader.read(JavaInputReader.java:395)
        at com.devonfw.cobigen.impl.generator.InputInterpreterImpl.readInput(InputInterpreterImpl.java:96)
        at com.devonfw.cobigen.impl.generator.InputInterpreterImpl.read(InputInterpreterImpl.java:70)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at com.devonfw.cobigen.api.util.ExceptionUtil.invokeTarget(ExceptionUtil.java:76)
        at com.devonfw.cobigen.impl.aop.CachedInterceptor.invoke(CachedInterceptor.java:41)
        at com.sun.proxy.$Proxy14.read(Unknown Source)
        at com.devonfw.cobigen.impl.generator.CobiGenImpl.read(CobiGenImpl.java:170)
        at com.devonfw.cobigen.cli.commands.GenerateCommand.preprocess(GenerateCommand.java:187)
        at com.devonfw.cobigen.cli.commands.GenerateCommand.doAction(GenerateCommand.java:115)
        at com.devonfw.cobigen.cli.commands.CommandCommons.call(CommandCommons.java:36)
        at com.devonfw.cobigen.cli.commands.CommandCommons.call(CommandCommons.java:15)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at com.devonfw.cobigen.cli.CobiGenCLI.main(CobiGenCLI.java:37)
Caused by: java.lang.ClassNotFoundException: com.example.application.cobigenexample.customermanagement.dataaccess.api.CustomerEntity
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        at com.devonfw.cobigen.javaplugin.inputreader.JavaParserUtil.getJavaContext(JavaParserUtil.java:141)
        ... 25 common frames omitted
[ERROR] Invalid input for CobiGen, please check your input file 'core\src\main\java\com\example\application\cobigenexample\customermanagement\dataaccess\api\CustomerEntity.java'
[ERROR] There are no common Templates/Increments which could be generated from every of your inputs. Please think about executing generation one by one input file.
←[31m←[1mjava.util.InputMismatchException: No compatible input files.←[21m←[39m←[0m
←[3m    at com.devonfw.cobigen.cli.commands.GenerateCommand.preprocess(GenerateCommand.java:212)←[23m←[0m
←[3m    at com.devonfw.cobigen.cli.commands.GenerateCommand.doAction(GenerateCommand.java:115)←[23m←[0m
←[3m    at com.devonfw.cobigen.cli.commands.CommandCommons.call(CommandCommons.java:36)←[23m←[0m
←[3m    at com.devonfw.cobigen.cli.commands.CommandCommons.call(CommandCommons.java:15)←[23m←[0m
←[3m    at picocli.CommandLine.executeUserObject(CommandLine.java:1953)←[23m←[0m
←[3m    at picocli.CommandLine.access$1300(CommandLine.java:145)←[23m←[0m
←[3m    at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)←[23m←[0m
←[3m    at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)←[23m←[0m
←[3m    at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)←[23m←[0m
←[3m    at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)←[23m←[0m
←[3m    at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)←[23m←[0m
←[3m    at picocli.CommandLine.execute(CommandLine.java:2078)←[23m←[0m
←[3m    at com.devonfw.cobigen.cli.CobiGenCLI.main(CobiGenCLI.java:37)←[23m←[0m
[INFO ] Failed

After building the project (devon mvn clean install -Dmaven.test.skip=true) this error does not happen

  1. Then after successfull generation add an attribute to the entity class
private String company;
public String getCompany() {
    return company;
}
  
public void setCompany(String company) {
  this.company = company;
}
  1. Run CobiGen again and select 5 or 8 as increments
    The following error occurs:
[DEBUG] Merge AbstractSearchCriteriaTo.java with char set UTF-8.
[WARN ] Generation finished non-successful. Generated contents can be reviewed in file:///C:/Users/jgunther/AppData/Local/Temp/cobigen-8748010421413070530/
[ERROR] Further reported error:
com.devonfw.cobigen.api.exception.CobiGenRuntimeException: An error occurred while generating the template: /src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}SearchCriteriaTo.java.ftl (FreeMarker v2.3.29)
        at com.devonfw.cobigen.tempeng.freemarker.FreeMarkerTemplateEngine.process(FreeMarkerTemplateEngine.java:77)
        at com.devonfw.cobigen.impl.generator.GenerationProcessorImpl.generate(GenerationProcessorImpl.java:477)
        at com.devonfw.cobigen.impl.generator.GenerationProcessorImpl.generate(GenerationProcessorImpl.java:208)
        at com.devonfw.cobigen.impl.generator.CobiGenImpl.generate(CobiGenImpl.java:99)
        at com.devonfw.cobigen.impl.generator.CobiGenImpl.generate(CobiGenImpl.java:82)
        at com.devonfw.cobigen.cli.commands.GenerateCommand.generate(GenerateCommand.java:332)
        at com.devonfw.cobigen.cli.commands.GenerateCommand.doAction(GenerateCommand.java:117)
        at com.devonfw.cobigen.cli.commands.CommandCommons.call(CommandCommons.java:36)
        at com.devonfw.cobigen.cli.commands.CommandCommons.call(CommandCommons.java:15)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at com.devonfw.cobigen.cli.CobiGenCLI.main(CobiGenCLI.java:37)
Caused by: freemarker.core._TemplateModelException: Java method "com.devonfw.cobigen.templates.devon4j.utils.JavaUtil.equalsJavaPrimitive(Class, String)" threw an exception when invoked on com.devonfw.cobigen.templates.devon4j.utils.JavaUtil object "com.devonfw.cobigen.templates.devon4j.utils.JavaUtil@6c101cc1"; see cause exception in the Java stack trace.

----
FTL stack trace ("~" means nesting-related):
        - Failed at: #elseif isSearchCriteria && JavaUtil...  [in template "functions.ftl" in macro "generateFieldDeclarations_withRespectTo_entityObjectToIdReferenceConversion" at line 20, column 1]
        - Reached through: @generateFieldDeclarations_withRespec...  [in template "templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}SearchCriteriaTo.java.ftl" at line 18, column 9]
----
        at freemarker.ext.beans._MethodUtil.newInvocationTemplateModelException(_MethodUtil.java:289)
        at freemarker.ext.beans._MethodUtil.newInvocationTemplateModelException(_MethodUtil.java:261)
        at freemarker.ext.beans.OverloadedMethodsModel.exec(OverloadedMethodsModel.java:65)
        at freemarker.core.MethodCall._eval(MethodCall.java:62)
        at freemarker.core.Expression.eval(Expression.java:101)
        at freemarker.core.Expression.evalToBoolean(Expression.java:179)
        at freemarker.core.Expression.evalToBoolean(Expression.java:165)
        at freemarker.core.AndExpression.evalToBoolean(AndExpression.java:36)
        at freemarker.core.IfBlock.accept(IfBlock.java:49)
        at freemarker.core.Environment.visit(Environment.java:367)
        at freemarker.core.IteratorBlock$IterationContext.executedNestedContentForCollOrSeqListing(IteratorBlock.java:291)
        at freemarker.core.IteratorBlock$IterationContext.executeNestedContent(IteratorBlock.java:271)
        at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:244)
        at freemarker.core.Environment.visitIteratorBlock(Environment.java:643)
        at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:108)
        at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
        at freemarker.core.Environment.visit(Environment.java:367)
        at freemarker.core.Environment.invokeMacroOrFunctionCommonPart(Environment.java:872)
        at freemarker.core.Environment.invokeMacro(Environment.java:809)
        at freemarker.core.UnifiedCall.accept(UnifiedCall.java:83)
        at freemarker.core.Environment.visit(Environment.java:331)
        at freemarker.core.Environment.visit(Environment.java:337)
        at freemarker.core.Environment.process(Environment.java:310)
        at com.devonfw.cobigen.tempeng.freemarker.FreeMarkerTemplateEngine.process(FreeMarkerTemplateEngine.java:74)
        ... 17 common frames omitted
Caused by: java.lang.NoSuchFieldException: company
        at java.base/java.lang.Class.getDeclaredField(Class.java:2411)
        at com.devonfw.cobigen.templates.devon4j.utils.JavaUtil.equalsJavaPrimitive(JavaUtil.java:131)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:1505)
        at freemarker.ext.beans.ReflectionCallableMemberDescriptor.invokeMethod(ReflectionCallableMemberDescriptor.java:56)
        at freemarker.ext.beans.MemberAndArguments.invokeMethod(MemberAndArguments.java:51)
        at freemarker.ext.beans.OverloadedMethodsModel.exec(OverloadedMethodsModel.java:61)
        ... 38 common frames omitted
←[31m←[1mcom.devonfw.cobigen.api.exception.CobiGenRuntimeException: An error occurred while generating the template: /src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl (FreeMarker v2.3.29)←[21m←[39m←[0m
←[3m    at com.devonfw.cobigen.tempeng.freemarker.FreeMarkerTemplateEngine.process(FreeMarkerTemplateEngine.java:77)←[23m←[0m
←[3m    at com.devonfw.cobigen.impl.generator.GenerationProcessorImpl.generate(GenerationProcessorImpl.java:477)←[23m←[0m
←[3m    at com.devonfw.cobigen.impl.generator.GenerationProcessorImpl.generate(GenerationProcessorImpl.java:208)←[23m←[0m
←[3m    at com.devonfw.cobigen.impl.generator.CobiGenImpl.generate(CobiGenImpl.java:99)←[23m←[0m
←[3m    at com.devonfw.cobigen.impl.generator.CobiGenImpl.generate(CobiGenImpl.java:82)←[23m←[0m
←[3m    at com.devonfw.cobigen.cli.commands.GenerateCommand.generate(GenerateCommand.java:332)←[23m←[0m
←[3m    at com.devonfw.cobigen.cli.commands.GenerateCommand.doAction(GenerateCommand.java:117)←[23m←[0m
←[3m    at com.devonfw.cobigen.cli.commands.CommandCommons.call(CommandCommons.java:36)←[23m←[0m
←[3m    at com.devonfw.cobigen.cli.commands.CommandCommons.call(CommandCommons.java:15)←[23m←[0m
←[3m    at picocli.CommandLine.executeUserObject(CommandLine.java:1953)←[23m←[0m
←[3m    at picocli.CommandLine.access$1300(CommandLine.java:145)←[23m←[0m
←[3m    at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)←[23m←[0m
←[3m    at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)←[23m←[0m
←[3m    at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)←[23m←[0m
←[3m    at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)←[23m←[0m
←[3m    at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)←[23m←[0m
←[3m    at picocli.CommandLine.execute(CommandLine.java:2078)←[23m←[0m
←[3m    at com.devonfw.cobigen.cli.CobiGenCLI.main(CobiGenCLI.java:37)←[23m←[0m
←[31m←[1mCaused by: freemarker.core._TemplateModelException: Java method "com.devonfw.cobigen.templates.devon4j.utils.JavaUtil.equalsJavaPrimitive(Class, String)" threw an exception when invoked on com.devonfw.cobigen.templates.devon4j.utils.JavaUtil object "com.devonfw.cobigen.templates.devon4j.utils.JavaUtil@6c101cc1"; see cause exception in the Java stack trace.

----
FTL stack trace ("~" means nesting-related):
        - Failed at: #if JavaUtil.equalsJavaPrimitive(clas...  [in template "templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl" at line 33, column 25]
----←[21m←[39m←[0m
←[3m    at freemarker.ext.beans._MethodUtil.newInvocationTemplateModelException(_MethodUtil.java:289)←[23m←[0m
←[3m    at freemarker.ext.beans._MethodUtil.newInvocationTemplateModelException(_MethodUtil.java:261)←[23m←[0m
←[3m    at freemarker.ext.beans.OverloadedMethodsModel.exec(OverloadedMethodsModel.java:65)←[23m←[0m
←[3m    at freemarker.core.MethodCall._eval(MethodCall.java:62)←[23m←[0m
←[3m    at freemarker.core.Expression.eval(Expression.java:101)←[23m←[0m
←[3m    at freemarker.core.Expression.evalToBoolean(Expression.java:179)←[23m←[0m
←[3m    at freemarker.core.Expression.evalToBoolean(Expression.java:165)←[23m←[0m
←[3m    at freemarker.core.IfBlock.accept(IfBlock.java:49)←[23m←[0m
←[3m    at freemarker.core.Environment.visit(Environment.java:367)←[23m←[0m
←[3m    at freemarker.core.IteratorBlock$IterationContext.executedNestedContentForCollOrSeqListing(IteratorBlock.java:291)←[23m←[0m
←[3m    at freemarker.core.IteratorBlock$IterationContext.executeNestedContent(IteratorBlock.java:271)←[23m←[0m
←[3m    at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:244)←[23m←[0m
←[3m    at freemarker.core.Environment.visitIteratorBlock(Environment.java:643)←[23m←[0m
←[3m    at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:108)←[23m←[0m
←[3m    at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)←[23m←[0m
←[3m    at freemarker.core.Environment.visit(Environment.java:331)←[23m←[0m
←[3m    at freemarker.core.Environment.visit(Environment.java:337)←[23m←[0m
←[3m    at freemarker.core.Environment.visit(Environment.java:337)←[23m←[0m
←[3m    at freemarker.core.Environment.process(Environment.java:310)←[23m←[0m
←[3m    at com.devonfw.cobigen.tempeng.freemarker.FreeMarkerTemplateEngine.process(FreeMarkerTemplateEngine.java:74)←[23m←[0m
←[3m    ... 17 more←[23m←[0m
←[31m←[1mCaused by: java.lang.NoSuchFieldException: company←[21m←[39m←[0m
←[3m    at java.base/java.lang.Class.getDeclaredField(Class.java:2411)←[23m←[0m
←[3m    at com.devonfw.cobigen.templates.devon4j.utils.JavaUtil.equalsJavaPrimitive(JavaUtil.java:131)←[23m←[0m
←[3m    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)←[23m←[0m
←[3m    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)←[23m←[0m
←[3m    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)←[23m←[0m
←[3m    at java.base/java.lang.reflect.Method.invoke(Method.java:566)←[23m←[0m
←[3m    at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:1505)←[23m←[0m
←[3m    at freemarker.ext.beans.ReflectionCallableMemberDescriptor.invokeMethod(ReflectionCallableMemberDescriptor.java:56)←[23m←[0m
←[3m    at freemarker.ext.beans.MemberAndArguments.invokeMethod(MemberAndArguments.java:51)←[23m←[0m
←[3m    at freemarker.ext.beans.OverloadedMethodsModel.exec(OverloadedMethodsModel.java:61)←[23m←[0m
←[3m    ... 34 more←[23m←[0m
[INFO ] Failed

Again after building the project this works

Related/Dependent Issues

devonfw-tutorials/tutorials#200

Comments/Hints:

In Eclipse the generation with the same steps works

Affected version:

  • OS: Windows/Linux
  • CobiGen latest release 2021.12.006
@GuentherJulian GuentherJulian added bug app:cli Team_CobiGen_Templates These issues will be handeled by the team CobiGen_Templates labels Mar 7, 2022
@maybeec maybeec added this to the v2021.12.007 milestone Apr 21, 2022
@Zylesto Zylesto assigned Zylesto and unassigned Zylesto Sep 6, 2022
@Zylesto
Copy link
Contributor

Zylesto commented Sep 13, 2022

The error seems to be that a ClassLoader is unable to load a non compiled class. What I have tried (without success) is to compile the EntityClass with the JavaCompiler, however the ClassLoader was still unable to find and load the class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app:cli bug prio:high Team_CobiGen_Templates These issues will be handeled by the team CobiGen_Templates
Projects
None yet
Development

No branches or pull requests

5 participants