Skip to content

Commit

Permalink
JDeprScan release 17 (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim te Beek authored Oct 17, 2022
1 parent e7a5623 commit c364748
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/main/java/org/openrewrite/java/migrate/AddJDeprScanPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -53,25 +59,24 @@ public Duration getEstimatedEffortPerOccurrence() {
@Override
protected List<SourceFile> visit(List<SourceFile> 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<ExecutionContext> {
private class AddJDeprScanPluginVisitor extends MavenVisitor<ExecutionContext> {

@Override
public Xml visitDocument(Xml.Document document, ExecutionContext o) {
doAfterVisit(new AddPlugin(
"org.apache.maven.plugins",
"maven-jdeprscan-plugin",
"3.0.0-alpha-1",
"" +
"<configuration>\n" +
" <release>11</release>\n" +
"</configuration>",
String.format("<configuration>\n <release>%s</release>\n</configuration>",
StringUtils.isNullOrEmpty(getRelease()) ? "11" : getRelease()),
null,
null));
return document;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/rewrite/upgrade-java-17.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c364748

Please sign in to comment.