Skip to content

Commit 8c6ff9e

Browse files
steve-aom-elliotttimtebeekJenson3210
authored
Upgrading spotbugs plugin and mapstruct (#818)
* WiP - upgrading spotbugs plugin and mapstruct - still need to sort out annotation processor for Gradle and finish up tests. * No need to add annotation processor, but do upgrade their version * Upgrade spotbugs and mapstruct adding test for Gradle * Deliver some value early for MapStruct & Lombok --------- Co-authored-by: Tim te Beek <[email protected]> Co-authored-by: Jente Sondervorst <[email protected]>
1 parent caec49a commit 8c6ff9e

File tree

2 files changed

+126
-1
lines changed

2 files changed

+126
-1
lines changed

src/main/resources/META-INF/rewrite/java-version-17.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ recipeList:
5858
groupId: commons-codec
5959
artifactId: commons-codec
6060
newVersion: 1.17.x
61+
# As it's a Maven plugin, we should only need Maven versions of these upgrades
62+
- org.openrewrite.maven.UpgradeDependencyVersion:
63+
groupId: com.github.spotbugs
64+
artifactId: spotbugs-maven-plugin
65+
newVersion: 4.9.x
66+
- org.openrewrite.maven.UpgradePluginVersion:
67+
groupId: com.github.spotbugs
68+
artifactId: spotbugs-maven-plugin
69+
newVersion: 4.9.x
70+
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
71+
groupId: org.mapstruct
72+
artifactId: mapstruct*
73+
newVersion: 1.6.x
6174
- org.openrewrite.java.migrate.AddLombokMapstructBinding
6275
- org.openrewrite.java.migrate.UpdateJakartaAnnotationsIfForJavax
6376
- org.openrewrite.java.migrate.UpdateJakartaAnnotationsIfExistsForJakarta
@@ -325,7 +338,6 @@ recipeList:
325338
groupId: org.projectlombok
326339
artifactId: lombok-mapstruct-binding
327340
version: 0.2.0
328-
329341
---
330342
# The scanning phase comes before the editing phase, therefor we check if a javax.annotation dependency is on the classpath (with whatever version)
331343
type: specs.openrewrite.org/v1beta/recipe

src/test/java/org/openrewrite/java/migrate/UpgradeToJava17Test.java

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import java.util.regex.Pattern;
2828

2929
import static org.assertj.core.api.Assertions.assertThat;
30+
import static org.openrewrite.gradle.Assertions.buildGradle;
31+
import static org.openrewrite.gradle.toolingapi.Assertions.withToolingApi;
3032
import static org.openrewrite.java.Assertions.*;
3133
import static org.openrewrite.maven.Assertions.pomXml;
3234

@@ -571,4 +573,115 @@ void init() {}
571573
8)
572574
);
573575
}
576+
577+
@Test
578+
void upgradeSpotbugsPluginVersion() {
579+
rewriteRun(
580+
pomXml(
581+
//language=xml
582+
"""
583+
<project>
584+
<modelVersion>4.0.0</modelVersion>
585+
<groupId>com.mycompany.app</groupId>
586+
<artifactId>my-app</artifactId>
587+
<version>1</version>
588+
<dependencies>
589+
<!-- Uncommon, but supported -->
590+
<dependency>
591+
<groupId>com.github.spotbugs</groupId>
592+
<artifactId>spotbugs-maven-plugin</artifactId>
593+
<version>3.1.0</version>
594+
</dependency>
595+
</dependencies>
596+
<build>
597+
<plugins>
598+
<!-- Expected and supported -->
599+
<plugin>
600+
<groupId>com.github.spotbugs</groupId>
601+
<artifactId>spotbugs-maven-plugin</artifactId>
602+
<version>3.1.0</version>
603+
</plugin>
604+
</plugins>
605+
</build>
606+
</project>
607+
""",
608+
spec -> spec.after(actual ->
609+
assertThat(actual)
610+
.containsPattern("<version>4.9.\\d+(.\\d+)?</version>")
611+
.doesNotContain("<version>3.1.0</version>")
612+
.actual()
613+
)
614+
)
615+
);
616+
}
617+
618+
@Test
619+
void upgradeMapstructAndAnnotationPaths() {
620+
rewriteRun(
621+
pomXml(
622+
//language=xml
623+
"""
624+
<project>
625+
<modelVersion>4.0.0</modelVersion>
626+
<groupId>com.mycompany.app</groupId>
627+
<artifactId>my-app</artifactId>
628+
<version>1</version>
629+
<dependencies>
630+
<dependency>
631+
<groupId>org.mapstruct</groupId>
632+
<artifactId>mapstruct</artifactId>
633+
<version>1.4.0.Final</version>
634+
</dependency>
635+
</dependencies>
636+
<build>
637+
<plugins>
638+
<plugin>
639+
<groupId>org.apache.maven.plugins</groupId>
640+
<artifactId>maven-compiler-plugin</artifactId>
641+
<version>3.8.1</version>
642+
<configuration>
643+
<annotationProcessorPaths>
644+
<path>
645+
<groupId>org.mapstruct</groupId>
646+
<artifactId>mapstruct-processor</artifactId>
647+
<version>1.4.1.Final</version>
648+
</path>
649+
</annotationProcessorPaths>
650+
</configuration>
651+
</plugin>
652+
</plugins>
653+
</build>
654+
</project>
655+
""",
656+
spec -> spec.after(actual ->
657+
assertThat(actual)
658+
.doesNotContain("1.4.0.Final")
659+
// TODO .doesNotContain("1.4.1.Final") // after https://github.com/openrewrite/rewrite/pull/5936
660+
.actual())
661+
)
662+
);
663+
}
664+
665+
@Test
666+
void upgradeMapstructAndAnnotationPathsWithGradle() {
667+
rewriteRun(
668+
spec -> spec.beforeRecipe(withToolingApi()),
669+
buildGradle(
670+
//language=groovy
671+
"""
672+
plugins { id 'java' }
673+
repositories { mavenCentral() }
674+
dependencies {
675+
implementation 'org.mapstruct:mapstruct:1.4.1.Final'
676+
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.1.Final'
677+
}
678+
""",
679+
spec -> spec.after(actual ->
680+
assertThat(actual)
681+
.doesNotContain("1.4.1.Final")
682+
.containsPattern("1.6.\\d+(.\\d+)?")
683+
.actual())
684+
)
685+
);
686+
}
574687
}

0 commit comments

Comments
 (0)