提交 a4c8c7c7 编写于 作者: K kohsuke

making the same change that I made to BuildStep to BuildWrapper.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@5548 71c3de6d-444a-0410-be80-ed276b4c234a
上级 b53e6a52
......@@ -20,6 +20,8 @@ import hudson.model.View;
import hudson.search.SearchableModelObject;
import hudson.tasks.BuildStep;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrappers;
import hudson.tasks.Builder;
import hudson.tasks.Publisher;
import org.apache.commons.jexl.parser.ASTSizeFunction;
......@@ -437,6 +439,10 @@ public class Functions {
return JobPropertyDescriptor.getPropertyDescriptors(clazz);
}
public static List<Descriptor<BuildWrapper>> getBuildWrapperDescriptors(AbstractProject<?,?> project) {
return BuildWrappers.getFor(project);
}
public static List<Descriptor<Builder>> getBuilderDescriptors(AbstractProject<?,?> project) {
return filterBuildStepDescriptors(BuildStep.BUILDERS,project);
}
......
......@@ -2,6 +2,7 @@ package hudson.tasks;
import hudson.ExtensionPoint;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.Build;
import hudson.model.BuildListener;
import hudson.model.Describable;
......@@ -78,8 +79,22 @@ public abstract class BuildWrapper implements ExtensionPoint, Describable<BuildW
* @throws IOException
* terminates the build abnormally. Hudson will handle the exception
* and reports a nice error message.
* @since 1.150
*/
public abstract boolean tearDown( Build build, BuildListener listener ) throws IOException, InterruptedException;
public boolean tearDown( AbstractBuild build, BuildListener listener ) throws IOException, InterruptedException {
if (build instanceof Build)
return tearDown((Build)build, listener);
else
return true;
}
/**
* @deprecated
* Use {@link #tearDown(AbstractBuild, BuildListener)} instead.
*/
public boolean tearDown( Build build, BuildListener listener ) throws IOException, InterruptedException {
return true;
}
}
/**
......@@ -100,6 +115,20 @@ public abstract class BuildWrapper implements ExtensionPoint, Describable<BuildW
* @throws IOException
* terminates the build abnormally. Hudson will handle the exception
* and reports a nice error message.
* @since 1.150
*/
public abstract Environment setUp( Build build, Launcher launcher, BuildListener listener ) throws IOException, InterruptedException;
public Environment setUp( AbstractBuild build, Launcher launcher, BuildListener listener ) throws IOException, InterruptedException {
if (build instanceof Build)
return setUp((Build)build,launcher,listener);
else
throw new AssertionError();
}
/**
* @deprecated
* Use {@link #setUp(AbstractBuild, Launcher, BuildListener)} instead.
*/
public Environment setUp( Build build, Launcher launcher, BuildListener listener ) throws IOException, InterruptedException {
throw new UnsupportedOperationException(getClass()+" needs to implement the setUp method");
}
}
package hudson.tasks;
import hudson.model.AbstractProject;
import hudson.model.Descriptor;
/**
* {@link Descriptor} for {@link BuildWrapper}.
*
* @author Kohsuke Kawaguchi
* @since 1.150
* @see BuildWrappers#WRAPPERS
*/
public abstract class BuildWrapperDescriptor extends Descriptor<BuildWrapper> {
protected BuildWrapperDescriptor(Class<? extends BuildWrapper> clazz) {
super(clazz);
}
/**
* Returns true if this task is applicable to the given project.
*
* @return
* true to allow user to configure this post-promotion task for the given project.
*/
public abstract boolean isApplicable(AbstractProject<?,?> item);
}
package hudson.tasks;
import hudson.model.AbstractProject;
import hudson.model.Descriptor;
import hudson.model.Project;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -12,4 +15,27 @@ import java.util.List;
public class BuildWrappers {
public static final List<Descriptor<BuildWrapper>> WRAPPERS = Descriptor.toList(
);
/**
* List up all {@link BuildWrapperDescriptor}s that are applicable for the given project.
*
* @return
* The signature doesn't use {@link BuildWrapperDescriptor} to maintain compatibility
* with {@link BuildWrapper} implementations before 1.150.
*/
public static List<Descriptor<BuildWrapper>> getFor(AbstractProject<?, ?> project) {
List<Descriptor<BuildWrapper>> result = new ArrayList<Descriptor<BuildWrapper>>();
for (Descriptor<BuildWrapper> w : WRAPPERS) {
if (w instanceof BuildWrapperDescriptor) {
BuildWrapperDescriptor bwd = (BuildWrapperDescriptor) w;
if(bwd.isApplicable(project))
result.add(bwd);
} else {
// old BuildWrapper that doesn't implement BuildWrapperDescriptor
if(project instanceof Project)
result.add(w);
}
}
return result;
}
}
......@@ -2,7 +2,7 @@
Build wrapper config pane
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:p="/lib/hudson/project">
<j:getStatic var="wrappers" className="hudson.tasks.BuildWrappers" field="WRAPPERS" />
<j:set var="wrappers" value="${h.getBuildWrapperDescriptors(it)}" />
<j:if test="${!empty(wrappers)}">
<f:descriptorList title="Build Environment"
descriptors="${wrappers}"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册