diff options
author | Loïc B <lbndev@yahoo.fr> | 2017-02-23 10:24:43 +0100 |
---|---|---|
committer | Janos Gyerik <janos.gyerik@sonarsource.com> | 2017-02-23 15:15:39 +0100 |
commit | 4abbd1f4890de33d6539bc282911c5cef83cd291 (patch) | |
tree | d84c92a29921cc048c682d2344ce1887e7af3381 /sonar-scanner-engine | |
parent | 2a90fd4a8e106b8d2f347cc30d9bd50405505fec (diff) | |
download | sonarqube-4abbd1f4890de33d6539bc282911c5cef83cd291.tar.gz sonarqube-4abbd1f4890de33d6539bc282911c5cef83cd291.zip |
SONAR-6724 : support analyzing root pom in multi-modules projects
Diffstat (limited to 'sonar-scanner-engine')
6 files changed, 48 insertions, 16 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java index ab75657cfdc..26f5b87d7d9 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java @@ -39,7 +39,6 @@ import org.sonar.api.utils.MessageException; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; import org.sonar.scanner.analysis.AnalysisProperties; -import org.sonar.scanner.scan.ProjectReactorBuilder; import static org.assertj.core.api.Assertions.assertThat; @@ -118,8 +117,17 @@ public class ProjectReactorBuilderTest { @Test public void shouldDefineMultiModuleProjectWithDefinitionsAllInRootProject() throws IOException { - ProjectDefinition rootProject = loadProjectDefinition("multi-module-definitions-all-in-root"); + execMultiModule("multi-module-definitions-all-in-root"); + } + @Test + public void shouldDefineMultiModuleProjectWithPomFileAtRootLevel() throws IOException { + ProjectDefinition project = execMultiModule("multi-module-pom-in-root"); + assertThat(project.sources()).containsExactlyInAnyOrder("pom.xml", "sources"); + } + + public ProjectDefinition execMultiModule(String key) throws IOException { + ProjectDefinition rootProject = loadProjectDefinition(key); // CHECK ROOT assertThat(rootProject.getKey()).isEqualTo("com.foo.project"); assertThat(rootProject.getName()).isEqualTo("Foo Project"); @@ -131,10 +139,8 @@ public class ProjectReactorBuilderTest { assertThat(rootProject.properties().get("module1.sonar.projectKey")).isNull(); assertThat(rootProject.properties().get("module2.sonar.projectKey")).isNull(); // Check baseDir and workDir - assertThat(rootProject.getBaseDir().getCanonicalFile()) - .isEqualTo(getResource(this.getClass(), "multi-module-definitions-all-in-root")); - assertThat(rootProject.getWorkDir().getCanonicalFile()) - .isEqualTo(new File(getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar")); + assertThat(rootProject.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), key)); + assertThat(rootProject.getWorkDir().getCanonicalFile()).isEqualTo(new File(getResource(this.getClass(), key), ".sonar")); // CHECK MODULES List<ProjectDefinition> modules = rootProject.getSubProjects(); @@ -142,7 +148,7 @@ public class ProjectReactorBuilderTest { // Module 1 ProjectDefinition module1 = modules.get(0); - assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), "multi-module-definitions-all-in-root/module1")); + assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), key + "/module1")); assertThat(module1.getKey()).isEqualTo("com.foo.project:module1"); assertThat(module1.getName()).isEqualTo("module1"); assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT"); @@ -154,14 +160,12 @@ public class ProjectReactorBuilderTest { assertThat(module1.properties().get("module1.sonar.projectKey")).isNull(); assertThat(module1.properties().get("module2.sonar.projectKey")).isNull(); // Check baseDir and workDir - assertThat(module1.getBaseDir().getCanonicalFile()) - .isEqualTo(getResource(this.getClass(), "multi-module-definitions-all-in-root/module1")); - assertThat(module1.getWorkDir().getCanonicalFile()) - .isEqualTo(new File(getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_module1")); + assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), key + "/module1")); + assertThat(module1.getWorkDir().getCanonicalFile()).isEqualTo(new File(getResource(this.getClass(), key), ".sonar/com.foo.project_module1")); // Module 2 ProjectDefinition module2 = modules.get(1); - assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), "multi-module-definitions-all-in-root/module2")); + assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), key + "/module2")); assertThat(module2.getKey()).isEqualTo("com.foo.project:com.foo.project.module2"); assertThat(module2.getName()).isEqualTo("Foo Module 2"); assertThat(module2.getVersion()).isEqualTo("1.0-SNAPSHOT"); @@ -172,10 +176,11 @@ public class ProjectReactorBuilderTest { assertThat(module2.properties().get("module1.sonar.projectKey")).isNull(); assertThat(module2.properties().get("module2.sonar.projectKey")).isNull(); // Check baseDir and workDir - assertThat(module2.getBaseDir().getCanonicalFile()) - .isEqualTo(getResource(this.getClass(), "multi-module-definitions-all-in-root/module2")); - assertThat(module2.getWorkDir().getCanonicalFile()) - .isEqualTo(new File(getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_com.foo.project.module2")); + assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), key + "/module2")); + assertThat(module2.getWorkDir().getCanonicalFile()).isEqualTo( + new File(getResource(this.getClass(), key), ".sonar/com.foo.project_com.foo.project.module2")); + + return rootProject; } // SONAR-4876 diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-module-pom-in-root/module1/pom.xml b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-module-pom-in-root/module1/pom.xml new file mode 100644 index 00000000000..421ccc9478b --- /dev/null +++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-module-pom-in-root/module1/pom.xml @@ -0,0 +1,3 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<!-- This is a fake pom --> +</project> diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-module-pom-in-root/module1/sources/Fake.java b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-module-pom-in-root/module1/sources/Fake.java new file mode 100644 index 00000000000..b48d3b534cb --- /dev/null +++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-module-pom-in-root/module1/sources/Fake.java @@ -0,0 +1 @@ +public class Fake {} diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-module-pom-in-root/module2/src/Fake.java b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-module-pom-in-root/module2/src/Fake.java new file mode 100644 index 00000000000..b48d3b534cb --- /dev/null +++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-module-pom-in-root/module2/src/Fake.java @@ -0,0 +1 @@ +public class Fake {} diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-module-pom-in-root/pom.xml b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-module-pom-in-root/pom.xml new file mode 100644 index 00000000000..421ccc9478b --- /dev/null +++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-module-pom-in-root/pom.xml @@ -0,0 +1,3 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<!-- This is a fake pom --> +</project> diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-module-pom-in-root/sonar-project.properties b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-module-pom-in-root/sonar-project.properties new file mode 100644 index 00000000000..a622ee679d7 --- /dev/null +++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-module-pom-in-root/sonar-project.properties @@ -0,0 +1,19 @@ +sonar.projectKey=com.foo.project +sonar.projectName=Foo Project +sonar.projectVersion=1.0-SNAPSHOT +sonar.projectDescription=Description of Foo Project + +sonar.sources=sources,pom.xml +sonar.tests=tests +sonar.binaries=target/classes + +sonar.modules=module1,\ + module2 + +# Mandatory properties for module1 are all inferred from the module ID + +module2.sonar.projectKey=com.foo.project.module2 +module2.sonar.projectName=Foo Module 2 +# redefine some properties +module2.sonar.projectDescription=Description of Module 2 +module2.sonar.sources=src |