Skip to content

Commit

Permalink
Remove wrong namespace-change of package javax.transaction.xa (#554)
Browse files Browse the repository at this point in the history
* Remove wrong change of javax.transaction.xa package

Removes a wrong package change previously made in jakarta-ee-9.yml. The package javax.transaction.xa was wrongly changed to jakarta.transaction.xa, which does not exist.

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tim te Beek <timtebeek@gmail.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tim te Beek <timtebeek@gmail.com>
  • Loading branch information
3 people authored Sep 13, 2024
1 parent dfecd4f commit 01888dd
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/rewrite/jakarta-ee-9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ recipeList:
- org.openrewrite.java.ChangePackage:
oldPackageName: javax.transaction
newPackageName: jakarta.transaction
recursive: true
recursive: false
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.jakarta.JavaxWebsocketToJakartaWebsocket
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* 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.intellij.lang.annotations.Language;
import org.junit.jupiter.api.Test;

import org.openrewrite.DocumentExample;
import org.openrewrite.config.Environment;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.java.Assertions.*;

public class JavaxTransactionMigrationToJakartaTransactionTest implements RewriteTest {
@Language("java")
private static final String javax_transaction =
"""
package javax.transaction;
public @interface Transactional {}
""";

@Language("java")
private static final String javax_transaction_xa =
"""
package javax.transaction.xa;
public class XAResource {
public static void stat() {}
public void foo() {}
}
""";

@Language("java")
private static final String jakarta_transaction =
"""
package jakarta.transaction;
public @interface Transactional {}
""";

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

@Test
void doNotChangeImportWhenPackageFromJavaSE() {
rewriteRun(
spec -> spec.parser(JavaParser.fromJavaVersion().dependsOn(javax_transaction_xa)),
//language=java
java(
"""
import javax.transaction.xa.*;
public class A {
XAResource xa;
}
""")
);
}

@DocumentExample
@Test
void changeImportWhenPackageFromJakartaTransaction() {
rewriteRun(
spec -> spec.parser(JavaParser.fromJavaVersion().dependsOn(javax_transaction, jakarta_transaction)),
//language=java
java(
"""
import javax.transaction.Transactional;
@Transactional
public class A {
public void foo() {}
}
""",
"""
import jakarta.transaction.Transactional;
@Transactional
public class A {
public void foo() {}
}
""")
);
}
}

0 comments on commit 01888dd

Please sign in to comment.