提交 cd968ce2 编写于 作者: I imod

integrate m2extra-steps into maven-plugin

上级 9a48907a
......@@ -38,12 +38,11 @@ import hudson.maven.settings.MavenSettingsProvider;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.BuildableItemWithBuildWrappers;
import hudson.tasks.Builder;
import hudson.model.DependencyGraph;
import hudson.model.Descriptor;
import hudson.model.Descriptor.FormException;
import hudson.model.Executor;
import hudson.model.TaskListener;
import jenkins.model.Jenkins;
import hudson.model.Item;
import hudson.model.ItemGroup;
import hudson.model.Job;
......@@ -52,6 +51,7 @@ import hudson.model.Queue.Task;
import hudson.model.ResourceActivity;
import hudson.model.SCMedItem;
import hudson.model.Saveable;
import hudson.model.TaskListener;
import hudson.model.TopLevelItem;
import hudson.search.CollectionSearchIndex;
import hudson.search.SearchIndexBuilder;
......@@ -87,6 +87,7 @@ import java.util.Stack;
import javax.servlet.ServletException;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.apache.commons.lang.math.NumberUtils;
......@@ -111,6 +112,8 @@ import org.kohsuke.stapler.export.Exported;
* @author Kohsuke Kawaguchi
*/
public class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,MavenModuleSetBuild> implements TopLevelItem, ItemGroup<MavenModule>, SCMedItem, Saveable, BuildableItemWithBuildWrappers {
/**
* All {@link MavenModule}s, keyed by their {@link MavenModule#getModuleName()} module name}s.
*/
......@@ -254,6 +257,18 @@ public class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,MavenMod
private DescribableList<BuildWrapper,Descriptor<BuildWrapper>> buildWrappers =
new DescribableList<BuildWrapper, Descriptor<BuildWrapper>>(this);
/**
* List of active {@link Builder}s configured for this project.
*/
private DescribableList<Builder,Descriptor<Builder>> prebuilders =
new DescribableList<Builder,Descriptor<Builder>>(this);
private DescribableList<Builder,Descriptor<Builder>> postbuilders =
new DescribableList<Builder,Descriptor<Builder>>(this);
private String runPostStepsIfResult;
/**
* @deprecated
* Use {@link #MavenModuleSet(ItemGroup, String)}
......@@ -266,6 +281,21 @@ public class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,MavenMod
super(parent,name);
}
public List<Builder> getPrebuilders() {
return prebuilders.toList();
}
public List<Builder> getPostbuilders() {
return postbuilders.toList();
}
/**
* @return Returns the runIfResult value.
*/
public String getRunPostStepsIfResult() {
return runPostStepsIfResult;
}
public String getUrlChildPrefix() {
// seemingly redundant "./" is used to make sure that ':' is not interpreted as the scheme identifier
return ".";
......@@ -595,16 +625,27 @@ public class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,MavenMod
this.sortedActiveModules = getDisabledModules(false);
}
if(reporters==null)
if(reporters==null){
reporters = new DescribableList<MavenReporter, Descriptor<MavenReporter>>(this);
}
reporters.setOwner(this);
if(publishers==null)
if(publishers==null){
publishers = new DescribableList<Publisher,Descriptor<Publisher>>(this);
}
publishers.setOwner(this);
if(buildWrappers==null)
if(buildWrappers==null){
buildWrappers = new DescribableList<BuildWrapper, Descriptor<BuildWrapper>>(this);
}
buildWrappers.setOwner(this);
if(prebuilders==null){
prebuilders = new DescribableList<Builder,Descriptor<Builder>>(this);
}
prebuilders.setOwner(this);
if(postbuilders==null){
postbuilders = new DescribableList<Builder,Descriptor<Builder>>(this);
}
postbuilders.setOwner(this);
updateTransientActions();
}
......@@ -660,6 +701,8 @@ public class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,MavenMod
publishers.buildDependencyGraph(this,graph);
buildWrappers.buildDependencyGraph(this,graph);
prebuilders.buildDependencyGraph(this,graph);
postbuilders.buildDependencyGraph(this,graph);
}
public MavenModule getRootModule() {
......@@ -678,6 +721,8 @@ public class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,MavenMod
activities.addAll(super.getResourceActivities());
activities.addAll(Util.filter(publishers,ResourceActivity.class));
activities.addAll(Util.filter(buildWrappers,ResourceActivity.class));
activities.addAll(Util.filter(prebuilders,ResourceActivity.class));
activities.addAll(Util.filter(postbuilders,ResourceActivity.class));
return activities;
}
......@@ -935,6 +980,10 @@ public class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,MavenMod
buildWrappers.rebuild(req,json,BuildWrappers.getFor(this));
settingConfigId = req.getParameter( "maven.mavenSettingsConfigId" );
globalSettingConfigId = req.getParameter( "maven.mavenGlobalSettingConfigId" );
runPostStepsIfResult = req.getParameter( "post-steps.runIfResult" );
prebuilders.rebuildHetero(req,json, Builder.all(), "prebuilder");
postbuilders.rebuildHetero(req,json, Builder.all(), "postbuilder");
}
/**
......
......@@ -47,7 +47,6 @@ import hudson.model.Computer;
import hudson.model.Environment;
import hudson.model.Executor;
import hudson.model.Fingerprint;
import jenkins.model.Jenkins;
import hudson.model.ParameterDefinition;
import hudson.model.ParametersAction;
import hudson.model.ParametersDefinitionProperty;
......@@ -58,6 +57,7 @@ import hudson.model.TaskListener;
import hudson.remoting.Channel;
import hudson.remoting.VirtualChannel;
import hudson.scm.ChangeLogSet;
import hudson.tasks.BuildStep;
import hudson.tasks.BuildWrapper;
import hudson.tasks.MailSender;
import hudson.tasks.Maven.MavenInstallation;
......@@ -71,6 +71,7 @@ import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.PrintStream;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
......@@ -85,6 +86,8 @@ import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.BuildFailureException;
......@@ -123,6 +126,7 @@ import org.sonatype.aether.transfer.TransferListener;
* @author Kohsuke Kawaguchi
*/
public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,MavenModuleSetBuild> {
/**
* {@link MavenReporter}s that will contribute project actions.
* Can be null if there's none.
......@@ -555,12 +559,13 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
private Map<ModuleName,MavenBuild.ProxyImpl2> proxies;
protected Result doRun(final BuildListener listener) throws Exception {
PrintStream logger = listener.getLogger();
Result r = null;
Result r = null;
PrintStream logger = listener.getLogger();
FilePath remoteSettings = null, remoteGlobalSettings = null;
try {
EnvVars envVars = getEnvironment(listener);
MavenInstallation mvn = project.getMaven();
if(mvn==null)
......@@ -586,6 +591,17 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
} else {
// do builds here
try {
// run pre build steps
if(!preBuild(listener,project.getPrebuilders())){
r = FAILURE;
return r;
}
if(!build(listener,project.getPrebuilders())){
r = FAILURE;
return r;
}
List<BuildWrapper> wrappers = new ArrayList<BuildWrapper>();
for (BuildWrapper w : project.getBuildWrappersList())
wrappers.add(w);
......@@ -601,8 +617,10 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
e.buildEnvVars(envVars); // #3502: too late for getEnvironment to do this
}
if(!preBuild(listener, project.getPublishers()))
return Result.FAILURE;
if(!preBuild(listener, project.getPublishers())){
r = FAILURE;
return r;
}
String settingsConfigId = project.getSettingConfigId();
......@@ -779,6 +797,20 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
r = Executor.currentExecutor().abortResult();
throw e;
} finally {
// only run post build steps if requested...
if(shouldPostStepsRun(r, project.getRunPostStepsIfResult())){
boolean proceedPostSteps = true;
if(!preBuild(listener,project.getPostbuilders())){
r = FAILURE;
proceedPostSteps = false;
}
if(proceedPostSteps){
if(!build(listener,project.getPostbuilders())){
r = FAILURE;
}
}
}
if (r != null) {
setResult(r);
}
......@@ -794,6 +826,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
}
}
return r;
} catch (AbortException e) {
if(e.getMessage()!=null)
......@@ -830,6 +863,40 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
}
}
private boolean build(BuildListener listener, Collection<hudson.tasks.Builder> steps) throws IOException, InterruptedException {
for( BuildStep bs : steps ){
if(!perform(bs,listener)) {
LOGGER.fine(MessageFormat.format("{1} failed", bs));
return false;
}
}
return true;
}
private boolean shouldPostStepsRun(Result buildResult, String runIfResult) {
// If runIfResult is null, set it to "allCases".
if (runIfResult == null) {
runIfResult = "allCases";
}
// If runIfResult is "allCases", we're running regardless.
if (runIfResult.equals("allCases")) {
return true;
}
else {
// Otherwise, we're going to need to compare against the build result.
if (runIfResult.equals("success")) {
return ((buildResult==null) || (buildResult.isBetterOrEqualTo(Result.SUCCESS)));
}
else if (runIfResult.equals("unstable")) {
return ((buildResult==null) || (buildResult.isBetterOrEqualTo(Result.UNSTABLE)));
}
}
// If we get down here, something weird's going on. Return false.
return false;
}
/**
* Returns the modules which have not been build since the last successful aggregator build
* though they should be because they had SCM changes.
......
......@@ -38,6 +38,15 @@ THE SOFTWARE.
<p:config-upstream-pseudo-trigger />
</p:config-trigger>
<f:section title="${%Pre Steps}">
<f:block>
<f:hetero-list name="prebuilder" hasHeader="true"
descriptors="${h.getBuilderDescriptors(it)}"
items="${it.prebuilders}"
addCaption="${%Add pre-build step}"/>
</f:block>
</f:section>
<f:section title="${%Build}">
<j:set var="mavens" value="${it.descriptor.mavenDescriptor.installations}" />
<j:if test="${empty(mavens)}">
......@@ -129,6 +138,39 @@ THE SOFTWARE.
</f:advanced>
</f:section>
<f:section title="${%Post Steps}">
<f:entry description="${%criteriaDescription}">
<f:radio name="post-steps.runIfResult" value="success" checked="${instance.runPostStepsIfResult =='success'}" />
<st:nbsp />
<label class="attach-previous">${%runIfStable}</label>
<st:nbsp />
<f:radio name="post-steps.runIfResult" value="unstable" checked="${instance.runPostStepsIfResult =='unstable'}" />
<st:nbsp />
<label class="attach-previous">${%runIfSuccessful}</label>
<st:nbsp />
<j:if test="${instance != null}">
<j:if test="${instance.runPostStepsIfResult == null}">
<f:radio name="post-steps.runIfResult" value="allCases" checked="${true}" />
</j:if>
<j:if test="${instance.runPostStepsIfResult != null}">
<f:radio name="post-steps.runIfResult" value="allCases" checked="${instance.runPostStepsIfResult =='allCases'}" />
</j:if>
</j:if>
<j:if test="${instance == null}">
<f:radio name="post-steps.runIfResult" value="allCases" checked="${true}" />
</j:if>
<st:nbsp />
<label class="attach-previous">${%runAlways}</label>
<st:nbsp />
</f:entry>
<f:block>
<f:hetero-list name="postbuilder" hasHeader="true"
descriptors="${h.getBuilderDescriptors(it)}"
items="${it.postbuilders}"
addCaption="${%Add post-build step}"/>
</f:block>
</f:section>
<j:invokeStatic var="reporters" className="hudson.maven.MavenReporters" method="getConfigurableList" />
<j:if test="${!empty(reporters)}">
<f:descriptorList title="${%Build Settings}"
......@@ -136,6 +178,7 @@ THE SOFTWARE.
instances="${it.reporters.toMap()}" />
</j:if>
<p:config-buildWrappers />
<p:config-publishers />
</j:jelly>
......@@ -21,4 +21,8 @@
# THE SOFTWARE.
Maven\ Version.error.1=Jenkins needs to know where your Maven2 is installed.
Maven\ Version.error.2=Please do so from <a href="{0}/configure" target="_new">the system configuration</a>.
\ No newline at end of file
Maven\ Version.error.2=Please do so from <a href="{0}/configure" target="_new">the system configuration</a>.
criteriaDescription=Should the post-build steps run only for successful builds, etc.
runIfStable=Run only if build succeeds
runIfSuccessful=Run only if build succeeds or is unstable
runAlways=Run regardless of build result
\ No newline at end of file
......@@ -40,3 +40,8 @@ Resolve\ Dependencies\ during\ Pom\ parsing=Effectue la r\u00e9solution de d\u00
Process\ Plugins\ during\ Pom\ parsing=Analyse les plugins pendant la lecture du POM
Maven\ Validation\ Level=Niveau de validation du POM Maven
Goals=Goals
Add\ post-build\ step=Ajouter une \u00E9tape pr\u00E9-build
Add\ pre-build\ step=Ajouter une \u00E9tape pr\u00E9-build
Post-Build\ Run\ Criteria=Crit\u00E8re pour ex\u00E9cuter le post-build
Steps\ to\ run\ after\ mvn\ build=\u00C9tapes \u00E0 lancer apr\u00E8s le build maven
Steps\ to\ run\ before\ mvn\ build=\u00C9tapes \u00E0 lancer avant le build maven
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册