Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert a versioned dep on a plugin otherwise mentioned only in tests classifier #256

Merged
merged 4 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins-compat-tester/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<properties>
<maven.scm.providers.version>1.5</maven.scm.providers.version>
<trimStackTrace>false</trimStackTrace> <!-- SUREFIRE-1798 -->
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -174,6 +177,14 @@ public void addDependencies(Map<String,VersionNumber> toAdd, Map<String,VersionN
}
}

Set<String> depsWithoutClassifier = new HashSet<>();
for (Element mavenDependency : (List<Element>) 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<String,VersionNumber> toReplaceUsed = new LinkedHashMap<>();
Map<String,VersionNumber> toReplaceTestUsed = new LinkedHashMap<>();
Expand Down Expand Up @@ -225,6 +236,14 @@ public void addDependencies(Map<String,VersionNumber> toAdd, Map<String,VersionN
Element scope = mavenDependency.element("scope");
if (scope != null && scope.getTextTrim().equals("test")) {
toReplaceTestUsed.put(trimmedArtifactId, replacement);
if (toReplaceTest.containsKey(trimmedArtifactId) && !depsWithoutClassifier.contains(trimmedArtifactId)) { // https://github.com/jenkinsci/bom/pull/301#issuecomment-694518923
Element mainDep = mavenDependency.createCopy();
Element classifier = mainDep.element(CLASSIFIER_ELEMENT);
if (classifier != null) {
mainDep.remove(classifier);
dependencies.add(mainDep); // would prefer to insert just before mavenDependency but API does not seem to support this
}
}
} else {
toReplaceUsed.put(trimmedArtifactId, replacement);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

package org.jenkins.tools.test.model;

import com.google.common.collect.ImmutableMap;
import hudson.util.VersionNumber;
import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.jvnet.hudson.test.Issue;

public class MavenPomTest {

@Rule public TemporaryFolder tmp = new TemporaryFolder();

@Issue("https://github.com/jenkinsci/bom/pull/301#issuecomment-694518923")
@Test public void addDependenciesWithTestsClassifier() throws Exception {
File prj = tmp.newFolder();
File pom = new File(prj, "pom.xml");
FileUtils.copyURLToFile(MavenPomTest.class.getResource("credentials-binding-pom-before.xml"), pom);
Map<String,VersionNumber> toAdd = new HashMap<>(Collections.singletonMap("trilead-api", new VersionNumber("1.0.8")));
Map<String,VersionNumber> 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<String,VersionNumber> toAddTest = new HashMap<>();
Map<String,VersionNumber> 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<String,String> 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<String> 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) +$", ""));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.1</version>
<relativePath/>
</parent>
<artifactId>credentials-binding</artifactId>
<version>1.23</version>
<packaging>hpi</packaging>
<name>Credentials Binding Plugin</name>
<description>Allows credentials to be bound to environment variables for use from miscellaneous build steps.</description>
<url>https://github.com/jenkinsci/credentials-binding-plugin</url>
<properties>
<revision>1.23</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.164.3</jenkins.version>
<java.level>8</java.level>
</properties>
<licenses>
<license>
<name>MIT</name>
<url>https://opensource.org/licenses/MIT</url>
</license>
</licenses>
<scm>
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:[email protected]:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<tag>credentials-binding-1.23</tag>
</scm>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.164.x</artifactId>
<version>9</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>2.3.12</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plain-credentials</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<scope>test</scope>
<version>2.83</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<scope>test</scope>
<version>2.39</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<scope>test</scope>
<version>2.35</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<scope>test</scope>
<version>2.20</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-credentials</artifactId>
<version>1.18.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
<version>2.83</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<scope>test</scope>
<version>1.74</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>authorize-project</artifactId>
<version>1.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-matchers</artifactId>
<version>2.6.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<scope>test</scope>
<version>3.5</version>
</dependency>
<!--SYNTHETIC-->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>trilead-api</artifactId>
<version>1.0.8</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>display-url-api</artifactId>
<version>2.3.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-scm-step</artifactId>
<version>2.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading