Skip to content

Commit 0948995

Browse files
committed
fix #652 fix jar files handling
1 parent 262b5ee commit 0948995

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

hotswap-agent-core/src/main/java/org/hotswap/agent/util/scanner/ClassPathScanner.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,33 +52,39 @@ public void scan(ClassLoader classLoader, String path, ScannerVisitor visitor) t
5252
LOGGER.trace("Scanning path {}", path);
5353
// find all directories - classpath directory or JAR
5454
Enumeration<URL> en = classLoader == null ? ClassLoader.getSystemResources(path) : classLoader.getResources(path);
55+
5556
while (en.hasMoreElements()) {
5657
URL pluginDirURL = en.nextElement();
57-
File pluginDir;
58-
try {
59-
pluginDir = new File(pluginDirURL.toURI());
60-
} catch (URISyntaxException e) {
61-
// Fallback for URLs that are not valid URIs
62-
pluginDir = new File(pluginDirURL.getFile());
63-
}
64-
if (pluginDir.isDirectory()) {
65-
scanDirectory(pluginDir, visitor);
66-
} else {
67-
// JAR file
68-
String uri;
58+
59+
// Only treat as File for real filesystem URLs
60+
if ("file".equalsIgnoreCase(pluginDirURL.getProtocol())) {
61+
File pluginDir;
6962
try {
70-
uri = pluginDirURL.toURI().toString();
71-
} catch (URISyntaxException e) {
72-
throw new IOException("Illegal directory URI " + pluginDirURL, e);
63+
pluginDir = java.nio.file.Paths.get(pluginDirURL.toURI()).toFile();
64+
} catch (Exception e) {
65+
pluginDir = new File(pluginDirURL.getPath());
7366
}
7467

75-
if (uri.startsWith(JAR_URL_PREFIX) || uri.startsWith(ZIP_URL_PREFIX)) {
76-
String jarFile = uri.substring(uri.indexOf(':') + 1); // remove the prefix
77-
scanJar(jarFile, visitor);
78-
} else {
79-
LOGGER.warning("Unknown resource type of file " + uri);
68+
if (pluginDir.isDirectory()) {
69+
scanDirectory(pluginDir, visitor);
70+
continue;
8071
}
8172
}
73+
74+
// JAR (or other) resource
75+
final String uri;
76+
try {
77+
uri = pluginDirURL.toURI().toString();
78+
} catch (URISyntaxException e) {
79+
throw new IOException("Illegal directory URI " + pluginDirURL, e);
80+
}
81+
82+
if (uri.startsWith(JAR_URL_PREFIX) || uri.startsWith(ZIP_URL_PREFIX)) {
83+
String jarFile = uri.substring(uri.indexOf(':') + 1); // remove the prefix
84+
scanJar(jarFile, visitor);
85+
} else {
86+
LOGGER.warning("Unknown resource type of file " + uri);
87+
}
8288
}
8389
}
8490

0 commit comments

Comments
 (0)