Skip to content

Commit

Permalink
Better support for removing signing plugin under Kotlin (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc authored Mar 17, 2022
1 parent e9c5207 commit c78ec90
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public static void pluginRemoval(Logger logger, File target, Set<String> 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
Expand Down
100 changes: 99 additions & 1 deletion common/src/test/java/org/jboss/gm/common/utils/PluginUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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>(\"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>(\"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 {
Expand Down

0 comments on commit c78ec90

Please sign in to comment.