Skip to content

Commit 7b0fa0e

Browse files
committed
Recipe to migrate JSR305 annotations
1 parent ca738df commit 7b0fa0e

4 files changed

Lines changed: 47 additions & 3 deletions

File tree

plugin-modernizer-core/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,17 @@
311311
<artifactId>hamcrest</artifactId>
312312
<version>3.0</version>
313313
</dependency>
314+
<!-- JSR305 annotations -->
315+
<dependency>
316+
<groupId>javax.annotation</groupId>
317+
<artifactId>javax.annotation-api</artifactId>
318+
<version>1.3.2</version>
319+
</dependency>
320+
<dependency>
321+
<groupId>com.google.code.findbugs</groupId>
322+
<artifactId>jsr305</artifactId>
323+
<version>3.0.2</version>
324+
</dependency>
314325
</artifactItems>
315326
</configuration>
316327
</execution>

plugin-modernizer-core/src/main/resources/META-INF/rewrite/recipes.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,11 +734,17 @@ tags: ['chore']
734734
recipeList:
735735
- io.jenkins.tools.pluginmodernizer.core.recipes.MigrateTomakehurstToWiremock
736736
---
737-
---
738737
type: specs.openrewrite.org/v1beta/recipe
739738
name: io.jenkins.tools.pluginmodernizer.JavaxAnnotationsToSpotbugs
740739
displayName: Migrate `javax.annotations` to SpotBugs annotations.
741740
description: SpotBugs is the [preferred replacement](https://www.jenkins.io/doc/developer/tutorial-improve/replace-jsr-305-annotations/) of JSR-305 annotations for Jenkins plugins.
742741
tags: ['chore']
743742
recipeList:
744-
- org.openrewrite.jenkins.JavaxAnnotationsToSpotbugs
743+
- org.openrewrite.java.ChangeType:
744+
oldFullyQualifiedTypeName: javax.annotation.Nonnull
745+
newFullyQualifiedTypeName: edu.umd.cs.findbugs.annotations.NonNull
746+
ignoreDefinition: true
747+
- org.openrewrite.java.ChangePackage:
748+
oldPackageName: javax.annotation
749+
newPackageName: edu.umd.cs.findbugs.annotations
750+
recursive: false

plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/recipes/DeclarativeRecipesTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,21 @@ void upgradeToRecommendCoreVersionTest() {
783783
import hudson.util.IOException2;
784784
import java.io.File;
785785
import java.io.IOException;
786+
import javax.annotation.CheckForNull;
787+
import javax.annotation.Nonnull;
786788
787789
public class Foo {
790+
791+
@CheckForNull
792+
public String getSomething() {
793+
return "something";
794+
}
795+
796+
@Nonnull
797+
public String getOther() {
798+
return "something";
799+
}
800+
788801
public static void main(String[] args) {
789802
try {
790803
parseFile(new File("invalid.xml"));
@@ -802,10 +815,23 @@ private static void parseFile(File file) throws IOException2 {
802815
}
803816
}
804817
""", """
818+
import edu.umd.cs.findbugs.annotations.NonNull;
805819
import java.io.File;
806820
import java.io.IOException;
821+
import edu.umd.cs.findbugs.annotations.CheckForNull;
807822
808823
public class Foo {
824+
825+
@CheckForNull
826+
public String getSomething() {
827+
return "something";
828+
}
829+
830+
@NonNull
831+
public String getOther() {
832+
return "something";
833+
}
834+
809835
public static void main(String[] args) {
810836
try {
811837
parseFile(new File("invalid.xml"));

scripts/validate_metadata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@
9595
"io.jenkins.tools.pluginmodernizer.MigrateTomakehurstToWiremock",
9696
"io.jenkins.tools.pluginmodernizer.MigrateCommonsLang2ToLang3AndCommonText",
9797
"io.jenkins.tools.pluginmodernizer.RemoveOldJavaVersionForModernJenkins",
98-
"io.jenkins.tools.pluginmodernizer.SwitchToRenovate"
98+
"io.jenkins.tools.pluginmodernizer.SwitchToRenovate",
99+
"io.jenkins.tools.pluginmodernizer.JavaxAnnotationsToSpotbugs"
99100
]
100101

101102
def validate_metadata(file_path):

0 commit comments

Comments
 (0)