mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 14:02:22 +00:00
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
This commit is contained in:
1 parent
c4156324ef
commit
5d1ea5c523
9 files changed
+150
-12
No files matched your search
@@ -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<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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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}.
|
||||
*
|
||||
* <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.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user