From c344792272e29f34b61b818c1db8b777d58ee3fd Mon Sep 17 00:00:00 2001 From: Erhard Siegl Date: Fri, 17 May 2024 23:22:18 +0200 Subject: [PATCH] Persistence ORM-XML to Jarkata --- .../META-INF/rewrite/deskriptors.yml | 49 ++++++++++++ .../xml/JavaxOrmXmlToJakartaOrmXmlTest.java | 75 +++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 src/main/resources/META-INF/rewrite/deskriptors.yml create mode 100644 src/test/java/com/gepardec/wor/xml/JavaxOrmXmlToJakartaOrmXmlTest.java diff --git a/src/main/resources/META-INF/rewrite/deskriptors.yml b/src/main/resources/META-INF/rewrite/deskriptors.yml new file mode 100644 index 0000000..7491e34 --- /dev/null +++ b/src/main/resources/META-INF/rewrite/deskriptors.yml @@ -0,0 +1,49 @@ +# +# Copyright 2023 the original author or authors. +#

+# 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 +#

+# https://www.apache.org/licenses/LICENSE-2.0 +#

+# 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. +# +--- +type: specs.openrewrite.org/v1beta/recipe +name: com.gepardec.java.migrate.jakarta.Descriptors +displayName: Migrate JEE Descriptors to Jakarta EE 10 +description: These recipes help with the Migration to Jakarta EE 10. +tags: + - jakarta +recipeList: + - org.openrewrite.java.migrate.jakarta.JavaxBeansXmlToJakartaBeansXml +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.migrate.jakarta.JavaxBeansXmlToJakartaBeansXml +displayName: Migrate xmlns entries in `beans.xml` files +description: Java EE has been rebranded to Jakarta EE, necessitating an XML namespace relocation. +tags: + - jakarta + - persistence + - orm +preconditions: + - org.openrewrite.FindSourceFiles: + filePattern: '**/*orm.xml' +recipeList: + - org.openrewrite.xml.ChangeTagAttribute: + attributeName: version + elementName: entity-mappings + newValue: 3.0 + - org.openrewrite.xml.ChangeTagAttribute: + attributeName: xmlns + elementName: entity-mappings + newValue: https://jakarta.ee/xml/ns/persistence/orm + - org.openrewrite.xml.ChangeTagAttribute: + attributeName: xsi:schemaLocation + elementName: entity-mappings + newValue: https://jakarta.ee/xml/ns/persistence/orm https://jakarta.ee/xml/ns/persistence/orm/orm_3_0.xsd \ No newline at end of file diff --git a/src/test/java/com/gepardec/wor/xml/JavaxOrmXmlToJakartaOrmXmlTest.java b/src/test/java/com/gepardec/wor/xml/JavaxOrmXmlToJakartaOrmXmlTest.java new file mode 100644 index 0000000..5ee8565 --- /dev/null +++ b/src/test/java/com/gepardec/wor/xml/JavaxOrmXmlToJakartaOrmXmlTest.java @@ -0,0 +1,75 @@ +/* + * Copyright 2023 the original author or authors. + *

+ * 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 + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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 com.gepardec.wor.xml; + +import com.gepardec.wor.lord.util.ParserUtil; +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 JavaxOrmXmlToJakartaOrmXmlTest implements RewriteTest { + @Override + public void defaults(RecipeSpec spec) { + spec + .parser(ParserUtil.createParserWithRuntimeClasspath()) + .recipe(Environment.builder() + .scanRuntimeClasspath("com.gepardec.wor") + .build() + .activateRecipes("org.openrewrite.java.migrate.jakarta.JavaxBeansXmlToJakartaBeansXml")); + } + + @DocumentExample + @Test + void testOrmXml() { + rewriteRun( + spec -> spec.expectedCyclesThatMakeChanges(2), + //language=xml + xml( + """ + + + SV Batch Framework JPA Entities + + + + + + + """, + """ + + + SV Batch Framework JPA Entities + + + + + + + """, + sourceSpecs -> sourceSpecs.path("myapp-orm.xml") + ) + ); + } +}