axonivy-market / persistence-utils

Axon Ivy persistence lib 4 fast DAO devs
Apache License 2.0
0 stars 3 forks source link

Meta model generation does not work if project has a dependecy to an iar project #32

Closed ivy-lli closed 1 year ago

ivy-lli commented 1 year ago

Currently, the meta model generation fails if the project contains a dependency to a packed iar project.

Way to reproduce:

Error: Errors running builder 'Java Builder' on project 'persistence-utils-demo'.

java.lang.NullPointerException: Cannot invoke "org.eclipse.core.runtime.IPath.toOSString()" because the return value of "org.eclipse.core.resources.IResource.getLocation()" is null
    at org.eclipse.jdt.apt.core.util.AptConfig.addProjectClasspath(AptConfig.java:368)
    at org.eclipse.jdt.apt.core.util.AptConfig.getProcessorOptions(AptConfig.java:255)
    at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeProcessingEnvImpl.getOptions(IdeProcessingEnvImpl.java:86)
    at org.hibernate.jpamodelgen.Context.<init>(Context.java:71)
    at org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor.init(JPAMetaModelEntityProcessor.java:76)
    at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.discoverNextProcessor(IdeAnnotationProcessorManager.java:97)
    at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:119)
    at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:172)
    at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.processAnnotations(IdeAnnotationProcessorManager.java:138)
    at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:950)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:450)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:426)
    at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:379)
    at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:214)
    at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:311)
    at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:79)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:272)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:192)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:860)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:232)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:281)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:334)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:337)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:392)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:417)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:161)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:255)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:60)

Is is a know problem that the method IResource#getLocation return null on packed iar projects. So we should maybe add a hint in the product Readme.md that this doesn't work.

@peters-axon FYI

ivy-lli commented 1 year ago

Possible workaround Generate the meta-model java sources with maven.

Example with the perstistence-utils-demo Generate first the meta-model sources (java files), then overwrite the default-comileProjectof the project-build-plugin that it should not run the annotation process.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.axonivy.utils.persistence</groupId>
  <artifactId>persistence-utils-demo</artifactId>
  <version>10.0.3-SNAPSHOT</version>
  <packaging>iar</packaging>
  <dependencies>

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-jpamodelgen</artifactId>
      <version>5.4.33.Final</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>com.axonivy.utils.persistence</groupId>
      <artifactId>persistence-utils</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>

  <repositories>
    <repository>
      <id>axonivy.public</id>
      <url>https://maven.axonivy.com</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>

  <build>
    <plugins>
      <plugin>
        <groupId>com.axonivy.ivy.ci</groupId>
        <artifactId>project-build-plugin</artifactId>
        <version>10.0.3</version>
        <extensions>true</extensions>
        <configuration>
          <compilerOptions>
            <compilerOption>-XprintProcessorInfo</compilerOption> 
            <compilerOption>-XprintRounds</compilerOption>
          </compilerOptions>
        </configuration>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <id>generate-meta-model-sources</id>
            <goals>
              <goal>compileProject</goal>
            </goals>
            <configuration>
              <skipScriptValidation>true</skipScriptValidation>
              <compilerOptions>
                <compilerOption>-proc:only</compilerOption>
                <compilerOption>-s</compilerOption>
                <compilerOption>${project.build.directory}/.apt_generated</compilerOption>
              </compilerOptions>
            </configuration>
          </execution>
          <execution>
            <phase>process-classes</phase>
            <id>default-compileProject</id>
            <configuration>
              <compilerOptions>
                <compilerOption>-proc:none</compilerOption>
              </compilerOptions>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
ivy-lli commented 1 year ago

The NPE is fixed for the Axon Ivy Designer 10.0.7: XIVY-11172 And it is also fixed in the eclipse.jdt.core project: https://github.com/eclipse-jdt/eclipse.jdt.core/issues/917