提交 f434777d 编写于 作者: K kohsuke

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
上级 2448f481
......@@ -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;
}
}
......@@ -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<FilePath> archivedFiles = new HashSet<FilePath>();
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<Void,IOException>() {
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<FilePath> 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() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册