Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDeprScan release 17 #127

Merged
merged 2 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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