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

fixed project provenance on gradle files #226

Merged
merged 2 commits into from
Sep 4, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ public Stream<SourceFile> parse(Project subproject, Set<Path> alreadyParsed, Exe
if (subproject.getPlugins().hasPlugin("org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension") ||
subproject.getExtensions().findByName("kotlin") != null && subproject.getExtensions().getByName("kotlin").getClass()
.getCanonicalName().startsWith("org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension")) {
sourceFileStream = sourceFileStream.concat(parseMultiplatformKotlinProject(subproject, exclusions, alreadyParsed, projectProvenance, ctx));
sourceFileStream = sourceFileStream.concat(parseMultiplatformKotlinProject(subproject, exclusions, alreadyParsed, ctx));
}

for (SourceSet sourceSet : sourceSets) {
Expand Down Expand Up @@ -798,17 +798,18 @@ public Stream<SourceFile> parse(Project subproject, Set<Path> alreadyParsed, Exe
}

JavaSourceSet sourceSetProvenance = JavaSourceSet.build(sourceSet.getName(), dependencyPaths, javaTypeCache, false);
sourceFileStream = sourceFileStream.concat(sourceSetSourceFiles.map(addProvenance(projectProvenance, sourceSetProvenance)), sourceSetSize);
sourceFileStream = sourceFileStream.concat(sourceSetSourceFiles.map(addProvenance(sourceSetProvenance)), sourceSetSize);
}

sourceFileStream = sourceFileStream.concat(parseGradleFiles(exclusions, alreadyParsed, ctx));
SourceFileStream gradleFiles = parseGradleFiles(exclusions, alreadyParsed, ctx);
sourceFileStream = sourceFileStream.concat(gradleFiles, gradleFiles.size());

SourceFileStream nonProjectResources = parseNonProjectResources(subproject, alreadyParsed, ctx, projectProvenance, sourceFileStream);
sourceFileStream = sourceFileStream.concat(nonProjectResources
.map(addProvenance(projectProvenance, null)), nonProjectResources.size());
sourceFileStream = sourceFileStream.concat(nonProjectResources, nonProjectResources.size());

progressBar.setMax(sourceFileStream.size());
return sourceFileStream.peek(it -> progressBar.step());
return sourceFileStream
.map(addProvenance(projectProvenance))
.peek(it -> progressBar.step());
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -952,7 +953,7 @@ private Collection<PathMatcher> pathMatchers(Path basePath, Collection<String> p
.collect(Collectors.toList());
}

private SourceFileStream parseMultiplatformKotlinProject(Project subproject, Collection<PathMatcher> exclusions, Set<Path> alreadyParsed, List<Marker> projectProvenance, ExecutionContext ctx) {
private SourceFileStream parseMultiplatformKotlinProject(Project subproject, Collection<PathMatcher> exclusions, Set<Path> alreadyParsed, ExecutionContext ctx) {
Object kotlinExtension = subproject.getExtensions().getByName("kotlin");
NamedDomainObjectContainer<KotlinSourceSet> sourceSets;
try {
Expand Down Expand Up @@ -1044,7 +1045,7 @@ private SourceFileStream parseMultiplatformKotlinProject(Project subproject, Col
}).filter(Objects::nonNull);
JavaSourceSet sourceSetProvenance = JavaSourceSet.build(sourceSetName, dependencyPaths, javaTypeCache, false);

sourceFileStream = sourceFileStream.concat(cus.map(addProvenance(projectProvenance, sourceSetProvenance)), kotlinPaths.size());
sourceFileStream = sourceFileStream.concat(cus.map(addProvenance(sourceSetProvenance)), kotlinPaths.size());
logger.info("Scanned {} Kotlin sources in {}/{}", kotlinPaths.size(), subproject.getPath(), kotlinDirectorySet.getName());
}
return sourceFileStream;
Expand Down Expand Up @@ -1150,19 +1151,25 @@ private UnaryOperator<SourceFile> applyAutodetectedStyle(Map<Class<? extends Tre
};
}

private <T extends SourceFile> UnaryOperator<T> addProvenance(List<Marker> projectProvenance, @Nullable Marker sourceSet) {
private <T extends SourceFile> UnaryOperator<T> addProvenance(List<Marker> projectProvenance) {
return s -> {
Markers m = s.getMarkers();
for (Marker marker : projectProvenance) {
m = m.add(marker);
}
if (sourceSet != null) {
m = m.add(sourceSet);
m = m.addIfAbsent(marker);
}
return s.withMarkers(m);
};
}

private <T extends SourceFile> UnaryOperator<T> addProvenance(Marker sourceSet) {
return s -> {
Markers m = s.getMarkers();
m = m.addIfAbsent(sourceSet);
return s.withMarkers(m);
};
}


protected void logRecipesThatMadeChanges(Result result) {
String indent = " ";
String prefix = " ";
Expand Down