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

fix: create dependencyResourceLoaders in 2 passes #4870

Merged
merged 2 commits into from
Jan 9, 2025
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
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
Loading