diff --git a/core/src/main/java/hudson/model/Run.java b/core/src/main/java/hudson/model/Run.java index 58f4d11fbc..0b7ea4f75f 100644 --- a/core/src/main/java/hudson/model/Run.java +++ b/core/src/main/java/hudson/model/Run.java @@ -615,6 +615,16 @@ public abstract class Run ,RunT extends Run changedModules = new ArrayList(); for (MavenModule m : project.sortedActiveModules) { + MavenBuild mb = m.newBuild(); // Check if incrementalBuild is selected and that there are changes - // we act as if incrementalBuild is not set if there are no changes. if (!MavenModuleSetBuild.this.getChangeSet().isEmptySet() && project.isIncrementalBuild()) { - if (!getChangeSetFor(m).isEmpty()) { + // If there are changes for this module, add it. + if ((!getChangeSetFor(m).isEmpty()) + // If the last actually-built build of this module wasn't a success, + // add it - i.e., rebuild anything that failed/was unstable in the past. + || (mb.getPreviousBuiltBuild().getResult().isWorseThan(Result.SUCCESS))) { changedModules.add(m.getModuleName().toString()); } } - MavenBuild mb = m.newBuild(); mb.setWorkspace(getModuleRoot().child(m.getRelativePath())); proxies.put(m.getModuleName(), mb.new ProxyImpl2(MavenModuleSetBuild.this,slistener)); } diff --git a/test/src/test/java/hudson/maven/MavenMultiModuleTest.java b/test/src/test/java/hudson/maven/MavenMultiModuleTest.java index fc8f452c8c..5bd7e6e75d 100644 --- a/test/src/test/java/hudson/maven/MavenMultiModuleTest.java +++ b/test/src/test/java/hudson/maven/MavenMultiModuleTest.java @@ -63,7 +63,48 @@ public class MavenMultiModuleTest extends HudsonTestCase { } } - + + /** + * Module failures in build X should lead to those modules being re-run in build X+1, even if + * incremental build is enabled and nothing changed in those modules. + */ + @Bug(4152) + public void testIncrementalMultiModWithErrorsMaven() throws Exception { + configureDefaultMaven("apache-maven-2.2.1"); + MavenModuleSet m = createMavenProject(); + m.getReporters().add(new TestReporter()); + m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource("maven-multimod-incr.zip"), + getClass().getResource("maven-multimod-changes.zip"))); + + assertBuildStatus(Result.UNSTABLE, m.scheduleBuild2(0).get()); + + // Now run a second build with the changes. + m.setIncrementalBuild(true); + assertBuildStatus(Result.UNSTABLE, m.scheduleBuild2(0).get()); + + MavenModuleSetBuild pBuild = m.getLastBuild(); + ExtractChangeLogSet changeSet = (ExtractChangeLogSet) pBuild.getChangeSet(); + + assertFalse("ExtractChangeLogSet should not be empty.", changeSet.isEmptySet()); + + for (MavenBuild modBuild : pBuild.getModuleLastBuilds().values()) { + if (modBuild.getParent().getModuleName().toString().equals("org.jvnet.hudson.main.test.multimod.incr:moduleA")) { + assertEquals("moduleA should have Result.UNSTABLE", modBuild.getResult(), Result.UNSTABLE); + } + if (modBuild.getParent().getModuleName().toString().equals("org.jvnet.hudson.main.test.multimod.incr:moduleB")) { + assertEquals("moduleB should have Result.SUCCESS", modBuild.getResult(), Result.SUCCESS); + } + if (modBuild.getParent().getModuleName().toString().equals("org.jvnet.hudson.main.test.multimod.incr:moduleC")) { + assertEquals("moduleC should have Result.SUCCESS", modBuild.getResult(), Result.SUCCESS); + } + if (modBuild.getParent().getModuleName().toString().equals("org.jvnet.hudson.main.test.multimod.incr:moduleD")) { + assertEquals("moduleC should have Result.NOT_BUILT", modBuild.getResult(), Result.NOT_BUILT); + } + + } + + } + /* public void testParallelMultiModMavenWsExists() throws Exception { configureDefaultMaven();