Skip to content

Commit be15d42

Browse files
committed
windows classpath with witespace fix
1 parent 00b2018 commit be15d42

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

  • src/main/java/com/github/pfmiles/dropincc/impl/util

src/main/java/com/github/pfmiles/dropincc/impl/util/Util.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
package com.github.pfmiles.dropincc.impl.util;
1212

1313
import java.io.File;
14+
import java.net.URISyntaxException;
1415
import java.net.URL;
1516
import java.net.URLClassLoader;
1617
import java.util.Collection;
@@ -244,7 +245,7 @@ public static String getClassPath() {
244245
ClassLoader loader = getParentClsLoader();
245246
if (loader instanceof URLClassLoader) {
246247
for (URL url : ((URLClassLoader) loader).getURLs()) {
247-
String dropinccPath = url.getPath();
248+
String dropinccPath = toFilePath(url);
248249
if (dropinccPath != null && !"".equals(dropinccPath) && sb.indexOf(dropinccPath) == -1) {
249250
if (sb.length() != 0)
250251
sb.append(File.pathSeparator);
@@ -258,12 +259,13 @@ public static String getClassPath() {
258259
if (url != null) {
259260
String dropinccPath = null;
260261
if ("jar".equalsIgnoreCase(url.getProtocol())) {
261-
String path = url.getPath();
262+
String path = toFilePath(url);
262263
// could not handle nested jars
263-
dropinccPath = path.substring(path.indexOf(":") + 1, path.indexOf("!"));
264+
dropinccPath = path != null ? path.substring(path.indexOf(":") + 1, path.indexOf("!")) : null;
264265
} else if ("file".equalsIgnoreCase(url.getProtocol())) {
265-
String path = url.getPath();
266-
dropinccPath = path.substring(0, path.lastIndexOf(PATH_SEP + Util.class.getName().replace(".", PATH_SEP) + ".class"));
266+
String path = toFilePath(url);
267+
dropinccPath = path != null ? path.substring(0, path.lastIndexOf(PATH_SEP + Util.class.getName().replace(".", PATH_SEP) + ".class"))
268+
: null;
267269
}
268270
if (dropinccPath != null && !"".equals(dropinccPath) && sb.indexOf(dropinccPath) == -1) {
269271
if (sb.length() != 0)
@@ -274,6 +276,22 @@ public static String getClassPath() {
274276
return sb.toString();
275277
}
276278

279+
private static String toFilePath(URL url) {
280+
String protocal = url.getProtocol();
281+
if (!("jar".equalsIgnoreCase(protocal) || "file".equalsIgnoreCase(protocal)))
282+
return null;
283+
try {
284+
File f = new File(url.toURI().getSchemeSpecificPart());
285+
if (f.exists()) {
286+
return f.getAbsolutePath();
287+
} else {
288+
return null;
289+
}
290+
} catch (URISyntaxException e) {
291+
throw new DropinccException(e);
292+
}
293+
}
294+
277295
/**
278296
* Get the proper parent class loader for hot compilation class loaders.
279297
*

0 commit comments

Comments
 (0)