diff --git a/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java b/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java index f5f7bfe021..8c5436421a 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java @@ -525,6 +525,14 @@ public final class MavenModuleSet extends AbstractMavenProject getMavenArgument(String shortForm, String longForm) { List args = new ArrayList(); boolean switchFound=false; @@ -576,6 +584,13 @@ public final class MavenModuleSet extends AbstractMavenProject relPath = new HashMap(); - MavenUtil.resolveModules(embedder,mp,getRootPath(),relPath,listener); + MavenUtil.resolveModules(embedder,mp,getRootPath(),relPath,listener,nonRecursive); if(verbose) { for (Entry e : relPath.entrySet()) diff --git a/maven-plugin/src/main/java/hudson/maven/MavenUtil.java b/maven-plugin/src/main/java/hudson/maven/MavenUtil.java index e49f472d93..62d18d3190 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenUtil.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenUtil.java @@ -160,33 +160,38 @@ public class MavenUtil { * @throws AbortException * errors will be reported to the listener and the exception thrown. */ - public static void resolveModules(MavenEmbedder embedder, MavenProject project, String rel, Map relativePathInfo, BuildListener listener) throws ProjectBuildingException, AbortException { - + public static void resolveModules(MavenEmbedder embedder, MavenProject project, + String rel, Map relativePathInfo, + BuildListener listener, boolean nonRecursive) throws ProjectBuildingException, + AbortException { + File basedir = project.getFile().getParentFile(); relativePathInfo.put(project,rel); - List modules = new ArrayList(); - - for (String modulePath : (List) project.getModules()) { - if (Util.fixEmptyAndTrim(modulePath)!=null) { - File moduleFile = new File(basedir, modulePath); - if (moduleFile.exists() && moduleFile.isDirectory()) { - moduleFile = new File(basedir, modulePath + "/pom.xml"); + if (!nonRecursive) { + List modules = new ArrayList(); + + for (String modulePath : (List) project.getModules()) { + if (Util.fixEmptyAndTrim(modulePath)!=null) { + File moduleFile = new File(basedir, modulePath); + if (moduleFile.exists() && moduleFile.isDirectory()) { + moduleFile = new File(basedir, modulePath + "/pom.xml"); + } + if(!moduleFile.exists()) + throw new AbortException(moduleFile+" is referenced from "+project.getFile()+" but it doesn't exist"); + + String relativePath = rel; + if(relativePath.length()>0) relativePath+='/'; + relativePath+=modulePath; + + MavenProject child = embedder.readProject(moduleFile); + resolveModules(embedder,child,relativePath,relativePathInfo,listener,nonRecursive); + modules.add(child); } - if(!moduleFile.exists()) - throw new AbortException(moduleFile+" is referenced from "+project.getFile()+" but it doesn't exist"); - - String relativePath = rel; - if(relativePath.length()>0) relativePath+='/'; - relativePath+=modulePath; - - MavenProject child = embedder.readProject(moduleFile); - resolveModules(embedder,child,relativePath,relativePathInfo,listener); - modules.add(child); } + + project.setCollectedProjects(modules); } - - project.setCollectedProjects(modules); } /** diff --git a/test/src/test/java/hudson/maven/MavenMultiModuleTest.java b/test/src/test/java/hudson/maven/MavenMultiModuleTest.java index d57a44782d..ebd24d8205 100644 --- a/test/src/test/java/hudson/maven/MavenMultiModuleTest.java +++ b/test/src/test/java/hudson/maven/MavenMultiModuleTest.java @@ -28,9 +28,10 @@ public class MavenMultiModuleTest extends HudsonTestCase { MavenModuleSet m = createMavenProject(); m.getReporters().add(new TestReporter()); m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimod.zip"))); + assertFalse("MavenModuleSet.isNonRecursive() should be false", m.isNonRecursive()); assertBuildStatusSuccess(m.scheduleBuild2(0).get()); } - + public void testIncrementalMultiModMaven() throws Exception { configureDefaultMaven("apache-maven-2.2.1"); MavenModuleSet m = createMavenProject(); @@ -64,6 +65,39 @@ public class MavenMultiModuleTest extends HudsonTestCase { } + /** + * When "-N' or "--non-recursive" show up in the goals, any child modules should be ignored. + */ + @Bug(4491) + public void testMultiModMavenNonRecursiveParsing() throws Exception { + configureDefaultMaven("apache-maven-2.2.1"); + MavenModuleSet m = createMavenProject(); + m.setGoals("clean install -N"); + m.getReporters().add(new TestReporter()); + m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimod.zip"))); + + assertBuildStatusSuccess(m.scheduleBuild2(0).get()); + + MavenModuleSetBuild pBuild = m.getLastBuild(); + + for (MavenBuild modBuild : pBuild.getModuleLastBuilds().values()) { + if (modBuild.getParent().getModuleName().toString().equals("org.jvnet.hudson.main.test.multimod:multimod-top")) { + assertEquals("moduleA should have Result.SUCCESS", modBuild.getResult(), Result.SUCCESS); + } + if (modBuild.getParent().getModuleName().toString().equals("org.jvnet.hudson.main.test.multimod:moduleA")) { + assertEquals("moduleA should have Result.NOT_BUILT", modBuild.getResult(), Result.NOT_BUILT); + } + if (modBuild.getParent().getModuleName().toString().equals("org.jvnet.hudson.main.test.multimod:moduleB")) { + assertEquals("moduleB should have Result.NOT_BUILT", modBuild.getResult(), Result.NOT_BUILT); + } + if (modBuild.getParent().getModuleName().toString().equals("org.jvnet.hudson.main.test.multimod:moduleC")) { + assertEquals("moduleC should have Result.NOT_BUILT", modBuild.getResult(), Result.NOT_BUILT); + } + + } + + } + /** * 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. @@ -105,7 +139,7 @@ public class MavenMultiModuleTest extends HudsonTestCase { } } - + /** * Test failures in a child module should lead to the parent being marked as unstable. */ @@ -139,7 +173,7 @@ public class MavenMultiModuleTest extends HudsonTestCase { } } - + /* public void testParallelMultiModMavenWsExists() throws Exception { configureDefaultMaven();