diff --git a/src/main/resources/META-INF/rewrite/add-inject-dependencies.yml b/src/main/resources/META-INF/rewrite/add-inject-dependencies.yml index f96dd7b963..c8e968f212 100644 --- a/src/main/resources/META-INF/rewrite/add-inject-dependencies.yml +++ b/src/main/resources/META-INF/rewrite/add-inject-dependencies.yml @@ -30,8 +30,7 @@ recipeList: groupId: jakarta.inject artifactId: jakarta.inject-api version: 1.0.3 - onlyIfUsing: - - javax.inject.* + onlyIfUsing: javax.inject.* - org.openrewrite.maven.UpgradeDependencyVersion: groupId: jakarta.inject diff --git a/src/main/resources/META-INF/rewrite/add-jaxb-dependencies.yml b/src/main/resources/META-INF/rewrite/add-jaxb-dependencies.yml index 6a25806231..d28d5ffaa3 100644 --- a/src/main/resources/META-INF/rewrite/add-jaxb-dependencies.yml +++ b/src/main/resources/META-INF/rewrite/add-jaxb-dependencies.yml @@ -26,25 +26,23 @@ tags: - glassfish recipeList: - #Add or update the jakarta.xml.bind-api to a maven project. This artifact still uses the javax.xml name space. + # Add or update the jakarta.xml.bind-api to a maven project. This artifact still uses the javax.xml name space. - org.openrewrite.maven.AddDependency: groupId: jakarta.xml.bind artifactId: jakarta.xml.bind-api version: 2.3.x - onlyIfUsing: - - javax.xml.bind.* + onlyIfUsing: javax.xml.bind.* - org.openrewrite.maven.UpgradeDependencyVersion: groupId: jakarta.xml.bind artifactId: jakarta.xml.bind-api newVersion: 2.3.x - #Add or update the jaxb-impl to a maven project. This artifact still uses the javax.xml name space. + # Add or update the jaxb-impl to a maven project. This artifact still uses the javax.xml name space. - org.openrewrite.maven.AddDependency: groupId: org.glassfish.jaxb artifactId: jaxb-runtime version: 2.3.x scope: runtime - onlyIfUsing: - - javax.xml.bind.* + onlyIfUsing: javax.xml.bind.* - org.openrewrite.maven.UpgradeDependencyVersion: groupId: org.glassfish.jaxb artifactId: jaxb-runtime diff --git a/src/main/resources/META-INF/rewrite/add-jaxws-dependencies.yml b/src/main/resources/META-INF/rewrite/add-jaxws-dependencies.yml index ca698cad46..f3e5e77ca3 100644 --- a/src/main/resources/META-INF/rewrite/add-jaxws-dependencies.yml +++ b/src/main/resources/META-INF/rewrite/add-jaxws-dependencies.yml @@ -31,8 +31,7 @@ recipeList: groupId: jakarta.xml.ws artifactId: jakarta.xml.ws-api version: 2.3.x - onlyIfUsing: - - javax.jws.* + onlyIfUsing: javax.jws.* - org.openrewrite.maven.UpgradeDependencyVersion: groupId: jakarta.xml.ws artifactId: jakarta.xml.ws-api @@ -43,8 +42,7 @@ recipeList: artifactId: jaxws-rt version: 2.3.x scope: runtime - onlyIfUsing: - - javax.jws.* + onlyIfUsing: javax.jws.* - org.openrewrite.maven.UpgradeDependencyVersion: groupId: com.sun.xml.ws artifactId: jaxws-rt diff --git a/src/main/resources/META-INF/rewrite/javax-to-jakarta.yml b/src/main/resources/META-INF/rewrite/javax-to-jakarta.yml index e6692aefed..55b5f25db4 100644 --- a/src/main/resources/META-INF/rewrite/javax-to-jakarta.yml +++ b/src/main/resources/META-INF/rewrite/javax-to-jakarta.yml @@ -49,8 +49,7 @@ recipeList: groupId: jakarta.activation artifactId: jakarta.activation-api version: 2.x - onlyIfUsing: - - javax.activation.* + onlyIfUsing: javax.activation.* # Upgrade the dependency to use the jakarta namespace if an older version already exists. - org.openrewrite.maven.UpgradeDependencyVersion: @@ -84,8 +83,7 @@ recipeList: groupId: jakarta.annotation artifactId: jakarta.annotation-api version: 2.x - onlyIfUsing: - - javax.annotation.* + onlyIfUsing: javax.annotation.* # Upgrade the dependency to use the jakarta namespace if an older version already exists. - org.openrewrite.maven.UpgradeDependencyVersion: @@ -119,8 +117,7 @@ recipeList: groupId: jakarta.batch artifactId: jakarta.batch-api version: 2.x - onlyIfUsing: - - javax.batch.* + onlyIfUsing: javax.batch.* # Upgrade the dependency to use the jakarta namespace if an older version already exists. - org.openrewrite.maven.UpgradeDependencyVersion: @@ -184,8 +181,7 @@ recipeList: groupId: jakarta.inject artifactId: jakarta.inject-api version: 2.x - onlyIfUsing: - - javax.batch.* + onlyIfUsing: javax.batch.* # Upgrade the dependency to use the jakarta namespace if an older version already exists. - org.openrewrite.maven.UpgradeDependencyVersion: @@ -219,8 +215,7 @@ recipeList: groupId: jakarta.transaction artifactId: jakarta.transaction-api version: 2.x - onlyIfUsing: - - javax.transaction.* + onlyIfUsing: javax.transaction.* # Upgrade the dependency to use the jakarta namespace if an older version already exists. - org.openrewrite.maven.UpgradeDependencyVersion: @@ -254,8 +249,7 @@ recipeList: groupId: jakarta.xml.bind artifactId: jakarta.xml.bind-api version: 3.x - onlyIfUsing: - - javax.xml.bind.* + onlyIfUsing: javax.xml.bind.* # Upgrade the dependency to use the jakarta namespace if an older version already exists. - org.openrewrite.maven.UpgradeDependencyVersion: @@ -269,8 +263,7 @@ recipeList: artifactId: jaxb-runtime version: 3.x scope: runtime - onlyIfUsing: - - javax.xml.bind.* + onlyIfUsing: javax.xml.bind.* # Upgrade the dependency to use the jakarta namespace if an older version already exists. - org.openrewrite.maven.UpgradeDependencyVersion: @@ -309,8 +302,7 @@ recipeList: groupId: jakarta.xml.ws artifactId: jakarta.xml.ws-api version: 3.x - onlyIfUsing: - - javax.xml.ws.* + onlyIfUsing: javax.xml.ws.* # Upgrade the dependency to use the jakarta namespace if an older version already exists. - org.openrewrite.maven.UpgradeDependencyVersion: @@ -324,8 +316,7 @@ recipeList: artifactId: jaxws-rt version: 3.x scope: runtime - onlyIfUsing: - - javax.xml.ws.* + onlyIfUsing: javax.xml.ws.* # Upgrade the dependency to use the jakarta namespace if an older version already exists. - org.openrewrite.maven.UpgradeDependencyVersion: diff --git a/src/test/kotlin/org/openrewrite/java/migrate/JavaxToJakartaTest.kt b/src/test/kotlin/org/openrewrite/java/migrate/JavaxToJakartaTest.kt index 15988334fc..73b25e6b65 100644 --- a/src/test/kotlin/org/openrewrite/java/migrate/JavaxToJakartaTest.kt +++ b/src/test/kotlin/org/openrewrite/java/migrate/JavaxToJakartaTest.kt @@ -15,19 +15,11 @@ */ package org.openrewrite.java.migrate -import org.assertj.core.api.Assertions import org.junit.jupiter.api.Test -import org.openrewrite.InMemoryExecutionContext -import org.openrewrite.Parser import org.openrewrite.Recipe -import org.openrewrite.SourceFile import org.openrewrite.config.Environment import org.openrewrite.java.ChangeType -import org.openrewrite.java.JavaParser import org.openrewrite.java.JavaRecipeTest -import org.openrewrite.maven.AddDependency -import org.openrewrite.maven.MavenParser -import java.util.* class JavaxToJakartaTest : JavaRecipeTest { override val recipe: Recipe = Environment.builder() @@ -308,66 +300,4 @@ class JavaxToJakartaTest : JavaRecipeTest { } """ ) - - @Test - fun onlyIfUsing() { - val recipe = AddDependency( - "jakarta.xml.bind", - "jakarta.xml.bind-api", - "3.0.0", - null, - true, - null, - null, - null, - null, - null, - listOf("jakarta.xml.bind.*") - ) - val javaSource = JavaParser.fromJavaVersion() - .dependsOn(Collections.singletonList(Parser.Input.fromString( - """ - package jakarta.xml.bind; - public class MarshalException extends Exception { - } - """))) - .build().parse(""" - package org.openrewrite.java.testing; - import jakarta.xml.bind.MarshalException; - public class A { - MarshalException getMap() { - return new MarshalException(); - } - } - """)[0] - val mavenSource = MavenParser.builder().build().parse(""" - - com.mycompany.app - my-app - 1 - - - - """.trimIndent())[0] - - val sources: List = listOf(javaSource, mavenSource) - val results = recipe.run(sources, InMemoryExecutionContext{ error: Throwable -> throw error}) - val mavenResult = results.find { it.before === mavenSource } - Assertions.assertThat(mavenResult).isNotNull - - Assertions.assertThat(mavenResult?.after?.print()).isEqualTo(""" - - com.mycompany.app - my-app - 1 - - - jakarta.xml.bind - jakarta.xml.bind-api - 3.0.0 - - - - """.trimIndent()) - } } diff --git a/src/test/kotlin/org/openrewrite/java/migrate/javax/AddJaxbDependenciesTest.kt b/src/test/kotlin/org/openrewrite/java/migrate/javax/AddJaxbDependenciesTest.kt deleted file mode 100644 index adde0be7f6..0000000000 --- a/src/test/kotlin/org/openrewrite/java/migrate/javax/AddJaxbDependenciesTest.kt +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright 2020 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.javax - -import org.junit.jupiter.api.Test -import org.openrewrite.Recipe -import org.openrewrite.config.Environment -import org.openrewrite.maven.MavenRecipeTest - -class AddJaxbDependenciesTest : MavenRecipeTest { - override val recipe: Recipe = Environment.builder() - .scanRuntimeClasspath("org.openrewrite.java.migrate") - .build() - .activateRecipes("org.openrewrite.java.migrate.javax.AddJaxbDependencies") - - companion object { - private val jaxbContextStub : String = """ - package javax.xml.bind; - public class JAXBContext { - public static JAXBContext newInstance(String packages) { - return null; - } - public static JAXBContext newInstance(java.lang.Class packages) { - return null; - } - } - """.trimIndent() - - private val javaSourceWithJaxb : String = """ - package org.old.code; - import javax.xml.bind.JAXBContext; - - public class Yep { - private static final JAXBContext context = JAXBContext.newInstance("org.old.code"); - } - """.trimIndent() - private val javaSourceWithoutJaxb : String = """ - package org.old.code; - public class Nope { - } - """.trimIndent() - } - - @Test - fun onlyIfUsingJaxb() = assertChanged( - before = """ - - com.mycompany.app - my-app - 1 - - - - """.trimIndent(), - after =""" - - com.mycompany.app - my-app - 1 - - - jakarta.xml.bind - jakarta.xml.bind-api - 2.3.3 - - - org.glassfish.jaxb - jaxb-runtime - 2.3.5 - runtime - - - - """.trimIndent(), - additionalJavaFiles = arrayOf(jaxbContextStub, javaSourceWithJaxb) - ) - - @Test - fun doNotChangeIfNoJaxb() = assertUnchanged( - before = """ - - com.mycompany.app - my-app - 1 - - - - """.trimIndent(), - additionalJavaFiles = arrayOf(javaSourceWithoutJaxb) - ) - - @Test - fun migrateFromJaxbToJakarta() = assertChanged( - before = """ - - com.mycompany.app - my-app - 1 - - - javax.xml.bind - jaxb-api - 2.3.1 - - - com.sun.xml.bind - jaxb-impl - 2.3.4 - runtime - - - - """.trimIndent(), - after =""" - - com.mycompany.app - my-app - 1 - - - jakarta.xml.bind - jakarta.xml.bind-api - 2.3.3 - - - org.glassfish.jaxb - jaxb-runtime - 2.3.5 - runtime - - - - """.trimIndent(), - additionalJavaFiles = arrayOf(jaxbContextStub, javaSourceWithJaxb) - ) - @Test - fun migrateFromJaxbToJakartaParent() = assertChanged( - before = """ - - - com.mycompany.app - my-parent - 1 - - com.mycompany.app - my-child - 1 - - - javax.xml.bind - jaxb-api - - - com.sun.xml.bind - jaxb-impl - runtime - - - - """.trimIndent(), - after =""" - - - com.mycompany.app - my-parent - 1 - - com.mycompany.app - my-child - 1 - - - jakarta.xml.bind - jakarta.xml.bind-api - 2.3.3 - - - org.glassfish.jaxb - jaxb-runtime - 2.3.5 - runtime - - - - """.trimIndent(), - additionalJavaFiles = arrayOf(jaxbContextStub, javaSourceWithJaxb), - additionalMavenFiles = arrayOf( - """ - - com.mycompany.app - my-parent - 1 - - - - javax.xml.bind - jaxb-api - 2.3.0 - - - com.sun.xml.bind - jaxb-impl - 2.3.4 - - - - - """.trimIndent() - ) - ) - -} diff --git a/src/test/kotlin/org/openrewrite/java/migrate/javax/AddJaxwsDependenciesTest.kt b/src/test/kotlin/org/openrewrite/java/migrate/javax/AddJaxwsDependenciesTest.kt deleted file mode 100644 index 0a5a83b30f..0000000000 --- a/src/test/kotlin/org/openrewrite/java/migrate/javax/AddJaxwsDependenciesTest.kt +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright 2020 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.javax - -import org.junit.jupiter.api.Test -import org.openrewrite.Recipe -import org.openrewrite.config.Environment -import org.openrewrite.maven.MavenRecipeTest - -class AddJaxwsDependenciesTest : MavenRecipeTest { - override val recipe: Recipe = Environment.builder() - .scanRuntimeClasspath("org.openrewrite.java.migrate") - .build() - .activateRecipes("org.openrewrite.java.migrate.javax.AddJaxwsDependencies") - - companion object { - private val jaxbContextStub : String = """ - package javax.jws; - - import java.lang.annotation.Target; - import java.lang.annotation.Retention; - import java.lang.annotation.RetentionPolicy; - import java.lang.annotation.ElementType; - - @Retention(value = RetentionPolicy.RUNTIME) - @Target(value = {ElementType.TYPE}) - public @interface WebService { - } - """.trimIndent() - - private val javaSourceWithJaxws : String = """ - package org.old.code; - import javax.jws.WebService; - - @WebService - public class Yep { - } - """.trimIndent() - private val javaSourceWithoutJaxws : String = """ - package org.old.code; - public class Nope { - } - """.trimIndent() - } - - @Test - fun onlyIfUsingJaxws() = assertChanged( - before = """ - - com.mycompany.app - my-app - 1 - - - - """.trimIndent(), - after =""" - - com.mycompany.app - my-app - 1 - - - jakarta.xml.ws - jakarta.xml.ws-api - 2.3.3 - - - com.sun.xml.ws - jaxws-rt - 2.3.5 - runtime - - - - """.trimIndent(), - additionalJavaFiles = arrayOf(jaxbContextStub, javaSourceWithJaxws) - ) - - @Test - fun doNotChangeIfNoJaxws() = assertUnchanged( - before = """ - - com.mycompany.app - my-app - 1 - - - - """.trimIndent(), - additionalJavaFiles = arrayOf(javaSourceWithoutJaxws) - ) - - @Test - fun migrateFromJaxwsApiToJakarta() = assertChanged( - before = """ - - com.mycompany.app - my-app - 1 - - - javax.xml.ws - jaxws-api - 2.3.1 - - - com.sun.xml.ws - jaxws-rt - 2.3.2 - runtime - - - - """.trimIndent(), - after =""" - - com.mycompany.app - my-app - 1 - - - jakarta.xml.ws - jakarta.xml.ws-api - 2.3.3 - - - com.sun.xml.ws - jaxws-rt - 2.3.5 - runtime - - - - """.trimIndent(), - additionalJavaFiles = arrayOf(jaxbContextStub, javaSourceWithJaxws) - ) - @Test - fun migrateFromJaxwsToJakartaParent() = assertChanged( - before = """ - - - com.mycompany.app - my-parent - 1 - - com.mycompany.app - my-child - 1 - - - javax.xml.ws - jaxws-api - - - com.sun.xml.ws - jaxws-rt - runtime - - - - """.trimIndent(), - after =""" - - - com.mycompany.app - my-parent - 1 - - com.mycompany.app - my-child - 1 - - - jakarta.xml.ws - jakarta.xml.ws-api - 2.3.3 - - - com.sun.xml.ws - jaxws-rt - runtime - - - - """.trimIndent(), - additionalJavaFiles = arrayOf(jaxbContextStub, javaSourceWithJaxws), - additionalMavenFiles = arrayOf( - """ - - com.mycompany.app - my-parent - 1 - - - - javax.xml.ws - jaxws-api - 2.3.1 - - - com.sun.xml.ws - jaxws-rt - 2.3.2 - runtime - - - - - """.trimIndent() - ) - ) - -}