-
Notifications
You must be signed in to change notification settings - Fork 112
Migrate com:intellij:annotations to org.jetbrains:annotations
#719
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
steve-aom-elliott
merged 7 commits into
main
from
289-com-intellij-annotations-to-org-jetbrains-annotations
May 13, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
38c3fd7
Adding declarative recipe for migrating `com.intellij:annotations` de…
steve-aom-elliott 155be9d
Update src/test/java/org/openrewrite/java/migrate/ComIntelliJAnnotati…
timtebeek 431ddf0
Update src/test/java/org/openrewrite/java/migrate/ComIntelliJAnnotati…
timtebeek 95d770c
Update src/test/java/org/openrewrite/java/migrate/ComIntelliJAnnotati…
timtebeek f4542aa
Trying to reformat license header
steve-aom-elliott 821e014
polishing + examples updated
Jenson3210 3375afd
Removing example from examples file and the `@DocumentExample` annota…
steve-aom-elliott 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
32 changes: 32 additions & 0 deletions
32
src/main/resources/META-INF/rewrite/intellij-annotations-to-jetbrains-annotations.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,32 @@ | ||
| # | ||
| # Copyright 2025 the original author or authors. | ||
| # <p> | ||
| # Licensed under the Moderne Source Available License (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://docs.moderne.io/licensing/moderne-source-available-license | ||
| # <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.ComIntelliJAnnotationsToOrgJetbrainsAnnotations | ||
| displayName: Migrate com.intellij:annotations to org.jetbrains:annotations | ||
| description: >- | ||
| This recipe will upgrade old dependency of com.intellij:annotations to the newer org.jetbrains:annotations. | ||
| tags: | ||
| - intellij | ||
| - jetbrains | ||
| - annotations | ||
| recipeList: | ||
| - org.openrewrite.java.dependencies.ChangeDependency: | ||
| oldGroupId: com.intellij | ||
| oldArtifactId: annotations | ||
| newGroupId: org.jetbrains | ||
| newVersion: latest.release | ||
121 changes: 121 additions & 0 deletions
121
...ava/org/openrewrite/java/migrate/ComIntelliJAnnotationsToOrgJetbrainsAnnotationsTest.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,121 @@ | ||
| /* | ||
| * Copyright 2025 the original author or authors. | ||
| * <p> | ||
| * Licensed under the Moderne Source Available License (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://docs.moderne.io/licensing/moderne-source-available-license | ||
| * <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; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.openrewrite.maven.tree.MavenResolutionResult; | ||
| import org.openrewrite.maven.tree.Scope; | ||
| import org.openrewrite.test.RecipeSpec; | ||
| import org.openrewrite.test.RewriteTest; | ||
|
|
||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| import static java.util.function.UnaryOperator.identity; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.openrewrite.gradle.Assertions.buildGradle; | ||
| import static org.openrewrite.gradle.toolingapi.Assertions.withToolingApi; | ||
| import static org.openrewrite.java.Assertions.mavenProject; | ||
| import static org.openrewrite.maven.Assertions.pomXml; | ||
timtebeek marked this conversation as resolved.
Show resolved
Hide resolved
timtebeek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| class ComIntelliJAnnotationsToOrgJetbrainsAnnotationsTest implements RewriteTest { | ||
| @Override | ||
| public void defaults(RecipeSpec spec) { | ||
| spec.beforeRecipe(withToolingApi()) | ||
| .recipeFromResource( | ||
| "/META-INF/rewrite/intellij-annotations-to-jetbrains-annotations.yml", | ||
| "org.openrewrite.java.migrate.ComIntelliJAnnotationsToOrgJetbrainsAnnotations" | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| void mavenDependencyUpdate() { | ||
| rewriteRun( | ||
| mavenProject("project", | ||
| pomXml( | ||
| //language=xml | ||
| """ | ||
| <project> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>com.mycompany.app</groupId> | ||
| <artifactId>my-app</artifactId> | ||
| <version>1</version> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.intellij</groupId> | ||
| <artifactId>annotations</artifactId> | ||
| <version>5.1</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> | ||
| """, | ||
| spec -> spec | ||
| .after(identity()) | ||
| .afterRecipe(doc -> assertThat(doc.getMarkers().findFirst(MavenResolutionResult.class) | ||
| .get().getDependencies().get(Scope.Compile)) | ||
| .filteredOn(rd -> rd.getDepth() == 0) | ||
| .satisfiesExactly( | ||
| rd -> { | ||
| assertThat(rd.getGroupId()).isEqualTo("org.jetbrains"); | ||
| assertThat(rd.getArtifactId()).isEqualTo("annotations"); | ||
| })) | ||
| ) | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| void gradleDependencyUpdates() { | ||
| rewriteRun( | ||
| buildGradle( | ||
| //language=groovy | ||
| """ | ||
| plugins { | ||
| id("java-library") | ||
| } | ||
| repositories { | ||
| mavenCentral() | ||
| } | ||
| dependencies { | ||
| implementation("com.intellij:annotations:5.1") | ||
| implementation "com.intellij:annotations:6.0.3" | ||
| implementation group: "com.intellij", name: "annotations", version: "12.0" | ||
| } | ||
| """, | ||
| spec -> spec.after(buildGradle -> { | ||
| Matcher version = Pattern.compile("\\d+\\.\\d+(\\.\\d+)?").matcher(buildGradle); | ||
| assertThat(version.find()).isTrue(); | ||
| String dependencyVersion = version.group(0); | ||
| return """ | ||
| plugins { | ||
| id("java-library") | ||
| } | ||
| repositories { | ||
| mavenCentral() | ||
| } | ||
| dependencies { | ||
| implementation("org.jetbrains:annotations:%1$s") | ||
| implementation "org.jetbrains:annotations:%1$s" | ||
| implementation group: "org.jetbrains", name: "annotations", version: "%1$s" | ||
| } | ||
| """.formatted(dependencyVersion); | ||
| }) | ||
| ) | ||
| ); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a change package recipe here as well? Or has that not changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The package name didn't change between the dependencies, no.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok; I was going on these import statements
com.intellij:annotationstoorg.jetbrains:annotations#289 (comment)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#289 (comment) They confirmed they didn't change here I believe. For the sake of it, I did also manually verify that was the case by importing the older versions of the library and browsing them in IntelliJ.