Skip to content

Commit f59f02d

Browse files
committed
Polish
1 parent b10ead6 commit f59f02d

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

plugin/src/main/java/org/openrewrite/gradle/isolated/DefaultProjectParser.java

+16-4
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,25 @@ public Stream<SourceFile> parse(ExecutionContext ctx) {
629629
builder = Stream.concat(builder, parse(subProject, alreadyParsed, ctx));
630630
}
631631
}
632+
builder = Stream.concat(builder, parse(project, alreadyParsed, ctx));
633+
return applyGradleScriptMarkers(builder)
634+
// log parse errors here at the end, so that we don't log parse errors for files that were excluded
635+
.map(this::logParseErrors);
636+
}
637+
638+
/**
639+
* Sometimes Gradle script plugins will define dependencies.
640+
* Recipes may want to modify dependencies declared in script plugins, which requires knowledge of which repositories dependencies should be resolved from.
641+
* This adds a synthetic GradleProject marker listing dependency repositories to any freestanding Gradle script plugins.
642+
*
643+
* @param sourceFiles a stream of sources which may contain Gradle build files and scripts
644+
* @return a stream of sources where any freestanding Gradle scripts have a GradleProject marker
645+
*/
646+
private Stream<SourceFile> applyGradleScriptMarkers(Stream<SourceFile> sourceFiles) {
632647
Set<MavenRepository> allBuildscriptRepositories = new LinkedHashSet<>();
633648
Set<MavenRepository> allRepositories = new LinkedHashSet<>();
634649
AtomicReference<GradleProject> freestandingScriptMarker = new AtomicReference<>();
635-
builder = Stream.concat(builder, parse(project, alreadyParsed, ctx))
650+
return sourceFiles
636651
.peek(s -> s.getMarkers()
637652
.findFirst(GradleProject.class)
638653
.ifPresent(gp -> {
@@ -655,9 +670,6 @@ public Stream<SourceFile> parse(ExecutionContext ctx) {
655670
}
656671
return before;
657672
});
658-
659-
// log parse errors here at the end, so that we don't log parse errors for files that were excluded
660-
return builder.map(this::logParseErrors);
661673
}
662674

663675
public Stream<SourceFile> parse(Project subproject, Set<Path> alreadyParsed, ExecutionContext ctx) {

0 commit comments

Comments
 (0)