Skip to content
Permalink
Browse files

Refactoring + Fixed partially JENKINS-10360 - Added support of maven …

…project
  • Loading branch information...
gboissinot committed Sep 25, 2011
1 parent a770afd commit 802f7a46926208aa33f6cdc6204340d4a7874463
Showing with 21 additions and 42 deletions.
  1. +7 −0 pom.xml
  2. +14 −42 src/main/java/org/jenkinsci/plugins/artifactdeployer/ArtifactDeployerPublisher.java
@@ -44,4 +44,11 @@
<developerConnection>scm:git:git://github.com/jenkinsci/artifactdeployer-plugin.git</developerConnection>
</scm>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
</dependency>
</dependencies>

</project>
@@ -5,9 +5,9 @@
import hudson.Extension;
import hudson.FilePath;
import hudson.Util;
import hudson.maven.MavenModuleSet;
import hudson.model.*;
import hudson.model.listeners.RunListener;
import hudson.remoting.VirtualChannel;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
@@ -16,15 +16,13 @@
import hudson.util.FormValidation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.tools.ant.types.FileSet;
import org.jenkinsci.plugins.artifactdeployer.exception.ArtifactDeployerException;
import org.jenkinsci.plugins.artifactdeployer.service.ArtifactDeployerCopy;
import org.jenkinsci.plugins.artifactdeployer.service.DeployedArtifactsActionManager;
import org.jenkinsci.plugins.artifactdeployer.service.LocalCopy;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
@@ -58,7 +56,8 @@ public boolean perform(hudson.model.AbstractBuild<?, ?> build, hudson.Launcher l
final FilePath workspace = build.getWorkspace();
Map<Integer, List<ArtifactDeployerVO>> deployedArtifacts;
try {
deployedArtifacts = processDeployment(build, listener, workspace);
int currentTotalDeployedCounter = deployedArtifactsAction.getDeployedArtifactsInfo().size();
deployedArtifacts = processDeployment(build, listener, currentTotalDeployedCounter);
} catch (ArtifactDeployerException ae) {
listener.getLogger().println("[ArtifactDeployer] - Failed to deploy " + ae.getMessage());
build.setResult(Result.FAILURE);
@@ -71,20 +70,18 @@ public boolean perform(hudson.model.AbstractBuild<?, ?> build, hudson.Launcher l
return true;
}

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

Map<Integer, List<ArtifactDeployerVO>> deployedArtifacts = new HashMap<Integer, List<ArtifactDeployerVO>>();
FilePath workspace = build.getWorkspace();

//Build and deploy artifact
DeployedArtifactsActionManager deployedArtifactsService = DeployedArtifactsActionManager.getInstance();
DeployedArtifacts deployedArtifactsAction = deployedArtifactsService.getOrCreateAction(build);
int currentTotalDeployedCounter = deployedArtifactsAction.getDeployedArtifactsInfo().size();
int numberOfCurrentDeployedArtifacts = currentNbDeployedArtifacts;
for (final ArtifactDeployerEntry entry : entries) {

final String includes = build.getEnvironment(listener).expand(entry.getIncludes());
final String excludes = build.getEnvironment(listener).expand(entry.getExcludes());
final String outputPath = build.getEnvironment(listener).expand(entry.getRemote());
final boolean flatten = entry.isFlatten();
final int forCounter = currentTotalDeployedCounter;

//Creating the remote directory
final FilePath outputFilePath = new FilePath(workspace.getChannel(), outputPath);
@@ -104,37 +101,11 @@ public boolean perform(hudson.model.AbstractBuild<?, ?> build, hudson.Launcher l
}
}

//Copying files to remote directory
List<ArtifactDeployerVO> results = workspace.act(new FilePath.FileCallable<List<ArtifactDeployerVO>>() {
public List<ArtifactDeployerVO> invoke(File localWorkspace, VirtualChannel channel) throws IOException, InterruptedException {

LocalCopy localCopy = new LocalCopy();
FileSet fileSet = Util.createFileSet(localWorkspace, includes, excludes);

int inputFiles = fileSet.size();
List<File> outputFilesList = localCopy.copyAndGetNumbers(fileSet, flatten, new File(outputFilePath.getRemote()));
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(), outputPath));
}

int localJobDeployedFileCounter = forCounter;
List<ArtifactDeployerVO> deployedArtifactsResultList = new LinkedList<ArtifactDeployerVO>();
for (File renoteFile : outputFilesList) {
ArtifactDeployerVO deploymentResultEntry = new ArtifactDeployerVO();
localJobDeployedFileCounter++;
deploymentResultEntry.setId(localJobDeployedFileCounter);
deploymentResultEntry.setDeployed(true);
deploymentResultEntry.setFileName(renoteFile.getName());
deploymentResultEntry.setRemotePath(renoteFile.getPath());

deployedArtifactsResultList.add(deploymentResultEntry);
}
return deployedArtifactsResultList;
}
});
currentTotalDeployedCounter += results.size();
ArtifactDeployerCopy deployerCopy =
new ArtifactDeployerCopy(listener, includes, excludes, flatten, outputFilePath, numberOfCurrentDeployedArtifacts);
List<ArtifactDeployerVO> results = workspace.act(deployerCopy);
numberOfCurrentDeployedArtifacts += results.size();
deployedArtifacts.put(entry.getUniqueId(), results);
}
return deployedArtifacts;
@@ -228,7 +199,8 @@ public void onDeleted(AbstractBuild build) {

@Override
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return FreeStyleProject.class.isAssignableFrom(jobType);
return FreeStyleProject.class.isAssignableFrom(jobType)
|| MavenModuleSet.class.isAssignableFrom(jobType);
}

@Override

0 comments on commit 802f7a4

Please sign in to comment.
You can’t perform that action at this time.