From 680fc8285ede0159f4f05dfcfb8c218697ecdad8 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 17 Sep 2020 22:39:12 -0400 Subject: [PATCH 1/2] Insert a versioned dep on a plugin otherwise mentioned only in tests classifier --- plugins-compat-tester/pom.xml | 1 + .../jenkins/tools/test/model/MavenPom.java | 19 ++ .../tools/test/model/MavenPomTest.java | 49 +++++ .../model/credentials-binding-pom-after.xml | 175 ++++++++++++++++++ .../model/credentials-binding-pom-before.xml | 148 +++++++++++++++ 5 files changed, 392 insertions(+) create mode 100644 plugins-compat-tester/src/test/java/org/jenkins/tools/test/model/MavenPomTest.java create mode 100644 plugins-compat-tester/src/test/resources/org/jenkins/tools/test/model/credentials-binding-pom-after.xml create mode 100644 plugins-compat-tester/src/test/resources/org/jenkins/tools/test/model/credentials-binding-pom-before.xml diff --git a/plugins-compat-tester/pom.xml b/plugins-compat-tester/pom.xml index cd737cc04..2163ff1e5 100644 --- a/plugins-compat-tester/pom.xml +++ b/plugins-compat-tester/pom.xml @@ -13,6 +13,7 @@ 1.5 + false diff --git a/plugins-compat-tester/src/main/java/org/jenkins/tools/test/model/MavenPom.java b/plugins-compat-tester/src/main/java/org/jenkins/tools/test/model/MavenPom.java index c441ec0d0..06bba524a 100644 --- a/plugins-compat-tester/src/main/java/org/jenkins/tools/test/model/MavenPom.java +++ b/plugins-compat-tester/src/main/java/org/jenkins/tools/test/model/MavenPom.java @@ -31,9 +31,11 @@ import java.io.Writer; import java.nio.charset.Charset; import java.nio.file.Files; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Nonnull; @@ -60,6 +62,7 @@ public class MavenPom { private final static String GROUP_ID_ELEMENT = "groupId"; private final static String ARTIFACT_ID_ELEMENT = "artifactId"; private final static String VERSION_ELEMENT = "version"; + private final static String CLASSIFIER_ELEMENT = "classifier"; private File rootDir; private String pomFileName; @@ -174,6 +177,14 @@ public void addDependencies(Map toAdd, Map depsWithoutClassifier = new HashSet<>(); + for (Element mavenDependency : (List) dependencies.elements("dependency")) { + Element artifactId = mavenDependency.element(ARTIFACT_ID_ELEMENT); + if (mavenDependency.element(CLASSIFIER_ELEMENT) == null) { + depsWithoutClassifier.add(artifactId.getTextTrim()); + } + } + Element properties = doc.getRootElement().element("properties"); Map toReplaceUsed = new LinkedHashMap<>(); Map toReplaceTestUsed = new LinkedHashMap<>(); @@ -225,6 +236,14 @@ public void addDependencies(Map toAdd, Map toAdd = new HashMap<>(Collections.singletonMap("trilead-api", new VersionNumber("1.0.8"))); + Map toReplace = new HashMap<>(ImmutableMap.of("credentials", new VersionNumber("2.3.12"), "ssh-credentials", new VersionNumber("1.18.1"), "plain-credentials", new VersionNumber("1.7"))); + Map toAddTest = new HashMap<>(); + Map toReplaceTest = new HashMap<>(ImmutableMap.of("workflow-scm-step", new VersionNumber("2.11"), "workflow-durable-task-step", new VersionNumber("2.35"), "display-url-api", new VersionNumber("2.3.3"), "script-security", new VersionNumber("1.74"), "workflow-cps", new VersionNumber("2.83"))); + toReplaceTest.putAll(ImmutableMap.of("workflow-support", new VersionNumber("3.5"), "workflow-job", new VersionNumber("2.39"), "workflow-basic-steps", new VersionNumber("2.20"))); + VersionNumber coreDep = new VersionNumber("2.164.3"); + Map pluginGroupIds = new HashMap<>(ImmutableMap.of("credentials-binding", "org.jenkins-ci.plugins", "pipeline-build-step", "org.jenkins-ci.plugins", "credentials", "org.jenkins-ci.plugins", "jdk-tool", "org.jenkins-ci.plugins", "snakeyaml-api", "io.jenkins.plugins")); + pluginGroupIds.putAll(ImmutableMap.of("workflow-step-api", "org.jenkins-ci.plugins.workflow", "plain-credentials", "org.jenkins-ci.plugins", "trilead-api", "org.jenkins-ci.plugins", "command-launcher", "org.jenkins-ci.plugins", "jquery", "org.jenkins-ci.plugins")); + pluginGroupIds.putAll(ImmutableMap.of("matrix-project", "org.jenkins-ci.plugins", "jquery-detached", "org.jenkins-ci.ui", "ace-editor", "org.jenkins-ci.ui", "git", "org.jenkins-ci.plugins", "workflow-durable-task-step", "org.jenkins-ci.plugins.workflow")); + pluginGroupIds.putAll(ImmutableMap.of("git-client", "org.jenkins-ci.plugins", "ssh-credentials", "org.jenkins-ci.plugins", "variant", "org.jenkins-ci.plugins", "cloudbees-folder", "org.jenkins-ci.plugins", "scm-api", "org.jenkins-ci.plugins")); + pluginGroupIds.putAll(ImmutableMap.of("pipeline-stage-step", "org.jenkins-ci.plugins", "junit-attachments", "org.jenkins-ci.plugins", "durable-task", "org.jenkins-ci.plugins", "workflow-job", "org.jenkins-ci.plugins.workflow", "workflow-basic-steps", "org.jenkins-ci.plugins.workflow")); + pluginGroupIds.putAll(ImmutableMap.of("jsch", "org.jenkins-ci.plugins", "timestamper", "org.jenkins-ci.plugins", "junit", "org.jenkins-ci.plugins", "apache-httpcomponents-client-4-api", "org.jenkins-ci.plugins", "structs", "org.jenkins-ci.plugins")); + pluginGroupIds.putAll(ImmutableMap.of("workflow-cps-global-lib", "org.jenkins-ci.plugins.workflow", "configuration-as-code", "io.jenkins", "workflow-cps", "org.jenkins-ci.plugins.workflow", "workflow-support", "org.jenkins-ci.plugins.workflow", "ssh-slaves", "org.jenkins-ci.plugins")); + pluginGroupIds.putAll(ImmutableMap.of("htmlpublisher", "org.jenkins-ci.plugins", "mailer", "org.jenkins-ci.plugins", "ansicolor", "org.jenkins-ci.plugins", "jackson2-api", "org.jenkins-ci.plugins", "workflow-scm-step", "org.jenkins-ci.plugins.workflow")); + pluginGroupIds.putAll(ImmutableMap.of("display-url-api", "org.jenkins-ci.plugins", "token-macro", "org.jenkins-ci.plugins", "script-security", "org.jenkins-ci.plugins", "pipeline-input-step", "org.jenkins-ci.plugins", "branch-api", "org.jenkins-ci.plugins")); + pluginGroupIds.putAll(ImmutableMap.of("workflow-api", "org.jenkins-ci.plugins.workflow", "git-server", "org.jenkins-ci.plugins")); + List toConvert = Collections.emptyList(); + new MavenPom(prj).addDependencies(toAdd, toReplace, toAddTest, toReplaceTest, coreDep, pluginGroupIds, toConvert); + assertEquals(IOUtils.toString(MavenPomTest.class.getResource("credentials-binding-pom-after.xml")).replaceAll("(?m) +$", ""), FileUtils.readFileToString(pom).replaceAll("(?m) +$", "")); + } + +} diff --git a/plugins-compat-tester/src/test/resources/org/jenkins/tools/test/model/credentials-binding-pom-after.xml b/plugins-compat-tester/src/test/resources/org/jenkins/tools/test/model/credentials-binding-pom-after.xml new file mode 100644 index 000000000..44d4ec8a1 --- /dev/null +++ b/plugins-compat-tester/src/test/resources/org/jenkins/tools/test/model/credentials-binding-pom-after.xml @@ -0,0 +1,175 @@ + + + + 4.0.0 + + org.jenkins-ci.plugins + plugin + 4.1 + + + credentials-binding + 1.23 + hpi + Credentials Binding Plugin + Allows credentials to be bound to environment variables for use from miscellaneous build steps. + https://github.com/jenkinsci/credentials-binding-plugin + + 1.23 + -SNAPSHOT + 2.164.3 + 8 + + + + MIT + https://opensource.org/licenses/MIT + + + + scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git + scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git + https://github.com/jenkinsci/${project.artifactId}-plugin + credentials-binding-1.23 + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + + io.jenkins.tools.bom + bom-2.164.x + 9 + import + pom + + + + + + org.jenkins-ci.plugins + credentials + 2.3.12 + + + org.jenkins-ci.plugins + plain-credentials + 1.7 + + + org.jenkins-ci.plugins.workflow + workflow-step-api + + + org.jenkins-ci.plugins + structs + + + org.jenkins-ci.plugins.workflow + workflow-cps + test + 2.83 + + + org.jenkins-ci.plugins.workflow + workflow-job + test + 2.39 + + + org.jenkins-ci.plugins.workflow + workflow-durable-task-step + test + 2.35 + + + org.jenkins-ci.plugins.workflow + workflow-basic-steps + test + 2.20 + + + org.jenkins-ci.plugins + ssh-credentials + 1.18.1 + + + org.jenkins-ci.plugins.workflow + workflow-cps + tests + test + 2.83 + + + org.jenkins-ci.plugins.workflow + workflow-step-api + tests + test + + + org.jenkins-ci.plugins.workflow + workflow-support + tests + test + 3.5 + + + org.jenkins-ci.plugins + script-security + test + 1.74 + + + org.jenkins-ci.plugins + authorize-project + 1.3.0 + test + + + org.xmlunit + xmlunit-matchers + 2.6.4 + test + + + org.hamcrest + hamcrest-core + + + + + org.jenkins-ci.plugins.workflow + workflow-support + test + 3.5 + + + + org.jenkins-ci.plugins + trilead-api + 1.0.8 + + + org.jenkins-ci.plugins + display-url-api + 2.3.3 + test + + + org.jenkins-ci.plugins.workflow + workflow-scm-step + 2.11 + test + + + diff --git a/plugins-compat-tester/src/test/resources/org/jenkins/tools/test/model/credentials-binding-pom-before.xml b/plugins-compat-tester/src/test/resources/org/jenkins/tools/test/model/credentials-binding-pom-before.xml new file mode 100644 index 000000000..c87b5b42f --- /dev/null +++ b/plugins-compat-tester/src/test/resources/org/jenkins/tools/test/model/credentials-binding-pom-before.xml @@ -0,0 +1,148 @@ + + + 4.0.0 + + + org.jenkins-ci.plugins + plugin + 4.1 + + + + credentials-binding + 1.23 + hpi + + Credentials Binding Plugin + Allows credentials to be bound to environment variables for use from miscellaneous build steps. + + https://github.com/jenkinsci/credentials-binding-plugin + + 1.23 + -SNAPSHOT + 2.164.3 + 8 + + + + MIT + https://opensource.org/licenses/MIT + + + + + scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git + scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git + https://github.com/jenkinsci/${project.artifactId}-plugin + credentials-binding-1.23 + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + + + io.jenkins.tools.bom + bom-2.164.x + 9 + import + pom + + + + + + org.jenkins-ci.plugins + credentials + + + org.jenkins-ci.plugins + plain-credentials + + + org.jenkins-ci.plugins.workflow + workflow-step-api + + + org.jenkins-ci.plugins + structs + + + org.jenkins-ci.plugins.workflow + workflow-cps + test + + + org.jenkins-ci.plugins.workflow + workflow-job + test + + + org.jenkins-ci.plugins.workflow + workflow-durable-task-step + test + + + org.jenkins-ci.plugins.workflow + workflow-basic-steps + test + + + org.jenkins-ci.plugins + ssh-credentials + + + org.jenkins-ci.plugins.workflow + workflow-cps + tests + test + + + org.jenkins-ci.plugins.workflow + workflow-step-api + tests + test + + + org.jenkins-ci.plugins.workflow + workflow-support + tests + test + + + org.jenkins-ci.plugins + script-security + test + + + org.jenkins-ci.plugins + authorize-project + 1.3.0 + test + + + org.xmlunit + xmlunit-matchers + 2.6.4 + test + + + org.hamcrest + hamcrest-core + + + + + + From 64ff861febbf660b6cd695c4b3c5ef6f97d9888d Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Fri, 18 Sep 2020 08:07:22 -0400 Subject: [PATCH 2/2] Noting SUREFIRE-1798 --- plugins-compat-tester/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins-compat-tester/pom.xml b/plugins-compat-tester/pom.xml index 2163ff1e5..7bd498b1a 100644 --- a/plugins-compat-tester/pom.xml +++ b/plugins-compat-tester/pom.xml @@ -13,7 +13,7 @@ 1.5 - false + false