Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix classpath splitting on Windows
We delimit classpaths in the properties file inside our jar files with
a colon. But, on Windows, a colon is also used to separate drive
letters from the rest of the path. So, we detect the case where we
split a path up into its drive letter and path and reassemble that
into the correct path.

We can't just rely on File.pathSeparator because then the built Jar
would only work on the same OS Family (Windows vs Linux/Mac) that it
was created on.
  • Loading branch information
bbrowning committed Apr 15, 2015
1 parent e428a13 commit 26d2e0d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion modules/core/src/main/java/org/projectodd/wunderboss/Utils.java
Expand Up @@ -46,7 +46,26 @@ public static List<File> classpathStringToFiles(String cp) {
}

public static String[] classpathStringToArray(String cp) {
return cp.trim().split(":");
cp = cp.trim();
String[] entries = cp.split(":");
// Basic splitting on ":" may break some entries under Windows of the
// form C:\foo\bar.jar
List<String> results = new ArrayList<>();
for (int i = 0; i < entries.length; i++) {
String entry = entries[i];
if (i + 1 < entries.length) {
String nextEntry = entries[i + 1];
if (entry.matches("[A-Za-z]") && nextEntry.charAt(0) == '\\') {
// We split up a path containing a Windows drive letter so
// reassemble it
results.add(entry + ":" + nextEntry);
i++;
continue;
}
}
results.add(entry);
}
return results.toArray(new String[results.size()]);
}

public static void deleteRecursively(File directory) {
Expand Down

0 comments on commit 26d2e0d

Please sign in to comment.