From: Evgeny Mandrikov Date: Thu, 5 May 2011 19:01:54 +0000 (+0400) Subject: SONAR-2298 Fix bug, when root project not a first one in Maven reactor X-Git-Tag: 2.8~33 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=804816f9434ba22951a4965155df0837d21f5d22;p=sonarqube.git SONAR-2298 Fix bug, when root project not a first one in Maven reactor This situation shouldn't lead to partial analysis. --- 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 0018b1c35f4..b50f882ba58 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java +++ b/sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java @@ -36,7 +36,7 @@ public final class MavenProjectConverter { private MavenProjectConverter() { } - public static ProjectDefinition convert(List poms) { + public static ProjectDefinition convert(List poms, MavenProject root) { Map paths = Maps.newHashMap(); // projects by canonical path Map defs = Maps.newHashMap(); @@ -59,10 +59,13 @@ public final class MavenProjectConverter { throw new SonarException(e); } - return defs.get(poms.get(0)); + return defs.get(root); } - public static ProjectDefinition convert(MavenProject pom) { + /** + * Visibility has been relaxed for tests. + */ + static ProjectDefinition convert(MavenProject pom) { Properties properties = new Properties(); String key = new StringBuilder().append(pom.getGroupId()).append(":").append(pom.getArtifactId()).toString(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java index 72a599821e6..54b97fb2b6f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java @@ -53,7 +53,7 @@ public class ProjectTree { protected ProjectTree(ProjectBuilder projectBuilder, List poms) { this.projectBuilder = projectBuilder; definitions = Lists.newArrayList(); - collectProjects(MavenProjectConverter.convert(poms), definitions); + collectProjects(MavenProjectConverter.convert(poms, poms.get(0)), definitions); } /** 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 c9a2c4124fb..1ee191bebe7 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java @@ -33,19 +33,19 @@ import java.util.Properties; public class MavenProjectConverterTest { @Test - public void test2() { + public void shouldConvertModules() { MavenProject root = new MavenProject(); root.setFile(new File("/foo/pom.xml")); root.getModules().add("module"); MavenProject module = new MavenProject(); module.setFile(new File("/foo/module/pom.xml")); - ProjectDefinition project = MavenProjectConverter.convert(Arrays.asList(root, module)); + ProjectDefinition project = MavenProjectConverter.convert(Arrays.asList(root, module), root); assertThat(project.getModules().size(), is(1)); } @Test - public void test() { + public void shouldConvertProperties() { MavenProject pom = new MavenProject(); pom.setGroupId("foo"); pom.setArtifactId("bar"); diff --git a/sonar-core-maven-plugin/src/main/java/org/sonar/maven2/BatchMojo.java b/sonar-core-maven-plugin/src/main/java/org/sonar/maven2/BatchMojo.java index f979a24944d..02578c37b0a 100644 --- a/sonar-core-maven-plugin/src/main/java/org/sonar/maven2/BatchMojo.java +++ b/sonar-core-maven-plugin/src/main/java/org/sonar/maven2/BatchMojo.java @@ -145,7 +145,7 @@ public final class BatchMojo extends AbstractMojo { } private void executeBatch() throws MojoExecutionException { - ProjectDefinition def = MavenProjectConverter.convert(session.getSortedProjects()); + ProjectDefinition def = MavenProjectConverter.convert(session.getSortedProjects(), project); Reactor reactor = new Reactor(def); Batch batch = new Batch(getInitialConfiguration(), reactor, session, project, diff --git a/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java b/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java index eb57053ba8a..0f84702b9c9 100644 --- a/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java +++ b/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java @@ -145,7 +145,7 @@ public final class SonarMojo extends AbstractMojo { } private void executeBatch() throws MojoExecutionException { - ProjectDefinition def = MavenProjectConverter.convert(session.getSortedProjects()); + ProjectDefinition def = MavenProjectConverter.convert(session.getSortedProjects(), project); Reactor reactor = new Reactor(def); Batch batch = new Batch(getInitialConfiguration(), diff --git a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java b/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java index 7bb5e3e5f69..82f0847f2de 100644 --- a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java +++ b/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java @@ -138,7 +138,7 @@ public final class SonarMojo extends AbstractMojo { } private void executeBatch() throws MojoExecutionException { - ProjectDefinition def = MavenProjectConverter.convert(session.getSortedProjects()); + ProjectDefinition def = MavenProjectConverter.convert(session.getSortedProjects(), project); Reactor reactor = new Reactor(def); Batch batch = new Batch(getInitialConfiguration(),