From c78ec900e18aa742585c1e2e9367d16a08ce4486 Mon Sep 17 00:00:00 2001 From: Nick Cross Date: Thu, 17 Mar 2022 20:24:49 +0000 Subject: [PATCH] Better support for removing signing plugin under Kotlin (#369) --- .../jboss/gm/common/utils/PluginUtils.java | 3 + .../gm/common/utils/PluginUtilsTest.java | 100 +++++++++++++++++- 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/jboss/gm/common/utils/PluginUtils.java b/common/src/main/java/org/jboss/gm/common/utils/PluginUtils.java index 083d7894..e84f09ef 100644 --- a/common/src/main/java/org/jboss/gm/common/utils/PluginUtils.java +++ b/common/src/main/java/org/jboss/gm/common/utils/PluginUtils.java @@ -105,6 +105,9 @@ public static void pluginRemoval(Logger logger, File target, Set plugins // Remove the plugin boolean removed = lines.removeIf(i -> i.contains(plugin)); + // This handles the scenario, often in Kotlin build files where the plugin may be just + // its name i.e. signing without any quotes or brackets + removed |= lines.removeIf(i -> i.contains(plugin.replace("\"", "")) && !i.contains("{")); // Remove any task references. // TODO: Handle if the task reference spans multiple lines diff --git a/common/src/test/java/org/jboss/gm/common/utils/PluginUtilsTest.java b/common/src/test/java/org/jboss/gm/common/utils/PluginUtilsTest.java index 471442c9..501f2a95 100644 --- a/common/src/test/java/org/jboss/gm/common/utils/PluginUtilsTest.java +++ b/common/src/test/java/org/jboss/gm/common/utils/PluginUtilsTest.java @@ -333,12 +333,110 @@ public void testRemoval5() PluginUtils.pluginRemoval(logger, target.getParentFile(), new HashSet<>(Collections.singleton("ALL"))); assertTrue(systemOutRule.getLog() - .contains("Removed instances of plugin 'signing' with configuration block of signing from")); + .contains("Removed instances of plugin \"signing\" with configuration block of signing from")); assertFalse(FileUtils.readFileToString(target, Charset.defaultCharset()).contains("com.github.ben-manes.versions")); assertTrue(FileUtils.readFileToString(subtarget, Charset.defaultCharset()).trim().isEmpty()); } + @Test + public void testRemoval6() + throws IOException, ManipulationException { + + File target = folder.newFile("build.gradle.kts"); + org.apache.commons.io.FileUtils.writeStringToFile(target, + "plugins {\n" + " `maven-publish`\n" + " signing\n" + "\n" + " id(\"otel.japicmp-conventions\")\n" + + "}\n" + "\n" + "publishing {\n" + " publications {\n" + + " register(\"mavenPublication\") {\n" + + " val release = findProperty(\"otel.release\")\n" + " if (release != null) {\n" + + " val versionParts = version.split('-').toMutableList()\n" + + " versionParts[0] += \"-$release\"\n" + + " version = versionParts.joinToString(\"-\")\n" + " }\n" + + " groupId = \"io.opentelemetry\"\n" + " afterEvaluate {\n" + + " // not available until evaluated.\n" + " artifactId = base.archivesName.get()\n" + + " pom.description.set(project.description)\n" + " }\n" + "\n" + + " plugins.withId(\"java-platform\") {\n" + " from(components[\"javaPlatform\"])\n" + + " }\n" + " plugins.withId(\"java-library\") {\n" + + " from(components[\"java\"])\n" + " }\n" + "\n" + " versionMapping {\n" + + " allVariants {\n" + " fromResolutionResult()\n" + " }\n" + " }\n" + + "\n" + " pom {\n" + " name.set(\"OpenTelemetry Java\")\n" + + " url.set(\"https://github.com/open-telemetry/opentelemetry-java\")\n" + "\n" + + " licenses {\n" + " license {\n" + + " name.set(\"The Apache License, Version 2.0\")\n" + + " url.set(\"http://www.apache.org/licenses/LICENSE-2.0.txt\")\n" + " }\n" + + " }\n" + "\n" + " developers {\n" + " developer {\n" + + " id.set(\"opentelemetry\")\n" + " name.set(\"OpenTelemetry\")\n" + + " url.set(\"https://github.com/open-telemetry/community\")\n" + " }\n" + + " }\n" + "\n" + " scm {\n" + + " connection.set(\"scm:git:git@github.com:open-telemetry/opentelemetry-java.git\")\n" + + " developerConnection.set(\"scm:git:git@github.com:open-telemetry/opentelemetry-java.git\")\n" + + " url.set(\"git@github.com:open-telemetry/opentelemetry-java.git\")\n" + " }\n" + + " }\n" + " }\n" + " }\n" + "}\n" + "if (System.getenv(\"CI\") != null) {\n" + + " signing {\n" + + " useInMemoryPgpKeys(System.getenv(\"GPG_PRIVATE_KEY\"), System.getenv(\"GPG_PASSWORD\"))\n" + + " sign(publishing.publications[\"mavenPublication\"])\n" + " }\n" + "}\n\n", + Charset.defaultCharset()); + + // Avoid singleton as the set is manipulated within the method + PluginUtils.pluginRemoval(logger, target.getParentFile(), new HashSet<>(Collections.singleton("ALL"))); + + assertTrue(systemOutRule.getLog() + .contains("Removed instances of plugin \"signing\" with configuration block of signing from")); + + assertTrue(FileUtils.readFileToString(target, Charset.defaultCharset()).contains(" id(\"otel.japicmp-conventions\")\n" + + "}\n" + "\n" + + "publishing {\n" + + " publications {\n" + + " register(\"mavenPublication\") {\n" + + " val release = findProperty(\"otel.release\")\n" + + " if (release != null) {\n" + + " val versionParts = version.split('-').toMutableList()\n" + + " versionParts[0] += \"-$release\"\n" + + " version = versionParts.joinToString(\"-\")\n" + + " }\n" + + " groupId = \"io.opentelemetry\"\n" + + " afterEvaluate {\n" + + " // not available until evaluated.\n" + + " artifactId = base.archivesName.get()\n" + + " pom.description.set(project.description)\n" + + " }\n" + "\n" + + " plugins.withId(\"java-platform\") {\n" + + " from(components[\"javaPlatform\"])\n" + + " }\n" + + " plugins.withId(\"java-library\") {\n" + + " from(components[\"java\"])\n" + + " }\n" + "\n" + + " versionMapping {\n" + + " allVariants {\n" + + " fromResolutionResult()\n" + + " }\n" + + " }\n" + "\n" + + " pom {\n" + + " name.set(\"OpenTelemetry Java\")\n" + + " url.set(\"https://github.com/open-telemetry/opentelemetry-java\")\n" + + "\n" + + " licenses {\n" + + " license {\n" + + " name.set(\"The Apache License, Version 2.0\")\n" + + " url.set(\"http://www.apache.org/licenses/LICENSE-2.0.txt\")\n" + + " }\n" + + " }\n" + "\n" + + " developers {\n" + + " developer {\n" + + " id.set(\"opentelemetry\")\n" + + " name.set(\"OpenTelemetry\")\n" + + " url.set(\"https://github.com/open-telemetry/community\")\n" + + " }\n" + + " }\n" + "\n" + + " scm {\n" + + " connection.set(\"scm:git:git@github.com:open-telemetry/opentelemetry-java.git\")\n" + + " developerConnection.set(\"scm:git:git@github.com:open-telemetry/opentelemetry-java.git\")\n" + + " url.set(\"git@github.com:open-telemetry/opentelemetry-java.git\")\n" + + " }\n" + + " }\n" + " }\n" + + " }\n" + "}\n")); + } + @Test public void testCheckForSemanticPlugin1() throws IOException, ManipulationException {