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

Only process markers when using type in AddDependency #4022

Merged
merged 1 commit into from
Feb 19, 2024
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 @@ -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