Skip to content

Commit

Permalink
Fix #439: web.xml/web-fragment.xml handle javax.sql. (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored May 11, 2024
1 parent d722b46 commit 3f65b43
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/main/resources/META-INF/rewrite/jakarta-faces-4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ recipeList:
find: "javax."
replace: "jakarta."
filePattern: '**/web-fragment.xml'
- org.openrewrite.text.FindAndReplace:
find: "jakarta.sql."
replace: "javax.sql."
filePattern: '**/web-fragment.xml'
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.jakarta.JavaxWebXmlToJakartaWebXml
Expand All @@ -218,6 +222,10 @@ recipeList:
find: "javax."
replace: "jakarta."
filePattern: '**/web.xml'
- org.openrewrite.text.FindAndReplace:
find: "jakarta.sql."
replace: "javax.sql."
filePattern: '**/web.xml'
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.jakarta.JakartaFacesEcmaScript
Expand Down Expand Up @@ -489,4 +497,4 @@ recipeList:
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
groupId: org.apache.myfaces.core
artifactId: myfaces-impl
newVersion: 4.0.x
newVersion: 4.0.x
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,42 @@ void migrateJCP() {
);
}

@Test
void migrateWithDatasource() {
rewriteRun(
//language=xml
xml(
"""
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="4.0"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_4_0.xsd">
<resource-ref>
<res-ref-name>myDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>CONTAINER</res-auth>
</resource-ref>
</web-fragment>
""",
"""
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="5.0"
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-fragment_5_0.xsd">
<resource-ref>
<res-ref-name>myDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>CONTAINER</res-auth>
</resource-ref>
</web-fragment>
""",
sourceSpecs -> sourceSpecs.path("web-fragment.xml")
)
);
}

@Nested
class NoChanges {
@Test
Expand All @@ -114,4 +150,4 @@ void fileNotWebFragmentXml() {
);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,50 @@ void migrateJCP() {
);
}

@DocumentExample
@Test
void migrateWithSQLDataSource() {
rewriteRun(
//language=xml
xml(
"""
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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/web-app_2_0.xsd"
version="2.0">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<resource-ref>
<res-ref-name>myDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>CONTAINER</res-auth>
</resource-ref>
</web-fragment>
""",
"""
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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/web-app_6_0.xsd"
version="6.0">
<context-param>
<param-name>jakarta.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<resource-ref>
<res-ref-name>myDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>CONTAINER</res-auth>
</resource-ref>
</web-fragment>
""",
sourceSpecs -> sourceSpecs.path("web.xml")
)
);
}
@Nested
class NoChanges {
@Test
Expand All @@ -118,4 +162,4 @@ void fileNotWebXml() {
);
}
}
}
}

0 comments on commit 3f65b43

Please sign in to comment.