Skip to content

Commit

Permalink
Fix #440: EE10 Jakarta ejb-jar.xml (#475)
Browse files Browse the repository at this point in the history
* Fix #440: EE10 Jakarta ejb-jar.xml

* Update src/test/java/org/openrewrite/java/migrate/jakarta/JavaxEjbJarXmlToJakartaEjbJarXmlTest.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/test/java/org/openrewrite/java/migrate/jakarta/JavaxEjbJarXmlToJakartaEjbJarXmlTest.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Apply suggestions from code review

* Add trailing newline

* Minor polish

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tim te Beek <[email protected]>
Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
4 people authored May 11, 2024
1 parent 3f65b43 commit be68bb5
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main/resources/META-INF/rewrite/jakarta-ee-10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ recipeList:
- org.openrewrite.java.migrate.BeanDiscovery
- org.openrewrite.java.migrate.jakarta.BeanValidationMessages
- org.openrewrite.java.migrate.jakarta.JavaxBeansXmlToJakartaBeansXml
- org.openrewrite.java.migrate.jakarta.JavaxEjbJarXmlToJakartaEjbJarXml
- org.openrewrite.java.migrate.jakarta.JavaxToJakartaCdiExtensions
- org.openrewrite.java.migrate.jakarta.UpdateJakartaPlatform10
---
Expand Down Expand Up @@ -122,6 +123,34 @@ recipeList:
newValue: https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.jakarta.JavaxEjbJarXmlToJakartaEjbJarXml
displayName: Migrate xmlns entries and javax. packages in `ejb-jar.xml` files
description: Java EE has been rebranded to Jakarta EE, necessitating an XML namespace relocation.
tags:
- jakarta
- ejb
preconditions:
- org.openrewrite.FindSourceFiles:
filePattern: '**/ejb-jar.xml'
recipeList:
- org.openrewrite.xml.ChangeTagAttribute:
attributeName: version
elementName: ejb-jar
newValue: 4.0
- org.openrewrite.xml.ChangeTagAttribute:
attributeName: xmlns
elementName: ejb-jar
newValue: https://jakarta.ee/xml/ns/jakartaee
- org.openrewrite.xml.ChangeTagAttribute:
attributeName: xsi:schemaLocation
elementName: ejb-jar
newValue: https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/ejb-jar_4_0.xsd
- org.openrewrite.text.FindAndReplace:
find: "javax."
replace: "jakarta."
filePattern: '**/ejb-jar.xml'
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.jakarta.RemovalsServletJakarta10
displayName: Replace deprecated Jakarta Servlet methods and classes
description: >
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Copyright 2024 the original author or authors.
* <p>
* 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
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.jakarta;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.config.Environment;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.xml.Assertions.xml;

class JavaxEjbJarXmlToJakartaEjbJarXmlTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.migrate.jakarta").build()
.activateRecipes("org.openrewrite.java.migrate.jakarta.JavaxEjbJarXmlToJakartaEjbJarXml"));
}

@Test
@DocumentExample
void migrateJCP() {
rewriteRun(
//language=xml
xml(
"""
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
version="3.0">
<enterprise-beans>
<session>
<ejb-name>HelloSessionBean</ejb-name>
<mapped-name>ejb/HelloSessionBean</mapped-name>
<business-local>com.mydomain.HelloSessionBeanLocal</business-local>
<business-remote>com.mydomain.HelloSessionBeanRemote</business-remote>
<ejb-class>com.mydomain.HelloSessionBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
<message-driven>
<ejb-name>MessageBean</ejb-name>
<ejb-class>samples.mdb.ejb.MessageBean</ejb-class>
<transaction-type>Container</transaction-type>
<message-driven-destination>
<destination-type>javax.jms.Queue</destination-type>
</message-driven-destination>
<resource-ref>
<res-ref-name>jms/QueueConnectionFactory</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</message-driven>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>MessageBean</ejb-name>
<method-intf>Bean</method-intf>
<method-name>onMessage</method-name>
<method-params>
<method-param>javax.jms.Message</method-param>
</method-params>
</method>
<trans-attribute>NotSupported</trans-attribute>
</container-transaction>
</assembly-descriptor>
</enterprise-beans>
</ejb-jar>
""",
"""
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/ejb-jar_4_0.xsd"
version="4.0">
<enterprise-beans>
<session>
<ejb-name>HelloSessionBean</ejb-name>
<mapped-name>ejb/HelloSessionBean</mapped-name>
<business-local>com.mydomain.HelloSessionBeanLocal</business-local>
<business-remote>com.mydomain.HelloSessionBeanRemote</business-remote>
<ejb-class>com.mydomain.HelloSessionBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
<message-driven>
<ejb-name>MessageBean</ejb-name>
<ejb-class>samples.mdb.ejb.MessageBean</ejb-class>
<transaction-type>Container</transaction-type>
<message-driven-destination>
<destination-type>jakarta.jms.Queue</destination-type>
</message-driven-destination>
<resource-ref>
<res-ref-name>jms/QueueConnectionFactory</res-ref-name>
<res-type>jakarta.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</message-driven>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>MessageBean</ejb-name>
<method-intf>Bean</method-intf>
<method-name>onMessage</method-name>
<method-params>
<method-param>jakarta.jms.Message</method-param>
</method-params>
</method>
<trans-attribute>NotSupported</trans-attribute>
</container-transaction>
</assembly-descriptor>
</enterprise-beans>
</ejb-jar>
""",
sourceSpecs -> sourceSpecs.path("ejb-jar.xml")
)
);
}

@Nested
class NoChanges {
@Test
void fileNotWebXml() {
rewriteRun(
//language=xml
xml(
"""
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>
""",
sourceSpecs -> sourceSpecs.path("not-ejb-jar.xml")
)
);
}
}
}

0 comments on commit be68bb5

Please sign in to comment.