Skip to content
Permalink
Browse files

JENKINS-12134 - Make fingerprinting artifacts optional.

  • Loading branch information...
Kelsey Prantis
Kelsey Prantis committed Jun 21, 2012
1 parent c587a69 commit d10dad4341bc2495f469dc5cd4534bbe5e58b13c
@@ -43,25 +43,43 @@ public void init(FilePath srcDir, FilePath baseTargetDir) throws IOException, In
public void init(Run src, AbstractBuild<?,?> dst, FilePath srcDir, FilePath baseTargetDir) throws IOException, InterruptedException {
init(srcDir,baseTargetDir); // for backward compatibility with older subtypes
}

/**
* @deprecated
* call/override {@link #copyAll(FilePath srcDir, String filter, FilePath targetDir, boolean fingerprintArtifacts)} instead.
*/
public int copyAll(FilePath srcDir, String filter, FilePath targetDir) throws IOException, InterruptedException {
return copyAll(srcDir, filter, targetDir, true);
}

/**
* Copy files matching the given file mask to the specified target.
* @param srcDir Source directory
* @param filter Ant GLOB pattern
* @param targetDir Target directory
* @param fingerprintArtifacts boolean controlling if the copy should also fingerprint the artifacts
* @return Number of files that were copied
* @see FilePath#copyRecursiveTo(String,FilePath)
*/
public abstract int copyAll(FilePath srcDir, String filter, FilePath targetDir) throws IOException, InterruptedException;
public abstract int copyAll(FilePath srcDir, String filter, FilePath targetDir, boolean fingerprintArtifacts) throws IOException, InterruptedException;

/**
* @deprecated
* call/override {@link #copyOne(FilePath source, FilePath target, boolean fingerprintArtifacts)} instead.
*/
public void copyOne(FilePath source, FilePath target) throws IOException, InterruptedException {
copyOne(source, target, true);
}

/**
* Copy a single file.
* @param source Source file
* @param target Target file (includes filename; this is not the target directory).
* Directory for target should already exist (copy-artifact build step calls mkdirs).
* @param fingerprintArtifacts boolean controlling if the copy should also fingerprint the artifacts
* @see FilePath#copyTo(FilePath)
*/
public abstract void copyOne(FilePath source, FilePath target) throws IOException, InterruptedException;
public abstract void copyOne(FilePath source, FilePath target, boolean fingerprintArtifacts) throws IOException, InterruptedException;

/**
* Ends what's started by the {@link #init(Run, AbstractBuild, FilePath, FilePath)} method.
@@ -94,11 +112,11 @@ public void init(FilePath srcDir, FilePath baseTargetDir) throws IOException, In
legacy.init(srcDir, baseTargetDir);
}

public int copyAll(FilePath srcDir, String filter, FilePath targetDir) throws IOException, InterruptedException {
public int copyAll(FilePath srcDir, String filter, FilePath targetDir, boolean fingerprintArtifacts) throws IOException, InterruptedException {
return legacy.copyAll(srcDir, filter, targetDir);
}

public void copyOne(FilePath source, FilePath target) throws IOException, InterruptedException {
public void copyOne(FilePath source, FilePath target, boolean fingerprintArtifacts) throws IOException, InterruptedException {
legacy.copyOne(source, target);
}

@@ -89,10 +89,11 @@
private /*almost final*/ BuildSelector selector;
@Deprecated private transient Boolean stable;
private final Boolean flatten, optional;
private final Boolean fingerprintArtifacts;

