Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Missing "Add explicit Common Annotations dependencies" in "Migrate to Java 11" #456

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ dependencies {
testRuntimeOnly("com.fasterxml.jackson.core:jackson-core")
testRuntimeOnly("com.fasterxml.jackson.core:jackson-databind")
testRuntimeOnly("org.codehaus.groovy:groovy:latest.release")
testRuntimeOnly("jakarta.annotation:jakarta.annotation-api:1.3.5")
testRuntimeOnly(gradleApi())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# 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.
#
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.javax.AddCommonAnnotationsDependencies
displayName: Add explicit Common Annotations dependencies
description: >
Add the necessary `annotation-api` dependency from Jakarta EE 8 to maintain compatibility with Java version 11 or greater.
tags:
- javax
- java11
- jsr250
- jakarta
recipeList:
# Add or update the jakarta.annotation-api to a maven project. This artifact still uses the javax.annotation name space.
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: javax.annotation
oldArtifactId: javax.annotation-api
newGroupId: jakarta.annotation
newArtifactId: jakarta.annotation-api
newVersion: 1.3.x
- org.openrewrite.java.dependencies.AddDependency:
groupId: jakarta.annotation
artifactId: jakarta.annotation-api
version: 1.3.x
onlyIfUsing: javax.annotation..*
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
1 change: 1 addition & 0 deletions src/main/resources/META-INF/rewrite/java-version-11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ recipeList:
- org.openrewrite.java.migrate.javax.AddJaxbDependencies
- org.openrewrite.java.migrate.javax.AddJaxwsDependencies
- org.openrewrite.java.migrate.javax.AddInjectDependencies
- org.openrewrite.java.migrate.javax.AddCommonAnnotationsDependencies
# Remediate deprecations
- org.openrewrite.staticanalysis.BigDecimalRoundingConstantsToEnums
- org.openrewrite.staticanalysis.PrimitiveWrapperClassConstructorToValueOf
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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.javax;
timtebeek marked this conversation as resolved.
Show resolved Hide resolved

import org.junit.jupiter.api.Test;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

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

class AddCommonAnnotationsDependenciesTest implements RewriteTest {

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

@Test
void addDependencyIfAnnotationJsr250Present() {
rewriteRun(
spec -> spec.parser(JavaParser.fromJavaVersion().classpath("jakarta.annotation-api")),
mavenProject("my-project",
//language=java
srcMainJava(
java(
"""
import javax.annotation.Generated;

@Generated("Hello")
class A {
}
"""
)
),
//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>
</project>
""",
"""
<?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>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>1.3.5</version>
</dependency>
</dependencies>
</project>
"""
)
)
);
}
}