diff --git a/src/main/java/org/codehaus/mojo/jaxb2/shared/FileSystemUtilities.java b/src/main/java/org/codehaus/mojo/jaxb2/shared/FileSystemUtilities.java index 62036e02..f6f8221e 100644 --- a/src/main/java/org/codehaus/mojo/jaxb2/shared/FileSystemUtilities.java +++ b/src/main/java/org/codehaus/mojo/jaxb2/shared/FileSystemUtilities.java @@ -539,14 +539,13 @@ public static String relativize(final String path, final File parentDir, final b String platformSpecificPath; if (p.normalize().startsWith(pd.normalize().toString())) { platformSpecificPath = pd.relativize(p).toString(); + if (removeInitialFileSep && platformSpecificPath.startsWith(File.separator)) { + platformSpecificPath = platformSpecificPath.substring(File.separator.length()); + } } else { platformSpecificPath = p.toString(); } - if (removeInitialFileSep && platformSpecificPath.startsWith(File.separator)) { - platformSpecificPath = platformSpecificPath.substring(File.separator.length()); - } - // NOTE: it appears this function is meant to preserve the file separator that was passed in the path if (path.indexOf('\\') == -1) { platformSpecificPath = platformSpecificPath.replace('\\', '/'); diff --git a/src/test/java/org/codehaus/mojo/jaxb2/shared/FileSystemUtilitiesTest.java b/src/test/java/org/codehaus/mojo/jaxb2/shared/FileSystemUtilitiesTest.java index 2f23ba32..01953cec 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/shared/FileSystemUtilitiesTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/shared/FileSystemUtilitiesTest.java @@ -427,9 +427,9 @@ public void validateRelativizingPaths() throws Exception { final String path = "/project/backend/foobar/my-schema.xsd"; final SortedMap parentDir2Expected = new TreeMap<>(); parentDir2Expected.put("/", "project/backend/foobar/my-schema.xsd"); - parentDir2Expected.put("", "project/backend/foobar/my-schema.xsd"); + parentDir2Expected.put("", "/project/backend/foobar/my-schema.xsd"); parentDir2Expected.put("/project", "backend/foobar/my-schema.xsd"); - parentDir2Expected.put("/not/a/path", "project/backend/foobar/my-schema.xsd"); + parentDir2Expected.put("/not/a/path", "/project/backend/foobar/my-schema.xsd"); parentDir2Expected.put("/project/", "backend/foobar/my-schema.xsd"); // Act & Assert