What version of OpenRewrite are you using?
I am using
- rewrite-recipe-bom 3.22.0
- rewrite-java 8.71.0
How are you running OpenRewrite?
Writing my own recipes with OpenRewrite as a basis, testing them using the framework.
What is the smallest, simplest way to reproduce the problem?
Simply add the following Test to the Test class:
@Test
@DisplayName("wenn xsi:schemaLocation einen Zeilenumbruch hat")
void correctReplacementSchemaLocationTwoLines() {
rewriteRun(
xml(
"""
<web-app version="4.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">
</web-app>
""",
"""
<web-app version="6.0" 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_5_0.xsd">
</web-app>
""",
spec -> spec.path("src/main/webapp/WEB-INF/web.xml")));
}
What did you expect to see?
The test should succeed because the recipe should replace xsi:schemaLocation with the correct, new schema location.
What did you see instead?
No change happens. schemaLocation is not updated.
Do you have any additional info?
This issue arises because the recipe only replaces the attribute value if the regex .*xml/ns/javaee.* matches:
- org.openrewrite.xml.ChangeTagAttribute:
elementName: web-app
attributeName: xsi:schemaLocation
newValue: https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd
oldValue: .*xml/ns/javaee.*
regex: true
That regex does not include linebreaks; it needs to be (?s).*xml/ns/javaee.* to do that.
This has the downside of replacing the old value containing linebreaks with a new value that does not contain them. However, I believe this is preferable to the recipe just not doing anything at all.
What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
Writing my own recipes with OpenRewrite as a basis, testing them using the framework.
What is the smallest, simplest way to reproduce the problem?
Simply add the following Test to the Test class:
What did you expect to see?
The test should succeed because the recipe should replace
xsi:schemaLocationwith the correct, new schema location.What did you see instead?
No change happens. schemaLocation is not updated.
Do you have any additional info?
This issue arises because the recipe only replaces the attribute value if the regex
.*xml/ns/javaee.*matches:That regex does not include linebreaks; it needs to be
(?s).*xml/ns/javaee.*to do that.This has the downside of replacing the old value containing linebreaks with a new value that does not contain them. However, I believe this is preferable to the recipe just not doing anything at all.