diff --git a/src/main/java/org/openrewrite/java/migrate/AddJDeprScanPlugin.java b/src/main/java/org/openrewrite/java/migrate/AddJDeprScanPlugin.java index aeddb2c060..cec6e6d5a5 100644 --- a/src/main/java/org/openrewrite/java/migrate/AddJDeprScanPlugin.java +++ b/src/main/java/org/openrewrite/java/migrate/AddJDeprScanPlugin.java @@ -15,11 +15,12 @@ */ package org.openrewrite.java.migrate; -import org.openrewrite.ExecutionContext; -import org.openrewrite.Incubating; -import org.openrewrite.Recipe; -import org.openrewrite.SourceFile; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import org.openrewrite.*; import org.openrewrite.internal.ListUtils; +import org.openrewrite.internal.StringUtils; import org.openrewrite.maven.AddPlugin; import org.openrewrite.maven.MavenVisitor; import org.openrewrite.maven.tree.MavenResolutionResult; @@ -29,12 +30,17 @@ import java.util.List; /** - * This imperative recipe will add the jdeprsacn plugin to a maven project. In the case of a multi-module project, + * This imperative recipe will add the jdeprscan plugin to a maven project. In the case of a multi-module project, * this recipe will attempt to add the plugin to only the top level project. */ @Incubating(since = "0.2.0") +@RequiredArgsConstructor +@Getter public class AddJDeprScanPlugin extends Recipe { + @Option(displayName = "release", description = "Specifies the Java SE release that provides the set of deprecated APIs for scanning.", required = false, example = "11") + private final String release; + @Override public String getDisplayName() { return "Add JDeprScan Maven Plug-in"; @@ -53,14 +59,15 @@ public Duration getEstimatedEffortPerOccurrence() { @Override protected List visit(List before, ExecutionContext ctx) { return ListUtils.map(before, s -> { - if ("pom.xml".equals(s.getSourcePath().toString()) && s.getMarkers().findFirst(MavenResolutionResult.class).isPresent()) { + if ("pom.xml".equals(s.getSourcePath().toString()) + && s.getMarkers().findFirst(MavenResolutionResult.class).isPresent()) { return (SourceFile) new AddJDeprScanPluginVisitor().visit(s, ctx); } return s; }); } - private static class AddJDeprScanPluginVisitor extends MavenVisitor { + private class AddJDeprScanPluginVisitor extends MavenVisitor { @Override public Xml visitDocument(Xml.Document document, ExecutionContext o) { @@ -68,10 +75,8 @@ public Xml visitDocument(Xml.Document document, ExecutionContext o) { "org.apache.maven.plugins", "maven-jdeprscan-plugin", "3.0.0-alpha-1", - "" + - "\n" + - " 11\n" + - "", + String.format("\n %s\n", + StringUtils.isNullOrEmpty(getRelease()) ? "11" : getRelease()), null, null)); return document; diff --git a/src/main/resources/META-INF/rewrite/upgrade-java-17.yml b/src/main/resources/META-INF/rewrite/upgrade-java-17.yml index 18dba71729..a72065923b 100644 --- a/src/main/resources/META-INF/rewrite/upgrade-java-17.yml +++ b/src/main/resources/META-INF/rewrite/upgrade-java-17.yml @@ -27,3 +27,5 @@ recipeList: - org.openrewrite.java.migrate.JavaVersion17 - org.openrewrite.java.migrate.lang.StringFormatted - org.openrewrite.java.migrate.lombok.LombokValToFinalVar + - org.openrewrite.java.migrate.AddJDeprScanPlugin: + release: 17