Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

review: refactor: reduce complexity of setInputClassLoader #5242

Merged
merged 3 commits into from
Jun 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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