Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix JENKINS-13841
  • Loading branch information
gboissinot committed Jul 11, 2012
1 parent fd180c0 commit ad3f87b
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 29 deletions.
Expand Up @@ -15,6 +15,7 @@
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.QueryParameter;
Expand Down Expand Up @@ -67,6 +68,7 @@ private Map<Integer, List<ArtifactDeployerVO>> processDeployment(final AbstractB
Map<Integer, List<ArtifactDeployerVO>> deployedArtifacts = new HashMap<Integer, List<ArtifactDeployerVO>>();
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 boolean flatten = entry.isFlatten();

Expand Down Expand Up @@ -94,7 +96,9 @@ private Map<Integer, List<ArtifactDeployerVO>> processDeployment(final AbstractB
int numberOfCurrentDeployedArtifacts = deployedArtifactsAction.getDeployedArtifactsInfo().size();
ArtifactDeployerCopy deployerCopy =
new ArtifactDeployerCopy(listener, includes, excludes, flatten, outputFilePath, numberOfCurrentDeployedArtifacts);
List<ArtifactDeployerVO> results = workspace.act(deployerCopy);
ArtifactDeployerManager deployerManager = new ArtifactDeployerManager();
FilePath basedirFilePath = deployerManager.getBasedirFilePath(workspace, basedir);
List<ArtifactDeployerVO> results = basedirFilePath.act(deployerCopy);
deployedArtifacts.put(entry.getUniqueId(), results);
return deployedArtifacts;
}
Expand Down Expand Up @@ -207,8 +211,9 @@ public String getDisplayName() {
public Builder newInstance(StaplerRequest req, JSONObject formData) throws FormException {
ArtifactDeployerBuilder builder = new ArtifactDeployerBuilder();
ArtifactDeployerEntry entry = new ArtifactDeployerEntry();
entry.setExcludes(Util.fixEmpty(formData.getString("excludes")));
entry.setIncludes(Util.fixEmpty(formData.getString("includes")));
entry.setBasedir(Util.fixEmpty(formData.getString("basedir")));
entry.setExcludes(Util.fixEmpty(formData.getString("excludes")));
entry.setRemote(Util.fixEmpty(formData.getString("remote")));
entry.setDeleteRemote(formData.getBoolean("deleteRemote"));
entry.setFlatten(formData.getBoolean("flatten"));
Expand Down
Expand Up @@ -10,31 +10,30 @@ public class ArtifactDeployerEntry implements Serializable {
@Deprecated
@SuppressWarnings("unused")
private transient String id;
@Deprecated
@SuppressWarnings("unused")
private transient boolean deletingRemote;

private String includes;

private String basedir;
private String excludes;

private String remote;

private boolean flatten;

@SuppressWarnings("unused")
private transient boolean deletingRemote;

private boolean deleteRemote;

private boolean deleteRemoteArtifacts;

private boolean deleteRemoteArtifactsByScript;

private String groovyExpression;

@SuppressWarnings("unused")
public String getIncludes() {
return includes;
}

@SuppressWarnings("unused")
public String getBasedir() {
return basedir;
}

@SuppressWarnings("unused")
public String getExcludes() {
return excludes;
Expand All @@ -50,7 +49,7 @@ public boolean isFlatten() {
return flatten;
}

@SuppressWarnings("unused")
@SuppressWarnings({"unused", "deprecation"})
@Deprecated
public String getId() {
return id;
Expand Down Expand Up @@ -80,6 +79,10 @@ public void setIncludes(String includes) {
this.includes = includes;
}

public void setBasedir(String basedir) {
this.basedir = basedir;
}

public void setExcludes(String excludes) {
this.excludes = excludes;
}
Expand Down Expand Up @@ -108,7 +111,7 @@ public void setGroovyExpression(String groovyExpression) {
this.groovyExpression = groovyExpression;
}

@SuppressWarnings("unused")
@SuppressWarnings({"unused", "deprecation"})
public Object readObject() {
if (this.deletingRemote) {
this.deleteRemote = true;
Expand All @@ -120,6 +123,7 @@ public int getUniqueId() {
int result = includes != null ? includes.hashCode() : 0;
result = 31 * result + (excludes != null ? excludes.hashCode() : 0);
result = 31 * result + (remote != null ? remote.hashCode() : 0);
result = 31 * result + (basedir != null ? basedir.hashCode() : 0);
result = 31 * result + (flatten ? 1 : 0);
result = 31 * result + (deletingRemote ? 1 : 0);
result = 31 * result + (deleteRemote ? 1 : 0);
Expand Down
Expand Up @@ -19,6 +19,7 @@
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.QueryParameter;
Expand Down Expand Up @@ -80,7 +81,7 @@ private boolean isPerformDeployment(AbstractBuild build) {
return build.getResult().isBetterOrEqualTo(Result.UNSTABLE);
}

public boolean _perform(hudson.model.AbstractBuild<?, ?> build, hudson.Launcher launcher, hudson.model.BuildListener listener) throws java.lang.InterruptedException, java.io.IOException {
private boolean _perform(hudson.model.AbstractBuild<?, ?> build, hudson.Launcher launcher, hudson.model.BuildListener listener) throws java.lang.InterruptedException, java.io.IOException {

if (isPerformDeployment(build)) {

Expand Down Expand Up @@ -120,6 +121,7 @@ private Map<Integer, List<ArtifactDeployerVO>> processDeployment(AbstractBuild<?

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 boolean flatten = entry.isFlatten();

Expand All @@ -144,7 +146,9 @@ private Map<Integer, List<ArtifactDeployerVO>> processDeployment(AbstractBuild<?

ArtifactDeployerCopy deployerCopy =
new ArtifactDeployerCopy(listener, includes, excludes, flatten, outputFilePath, numberOfCurrentDeployedArtifacts);
List<ArtifactDeployerVO> results = workspace.act(deployerCopy);
ArtifactDeployerManager deployerManager = new ArtifactDeployerManager();
FilePath basedirFilPath = deployerManager.getBasedirFilePath(workspace, basedir);
List<ArtifactDeployerVO> results = basedirFilPath.act(deployerCopy);
numberOfCurrentDeployedArtifacts += results.size();
deployedArtifacts.put(entry.getUniqueId(), results);
}
Expand Down Expand Up @@ -263,8 +267,9 @@ public String getDisplayName() {

private ArtifactDeployerEntry populateAndGetEntry(JSONObject element) {
ArtifactDeployerEntry entry = new ArtifactDeployerEntry();
entry.setExcludes(Util.fixEmpty(element.getString("excludes")));
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"));
Expand Down
Expand Up @@ -55,12 +55,12 @@ public int compare(ArtifactDeployerVO artifactDeployer1, ArtifactDeployerVO arti
return 0;
}

String fileName1 = artifactDeployer1.getFileName();
String fileName2 = artifactDeployer2.getFileName();
if (fileName1 == null || fileName2 == null) {
String remotePath1 = artifactDeployer1.getRemotePath();
String remotePath2 = artifactDeployer2.getRemotePath();
if (remotePath1 == null || remotePath2 == null) {
return 0;
}
return fileName1.compareTo(fileName2);
return remotePath1.compareTo(remotePath2);
}
};

Expand Down
Expand Up @@ -38,18 +38,18 @@ public ArtifactDeployerCopy(BuildListener listener, String includes, String excl
this.numberOfCurrentDeployedArtifacts = numberOfCurrentDeployedArtifacts;
}

public List<ArtifactDeployerVO> invoke(File localWorkspace, VirtualChannel channel) throws IOException, InterruptedException {
public List<ArtifactDeployerVO> invoke(File localBasedir, VirtualChannel channel) throws IOException, InterruptedException {

String remote = outputFilePath.getRemote();
FileSet fileSet = Util.createFileSet(localWorkspace, includes, excludes);
FileSet fileSet = Util.createFileSet(localBasedir, includes, excludes);
int inputFiles = fileSet.size();

LocalCopy localCopy = new LocalCopy();
List<File> outputFilesList = localCopy.copyAndGetNumbers(fileSet, flatten, new File(remote));
if (inputFiles != outputFilesList.size()) {
listener.getLogger().println(String.format("[ArtifactDeployer] - All the files have not been deployed. There was %d input files but only %d was copied. Maybe you have to use 'Delete content of remote directory' feature for deleting remote directory before deploying.", inputFiles, outputFilesList.size()));
} else {
listener.getLogger().println(String.format("[ArtifactDeployer] - %d file(s) have been copied from the workspace to '%s'.", outputFilesList.size(), outputFilePath));
listener.getLogger().println(String.format("[ArtifactDeployer] - %d file(s) have been copied from the '%s' to '%s'.", outputFilesList.size(), localBasedir.getPath(), outputFilePath));
}

List<ArtifactDeployerVO> deployedArtifactsResultList = new LinkedList<ArtifactDeployerVO>();
Expand Down
@@ -0,0 +1,30 @@
package org.jenkinsci.plugins.artifactdeployer.service;

import hudson.FilePath;
import org.jenkinsci.plugins.artifactdeployer.exception.ArtifactDeployerException;

import java.io.IOException;

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

public FilePath getBasedirFilePath(FilePath ws, String basedirField) {
if (basedirField == null) {
return ws;
}
FilePath basedirFilePath = ws.child(basedirField);
try {
if (!basedirFilePath.exists()) {
throw new ArtifactDeployerException(String.format("The basedir path '%s' from the workspace doesn't exist.", basedirField));
}
} catch (IOException ioe) {
throw new ArtifactDeployerException(ioe);
} catch (InterruptedException ae) {
throw new ArtifactDeployerException(ae);
}
return basedirFilePath;
}

}
Expand Up @@ -4,6 +4,12 @@
<f:textbox name="artifactdeployer.entry.includes" value="${instance.entry.includes}"/>
</f:entry>

<f:advanced>
<f:entry field="basedir" title="${%Basedir}">
<f:textbox name="artifactdeployer.entry.basedir" value="${instance.entry.basedir}"/>
</f:entry>
</f:advanced>

<f:entry field="remote" title="${%Remote directory}">
<f:textbox name="artifactdeployer.entry.remote" value="${instance.entry.remote}"/>
</f:entry>
Expand Down Expand Up @@ -48,5 +54,4 @@

</f:advanced>


</j:jelly>
@@ -0,0 +1,6 @@
<div>
<p>
By default, the basedir is the job workspace.<br/>
Give a value to override the default value.
</p>
</div>
Expand Up @@ -2,7 +2,7 @@
<p>
Can use wildcards like 'module/dist/**/*.zip'. See the <a
href="http://ant.apache.org/manual/Types/fileset.html">@includes of Ant fileset</a> for the exact
format.
The current project, the base directory is the workspace or the SCM module root.
format.<br/>
Files are deployed from the the workspace. You can change this basedir by specifying the basedir field.
</p>
</div>
Expand Up @@ -10,6 +10,12 @@
<f:textbox name="artifactdeployer.entry.includes" value="${deployedArtifact.includes}"/>
</f:entry>

<f:advanced>
<f:entry field="basedir" title="${%Basedir}">
<f:textbox name="artifactdeployer.entry.basedir" value="${deployedArtifact.basedir}"/>
</f:entry>
</f:advanced>

<f:entry field="remote" title="${%Remote directory}">
<f:textbox name="artifactdeployer.entry.remote" value="${deployedArtifact.remote}"/>
</f:entry>
Expand Down
@@ -0,0 +1,6 @@
<div>
<p>
By default, the basedir is the job workspace.<br/>
Give a value to override the default value.
</p>
</div>
Expand Up @@ -2,7 +2,7 @@
<p>
Can use wildcards like 'module/dist/**/*.zip'. See the <a
href="http://ant.apache.org/manual/Types/fileset.html">@includes of Ant fileset</a> for the exact
format.
The current project, the base directory is the workspace or the SCM module root.
format. <br/>
Files are deployed from the the workspace. You can change this basedir by specifying the basedir field.
</p>
</div>

0 comments on commit ad3f87b

Please sign in to comment.