diff --git a/build.gradle.kts b/build.gradle.kts index fb0e89dd79..173ac4a65a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -103,6 +103,7 @@ dependencies { testRuntimeOnly("javax.mail:mail:1.4.7") testRuntimeOnly("javax.mail:javax.mail-api:1.6.2") testRuntimeOnly("javax.ws.rs:javax.ws.rs-api:2.1.1") + testRuntimeOnly("org.bouncycastle:bcprov-jdk15on:1.70") testRuntimeOnly(gradleApi()) } diff --git a/src/main/resources/META-INF/rewrite/bouncycastle-jdk15to18.yml b/src/main/resources/META-INF/rewrite/bouncycastle-jdk15to18.yml index e8a0854637..e643aaf5ce 100644 --- a/src/main/resources/META-INF/rewrite/bouncycastle-jdk15to18.yml +++ b/src/main/resources/META-INF/rewrite/bouncycastle-jdk15to18.yml @@ -17,21 +17,29 @@ --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.BouncyCastleFromJdk15OnToJdk15to18 -displayName: Migrate Bouncy Castle from `jdk15on` to `jdk15to18` for Java < 8 +displayName: Migrate Bouncy Castle to `jdk15to18` for Java < 8 description: >- - This recipe replaces the Bouncy Castle artifacts from `jdk15on` to `jdk15to18`. - `jdk15on` isn't maintained anymore and `jdk18on` is only for Java 8 and above. - The `jdk15to18` artifact is the up-to-date replacement of the unmaintained `jdk15on` for Java < 8. + This recipe replaces the Bouncy Castle artifacts from any of the legacy artifact suffixes + `-jdk12`, `-jdk14`, `-jdk15`, `-jdk15+`, `-jdk16` or `-jdk15on` to `-jdk15to18`. + Those artifacts aren't maintained anymore and `jdk18on` is only for Java 8 and above. + The `jdk15to18` artifact is the up-to-date replacement for Java < 8. + The `bctsp` artifacts map onto `bcpkix`, which absorbed the time stamp protocol support in 1.47. tags: - bouncycastle preconditions: - org.openrewrite.Singleton recipeList: + # -jdk15on migration - org.openrewrite.java.dependencies.ChangeDependency: oldGroupId: org.bouncycastle oldArtifactId: bcprov-jdk15on newArtifactId: bcprov-jdk15to18 newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-ext-jdk15on + newArtifactId: bcprov-ext-jdk15to18 + newVersion: latest.release - org.openrewrite.java.dependencies.ChangeDependency: oldGroupId: org.bouncycastle oldArtifactId: bcutil-jdk15on @@ -62,3 +70,140 @@ recipeList: oldArtifactId: bctls-jdk15on newArtifactId: bctls-jdk15to18 newVersion: latest.release + + # -jdk16 migration + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-jdk16 + newArtifactId: bcprov-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-ext-jdk16 + newArtifactId: bcprov-ext-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcmail-jdk16 + newArtifactId: bcmail-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcpg-jdk16 + newArtifactId: bcpg-jdk15to18 + newVersion: latest.release + + # -jdk15+ migration + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-jdk15+ + newArtifactId: bcprov-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcmail-jdk15+ + newArtifactId: bcmail-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcpg-jdk15+ + newArtifactId: bcpg-jdk15to18 + newVersion: latest.release + + # -jdk15 migration + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-jdk15 + newArtifactId: bcprov-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-ext-jdk15 + newArtifactId: bcprov-ext-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcmail-jdk15 + newArtifactId: bcmail-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcpg-jdk15 + newArtifactId: bcpg-jdk15to18 + newVersion: latest.release + + # -jdk14 migration + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-jdk14 + newArtifactId: bcprov-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-ext-jdk14 + newArtifactId: bcprov-ext-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcutil-jdk14 + newArtifactId: bcutil-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcpkix-jdk14 + newArtifactId: bcpkix-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcmail-jdk14 + newArtifactId: bcmail-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcpg-jdk14 + newArtifactId: bcpg-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bctls-jdk14 + newArtifactId: bctls-jdk15to18 + newVersion: latest.release + + # -jdk12 migration + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-jdk12 + newArtifactId: bcprov-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcpg-jdk12 + newArtifactId: bcpg-jdk15to18 + newVersion: latest.release + + # bctsp migration; folded into bcpkix in 1.47 + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bctsp-jdk15on + newArtifactId: bcpkix-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bctsp-jdk16 + newArtifactId: bcpkix-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bctsp-jdk15+ + newArtifactId: bcpkix-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bctsp-jdk15 + newArtifactId: bcpkix-jdk15to18 + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bctsp-jdk14 + newArtifactId: bcpkix-jdk15to18 + newVersion: latest.release diff --git a/src/main/resources/META-INF/rewrite/bouncycastle-jdk18on.yml b/src/main/resources/META-INF/rewrite/bouncycastle-jdk18on.yml index 6658daf1e7..5287403664 100644 --- a/src/main/resources/META-INF/rewrite/bouncycastle-jdk18on.yml +++ b/src/main/resources/META-INF/rewrite/bouncycastle-jdk18on.yml @@ -19,18 +19,28 @@ type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On displayName: Migrate Bouncy Castle to `jdk18on` description: >- - This recipe will upgrade Bouncy Castle dependencies from `-jdk15on` or `-jdk15to18` to `-jdk18on`. + This recipe will upgrade Bouncy Castle dependencies from any of the legacy artifact suffixes + `-jdk12`, `-jdk14`, `-jdk15`, `-jdk15+`, `-jdk16`, `-jdk15on` or `-jdk15to18` to `-jdk18on`. + The `bctsp` artifacts map onto `bcpkix`, which absorbed the time stamp protocol support in 1.47. tags: - bouncycastle preconditions: - org.openrewrite.Singleton recipeList: + - org.openrewrite.java.migrate.BouncyCastleDerStringGetInstanceReturnType + - org.openrewrite.java.migrate.BouncyCastleSphincsPlusToPqcLegacy + # -jdk15on migration - org.openrewrite.java.dependencies.ChangeDependency: oldGroupId: org.bouncycastle oldArtifactId: bcprov-jdk15on newArtifactId: bcprov-jdk18on newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-ext-jdk15on + newArtifactId: bcprov-ext-jdk18on + newVersion: latest.release - org.openrewrite.java.dependencies.ChangeDependency: oldGroupId: org.bouncycastle oldArtifactId: bcutil-jdk15on @@ -68,6 +78,11 @@ recipeList: oldArtifactId: bcprov-jdk15to18 newArtifactId: bcprov-jdk18on newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-ext-jdk15to18 + newArtifactId: bcprov-ext-jdk18on + newVersion: latest.release - org.openrewrite.java.dependencies.ChangeDependency: oldGroupId: org.bouncycastle oldArtifactId: bcutil-jdk15to18 @@ -98,3 +113,206 @@ recipeList: oldArtifactId: bctls-jdk15to18 newArtifactId: bctls-jdk18on newVersion: latest.release + + # -jdk16 migration + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-jdk16 + newArtifactId: bcprov-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-ext-jdk16 + newArtifactId: bcprov-ext-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcmail-jdk16 + newArtifactId: bcmail-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcpg-jdk16 + newArtifactId: bcpg-jdk18on + newVersion: latest.release + + # -jdk15+ migration + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-jdk15+ + newArtifactId: bcprov-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcmail-jdk15+ + newArtifactId: bcmail-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcpg-jdk15+ + newArtifactId: bcpg-jdk18on + newVersion: latest.release + + # -jdk15 migration + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-jdk15 + newArtifactId: bcprov-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-ext-jdk15 + newArtifactId: bcprov-ext-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcmail-jdk15 + newArtifactId: bcmail-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcpg-jdk15 + newArtifactId: bcpg-jdk18on + newVersion: latest.release + + # -jdk14 migration + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-jdk14 + newArtifactId: bcprov-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-ext-jdk14 + newArtifactId: bcprov-ext-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcutil-jdk14 + newArtifactId: bcutil-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcpkix-jdk14 + newArtifactId: bcpkix-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcmail-jdk14 + newArtifactId: bcmail-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcpg-jdk14 + newArtifactId: bcpg-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bctls-jdk14 + newArtifactId: bctls-jdk18on + newVersion: latest.release + + # -jdk12 migration + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcprov-jdk12 + newArtifactId: bcprov-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bcpg-jdk12 + newArtifactId: bcpg-jdk18on + newVersion: latest.release + + # bctsp migration; folded into bcpkix in 1.47 + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bctsp-jdk15on + newArtifactId: bcpkix-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bctsp-jdk16 + newArtifactId: bcpkix-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bctsp-jdk15+ + newArtifactId: bcpkix-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bctsp-jdk15 + newArtifactId: bcpkix-jdk18on + newVersion: latest.release + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.bouncycastle + oldArtifactId: bctsp-jdk14 + newArtifactId: bcpkix-jdk18on + newVersion: latest.release + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.migrate.BouncyCastleDerStringGetInstanceReturnType +displayName: Use `ASN1*String` for the result of `DER*String.getInstance(..)` +description: >- + In Bouncy Castle 1.71 the `getInstance(..)` methods on the `DER*String` ASN.1 types were pulled up to their + `ASN1*String` supertypes, widening their return type. The call itself still compiles, as static methods are + inherited, but assigning the result to a `DER*String` variable or field no longer does. This recipe widens + those declared types to the matching `ASN1*String`, which compiles against both the `-jdk15on` and `-jdk18on` + artifacts, and can therefore safely be applied ahead of the upgrade. +tags: + - bouncycastle +recipeList: + - org.openrewrite.java.ChangeMethodInvocationReturnType: + methodPattern: org.bouncycastle.asn1.DERBMPString getInstance(..) + newReturnType: org.bouncycastle.asn1.ASN1BMPString + - org.openrewrite.java.ChangeMethodInvocationReturnType: + methodPattern: org.bouncycastle.asn1.DERBitString getInstance(..) + newReturnType: org.bouncycastle.asn1.ASN1BitString + - org.openrewrite.java.ChangeMethodInvocationReturnType: + methodPattern: org.bouncycastle.asn1.DERGeneralString getInstance(..) + newReturnType: org.bouncycastle.asn1.ASN1GeneralString + - org.openrewrite.java.ChangeMethodInvocationReturnType: + methodPattern: org.bouncycastle.asn1.DERGraphicString getInstance(..) + newReturnType: org.bouncycastle.asn1.ASN1GraphicString + - org.openrewrite.java.ChangeMethodInvocationReturnType: + methodPattern: org.bouncycastle.asn1.DERIA5String getInstance(..) + newReturnType: org.bouncycastle.asn1.ASN1IA5String + - org.openrewrite.java.ChangeMethodInvocationReturnType: + methodPattern: org.bouncycastle.asn1.DERNumericString getInstance(..) + newReturnType: org.bouncycastle.asn1.ASN1NumericString + - org.openrewrite.java.ChangeMethodInvocationReturnType: + methodPattern: org.bouncycastle.asn1.DERPrintableString getInstance(..) + newReturnType: org.bouncycastle.asn1.ASN1PrintableString + - org.openrewrite.java.ChangeMethodInvocationReturnType: + methodPattern: org.bouncycastle.asn1.DERT61String getInstance(..) + newReturnType: org.bouncycastle.asn1.ASN1T61String + - org.openrewrite.java.ChangeMethodInvocationReturnType: + methodPattern: org.bouncycastle.asn1.DERUTF8String getInstance(..) + newReturnType: org.bouncycastle.asn1.ASN1UTF8String + - org.openrewrite.java.ChangeMethodInvocationReturnType: + methodPattern: org.bouncycastle.asn1.DERUniversalString getInstance(..) + newReturnType: org.bouncycastle.asn1.ASN1UniversalString + - org.openrewrite.java.ChangeMethodInvocationReturnType: + methodPattern: org.bouncycastle.asn1.DERVideotexString getInstance(..) + newReturnType: org.bouncycastle.asn1.ASN1VideotexString + - org.openrewrite.java.ChangeMethodInvocationReturnType: + methodPattern: org.bouncycastle.asn1.DERVisibleString getInstance(..) + newReturnType: org.bouncycastle.asn1.ASN1VisibleString + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.migrate.BouncyCastleSphincsPlusToPqcLegacy +displayName: Move Bouncy Castle SPHINCS+ classes to `pqc.legacy` +description: >- + Bouncy Castle 1.78 moved the pre-standardization SPHINCS+ implementation from + `org.bouncycastle.pqc.crypto.sphincsplus` to `org.bouncycastle.pqc.legacy.sphincsplus`, to free up the original + package for the FIPS 205 SLH-DSA implementation. All types moved unchanged, so this is a straight package rename. +tags: + - bouncycastle +recipeList: + - org.openrewrite.java.ChangePackage: + oldPackageName: org.bouncycastle.pqc.crypto.sphincsplus + newPackageName: org.bouncycastle.pqc.legacy.sphincsplus + recursive: false diff --git a/src/main/resources/META-INF/rewrite/recipes.csv b/src/main/resources/META-INF/rewrite/recipes.csv index e51cb061b2..12a82bd4a4 100644 --- a/src/main/resources/META-INF/rewrite/recipes.csv +++ b/src/main/resources/META-INF/rewrite/recipes.csv @@ -21,8 +21,10 @@ maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.A maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.ArrayStoreExceptionToTypeNotPresentException,Catch `TypeNotPresentException` thrown by `Class.getAnnotation()`,Replace catch blocks for `ArrayStoreException` around `Class.getAnnotation()` with `TypeNotPresentException` to ensure compatibility with Java 11+.,1,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.BeanDiscovery,Behavior change to bean discovery in modules with `beans.xml` file with no version specified,Alters beans with missing version attribute to include this attribute as well as the bean-discovery-mode="all" attribute to maintain an explicit bean archive.,1,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.BeansXmlNamespace,Change `beans.xml` `schemaLocation` to match XML namespace,Set the `schemaLocation` that corresponds to the `xmlns` set in `beans.xml` files.,1,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On,Migrate Bouncy Castle to `jdk18on`,This recipe will upgrade Bouncy Castle dependencies from `-jdk15on` or `-jdk15to18` to `-jdk18on`.,15,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.BouncyCastleFromJdk15OnToJdk15to18,Migrate Bouncy Castle from `jdk15on` to `jdk15to18` for Java < 8,This recipe replaces the Bouncy Castle artifacts from `jdk15on` to `jdk15to18`. `jdk15on` isn't maintained anymore and `jdk18on` is only for Java 8 and above. The `jdk15to18` artifact is the up-to-date replacement of the unmaintained `jdk15on` for Java < 8.,8,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On,Migrate Bouncy Castle to `jdk18on`,"This recipe will upgrade Bouncy Castle dependencies from any of the legacy artifact suffixes `-jdk12`, `-jdk14`, `-jdk15`, `-jdk15+`, `-jdk16`, `-jdk15on` or `-jdk15to18` to `-jdk18on`. The `bctsp` artifacts map onto `bcpkix`, which absorbed the time stamp protocol support in 1.47.",57,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.BouncyCastleDerStringGetInstanceReturnType,Use `ASN1*String` for the result of `DER*String.getInstance(..)`,"In Bouncy Castle 1.71 the `getInstance(..)` methods on the `DER*String` ASN.1 types were pulled up to their `ASN1*String` supertypes, widening their return type. The call itself still compiles, as static methods are inherited, but assigning the result to a `DER*String` variable or field no longer does. This recipe widens those declared types to the matching `ASN1*String`, which compiles against both the `-jdk15on` and `-jdk18on` artifacts, and can therefore safely be applied ahead of the upgrade.",13,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.BouncyCastleFromJdk15OnToJdk15to18,Migrate Bouncy Castle to `jdk15to18` for Java < 8,"This recipe replaces the Bouncy Castle artifacts from any of the legacy artifact suffixes `-jdk12`, `-jdk14`, `-jdk15`, `-jdk15+`, `-jdk16` or `-jdk15on` to `-jdk15to18`. Those artifacts aren't maintained anymore and `jdk18on` is only for Java 8 and above. The `jdk15to18` artifact is the up-to-date replacement for Java < 8. The `bctsp` artifacts map onto `bcpkix`, which absorbed the time stamp protocol support in 1.47.",34,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.BouncyCastleSphincsPlusToPqcLegacy,Move Bouncy Castle SPHINCS+ classes to `pqc.legacy`,"Bouncy Castle 1.78 moved the pre-standardization SPHINCS+ implementation from `org.bouncycastle.pqc.crypto.sphincsplus` to `org.bouncycastle.pqc.legacy.sphincsplus`, to free up the original package for the FIPS 205 SLH-DSA implementation. All types moved unchanged, so this is a straight package rename.",2,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.CastArraysAsListToList,Remove explicit casts on `Arrays.asList(..).toArray()`,"Convert code like `(Integer[]) Arrays.asList(1, 2, 3).toArray()` to `Arrays.asList(1, 2, 3).toArray(new Integer[0])`.",1,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.ChangeDefaultKeyStore,Return String `jks` when `KeyStore.getDefaultType()` is called,"In Java 11 the default keystore was updated from JKS to PKCS12. As a result, applications relying on KeyStore.getDefaultType() may encounter issues after migrating, unless their JKS keystore has been converted to PKCS12. This recipe returns default key store of `jks` when `KeyStore.getDefaultType()` method is called to use the pre Java 11 default keystore.",1,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.ChangeMethodInvocationReturnType,Change method invocation return type,Changes the return type of a method invocation.,2,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,"[{""name"":""methodPattern"",""type"":""String"",""displayName"":""Method pattern"",""description"":""A method pattern that is used to find matching method declarations/invocations."",""example"":""org.mockito.Matchers anyVararg()"",""required"":true},{""name"":""newReturnType"",""type"":""String"",""displayName"":""New method invocation return type"",""description"":""The fully qualified new return type of method invocation."",""example"":""long"",""required"":true}]", @@ -48,8 +50,8 @@ maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.J maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.JREJdbcInterfaceNewMethods,Adds missing JDBC interface methods,Add method implementations stubs to classes that implement JDBC interfaces.,10,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.JREThrowableFinalMethods,Rename final method declarations `getSuppressed()` and `addSuppressed(Throwable exception)` in classes that extend `Throwable`,The recipe renames `getSuppressed()` and `addSuppressed(Throwable exception)` methods in classes that extend `java.lang.Throwable` to `myGetSuppressed` and `myAddSuppressed(Throwable)`. These methods were added to Throwable in Java 7 and are marked final which cannot be overridden.,1,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.JREWrapperInterface,Add missing `isWrapperFor` and `unwrap` methods,Add method implementations stubs to classes that implement `java.sql.Wrapper`.,3,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.Java8toJava11,Migrate to Java 11,"This recipe will apply changes commonly needed when upgrading to Java 11. Specifically, for those applications that are built on Java 8, this recipe will update and add dependencies on J2EE libraries that are no longer directly bundled with the JDK. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy. Build files will also be updated to use Java 11 as the target/source and plugins will be also be upgraded to versions that are compatible with Java 11.",256,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.JavaBestPractices,Java best practices,"Applies opinionated best practices for Java projects targeting Java 25. This recipe includes the full Java 25 upgrade chain plus additional improvements to code style, API usage, and third-party dependency reduction that go beyond what the version migration recipes apply.",1687,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.Java8toJava11,Migrate to Java 11,"This recipe will apply changes commonly needed when upgrading to Java 11. Specifically, for those applications that are built on Java 8, this recipe will update and add dependencies on J2EE libraries that are no longer directly bundled with the JDK. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy. Build files will also be updated to use Java 11 as the target/source and plugins will be also be upgraded to versions that are compatible with Java 11.",324,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.JavaBestPractices,Java best practices,"Applies opinionated best practices for Java projects targeting Java 25. This recipe includes the full Java 25 upgrade chain plus additional improvements to code style, API usage, and third-party dependency reduction that go beyond what the version migration recipes apply.",1755,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.JpaCacheProperties,Disable the persistence unit second-level cache,Sets an explicit value for the shared cache mode.,1,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.Jre17AgentMainPreMainPublic,Set visibility of `premain` and `agentmain` methods to `public`,Check for a behavior change in Java agents.,5,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.Krb5LoginModuleClass,Use `com.sun.security.auth.module.Krb5LoginModule` instead of `com.ibm.security.auth.module.Krb5LoginModule`,Do not use the `com.ibm.security.auth.module.Krb5LoginModule` class.,2,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,, @@ -97,12 +99,12 @@ maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.U maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UpgradePluginsForJava17,Upgrade plugins to Java 17 compatible versions,Updates plugins to version compatible with Java 17.,8,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UpgradePluginsForJava21,Upgrade plugins to Java 21 compatible versions,Updates plugins and dependencies to version compatible with Java 21.,6,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UpgradePluginsForJava25,Upgrade plugins to Java 25 compatible versions,Updates plugins and dependencies to versions compatible with Java 25.,10,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UpgradeToJava17,Migrate to Java 17,"This recipe will apply changes commonly needed when migrating to Java 17. Specifically, for those applications that are built on Java 8, this recipe will update and add dependencies on J2EE libraries that are no longer directly bundled with the JDK. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy. Build files will also be updated to use Java 17 as the target/source and plugins will be also be upgraded to versions that are compatible with Java 17.",418,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UpgradeToJava21,Migrate to Java 21,This recipe will apply changes commonly needed when migrating to Java 21. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy. Build files will also be updated to use Java 21 as the target/source and plugins will be also be upgraded to versions that are compatible with Java 21.,594,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UpgradeToJava25,Migrate to Java 25,This recipe will apply changes commonly needed when migrating to Java 25. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy. Build files will also be updated to use Java 25 as the target/source and plugins will be also be upgraded to versions that are compatible with Java 25.,1330,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UpgradeToJava17,Migrate to Java 17,"This recipe will apply changes commonly needed when migrating to Java 17. Specifically, for those applications that are built on Java 8, this recipe will update and add dependencies on J2EE libraries that are no longer directly bundled with the JDK. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy. Build files will also be updated to use Java 17 as the target/source and plugins will be also be upgraded to versions that are compatible with Java 17.",486,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UpgradeToJava21,Migrate to Java 21,This recipe will apply changes commonly needed when migrating to Java 21. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy. Build files will also be updated to use Java 21 as the target/source and plugins will be also be upgraded to versions that are compatible with Java 21.,662,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UpgradeToJava25,Migrate to Java 25,This recipe will apply changes commonly needed when migrating to Java 25. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy. Build files will also be updated to use Java 25 as the target/source and plugins will be also be upgraded to versions that are compatible with Java 25.,1398,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UpgradeToJava6,Migrate to Java 6,This recipe will apply changes commonly needed when upgrading to Java 6. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy.,7,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UpgradeToJava7,Migrate to Java 7,This recipe will apply changes commonly needed when upgrading to Java 7. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy.,28,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" -maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UpgradeToJava8,Migrate to Java 8,This recipe will apply changes commonly needed when upgrading to Java 8. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy.,54,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UpgradeToJava7,Migrate to Java 7,This recipe will apply changes commonly needed when upgrading to Java 7. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy.,54,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" +maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UpgradeToJava8,Migrate to Java 8,This recipe will apply changes commonly needed when upgrading to Java 8. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy.,122,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UseJavaUtilBase64,Prefer `java.util.Base64` instead of `sun.misc`,Prefer `java.util.Base64` instead of using `sun.misc` in Java 8 or higher. `sun.misc` is not exported by the Java module system and accessing this class will result in a warning in Java 11 and an error in Java 17.,1,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,"[{""name"":""useMimeCoder"",""type"":""boolean"",""displayName"":""Use Mime Coder"",""description"":""Use `Base64.getMimeEncoder()/getMimeDecoder()` instead of `Base64.getEncoder()/getDecoder()`."",""example"":""false"",""value"":false}]", maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.UseTabsOrSpaces,Force indentation to either tabs or spaces,"This is useful for one-off migrations of a codebase that has mixed indentation styles, while preserving all other auto-detected formatting rules.",1,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,"[{""name"":""useTabs"",""type"":""boolean"",""displayName"":""Use tabs"",""description"":""Whether to use tabs for indentation."",""required"":true,""value"":false}]", maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.WasDevMvnChangeParentArtifactId,Change `net.wasdev.maven.parent:java8-parent` to `:parent`,This recipe changes the artifactId of the `` tag in the `pom.xml` from `java8-parent` to `parent`.,2,,,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]" diff --git a/src/test/java/org/openrewrite/java/migrate/BouncyCastleApiTest.java b/src/test/java/org/openrewrite/java/migrate/BouncyCastleApiTest.java new file mode 100644 index 0000000000..8b93903f82 --- /dev/null +++ b/src/test/java/org/openrewrite/java/migrate/BouncyCastleApiTest.java @@ -0,0 +1,200 @@ +/* + * Copyright 2026 the original author or authors. + *

