Skip to content

Commit 430689d

Browse files
committed
Updated AddJDeprScanPlugin recipe.
1 parent 1dc7bdf commit 430689d

File tree

3 files changed

+75
-46
lines changed

3 files changed

+75
-46
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2021 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite.java.migrate;
17+
18+
import org.openrewrite.ExecutionContext;
19+
import org.openrewrite.Incubating;
20+
import org.openrewrite.Recipe;
21+
import org.openrewrite.SourceFile;
22+
import org.openrewrite.internal.ListUtils;
23+
import org.openrewrite.maven.AddPlugin;
24+
import org.openrewrite.maven.MavenVisitor;
25+
import org.openrewrite.maven.tree.Maven;
26+
27+
import java.util.List;
28+
29+
/**
30+
* This imperative recipe will add the jdeprsacn plugin to a maven project. In the case of a multi-module project,
31+
* this recipe will attempt to add the plugin to only the top level project.
32+
*/
33+
@Incubating(since = "0.2.0")
34+
public class AddJDeprScanPlugin extends Recipe {
35+
36+
@Override
37+
public String getDisplayName() {
38+
return "Add JDeprScan Maven Plug-in";
39+
}
40+
41+
@Override
42+
public String getDescription() {
43+
return "JDeprScan scans class files for uses of deprecated APIs.";
44+
}
45+
46+
@Override
47+
protected List<SourceFile> visit(List<SourceFile> before, ExecutionContext ctx) {
48+
return ListUtils.map(before, s -> {
49+
if (s instanceof Maven && "pom.xml".equals(s.getSourcePath().toString())) {
50+
Maven maven = (Maven) s;
51+
return (SourceFile) new AddJDeprScanPluginVisitor().visit(maven, ctx);
52+
}
53+
return s;
54+
});
55+
}
56+
57+
private static class AddJDeprScanPluginVisitor extends MavenVisitor {
58+
59+
@Override
60+
public Maven visitMaven(Maven maven, ExecutionContext ctx) {
61+
doAfterVisit(new AddPlugin(
62+
"org.apache.maven.plugins",
63+
"maven-jdeprscan-plugin",
64+
"3.0.0-alpha-1",
65+
"" +
66+
"<configuration>\n" +
67+
" <release>11</release>\n" +
68+
"</configuration>",
69+
null,
70+
null));
71+
return maven;
72+
}
73+
}
74+
}

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

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/main/resources/META-INF/rewrite/java8-to-java11.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ recipeList:
3131
- org.openrewrite.java.migrate.javax.AddJaxwsDependencies
3232
- org.openrewrite.java.migrate.javax.AddInjectDependencies
3333
# Add jdeprscan plugin to a maven-based build.
34-
- org.openrewrite.java.migrate.AddJdeprscanPlugin
34+
- org.openrewrite.java.migrate.AddJDeprScanPlugin
3535
# Remediate deprecations
3636
- org.openrewrite.java.cleanup.BigDecimalRoundingConstantsToEnums
3737
- org.openrewrite.java.cleanup.PrimitiveWrapperClassConstructorToValueOf

0 commit comments

Comments
 (0)