Skip to content

Commit

Permalink
refactor: reduce complexity of setInputClassLoader (#5242)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt authored Jun 11, 2023
1 parent 6750d61 commit cce82f1
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/main/java/spoon/support/StandardEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,25 +430,20 @@ public void setInputClassLoader(ClassLoader aClassLoader) {
final URL[] urls = ((URLClassLoader) aClassLoader).getURLs();
if (urls != null && urls.length > 0) {
// Check that the URLs are only file URLs
boolean onlyFileURLs = true;
for (URL url : urls) {
if (!"file".equals(url.getProtocol())) {
onlyFileURLs = false;
throw new SpoonException("Spoon does not support a URLClassLoader containing other resources than local file.");
}
}
if (onlyFileURLs) {
List<String> classpath = new ArrayList<>();
for (URL url : urls) {
try {
classpath.add(Path.of(url.toURI()).toAbsolutePath().toString());
} catch (URISyntaxException | FileSystemNotFoundException | IllegalArgumentException ignored) {
classpath.add(URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8));
}
List<String> classpath = new ArrayList<>();
for (URL url : urls) {
try {
classpath.add(Path.of(url.toURI()).toAbsolutePath().toString());
} catch (URISyntaxException | FileSystemNotFoundException | IllegalArgumentException ignored) {
classpath.add(URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8));
}
setSourceClasspath(classpath.toArray(new String[0]));
} else {
throw new SpoonException("Spoon does not support a URLClassLoader containing other resources than local file.");
}
setSourceClasspath(classpath.toArray(new String[0]));
}
}
this.classloader = aClassLoader;
Expand Down

0 comments on commit cce82f1

Please sign in to comment.