提交 d741f23d 编写于 作者: K kohsuke

- allowing InterruptedException in more places.

- hooking up FileSystemProvisioner


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15345 71c3de6d-444a-0410-be80-ed276b4c234a
上级 6e8b8141
......@@ -30,7 +30,6 @@ import hudson.model.Computer;
import hudson.model.Describable;
import hudson.model.Job;
import hudson.model.TaskListener;
import hudson.model.Node;
import hudson.model.listeners.RunListener;
import hudson.util.DescriptorList;
import hudson.scm.SCM;
......@@ -140,7 +139,7 @@ public abstract class FileSystemProvisioner implements ExtensionPoint, Describab
* When a project is deleted, this method is called to undo the effect of
* {@link #prepareWorkspace(AbstractBuild, FilePath, TaskListener)}.
*/
public abstract void discardWorkspace(AbstractProject<?,?> project, TaskListener listener) throws IOException, InterruptedException;
public abstract void discardWorkspace(AbstractProject<?,?> project) throws IOException, InterruptedException;
// public abstract void moveWorkspace(AbstractProject<?,?> project, File oldWorkspace, File newWorkspace) throws IOException;
......@@ -167,15 +166,6 @@ public abstract class FileSystemProvisioner implements ExtensionPoint, Describab
public abstract FileSystemProvisionerDescriptor getDescriptor();
/**
* TODO: eventually move this to {@link Node} since it needs to be configurable
* per node, but as of now kept here to avoid interfering with the production code.
*/
public static FileSystemProvisioner get(Node node) {
return DEFAULT;
}
/**
* A list of available file system provider types.
*/
......@@ -194,11 +184,9 @@ public abstract class FileSystemProvisioner implements ExtensionPoint, Describab
private Default() {}
public void prepareWorkspace(AbstractBuild<?, ?> build, FilePath ws, TaskListener listener) throws IOException, InterruptedException {
ws.mkdirs();
}
public void discardWorkspace(AbstractProject<?, ?> project, TaskListener listener) throws IOException, InterruptedException {
project.getWorkspace().deleteRecursive();
public void discardWorkspace(AbstractProject<?,?> project) throws IOException, InterruptedException {
}
/**
......
......@@ -45,7 +45,7 @@ final class LinkedLogRotator extends LogRotator {
}
@Override
public void perform(Job _job) throws IOException {
public void perform(Job _job) throws IOException, InterruptedException {
// copy it to the array because we'll be deleting builds as we go.
MatrixConfiguration job = (MatrixConfiguration) _job;
......
......@@ -421,7 +421,7 @@ public final class MavenModule extends AbstractMavenProject<MavenModule,MavenBui
Hudson.getInstance().rebuildDependencyGraph();
}
protected void performDelete() throws IOException {
protected void performDelete() throws IOException, InterruptedException {
super.performDelete();
getParent().onModuleDeleted(this);
}
......
......@@ -613,7 +613,7 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
/**
* Delete all disabled modules.
*/
public void doDoDeleteAllDisabledModules(StaplerRequest req, StaplerResponse rsp) throws IOException {
public void doDoDeleteAllDisabledModules(StaplerRequest req, StaplerResponse rsp) throws IOException, InterruptedException {
checkPermission(DELETE);
for( MavenModule m : getDisabledModules(true))
m.delete();
......
......@@ -259,6 +259,8 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
if(node instanceof Slave)
listener.getLogger().println(Messages.AbstractBuild_BuildingRemotely(node.getNodeName()));
node.getFileSystemProvisioner().prepareWorkspace(AbstractBuild.this,project.getWorkspace(),listener);
if(checkout(listener))
return Result.FAILURE;
......
......@@ -255,7 +255,7 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet
/**
* Deletes this item.
*/
public void doDoDelete( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
public void doDoDelete( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, InterruptedException {
checkPermission(DELETE);
if(!"POST".equals(req.getMethod())) {
rsp.setStatus(SC_BAD_REQUEST);
......@@ -267,13 +267,18 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet
}
public void delete( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
doDoDelete(req,rsp);
try {
doDoDelete(req,rsp);
} catch (InterruptedException e) {
// TODO: allow this in Stapler
throw new ServletException(e);
}
}
/**
* Deletes this item.
*/
public synchronized void delete() throws IOException {
public synchronized void delete() throws IOException, InterruptedException {
performDelete();
if(this instanceof TopLevelItem)
......@@ -285,7 +290,7 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet
/**
* Does the real job of deleting the item.
*/
protected void performDelete() throws IOException {
protected void performDelete() throws IOException, InterruptedException {
Util.deleteRecursive(getRootDir());
}
......
......@@ -198,12 +198,15 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
updateTransientActions();
}
protected void performDelete() throws IOException {
protected void performDelete() throws IOException, InterruptedException {
// prevent a new build while a delete operation is in progress
makeDisabled(true);
FilePath ws = getWorkspace();
if(ws!=null)
getScm().processWorkspaceBeforeDeletion(this, ws,getLastBuiltOn());
getLastBuiltOn().getFileSystemProvisioner().discardWorkspace(this);
super.performDelete();
}
......
......@@ -173,7 +173,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
this.nextBuildNumber = 1; // reset the next build number
}
protected void performDelete() throws IOException {
protected void performDelete() throws IOException, InterruptedException {
// if a build is in progress. Cancel it.
RunT lb = getLastBuild();
if (lb != null) {
......@@ -278,7 +278,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
/**
* Perform log rotation.
*/
public void logRotate() throws IOException {
public void logRotate() throws IOException, InterruptedException {
LogRotator lr = getLogRotator();
if (lr != null)
lr.perform(this);
......
......@@ -26,6 +26,7 @@ package hudson.model;
import hudson.FilePath;
import hudson.Launcher;
import hudson.ExtensionPoint;
import hudson.FileSystemProvisioner;
import hudson.remoting.VirtualChannel;
import hudson.security.AccessControlled;
import hudson.security.Permission;
......@@ -176,6 +177,11 @@ public abstract class Node extends AbstractModelObject implements Describable<No
return new FilePath(ch,absolutePath);
}
public FileSystemProvisioner getFileSystemProvisioner() {
// TODO: make this configurable or auto-detectable or something else
return FileSystemProvisioner.DEFAULT;
}
public ACL getACL() {
return Hudson.getInstance().getAuthorizationStrategy().getACL(this);
}
......
......@@ -68,7 +68,6 @@ import java.io.PrintWriter;
import java.io.Writer;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
......@@ -746,7 +745,7 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
return builder;
}
public Api getApi(final StaplerRequest req) {
public Api getApi() {
return new Api(this);
}
......@@ -926,6 +925,8 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
getParent().logRotate();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Failed to rotate log",e);
} catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "Failed to rotate log",e);
}
} finally {
onEndBuilding();
......
......@@ -167,7 +167,7 @@ public abstract class SCM implements Describable<SCM>, ExtensionPoint {
*
* @since 1.246
*/
public boolean processWorkspaceBeforeDeletion(AbstractProject<?,?> project, FilePath workspace, Node node) {
public boolean processWorkspaceBeforeDeletion(AbstractProject<?,?> project, FilePath workspace, Node node) throws IOException, InterruptedException {
return true;
}
......
......@@ -75,7 +75,7 @@ public class LogRotator implements Describable<LogRotator> {
this.numToKeep = numToKeep;
}
public void perform(Job<?,?> job) throws IOException {
public void perform(Job<?,?> job) throws IOException, InterruptedException {
// keep the last successful build regardless of the status
Run lsb = job.getLastSuccessfulBuild();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册