Skip to content

Commit

Permalink
Merge pull request #9 from mrumpf/master
Browse files Browse the repository at this point in the history
Fixes for JENKINS-28323 and JENKINS-27641. All tests are fine.
  • Loading branch information
mrumpf committed May 12, 2015
2 parents a75b5e6 + fbc42db commit 9d9175f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 28 deletions.
Expand Up @@ -5,11 +5,12 @@
import hudson.model.SimpleParameterDefinition;
import hudson.model.StringParameterValue;
import hudson.util.FormValidation;
import java.io.File;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -19,20 +20,15 @@
import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.jvnet.hudson.plugins.repositoryconnector.aether.Aether;

import org.jvnet.hudson.plugins.repositoryconnector.aether.Aether;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.export.Exported;
import org.sonatype.aether.resolution.VersionRangeResolutionException;
import org.sonatype.aether.version.Version;

/**
*
* @author mrumpf
*
*/
public class VersionParameterDefinition extends
SimpleParameterDefinition {

Expand All @@ -41,22 +37,24 @@ public class VersionParameterDefinition extends
private final String groupid;
private final String repoid;
private final String artifactid;
private final String propertyName;

@DataBoundConstructor
public VersionParameterDefinition(String repoid, String groupid,
String artifactid, String description) {
String artifactid, String propertyName, String description) {
super(groupid + "." + artifactid, description);
this.repoid = repoid;
this.groupid = groupid;
this.artifactid = artifactid;
this.propertyName = propertyName;
}

@Override
public VersionParameterDefinition copyWithDefaultValue(ParameterValue defaultValue) {
if (defaultValue instanceof StringParameterValue) {
StringParameterValue value = (StringParameterValue) defaultValue;
// TODO: StringParameterValue value = (StringParameterValue) defaultValue;
return new VersionParameterDefinition(getRepoid(), "",
"", getDescription());
"", "", getDescription());
} else {
return this;
}
Expand All @@ -77,6 +75,13 @@ public List<String> getChoices() {
} catch (VersionRangeResolutionException ex) {
log.log(Level.SEVERE, "Could not determine versions", ex);
}
if (!versionStrings.isEmpty()) {
// reverseorder to have the latest versions on top of the list
Collections.reverse(versionStrings);
// add the default parameters
versionStrings.add(0, "LATEST");
versionStrings.add(0, "RELEASE");
}
}
return versionStrings;
}
Expand All @@ -96,9 +101,14 @@ public String getGroupid() {
return groupid;
}

@Exported
public String getPropertyName() {
return propertyName;
}

@Override
public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
return new VersionParameterValue(groupid, artifactid, jo.getString("value"));
return new VersionParameterValue(groupid, artifactid, propertyName, jo.getString("value"));
}

@Override
Expand All @@ -123,14 +133,22 @@ public DescriptorImpl() {
}

public Repository getRepo(String id) {
Repository repo = RepositoryConfiguration.get().getRepositoryMap().get(id);
log.fine("getRepo(" + id + ")=" + repo);
Repository repo = null;
RepositoryConfiguration repoConfig = RepositoryConfiguration.get();
if (repoConfig != null) {
repo = repoConfig.getRepositoryMap().get(id);
log.fine("getRepo(" + id + ")=" + repo);
}
return repo;
}

public Collection<Repository> getRepos() {
Collection<Repository> repos = RepositoryConfiguration.get().getRepos();
log.fine("getRepos()=" + repos);
Collection<Repository> repos = null;
RepositoryConfiguration repoConfig = RepositoryConfiguration.get();
if (repoConfig != null) {
repos = repoConfig.getRepos();
log.fine("getRepos()=" + repos);
}
return repos;
}

Expand Down
@@ -1,25 +1,22 @@
package org.jvnet.hudson.plugins.repositoryconnector;

import hudson.model.StringParameterValue;
import java.util.logging.Level;

import java.util.logging.Logger;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* This class sets the build parameter as environment value
* "groupid.artifactid=version"
* "groupid.artifactid=version" or as "name=value".
*
* @author mrumpf
*
*/
@SuppressWarnings("serial")
public class VersionParameterValue extends StringParameterValue {

private static final Logger log = Logger
.getLogger(VersionParameterValue.class.getName());

private final String groupid;
private final String artifactid;
private final String propertyName;

public String getGroupid() {
return groupid;
Expand All @@ -29,14 +26,16 @@ public String getArtifactid() {
return artifactid;
}

public String getPropertyName() {
return propertyName;
}

@DataBoundConstructor
public VersionParameterValue(String groupid, String artifactid, String version) {
super(groupid + "." + artifactid, version);
if (log.isLoggable(Level.FINE)) {
log.fine("Creating environment build parameter 'groupid.artifactid=version'");
}
public VersionParameterValue(String groupid, String artifactid, String propertyName, String version) {
super((propertyName != null && !propertyName.isEmpty()) ? propertyName : groupid + "." + artifactid, version);
this.groupid = groupid;
this.artifactid = artifactid;
this.propertyName = propertyName;
}

public String toString() {
Expand All @@ -49,6 +48,8 @@ public String toString() {
sb.append(groupid);
sb.append(", artifactid=");
sb.append(artifactid);
sb.append(", propertyName=");
sb.append(propertyName);
sb.append(']');
return sb.toString();
}
Expand Down
Expand Up @@ -9,6 +9,9 @@
</j:forEach>
</select>
</f:entry>
<f:entry title="${%PropertyName}">
<f:textbox field="propertyName" value="${instance.propertyName}" />
</f:entry>
<f:entry title="${%GroupId}">
<f:textbox field="groupid" value="${instance.groupid}" />
</f:entry>
Expand Down
@@ -1,4 +1,5 @@
Repository=Repository
GroupId=Group Id
ArtifactId=Artifact Id
Description=Description
Description=Description
PropertyName=Property Name
@@ -1,4 +1,5 @@
Repository=Verzeichnis
GroupId=Gruppen Id
ArtifactId=Artefakt Id
Description=Beschreibung
Description=Beschreibung
PropertyName=Attributname

0 comments on commit 9d9175f

Please sign in to comment.