Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.10</version>
<version>3.13</version>
<relativePath />
</parent>

Expand All @@ -26,9 +26,9 @@
<properties>
<revision>1.41</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.118</jenkins.version>
<jenkins.version>2.121</jenkins.version>
<java.level>8</java.level>
<workflow-api-plugin.version>2.28-rc333.0675e9e9cb4c</workflow-api-plugin.version> <!-- TODO https://github.com/jenkinsci/workflow-api-plugin/pull/67 -->
<workflow-api-plugin.version>2.28-rc343.e9b9e0610374</workflow-api-plugin.version> <!-- TODO https://github.com/jenkinsci/workflow-api-plugin/pull/67 -->
<useBeta>true</useBeta>
</properties>

Expand All @@ -44,6 +44,11 @@
<artifactId>structs</artifactId>
<version>1.14</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>apache-httpcomponents-client-4-api</artifactId>
<version>4.5.5-3.0</version>
</dependency>
<!-- Used for UI test -->
<dependency>
<groupId>org.jenkins-ci.main</groupId>
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/hudson/plugins/copyartifact/CopyArtifact.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import hudson.util.FormValidation;
import hudson.util.VariableResolver;
import hudson.util.XStream2;
import io.jenkins.plugins.httpclient.RobustHTTPClient;
import java.io.File;
import java.io.FileOutputStream;

Expand Down Expand Up @@ -93,6 +94,7 @@
import jenkins.MasterToSlaveFileCallable;
import jenkins.util.VirtualFile;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.HttpGet;

/**
* Build step to copy artifacts from another project.
Expand Down Expand Up @@ -598,9 +600,9 @@ private static String copyOne(VirtualFile s, FilePath d, boolean fingerprint, Ta
byte[] digest;
if (u != null) {
if (fingerprint) {
digest = d.act(new CopyURLWithFingerprinting(u));
digest = d.act(new CopyURLWithFingerprinting(u, listener));
} else {
d.copyFromRemotely(u);
new RobustHTTPClient().copyFromRemotely(d, u, listener);
digest = null;
}
} else {
Expand Down Expand Up @@ -636,16 +638,21 @@ private static String copyOne(VirtualFile s, FilePath d, boolean fingerprint, Ta
private static class CopyURLWithFingerprinting extends MasterToSlaveFileCallable<byte[]> {
private static final long serialVersionUID = 1;
private final URL u;
CopyURLWithFingerprinting(URL u) {
private final TaskListener listener;
private final RobustHTTPClient client = new RobustHTTPClient();
CopyURLWithFingerprinting(URL u, TaskListener listener) {
this.u = u;
this.listener = listener;
}
@Override
public byte[] invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
hudson.util.IOUtils.mkdirs(f.getParentFile());
MessageDigest md5 = md5();
try (InputStream is = u.openStream(); OutputStream os = new FileOutputStream(f)) {
IOUtils.copy(is, new DigestOutputStream(os, md5));
}
client.connect("download", "download " + RobustHTTPClient.sanitize(u) + " to " + f, c -> c.execute(new HttpGet(u.toString())), response -> {
try (InputStream is = response.getEntity().getContent(); OutputStream os = new FileOutputStream(f)) {
IOUtils.copy(is, new DigestOutputStream(os, md5));
}
}, listener);
return md5.digest();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,18 @@

import static org.junit.Assert.*;
import static org.junit.Assume.*;
import org.junit.ClassRule;
import org.jvnet.hudson.test.BuildWatcher;

/**
* Test interaction of copyartifact plugin with Jenkins core.
* @author Alan Harder
*/
public class CopyArtifactTest {

@ClassRule
public static BuildWatcher watcher = new BuildWatcher();

@Rule
public final JenkinsRule rule = new JenkinsRule();

Expand Down