Skip to content

Commit

Permalink
Further work on improving support for removing plugins. Add support f… (
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc authored Mar 18, 2022
1 parent c78ec90 commit e0a30f1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 39 deletions.
10 changes: 6 additions & 4 deletions common/src/main/java/org/jboss/gm/common/utils/PluginUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -25,14 +25,16 @@
import org.slf4j.Logger;

public class PluginUtils {
private static final Map<String, Pair<String, Set<String>>> SUPPORTED_PLUGINS = new HashMap<>();
private static final Map<String, Pair<String, Set<String>>> SUPPORTED_PLUGINS = new LinkedHashMap<>();

public static final String SEMANTIC_BUILD_VERSIONING = "net.vivin.gradle-semantic-build-versioning";

static {
// Pair left is tasks, right is configuration
SUPPORTED_PLUGINS.put("com.github.ben-manes.versions", Pair.of("dependencyUpdates", Collections.emptySet()));
SUPPORTED_PLUGINS.put("com.github.burrunan.s3-build-cache", Pair.of("buildCache", Collections.emptySet()));
SUPPORTED_PLUGINS.put("de.marcphilipp.nexus-publish", Pair.of("nexusPublishing", Collections.emptySet()));
SUPPORTED_PLUGINS.put("de.marcphilipp.nexus-publish",
Pair.of("nexusPublishing", Collections.singleton("publishToSonatype")));
SUPPORTED_PLUGINS.put("gradle-enterprise", Pair.of("gradleEnterprise", Collections.emptySet()));
SUPPORTED_PLUGINS.put("io.codearte.nexus-staging",
Pair.of("nexusStaging", Stream.of("closeRepository", "releaseRepository", "closeAndReleaseRepository").collect(
Expand Down Expand Up @@ -66,8 +68,8 @@ public static void pluginRemoval(Logger logger, File target, Set<String> plugins
// As the configuration block is named the same as the plugin we differentiate via the
// potential quoting mechanism to avoid problems when parsing the file to remove the plugins
if (plugins.remove("signing")) {
plugins.add("'signing'");
plugins.add("\"signing\"");
plugins.add("'signing'");
}

Collection<File> files = new HashSet<>();
Expand Down
82 changes: 47 additions & 35 deletions common/src/test/java/org/jboss/gm/common/utils/PluginUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;

import org.apache.commons.io.FileUtils;
import org.commonjava.maven.ext.common.ManipulationException;
Expand Down Expand Up @@ -217,7 +218,7 @@ public void testRemoval2()
+ "if (true) { }\n",
Charset.defaultCharset());

HashSet<String> plugins = new HashSet<>();
HashSet<String> plugins = new LinkedHashSet<>();
plugins.add("com.github.burrunan.s3-build-cache");
plugins.add("gradle-enterprise");
PluginUtils.pluginRemoval(logger, target.getParentFile(), plugins);
Expand Down Expand Up @@ -283,7 +284,7 @@ public void testRemoval4()
Charset.defaultCharset());

// Avoid singleton as the set is manipulated within the method
PluginUtils.pluginRemoval(logger, target.getParentFile(), new HashSet<>(Collections.singleton("ALL")));
PluginUtils.pluginRemoval(logger, target.getParentFile(), new LinkedHashSet<>(Collections.singleton("ALL")));

assertTrue(systemOutRule.getLog()
.contains("Removed instances of plugin gradle-enterprise with configuration block of gradleEnterprise from"));
Expand Down Expand Up @@ -330,7 +331,7 @@ public void testRemoval5()
+ "}\n", Charset.defaultCharset());

// Avoid singleton as the set is manipulated within the method
PluginUtils.pluginRemoval(logger, target.getParentFile(), new HashSet<>(Collections.singleton("ALL")));
PluginUtils.pluginRemoval(logger, target.getParentFile(), new LinkedHashSet<>(Collections.singleton("ALL")));

assertTrue(systemOutRule.getLog()
.contains("Removed instances of plugin \"signing\" with configuration block of signing from"));
Expand All @@ -344,45 +345,56 @@ 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",
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" + "\n" + "afterEvaluate {\n"
+ " val publishToSonatype by tasks.getting\n" + " val release by rootProject.tasks.existing\n"
+ " release.configure {\n" + " finalizedBy(publishToSonatype)\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",
Charset.defaultCharset());

// Avoid singleton as the set is manipulated within the method
PluginUtils.pluginRemoval(logger, target.getParentFile(), new HashSet<>(Collections.singleton("ALL")));
PluginUtils.pluginRemoval(logger, target.getParentFile(), new LinkedHashSet<>(Collections.singleton("ALL")));

assertTrue(systemOutRule.getLog()
.contains("Removed instances of plugin \"signing\" with configuration block of signing from"));

assertFalse(FileUtils.readFileToString(target, Charset.defaultCharset()).contains("publishToSonatype"));
assertTrue(FileUtils.readFileToString(target, Charset.defaultCharset()).contains(" id(\"otel.japicmp-conventions\")\n"
+ "}\n" + "\n"
+ "publishing {\n"
Expand Down

0 comments on commit e0a30f1

Please sign in to comment.