Skip to content

Commit

Permalink
Merge pull request #14 from jenkinsci/feature/JENKINS-38978_update-ve…
Browse files Browse the repository at this point in the history
…rsions

[JENKINS-38978] Plugin needs updating to address SECURITY-170
  • Loading branch information
marcrohlfs committed Jan 9, 2018
2 parents cc341d1 + 77e3691 commit 8f52aba
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 85 deletions.
1 change: 1 addition & 0 deletions Jenkinsfile
@@ -0,0 +1 @@
buildPlugin()
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -23,7 +23,7 @@ If all you need to do is download an artifact from a repository and use it durin

## Jenkins: ##

Built and tested against Jenkins 1.447.
Built and tested against Jenkins 2.32.1.

# AUTHOR & CONTRIBUTORS: #

Expand Down
63 changes: 20 additions & 43 deletions pom.xml
@@ -1,29 +1,28 @@
<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">
<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>1.481</version>
<version>3.2</version>
</parent>

<prerequisites>
<maven>3.0.4</maven>
</prerequisites>

<groupId>eu.markov.jenkins.plugin.mvnmeta</groupId>
<artifactId>maven-metadata-plugin</artifactId>
<version>1.5.1-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Maven Metadata Plugin for Jenkins CI server</name>
<description>Adds a new build parameter type for resolving artifact versions reading the repository maven-metadata.xml</description>
<inceptionYear>2012</inceptionYear>

<url>https://wiki.jenkins-ci.org/display/JENKINS/Maven+Metadata+Plugin</url>
<url>https://wiki.jenkins.io/display/JENKINS/Maven+Metadata+Plugin</url>

<scm>
<connection>scm:git:ssh://github.com/jenkinsci/maven-metadata-plugin.git</connection>
<developerConnection>scm:git:ssh://git@github.com/jenkinsci/maven-metadata-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/maven-metadata-plugin</url>
<tag>HEAD</tag>
</scm>
<tag>HEAD</tag>
</scm>

