Skip to content

Commit

Permalink
Update dependency handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed Aug 21, 2021
1 parent a870437 commit bc24e7c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 552 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions src/main/resources/META-INF/rewrite/add-jaxb-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
27 changes: 9 additions & 18 deletions src/main/resources/META-INF/rewrite/javax-to-jakarta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
70 changes: 0 additions & 70 deletions src/test/kotlin/org/openrewrite/java/migrate/JavaxToJakartaTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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("""
<project>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<dependencies>
</dependencies>
</project>
""".trimIndent())[0]

val sources: List<SourceFile> = 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("""
<project>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
</project>
""".trimIndent())
}
}
Loading

0 comments on commit bc24e7c

Please sign in to comment.