Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix JENKINS-15354
  • Loading branch information
gboissinot committed Oct 7, 2012
1 parent 2152896 commit 57ce72e
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 6 deletions.
Expand Up @@ -23,6 +23,7 @@ public class ArtifactDeployerEntry implements Serializable {
private boolean deleteRemoteArtifacts;
private boolean deleteRemoteArtifactsByScript;
private String groovyExpression;
private boolean failNoFilesDeploy;

@SuppressWarnings("unused")
public String getIncludes() {
Expand Down Expand Up @@ -75,6 +76,10 @@ public String getGroovyExpression() {
return groovyExpression;
}

public boolean isFailNoFilesDeploy() {
return failNoFilesDeploy;
}

public void setIncludes(String includes) {
this.includes = includes;
}
Expand Down Expand Up @@ -111,6 +116,10 @@ public void setGroovyExpression(String groovyExpression) {
this.groovyExpression = groovyExpression;
}

public void setFailNoFilesDeploy(boolean failNoFilesDeploy) {
this.failNoFilesDeploy = failNoFilesDeploy;
}

@SuppressWarnings({"unused", "deprecation"})
public Object readObject() {
if (this.deletingRemote) {
Expand All @@ -130,6 +139,7 @@ public int getUniqueId() {
result = 31 * result + (deleteRemoteArtifacts ? 1 : 0);
result = 31 * result + (deleteRemoteArtifactsByScript ? 1 : 0);
result = 31 * result + (groovyExpression != null ? groovyExpression.hashCode() : 0);
result = 31 * result + (failNoFilesDeploy ? 1 : 0);
return result;
}
}
Expand Up @@ -107,7 +107,7 @@ private boolean _perform(hudson.model.AbstractBuild<?, ?> build, hudson.Launcher
return true;
}

private Map<Integer, List<ArtifactDeployerVO>> processDeployment(AbstractBuild<?, ?> build, final BuildListener listener, int currentNbDeployedArtifacts) throws IOException, InterruptedException {
private Map<Integer, List<ArtifactDeployerVO>> processDeployment(AbstractBuild<?, ?> build, final BuildListener listener, int currentNbDeployedArtifacts) throws ArtifactDeployerException {

Map<Integer, List<ArtifactDeployerVO>> deployedArtifacts = new HashMap<Integer, List<ArtifactDeployerVO>>();
FilePath workspace = build.getWorkspace();
Expand All @@ -119,10 +119,21 @@ private Map<Integer, List<ArtifactDeployerVO>> processDeployment(AbstractBuild<?
throw new ArtifactDeployerException("All remote directories must be set.");
}

final String includes = build.getEnvironment(listener).expand(entry.getIncludes());
final String excludes = build.getEnvironment(listener).expand(entry.getExcludes());
final String basedir = build.getEnvironment(listener).expand(entry.getBasedir());
final String outputPath = build.getEnvironment(listener).expand(entry.getRemote());
final String includes;
final String excludes;
final String basedir;
final String outputPath;
try {
includes = build.getEnvironment(listener).expand(entry.getIncludes());
excludes = build.getEnvironment(listener).expand(entry.getExcludes());
basedir = build.getEnvironment(listener).expand(entry.getBasedir());
outputPath = build.getEnvironment(listener).expand(entry.getRemote());
} catch (IOException ioe) {
throw new ArtifactDeployerException(ioe);
} catch (InterruptedException ie) {
throw new ArtifactDeployerException(ie);
}

final boolean flatten = entry.isFlatten();

//Creating the remote directory
Expand All @@ -131,6 +142,8 @@ private Map<Integer, List<ArtifactDeployerVO>> processDeployment(AbstractBuild<?
outputFilePath.mkdirs();
} catch (IOException ioe) {
throw new ArtifactDeployerException(String.format("Can't create the directory '%s'", outputPath), ioe);
} catch (InterruptedException ie) {
throw new ArtifactDeployerException(String.format("Can't create the directory '%s'", outputPath), ie);
}

//Deleting files to remote directory if necessary
Expand All @@ -140,6 +153,8 @@ private Map<Integer, List<ArtifactDeployerVO>> processDeployment(AbstractBuild<?
outputFilePath.deleteContents();
} catch (IOException ioe) {
throw new ArtifactDeployerException(String.format("Can't delete contents of '%s'", outputPath), ioe);
} catch (InterruptedException ie) {
throw new ArtifactDeployerException(String.format("Can't delete contents of '%s'", outputPath), ie);
}
}

Expand All @@ -148,13 +163,49 @@ private Map<Integer, List<ArtifactDeployerVO>> processDeployment(AbstractBuild<?
new ArtifactDeployerCopy(listener, includes, excludes, flatten, outputFilePath, numberOfCurrentDeployedArtifacts);
ArtifactDeployerManager deployerManager = new ArtifactDeployerManager();
FilePath basedirFilPath = deployerManager.getBasedirFilePath(workspace, basedir);
List<ArtifactDeployerVO> results = basedirFilPath.act(deployerCopy);
List<ArtifactDeployerVO> results;
try {
results = basedirFilPath.act(deployerCopy);
} catch (IOException ioe) {
throw new ArtifactDeployerException(ioe);
} catch (InterruptedException ie) {
throw new ArtifactDeployerException(ie);
}

if (isFailNoFilesDeploy(results, entry)) {
throw new ArtifactDeployerException("Can't find any artifacts to deploy with the following configuration :"
+ printConfiguration(includes, excludes, basedirFilPath.getRemote(), outputPath));
}

numberOfCurrentDeployedArtifacts += results.size();
deployedArtifacts.put(entry.getUniqueId(), results);
}
return deployedArtifacts;
}

private boolean isFailNoFilesDeploy(List<ArtifactDeployerVO> results, ArtifactDeployerEntry entry) {
return ((results == null || results.size() == 0) && entry.isFailNoFilesDeploy());
}

private String printConfiguration(String includes, String excludes, String basedir, String outputPath) {
StringBuffer sb = new StringBuffer();

if (includes != null) {
sb.append(",includes:").append(includes);
}
if (excludes != null) {
sb.append(",excludes:").append(excludes);
}

sb.append(",basedir:").append(basedir);
sb.append(",outPath:").append(outputPath);
sb.append("]");

sb = sb.replace(0, 1, "[");

return sb.toString();
}

@SuppressWarnings("unused")
public List<ArtifactDeployerEntry> getEntries() {
return entries;
Expand Down Expand Up @@ -279,6 +330,7 @@ private ArtifactDeployerEntry populateAndGetEntry(JSONObject element) {
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) {
Expand Down
Expand Up @@ -31,6 +31,12 @@
<label class="attach-previous">Flatten</label>
</f:entry>

<f:entry field="failNoFilesDeploy">
<f:checkbox name="artifactdeployer.entry.failNoFilesDeploy"
checked="${deployedArtifact.failNoFilesDeploy}"/>
<label class="attach-previous">Fail build if there are no files to deploy</label>
</f:entry>

<f:entry field="deleteRemote">
<f:checkbox name="artifactdeployer.entry.deleteRemote"
checked="${deployedArtifact.deleteRemote}"/>
Expand Down

0 comments on commit 57ce72e

Please sign in to comment.