Skip to content

Commit

Permalink
cache URLs of sourceClasspath to avoid failing of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky committed Nov 18, 2016
1 parent f657cef commit 7876e39
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/main/java/spoon/support/StandardEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 7876e39

Please sign in to comment.