Skip to content

Commit

Permalink
Persistence ORM-XML to Jarkata
Browse files Browse the repository at this point in the history
  • Loading branch information
ErhardSiegl committed May 17, 2024
1 parent 5ed7583 commit c344792
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/main/resources/META-INF/rewrite/deskriptors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Copyright 2023 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.
#
---
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2023 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 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(
"""
<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
version="2.0">
<description>SV Batch Framework JPA Entities</description>
<!-- SV-Batch Entity Mapping -->
<entity class="com.gepardec.JobDefinition" />
<entity class="com.gepardec.JobType" />
</entity-mappings>
""",
"""
<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="https://jakarta.ee/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence/orm https://jakarta.ee/xml/ns/persistence/orm/orm_3_0.xsd"
version="3.0">
<description>SV Batch Framework JPA Entities</description>
<!-- SV-Batch Entity Mapping -->
<entity class="com.gepardec.JobDefinition" />
<entity class="com.gepardec.JobType" />
</entity-mappings>
""",
sourceSpecs -> sourceSpecs.path("myapp-orm.xml")
)
);
}
}

0 comments on commit c344792

Please sign in to comment.