Skip to content

Commit

Permalink
Added support for javax.inject (#513)
Browse files Browse the repository at this point in the history
* Added support for javax.inject

* Shorten test to the bare essentials

---------

Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
sgartner03 and timtebeek authored Jul 15, 2024
1 parent 78159d1 commit 6309fee
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main/resources/META-INF/rewrite/jakarta-ee-9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ recipeList:
newGroupId: jakarta.inject
newArtifactId: jakarta.inject-api
newVersion: latest.release
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: javax.inject
oldArtifactId: javax.inject
newGroupId: jakarta.inject
newArtifactId: jakarta.inject-api
newVersion: latest.release
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
groupId: jakarta.inject
artifactId: jakarta.inject-api
Expand Down Expand Up @@ -1028,4 +1034,4 @@ preconditions:
recipeList:
- org.openrewrite.java.dependencies.RemoveDependency:
groupId: jakarta.annotation
artifactId: jakarta.annotation-api
artifactId: jakarta.annotation-api
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openrewrite.maven.Assertions.pomXml;

class JavaxInjectToJakartaInjectTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
spec.recipeFromResource(
"/META-INF/rewrite/jakarta-ee-9.yml",
"org.openrewrite.java.migrate.jakarta.JavaxInjectMigrationToJakartaInject");
}

@Test
@DocumentExample
void projectWithJavaxInject() {
rewriteRun(
//language=xml
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
</dependencies>
</project>
""",
spec -> spec.after(actual -> {
assertThat(actual)
.contains("<groupId>jakarta.inject</groupId>")
.contains("<artifactId>jakarta.inject-api</artifactId>")
.containsPattern("<version>[0-9]+\\.[0-9]+\\.[0-9]+</version>");
return actual;
})
)
);
}
}

0 comments on commit 6309fee

Please sign in to comment.