Skip to content

Commit f63fca7

Browse files
steve-aom-elliotttimtebeekJenson3210
authored
Migrate com:intellij:annotations to org.jetbrains:annotations (#719)
* Adding declarative recipe for migrating `com.intellij:annotations` dependencies to `org.jetbrains:annotations`. As noted in the issue, the packages used within the dependencies were already using `org.jetbrains.annotations` back to the oldest available version of `com.intelli:annotations` so packages do not need to be migrated. --------- Co-authored-by: Tim te Beek <[email protected]> Co-authored-by: Jente Sondervorst <[email protected]>
1 parent 577c7f2 commit f63fca7

File tree

3 files changed

+172
-19
lines changed

3 files changed

+172
-19
lines changed

src/main/resources/META-INF/rewrite/examples.yml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,25 +3279,6 @@ examples:
32793279
type: specs.openrewrite.org/v1beta/example
32803280
recipeName: org.openrewrite.java.migrate.guava.NoGuava
32813281
examples:
3282-
- description: ''
3283-
sources:
3284-
- before: |
3285-
import com.google.common.base.MoreObjects;
3286-
3287-
class A {
3288-
Object foo(Object obj) {
3289-
return MoreObjects.firstNonNull(obj, "default");
3290-
}
3291-
}
3292-
after: |
3293-
import java.util.Objects;
3294-
3295-
class A {
3296-
Object foo(Object obj) {
3297-
return Objects.requireNonNullElse(obj, "default");
3298-
}
3299-
}
3300-
language: java
33013282
- description: ''
33023283
sources:
33033284
- before: |
@@ -3344,6 +3325,25 @@ examples:
33443325
}
33453326
}
33463327
language: java
3328+
- description: ''
3329+
sources:
3330+
- before: |
3331+
import com.google.common.base.MoreObjects;
3332+
3333+
class A {
3334+
Object foo(Object obj) {
3335+
return MoreObjects.firstNonNull(obj, "default");
3336+
}
3337+
}
3338+
after: |
3339+
import java.util.Objects;
3340+
3341+
class A {
3342+
Object foo(Object obj) {
3343+
return Objects.requireNonNullElse(obj, "default");
3344+
}
3345+
}
3346+
language: java
33473347
---
33483348
type: specs.openrewrite.org/v1beta/example
33493349
recipeName: org.openrewrite.java.migrate.guava.NoGuavaAtomicsNewReference
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# Copyright 2025 the original author or authors.
3+
# <p>
4+
# Licensed under the Moderne Source Available License (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# <p>
8+
# https://docs.moderne.io/licensing/moderne-source-available-license
9+
# <p>
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
---
18+
type: specs.openrewrite.org/v1beta/recipe
19+
name: org.openrewrite.java.migrate.ComIntelliJAnnotationsToOrgJetbrainsAnnotations
20+
displayName: Migrate com.intellij:annotations to org.jetbrains:annotations
21+
description: >-
22+
This recipe will upgrade old dependency of com.intellij:annotations to the newer org.jetbrains:annotations.
23+
tags:
24+
- intellij
25+
- jetbrains
26+
- annotations
27+
recipeList:
28+
- org.openrewrite.java.dependencies.ChangeDependency:
29+
oldGroupId: com.intellij
30+
oldArtifactId: annotations
31+
newGroupId: org.jetbrains
32+
newVersion: latest.release
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
* <p>
4+
* Licensed under the Moderne Source Available License (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://docs.moderne.io/licensing/moderne-source-available-license
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite.java.migrate;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.openrewrite.maven.tree.MavenResolutionResult;
20+
import org.openrewrite.maven.tree.Scope;
21+
import org.openrewrite.test.RecipeSpec;
22+
import org.openrewrite.test.RewriteTest;
23+
24+
import java.util.regex.Matcher;
25+
import java.util.regex.Pattern;
26+
27+
import static java.util.function.UnaryOperator.identity;
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
import static org.openrewrite.gradle.Assertions.buildGradle;
30+
import static org.openrewrite.gradle.toolingapi.Assertions.withToolingApi;
31+
import static org.openrewrite.java.Assertions.mavenProject;
32+
import static org.openrewrite.maven.Assertions.pomXml;
33+
34+
class ComIntelliJAnnotationsToOrgJetbrainsAnnotationsTest implements RewriteTest {
35+
@Override
36+
public void defaults(RecipeSpec spec) {
37+
spec.beforeRecipe(withToolingApi())
38+
.recipeFromResource(
39+
"/META-INF/rewrite/intellij-annotations-to-jetbrains-annotations.yml",
40+
"org.openrewrite.java.migrate.ComIntelliJAnnotationsToOrgJetbrainsAnnotations"
41+
);
42+
}
43+
44+
@Test
45+
void mavenDependencyUpdate() {
46+
rewriteRun(
47+
mavenProject("project",
48+
pomXml(
49+
//language=xml
50+
"""
51+
<project>
52+
<modelVersion>4.0.0</modelVersion>
53+
54+
<groupId>com.mycompany.app</groupId>
55+
<artifactId>my-app</artifactId>
56+
<version>1</version>
57+
58+
<dependencies>
59+
<dependency>
60+
<groupId>com.intellij</groupId>
61+
<artifactId>annotations</artifactId>
62+
<version>5.1</version>
63+
</dependency>
64+
</dependencies>
65+
</project>
66+
""",
67+
spec -> spec
68+
.after(identity())
69+
.afterRecipe(doc -> assertThat(doc.getMarkers().findFirst(MavenResolutionResult.class)
70+
.get().getDependencies().get(Scope.Compile))
71+
.filteredOn(rd -> rd.getDepth() == 0)
72+
.satisfiesExactly(
73+
rd -> {
74+
assertThat(rd.getGroupId()).isEqualTo("org.jetbrains");
75+
assertThat(rd.getArtifactId()).isEqualTo("annotations");
76+
}))
77+
)
78+
)
79+
);
80+
}
81+
82+
@Test
83+
void gradleDependencyUpdates() {
84+
rewriteRun(
85+
buildGradle(
86+
//language=groovy
87+
"""
88+
plugins {
89+
id("java-library")
90+
}
91+
repositories {
92+
mavenCentral()
93+
}
94+
dependencies {
95+
implementation("com.intellij:annotations:5.1")
96+
implementation "com.intellij:annotations:6.0.3"
97+
implementation group: "com.intellij", name: "annotations", version: "12.0"
98+
}
99+
""",
100+
spec -> spec.after(buildGradle -> {
101+
Matcher version = Pattern.compile("\\d+\\.\\d+(\\.\\d+)?").matcher(buildGradle);
102+
assertThat(version.find()).isTrue();
103+
String dependencyVersion = version.group(0);
104+
return """
105+
plugins {
106+
id("java-library")
107+
}
108+
repositories {
109+
mavenCentral()
110+
}
111+
dependencies {
112+
implementation("org.jetbrains:annotations:%1$s")
113+
implementation "org.jetbrains:annotations:%1$s"
114+
implementation group: "org.jetbrains", name: "annotations", version: "%1$s"
115+
}
116+
""".formatted(dependencyVersion);
117+
})
118+
)
119+
);
120+
}
121+
}

0 commit comments

Comments
 (0)