提交 834f10a5 编写于 作者: J Jesse Glick

Passing in the workspace explicitly means the standard manager can work on any Run.

上级 42922b9a
......@@ -107,11 +107,8 @@ import org.kohsuke.stapler.export.ExportedBean;
import com.thoughtworks.xstream.XStream;
import hudson.ExtensionList;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Run.RunExecution;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import org.kohsuke.stapler.interceptor.RequirePOST;
import java.io.FileOutputStream;
......@@ -952,7 +949,16 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
return new File(project.getBuildDir(),getId());
}
public final synchronized ArtifactManager getArtifactManager() {
/**
* Gets an object responsible for storing and retrieving build artifacts.
* The first time this is called on a running build, a list of all registered custom managers is checked
* to see if one will handle this build.
* If so, the identity of that manager is saved in the build and it will be used henceforth.
* If no manager claimed the build, or we are loading a historical build created prior to this feature, {@link StandardArtifactManager} is used.
* @return an appropriate artifact manager
* @since XXX
*/
public final synchronized @Nonnull ArtifactManager getArtifactManager() {
ExtensionList<ArtifactManager> managers = Jenkins.getInstance().getExtensionList(ArtifactManager.class);
if (artifactManager != null) {
for (ArtifactManager mgr : managers) {
......@@ -973,35 +979,8 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
return mgr;
}
}
} else { // compatibility: completed build prior to introduction of ArtifactManager
ArtifactManager mgr = managers.get(StandardArtifactManager.class);
if (mgr.appliesTo(this)) {
return mgr;
}
}
return new ArtifactManager() { // fallback for non-AbstractProject runs
@Override public boolean appliesTo(Run<?, ?> build) {
return true;
}
@Override public int archive(Run<?,?> build, Launcher launcher, BuildListener listener, String artifacts, String excludes) throws IOException, InterruptedException {
throw new IOException("not supported");
}
@Override public void archiveSingle(Run<?,?> build, Launcher launcher, BuildListener listener, FilePath source, String target) throws IOException, InterruptedException {
throw new IOException("not supported");
}
@Override public boolean deleteArtifacts(Run<?,?> build) throws IOException, InterruptedException {
throw new IOException("not supported");
}
@Override public HttpResponse browseArtifacts(Run<?, ?> build) {
return HttpResponses.notFound();
}
@Override public <JobT extends Job<JobT,RunT>, RunT extends Run<JobT,RunT>> Run<JobT,RunT>.ArtifactList getArtifactsUpTo(Run<JobT,RunT> build, int n) {
return build.new ArtifactList();
}
@Override public InputStream loadArtifact(Run<?,?> build, String artifact) throws IOException {
throw new FileNotFoundException();
}
};
return new StandardArtifactManager();
}
/**
......
......@@ -110,7 +110,7 @@ public class ArtifactArchiver extends Recorder {
String artifacts = build.getEnvironment(listener).expand(this.artifacts);
if (build.getArtifactManager().archive(build, launcher, listener, artifacts, excludes) == 0) {
if (build.getArtifactManager().archive(build, ws, launcher, listener, artifacts, excludes) == 0) {
if(build.getResult().isBetterOrEqualTo(Result.UNSTABLE)) {
// If the build failed, don't complain that there was no matching artifact.
// The build probably didn't even get to the point where it produces artifacts.
......
......@@ -57,7 +57,6 @@ public abstract class ArtifactManager implements ExtensionPoint {
/**
* Permits the manager to restrict its operation to certain kinds of projects, slaves, etc.
* (For example you can limit support to instances of {@link AbstractBuild}, for which {@link AbstractBuild#getWorkspace} is defined.)
* @param build a running build ready for {@link #archive} (the choice of manager will be remembered via {@link #id})
* @return true to handle this build, false to continue the search
*/
......@@ -65,16 +64,18 @@ public abstract class ArtifactManager implements ExtensionPoint {
/**
* Archive all configured artifacts from a build.
* (If called multiple times for the same build, do not delete the old artifacts but keep them all.)
* @param build the build which may have produced archivable files
* @param workspace the workspace from which to copy files
* @param launcher a launcher to use if external processes need to be forked
* @param listener a way to print messages about progress or problems
* @param artifacts comma- or space-separated list of patterns of files/directories to be archived (Ant format, any variables already substituted)
* @param artifacts comma- or space-separated list of patterns of files/directories to be archived relative to the workspace (Ant format, any variables already substituted)
* @param excludes patterns of files to be excluded from the artifact list (Ant format, may be null for no excludes)
* @return the number of files actually archived (may be zero)
* @throws IOException if transfer or copying failed in any way
* @see ArtifactArchiver#perform(AbstractBuild, Launcher, BuildListener)
*/
public abstract int archive(Run<?,?> build, Launcher launcher, BuildListener listener, String artifacts, @CheckForNull String excludes) throws IOException, InterruptedException;
public abstract int archive(Run<?,?> build, FilePath workspace, Launcher launcher, BuildListener listener, String artifacts, @CheckForNull String excludes) throws IOException, InterruptedException;
/**
* Add a single file to the list of archives for a build.
......
......@@ -24,11 +24,9 @@
package jenkins.model;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.DirectoryBrowserSupport;
import hudson.model.Job;
......@@ -46,21 +44,15 @@ import org.kohsuke.stapler.HttpResponse;
* May be subclassed to provide an artifact manager which uses the standard storage but which only overrides {@link #archive}.
* @since XXX
*/
@Extension(ordinal=0)
public class StandardArtifactManager extends ArtifactManager {
@Override public boolean appliesTo(Run<?,?> build) {
// XXX if #archive took a FilePath workspace argument, we could accept any Run
return build instanceof AbstractBuild;
return true;
}
@Override public int archive(Run<?,?> build, Launcher launcher, BuildListener listener, String artifacts, String excludes) throws IOException, InterruptedException {
@Override public int archive(Run<?,?> build, FilePath workspace, Launcher launcher, BuildListener listener, String artifacts, String excludes) throws IOException, InterruptedException {
File dir = getArtifactsDir(build);
dir.mkdirs();
FilePath workspace = ((AbstractBuild) build).getWorkspace();
if (workspace == null) {
return 0; // ArtifactArchiver has already checked this case
}
return workspace.copyRecursiveTo(artifacts, excludes, new FilePath(dir));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册