Skip to content

Commit

Permalink
fix: create dependencyResourceLoaders in 2 passes (#4870)
Browse files Browse the repository at this point in the history
* fix: create dependencyResourceLoaders in 2 passes

* Inline variables used once

---------

Co-authored-by: Tim te Beek <tim@moderne.io>
  • Loading branch information
natedanner and timtebeek authored Jan 9, 2025
1 parent 13b6168 commit 1bb9da0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions rewrite-core/src/main/java/org/openrewrite/config/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,23 @@ public Builder scanYamlResources() {
*/
@SuppressWarnings("unused")
public Builder scanJar(Path jar, Collection<Path> dependencies, ClassLoader classLoader) {
List<ClasspathScanningLoader> list = new ArrayList<>();
List<ClasspathScanningLoader> firstPassLoaderList = new ArrayList<>();
for (Path dep : dependencies) {
ClasspathScanningLoader classpathScanningLoader = new ClasspathScanningLoader(dep, properties, emptyList(), classLoader);
list.add(classpathScanningLoader);
firstPassLoaderList.add(new ClasspathScanningLoader(dep, properties, emptyList(), classLoader));
}
return load(new ClasspathScanningLoader(jar, properties, list, classLoader), list);

/*
* Second loader creation pass where the firstPassLoaderList is passed as the
* dependencyResourceLoaders list to ensure that we can resolve transitive
* dependencies using the loaders we just created. This is necessary because
* the first pass may have missing recipes since the full list of loaders was
* not provided.
*/
List<ClasspathScanningLoader> secondPassLoaderList = new ArrayList<>();
for (Path dep : dependencies) {
secondPassLoaderList.add(new ClasspathScanningLoader(dep, properties, firstPassLoaderList, classLoader));
}
return load(new ClasspathScanningLoader(jar, properties, secondPassLoaderList, classLoader), secondPassLoaderList);
}

@SuppressWarnings("unused")
Expand Down

0 comments on commit 1bb9da0

Please sign in to comment.