<developers>
<developer>
Expand Down Expand Up @@ -63,7 +62,10 @@
</pluginRepositories>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jenkins.version>2.32.1</jenkins.version>
<java.level>8</java.level>
<maven.compiler.source>1.${java.level}</maven.compiler.source>
<maven.compiler.target>1.${java.level}</maven.compiler.target>
<lombok.version>1.12.2</lombok.version>
<lombok.plugin.version>1.12.2.0</lombok.plugin.version>
</properties>
Expand All @@ -72,46 +74,22 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>1.9.1</version>
<version>1.14</version>
</dependency>
<dependency>
<groupId>com.sonyericsson.hudson.plugins.rebuild</groupId>
<artifactId>rebuild</artifactId>
<version>1.25</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.7</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<groupId>org.kohsuke</groupId>
<artifactId>access-modifier-checker</artifactId>
<version>1.4</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerVersion>1.6</compilerVersion>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<!-- Automatically create the base configuration for the Jenkins development workspace when it doesn't exist. -->
Expand All @@ -126,7 +104,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>workspace-base-configuration</id>
Expand Down
Expand Up @@ -18,7 +18,7 @@
<versionFilter></versionFilter>
<sortOrder>DESC</sortOrder>
<maxVersions></maxVersions>
<currentArtifactInfoUrl>file://${project.basedir}/work/jobs/testjob/currentArtifactInfo.txt</currentArtifactInfoUrl>
<currentArtifactInfoUrl>file://${project.basedir}/work/jobs/test-freestyle/currentArtifactInfo.txt</currentArtifactInfoUrl>
<currentArtifactInfoLabel>Currently under development</currentArtifactInfoLabel>
<currentArtifactInfoPattern>Plugin Version: ([\S]+)</currentArtifactInfoPattern>
<credentialsId></credentialsId>
Expand All @@ -31,18 +31,11 @@
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers class="vector"/>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.tasks.Shell>
<command>echo &quot;Selected artifact:&quot;
echo &quot; Group ID: ${ARTIFACT_GROUP_ID}&quot;
echo &quot; Artifact ID: ${ARTIFACT_ARTIFACT_ID}&quot;
echo &quot; Version: ${ARTIFACT_VERSION}&quot;
echo &quot; Type: ${ARTIFACT_PACKAGING}&quot;
echo &quot; Classifier: ${ARTIFACT_CLASSIFIER}&quot;
echo &quot; Download URL: ${ARTIFACT_ARTIFACT_URL}&quot;
</command>
<command>env | grep &quot;^ARTIFACT_&quot; | sort</command>
</hudson.tasks.Shell>
</builders>
<publishers/>
Expand Down
62 changes: 62 additions & 0 deletions src/dev/assets/work/jobs/test-matrix/config.xml
@@ -0,0 +1,62 @@
<?xml version='1.0' encoding='UTF-8'?>
<matrix-project>
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<eu.markov.jenkins.plugin.mvnmeta.MavenMetadataParameterDefinition>
<name>ARTIFACT</name>
<description></description>
<repoBaseUrl>http://repo.jenkins-ci.org/public</repoBaseUrl>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<packaging>${project.packaging}</packaging>
<defaultValue></defaultValue>
<classifier></classifier>
<versionFilter></versionFilter>
<sortOrder>DESC</sortOrder>
<maxVersions></maxVersions>
<currentArtifactInfoUrl>file://${project.basedir}/work/jobs/test-matrix/currentArtifactInfo.txt</currentArtifactInfoUrl>
<currentArtifactInfoLabel>Currently under development</currentArtifactInfoLabel>
<currentArtifactInfoPattern>Plugin Version: ([\S]+)</currentArtifactInfoPattern>
<credentialsId></credentialsId>
</eu.markov.jenkins.plugin.mvnmeta.MavenMetadataParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<axes>
<hudson.matrix.TextAxis>
<name>ARTIFACT_AXIS_A</name>
<values>
<string>1</string>
<string>2</string>
</values>
</hudson.matrix.TextAxis>
<hudson.matrix.TextAxis>
<name>ARTIFACT_AXIS_B</name>
<values>
<string>3</string>
<string>4</string>
</values>
</hudson.matrix.TextAxis>
</axes>
<builders>
<hudson.tasks.Shell>
<command>env | grep &quot;^ARTIFACT_&quot; | sort</command>
</hudson.tasks.Shell>
</builders>
<publishers/>
<buildWrappers/>
<executionStrategy class="hudson.matrix.DefaultMatrixExecutionStrategyImpl">
<runSequentially>false</runSequentially>
</executionStrategy>
</matrix-project>
3 changes: 3 additions & 0 deletions src/dev/assets/work/jobs/test-matrix/currentArtifactInfo.txt
@@ -0,0 +1,3 @@
Plugin ID: ${project.artifactId}
Plugin Version: ${project.version}
Jenkins Core Version: ${project.parent.version}
Expand Up @@ -26,7 +26,6 @@
import hudson.Extension;
import hudson.Util;
import hudson.cli.CLICommand;
import hudson.model.Hudson;
import hudson.model.ParameterValue;
import hudson.security.ACL;
import hudson.util.FormValidation;
Expand All @@ -49,6 +48,8 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

import jenkins.model.Jenkins;

import com.cloudbees.plugins.credentials.CredentialsMatcher;
import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.CredentialsProvider;
Expand Down Expand Up @@ -85,7 +86,7 @@ public class MavenMetadataParameterDefinition extends MavenMetadataParameterDefi
private static final Pattern MATCH_ALL = Pattern.compile(".*");
private static final Charset UTF8 = Charset.forName("UTF-8");

private transient int maxVers = Integer.MIN_VALUE;
private transient Integer maxVers = null;
private transient Pattern versionFilterPattern = null;

private final String repoBaseUrl;
Expand Down Expand Up @@ -124,13 +125,12 @@ public MavenMetadataParameterDefinition(String name, String description, String
}

public int getMaxVers() {
if (this.maxVers == Integer.MIN_VALUE) {
int maxVers = Integer.MAX_VALUE;
if (this.maxVers == null) {
try {
maxVers = Integer.parseInt(maxVersions);
this.maxVers = Integer.parseInt(maxVersions);
} catch (NumberFormatException e) {
this.maxVers = Integer.MAX_VALUE;
}
this.maxVers = maxVers;
}
return this.maxVers;
}
Expand Down Expand Up @@ -309,12 +309,7 @@ private MavenMetadataVersions getArtifactMetadata() {
result.versioning.versions.add("<" + e.getClass().getName() + ": " + e.getMessage() + ">");
return result;
} finally {
try {
if (input != null)
input.close();
} catch (IOException e) {
// ignore
}
IOUtils.closeQuietly(input);
}
}

