From 3987a736db1d01c7b9a75df8b16dd83fb699ba71 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Fri, 1 Nov 2024 18:50:32 +0100 Subject: [PATCH 1/2] Use Java 21 toolchain for rewrite-migrate-java Replaces #337 --- .sdkmanrc | 2 +- build.gradle.kts | 6 ++++ .../migrate/DeleteDeprecatedFinalizeTest.java | 29 ++++++++++--------- .../migrate/util/SequencedCollectionTest.java | 15 ++++------ 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/.sdkmanrc b/.sdkmanrc index ed31de442e..d2635abfaf 100644 --- a/.sdkmanrc +++ b/.sdkmanrc @@ -1,3 +1,3 @@ # Enable auto-env through the sdkman_auto_env config # Add key=value pairs of SDKs to use below -java=21.0.2-tem +java=21.0.5-tem diff --git a/build.gradle.kts b/build.gradle.kts index d02f433cd3..e7f9cafba1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -62,6 +62,12 @@ dependencies { testRuntimeOnly(gradleApi()) } +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(21)) + } +} + tasks.withType(Javadoc::class.java) { exclude("**/PlanJavaMigration.java") } diff --git a/src/test/java/org/openrewrite/java/migrate/DeleteDeprecatedFinalizeTest.java b/src/test/java/org/openrewrite/java/migrate/DeleteDeprecatedFinalizeTest.java index eb8d42da0b..44952260a1 100644 --- a/src/test/java/org/openrewrite/java/migrate/DeleteDeprecatedFinalizeTest.java +++ b/src/test/java/org/openrewrite/java/migrate/DeleteDeprecatedFinalizeTest.java @@ -16,12 +16,15 @@ package org.openrewrite.java.migrate; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; import org.openrewrite.DocumentExample; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; import static org.openrewrite.java.Assertions.java; +@EnabledForJreRange(max = JRE.JAVA_17) class DeleteDeprecatedFinalizeTest implements RewriteTest { @Override @@ -38,54 +41,54 @@ void deleteDeprecatedFinalize() { java( """ package java.awt.color; - + import java.awt.color.ICC_Profile; import java.awt.image.ColorModel; import java.awt.image.IndexColorModel; - + public class Test { public static void main(String[] args) { byte ff = (byte) 0xff; byte[] r = { ff, 0, 0, ff, 0 }; byte[] g = { 0, ff, 0, ff, 0 }; byte[] b = { 0, 0, ff, ff, 0 }; - + ICC_Profile profile = ICC_Profile.getInstance(ICC_Profile.CLASS_COLORSPACECONVERSION); // flag profile.finalize(); - + ColorModel cm = new IndexColorModel(3, 5, r, g, b); - + // flag cm.finalize(); - + IndexColorModel icm = new IndexColorModel(3, 5, r, g, b); // flag icm.finalize(); - + } } """, """ package java.awt.color; - + import java.awt.color.ICC_Profile; import java.awt.image.ColorModel; import java.awt.image.IndexColorModel; - + public class Test { public static void main(String[] args) { byte ff = (byte) 0xff; byte[] r = { ff, 0, 0, ff, 0 }; byte[] g = { 0, ff, 0, ff, 0 }; byte[] b = { 0, 0, ff, ff, 0 }; - + ICC_Profile profile = ICC_Profile.getInstance(ICC_Profile.CLASS_COLORSPACECONVERSION); - + ColorModel cm = new IndexColorModel(3, 5, r, g, b); - + IndexColorModel icm = new IndexColorModel(3, 5, r, g, b); - + } } """ diff --git a/src/test/java/org/openrewrite/java/migrate/util/SequencedCollectionTest.java b/src/test/java/org/openrewrite/java/migrate/util/SequencedCollectionTest.java index abc1d38cd8..8ab83ef905 100644 --- a/src/test/java/org/openrewrite/java/migrate/util/SequencedCollectionTest.java +++ b/src/test/java/org/openrewrite/java/migrate/util/SequencedCollectionTest.java @@ -17,18 +17,15 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; -import org.junit.jupiter.api.condition.JRE; import org.openrewrite.Issue; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; import static org.openrewrite.java.Assertions.java; - @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/243") -@EnabledForJreRange(min = JRE.JAVA_21) class SequencedCollectionTest implements RewriteTest { + @Override public void defaults(RecipeSpec spec) { spec.recipeFromResource("/META-INF/rewrite/java-version-21.yml", "org.openrewrite.java.migrate.util.SequencedCollection"); @@ -42,8 +39,8 @@ void firstToGetFirst() { //language=java java( """ - import java.util.*; - + import java.util.SortedSet; + class Foo { void bar(SortedSet collection) { String first = collection.first(); @@ -53,7 +50,7 @@ void bar(SortedSet collection) { """, """ import java.util.*; - + class Foo { void bar(SortedSet collection) { String first = collection.getFirst(); @@ -75,7 +72,7 @@ void descendingSetToReversed() { java( """ import java.util.*; - + class Foo { void bar(NavigableSet collection) { NavigableSet reversed = collection.descendingSet(); @@ -84,7 +81,7 @@ void bar(NavigableSet collection) { """, """ import java.util.*; - + class Foo { void bar(NavigableSet collection) { NavigableSet reversed = collection.reversed(); From 9a066b663495f2159b61cf5ec85669a1cf26a4cf Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Fri, 1 Nov 2024 18:53:19 +0100 Subject: [PATCH 2/2] Restore original import --- .../openrewrite/java/migrate/util/SequencedCollectionTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/openrewrite/java/migrate/util/SequencedCollectionTest.java b/src/test/java/org/openrewrite/java/migrate/util/SequencedCollectionTest.java index 8ab83ef905..98672d2a71 100644 --- a/src/test/java/org/openrewrite/java/migrate/util/SequencedCollectionTest.java +++ b/src/test/java/org/openrewrite/java/migrate/util/SequencedCollectionTest.java @@ -39,7 +39,7 @@ void firstToGetFirst() { //language=java java( """ - import java.util.SortedSet; + import java.util.*; class Foo { void bar(SortedSet collection) {