@DataBoundConstructor
public CopyArtifact(String projectName, BuildSelector selector, String filter, String target,
boolean flatten, boolean optional) {
boolean flatten, boolean optional, boolean fingerprintArtifacts) {
// check the permissions only if we can
StaplerRequest req = Stapler.getCurrentRequest();
if (req!=null) {
@@ -111,6 +112,7 @@ public CopyArtifact(String projectName, BuildSelector selector, String filter, S
this.target = Util.fixNull(target).trim();
this.flatten = flatten ? Boolean.TRUE : null;
this.optional = optional ? Boolean.TRUE : null;
this.fingerprintArtifacts = fingerprintArtifacts ? Boolean.TRUE : null;
}

// Upgrade data from old format
@@ -148,6 +150,10 @@ public boolean isOptional() {
return optional != null && optional;
}

public boolean isFingerprintArtifacts() {
return fingerprintArtifacts != null && fingerprintArtifacts;
}

@Override
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener)
throws InterruptedException {
@@ -240,12 +246,12 @@ private boolean perform(Run src, AbstractBuild<?,?> dst, String expandedFilter,
try {
int cnt;
if (!isFlatten())
cnt = copier.copyAll(srcDir, expandedFilter, targetDir);
cnt = copier.copyAll(srcDir, expandedFilter, targetDir, isFingerprintArtifacts());
else {
targetDir.mkdirs(); // Create target if needed
FilePath[] list = srcDir.list(expandedFilter);
for (FilePath file : list)
copier.copyOne(file, new FilePath(targetDir, file.getName()));
copier.copyOne(file, new FilePath(targetDir, file.getName()), isFingerprintArtifacts());
cnt = list.length;
}

@@ -40,14 +40,14 @@
public class FilePathCopyMethod extends Copier {
/** @see FilePath#recursiveCopyTo(String,FilePath) */
@Override
public int copyAll(FilePath srcDir, String filter, FilePath targetDir)
public int copyAll(FilePath srcDir, String filter, FilePath targetDir, boolean fingerprintArtifacts)
throws IOException, InterruptedException {
return srcDir.copyRecursiveTo(filter, targetDir);
}

/** @see FilePath#copyTo(FilePath) */
@Override
public void copyOne(FilePath source, FilePath target)
public void copyOne(FilePath source, FilePath target, boolean fingerprintArtifacts)
throws IOException, InterruptedException {
source.copyToWithPermission(target);
}
@@ -53,20 +53,20 @@ private MessageDigest newMD5() {
}

@Override
public int copyAll(FilePath srcDir, String filter, FilePath targetDir) throws IOException, InterruptedException {
public int copyAll(FilePath srcDir, String filter, FilePath targetDir, boolean fingerprintArtifacts) throws IOException, InterruptedException {
targetDir.mkdirs(); // Create target if needed
FilePath[] list = srcDir.list(filter);
for (FilePath file : list) {
String tail = file.getRemote().substring(srcDir.getRemote().length());
if (tail.startsWith("\\") || tail.startsWith("/"))
tail = tail.substring(1);
copyOne(file, new FilePath(targetDir, tail));
copyOne(file, new FilePath(targetDir, tail), fingerprintArtifacts);
}
return list.length;
}

@Override
public void copyOne(FilePath s, FilePath d) throws IOException, InterruptedException {
public void copyOne(FilePath s, FilePath d, boolean fingerprintArtifacts) throws IOException, InterruptedException {
try {
md5.reset();
DigestOutputStream out =new DigestOutputStream(d.write(),md5);
@@ -79,14 +79,16 @@ public void copyOne(FilePath s, FilePath d) throws IOException, InterruptedExcep
d.touch(s.lastModified());
String digest = Util.toHexString(md5.digest());

FingerprintMap map = Jenkins.getInstance().getFingerprintMap();
if (fingerprintArtifacts) {
FingerprintMap map = Jenkins.getInstance().getFingerprintMap();

Fingerprint f = map.getOrCreate(src, s.getName(), digest);
if (src!=null) {
f.add((AbstractBuild)src);
Fingerprint f = map.getOrCreate(src, s.getName(), digest);
if (src!=null) {
f.add((AbstractBuild)src);
}
f.add(dst);
fingerprints.put(s.getName(), digest);
}
f.add(dst);
fingerprints.put(s.getName(), digest);
} catch (IOException e) {
throw new IOException2("Failed to copy "+s+" to "+d,e);
}
@@ -40,5 +40,8 @@ THE SOFTWARE.
<st:nbsp/> <st:nbsp/> <st:nbsp/> <st:nbsp/> <st:nbsp/>
<f:checkbox field="optional"/>
<label class="attach-previous">${%Optional}</label>
<st:nbsp/> <st:nbsp/> <st:nbsp/> <st:nbsp/> <st:nbsp/>
<f:checkbox field="fingerprintArtifacts"/>
<label class="attach-previous">${%Fingerprint Artifacts}</label>
</f:entry>
</j:jelly>
@@ -8,4 +8,7 @@
matching the "Which build" condition selected above, the build's workspace does
not exist or is inaccessible, or no artifacts are found matching the specified
pattern. By default this build step fails the build if no artifacts are copied.
<p/>
Select "Fingerprint Artifacts" to automatically fingerprint all artifacts
that are copied as part of this build step.
</div>
Oops, something went wrong.

0 comments on commit d10dad4

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