Skip to content

Commit

Permalink
feat: include Gradle build files of subprojects (#250)
Browse files Browse the repository at this point in the history
* feat: include Gradle build files of subprojects

* Apply suggestions from code review

---------

Co-authored-by: Andreas Nübel <[email protected]>
Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2023
1 parent 0047896 commit f9bf303
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ public Stream<SourceFile> parse(Project subproject, Set<Path> alreadyParsed, Exe
alreadyParsed.add(file.toPath());
}
}
SourceFileStream gradleFiles = parseGradleFiles(exclusions, alreadyParsed, ctx);
SourceFileStream gradleFiles = parseGradleFiles(subproject, exclusions, alreadyParsed, ctx);
sourceFileStream = sourceFileStream.concat(gradleFiles, gradleFiles.size());

SourceFileStream gradleWrapperFiles = parseGradleWrapperFiles(exclusions, alreadyParsed, ctx);
Expand Down Expand Up @@ -877,14 +877,14 @@ private GradleParser gradleParser() {
}

private SourceFileStream parseGradleFiles(
Collection<PathMatcher> exclusions, Set<Path> alreadyParsed, ExecutionContext ctx) {
Project subproject, Collection<PathMatcher> exclusions, Set<Path> alreadyParsed, ExecutionContext ctx) {
Stream<SourceFile> sourceFiles = Stream.empty();
int gradleFileCount = 0;

GradleParser gradleParser = null;
if (project.getBuildscript().getSourceFile() != null) {
File buildGradleFile = project.getBuildscript().getSourceFile();
Path buildScriptPath = baseDir.relativize(project.getBuildscript().getSourceFile().toPath());
File buildGradleFile = subproject.getBuildscript().getSourceFile();
if (buildGradleFile != null) {
Path buildScriptPath = baseDir.relativize(buildGradleFile.toPath());
if (!isExcluded(exclusions, buildScriptPath) && buildGradleFile.exists()) {
alreadyParsed.add(buildScriptPath);
GradleProject gp = GradleProjectBuilder.gradleProject(project);
Expand All @@ -897,13 +897,13 @@ private SourceFileStream parseGradleFiles(
}
gradleFileCount++;
sourceFiles = sourceFiles.map(sourceFile -> sourceFile.withMarkers(sourceFile.getMarkers().add(gp)));
alreadyParsed.add(project.getBuildscript().getSourceFile().toPath());
alreadyParsed.add(buildGradleFile.toPath());
}
}

if (project == project.getRootProject()) {
File settingsGradleFile = project.file("settings.gradle");
File settingsGradleKtsFile = project.file("settings.gradle.kts");
if (subproject == project.getRootProject()) {
File settingsGradleFile = subproject.file("settings.gradle");
File settingsGradleKtsFile = subproject.file("settings.gradle.kts");
GradleSettings gs = null;
if (GradleVersion.current().compareTo(GradleVersion.version("4.4")) >= 0 && (settingsGradleFile.exists() || settingsGradleKtsFile.exists())) {
gs = GradleSettingsBuilder.gradleSettings(((DefaultGradle) project.getGradle()).getSettings());
Expand Down

0 comments on commit f9bf303

Please sign in to comment.