diff --git a/maven-plugin/src/main/java/hudson/maven/MavenUtil.java b/maven-plugin/src/main/java/hudson/maven/MavenUtil.java index d4d2df0a668ad45faa3f7f864004bb7f6cd41ed6..b922761d462a7b1a1f8be82324a1186610994181 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenUtil.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenUtil.java @@ -24,6 +24,7 @@ package hudson.maven; import hudson.AbortException; +import hudson.Util; import hudson.model.BuildListener; import hudson.model.TaskListener; import hudson.model.AbstractProject; @@ -166,21 +167,23 @@ public class MavenUtil { List modules = new ArrayList(); for (String modulePath : (List) project.getModules()) { - 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); - modules.add(child); - } + 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); + modules.add(child); + } + } project.setCollectedProjects(modules); } diff --git a/test/src/test/java/hudson/maven/MavenEmptyModuleTest.java b/test/src/test/java/hudson/maven/MavenEmptyModuleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..dab602bb9c5fc53d1f32c5a1ad515486b7bc37c1 --- /dev/null +++ b/test/src/test/java/hudson/maven/MavenEmptyModuleTest.java @@ -0,0 +1,40 @@ +package hudson.maven; + +import org.jvnet.hudson.test.HudsonTestCase; +import org.jvnet.hudson.test.Bug; +import org.jvnet.hudson.test.ExtractResourceSCM; + + +import hudson.Launcher; +import hudson.model.BuildListener; +import hudson.model.Result; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +/** + * @author Andrew Bayer + */ +public class MavenEmptyModuleTest extends HudsonTestCase { + /** + * Verify that a build will work with a module and a module + */ + @Bug(4442) + public void testEmptyModuleParsesAndBuilds() throws Exception { + configureDefaultMaven(); + MavenModuleSet m = createMavenProject(); + m.getReporters().add(new TestReporter()); + m.setScm(new ExtractResourceSCM(getClass().getResource("maven-empty-mod.zip"))); + assertBuildStatusSuccess(m.scheduleBuild2(0).get()); + } + + private static class TestReporter extends MavenReporter { + @Override + public boolean end(MavenBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { + assertNotNull(build.getProject().getWorkspace()); + assertNotNull(build.getWorkspace()); + return true; + } + } +} \ No newline at end of file diff --git a/test/src/test/resources/hudson/maven/maven-empty-mod.zip b/test/src/test/resources/hudson/maven/maven-empty-mod.zip new file mode 100644 index 0000000000000000000000000000000000000000..e6c8e05599a495e28b90cc7aaf75706a41100e19 Binary files /dev/null and b/test/src/test/resources/hudson/maven/maven-empty-mod.zip differ