From 1dfe9381bc4bb61ec9e8b39968f6da19297b1dec Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 21 Aug 2024 12:57:18 +0200 Subject: [PATCH] Allow composition of DependencyInsight in rewrite-java-dependencies Since the call to `isAcceptable` would otherwise return true even for Maven pom.xml files. https://github.com/openrewrite/rewrite-java-dependencies/blob/09f24942ee913d5932761cd2baacf13db2b36907/src/main/java/org/openrewrite/java/dependencies/DependencyInsight.java#L72-L78 --- .../org/openrewrite/gradle/search/DependencyInsight.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/search/DependencyInsight.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/search/DependencyInsight.java index 19e4bc9b445..eb1a6e47ae1 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/search/DependencyInsight.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/search/DependencyInsight.java @@ -44,7 +44,6 @@ import static java.util.Objects.requireNonNull; - @Value @EqualsAndHashCode(callSuper = false) public class DependencyInsight extends Recipe { @@ -102,6 +101,11 @@ public Validated validate() { @Override public TreeVisitor getVisitor() { return new TreeVisitor() { + @Override + public boolean isAcceptable(SourceFile sourceFile, ExecutionContext ctx) { + return sourceFile.getMarkers().findFirst(GradleProject.class).isPresent(); + } + @Override public Tree visit(@Nullable Tree tree, ExecutionContext ctx) { SourceFile sourceFile = (SourceFile) requireNonNull(tree);