From 75ec5aef9216ca521f860a15886ab91659cbc9f8 Mon Sep 17 00:00:00 2001 From: abayer Date: Fri, 11 Sep 2009 15:06:22 +0000 Subject: [PATCH] [FIXED HUDSON-4442] Empty or whitespace-only modules are now properly ignored by POM parser git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@21610 71c3de6d-444a-0410-be80-ed276b4c234a --- .../src/main/java/hudson/maven/MavenUtil.java | 33 ++++++++------- .../hudson/maven/MavenEmptyModuleTest.java | 40 ++++++++++++++++++ .../hudson/maven/maven-empty-mod.zip | Bin 0 -> 5328 bytes 3 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 test/src/test/java/hudson/maven/MavenEmptyModuleTest.java create mode 100644 test/src/test/resources/hudson/maven/maven-empty-mod.zip diff --git a/maven-plugin/src/main/java/hudson/maven/MavenUtil.java b/maven-plugin/src/main/java/hudson/maven/MavenUtil.java index d4d2df0a66..b922761d46 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 0000000000..dab602bb9c --- /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 GIT binary patch literal 5328 zcmbW4dpMMN8^<4pjKer(T5Fm`4W%5$hG@LyR5o^H#TH(!W^2M~NQ<>Ow8dCWBr3g^ z7ri-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