-
Notifications
You must be signed in to change notification settings - Fork 101
feat: Missing "Add explicit Common Annotations dependencies" in "Migrate to Java 11" #456
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
Merged
timtebeek
merged 6 commits into
openrewrite:main
from
ghusta:add-AddCommonAnnotationsDependencies-recipe
Apr 22, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
191a3c4
feat: Missing "Add explicit Common Annotations dependencies" in "Migr…
ghusta 3166a8e
Merge branch 'main' into add-AddCommonAnnotationsDependencies-recipe
timtebeek f106fa3
Apply suggestions from code review
timtebeek 71554d5
Apply suggestions from code review
ghusta da92471
Merge branch 'main' into add-AddCommonAnnotationsDependencies-recipe
timtebeek e46e6aa
Minor touch ups
timtebeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/resources/META-INF/rewrite/add-common-annotations-dependencies.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/test/java/org/openrewrite/java/migrate/javax/AddCommonAnnotationsDependenciesTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
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> | ||
""" | ||
) | ||
) | ||
); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.