From f434777d5120891a6ac7761184d69766540e7aa9 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Tue, 16 Jan 2007 00:12:10 +0000 Subject: [PATCH] record fingerprints as well as archive artifacts. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@1778 71c3de6d-444a-0410-be80-ed276b4c234a --- .../java/hudson/maven/MavenBuildProxy.java | 9 +++- .../reporters/MavenArtifactArchiver.java | 43 ++++++++++++++----- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/hudson/maven/MavenBuildProxy.java b/core/src/main/java/hudson/maven/MavenBuildProxy.java index 282f241aab..ac1ed601dc 100644 --- a/core/src/main/java/hudson/maven/MavenBuildProxy.java +++ b/core/src/main/java/hudson/maven/MavenBuildProxy.java @@ -47,7 +47,14 @@ public interface MavenBuildProxy { /** * Performs computation and returns the result, * or throws some exception. + * + * @throws InterruptedException + * if the processing is interrupted in the middle. Exception will be + * propagated to the caller. + * @throws IOException + * if the program simply wishes to propage the exception, it may throw + * {@link IOException}. */ - V call(MavenBuild build) throws T; + V call(MavenBuild build) throws T, IOException, InterruptedException; } } diff --git a/core/src/main/java/hudson/maven/reporters/MavenArtifactArchiver.java b/core/src/main/java/hudson/maven/reporters/MavenArtifactArchiver.java index 69c6821ac4..5095dd2810 100644 --- a/core/src/main/java/hudson/maven/reporters/MavenArtifactArchiver.java +++ b/core/src/main/java/hudson/maven/reporters/MavenArtifactArchiver.java @@ -3,42 +3,65 @@ package hudson.maven.reporters; import hudson.FilePath; import hudson.maven.MavenBuildProxy; import hudson.maven.MavenReporter; +import hudson.maven.MavenBuild; +import hudson.maven.MavenBuildProxy.BuildCallable; import hudson.model.BuildListener; import hudson.model.Descriptor; +import hudson.model.FingerprintMap; +import hudson.model.Hudson; import org.apache.maven.artifact.Artifact; import org.apache.maven.project.MavenProject; import org.kohsuke.stapler.StaplerRequest; import java.io.IOException; +import java.util.Set; +import java.util.HashSet; /** - * Archives artifacts of the build. + * Archives artifacts of the build, + * as well as record fingerprints. * * @author Kohsuke Kawaguchi */ public class MavenArtifactArchiver extends MavenReporter { public boolean postBuild(MavenBuildProxy build, MavenProject pom, BuildListener listener) throws InterruptedException, IOException { - record(build,pom.getArtifact(),listener); + final Set archivedFiles = new HashSet(); + + record(build,pom.getArtifact(),listener,archivedFiles); for( Object a : pom.getAttachedArtifacts() ) - record(build,(Artifact)a,listener); + record(build,(Artifact)a,listener,archivedFiles); + + // record fingerprints + build.execute(new BuildCallable() { + public Void call(MavenBuild build) throws IOException, InterruptedException { + FingerprintMap map = Hudson.getInstance().getFingerprintMap(); + for (FilePath file : archivedFiles) + map.getOrCreate(build, file.getName(), file.digest()); + return null; + } + }); + return true; } /** * Archives the given {@link Artifact}. */ - private void record(MavenBuildProxy build, Artifact a, BuildListener listener) throws IOException, InterruptedException { + private void record(MavenBuildProxy build, Artifact a, BuildListener listener, Set archivedFiles) throws IOException, InterruptedException { if(a.getFile()==null) return; // perhaps build failed and didn't leave an artifact listener.getLogger().println("Archiving "+a.getFile()); - new FilePath(a.getFile()).copyTo( - build.getArtifactsDir() - .child(a.getGroupId()) - .child(a.getArtifactId()) - .child(a.getVersion()) - .child(a.getArtifactId()+'-'+a.getVersion()+(a.getClassifier()!=null?'-'+a.getClassifier():"")+'.'+a.getType())); + FilePath target = build.getArtifactsDir() + .child(a.getGroupId()) + .child(a.getArtifactId()) + .child(a.getVersion()) + .child(a.getArtifactId() + '-' + a.getVersion() + (a.getClassifier() != null ? '-' + a.getClassifier() : "") + '.' + a.getType()); + + new FilePath(a.getFile()).copyTo(target); + + archivedFiles.add(target); } public DescriptorImpl getDescriptor() { -- GitLab