diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-09-30 18:37:56 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-09-30 20:14:28 +0400 |
commit | 02c48e61717340c546cee73635c76d22fc722efc (patch) | |
tree | 3ef0a4912a16887091921095fda2f73d8de05894 /sonar-batch | |
parent | de481da782ff9c277fafa85d7a062077ab9839dd (diff) | |
download | sonarqube-02c48e61717340c546cee73635c76d22fc722efc.tar.gz sonarqube-02c48e61717340c546cee73635c76d22fc722efc.zip |
SONAR-2735 Fix handling of different ways to declare Maven modules
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java | 42 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java | 2 |
2 files changed, 31 insertions, 13 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java b/sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java index 5c35f335a1d..e4381e89b95 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java +++ b/sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java @@ -19,16 +19,17 @@ */ package org.sonar.batch; -import com.google.common.collect.Maps; -import org.apache.maven.project.MavenProject; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.utils.SonarException; - import java.io.File; import java.io.IOException; import java.util.List; import java.util.Map; +import org.apache.maven.project.MavenProject; +import org.sonar.api.batch.bootstrap.ProjectDefinition; +import org.sonar.api.utils.SonarException; + +import com.google.common.collect.Maps; + public final class MavenProjectConverter { private MavenProjectConverter() { @@ -36,29 +37,46 @@ public final class MavenProjectConverter { } public static ProjectDefinition convert(List<MavenProject> poms, MavenProject root) { - Map<String, MavenProject> paths = Maps.newHashMap(); // projects by canonical path + Map<String, MavenProject> paths = Maps.newHashMap(); // projects by canonical path to pom.xml Map<MavenProject, ProjectDefinition> defs = Maps.newHashMap(); try { for (MavenProject pom : poms) { - String basedir = pom.getBasedir().getCanonicalPath(); - paths.put(basedir, pom); + paths.put(pom.getFile().getCanonicalPath(), pom); defs.put(pom, convert(pom)); } for (Map.Entry<String, MavenProject> entry : paths.entrySet()) { MavenProject pom = entry.getValue(); - for (Object moduleId : pom.getModules()) { - File modulePath = new File(pom.getBasedir(), (String) moduleId); + for (Object m : pom.getModules()) { + String moduleId = (String) m; + File modulePath = new File(pom.getBasedir(), moduleId); + if (modulePath.exists() && modulePath.isDirectory()) { + modulePath = new File(modulePath, "pom.xml"); + } MavenProject module = paths.get(modulePath.getCanonicalPath()); - defs.get(pom).addSubProject(defs.get(module)); + + ProjectDefinition parentProject = defs.get(pom); + ProjectDefinition subProject = defs.get(module); + if (parentProject == null) { + throw new IllegalStateException(); + } + if (subProject == null) { + throw new IllegalStateException(); + } + parentProject.addSubProject(subProject); } } } catch (IOException e) { throw new SonarException(e); } - return defs.get(root); + ProjectDefinition rootProject = defs.get(root); + if (rootProject == null) { + throw new IllegalStateException(); + } + + return rootProject; } /** diff --git a/sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java b/sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java index 7077ddde528..872de93fed8 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java @@ -46,7 +46,7 @@ public class MavenProjectConverterTest { MavenProject root = new MavenProject(); root.setFile(new File("/foo/pom.xml")); root.getBuild().setDirectory("target"); - root.getModules().add("module"); + root.getModules().add("module/pom.xml"); MavenProject module = new MavenProject(); module.setFile(new File("/foo/module/pom.xml")); module.getBuild().setDirectory("target"); |