|
136 | 136 | import com.google.common.base.Function;
|
137 | 137 | import com.google.common.base.Joiner;
|
138 | 138 | import com.google.common.base.Optional;
|
| 139 | +import com.google.common.base.Splitter; |
| 140 | +import com.google.common.base.StandardSystemProperty; |
139 | 141 | import com.google.common.base.Strings;
|
140 | 142 | import com.google.common.base.Utf8;
|
141 | 143 | import com.google.common.collect.ForwardingMap;
|
@@ -3198,23 +3200,30 @@ public String toString() {
|
3198 | 3200 | * @return A list of absolute paths to the resources the class loader uses.
|
3199 | 3201 | */
|
3200 | 3202 | protected static List<String> detectClassPathResourcesToStage(ClassLoader classLoader) {
|
3201 |
| - if (!(classLoader instanceof URLClassLoader)) { |
| 3203 | + List<String> files = new ArrayList<>(); |
| 3204 | + if (classLoader == ClassLoader.getSystemClassLoader()) { |
| 3205 | + for (String element : |
| 3206 | + Splitter.on(File.pathSeparatorChar) |
| 3207 | + .split(StandardSystemProperty.JAVA_CLASS_PATH.value())) { |
| 3208 | + files.add(new File(element).getAbsolutePath()); |
| 3209 | + } |
| 3210 | + } else if (classLoader instanceof URLClassLoader) { |
| 3211 | + for (URL url : ((URLClassLoader) classLoader).getURLs()) { |
| 3212 | + try { |
| 3213 | + files.add(new File(url.toURI()).getAbsolutePath()); |
| 3214 | + } catch (IllegalArgumentException | URISyntaxException e) { |
| 3215 | + String message = String.format("Unable to convert url (%s) to file.", url); |
| 3216 | + LOG.error(message); |
| 3217 | + throw new IllegalArgumentException(message, e); |
| 3218 | + } |
| 3219 | + } |
| 3220 | + } else { |
3202 | 3221 | String message = String.format("Unable to use ClassLoader to detect classpath elements. "
|
3203 |
| - + "Current ClassLoader is %s, only URLClassLoaders are supported.", classLoader); |
| 3222 | + + "Current ClassLoader is %s, only URLClassLoaders and the system ClassLoader are " |
| 3223 | + + "supported.", classLoader); |
3204 | 3224 | LOG.error(message);
|
3205 | 3225 | throw new IllegalArgumentException(message);
|
3206 | 3226 | }
|
3207 |
| - |
3208 |
| - List<String> files = new ArrayList<>(); |
3209 |
| - for (URL url : ((URLClassLoader) classLoader).getURLs()) { |
3210 |
| - try { |
3211 |
| - files.add(new File(url.toURI()).getAbsolutePath()); |
3212 |
| - } catch (IllegalArgumentException | URISyntaxException e) { |
3213 |
| - String message = String.format("Unable to convert url (%s) to file.", url); |
3214 |
| - LOG.error(message); |
3215 |
| - throw new IllegalArgumentException(message, e); |
3216 |
| - } |
3217 |
| - } |
3218 | 3227 | return files;
|
3219 | 3228 | }
|
3220 | 3229 |
|
|
0 commit comments