+ * Licensed under the Moderne Source Available License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://docs.moderne.io/licensing/moderne-source-available-license + *

+ * 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.java.JavaParser; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.java.Assertions.java; + +class BouncyCastleApiTest implements RewriteTest { + + @Override + public void defaults(RecipeSpec spec) { + spec.parser(JavaParser.fromJavaVersion().classpath("bcprov-jdk15on")); + } + + private static RecipeSpec derStringRecipe(RecipeSpec spec) { + return spec.recipeFromResource( + "/META-INF/rewrite/bouncycastle-jdk18on.yml", + "org.openrewrite.java.migrate.BouncyCastleDerStringGetInstanceReturnType"); + } + + @DocumentExample + @Test + void widenLocalVariableToAsn1String() { + rewriteRun( + BouncyCastleApiTest::derStringRecipe, + //language=java + java( + """ + import org.bouncycastle.asn1.DERIA5String; + + class A { + String extract(Object o) { + DERIA5String value = DERIA5String.getInstance(o); + return value.getString(); + } + } + """, + """ + import org.bouncycastle.asn1.ASN1IA5String; + import org.bouncycastle.asn1.DERIA5String; + + class A { + String extract(Object o) { + ASN1IA5String value = DERIA5String.getInstance(o); + return value.getString(); + } + } + """ + ) + ); + } + + @Test + void widenField() { + rewriteRun( + BouncyCastleApiTest::derStringRecipe, + //language=java + java( + """ + import org.bouncycastle.asn1.DERPrintableString; + + class A { + private final DERPrintableString name = DERPrintableString.getInstance(new byte[0]); + } + """, + """ + import org.bouncycastle.asn1.ASN1PrintableString; + import org.bouncycastle.asn1.DERPrintableString; + + class A { + private final ASN1PrintableString name = DERPrintableString.getInstance(new byte[0]); + } + """ + ) + ); + } + + @Test + void widenTaggedObjectOverload() { + rewriteRun( + BouncyCastleApiTest::derStringRecipe, + //language=java + java( + """ + import org.bouncycastle.asn1.ASN1TaggedObject; + import org.bouncycastle.asn1.DERUTF8String; + + class A { + DERUTF8String extract(ASN1TaggedObject tagged) { + DERUTF8String value = DERUTF8String.getInstance(tagged, true); + return value; + } + } + """, + """ + import org.bouncycastle.asn1.ASN1TaggedObject; + import org.bouncycastle.asn1.ASN1UTF8String; + import org.bouncycastle.asn1.DERUTF8String; + + class A { + DERUTF8String extract(ASN1TaggedObject tagged) { + ASN1UTF8String value = DERUTF8String.getInstance(tagged, true); + return value; + } + } + """ + ) + ); + } + + @Test + void doesNotTouchConstructorsBecauseAsn1TypesAreAbstract() { + rewriteRun( + BouncyCastleApiTest::derStringRecipe, + //language=java + java( + """ + import org.bouncycastle.asn1.DERIA5String; + + class A { + DERIA5String create(String value) { + return new DERIA5String(value); + } + } + """ + ) + ); + } + + @Test + void alreadyDeclaredAsAsn1String() { + rewriteRun( + // The upstream recipe re-attributes the invocation type on every match, so a cycle is consumed + // even though the printed source is unchanged. + spec -> derStringRecipe(spec).expectedCyclesThatMakeChanges(1), + //language=java + java( + """ + import org.bouncycastle.asn1.ASN1IA5String; + import org.bouncycastle.asn1.DERIA5String; + + class A { + String extract(Object o) { + ASN1IA5String value = DERIA5String.getInstance(o); + return value.getString(); + } + } + """ + ) + ); + } + + @Test + void sphincsPlusMovedToPqcLegacy() { + rewriteRun( + spec -> spec.recipeFromResource( + "/META-INF/rewrite/bouncycastle-jdk18on.yml", + "org.openrewrite.java.migrate.BouncyCastleSphincsPlusToPqcLegacy"), + //language=java + java( + """ + import org.bouncycastle.pqc.crypto.sphincsplus.SPHINCSPlusParameters; + import org.bouncycastle.pqc.crypto.sphincsplus.SPHINCSPlusSigner; + + class A { + SPHINCSPlusSigner signer = new SPHINCSPlusSigner(); + SPHINCSPlusParameters parameters = SPHINCSPlusParameters.sha2_128f; + } + """, + """ + import org.bouncycastle.pqc.legacy.sphincsplus.SPHINCSPlusParameters; + import org.bouncycastle.pqc.legacy.sphincsplus.SPHINCSPlusSigner; + + class A { + SPHINCSPlusSigner signer = new SPHINCSPlusSigner(); + SPHINCSPlusParameters parameters = SPHINCSPlusParameters.sha2_128f; + } + """ + ) + ); + } +} diff --git a/src/test/java/org/openrewrite/java/migrate/BouncyCastleTest.java b/src/test/java/org/openrewrite/java/migrate/BouncyCastleTest.java index 500863b13f..002c6aef90 100644 --- a/src/test/java/org/openrewrite/java/migrate/BouncyCastleTest.java +++ b/src/test/java/org/openrewrite/java/migrate/BouncyCastleTest.java @@ -17,14 +17,12 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; import org.openrewrite.DocumentExample; import org.openrewrite.maven.tree.MavenResolutionResult; import org.openrewrite.maven.tree.Scope; import org.openrewrite.test.RewriteTest; -import java.util.List; - import static java.util.function.UnaryOperator.identity; import static org.assertj.core.api.Assertions.assertThat; import static org.openrewrite.java.Assertions.mavenProject; @@ -32,10 +30,6 @@ class BouncyCastleTest implements RewriteTest { - static List artifactBaseNames() { - return List.of("bcprov", "bcutil", "bcpkix", "bcmail", "bcjmail", "bcpg", "bctls"); - } - @DocumentExample @Test void document() { @@ -85,7 +79,7 @@ void document() { ); } - @MethodSource("artifactBaseNames") + @ValueSource(strings = {"bcprov", "bcprov-ext", "bcutil", "bcpkix", "bcmail", "bcjmail", "bcpg", "bctls"}) @ParameterizedTest void jdk15onToJdk18on(String artifactBaseName) { runBouncyCastleArtifactUpgradeRecipe( @@ -93,11 +87,12 @@ void jdk15onToJdk18on(String artifactBaseName) { "org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On", artifactBaseName, "jdk15on", + "1.70", "jdk18on" ); } - @MethodSource("artifactBaseNames") + @ValueSource(strings = {"bcprov", "bcprov-ext", "bcutil", "bcpkix", "bcmail", "bcjmail", "bcpg", "bctls"}) @ParameterizedTest void jdk15to18ToJdk18on(String artifactBaseName) { runBouncyCastleArtifactUpgradeRecipe( @@ -105,11 +100,77 @@ void jdk15to18ToJdk18on(String artifactBaseName) { "org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On", artifactBaseName, "jdk15to18", + "1.70", + "jdk18on" + ); + } + + @ValueSource(strings = {"bcprov", "bcprov-ext", "bcutil", "bcpkix", "bcmail", "bcpg", "bctls"}) + @ParameterizedTest + void jdk14ToJdk18on(String artifactBaseName) { + runBouncyCastleArtifactUpgradeRecipe( + "/META-INF/rewrite/bouncycastle-jdk18on.yml", + "org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On", + artifactBaseName, + "jdk14", + "1.70", + "jdk18on" + ); + } + + @ValueSource(strings = {"bcprov", "bcprov-ext", "bcmail", "bcpg"}) + @ParameterizedTest + void jdk15ToJdk18on(String artifactBaseName) { + runBouncyCastleArtifactUpgradeRecipe( + "/META-INF/rewrite/bouncycastle-jdk18on.yml", + "org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On", + artifactBaseName, + "jdk15", + "1.46", "jdk18on" ); } - @MethodSource("artifactBaseNames") + @ValueSource(strings = {"bcprov", "bcmail", "bcpg"}) + @ParameterizedTest + void jdk15PlusToJdk18on(String artifactBaseName) { + runBouncyCastleArtifactUpgradeRecipe( + "/META-INF/rewrite/bouncycastle-jdk18on.yml", + "org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On", + artifactBaseName, + "jdk15+", + "1.46", + "jdk18on" + ); + } + + @ValueSource(strings = {"bcprov", "bcprov-ext", "bcmail", "bcpg"}) + @ParameterizedTest + void jdk16ToJdk18on(String artifactBaseName) { + runBouncyCastleArtifactUpgradeRecipe( + "/META-INF/rewrite/bouncycastle-jdk18on.yml", + "org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On", + artifactBaseName, + "jdk16", + "1.46", + "jdk18on" + ); + } + + @ValueSource(strings = {"bcprov", "bcpg"}) + @ParameterizedTest + void jdk12ToJdk18on(String artifactBaseName) { + runBouncyCastleArtifactUpgradeRecipe( + "/META-INF/rewrite/bouncycastle-jdk18on.yml", + "org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On", + artifactBaseName, + "jdk12", + "130", + "jdk18on" + ); + } + + @ValueSource(strings = {"bcprov", "bcprov-ext", "bcutil", "bcpkix", "bcmail", "bcjmail", "bcpg", "bctls"}) @ParameterizedTest void jdk15onToJdk15To18(String artifactBaseName) { runBouncyCastleArtifactUpgradeRecipe( @@ -117,16 +178,169 @@ void jdk15onToJdk15To18(String artifactBaseName) { "org.openrewrite.java.migrate.BouncyCastleFromJdk15OnToJdk15to18", artifactBaseName, "jdk15on", + "1.70", + "jdk15to18" + ); + } + + @ValueSource(strings = {"bcprov", "bcprov-ext", "bcutil", "bcpkix", "bcmail", "bcpg", "bctls"}) + @ParameterizedTest + void jdk14ToJdk15to18(String artifactBaseName) { + runBouncyCastleArtifactUpgradeRecipe( + "/META-INF/rewrite/bouncycastle-jdk15to18.yml", + "org.openrewrite.java.migrate.BouncyCastleFromJdk15OnToJdk15to18", + artifactBaseName, + "jdk14", + "1.70", + "jdk15to18" + ); + } + + @ValueSource(strings = {"bcprov", "bcprov-ext", "bcmail", "bcpg"}) + @ParameterizedTest + void jdk15ToJdk15to18(String artifactBaseName) { + runBouncyCastleArtifactUpgradeRecipe( + "/META-INF/rewrite/bouncycastle-jdk15to18.yml", + "org.openrewrite.java.migrate.BouncyCastleFromJdk15OnToJdk15to18", + artifactBaseName, + "jdk15", + "1.46", + "jdk15to18" + ); + } + + @ValueSource(strings = {"bcprov", "bcmail", "bcpg"}) + @ParameterizedTest + void jdk15PlusToJdk15to18(String artifactBaseName) { + runBouncyCastleArtifactUpgradeRecipe( + "/META-INF/rewrite/bouncycastle-jdk15to18.yml", + "org.openrewrite.java.migrate.BouncyCastleFromJdk15OnToJdk15to18", + artifactBaseName, + "jdk15+", + "1.46", "jdk15to18" ); } + @ValueSource(strings = {"bcprov", "bcprov-ext", "bcmail", "bcpg"}) + @ParameterizedTest + void jdk16ToJdk15to18(String artifactBaseName) { + runBouncyCastleArtifactUpgradeRecipe( + "/META-INF/rewrite/bouncycastle-jdk15to18.yml", + "org.openrewrite.java.migrate.BouncyCastleFromJdk15OnToJdk15to18", + artifactBaseName, + "jdk16", + "1.46", + "jdk15to18" + ); + } + + @ValueSource(strings = {"bcprov", "bcpg"}) + @ParameterizedTest + void jdk12ToJdk15to18(String artifactBaseName) { + runBouncyCastleArtifactUpgradeRecipe( + "/META-INF/rewrite/bouncycastle-jdk15to18.yml", + "org.openrewrite.java.migrate.BouncyCastleFromJdk15OnToJdk15to18", + artifactBaseName, + "jdk12", + "130", + "jdk15to18" + ); + } + + @ValueSource(strings = {"jdk14", "jdk15", "jdk15+", "jdk15on", "jdk16"}) + @ParameterizedTest + void bctspToBcpkixJdk18on(String originalArtifactSuffix) { + runBouncyCastleDependencyChangeRecipe( + "/META-INF/rewrite/bouncycastle-jdk18on.yml", + "org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On", + "bctsp-" + originalArtifactSuffix, + "1.46", + "bcpkix-jdk18on" + ); + } + + @ValueSource(strings = {"jdk14", "jdk15", "jdk15+", "jdk15on", "jdk16"}) + @ParameterizedTest + void bctspToBcpkixJdk15to18(String originalArtifactSuffix) { + runBouncyCastleDependencyChangeRecipe( + "/META-INF/rewrite/bouncycastle-jdk15to18.yml", + "org.openrewrite.java.migrate.BouncyCastleFromJdk15OnToJdk15to18", + "bctsp-" + originalArtifactSuffix, + "1.46", + "bcpkix-jdk15to18" + ); + } + + @Test + void bctspAlongsideBcpkixCollapsesToASingleDependency() { + rewriteRun( + spec -> spec.recipeFromResource( + "/META-INF/rewrite/bouncycastle-jdk18on.yml", + "org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On"), + mavenProject("project", + //language=xml + pomXml( + """ + + 4.0.0 + com.mycompany.app + my-app + 1 + + + org.bouncycastle + bctsp-jdk15on + 1.46 + + + org.bouncycastle + bcpkix-jdk15on + 1.70 + + + + """, + spec -> spec + .after(actual -> { + assertThat(actual).containsOnlyOnce("bcpkix-jdk18on"); + return actual; + }) + .afterRecipe(doc -> assertThat(doc.getMarkers().findFirst(MavenResolutionResult.class) + .get().getDependencies().get(Scope.Compile)) + .filteredOn(rd -> rd.getDepth() == 0) + .singleElement() + .satisfies(rd -> { + assertThat(rd.getGroupId()).isEqualTo("org.bouncycastle"); + assertThat(rd.getArtifactId()).isEqualTo("bcpkix-jdk18on"); + })) + ) + ) + ); + } + void runBouncyCastleArtifactUpgradeRecipe( String yamlFile, String recipe, String baseArtifactId, String originalArtifactSuffix, + String originalVersion, String expectedArtifactSuffix) { + runBouncyCastleDependencyChangeRecipe( + yamlFile, + recipe, + "%s-%s".formatted(baseArtifactId, originalArtifactSuffix), + originalVersion, + "%s-%s".formatted(baseArtifactId, expectedArtifactSuffix) + ); + } + + void runBouncyCastleDependencyChangeRecipe( + String yamlFile, + String recipe, + String originalArtifactId, + String originalVersion, + String expectedArtifactId) { rewriteRun( recipeSpec -> recipeSpec.recipeFromResource(yamlFile, recipe), mavenProject("project", @@ -141,12 +355,12 @@ void runBouncyCastleArtifactUpgradeRecipe( org.bouncycastle - %s-%s - 1.70 + %s + %s - """.formatted(baseArtifactId, originalArtifactSuffix), + """.formatted(originalArtifactId, originalVersion), spec -> spec .after(identity()) .afterRecipe(doc -> assertThat(doc.getMarkers().findFirst(MavenResolutionResult.class) @@ -155,7 +369,7 @@ void runBouncyCastleArtifactUpgradeRecipe( .singleElement() .satisfies(rd -> { assertThat(rd.getGroupId()).isEqualTo("org.bouncycastle"); - assertThat(rd.getArtifactId()).isEqualTo("%s-%s".formatted(baseArtifactId, expectedArtifactSuffix)); + assertThat(rd.getArtifactId()).isEqualTo(expectedArtifactId); })) ) )