Permalink
Browse files

Fixed partially [JENKINS-9996] - Conserve file permission to copy

  • Loading branch information...
gboissinot committed Nov 6, 2011
1 parent d75938b commit 2d989ecbc2eb024a1a6efd0f992a54dda034c61c
Binary file not shown.
13 pom.xml
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
@@ -44,10 +45,20 @@
</scm>

<dependencies>

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

<dependency>
<groupId>com.atlassian.ant.tasks</groupId>
<artifactId>ant-filesystem-tasks</artifactId>
<version>0.0.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ant-filesystem-tasks-0.0.2.jar</systemPath>
</dependency>

</dependencies>

</project>
@@ -36,7 +36,7 @@
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {

listener.getLogger().println("[ArtifactDeployer] - Starting deployment...");
listener.getLogger().println("[ArtifactDeployer] - Starting deployment from the build step ...");
DeployedArtifactsActionManager deployedArtifactsService = DeployedArtifactsActionManager.getInstance();
DeployedArtifacts deployedArtifactsAction = deployedArtifactsService.getOrCreateAction(build);
final FilePath workspace = build.getWorkspace();
@@ -45,12 +45,15 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
deployedArtifacts = processDeployment(build, listener, workspace);
} catch (ArtifactDeployerException ae) {
listener.getLogger().println("[ArtifactDeployer] - [ERROR] - Failed to deploy. " + ae.getMessage());
if (ae.getCause() != null) {
listener.getLogger().println("[ArtifactDeployer] - [ERROR] - " + ae.getCause().getMessage());
}
build.setResult(Result.FAILURE);
return false;
}

deployedArtifactsAction.addDeployedArtifacts(deployedArtifacts);
listener.getLogger().println("[ArtifactDeployer] - Stopping deployment...");
listener.getLogger().println("[ArtifactDeployer] - Stopping deployment from the build step ...");

return true;
}
@@ -70,22 +70,24 @@ public boolean _perform(hudson.model.AbstractBuild<?, ?> build, hudson.Launcher

if (build.getResult() == null || build.getResult().isBetterOrEqualTo(Result.SUCCESS)) {

listener.getLogger().println("[ArtifactDeployer] - Starting deployment...");
listener.getLogger().println("[ArtifactDeployer] - Starting deployment from the post-action ...");
DeployedArtifactsActionManager deployedArtifactsService = DeployedArtifactsActionManager.getInstance();
DeployedArtifacts deployedArtifactsAction = deployedArtifactsService.getOrCreateAction(build);
final FilePath workspace = build.getWorkspace();
Map<Integer, List<ArtifactDeployerVO>> deployedArtifacts;
try {
int currentTotalDeployedCounter = deployedArtifactsAction.getDeployedArtifactsInfo().size();
deployedArtifacts = processDeployment(build, listener, currentTotalDeployedCounter);
} catch (ArtifactDeployerException ae) {
listener.getLogger().println("[ArtifactDeployer] - [ERROR] - Failed to deploy. " + ae.getMessage());
if (ae.getCause() != null) {
listener.getLogger().println("[ArtifactDeployer] - [ERROR] - " + ae.getCause().getMessage());
}
build.setResult(Result.FAILURE);
return false;
}

deployedArtifactsAction.addDeployedArtifacts(deployedArtifacts);
listener.getLogger().println("[ArtifactDeployer] - Stopping deployment...");
listener.getLogger().println("[ArtifactDeployer] - Stopping deployment from the post-action...");
}
return true;
}
@@ -98,7 +100,6 @@ public boolean _perform(hudson.model.AbstractBuild<?, ?> build, hudson.Launcher
int numberOfCurrentDeployedArtifacts = currentNbDeployedArtifacts;
for (final ArtifactDeployerEntry entry : entries) {


if (entry.getRemote() == null) {
throw new ArtifactDeployerException("All remote directories must be set.");
}
@@ -39,18 +39,19 @@ public ArtifactDeployerCopy(BuildListener listener, String includes, String excl
}

public List<ArtifactDeployerVO> invoke(File localWorkspace, VirtualChannel channel) throws IOException, InterruptedException {
LocalCopy localCopy = new LocalCopy();
FileSet fileSet = Util.createFileSet(localWorkspace, includes, excludes);

String remote = outputFilePath.getRemote();
FileSet fileSet = Util.createFileSet(localWorkspace, includes, excludes);
int inputFiles = fileSet.size();
List<File> outputFilesList = localCopy.copyAndGetNumbers(fileSet, flatten, new File(outputFilePath.getRemote()));

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));
}


List<ArtifactDeployerVO> deployedArtifactsResultList = new LinkedList<ArtifactDeployerVO>();
for (File renoteFile : outputFilesList) {
ArtifactDeployerVO deploymentResultEntry = new ArtifactDeployerVO();
@@ -1,7 +1,7 @@
package org.jenkinsci.plugins.artifactdeployer.service;

import com.atlassian.ant.tasks.CopyWithPerms;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Copy;
import org.apache.tools.ant.types.FileSet;
import org.jenkinsci.plugins.artifactdeployer.exception.ArtifactDeployerException;

@@ -16,7 +16,7 @@

public List<File> copyAndGetNumbers(FileSet fileSet, boolean flatten, File target) throws ArtifactDeployerException {

class CopyImpl extends Copy {
class CopyImpl extends CopyWithPerms {

private final List<File> deployedFiles = new ArrayList<File>();

@@ -36,7 +36,6 @@ protected void doFileOperations() {
}
}
super.doFileOperations();

}

public int getNumCopied() {
@@ -55,11 +54,12 @@ public int getNumCopied() {
copyTask.setOverwrite(false);
copyTask.setIncludeEmptyDirs(true);
copyTask.setFlatten(flatten);
copyTask.setPreservePermissions(true);

try {
copyTask.execute();
} catch (BuildException be) {
throw new ArtifactDeployerException("Error on copying file", be);
throw new ArtifactDeployerException("Error on copying file.", be);
}
return copyTask.getDeployedFiles();
}

0 comments on commit 2d989ec

Please sign in to comment.