提交 fe44825a 编写于 作者: K kohsuke

Publishers are now exposed to the m2 job type, too.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@6945 71c3de6d-444a-0410-be80-ed276b4c234a
上级 9142dadd
......@@ -59,8 +59,9 @@ public class Util {
/**
* Creates a filtered sublist.
* @since 1.176
*/
public static <T> List<T> filter( List<?> base, Class<T> type ) {
public static <T> List<T> filter( Iterable<?> base, Class<T> type ) {
List<T> r = new ArrayList<T>();
for (Object i : base) {
if(type.isInstance(i))
......@@ -69,6 +70,13 @@ public class Util {
return r;
}
/**
* Creates a filtered sublist.
*/
public static <T> List<T> filter( List<?> base, Class<T> type ) {
return filter((Iterable)base,type);
}
/**
* Pattern for capturing variables. Either $xyz or ${xyz}, while ignoring "$$"
*/
......
package hudson.maven;
import hudson.CopyOnWrite;
import hudson.FilePath;
import hudson.Indenter;
import hudson.Util;
import hudson.StructuredForm;
import static hudson.Util.fixNull;
import hudson.search.SearchIndexBuilder;
import hudson.search.CollectionSearchIndex;
import hudson.*;
import hudson.model.*;
import hudson.model.Descriptor.FormException;
import static hudson.model.ItemGroupMixIn.loadChildren;
import hudson.model.Queue;
import hudson.model.Queue.Task;
import hudson.tasks.Maven;
import hudson.search.CollectionSearchIndex;
import hudson.search.SearchIndexBuilder;
import hudson.tasks.Maven.MavenInstallation;
import hudson.tasks.*;
import hudson.util.CopyOnWriteMap;
import hudson.util.DescribableList;
import hudson.util.Function1;
import hudson.util.FormFieldValidator;
import hudson.util.Function1;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.QueryParameter;
import javax.servlet.ServletException;
import java.io.File;
import java.io.IOException;
import java.util.*;
import net.sf.json.JSONObject;
/**
* Group of {@link MavenModule}s.
*
......@@ -77,7 +73,9 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
private String mavenOpts;
/**
* If true, the build will be aggregator style. False otherwise.
* If true, the build will be aggregator style, meaning
* all the modules are executed in a single Maven invocation, as in CLI.
* False otherwise, meaning each module is built separately and possibly in parallel.
*
* @since 1.133
*/
......@@ -89,6 +87,14 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
private DescribableList<MavenReporter,Descriptor<MavenReporter>> reporters =
new DescribableList<MavenReporter,Descriptor<MavenReporter>>(this);
/**
* List of active {@link Publisher}s configured for this project.
* @since 1.176
*/
private DescribableList<Publisher,Descriptor<Publisher>> publishers =
new DescribableList<Publisher,Descriptor<Publisher>>(this);
public MavenModuleSet(String name) {
super(Hudson.getInstance(),name);
}
......@@ -124,6 +130,11 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
for (MavenModule module: modules.values()) {
module.updateTransientActions();
}
for (BuildStep step : publishers) {
Action a = step.getProjectAction(this);
if(a!=null)
transientActions.add(a);
}
}
protected void addTransientActionsFromBuild(MavenModuleSetBuild build, Set<Class> added) {
......@@ -190,6 +201,13 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
return reporters;
}
/**
* List of active {@link Publisher}s. Can be empty but never null.
*/
public DescribableList<Publisher, Descriptor<Publisher>> getPublishers() {
return publishers;
}
public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp) {
if(ModuleName.isValid(token))
return getModule(token);
......@@ -279,6 +297,8 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
if(reporters==null)
reporters = new DescribableList<MavenReporter, Descriptor<MavenReporter>>(this);
if(publishers==null)
publishers = new DescribableList<Publisher,Descriptor<Publisher>>(this);
updateTransientActions();
}
......@@ -327,7 +347,7 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
}
protected void buildDependencyGraph(DependencyGraph graph) {
// no dependency for this.
publishers.buildDependencyGraph(this,graph);
}
public MavenModule getRootModule() {
......@@ -335,6 +355,16 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
return modules.get(rootModule);
}
@Override
protected Set<ResourceActivity> getResourceActivities() {
final Set<ResourceActivity> activities = new HashSet<ResourceActivity>();
activities.addAll(super.getResourceActivities());
activities.addAll(Util.filter(publishers,ResourceActivity.class));
return activities;
}
/**
* Gets the location of top-level <tt>pom.xml</tt> relative to the workspace root.
*/
......@@ -444,7 +474,11 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
mavenName = req.getParameter("maven_version");
aggregatorStyleBuild = req.getParameter("maven.perModuleBuild")==null;
reporters.rebuild(req, StructuredForm.get(req),MavenReporters.getConfigurableList(),"reporter");
JSONObject json = StructuredForm.get(req);
reporters.rebuild(req,json,MavenReporters.getConfigurableList(),"reporter");
publishers.rebuild(req,json,BuildStepDescriptor.filter(BuildStep.PUBLISHERS,getClass()),"publisher");
updateTransientActions(); // to pick up transient actions from builder, publisher, etc.
}
/**
......
package hudson.maven;
import hudson.AbortException;
import hudson.Launcher;
import hudson.FilePath;
import hudson.maven.MavenBuild.ProxyImpl2;
import hudson.FilePath.FileCallable;
import hudson.Launcher;
import hudson.maven.MavenBuild.ProxyImpl2;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.Build;
import hudson.model.BuildListener;
import hudson.model.Hudson;
import hudson.model.Result;
import hudson.model.AbstractProject;
import hudson.remoting.VirtualChannel;
import hudson.remoting.Channel;
import hudson.remoting.VirtualChannel;
import hudson.util.ArgumentListBuilder;
import org.apache.maven.BuildFailureException;
import org.apache.maven.embedder.MavenEmbedderException;
......@@ -284,6 +284,8 @@ public final class MavenModuleSetBuild extends AbstractBuild<MavenModuleSet,Mave
} catch (InterruptedException e) {
listener.error("Aborted");
return Result.ABORTED;
} catch (RunnerAbortedException e) {
return Result.FAILURE;
} catch (RuntimeException e) {
// bug in the code.
e.printStackTrace(listener.error("Processing failed due to a bug in the code. Please report thus to users@hudson.dev.java.net"));
......@@ -360,6 +362,8 @@ public final class MavenModuleSetBuild extends AbstractBuild<MavenModuleSet,Mave
// so just to be safe, save them all.
for (MavenBuild b : getModuleLastBuilds().values())
b.save();
performAllBuildStep(listener, project.getPublishers(),true);
}
@Override
......@@ -374,6 +378,8 @@ public final class MavenModuleSetBuild extends AbstractBuild<MavenModuleSet,Mave
p.owner().scheduleDownstreamBuilds(listener,downstreams);
}
}
performAllBuildStep(listener, project.getPublishers(),false);
}
}
......
......@@ -14,8 +14,10 @@ import hudson.scm.ChangeLogParser;
import hudson.scm.ChangeLogSet;
import hudson.scm.ChangeLogSet.Entry;
import hudson.scm.SCM;
import hudson.tasks.BuildStep;
import hudson.tasks.Builder;
import hudson.tasks.Fingerprinter.FingerprintAction;
import hudson.tasks.Publisher;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.util.AdaptedIterator;
import hudson.util.Iterators;
......@@ -28,17 +30,7 @@ import javax.servlet.ServletException;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* Base implementation of {@link Run}s that build software.
......@@ -264,6 +256,23 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
public void cleanUp(BuildListener listener) throws Exception {
// default is no-op
}
protected final void performAllBuildStep(BuildListener listener, Map<?,? extends BuildStep> buildSteps, boolean phase) throws InterruptedException, IOException {
performAllBuildStep(listener,buildSteps.values(),phase);
}
/**
* Runs all the given build steps, even if one of them fail.
*
* @param phase
* true for the post build processing, and false for the final "run after finished" execution.
*/
protected final void performAllBuildStep(BuildListener listener, Iterable<? extends BuildStep> buildSteps, boolean phase) throws InterruptedException, IOException {
for( BuildStep bs : buildSteps ) {
if( (bs instanceof Publisher && ((Publisher)bs).needsToRunAfterFinalized()) ^ phase)
bs.perform(AbstractBuild.this, launcher, listener);
}
}
}
/**
......
......@@ -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;
......@@ -143,14 +142,6 @@ public abstract class Build <P extends Project<P,B>,B extends Build<P,B>>
performAllBuildStep(listener, project.getProperties(),false);
}
// run all of them even if one of them failed
private void performAllBuildStep(BuildListener listener, Map<?, ? extends BuildStep> buildSteps, boolean phase) throws InterruptedException, IOException {
for( BuildStep bs : buildSteps.values() ) {
if( (bs instanceof Publisher && ((Publisher)bs).needsToRunAfterFinalized()) ^ phase)
bs.perform(Build.this, launcher, listener);
}
}
private boolean build(BuildListener listener, Map<?, Builder> steps) throws IOException, InterruptedException {
for( BuildStep bs : steps.values() )
if(!bs.perform(Build.this, launcher, listener))
......
......@@ -3,6 +3,7 @@ package hudson.tasks;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.maven.AbstractMavenProject;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
......@@ -109,7 +110,7 @@ public class ArtifactArchiver extends Publisher {
public static final Descriptor<Publisher> DESCRIPTOR = new DescriptorImpl();
public static class DescriptorImpl extends Descriptor<Publisher> {
public static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
public DescriptorImpl() {
super(ArtifactArchiver.class);
}
......@@ -132,5 +133,11 @@ public class ArtifactArchiver extends Publisher {
public ArtifactArchiver newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return req.bindJSON(ArtifactArchiver.class,formData);
}
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
// for Maven, this happens automatically.
// TODO: we should still consider enabling this for additional controls?
return !AbstractMavenProject.class.isAssignableFrom(jobType);
}
}
}
......@@ -4,6 +4,8 @@ import hudson.FilePath;
import hudson.FilePath.FileCallable;
import hudson.Launcher;
import hudson.Util;
import hudson.maven.MavenModuleSet;
import hudson.maven.AbstractMavenProject;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
......@@ -177,7 +179,7 @@ public class Fingerprinter extends Publisher implements Serializable {
public static final Descriptor<Publisher> DESCRIPTOR = new DescriptorImpl();
public static class DescriptorImpl extends Descriptor<Publisher> {
public static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
public DescriptorImpl() {
super(Fingerprinter.class);
}
......@@ -202,6 +204,11 @@ public class Fingerprinter extends Publisher implements Serializable {
req.getParameter("fingerprint_targets").trim(),
req.getParameter("fingerprint_artifacts")!=null);
}
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
// for Maven, fingerprinting kicks in automatically.
return !AbstractMavenProject.class.isAssignableFrom(jobType);
}
}
/**
......
......@@ -3,15 +3,9 @@ package hudson.tasks;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.AbstractItem;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.Descriptor;
import hudson.model.DirectoryBrowserSupport;
import hudson.model.Project;
import hudson.model.ProminentProjectAction;
import hudson.model.Result;
import hudson.maven.MavenModuleSet;
import hudson.maven.AbstractMavenProject;
import hudson.model.*;
import hudson.util.FormFieldValidator;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
......@@ -112,7 +106,7 @@ public class JavadocArchiver extends Publisher {
}
}
public static class DescriptorImpl extends Descriptor<Publisher> {
public static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
private DescriptorImpl() {
super(JavadocArchiver.class);
}
......@@ -131,5 +125,10 @@ public class JavadocArchiver extends Publisher {
public void doCheck(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
new FormFieldValidator.WorkspaceDirectory(req,rsp).process();
}
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
// for Maven, javadoc archiving kicks in automatically
return !AbstractMavenProject.class.isAssignableFrom(jobType);
}
}
}
package hudson.tasks;
import hudson.Launcher;
import hudson.model.Build;
import hudson.model.BuildListener;
import hudson.model.Descriptor;
import hudson.model.Project;
import hudson.model.User;
import hudson.model.UserPropertyDescriptor;
import hudson.maven.AbstractMavenProject;
import hudson.model.*;
import hudson.util.FormFieldValidator;
import org.apache.tools.ant.types.selectors.SelectorUtils;
import org.kohsuke.stapler.QueryParameter;
......@@ -108,7 +104,7 @@ public class Mailer extends Publisher {
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
public static final class DescriptorImpl extends Descriptor<Publisher> {
public static final class DescriptorImpl extends BuildStepDescriptor<Publisher> {
/**
* The default e-mail address suffix appended to the user name found from changelog,
* to send e-mails. Null if not configured.
......@@ -323,6 +319,11 @@ public class Mailer extends Publisher {
}
writer.flush();
}
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
// for historical reasons, Maven uses MavenMailer
return !AbstractMavenProject.class.isAssignableFrom(jobType);
}
}
/**
......
......@@ -50,4 +50,6 @@
instances="${it.reporters.toMap()}"
varName="reporter" />
</j:if>
<p:config-publishers />
</j:jelly>
......@@ -2,4 +2,6 @@ MavenModuleSet.DiplayName=Build a maven2 project (beta)
MavenModule.Pronoun=Module
MavenProbeAction.DisplayName=Monitor Maven Process
\ No newline at end of file
MavenProbeAction.DisplayName=Monitor Maven Process
ReleaseAction.DisplayName=Release New Version
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册