From dda4fa4aaa9e997a5d2c70078a7ae5c727a12aa8 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 1 May 2024 08:23:53 +0200 Subject: [PATCH] Drop intermediate JavaVersion11/17/21 recipes (#468) * Drop intermediate JavaVersion11/17/21 recipes These only delegate to UpgradeJavaVersion, but had a displayName and description that were Maven specific, despite also updating Gradle build files, and source file markers after 9c6acfb5c5f2c942f8660a687b5263b3841c65ac * Drop duplicate tests --- .../META-INF/rewrite/java-version-11.yml | 19 +-- .../META-INF/rewrite/java-version-17.yml | 14 +- .../META-INF/rewrite/java-version-21.yml | 14 +- .../java/migrate/UpdateMavenToJava11Test.java | 142 ------------------ .../java/migrate/UpgradeJavaVersionTest.java | 24 +++ 5 files changed, 34 insertions(+), 179 deletions(-) delete mode 100644 src/test/java/org/openrewrite/java/migrate/UpdateMavenToJava11Test.java diff --git a/src/main/resources/META-INF/rewrite/java-version-11.yml b/src/main/resources/META-INF/rewrite/java-version-11.yml index 235abc5d5b..7c9347f41e 100644 --- a/src/main/resources/META-INF/rewrite/java-version-11.yml +++ b/src/main/resources/META-INF/rewrite/java-version-11.yml @@ -57,7 +57,12 @@ recipeList: - org.openrewrite.java.migrate.cobertura.RemoveCoberturaMavenPlugin - org.openrewrite.java.migrate.wro4j.UpgradeWro4jMavenPluginVersion - org.openrewrite.java.migrate.jacoco.UpgradeJaCoCoMavenPluginVersion - - org.openrewrite.java.migrate.JavaVersion11 + - org.openrewrite.java.migrate.UpgradeJavaVersion: + version: 11 + - org.openrewrite.maven.UpgradePluginVersion: + groupId: org.apache.maven.plugins + artifactId: maven-compiler-plugin + newVersion: 3.6.2 # Disabled due to null safety issues in the current implementation # https://github.com/openrewrite/rewrite-migrate-java/issues/250 # - org.openrewrite.java.migrate.util.JavaUtilAPIs @@ -71,18 +76,6 @@ recipeList: --- type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.java.migrate.JavaVersion11 -displayName: Change Maven Java version property values to 11 -description: Change maven.compiler.source and maven.compiler.target values to 11. -recipeList: - - org.openrewrite.java.migrate.UpgradeJavaVersion: - version: 11 - - org.openrewrite.maven.UpgradePluginVersion: - groupId: org.apache.maven.plugins - artifactId: maven-compiler-plugin - newVersion: 3.6.2 ---- -type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.javax.AddJaxbDependencies displayName: Add explicit JAXB dependencies description: > diff --git a/src/main/resources/META-INF/rewrite/java-version-17.yml b/src/main/resources/META-INF/rewrite/java-version-17.yml index 0e9d4dc62e..1d4df01fb5 100644 --- a/src/main/resources/META-INF/rewrite/java-version-17.yml +++ b/src/main/resources/META-INF/rewrite/java-version-17.yml @@ -27,7 +27,8 @@ tags: - java17 recipeList: - org.openrewrite.java.migrate.Java8toJava11 - - org.openrewrite.java.migrate.JavaVersion17 + - org.openrewrite.java.migrate.UpgradeJavaVersion: + version: 17 - org.openrewrite.java.migrate.lang.StringFormatted - org.openrewrite.github.SetupJavaUpgradeJavaVersion: minimumJavaMajorVersion: 17 @@ -57,17 +58,6 @@ recipeList: - org.openrewrite.java.migrate.RemovedFileIOFinalizeMethods --- type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.java.migrate.JavaVersion17 -displayName: Change Maven Java version property values to 17 -description: Change maven.compiler.source and maven.compiler.target values to 17. -tags: - - java17 - - compiler -recipeList: - - org.openrewrite.java.migrate.UpgradeJavaVersion: - version: 17 ---- -type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.DeprecatedJavaxSecurityCert displayName: Use `java.security.cert` instead of `javax.security.cert` description: The `javax.security.cert` package has been deprecated for removal. diff --git a/src/main/resources/META-INF/rewrite/java-version-21.yml b/src/main/resources/META-INF/rewrite/java-version-21.yml index e54749d031..309c481658 100644 --- a/src/main/resources/META-INF/rewrite/java-version-21.yml +++ b/src/main/resources/META-INF/rewrite/java-version-21.yml @@ -25,7 +25,8 @@ tags: - java21 recipeList: - org.openrewrite.java.migrate.UpgradeToJava17 - - org.openrewrite.java.migrate.JavaVersion21 + - org.openrewrite.java.migrate.UpgradeJavaVersion: + version: 21 - org.openrewrite.java.migrate.RemoveIllegalSemicolons - org.openrewrite.java.migrate.lang.ThreadStopUnsupported - org.openrewrite.java.migrate.net.URLConstructorsToURIRecipes @@ -61,17 +62,6 @@ recipeList: --- type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.java.migrate.JavaVersion21 -displayName: Change Maven Java version property values to 21 -description: Change maven.compiler.source and maven.compiler.target values to 21. -tags: - - java21 - - compiler -recipeList: - - org.openrewrite.java.migrate.UpgradeJavaVersion: - version: 21 ---- -type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.util.SequencedCollection displayName: Adopt `SequencedCollection` description: Replace older code patterns with `SequencedCollection` methods, as per https://openjdk.org/jeps/431. diff --git a/src/test/java/org/openrewrite/java/migrate/UpdateMavenToJava11Test.java b/src/test/java/org/openrewrite/java/migrate/UpdateMavenToJava11Test.java deleted file mode 100644 index 2e2dac6ad8..0000000000 --- a/src/test/java/org/openrewrite/java/migrate/UpdateMavenToJava11Test.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2021 the original author or authors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.java.migrate; - -import org.junit.jupiter.api.Test; -import org.openrewrite.DocumentExample; -import org.openrewrite.Issue; -import org.openrewrite.config.Environment; -import org.openrewrite.test.RecipeSpec; -import org.openrewrite.test.RewriteTest; - -import static org.openrewrite.java.Assertions.version; -import static org.openrewrite.maven.Assertions.pomXml; - -class UpdateMavenToJava11Test implements RewriteTest { - - @Override - public void defaults(RecipeSpec spec) { - spec.recipe(Environment.builder() - .scanRuntimeClasspath("org.openrewrite.java.migrate") - .build().activateRecipes("org.openrewrite.java.migrate.JavaVersion11")); - } - - @DocumentExample - @Test - void changeJavaVersion() { - //language=xml - rewriteRun( - version( - pomXml( - """ - - 4.0.0 - - - 1.8 - - - com.mycompany.app - my-app - 1 - - """, - """ - - 4.0.0 - - - 11 - - - com.mycompany.app - my-app - 1 - - """ - ), - 8 - ) - ); - } - - @Test - void changeMavenCompiler() { - //language=xml - rewriteRun( - version( - pomXml( - """ - - 4.0.0 - - - 1.8 - 1.8 - - - com.mycompany.app - my-app - 1 - - """, - """ - - 4.0.0 - - - 11 - 11 - - - com.mycompany.app - my-app - 1 - - """ - ), - 8 - ) - ); - } - - @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/169") - @Test - void noDowngrade() { - rewriteRun( - version( - //language=xml - pomXml( - """ - - 4.0.0 - - - 17 - 17 - - - com.mycompany.app - my-app - 1 - - """ - ), - 17 - ) - ); - } -} diff --git a/src/test/java/org/openrewrite/java/migrate/UpgradeJavaVersionTest.java b/src/test/java/org/openrewrite/java/migrate/UpgradeJavaVersionTest.java index 9e4975d582..3e79c56796 100644 --- a/src/test/java/org/openrewrite/java/migrate/UpgradeJavaVersionTest.java +++ b/src/test/java/org/openrewrite/java/migrate/UpgradeJavaVersionTest.java @@ -183,6 +183,30 @@ void gradleSourceTargetFromJava11ToJava17() { ); } + @Test + void gradleSourceTargetFromJava11ToJava21ThroughEnum() { + rewriteRun( + spec -> spec.recipe(new UpgradeJavaVersion(21)), + buildGradle( + //language=groovy + """ + java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + """, + //language=groovy + """ + java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 + } + """, + spec -> spec.markers(new JavaVersion(UUID.randomUUID(), "", "", "11.0.15+10", "11.0.15+10")) + ) + ); + } + @Test void gradleNoChangeIfUpgradeFromJava11ToJava8() { rewriteRun(