Skip to content

Commit

Permalink
Only process markers when using type in AddDependency (#4022)
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek authored Feb 19, 2024
1 parent 4dd635a commit 79327eb
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

import static java.util.Objects.requireNonNull;


/**
* This recipe will detect the presence of Java types (in Java ASTs) to determine if a dependency should be added
* to a maven build file. Java Provenance information is used to filter the type search to only those java ASTs that
Expand Down Expand Up @@ -178,17 +177,17 @@ public TreeVisitor<?, ExecutionContext> getScanner(Scanned acc) {
public Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
SourceFile sourceFile = (SourceFile) requireNonNull(tree);
if (tree instanceof JavaSourceFile) {
boolean sourceFileUsesType = onlyIfUsing == null || sourceFile != new UsesType<>(onlyIfUsing, true).visit(sourceFile, ctx);
acc.usingType |= sourceFileUsesType;
sourceFile.getMarkers().findFirst(JavaProject.class).ifPresent(javaProject ->
sourceFile.getMarkers().findFirst(JavaSourceSet.class).ifPresent(sourceSet -> {
if (sourceFileUsesType) {
acc.scopeByProject.compute(javaProject, (jp, scope) -> "compile".equals(scope) ?
scope /* a `compile` scope dependency will also be available in test source set */ :
"test".equals(sourceSet.getName()) ? "test" : "compile"
);
}
}));
if (onlyIfUsing == null || sourceFile != new UsesType<>(onlyIfUsing, true).visit(sourceFile, ctx)) {
acc.usingType = true;
sourceFile.getMarkers().findFirst(JavaProject.class).ifPresent(javaProject ->
sourceFile.getMarkers().findFirst(JavaSourceSet.class).ifPresent(sourceSet ->
acc.scopeByProject.compute(javaProject, (jp, scope) -> "compile".equals(scope) ?
scope /* a `compile` scope dependency will also be available in test source set */ :
"test".equals(sourceSet.getName()) ? "test" : "compile"
)
)
);
}
}
return sourceFile;
}
Expand Down

0 comments on commit 79327eb

Please sign in to comment.