Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<revision>1.4</revision>
<changelist>-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/artifactdeployer-plugin</gitHubRepo>
<hpi.bundledArtifacts>ant,ant-filesystem-tasks,ant-launcher,jna,jna-posix</hpi.bundledArtifacts>
<hpi.strictBundledArtifacts>true</hpi.strictBundledArtifacts>
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.baseline>2.479</jenkins.baseline>
Expand Down Expand Up @@ -59,22 +58,13 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
</dependency>
<dependency>
<groupId>com.atlassian</groupId>
<artifactId>ant-filesystem-tasks</artifactId>
<version>0.0.5</version>
</dependency>
</dependencies>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
<repository>
<id>atlassian-public</id>
<url>https://maven.atlassian.com/repository/public</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package org.jenkinsci.plugins.artifactdeployer.service;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.LinkOption;
import java.util.Enumeration;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Copy;
import org.apache.tools.ant.types.FilterSet;
import org.apache.tools.ant.types.FilterSetCollection;

public class CopyWithPerms extends Copy
{

static final String LINE_SEPARATOR = System.getProperty("line.separator");

private boolean preservePermissions = true;

public boolean isPreservePermissions()
{
return preservePermissions;

Check warning on line 25 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 25 is not covered by tests
}

public void setPreservePermissions(boolean preservePermissions)
{
this.preservePermissions = preservePermissions;
}

/**
* Actually does the file (and possibly empty directory) copies.
* This is a good method for subclasses to override.
*/
@Override
protected void doFileOperations() {
if (fileCopyMap.size() > 0) {

Check warning on line 39 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 39 is only partially covered, one branch is missing
log("Copying " + fileCopyMap.size()
+ " file" + (fileCopyMap.size() == 1 ? "" : "s")

Check warning on line 41 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 41 is only partially covered, one branch is missing
+ " to " + destDir.getAbsolutePath());

Enumeration e = fileCopyMap.keys();
while (e.hasMoreElements()) {
String fromFile = (String) e.nextElement();
String[] toFiles = (String[]) fileCopyMap.get(fromFile);

for (int i = 0; i < toFiles.length; i++) {
String toFile = toFiles[i];

if (fromFile.equals(toFile)) {

Check warning on line 52 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 52 is only partially covered, one branch is missing
log("Skipping self-copy of " + fromFile, verbosity);
continue;

Check warning on line 54 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 53-54 are not covered by tests
}
try {
log("Copying " + fromFile + " to " + toFile, verbosity);

FilterSetCollection executionFilters =
new FilterSetCollection();
if (filtering) {

Check warning on line 61 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 61 is only partially covered, one branch is missing
executionFilters
.addFilterSet(getProject().getGlobalFilterSet());

Check warning on line 63 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 62-63 are not covered by tests
}
for (Enumeration filterEnum = getFilterSets().elements();
filterEnum.hasMoreElements();) {

Check warning on line 66 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 66 is only partially covered, one branch is missing
executionFilters
.addFilterSet((FilterSet) filterEnum.nextElement());

Check warning on line 68 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 67-68 are not covered by tests
}
fileUtils.copyFile(new File(fromFile), new File(toFile),
executionFilters,
getFilterChains(), forceOverwrite,
preserveLastModified,
/* append: */ false, getEncoding(),
getOutputEncoding(), getProject()
/*, getForce()*/); //ant 1.8.2

if (preservePermissions) {

Check warning on line 78 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 78 is only partially covered, one branch is missing
var perms = Files.getPosixFilePermissions(Path.of(fromFile), LinkOption.NOFOLLOW_LINKS);
Files.setPosixFilePermissions(Path.of(toFile), perms);
}

} catch (IOException ioe) {
String msg = "Failed to copy " + fromFile + " to " + toFile
+ " due to " + getDueTo(ioe);
File targetFile = new File(toFile);
if (targetFile.exists() && !targetFile.delete()) {

Check warning on line 87 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 87 is only partially covered, 3 branches are missing
msg += " and I couldn't delete the corrupt " + toFile;

Check warning on line 88 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 88 is not covered by tests
}
if (failonerror) {

Check warning on line 90 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 90 is only partially covered, one branch is missing
throw new BuildException(msg, ioe, getLocation());
}
log(msg, Project.MSG_ERR);

Check warning on line 93 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 93 is not covered by tests
}
}
}
}
if (includeEmpty) {

Check warning on line 98 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 98 is only partially covered, one branch is missing
Enumeration e = dirCopyMap.elements();
int createCount = 0;
while (e.hasMoreElements()) {

Check warning on line 101 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 101 is only partially covered, one branch is missing
String[] dirs = (String[]) e.nextElement();
for (int i = 0; i < dirs.length; i++) {
File d = new File(dirs[i]);
if (!d.exists()) {
if (!d.mkdirs()) {
log("Unable to create directory "
+ d.getAbsolutePath(), Project.MSG_ERR);
} else {
createCount++;
}
}
}
}

Check warning on line 114 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 102-114 are not covered by tests
if (createCount > 0) {

Check warning on line 115 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 115 is only partially covered, one branch is missing
log("Copied " + dirCopyMap.size()
+ " empty director"
+ (dirCopyMap.size() == 1 ? "y" : "ies")
+ " to " + createCount
+ " empty director"
+ (createCount == 1 ? "y" : "ies") + " under "
+ destDir.getAbsolutePath());

Check warning on line 122 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 116-122 are not covered by tests
}
}
}


/**
* Returns a reason for failure based on
* the exception thrown.
* If the exception is not IOException output the class name,
* output the message
* if the exception is MalformedInput add a little note.
*/
private String getDueTo(Exception ex) {
boolean baseIOException = ex.getClass() == IOException.class;

Check warning on line 136 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 136 is only partially covered, one branch is missing
StringBuffer message = new StringBuffer();
if (!baseIOException || ex.getMessage() == null) {

Check warning on line 138 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 138 is only partially covered, 3 branches are missing
message.append(ex.getClass().getName());
}
if (ex.getMessage() != null) {

Check warning on line 141 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 141 is only partially covered, one branch is missing
if (!baseIOException) {

Check warning on line 142 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 142 is only partially covered, one branch is missing
message.append(" ");
}
message.append(ex.getMessage());
}
if (ex.getClass().getName().indexOf("MalformedInput") != -1) {

Check warning on line 147 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 147 is only partially covered, one branch is missing
message.append(LINE_SEPARATOR);
message.append(
"This is normally due to the input file containing invalid");
message.append(LINE_SEPARATOR);
message.append("bytes for the character encoding used : ");
message.append(
(getEncoding() == null
? fileUtils.getDefaultEncoding() : getEncoding()));
message.append(LINE_SEPARATOR);

Check warning on line 156 in src/main/java/org/jenkinsci/plugins/artifactdeployer/service/CopyWithPerms.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 148-156 are not covered by tests
}
return message.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/
package org.jenkinsci.plugins.artifactdeployer.service;

import com.atlassian.ant.tasks.CopyWithPerms;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.FileSet;
import org.jenkinsci.plugins.artifactdeployer.ArtifactDeployerException;
Expand Down