Skip to content

Commit 4bfca04

Browse files
committed
Update UpgradePluginVersion and AddPluginVisitor to use MethodMatcher
Use MethodMatcher for version detection in UpgradePluginVersion instead of string-based name matching. Tighten AddPluginVisitor's wildcard id matcher to use real PluginDependenciesSpec type.
1 parent ee16cd8 commit 4bfca04

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/AddPluginVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Integ
300300

301301
private K.CompilationUnit addPluginToKotlinCompilationUnit(K.CompilationUnit cu, ExecutionContext ctx) {
302302
MethodMatcher pluginsMatcher = new MethodMatcher("*..* plugins(..)");
303-
MethodMatcher pluginIdMatcher = new MethodMatcher("*..* id(..)");
303+
MethodMatcher pluginIdMatcher = new MethodMatcher("org.gradle.plugin.use.PluginDependenciesSpec id(..)", true);
304304
AtomicBoolean hasPlugin = new JavaIsoVisitor<AtomicBoolean>() {
305305
@Override
306306
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, AtomicBoolean found) {

rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/UpgradePluginVersion.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.openrewrite.internal.ListUtils;
2929
import org.openrewrite.internal.StringUtils;
3030
import org.openrewrite.java.JavaVisitor;
31+
import org.openrewrite.java.MethodMatcher;
3132
import org.openrewrite.java.tree.Expression;
3233
import org.openrewrite.java.tree.J;
3334
import org.openrewrite.maven.MavenDownloadingException;
@@ -53,6 +54,7 @@
5354
@EqualsAndHashCode(callSuper = false)
5455
public class UpgradePluginVersion extends ScanningRecipe<UpgradePluginVersion.DependencyVersionState> {
5556
private static final String GRADLE_PROPERTIES_FILE_NAME = "gradle.properties";
57+
private static final MethodMatcher VERSION_MATCHER = new MethodMatcher("org.gradle.plugin.use.PluginDependencySpec version(..)", true);
5658

5759
@EqualsAndHashCode.Exclude
5860
transient MavenMetadataFailures metadataFailures = new MavenMetadataFailures(this);
@@ -112,7 +114,7 @@ private boolean isPluginVersion(Cursor cursor) {
112114
return false;
113115
}
114116
J.MethodInvocation maybeVersion = cursor.getValue();
115-
if (!"version".equals(maybeVersion.getSimpleName())) {
117+
if (!VERSION_MATCHER.matches(maybeVersion, true)) {
116118
return false;
117119
}
118120
Cursor parent = cursor.dropParentUntil(it -> (it instanceof J.MethodInvocation) || it == Cursor.ROOT_VALUE);

0 commit comments

Comments
 (0)