Skip to content

Commit

Permalink
Revert to old recipe names for jaxb/jaxws recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
tkvangorder committed Nov 19, 2022
1 parent 895a6a4 commit 7558758
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.java.migrate.jakarta;
package org.openrewrite.java.migrate.javax;

import lombok.EqualsAndHashCode;
import lombok.Value;
Expand All @@ -28,10 +28,7 @@

@Value
@EqualsAndHashCode(callSuper = true)
public class UpdateJaxbRuntimeToJakartaEE8 extends Recipe {

private static final String LEGACY_JAVA_JAXB_API_GROUP = "javax.xml.bind";
private static final String LEGACY_JAVA_JAXB_API_ARTIFACT = "jaxb-api";
public class AddJaxbRuntime extends Recipe {

private static final String JAKARTA_API_GROUP = "jakarta.xml.bind";
private static final String JAKARTA_API_ARTIFACT = "jakarta.xml.bind-api";
Expand All @@ -55,12 +52,10 @@ public String getDisplayName() {

@Override
public String getDescription() {
return "Update maven build files to use the latest JAXB API from Jakarta EE8 and add a compatible runtime " +
"dependency to maintain compatibility with Java versions greater than Java 8. This recipe will change " +
"existing dependencies on `javax.xml.bind:jax-api` to `jakarta.xml.bind:jakarta.xml.bind-api`. The " +
"recipe will also add a JAXB run-time, in `provided` scope, to any project that has a transitive dependency " +
"on the JAXB API. **The resulting dependencies still use the `javax` namespace, despite the move " +
"to the Jakarta artifact**.";
return "Update maven build files to use the latest JAXB runtime from Jakarta EE 8 to maintain compatibility " +
"with Java version 11 or greater. The recipe will add a JAXB run-time, in `provided` scope, to any project " +
"that has a transitive dependency on the JAXB API. **The resulting dependencies still use the `javax` " +
"namespace, despite the move to the Jakarta artifact**.";
}

@Override
Expand All @@ -73,27 +68,25 @@ public Set<String> getTags() {
return new HashSet<>(Arrays.asList("javax", "jakarta", "javaee", "jaxb", "glassfish", "java11"));
}

@Override
public boolean causesAnotherCycle() {
return true;
}

@Override
protected TreeVisitor<?, ExecutionContext> getVisitor() {
return new MavenIsoVisitor<ExecutionContext>() {
@SuppressWarnings("ConstantConditions")
@Override
public Xml.Document visitDocument(Xml.Document document, ExecutionContext ctx) {
//remove legacy jaxb-core, regardless of which runtime is being used.
doAfterVisit(new RemoveDependency("com.sun.xml.bind", "jaxb-core", null));
Xml.Document d = super.visitDocument(document, ctx);

d = (Xml.Document) new ChangeDependencyGroupIdAndArtifactId(
LEGACY_JAVA_JAXB_API_GROUP, LEGACY_JAVA_JAXB_API_ARTIFACT,
JAKARTA_API_GROUP, JAKARTA_API_ARTIFACT, "2.3.2", null
).getVisitor().visit(d, ctx);
d = (Xml.Document) new ChangeManagedDependencyGroupIdAndArtifactId(
LEGACY_JAVA_JAXB_API_GROUP, LEGACY_JAVA_JAXB_API_ARTIFACT,
JAKARTA_API_GROUP, JAKARTA_API_ARTIFACT, "2.3.2"
).getVisitor().visit(d, ctx);

//Normalize any existing runtimes to the one selected in this recipe.
if ("sun".equals(runtime)) {
if (getRecipeList().isEmpty()) {
//Upgrade any previous runtimes to the most current 2.3.x version
doNext(new UpgradeDependencyVersion(SUN_JAXB_RUNTIME_GROUP, SUN_JAXB_RUNTIME_ARTIFACT, "2.3.x", null, null));
}
d = (Xml.Document) new ChangeDependencyGroupIdAndArtifactId(
GLASSFISH_JAXB_RUNTIME_GROUP, GLASSFISH_JAXB_RUNTIME_ARTIFACT,
SUN_JAXB_RUNTIME_GROUP, SUN_JAXB_RUNTIME_ARTIFACT, "2.3.2", null
Expand All @@ -103,6 +96,10 @@ public Xml.Document visitDocument(Xml.Document document, ExecutionContext ctx) {
SUN_JAXB_RUNTIME_GROUP, SUN_JAXB_RUNTIME_ARTIFACT, "2.3.2"
).getVisitor().visit(d, ctx);
} else {
if (getRecipeList().isEmpty()) {
//Upgrade any previous runtimes to the most current 2.3.x version
doNext(new UpgradeDependencyVersion(GLASSFISH_JAXB_RUNTIME_GROUP, GLASSFISH_JAXB_RUNTIME_ARTIFACT, "2.3.x", null, null));
}
d = (Xml.Document) new ChangeDependencyGroupIdAndArtifactId(
SUN_JAXB_RUNTIME_GROUP, SUN_JAXB_RUNTIME_ARTIFACT,
GLASSFISH_JAXB_RUNTIME_GROUP, GLASSFISH_JAXB_RUNTIME_ARTIFACT, "2.3.2", null
Expand All @@ -113,17 +110,10 @@ public Xml.Document visitDocument(Xml.Document document, ExecutionContext ctx) {
).getVisitor().visit(d, ctx);
}
if (d != document) {
//If any changes to dependencies were made, return now to allow the maven model to be updated.
//The logic for adding missing dependencies will happen in the next cycle.
//If changes have been made, update the maven model, next cycle, runtime will be added.
return d;
}
d = maybeAddRuntimeDependency(d, ctx);
if (d != document) {
doAfterVisit(new RemoveRedundantDependencyVersions("org.glassfish.jaxb", "*", true));
doAfterVisit(new RemoveRedundantDependencyVersions("com.sun.xml.bind", "*", true));
doAfterVisit(new RemoveRedundantDependencyVersions("jakarta.xml.bind", "*", true));
}
return d;
return maybeAddRuntimeDependency(d, ctx);
}

@SuppressWarnings("ConstantConditions")
Expand All @@ -139,8 +129,8 @@ private Xml.Document maybeAddRuntimeDependency(Xml.Document d, ExecutionContext
if (apiScope != null && (runtimeScope == null || !apiScope.isInClasspathOf(runtimeScope))) {
String resolvedScope = apiScope == Scope.Test ? "test" : "provided";
AddDependencyVisitor addDependency = "sun".equals(runtime) ?
new AddDependencyVisitor(SUN_JAXB_RUNTIME_GROUP, SUN_JAXB_RUNTIME_ARTIFACT, "2.3.2", null, resolvedScope, null, null, null, null, null) :
new AddDependencyVisitor(GLASSFISH_JAXB_RUNTIME_GROUP, GLASSFISH_JAXB_RUNTIME_ARTIFACT, "2.3.2", null, resolvedScope, null, null, null, null, null);
new AddDependencyVisitor(SUN_JAXB_RUNTIME_GROUP, SUN_JAXB_RUNTIME_ARTIFACT, "2.3.x", null, resolvedScope, null, null, null, null, null) :
new AddDependencyVisitor(GLASSFISH_JAXB_RUNTIME_GROUP, GLASSFISH_JAXB_RUNTIME_ARTIFACT, "2.3.x", null, resolvedScope, null, null, null, null, null);
return (Xml.Document) addDependency.visit(d, ctx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.java.migrate.jakarta;
package org.openrewrite.java.migrate.javax;

import lombok.EqualsAndHashCode;
import lombok.Value;
Expand All @@ -32,7 +32,7 @@

@Value
@EqualsAndHashCode(callSuper = true)
public class UpdateJaxwsRuntimeToJakartaEE8 extends Recipe {
public class AddJaxwsRuntime extends Recipe {

private static final String LEGACY_JAVA_JAXWS_API_GROUP = "javax.xml.ws";
private static final String LEGACY_JAVA_JAXWS_API_ARTIFACT = "jaxws-api";
Expand All @@ -50,12 +50,10 @@ public String getDisplayName() {

@Override
public String getDescription() {
return "Update maven build files to use the latest JAX-WS API from Jakarta EE 8 and add a compatible runtime " +
"dependency to maintain compatibility with Java version greater than Java 8. This recipe will change " +
"existing dependencies on `javax.xml.ws:jaxws-api` to `jakarta.xml.ws:jakarta.xml.ws-api`. The " +
"recipe will also add a JAXWS run-time, in `provided` scope, to any project that has a transitive dependency " +
"on the JAXWS API. **The resulting dependencies still use the `javax` namespace, despite the move " +
"to the Jakarta artifact**.";
return "Update maven build files to use the latest JAX-WS runtime from Jakarta EE 8 to maintain compatibility " +
"with Java version 11 or greater. The recipe will add a JAX-WS run-time, in `provided` scope, to any project " +
"that has a transitive dependency on the JAX-WS API. **The resulting dependencies still use the `javax` " +
"namespace, despite the move to the Jakarta artifact**.";
}

@Override
Expand All @@ -65,7 +63,7 @@ public Duration getEstimatedEffortPerOccurrence() {

@Override
public Set<String> getTags() {
return new HashSet<>(Arrays.asList("javax", "jakarta", "javaee", "jax-ws", "java11"));
return new HashSet<>(Arrays.asList("javax", "jakarta", "javaee", "jaxws", "java11"));
}


Expand All @@ -75,38 +73,7 @@ protected TreeVisitor<?, ExecutionContext> getVisitor() {
@SuppressWarnings({"ReassignedVariable", "ConstantConditions"})
@Override
public Xml.Document visitDocument(Xml.Document document, ExecutionContext ctx) {
// Remove legacy jaxws-ri library (in favor of the jaxws-rt)
doAfterVisit(new RemoveDependency(SUN_JAXWS_RUNTIME_GROUP, "jaxws-ri", null));
doAfterVisit(new RemoveManagedDependency(SUN_JAXWS_RUNTIME_GROUP, "jaxws-ri", null));
Xml.Document d = super.visitDocument(document, ctx);

d = (Xml.Document) new ChangeDependencyGroupIdAndArtifactId(
LEGACY_JAVA_JAXWS_API_GROUP, LEGACY_JAVA_JAXWS_API_ARTIFACT,
JAKARTA_JAXWS_API_GROUP, JAKARTA_JAXWS_API_ARTIFACT, "2.3.2", null
).getVisitor().visit(d, ctx);
// Change javax.xml.ws:jaxws-api to jakarta.xml.ws:jakarta.xml.ws-api
d = (Xml.Document) new ChangeManagedDependencyGroupIdAndArtifactId(
LEGACY_JAVA_JAXWS_API_GROUP, LEGACY_JAVA_JAXWS_API_ARTIFACT,
JAKARTA_JAXWS_API_GROUP, JAKARTA_JAXWS_API_ARTIFACT, "2.3.2"
).getVisitor().visit(d, ctx);

if (d != document) {
//If any changes to dependencies were made, return now to allow the maven model to be updated.
//The logic for adding missing dependencies will happen in the next cycle.
return d;
}

d = maybeAddRuntimeDependency(d, ctx);
if (d != document) {
doAfterVisit(new RemoveRedundantDependencyVersions("jakarta.xml.ws", "*", true));
doAfterVisit(new RemoveRedundantDependencyVersions("com.sun.xml.ws", "*", true));
}
return d;
}

@SuppressWarnings("ConstantConditions")
private Xml.Document maybeAddRuntimeDependency(Xml.Document d, ExecutionContext ctx) {

MavenResolutionResult mavenModel = getResolutionResult();

//Find the highest scope of a transitive dependency on the JAX-WS API (if it exists at all)
Expand All @@ -117,12 +84,11 @@ private Xml.Document maybeAddRuntimeDependency(Xml.Document d, ExecutionContext
if (apiScope != null && (runtimeScope == null || !apiScope.isInClasspathOf(runtimeScope))) {
String resolvedScope = apiScope == Scope.Test ? "test" : "provided";
d = (Xml.Document) new AddDependencyVisitor(SUN_JAXWS_RUNTIME_GROUP, SUN_JAXWS_RUNTIME_ARTIFACT,
"2.3.2", null, resolvedScope, null, null, null, null, null).visit(d, ctx);
"2.3.x", null, resolvedScope, null, null, null, null, null).visit(d, ctx);
}

return d;
}

};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
@NonNullApi
@NonNullFields
package org.openrewrite.java.migrate.jakarta;
package org.openrewrite.java.migrate.javax;

import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.internal.lang.NonNullFields;
125 changes: 122 additions & 3 deletions src/main/resources/META-INF/rewrite/java-version-11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ tags:
recipeList:
- org.openrewrite.java.migrate.UseJavaUtilBase64
# Add an explicit JAXB/JAX-WS runtime and upgrade the dependencies to Jakarta EE 8
- org.openrewrite.java.migrate.jakarta.UpdateJaxbRuntimeToJakartaEE8:
runtime: glassfish
- org.openrewrite.java.migrate.jakarta.UpdateJaxwsRuntimeToJakartaEE8
- org.openrewrite.java.migrate.javax.AddJaxbDependencies
- org.openrewrite.java.migrate.javax.AddJaxwsDependencies
- org.openrewrite.java.migrate.javax.AddInjectDependencies
# Add jdeprscan plugin to a maven-based build.
- org.openrewrite.java.migrate.AddJDeprScanPlugin
Expand Down Expand Up @@ -75,3 +74,123 @@ recipeList:
key: maven.compiler.target
newValue: 11
addIfMissing: false
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.javax.AddJaxbDependencies
displayName: Add explicit JAXB dependencies
description: >
This recipe will add explicit dependencies for Jakarta EE 8 when a Java 8 application is using JAXB. Any existing
dependencies will be upgraded to the latest version of Jakarta EE 8. **The artifacts are moved to Jakarta EE 8 but the
application can continue to use the `javax.xml.bind` namespace.
tags:
- javax
- java11
- jaxb
- jakarta
- glassfish
recipeList:
# Remove the legacy jaxb-core artifact
- org.openrewrite.maven.RemoveDependency:
groupId: com.sun.xml.bind
artifactId: jaxb-core
- org.openrewrite.maven.RemoveManagedDependency:
groupId: com.sun.xml.bind
artifactId: jaxb-core
# Change any existing places in the project poms that use the jaxb-api.
- org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId:
oldGroupId: javax.xml.bind
oldArtifactId: jaxb-api
newGroupId: jakarta.xml.bind
newArtifactId: jakarta.xml.bind-api
newVersion: 2.3.x
- org.openrewrite.maven.ChangeManagedDependencyGroupIdAndArtifactId:
oldGroupId: javax.xml.bind
oldArtifactId: jaxb-api
newGroupId: jakarta.xml.bind
newArtifactId: jakarta.xml.bind-api
newVersion: 2.3.x
# Add the jakarta JAXB artifact if it is missing but a project uses types in java.xml.bind
- org.openrewrite.maven.AddDependency:
groupId: jakarta.xml.bind
artifactId: jakarta.xml.bind-api
version: 2.3.x
onlyIfUsing: javax.xml.bind.*
# If a project already had the jakarta api, make sure it is at the latest version.
- org.openrewrite.maven.UpgradeDependencyVersion:
groupId: jakarta.xml.bind
artifactId: jakarta.xml.bind-api
newVersion: 2.3.x
# Add the jaxb runtime to any projects that have a transitive dependency on the api
- org.openrewrite.java.migrate.javax.AddJaxbRuntime:
runtime: glassfish
# Remove the version from added dependencies when a managed version exists.
- org.openrewrite.maven.RemoveRedundantDependencyVersions:
groupPattern: org.glassfish.jaxb
artifactPattern: "*"
onlyIfVersionsMatch: true
- org.openrewrite.maven.RemoveRedundantDependencyVersions:
groupPattern: com.sun.xml.bind
artifactPattern: "*"
onlyIfVersionsMatch: true
- org.openrewrite.maven.RemoveRedundantDependencyVersions:
groupPattern: jakarta.xml.bind
artifactPattern: "*"
onlyIfVersionsMatch: true
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.javax.AddJaxwsDependencies
displayName: Add explicit JAX-WS dependencies
description: >
This recipe will add explicit dependencies for Jakarta EE 8 when a Java 8 application is using JAX-WS. Any existing
dependencies will be upgraded to the latest version of Jakarta EE 8. **The artifacts are moved to Jakarta EE 8 but the
application can continue to use the `javax.xml.bind` namespace.
tags:
- javax
- java11
- jaxb
- jakarta
- glassfish
recipeList:
# Remove the legacy jaxws-ri artifact
- org.openrewrite.maven.RemoveDependency:
groupId: com.sun.xml.ws
artifactId: jaxws-ri
- org.openrewrite.maven.RemoveManagedDependency:
groupId: com.sun.xml.ws
artifactId: jaxws-ri
# Change any existing places in the project poms that use the jaxb-api.
- org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId:
oldGroupId: javax.xml.ws
oldArtifactId: jaxws-api
newGroupId: jakarta.xml.ws
newArtifactId: jakarta.xml.ws-api
newVersion: 2.3.x
- org.openrewrite.maven.ChangeManagedDependencyGroupIdAndArtifactId:
oldGroupId: javax.xml.ws
oldArtifactId: jaxws-api
newGroupId: jakarta.xml.ws
newArtifactId: jakarta.xml.ws-api
newVersion: 2.3.x
# Add the jakarta JAXB artifact if it is missing but a project uses types in java.xml.bind
- org.openrewrite.maven.AddDependency:
groupId: jakarta.xml.ws
artifactId: jakarta.xml.ws-api
version: 2.3.x
onlyIfUsing: javax.jws..*
# If a project already had the jakarta api, make sure it is at the latest version.
- org.openrewrite.maven.UpgradeDependencyVersion:
groupId: jakarta.xml.ws
artifactId: jakarta.xml.ws-api
newVersion: 2.3.x
# Add the jaxb runtime to any projects that have a transitive dependency on the api
- org.openrewrite.java.migrate.javax.AddJaxwsRuntime
# Remove the version from added dependencies when a managed version exists.
- org.openrewrite.maven.RemoveRedundantDependencyVersions:
groupPattern: jakarta.xml.ws
artifactPattern: "*"
onlyIfVersionsMatch: true
- org.openrewrite.maven.RemoveRedundantDependencyVersions:
groupPattern: com.sun.xml.ws
artifactPattern: "*"
onlyIfVersionsMatch: true

Loading

0 comments on commit 7558758

Please sign in to comment.