From 119bedb8d336c568e9ef4a3caa895afb8a84a7b0 Mon Sep 17 00:00:00 2001 From: Pavel Vojtechovsky Date: Thu, 17 Nov 2016 15:23:05 +0100 Subject: [PATCH] cache URLs of sourceClasspath to avoid failing of tests --- .../spoon/support/StandardEnvironment.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/spoon/support/StandardEnvironment.java b/src/main/java/spoon/support/StandardEnvironment.java index 2d1a1c3e756..87ea9e50864 100644 --- a/src/main/java/spoon/support/StandardEnvironment.java +++ b/src/main/java/spoon/support/StandardEnvironment.java @@ -70,6 +70,7 @@ public class StandardEnvironment implements Serializable, Environment { private int warningCount = 0; private String[] sourceClasspath = null; + private URL[] urlSourceClasspath = null; private boolean preserveLineNumbers = false; @@ -367,17 +368,20 @@ public ClassLoader getClassLoader() { * Creates a URL class path from {@link Environment#getSourceClasspath()} */ public URL[] urlClasspath() { - String[] classpath = getSourceClasspath(); - int length = (classpath == null) ? 0 : classpath.length; - URL[] urls = new URL[length]; - for (int i = 0; i < length; i += 1) { - try { - urls[i] = new File(classpath[i]).toURI().toURL(); - } catch (MalformedURLException e) { - throw new IllegalStateException("Invalid classpath: " + classpath, e); + if (urlSourceClasspath == null) { + String[] classpath = getSourceClasspath(); + int length = (classpath == null) ? 0 : classpath.length; + URL[] urls = new URL[length]; + for (int i = 0; i < length; i += 1) { + try { + urls[i] = new File(classpath[i]).toURI().toURL(); + } catch (MalformedURLException e) { + throw new IllegalStateException("Invalid classpath: " + classpath, e); + } } + urlSourceClasspath = urls; } - return urls; + return urlSourceClasspath; } @Override @@ -389,6 +393,7 @@ public String[] getSourceClasspath() { public void setSourceClasspath(String[] sourceClasspath) { verifySourceClasspath(sourceClasspath); this.sourceClasspath = sourceClasspath; + urlSourceClasspath = null; } private void verifySourceClasspath(String[] sourceClasspath) throws InvalidClassPathException {