Skip to content

Commit

Permalink
Minor touch ups
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Apr 22, 2024
1 parent da92471 commit e46e6aa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ recipeList:
artifactId: jakarta.annotation-api
version: 1.3.x
onlyIfUsing: javax.annotation..*
acceptTransitive: true
acceptTransitive: true
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.javax.AddInjectDependencies
displayName: Add explicit Inject dependencies
description: >
This recipe will add the necessary `inject-api` dependency from Jakarta EE 8 to maintain compatibility with Java
version 11 or greater.
Add the necessary `inject-api` dependency from Jakarta EE 8 to maintain compatibility with Java version 11 or greater.
tags:
- javax
- java11
Expand All @@ -33,7 +32,6 @@ recipeList:
version: 1.0.3
onlyIfUsing: javax.inject.*
acceptTransitive: true

- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
groupId: jakarta.inject
artifactId: jakarta.inject-api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,20 @@
package org.openrewrite.java.migrate.javax;

import org.junit.jupiter.api.Test;
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.java;
import static org.openrewrite.java.Assertions.javaVersion;
import static org.openrewrite.java.Assertions.mavenProject;
import static org.openrewrite.java.Assertions.srcMainJava;
import static org.openrewrite.java.Assertions.version;
import static org.openrewrite.java.Assertions.*;
import static org.openrewrite.maven.Assertions.pomXml;

class AddCommonAnnotationsDependenciesTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
spec.recipe(
Environment.builder()
.scanYamlResources()
.build()
.activateRecipes("org.openrewrite.java.migrate.javax.AddCommonAnnotationsDependencies"))
spec.recipeFromResource(
"/META-INF/rewrite/add-common-annotations-dependencies.yml",
"org.openrewrite.java.migrate.javax.AddCommonAnnotationsDependencies")
.allSources(src -> src.markers(javaVersion(8)));
}

Expand All @@ -46,25 +39,26 @@ void addDependencyIfAnnotationJsr250Present() {
spec -> spec.parser(JavaParser.fromJavaVersion().classpath("jakarta.annotation-api")),
mavenProject("my-project",
//language=java
srcMainJava(version(java("""
import javax.annotation.Generated;
@Generated("Hello")
class A {
}
"""), 8)),
srcMainJava(
java(
"""
import javax.annotation.Generated;
@Generated("Hello")
class A {
}
"""
)
),
//language=xml
pomXml("""
pomXml(
"""
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0.0</version>
<dependencies>
</dependencies>
</project>
""",
"""
Expand All @@ -74,47 +68,17 @@ class A {
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>1.3.5</version>
</dependency>
</dependencies>
</project>
""")
)
);
}

@Test
void dontAddDependencyWhenAnnotationJsr250Absent() {
rewriteRun(
mavenProject("my-project",
//language=java
srcMainJava(java("""
class A {
}
""",
src -> src.markers(javaVersion(8)))),
//language=xml
pomXml("""
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0.0</version>
<dependencies>
</dependencies>
</project>
""")
"""
)
)
);
}

}

0 comments on commit e46e6aa

Please sign in to comment.