Skip to content
Merged
38 changes: 19 additions & 19 deletions src/main/resources/META-INF/rewrite/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3279,25 +3279,6 @@ examples:
type: specs.openrewrite.org/v1beta/example
recipeName: org.openrewrite.java.migrate.guava.NoGuava
examples:
- description: ''
sources:
- before: |
import com.google.common.base.MoreObjects;

class A {
Object foo(Object obj) {
return MoreObjects.firstNonNull(obj, "default");
}
}
after: |
import java.util.Objects;

class A {
Object foo(Object obj) {
return Objects.requireNonNullElse(obj, "default");
}
}
language: java
- description: ''
sources:
- before: |
Expand Down Expand Up @@ -3344,6 +3325,25 @@ examples:
}
}
language: java
- description: ''
sources:
- before: |
import com.google.common.base.MoreObjects;

class A {
Object foo(Object obj) {
return MoreObjects.firstNonNull(obj, "default");
}
}
after: |
import java.util.Objects;

class A {
Object foo(Object obj) {
return Objects.requireNonNullElse(obj, "default");
}
}
language: java
---
type: specs.openrewrite.org/v1beta/example
recipeName: org.openrewrite.java.migrate.guava.NoGuavaAtomicsNewReference
Expand Down
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
Comment on lines +28 to +32
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@steve-aom-elliott steve-aom-elliott May 13, 2025

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.

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;

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);
})
)
);
}
}