devonfw / cobigen

Code-based Incremental Generator
Apache License 2.0
35 stars 70 forks source link

CobiGen has no consistent template conventions, custom templates not working, NPEs #1169

Open hohwille opened 4 years ago

hohwille commented 4 years ago

Expected behavior

As a CobiGen user, I want to use my custom templates so that I can generate code specific for the needs of my projects.

Actual behavior

CobiGen has no clearly designed and documented concept for templates and the template detection is full of hacks, inconsistencies and bugs:

I get NPEs like:

java.lang.NullPointerException
at com.devonfw.cobigen.cli.utils.CobiGenUtils.initializeCobiGen(CobiGenUtils.java:89)
at com.devonfw.cobigen.cli.commands.GenerateCommand.call(GenerateCommand.java:123)
at com.devonfw.cobigen.cli.commands.GenerateCommand.call(GenerateCommand.java:1)
at picocli.CommandLine.executeUserObject(CommandLine.java:1680)
at picocli.CommandLine.access$900(CommandLine.java:144)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2038)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2005)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:1872)
at picocli.CommandLine.execute(CommandLine.java:1801)
at com.devonfw.cobigen.cli.CobiGenCLI.main(CobiGenCLI.java:43)

So to summarize what CobiGen currently demands:

This is all historically grown and inconsistent, violating Java/maven conventions, etc.

IMHO CobiGen urgently requires a design for conventions and detection of templates. My suggestion would be:

  1. Define a new reasonable package namespace for templates. For simplicity I suggest cobigen - you could even keep src.main.templates but IMHO this is kind of sick.
  2. Remove any requirements for Maven GAV coordinates for templates as JAR files/dependencies
  3. So in the end a templates project/module would have its templates in src/main/resources/cobigen
  4. CobiGen would find Templates like this: Thread.currentThread().getContextClassLoader().getResources("cobigen/triggers.xml")
  5. The triggers.xml (feel free to choose any better name but templates.xml is already taken) should be a modular variant of the current context.xml.
  6. For all matches of step 4. the templates are loaded and in triggers.xml could be defined which plugins of cobigen are required that could be installed dynamically if not available.
  7. If no match is found, a legacy machanism could apply for backward compatibility.

Also CobiGen CLI should allow to ease configuration for templates (instead of hacking a pom.xml just put a config in a defined place that can override the defaults).

Steps to reproduce (bug) / Use Case of feature request (enhancement)

  1. Create custom templates and try generation with cobigen-cli by hacking cobigen-cli/pom.xml.

Related/Dependent Issues

Comments/Hints:

Affected version:

MikeSchumacherCapgemini commented 4 years ago

@hohwille How exactly does the mentioned NPE happen? Perhaps you can create a seperate issue detailing how you got it?