Skip to content

Commit

Permalink
Symlink support.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Feb 21, 2018
1 parent 45720aa commit ccee158
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -24,8 +24,8 @@
</licenses>

<properties>
<jenkins-core.version>2.109-20180221.200457-2</jenkins-core.version> <!-- TODO https://github.com/jenkinsci/jenkins/pull/3302 -->
<jenkins-war.version>2.109-20180221.200518-2</jenkins-war.version>
<jenkins-core.version>2.109-20180221.210000-3</jenkins-core.version> <!-- TODO https://github.com/jenkinsci/jenkins/pull/3302 -->
<jenkins-war.version>2.109-20180221.210022-3</jenkins-war.version>
<java.level>8</java.level>
</properties>

Expand Down
22 changes: 14 additions & 8 deletions src/main/java/hudson/plugins/copyartifact/CopyArtifact.java
Expand Up @@ -444,13 +444,13 @@ public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace, @Nonn
if (jenkins.getPlugin("maven-plugin") != null && (src instanceof MavenModuleSetBuild) ) {
// use classes in the "maven-plugin" plugin as might not be installed
// Copy artifacts from the build (ArchiveArtifacts build step)
boolean ok = perform(src, build, expandedFilter, expandedExcludes, targetDir, console);
boolean ok = perform(src, build, expandedFilter, expandedExcludes, targetDir, listener);
// Copy artifacts from all modules of this Maven build (automatic archiving)
for (Iterator<MavenBuild> it = ((MavenModuleSetBuild)src).getModuleLastBuilds().values().iterator(); it.hasNext(); ) {
// for(Run r: ....values()) causes upcasting and loading MavenBuild compiled with jdk 1.6.
// SEE https://wiki.jenkins-ci.org/display/JENKINS/Tips+for+optional+dependencies for details.
Run<?,?> r = it.next();
ok |= perform(r, build, expandedFilter, expandedExcludes, targetDir, console);
ok |= perform(r, build, expandedFilter, expandedExcludes, targetDir, listener);
}
if (!ok) {
throw new AbortException(Messages.CopyArtifact_FailedToCopy(expandedProject, expandedFilter));
Expand All @@ -461,13 +461,13 @@ public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace, @Nonn
// Use MatrixBuild.getExactRuns if available
for (Run r : ((MatrixBuild) src).getExactRuns())
// Use subdir of targetDir with configuration name (like "jdk=java6u20")
ok |= perform(r, build, expandedFilter, expandedExcludes, targetDir.child(r.getParent().getName()), console);
ok |= perform(r, build, expandedFilter, expandedExcludes, targetDir.child(r.getParent().getName()), listener);

if (!ok) {
throw new AbortException(Messages.CopyArtifact_FailedToCopy(expandedProject, expandedFilter));
}
} else {
if (!perform(src, build, expandedFilter, expandedExcludes, targetDir, console)) {
if (!perform(src, build, expandedFilter, expandedExcludes, targetDir, listener)) {
throw new AbortException(Messages.CopyArtifact_FailedToCopy(expandedProject, expandedFilter));
}
}
Expand Down Expand Up @@ -521,7 +521,8 @@ private static ItemGroup getItemGroup(Run<?, ?> build) {
}


private boolean perform(Run src, Run<?,?> dst, String expandedFilter, @CheckForNull String expandedExcludes, FilePath targetDir, PrintStream console) throws IOException, InterruptedException {
private boolean perform(Run src, Run<?,?> dst, String expandedFilter, @CheckForNull String expandedExcludes, FilePath targetDir, TaskListener listener) throws IOException, InterruptedException {
PrintStream console = listener.getLogger();
VirtualFile srcDir = selector.getArtifacts(src, console);
if (srcDir == null) {
return isOptional(); // Fail build unless copy is optional
Expand All @@ -544,7 +545,7 @@ private boolean perform(Run src, Run<?,?> dst, String expandedFilter, @CheckForN
targetDir.mkdirs(); // Create target if needed
Collection<String> list = srcDir.list(expandedFilter.replace('\\', '/'), expandedExcludes != null ? expandedExcludes.replace('\\', '/') : null, false);
for (String file : list) {
copyOne(src, dst, fingerprints, srcDir.child(file), new FilePath(targetDir, isFlatten() ? file.replaceFirst(".+/", "") : file), md5);
copyOne(src, dst, fingerprints, srcDir.child(file), new FilePath(targetDir, isFlatten() ? file.replaceFirst(".+/", "") : file), md5, listener);
}
int cnt = list.size();
console.println(Messages.CopyArtifact_Copied(cnt, HyperlinkNote.encodeTo('/'+ src.getParent().getUrl(), src.getParent().getFullDisplayName()),
Expand Down Expand Up @@ -576,9 +577,14 @@ private static String normalizePattern(String p) {
return pattern;
}

private static void copyOne(Run<?,?> src, Run<?,?> dst, Map<String, String> fingerprints, VirtualFile s, FilePath d, MessageDigest md5) throws IOException, InterruptedException {
private static void copyOne(Run<?,?> src, Run<?,?> dst, Map<String, String> fingerprints, VirtualFile s, FilePath d, MessageDigest md5, TaskListener listener) throws IOException, InterruptedException {
assert (fingerprints == null) == (md5 == null);
// TODO JENKINS-26810 handle symlinks
String link = s.readLink();
if (link != null) {
d.getParent().mkdirs();
d.symlinkTo(link, listener);
return;
}
try {
try (InputStream is = s.open(); OutputStream os = d.write()) {
OutputStream os2;
Expand Down
Expand Up @@ -100,7 +100,6 @@

import static org.junit.Assert.*;
import static org.junit.Assume.*;
import org.junit.Ignore;

/**
* Test interaction of copyartifact plugin with Jenkins core.
Expand Down Expand Up @@ -1807,7 +1806,6 @@ public void testFilePermission() throws Exception {
}
}

@Ignore("TODO not yet (re-)implemented")
@Issue("JENKINS-20546")
@Test
public void testSymlinks() throws Exception {
Expand All @@ -1831,7 +1829,6 @@ public void testSymlinks() throws Exception {
assertEquals("nonexistent", ws.child("link2").readLink());
}

@Ignore("TODO not yet (re-)implemented")
@Issue("JENKINS-32832")
@Test
public void testSymlinksInDirectory() throws Exception {
Expand Down

0 comments on commit ccee158

Please sign in to comment.