Skip to content

Commit c364748

Browse files
author
Tim te Beek
authored
JDeprScan release 17 (#127)
1 parent e7a5623 commit c364748

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/main/java/org/openrewrite/java/migrate/AddJDeprScanPlugin.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
*/
1616
package org.openrewrite.java.migrate;
1717

18-
import org.openrewrite.ExecutionContext;
19-
import org.openrewrite.Incubating;
20-
import org.openrewrite.Recipe;
21-
import org.openrewrite.SourceFile;
18+
import lombok.Getter;
19+
import lombok.RequiredArgsConstructor;
20+
21+
import org.openrewrite.*;
2222
import org.openrewrite.internal.ListUtils;
23+
import org.openrewrite.internal.StringUtils;
2324
import org.openrewrite.maven.AddPlugin;
2425
import org.openrewrite.maven.MavenVisitor;
2526
import org.openrewrite.maven.tree.MavenResolutionResult;
@@ -29,12 +30,17 @@
2930
import java.util.List;
3031

3132
/**
32-
* This imperative recipe will add the jdeprsacn plugin to a maven project. In the case of a multi-module project,
33+
* This imperative recipe will add the jdeprscan plugin to a maven project. In the case of a multi-module project,
3334
* this recipe will attempt to add the plugin to only the top level project.
3435
*/
3536
@Incubating(since = "0.2.0")
37+
@RequiredArgsConstructor
38+
@Getter
3639
public class AddJDeprScanPlugin extends Recipe {
3740

41+
@Option(displayName = "release", description = "Specifies the Java SE release that provides the set of deprecated APIs for scanning.", required = false, example = "11")
42+
private final String release;
43+
3844
@Override
3945
public String getDisplayName() {
4046
return "Add JDeprScan Maven Plug-in";
@@ -53,25 +59,24 @@ public Duration getEstimatedEffortPerOccurrence() {
5359
@Override
5460
protected List<SourceFile> visit(List<SourceFile> before, ExecutionContext ctx) {
5561
return ListUtils.map(before, s -> {
56-
if ("pom.xml".equals(s.getSourcePath().toString()) && s.getMarkers().findFirst(MavenResolutionResult.class).isPresent()) {
62+
if ("pom.xml".equals(s.getSourcePath().toString())
63+
&& s.getMarkers().findFirst(MavenResolutionResult.class).isPresent()) {
5764
return (SourceFile) new AddJDeprScanPluginVisitor().visit(s, ctx);
5865
}
5966
return s;
6067
});
6168
}
6269

63-
private static class AddJDeprScanPluginVisitor extends MavenVisitor<ExecutionContext> {
70+
private class AddJDeprScanPluginVisitor extends MavenVisitor<ExecutionContext> {
6471

6572
@Override
6673
public Xml visitDocument(Xml.Document document, ExecutionContext o) {
6774
doAfterVisit(new AddPlugin(
6875
"org.apache.maven.plugins",
6976
"maven-jdeprscan-plugin",
7077
"3.0.0-alpha-1",
71-
"" +
72-
"<configuration>\n" +
73-
" <release>11</release>\n" +
74-
"</configuration>",
78+
String.format("<configuration>\n <release>%s</release>\n</configuration>",
79+
StringUtils.isNullOrEmpty(getRelease()) ? "11" : getRelease()),
7580
null,
7681
null));
7782
return document;

src/main/resources/META-INF/rewrite/upgrade-java-17.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ recipeList:
2727
- org.openrewrite.java.migrate.JavaVersion17
2828
- org.openrewrite.java.migrate.lang.StringFormatted
2929
- org.openrewrite.java.migrate.lombok.LombokValToFinalVar
30+
- org.openrewrite.java.migrate.AddJDeprScanPlugin:
31+
release: 17

0 commit comments

Comments
 (0)