diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index 53d14d3371..a024b713a2 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -1,7 +1,10 @@ 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> getBuilderDescriptors(AbstractProject project) { + return filterBuildStepDescriptors(BuildStep.BUILDERS,project); + } + + public static List> getPublisherDescriptors(AbstractProject project) { + return filterBuildStepDescriptors(BuildStep.PUBLISHERS,project); + } + + private static > List> filterBuildStepDescriptors(List> list,AbstractProject project) { + List> result = new ArrayList>(); + for (Descriptor 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. diff --git a/core/src/main/java/hudson/model/Build.java b/core/src/main/java/hudson/model/Build.java index 4f05ab7119..555d8f1451 100644 --- a/core/src/main/java/hudson/model/Build.java +++ b/core/src/main/java/hudson/model/Build.java @@ -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

,B extends Build> 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 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; diff --git a/core/src/main/java/hudson/tasks/BuildStep.java b/core/src/main/java/hudson/tasks/BuildStep.java index 6c4fe8986b..4e0a81f3f7 100644 --- a/core/src/main/java/hudson/tasks/BuildStep.java +++ b/core/src/main/java/hudson/tasks/BuildStep.java @@ -1,6 +1,8 @@ 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. diff --git a/core/src/main/java/hudson/tasks/BuildStepCompatibilityLayer.java b/core/src/main/java/hudson/tasks/BuildStepCompatibilityLayer.java new file mode 100644 index 0000000000..02eb11df67 --- /dev/null +++ b/core/src/main/java/hudson/tasks/BuildStepCompatibilityLayer.java @@ -0,0 +1,70 @@ +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; + } +} diff --git a/core/src/main/java/hudson/tasks/BuildStepDescriptor.java b/core/src/main/java/hudson/tasks/BuildStepDescriptor.java new file mode 100644 index 0000000000..9da5fb1af7 --- /dev/null +++ b/core/src/main/java/hudson/tasks/BuildStepDescriptor.java @@ -0,0 +1,28 @@ +package hudson.tasks; + +import hudson.model.Describable; +import hudson.model.Descriptor; +import hudson.model.AbstractProject; + +/** + * {@link Descriptor} for {@link Builder} and {@link Publisher}. + * + *

+ * 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> extends Descriptor { + protected BuildStepDescriptor(Class 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); +} diff --git a/core/src/main/java/hudson/tasks/Builder.java b/core/src/main/java/hudson/tasks/Builder.java index 10f5eeacc5..6316b97248 100644 --- a/core/src/main/java/hudson/tasks/Builder.java +++ b/core/src/main/java/hudson/tasks/Builder.java @@ -16,7 +16,12 @@ import hudson.model.Project; * * @author Kohsuke Kawaguchi */ -public abstract class Builder implements BuildStep, Describable, ExtensionPoint { +public abstract class Builder extends BuildStepCompatibilityLayer implements BuildStep, Describable, ExtensionPoint { + + +// +// these two methods need to remain to keep binary compatibility with plugins built with Hudson < 1.150 +// /** * Default implementation that does nothing. */ diff --git a/core/src/main/java/hudson/tasks/Publisher.java b/core/src/main/java/hudson/tasks/Publisher.java index e32f941f45..d7a1a53056 100644 --- a/core/src/main/java/hudson/tasks/Publisher.java +++ b/core/src/main/java/hudson/tasks/Publisher.java @@ -16,7 +16,10 @@ import hudson.model.Project; * * @author Kohsuke Kawaguchi */ -public abstract class Publisher implements BuildStep, Describable, ExtensionPoint { +public abstract class Publisher extends BuildStepCompatibilityLayer implements BuildStep, Describable, ExtensionPoint { +// +// these two methods need to remain to keep binary compatibility with plugins built with Hudson < 1.150 +// /** * Default implementation that does nothing. */ diff --git a/core/src/main/resources/lib/hudson/project/config-builders.jelly b/core/src/main/resources/lib/hudson/project/config-builders.jelly index 476a468056..c56f22e740 100644 --- a/core/src/main/resources/lib/hudson/project/config-builders.jelly +++ b/core/src/main/resources/lib/hudson/project/config-builders.jelly @@ -3,9 +3,8 @@ --> - \ No newline at end of file diff --git a/core/src/main/resources/lib/hudson/project/config-publishers.jelly b/core/src/main/resources/lib/hudson/project/config-publishers.jelly index 8d05815c19..0808b3b6d4 100644 --- a/core/src/main/resources/lib/hudson/project/config-publishers.jelly +++ b/core/src/main/resources/lib/hudson/project/config-publishers.jelly @@ -2,9 +2,8 @@ Publisher config pane --> - \ No newline at end of file