Expand Down Expand Up @@ -415,7 +410,7 @@ private URLConnection prepareConnection(URL url) throws IOException {
@Override
protected UsernamePasswordCredentials findCredentialsByCredentialsId() {
List<UsernamePasswordCredentials> credentials =
CredentialsProvider.lookupCredentials(UsernamePasswordCredentials.class, Hudson.getInstance(), ACL.SYSTEM, new DomainRequirement());
CredentialsProvider.lookupCredentials(UsernamePasswordCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, new DomainRequirement());
CredentialsMatcher credentialsIdMatcher = CredentialsMatchers.withId(this.credentialsId);
return CredentialsMatchers.firstOrNull(credentials, credentialsIdMatcher);
}
Expand Down Expand Up @@ -466,7 +461,7 @@ public static class DescriptorImpl extends ParameterDescriptor {

public ListBoxModel doFillCredentialsIdItems() {
List<StandardCredentials> credentials =
CredentialsProvider.lookupCredentials(StandardCredentials.class, Hudson.getInstance(), ACL.SYSTEM, new DomainRequirement());
CredentialsProvider.lookupCredentials(StandardCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, new DomainRequirement());
CredentialsMatcher credentialsTypeMatcher = CredentialsMatchers.instanceOf(UsernamePasswordCredentials.class);
return new StandardListBoxModel().withEmptySelection().withMatching(credentialsTypeMatcher, credentials);
}
Expand Down
Expand Up @@ -23,23 +23,22 @@
*/
package eu.markov.jenkins.plugin.mvnmeta;

import hudson.model.Hudson;
import hudson.model.ParameterDefinition;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Logger;

import jenkins.model.Jenkins;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.CredentialsStore;
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.domains.Domain;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;

import lombok.Getter;

import org.apache.commons.lang.StringUtils;

/**
Expand All @@ -51,7 +50,6 @@
*
* @author Marc Rohlfs, Silpion IT-Solutions GmbH - <a href="mailto:rohlfs@silpion.de">rohlfs@silpion.de</a>
*/
@Getter
@SuppressWarnings("deprecation")
public abstract class MavenMetadataParameterDefinitionBackwardCompatibility extends ParameterDefinition {
private static final long serialVersionUID = -694351540106684393L;
Expand Down Expand Up @@ -107,7 +105,7 @@ private void migrateCredentials() throws IOException {
String description = "Generated credentials for " + customCredentialsId;
credentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, customCredentialsId, description, this.username, this.password);

CredentialsStore credentialsStore = CredentialsProvider.lookupStores(Hudson.getInstance()).iterator().next();
CredentialsStore credentialsStore = CredentialsProvider.lookupStores(Jenkins.getInstance()).iterator().next();
credentialsStore.addCredentials(Domain.global(), credentials);
}

Expand Down Expand Up @@ -148,4 +146,28 @@ private String createRepoBaseUrlWithImplicitUser() throws MalformedURLException
protected abstract String getCredentialsId();

protected abstract void setCredentialsId(final String credentialsId);

/**
* Returns the username.
*
* @return the username.
* @deprecated Migrated to {@link MavenMetadataParameterDefinition#credentialsId}
*/
@Deprecated
@SuppressWarnings("all")
public String getUsername() {
return this.username;
}

/**
* Returns the password.
*
* @return the password.
* @deprecated Migrated to {@link MavenMetadataParameterDefinition#credentialsId}
*/
@Deprecated
@SuppressWarnings("all")
public String getPassword() {
return this.password;
}
}
Expand Up @@ -24,8 +24,9 @@
package eu.markov.jenkins.plugin.mvnmeta;

import hudson.EnvVars;
import hudson.model.ParameterValue;
import hudson.model.AbstractBuild;
import hudson.model.ParameterValue;
import hudson.model.Run;
import hudson.util.VariableResolver;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -64,9 +65,6 @@ public class MavenMetadataParameterValue extends ParameterValue {
@Exported
private String artifactUrl;

/**
* @param name
*/
@DataBoundConstructor
public MavenMetadataParameterValue(String name, String description, String groupId, String artifactId, String version,
String packaging, String classifier, String artifactUrl) {
Expand All @@ -80,7 +78,7 @@ public MavenMetadataParameterValue(String name, String description, String group
}

@Override
public void buildEnvVars(AbstractBuild<?, ?> build, EnvVars env) {
public void buildEnvironment(Run<?, ?> build, EnvVars env) {
env.put(getName() + GROUP_ID_SUFFIX, getGroupId());
env.put(getName() + ARTIFACT_ID_SUFFIX, getArtifactId());
env.put(getName() + VERSION_SUFFIX, getVersion());
Expand Down

0 comments on commit 8f52aba

Please sign in to comment.