Skip to content
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
14 changes: 13 additions & 1 deletion src/main/resources/META-INF/rewrite/java-version-17.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ recipeList:
groupId: commons-codec
artifactId: commons-codec
newVersion: 1.17.x
# As it's a Maven plugin, we should only need Maven versions of these upgrades
- org.openrewrite.maven.UpgradeDependencyVersion:
groupId: com.github.spotbugs
artifactId: spotbugs-maven-plugin
newVersion: 4.9.x
- org.openrewrite.maven.UpgradePluginVersion:
groupId: com.github.spotbugs
artifactId: spotbugs-maven-plugin
newVersion: 4.9.x
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
groupId: org.mapstruct
artifactId: mapstruct*
newVersion: 1.6.x
- org.openrewrite.java.migrate.AddLombokMapstructBinding
- org.openrewrite.java.migrate.UpdateJakartaAnnotationsIfForJavax
- org.openrewrite.java.migrate.UpdateJakartaAnnotationsIfExistsForJakarta
Expand Down Expand Up @@ -325,7 +338,6 @@ recipeList:
groupId: org.projectlombok
artifactId: lombok-mapstruct-binding
version: 0.2.0

---
# The scanning phase comes before the editing phase, therefor we check if a javax.annotation dependency is on the classpath (with whatever version)
type: specs.openrewrite.org/v1beta/recipe
Expand Down
113 changes: 113 additions & 0 deletions src/test/java/org/openrewrite/java/migrate/UpgradeToJava17Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.regex.Pattern;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openrewrite.gradle.Assertions.buildGradle;
import static org.openrewrite.gradle.toolingapi.Assertions.withToolingApi;
import static org.openrewrite.java.Assertions.*;
import static org.openrewrite.maven.Assertions.pomXml;

Expand Down Expand Up @@ -571,4 +573,115 @@ void init() {}
8)
);
}

@Test
void upgradeSpotbugsPluginVersion() {
rewriteRun(
pomXml(
//language=xml
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<dependencies>
<!-- Uncommon, but supported -->
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Expected and supported -->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</build>
</project>
""",
spec -> spec.after(actual ->
assertThat(actual)
.containsPattern("<version>4.9.\\d+(.\\d+)?</version>")
.doesNotContain("<version>3.1.0</version>")
.actual()
)
)
);
}

@Test
void upgradeMapstructAndAnnotationPaths() {
rewriteRun(
pomXml(
//language=xml
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.4.0.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.1.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
""",
spec -> spec.after(actual ->
assertThat(actual)
.doesNotContain("1.4.0.Final")
// TODO .doesNotContain("1.4.1.Final") // after https://github.com/openrewrite/rewrite/pull/5936
.actual())
)
);
}

@Test
void upgradeMapstructAndAnnotationPathsWithGradle() {
rewriteRun(
spec -> spec.beforeRecipe(withToolingApi()),
buildGradle(
//language=groovy
"""
plugins { id 'java' }
repositories { mavenCentral() }
dependencies {
implementation 'org.mapstruct:mapstruct:1.4.1.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.1.Final'
}
""",
spec -> spec.after(actual ->
assertThat(actual)
.doesNotContain("1.4.1.Final")
.containsPattern("1.6.\\d+(.\\d+)?")
.actual())
)
);
}
}