提交 5d1ea5c5 编写于 作者: K kohsuke

refactoring BuildStep so that it can be used for other project types.

This is so far done in a way that maintains the binary/source compatibility with old plugins.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@5546 71c3de6d-444a-0410-be80-ed276b4c234a
上级 c4156324
package hudson;
import hudson.maven.ExecutedMojo;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.model.Item;
import hudson.model.ItemGroup;
......@@ -15,6 +18,10 @@ import hudson.model.Run;
import hudson.model.TopLevelItem;
import hudson.model.View;
import hudson.search.SearchableModelObject;
import hudson.tasks.BuildStep;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.tasks.Publisher;
import org.apache.commons.jexl.parser.ASTSizeFunction;
import org.apache.commons.jexl.util.Introspector;
import org.kohsuke.stapler.Ancestor;
......@@ -37,6 +44,7 @@ import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
......@@ -429,6 +437,31 @@ public class Functions {
return JobPropertyDescriptor.getPropertyDescriptors(clazz);
}
public static List<Descriptor<Builder>> getBuilderDescriptors(AbstractProject<?,?> project) {
return filterBuildStepDescriptors(BuildStep.BUILDERS,project);
}
public static List<Descriptor<Publisher>> getPublisherDescriptors(AbstractProject<?,?> project) {
return filterBuildStepDescriptors(BuildStep.PUBLISHERS,project);
}
private static <T extends BuildStep&Describable<T>> List<Descriptor<T>> filterBuildStepDescriptors(List<Descriptor<T>> list,AbstractProject<?,?> project) {
List<Descriptor<T>> result = new ArrayList<Descriptor<T>>();
for (Descriptor<T> b : list) {
if (b instanceof BuildStepDescriptor) {
BuildStepDescriptor bsd = (BuildStepDescriptor) b;
if(bsd.isApplicable(project))
result.add(b);
} else {
// old plugins built before 1.150 may not implement BuildStepDescriptor
if(project instanceof Project) {
result.add(b);
}
}
}
return result;
}
/**
* Computes the path to the icon of the given action
* from the context path.
......
......@@ -4,7 +4,6 @@ import hudson.tasks.BuildStep;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapper.Environment;
import hudson.tasks.Builder;
import hudson.tasks.Publisher;
import hudson.triggers.SCMTrigger;
import java.io.File;
......@@ -133,12 +132,12 @@ public abstract class Build <P extends Project<P,B>,B extends Build<P,B>>
public void post2(BuildListener listener) throws IOException, InterruptedException {
// run all of them even if one of them failed
for( Publisher bs : project.getPublishers().values() )
for( BuildStep bs : project.getPublishers().values() )
bs.perform(Build.this, launcher, listener);
}
private boolean build(BuildListener listener, Map<?, Builder> steps) throws IOException, InterruptedException {
for( Builder bs : steps.values() )
for( BuildStep bs : steps.values() )
if(!bs.perform(Build.this, launcher, listener))
return false;
return true;
......
package hudson.tasks;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.Build;
import hudson.model.BuildListener;
......@@ -41,7 +43,7 @@ public interface BuildStep {
* true if the build can continue, false if there was an error
* and the build needs to be aborted.
*/
boolean prebuild( Build<?,?> build, BuildListener listener );
boolean prebuild( AbstractBuild<?,?> build, BuildListener listener );
/**
* Runs the step over the given build and reports the progress to the listener.
......@@ -67,7 +69,7 @@ public interface BuildStep {
* provide a better error message, if it can do so, so that users have better
* understanding on why it failed.
*/
boolean perform(Build<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException;
boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException;
/**
* Returns an action object if this {@link BuildStep} has an action
......@@ -84,7 +86,7 @@ public interface BuildStep {
* @return
* null if there's no action to be contributed.
*/
Action getProjectAction(Project<?,?> project);
Action getProjectAction(AbstractProject<?,?> project);
/**
* List of all installed builders.
......
package hudson.tasks;
import hudson.model.Build;
import hudson.model.BuildListener;
import hudson.model.Action;
import hudson.model.Project;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.Launcher;
import java.io.IOException;
/**
* Provides compatibility with {@link BuildStep} before 1.150
* so that old plugin binaries can continue to function with new Hudson.
*
* @author Kohsuke Kawaguchi
* @since 1.150
*/
public abstract class BuildStepCompatibilityLayer implements BuildStep {
//
// new definitions >= 1.150
//
public boolean prebuild(AbstractBuild<?,?> build, BuildListener listener) {
if (build instanceof Build)
return prebuild((Build)build,listener);
else
return true;
}
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
if (build instanceof Build)
return perform((Build)build,launcher,listener);
else
return true;
}
public Action getProjectAction(AbstractProject<?, ?> project) {
if (project instanceof Project)
return getProjectAction((Project) project);
else
return null;
}
//
// old definitions < 1.150
//
/**
* @deprecated
* Use {@link #prebuild(AbstractBuild, BuildListener)} instead.
*/
public boolean prebuild(Build<?,?> build, BuildListener listener) {
return true;
}
/**
* @deprecated
* Use {@link #perform(AbstractBuild, Launcher, BuildListener)} instead.
*/
public boolean perform(Build<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
throw new UnsupportedOperationException();
}
/**
* @deprecated
* Use {@link #getProjectAction(AbstractProject)} instead.
*/
public Action getProjectAction(Project<?,?> project) {
return null;
}
}
package hudson.tasks;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.AbstractProject;
/**
* {@link Descriptor} for {@link Builder} and {@link Publisher}.
*
* <p>
* For compatibility reasons, plugins developed before 1.150 may not extend from this descriptor type.
*
* @author Kohsuke Kawaguchi
* @since 1.150
*/
public abstract class BuildStepDescriptor<T extends BuildStep & Describable<T>> extends Descriptor<T> {
protected BuildStepDescriptor(Class<? extends T> 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);
}
......@@ -16,7 +16,12 @@ import hudson.model.Project;
*
* @author Kohsuke Kawaguchi
*/
public abstract class Builder implements BuildStep, Describable<Builder>, ExtensionPoint {
public abstract class Builder extends BuildStepCompatibilityLayer implements BuildStep, Describable<Builder>, ExtensionPoint {
//
// these two methods need to remain to keep binary compatibility with plugins built with Hudson < 1.150
//
/**
* Default implementation that does nothing.
*/
......
......@@ -16,7 +16,10 @@ import hudson.model.Project;
*
* @author Kohsuke Kawaguchi
*/
public abstract class Publisher implements BuildStep, Describable<Publisher>, ExtensionPoint {
public abstract class Publisher extends BuildStepCompatibilityLayer implements BuildStep, Describable<Publisher>, ExtensionPoint {
//
// these two methods need to remain to keep binary compatibility with plugins built with Hudson < 1.150
//
/**
* Default implementation that does nothing.
*/
......
......@@ -3,9 +3,8 @@
-->
<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">
<!-- build config pane -->
<j:getStatic var="builders" className="hudson.tasks.BuildStep" field="BUILDERS" />
<f:descriptorList title="Build"
descriptors="${builders}"
descriptors="${h.getBuilderDescriptors(it)}"
instances="${it.builders}"
varName="builder" />
</j:jelly>
\ No newline at end of file
......@@ -2,9 +2,8 @@
Publisher 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="publishers" className="hudson.tasks.BuildStep" field="PUBLISHERS" />
<f:descriptorList title="Post-build Actions"
descriptors="${publishers}"
descriptors="${h.getPublisherDescriptors(it)}"
instances="${it.publishers}"
varName="publisher" />
</j:jelly>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册