Skip to content

Commit

Permalink
Fix issues with Windows Path handling (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamretter authored Jan 31, 2021
1 parent 72a0f9d commit 41c629c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/it/xjc-handles-spaces-in-filenames/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ File expectedObjectFactoryFile = new File(basedir, pathToLeafPackage + "ObjectFa
| [7]: E:\Mojohaus\jaxb2-maven-plugin\target\it\xjc-handles-spaces-in-filenames\target\generated-sources\jaxb\META-INF\sun-jaxb.episode
| [8]: -b
| [9]: E:\Mojohaus\jaxb2-maven-plugin\target\it\xjc-handles-spaces-in-filenames\src\main\xjb\spaced filename.xjb
| [10]: /E:/Mojohaus/jaxb2-maven-plugin/target/it/xjc-handles-spaces-in-filenames/src/main/xsd/address.xsd
| [10]: E:\Mojohaus\jaxb2-maven-plugin\target\it\xjc-handles-spaces-in-filenames\src\main\xsd\address.xsd
|
+=================== [End 11 XJC Arguments]
*/
Expand All @@ -66,7 +66,7 @@ def xjcArgumentPatternPrefix = "\\| \\[\\p{Digit}+\\]: ";
Pattern expectedBArgumentPattern = Pattern.compile(xjcArgumentPatternPrefix + "\\-b");
Pattern expectedXjbArgumentPattern = Pattern.compile(xjcArgumentPatternPrefix
+ ".*src/main/xjb/spaced filename.xjb".replace("/", sep));
Pattern expectedSourceArgumentPattern = Pattern.compile(xjcArgumentPatternPrefix + ".*src/main/xsd/address.xsd");
Pattern expectedSourceArgumentPattern = Pattern.compile(xjcArgumentPatternPrefix + ".*src(/|\\\\)main(/|\\\\)xsd(/|\\\\)address.xsd");

boolean foundBArgument = false;
boolean foundXjbArgument = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.io.File;
import java.io.FileWriter;
import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
Expand Down Expand Up @@ -661,10 +662,11 @@ private String[] getXjcArguments(final String classPath, final String episodeFil

// Shorten the argument if possible.
if ("file".equalsIgnoreCase(current.getProtocol())) {
unwrappedSourceXSDs.add(FileSystemUtilities.relativize(
current.getPath(),
new File(System.getProperty("user.dir")),
true));
try {
unwrappedSourceXSDs.add(new File(current.toURI()).getPath());
} catch (final URISyntaxException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
} else {
unwrappedSourceXSDs.add(current.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -535,18 +537,26 @@ public static String relativize(final String path,
Validate.notNull(path, "path");
Validate.notNull(parentDir, "parentDir");

final String basedirPath = FileSystemUtilities.getCanonicalPath(parentDir);
String toReturn = path;
final Path p = Paths.get(path);
final Path pd = parentDir.toPath();

// Compare case insensitive
if (path.toLowerCase().startsWith(basedirPath.toLowerCase())) {
toReturn = path.substring(basedirPath.length());
String platformSpecificPath;
if (p.normalize().startsWith(pd.normalize().toString())) {
platformSpecificPath = pd.relativize(p).toString();
} else {
platformSpecificPath = p.toString();
}

// Handle whitespace in the argument.
return removeInitialFileSep && toReturn.startsWith(File.separator)
? toReturn.substring(File.separator.length())
: toReturn;
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('\\', '/');
}

return platformSpecificPath;
}

/**
Expand Down

0 comments on commit 41c629c

Please sign in to comment.