File tree Expand file tree Collapse file tree 6 files changed +79
-1
lines changed
resources/META-INF/rewrite
test/java/io/jenkins/tools/pluginmodernizer/core Expand file tree Collapse file tree 6 files changed +79
-1
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 1+
2+ @import io.jenkins.tools.pluginmodernizer.core.model.Plugin
3+ @import io.jenkins.tools.pluginmodernizer.core.model.Recipe
4+ @param Plugin plugin
5+ @param Recipe recipe
6+ Migrate `javax.annotations` to SpotBugs annotations
Original file line number Diff line number Diff line change @@ -573,6 +573,7 @@ recipeList:
573573 - io.jenkins.tools.pluginmodernizer.core.recipes.MigrateStaplerAndJavaxToJakarta
574574 - io.jenkins.tools.pluginmodernizer.core.recipes.MigrateAcegiSecurityToSpringSecurity
575575 - io.jenkins.tools.pluginmodernizer.MigrateCommonsLang2ToLang3AndCommonText
576+ - io.jenkins.tools.pluginmodernizer.JavaxAnnotationsToSpotbugs
576577 - io.jenkins.tools.pluginmodernizer.core.recipes.MigrateTomakehurstToWiremock
577578 - io.jenkins.tools.pluginmodernizer.ReplaceIOException2WithIOException
578579 - io.jenkins.tools.pluginmodernizer.RemoveDevelopersTag
@@ -732,3 +733,18 @@ description: This PR migrates the groupId and artifactId to the new artifact and
732733tags : ['chore']
733734recipeList :
734735 - io.jenkins.tools.pluginmodernizer.core.recipes.MigrateTomakehurstToWiremock
736+ ---
737+ type : specs.openrewrite.org/v1beta/recipe
738+ name : io.jenkins.tools.pluginmodernizer.JavaxAnnotationsToSpotbugs
739+ displayName : Migrate `javax.annotations` to SpotBugs annotations.
740+ 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.
741+ tags : ['chore']
742+ recipeList :
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
Original file line number Diff line number Diff 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"));
Original file line number Diff line number Diff line change @@ -811,4 +811,22 @@ public void testFriendlyPrBodyMigrateCommonsLang2ToLang3AndCommonText() {
811811 result .contains ("This pull request upgrades `Apache Commons Lang 2` to `Apache Commons Lang 3`" ),
812812 "Description" );
813813 }
814+
815+ @ Test
816+ public void testFriendlyPrTitleMigrateJavaxAnnotationsToSpotbugs () {
817+
818+ // Mocks
819+ Plugin plugin = mock (Plugin .class );
820+ Recipe recipe = mock (Recipe .class );
821+
822+ doReturn ("io.jenkins.tools.pluginmodernizer.JavaxAnnotationsToSpotbugs" )
823+ .when (recipe )
824+ .getName ();
825+
826+ // Test
827+ String result = TemplateUtils .renderPullRequestTitle (plugin , recipe );
828+
829+ // Assert
830+ assertEquals ("Migrate `javax.annotations` to SpotBugs annotations" , result );
831+ }
814832}
Original file line number Diff line number Diff line change 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
101102def validate_metadata (file_path ):
You can’t perform that action at this time.
0 commit comments