From c82c73a85d7f5f13523d09a4709bf61dba9f7b53 Mon Sep 17 00:00:00 2001 From: Nick McKinney Date: Thu, 2 May 2024 12:02:48 -0600 Subject: [PATCH] =?UTF-8?q?jacoco=20upgrade=20now=20includes=20arbitrary?= =?UTF-8?q?=20jacoco=20deps=20(eg=20agent),=20always=20=E2=80=A6=20(#471)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * jacoco upgrade now includes arbitrary jacoco deps (eg agent), always sends to highest patch version, and happens in the java 6 recipe (and therefore runs at every java upgrade) * test fix * Remove constant from test to guard against new releases --------- Co-authored-by: Tim te Beek --- .../resources/META-INF/rewrite/jacoco.yml | 13 +- .../META-INF/rewrite/java-version-11.yml | 1 - .../META-INF/rewrite/java-version-21.yml | 4 - .../META-INF/rewrite/java-version-6.yml | 1 + .../java/migrate/UpgradeToJava6Test.java | 2 +- .../UpgradeJaCoCoMavenPluginVersionTest.java | 85 ----- .../migrate/jacoco/UpgradeJaCoCoTest.java | 319 ++++++++++++++++++ 7 files changed, 329 insertions(+), 96 deletions(-) delete mode 100644 src/test/java/org/openrewrite/java/migrate/jacoco/UpgradeJaCoCoMavenPluginVersionTest.java create mode 100644 src/test/java/org/openrewrite/java/migrate/jacoco/UpgradeJaCoCoTest.java diff --git a/src/main/resources/META-INF/rewrite/jacoco.yml b/src/main/resources/META-INF/rewrite/jacoco.yml index e10146c33c..6fd953db1c 100644 --- a/src/main/resources/META-INF/rewrite/jacoco.yml +++ b/src/main/resources/META-INF/rewrite/jacoco.yml @@ -19,14 +19,17 @@ name: 'JaCoCo' packageName: org.openrewrite.java.migrate.jacoco --- type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.java.migrate.jacoco.UpgradeJaCoCoMavenPluginVersion -displayName: Upgrade JaCoCo Maven plugin version -description: This recipe will upgrade the JaCoCo Maven plugin to a more recent version compatible with Java 11. +name: org.openrewrite.java.migrate.jacoco.UpgradeJaCoCo +displayName: Upgrade JaCoCo +description: This recipe will upgrade JaCoCo to the latest patch version, which traditionally advertises full backwards compatibility for older Java versions. tags: - - java11 - jacoco recipeList: + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.jacoco + artifactId: "*" + newVersion: 0.8.x - org.openrewrite.maven.UpgradePluginVersion: groupId: org.jacoco artifactId: jacoco-maven-plugin - newVersion: 0.8.8 + newVersion: 0.8.x diff --git a/src/main/resources/META-INF/rewrite/java-version-11.yml b/src/main/resources/META-INF/rewrite/java-version-11.yml index 7c9347f41e..8147eacec1 100644 --- a/src/main/resources/META-INF/rewrite/java-version-11.yml +++ b/src/main/resources/META-INF/rewrite/java-version-11.yml @@ -56,7 +56,6 @@ recipeList: - org.openrewrite.java.migrate.javax.JavaxXmlStreamAPIs - org.openrewrite.java.migrate.cobertura.RemoveCoberturaMavenPlugin - org.openrewrite.java.migrate.wro4j.UpgradeWro4jMavenPluginVersion - - org.openrewrite.java.migrate.jacoco.UpgradeJaCoCoMavenPluginVersion - org.openrewrite.java.migrate.UpgradeJavaVersion: version: 11 - org.openrewrite.maven.UpgradePluginVersion: diff --git a/src/main/resources/META-INF/rewrite/java-version-21.yml b/src/main/resources/META-INF/rewrite/java-version-21.yml index 309c481658..778444b17d 100644 --- a/src/main/resources/META-INF/rewrite/java-version-21.yml +++ b/src/main/resources/META-INF/rewrite/java-version-21.yml @@ -38,10 +38,6 @@ recipeList: - org.openrewrite.gradle.UpdateGradleWrapper: version: 8.5 addIfMissing: false - - org.openrewrite.maven.UpgradePluginVersion: - groupId: org.jacoco - artifactId: jacoco-maven-plugin - newVersion: 0.8.+ - org.openrewrite.maven.UpgradePluginVersion: groupId: com.sonatype.clm artifactId: clm-maven-plugin diff --git a/src/main/resources/META-INF/rewrite/java-version-6.yml b/src/main/resources/META-INF/rewrite/java-version-6.yml index 8f5c6f34bf..370a715af9 100644 --- a/src/main/resources/META-INF/rewrite/java-version-6.yml +++ b/src/main/resources/META-INF/rewrite/java-version-6.yml @@ -30,6 +30,7 @@ name: org.openrewrite.java.migrate.JREWrapperInterface displayName: Add missing `isWrapperFor` and `unwrap` methods. description: Add method implementations stubs to classes that implement `java.sql.Wrapper`. recipeList: + - org.openrewrite.java.migrate.jacoco.UpgradeJaCoCo - org.openrewrite.java.migrate.AddMissingMethodImplementation: fullyQualifiedClassName: java.sql.Wrapper methodPattern: "*..* isWrapperFor(..)" diff --git a/src/test/java/org/openrewrite/java/migrate/UpgradeToJava6Test.java b/src/test/java/org/openrewrite/java/migrate/UpgradeToJava6Test.java index 00237e39ce..c9a67a7729 100644 --- a/src/test/java/org/openrewrite/java/migrate/UpgradeToJava6Test.java +++ b/src/test/java/org/openrewrite/java/migrate/UpgradeToJava6Test.java @@ -27,7 +27,7 @@ class UpgradeToJava6Test implements RewriteTest { @Override public void defaults(RecipeSpec spec) { - spec.recipeFromResource("/META-INF/rewrite/java-version-6.yml", "org.openrewrite.java.migrate.UpgradeToJava6") + spec.recipeFromResources("org.openrewrite.java.migrate.UpgradeToJava6") .allSources(src -> src.markers(javaVersion(6))); } diff --git a/src/test/java/org/openrewrite/java/migrate/jacoco/UpgradeJaCoCoMavenPluginVersionTest.java b/src/test/java/org/openrewrite/java/migrate/jacoco/UpgradeJaCoCoMavenPluginVersionTest.java deleted file mode 100644 index 28813bd98a..0000000000 --- a/src/test/java/org/openrewrite/java/migrate/jacoco/UpgradeJaCoCoMavenPluginVersionTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2022 the original author or authors. - *

- * 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 - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * 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.jacoco; - -import org.junit.jupiter.api.Test; -import org.openrewrite.DocumentExample; -import org.openrewrite.config.Environment; -import org.openrewrite.test.RecipeSpec; -import org.openrewrite.test.RewriteTest; - -import static org.openrewrite.maven.Assertions.pomXml; - - -class UpgradeJaCoCoMavenPluginVersionTest implements RewriteTest { - @Override - public void defaults(RecipeSpec spec) { - spec.recipe(Environment.builder() - .scanRuntimeClasspath("org.openrewrite.java.migrate.jacoco") - .build() - .activateRecipes("org.openrewrite.java.migrate.jacoco.UpgradeJaCoCoMavenPluginVersion")); - } - - @DocumentExample - @Test - void property() { - rewriteRun( - //language=xml - pomXml( - """ - - - 0.8.1 - - - com.mycompany.app - my-app - 1 - - - - org.jacoco - jacoco-maven-plugin - ${jacoco.version} - - - - - """, - """ - - - 0.8.8 - - - com.mycompany.app - my-app - 1 - - - - org.jacoco - jacoco-maven-plugin - ${jacoco.version} - - - - - """ - ) - ); - } -} diff --git a/src/test/java/org/openrewrite/java/migrate/jacoco/UpgradeJaCoCoTest.java b/src/test/java/org/openrewrite/java/migrate/jacoco/UpgradeJaCoCoTest.java new file mode 100644 index 0000000000..4a22697a2a --- /dev/null +++ b/src/test/java/org/openrewrite/java/migrate/jacoco/UpgradeJaCoCoTest.java @@ -0,0 +1,319 @@ +/* + * Copyright 2022 the original author or authors. + *

+ * 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 + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.jacoco; + +import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import java.util.regex.Pattern; + +import static org.openrewrite.maven.Assertions.pomXml; + +class UpgradeJaCoCoTest implements RewriteTest { + private static final Pattern JACOCO_VERSION_PATTERN = Pattern.compile("(0\\.8\\.\\d\\d+)"); + + @Override + public void defaults(RecipeSpec spec) { + spec.recipeFromResources("org.openrewrite.java.migrate.jacoco.UpgradeJaCoCo"); + } + + @DocumentExample + @Test + void pluginWithProperty() { + rewriteRun( + //language=xml + pomXml( + """ + + + 0.8.1 + + com.mycompany.app + my-app + 1 + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + + + """, + spec -> spec.after(pomXml -> String.format(""" + + + %s + + com.mycompany.app + my-app + 1 + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + + + """, JACOCO_VERSION_PATTERN.matcher(pomXml).results().findFirst().get().group(1))) + ) + ); + } + + @Test + void pluginAndDepWithProperty() { + rewriteRun( + //language=xml + pomXml( + """ + + + 0.8.1 + + + com.mycompany.app + my-app + 1 + + + org.jacoco + org.jacoco.agent + runtime + test + ${jacoco.version} + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + + + """, + spec -> spec.after(pomXml -> String.format(""" + + + %s + + + com.mycompany.app + my-app + 1 + + + org.jacoco + org.jacoco.agent + runtime + test + ${jacoco.version} + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + + + """, JACOCO_VERSION_PATTERN.matcher(pomXml).results().findFirst().get().group(1)) + ) + ) + ); + } + + @Test + void pluginAndDepAndDepMgmt() { + Pattern versionPattern = Pattern.compile("(0\\.8\\.\\d\\d+)"); + rewriteRun( + //language=xml + pomXml( + """ + + com.mycompany.app + my-app + 1 + + + + org.jacoco + org.jacoco.agent + 0.8.1 + runtime + test + + + + + + org.jacoco + org.jacoco.agent + runtime + test + + + + + + org.jacoco + jacoco-maven-plugin + 0.8.1 + + + + + """, + spec -> spec.after(pomXml -> String.format(""" + + com.mycompany.app + my-app + 1 + + + + org.jacoco + org.jacoco.agent + %s + runtime + test + + + + + + org.jacoco + org.jacoco.agent + runtime + test + + + + + + org.jacoco + jacoco-maven-plugin + %1$s + + + + + """, versionPattern.matcher(pomXml).results().findFirst().get().group(1)) + ) + ) + ); + } + + @Test + void pluginAndDepAndDepMgmtWithProperty() { + rewriteRun( + //language=xml + pomXml( + """ + + + 0.8.1 + + + com.mycompany.app + my-app + 1 + + + + org.jacoco + org.jacoco.agent + ${jacoco.version} + runtime + test + + + + + + org.jacoco + org.jacoco.agent + runtime + test + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + + + """, + spec -> spec.after(pomXml -> String.format(""" + + + %s + + + com.mycompany.app + my-app + 1 + + + + org.jacoco + org.jacoco.agent + ${jacoco.version} + runtime + test + + + + + + org.jacoco + org.jacoco.agent + runtime + test + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + + + """, JACOCO_VERSION_PATTERN.matcher(pomXml).results().findFirst().get().group(1)) + ) + ) + ); + } +}