diff --git a/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java b/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java index 95e0d6551e5213521d18b7f753123aad22de22d6..5c758d646cfdf4ec675e2913e38479006ae106bc 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java @@ -31,6 +31,7 @@ import hudson.EnvVars; import hudson.Extension; import hudson.ExtensionList; import hudson.FilePath; +import hudson.Functions; import hudson.Indenter; import hudson.Util; import hudson.maven.settings.GlobalMavenSettingsProvider; @@ -38,12 +39,12 @@ import hudson.maven.settings.MavenSettingsProvider; import hudson.model.AbstractProject; import hudson.model.Action; import hudson.model.BuildableItemWithBuildWrappers; +import hudson.model.Result; +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 +53,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; @@ -60,7 +62,6 @@ import hudson.tasks.BuildStepDescriptor; import hudson.tasks.BuildWrapper; import hudson.tasks.BuildWrappers; import hudson.tasks.Fingerprinter; -import hudson.tasks.JavadocArchiver; import hudson.tasks.Mailer; import hudson.tasks.Maven; import hudson.tasks.Maven.MavenInstallation; @@ -87,6 +88,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 +113,8 @@ import org.kohsuke.stapler.export.Exported; * @author Kohsuke Kawaguchi */ public class MavenModuleSet extends AbstractMavenProject implements TopLevelItem, ItemGroup, SCMedItem, Saveable, BuildableItemWithBuildWrappers { + + /** * All {@link MavenModule}s, keyed by their {@link MavenModule#getModuleName()} module name}s. */ @@ -254,6 +258,18 @@ public class MavenModuleSet extends AbstractMavenProject> buildWrappers = new DescribableList>(this); + /** + * List of active {@link Builder}s configured for this project. + */ + private DescribableList> prebuilders = + new DescribableList>(this); + + private DescribableList> postbuilders = + new DescribableList>(this); + + private Result runPostStepsIfResult; + + /** * @deprecated * Use {@link #MavenModuleSet(ItemGroup, String)} @@ -266,6 +282,39 @@ public class MavenModuleSet extends AbstractMavenProject> getPrebuilders() { + return prebuilders; + } + + /** + * Builders that are run after the main Maven execution. + * + * @since 1.433 + */ + public DescribableList> getPostbuilders() { + return postbuilders; + } + + /** + * {@link #postbuilders} are run if the result is better or equal to this threshold. + * + * @return + * never null + * @since 1.433 + */ + public Result getRunPostStepsIfResult() { + return Functions.defaulted(runPostStepsIfResult,Result.FAILURE); + } + + public void setRunPostStepsIfResult(Result v) { + this.runPostStepsIfResult = Functions.defaulted(v,Result.FAILURE); + } + public String getUrlChildPrefix() { // seemingly redundant "./" is used to make sure that ':' is not interpreted as the scheme identifier return "."; @@ -595,16 +644,27 @@ public class MavenModuleSet extends AbstractMavenProject>(this); + } reporters.setOwner(this); - if(publishers==null) + if(publishers==null){ publishers = new DescribableList>(this); + } publishers.setOwner(this); - if(buildWrappers==null) + if(buildWrappers==null){ buildWrappers = new DescribableList>(this); + } buildWrappers.setOwner(this); - + if(prebuilders==null){ + prebuilders = new DescribableList>(this); + } + prebuilders.setOwner(this); + if(postbuilders==null){ + postbuilders = new DescribableList>(this); + } + postbuilders.setOwner(this); + updateTransientActions(); } @@ -660,6 +720,8 @@ public class MavenModuleSet extends AbstractMavenProject { + /** * {@link MavenReporter}s that will contribute project actions. * Can be null if there's none. @@ -555,12 +559,13 @@ public class MavenModuleSetBuild extends AbstractMavenBuild 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) @@ -601,9 +606,18 @@ public class MavenModuleSetBuild extends AbstractMavenBuild=0; i-- ) { @@ -794,6 +816,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild steps) throws IOException, InterruptedException { + for( BuildStep bs : steps ){ + if(!perform(bs,listener)) { + LOGGER.fine(MessageFormat.format("{1} failed", bs)); + return false; + } + } + return true; + } + /** * Returns the modules which have not been build since the last successful aggregator build * though they should be because they had SCM changes. diff --git a/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries.jelly b/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries.jelly index 324e06b7ef61f7126798e23cb675c317ae5af71f..fb96c30b944e95b3320580fd85ef769e33fe6947 100644 --- a/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries.jelly +++ b/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries.jelly @@ -38,6 +38,15 @@ THE SOFTWARE. + + + + + + @@ -129,6 +138,22 @@ THE SOFTWARE. + + + + + + + + + + + + + + diff --git a/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries.properties b/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries.properties index d91e31e66c7a533dece47f096a5118bdadd4f6fd..a0a2620a63d73e1850572b67dad8e0bcc3f3e51c 100644 --- a/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries.properties +++ b/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries.properties @@ -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 the system configuration. \ No newline at end of file +Maven\ Version.error.2=Please do so from the system configuration. +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 diff --git a/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries_fr.properties b/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries_fr.properties index bb43380281025024641e43c84eb8ef75c7e1aca4..64366fb6e749503e2b9a15832fac3bb8b8f3582d 100644 --- a/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries_fr.properties +++ b/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries_fr.properties @@ -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 diff --git a/test/src/test/java/hudson/maven/MavenProjectTest.java b/test/src/test/java/hudson/maven/MavenProjectTest.java index 10ed0c15706679132db956e362d257649fd04a6d..080556e516105409f9829b1982a2abe482d3f3cd 100644 --- a/test/src/test/java/hudson/maven/MavenProjectTest.java +++ b/test/src/test/java/hudson/maven/MavenProjectTest.java @@ -23,10 +23,12 @@ */ package hudson.maven; +import hudson.model.Result; import hudson.tasks.Maven.MavenInstallation; import java.io.File; +import hudson.tasks.Shell; import org.junit.Assert; import org.jvnet.hudson.test.Bug; import org.jvnet.hudson.test.ExtractResourceSCM; @@ -151,4 +153,30 @@ public class MavenProjectTest extends HudsonTestCase { project.setGoals("install"); buildAndAssertSuccess(project); } + + /** + * Config roundtrip test around pre/post build step + */ + public void testConfigRoundtrip() throws Exception { + MavenModuleSet m = createMavenProject(); + Shell b1 = new Shell("1"); + Shell b2 = new Shell("2"); + m.getPrebuilders().add(b1); + m.getPostbuilders().add(b2); + configRoundtrip(m); + + assertEquals(1, m.getPrebuilders().size()); + assertNotSame(b1,m.getPrebuilders().get(Shell.class)); + assertEquals("1",m.getPrebuilders().get(Shell.class).getCommand()); + + assertEquals(1, m.getPostbuilders().size()); + assertNotSame(b2,m.getPostbuilders().get(Shell.class)); + assertEquals("2",m.getPostbuilders().get(Shell.class).getCommand()); + + for (Result r : new Result[]{Result.SUCCESS, Result.UNSTABLE, Result.FAILURE}) { + m.setRunPostStepsIfResult(r); + configRoundtrip(m); + assertEquals(r,m.getRunPostStepsIfResult()); + } + } }