Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix JENKINS-15709
  • Loading branch information
gboissinot committed Nov 3, 2012
1 parent e7fc8fe commit 61d97a0
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 45 deletions.
@@ -1,5 +1,7 @@
package org.jenkinsci.plugins.artifactdeployer;

import org.kohsuke.stapler.DataBoundConstructor;

import java.io.Serializable;

/**
Expand All @@ -25,6 +27,29 @@ public class ArtifactDeployerEntry implements Serializable {
private String groovyExpression;
private boolean failNoFilesDeploy;

public ArtifactDeployerEntry() {
}

@DataBoundConstructor
public ArtifactDeployerEntry(String includes, String basedir, String excludes, String remote, boolean flatten, boolean deleteRemote, boolean deleteRemoteArtifacts, DeleteRemoteArtifactsByScriptModel deleteRemoteArtifactsByScript, boolean failNoFilesDeploy) {
this.includes = includes;
this.basedir = basedir;
this.excludes = excludes;
this.remote = remote;
this.flatten = flatten;
this.deleteRemote = deleteRemote;
this.deleteRemoteArtifacts = deleteRemoteArtifacts;
//this.deleteRemoteArtifactsByScript = deleteRemoteArtifactsByScript;
//this.groovyExpression = groovyExpression;
if (deleteRemoteArtifactsByScript != null) {
this.deleteRemoteArtifactsByScript = true;
this.groovyExpression = deleteRemoteArtifactsByScript.getGroovyExpression();
} else {
this.deleteRemoteArtifactsByScript = false;
}
this.failNoFilesDeploy = failNoFilesDeploy;
}

@SuppressWarnings("unused")
public String getIncludes() {
return includes;
Expand Down
Expand Up @@ -5,7 +5,6 @@
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.matrix.*;
import hudson.model.*;
import hudson.model.listeners.RunListener;
Expand All @@ -15,15 +14,13 @@
import hudson.tasks.Recorder;
import hudson.util.DescribableList;
import hudson.util.FormValidation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.jenkinsci.plugins.artifactdeployer.exception.ArtifactDeployerException;
import org.jenkinsci.plugins.artifactdeployer.service.ArtifactDeployerCopy;
import org.jenkinsci.plugins.artifactdeployer.service.ArtifactDeployerManager;
import org.jenkinsci.plugins.artifactdeployer.service.DeployedArtifactsActionManager;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;
import java.io.Serializable;
Expand All @@ -36,8 +33,14 @@
*/
public class ArtifactDeployerPublisher extends Recorder implements MatrixAggregatable, Serializable {

private boolean deployEvenBuildFail;
private List<ArtifactDeployerEntry> entries = Collections.emptyList();
private boolean deployEvenBuildFail;

@DataBoundConstructor
public ArtifactDeployerPublisher(List<ArtifactDeployerEntry> deployedArtifact, boolean deployEvenBuildFail) {
this.entries = deployedArtifact;
this.deployEvenBuildFail = deployEvenBuildFail;
}

public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
Expand Down Expand Up @@ -322,46 +325,46 @@ public String getDisplayName() {
}


private ArtifactDeployerEntry populateAndGetEntry(JSONObject element) {
ArtifactDeployerEntry entry = new ArtifactDeployerEntry();
entry.setIncludes(Util.fixEmpty(element.getString("includes")));
entry.setBasedir(Util.fixEmpty(element.getString("basedir")));
entry.setExcludes(Util.fixEmpty(element.getString("excludes")));
entry.setRemote(Util.fixEmpty(element.getString("remote")));
entry.setDeleteRemote(element.getBoolean("deleteRemote"));
entry.setFlatten(element.getBoolean("flatten"));
entry.setFailNoFilesDeploy(element.getBoolean("failNoFilesDeploy"));
entry.setDeleteRemoteArtifacts(element.getBoolean("deleteRemoteArtifacts"));
Object deleteRemoteArtifactsObject = element.get("deleteRemoteArtifactsByScript");
if (deleteRemoteArtifactsObject == null) {
entry.setDeleteRemoteArtifactsByScript(false);
} else {
entry.setDeleteRemoteArtifactsByScript(true);
entry.setGroovyExpression(Util.fixEmpty(element.getJSONObject("deleteRemoteArtifactsByScript").getString("groovyExpression")));
}
return entry;
}

@Override
public Publisher newInstance(StaplerRequest req, JSONObject formData) throws FormException {
ArtifactDeployerPublisher pub = new ArtifactDeployerPublisher();
List<ArtifactDeployerEntry> artifactDeployerEntries = new ArrayList<ArtifactDeployerEntry>();
Object entries = formData.get("deployedArtifact");
if (entries != null) {
if (entries instanceof JSONObject) {
artifactDeployerEntries.add(populateAndGetEntry((JSONObject) entries));
} else {
JSONArray jsonArray = (JSONArray) entries;
Iterator it = jsonArray.iterator();
while (it.hasNext()) {
artifactDeployerEntries.add(populateAndGetEntry((JSONObject) it.next()));
}
}
}
pub.setEntries(artifactDeployerEntries);
pub.setDeployEvenBuildFail(formData.getBoolean("deployEvenBuildFail"));
return pub;
}
// private ArtifactDeployerEntry populateAndGetEntry(JSONObject element) {
// ArtifactDeployerEntry entry = new ArtifactDeployerEntry();
// entry.setIncludes(Util.fixEmpty(element.getString("includes")));
// entry.setBasedir(Util.fixEmpty(element.getString("basedir")));
// entry.setExcludes(Util.fixEmpty(element.getString("excludes")));
// entry.setRemote(Util.fixEmpty(element.getString("remote")));
// entry.setDeleteRemote(element.getBoolean("deleteRemote"));
// entry.setFlatten(element.getBoolean("flatten"));
// entry.setFailNoFilesDeploy(element.getBoolean("failNoFilesDeploy"));
// entry.setDeleteRemoteArtifacts(element.getBoolean("deleteRemoteArtifacts"));
// Object deleteRemoteArtifactsObject = element.get("deleteRemoteArtifactsByScript");
// if (deleteRemoteArtifactsObject == null) {
// entry.setDeleteRemoteArtifactsByScript(false);
// } else {
// entry.setDeleteRemoteArtifactsByScript(true);
// entry.setGroovyExpression(Util.fixEmpty(element.getJSONObject("deleteRemoteArtifactsByScript").getString("groovyExpression")));
// }
// return entry;
// }

// @Override
// public Publisher newInstance(StaplerRequest req, JSONObject formData) throws FormException {
// ArtifactDeployerPublisher pub = new ArtifactDeployerPublisher();
// List<ArtifactDeployerEntry> artifactDeployerEntries = new ArrayList<ArtifactDeployerEntry>();
// Object entries = formData.get("deployedArtifact");
// if (entries != null) {
// if (entries instanceof JSONObject) {
// artifactDeployerEntries.add(populateAndGetEntry((JSONObject) entries));
// } else {
// JSONArray jsonArray = (JSONArray) entries;
// Iterator it = jsonArray.iterator();
// while (it.hasNext()) {
// artifactDeployerEntries.add(populateAndGetEntry((JSONObject) it.next()));
// }
// }
// }
// pub.setEntries(artifactDeployerEntries);
// pub.setDeployEvenBuildFail(formData.getBoolean("deployEvenBuildFail"));
// return pub;
// }

public FormValidation doCheckIncludes(@AncestorInPath AbstractProject project, @QueryParameter String value) throws IOException {
return FilePath.validateFileMask(project.getSomeWorkspace(), value);
Expand Down
@@ -0,0 +1,20 @@
package org.jenkinsci.plugins.artifactdeployer;

import org.kohsuke.stapler.DataBoundConstructor;

/**
* @author Gregory Boissinot
*/
public class DeleteRemoteArtifactsByScriptModel {

private String groovyExpression;

@DataBoundConstructor
public DeleteRemoteArtifactsByScriptModel(String groovyExpression) {
this.groovyExpression = groovyExpression;
}

public String getGroovyExpression() {
return groovyExpression;
}
}

0 comments on commit 61d97a0

Please sign in to comment.