mojohaus / jaxb2-maven-plugin

JAXB2 Maven Plugin
https://www.mojohaus.org/jaxb2-maven-plugin/
Apache License 2.0
105 stars 76 forks source link

XJC error when module is a child #149

Open kevinbourne75 opened 4 years ago

kevinbourne75 commented 4 years ago

My issues is similar to #115 but that had no resolution.

ROOT
--myProj
  --pom.xml
--myProj-commons
  --pom.xml
  myProj-schemas
    --pom.xml
    --src
      --main
        --xsd
          --something
            --xsd1.xsd
            --xsd2.xsd
        --xjbs
          --some-binding.xjb

During SchemaGen there are errors. With debug I can see that the wrong path to the XSDs is being provided as XJC arguments. This is the path being used:

commons/myProj-schemas/src/main/xsd/something/xsd1.xsd
commons/myProj-schemas/src/main/xsd/something/xsd2.xsd

when it shoud be:

myProj-commons/myProj-schemas/src/main/xsd/something/xsd1.xsd
myProj-commons/myProj-schemas/src/main/xsd/something/xsd2.xsd

So it is cutting off the "myProj-" prefix.

Using -X option I see the XJC Arguments are:

commons/myProj-schemas/src/main/xsd/something/xsd1.xsd
commons/myProj-schemas/src/main/xsd/something/xsd2.xsd

The XJC Errors have the correct path though:

0: file: /home/user/git/myProj-commons/myProj-schemas/src/main/xsd/something/xsd1,xsd
0: file: /home/user/git/myProj-commons/myProj-schemas/src/main/xsd/something/xsd2,xsd

NOTE: When I run maven from the myProj-commons directory or the myProj-schemas directory, everything compiles fine. This only happens from running from the directory where the parent project is, the myProj directory.

kevinbourne75 commented 4 years ago

Note this issue is with 2.3.1. Not able to try a more recent version.

But, the issue is in FileSystemUtils.relativize(String path. File parentDir). It does the following:

if (path.toLowerCase().startsWith(basedirPath.toLowerCase())) {
            toReturn = path.substring(basedirPath.length());
}

With my example you can see that it is entering this if statement and cutting off the myProj prefix by doing the substring operation.