Skip to content

Commit

Permalink
Move memoized runtime classpath to a package private utility class.
Browse files Browse the repository at this point in the history
  • Loading branch information
sambsnyd committed Apr 25, 2024
1 parent 559b956 commit 8988375
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions rewrite-java/src/main/java/org/openrewrite/java/JavaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,8 @@ public interface JavaParser extends Parser {
*/
String SKIP_SOURCE_SET_TYPE_GENERATION = "org.openrewrite.java.skipSourceSetTypeGeneration";

List<Path> runtimeClasspath = new ArrayList<>();
static List<Path> runtimeClasspath() {
if(runtimeClasspath.isEmpty()) {
runtimeClasspath.addAll(new ClassGraph()
.disableNestedJarScanning()
.getClasspathURIs().stream()
.filter(uri -> "file".equals(uri.getScheme()))
.map(Paths::get).collect(toList()));
}
return runtimeClasspath;
return RuntimeClasspathCache.getRuntimeClasspath();
}

/**
Expand Down Expand Up @@ -456,3 +448,22 @@ static Path resolveSourcePathFromSourceText(Path prefix, String sourceCode) {
return prefix.resolve(Paths.get(pkg + className));
}
}

class RuntimeClasspathCache {
private RuntimeClasspathCache() {
}

@Nullable
private static List<Path> runtimeClasspath = null;

static List<Path> getRuntimeClasspath() {
if (runtimeClasspath == null) {
runtimeClasspath = new ClassGraph()
.disableNestedJarScanning()
.getClasspathURIs().stream()
.filter(uri -> "file".equals(uri.getScheme()))
.map(Paths::get).collect(toList());
}
return runtimeClasspath;
}
}

0 comments on commit 8988375

Please sign in to comment.