diff --git a/core/src/main/java/hudson/maven/MavenBuildProxy.java b/core/src/main/java/hudson/maven/MavenBuildProxy.java index 282f241aabd89520e47fa03e4c22ab1c0d165b16..ac1ed601dc7ccf1267ebb3bb4cfc095ae3e4ce29 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 69c6821ac450371f3356fc976ad428accaf3a593..5095dd281012bbd882aa51f03477efd5aadcb408 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() {