mojohaus / jaxb2-maven-plugin

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

Plugin fails with FileNotFoundException if run from filesystem root directory #107

Closed yankee42 closed 6 years ago

yankee42 commented 6 years ago

When I run

cd / && mvn -f /project/backend/pom.xml clean compile

I get an error message like this:

java.io.FileNotFoundException: /roject/backend/foobar/my-schema.xsd (No such file or directory)

Note that the path here starts with /roject, not /project.

When I run

cd /tmp && mvn -f /project/backend/pom.xml clean compile

Everything works fine.

I tracked the problem down to the FileSystemUtilities.relativize method. Shortened to the essential part, the method looks like this:

public static String relativize(final String path, final File parentDir) {
    final String basedirPath = FileSystemUtilities.getCanonicalPath(parentDir);
    String toReturn = path;
    if (path.toLowerCase().startsWith(basedirPath.toLowerCase())) {
        toReturn = path.substring(basedirPath.length() + 1);
    }
    return toReturn;
}

This method is called with path=/project/backend/foobar/my-schema.xsd and parentDir=/. The substring command removes the /p which I think is not intended.