aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java8
-rw-r--r--src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java31
-rw-r--r--src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-language-definitions-all-in-root/sonar-project.properties13
-rw-r--r--src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-language-definitions-all-in-root/src/main/groovy/Fake.groovy0
-rw-r--r--src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-language-definitions-all-in-root/src/main/java/Fake.java1
5 files changed, 52 insertions, 1 deletions
diff --git a/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java b/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java
index 40e715f..60ddfb1 100644
--- a/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java
+++ b/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java
@@ -193,7 +193,13 @@ public final class SonarProjectBuilder {
if (moduleProps.containsKey(PROPERTY_PROJECT_BASEDIR)) {
File baseDir = getFileFromPath(moduleProps.getProperty(PROPERTY_PROJECT_BASEDIR), parentProject.getBaseDir());
setProjectBaseDir(baseDir, moduleProps, moduleId);
- tryToFindAndLoadPropsFile(baseDir, moduleProps, moduleId);
+ try {
+ if (!parentProject.getBaseDir().getCanonicalFile().equals(baseDir.getCanonicalFile())) {
+ tryToFindAndLoadPropsFile(baseDir, moduleProps, moduleId);
+ }
+ } catch (IOException e) {
+ throw new RunnerException("Error when resolving baseDir", e);
+ }
} else if (moduleProps.containsKey(PROPERTY_PROJECT_CONFIG_FILE)) {
loadPropsFile(parentProject, moduleProps, moduleId);
} else {
diff --git a/src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java b/src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java
index 7f88357..8f2143e 100644
--- a/src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java
+++ b/src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java
@@ -243,6 +243,37 @@ public class SonarProjectBuilderTest {
assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull();
}
+ // SONARPLUGINS-2421
+ @Test
+ public void shouldDefineMultiLanguageProjectWithDefinitionsAllInRootProject() throws IOException {
+ ProjectDefinition rootProject = loadProjectDefinition("multi-language-definitions-all-in-root");
+
+ // CHECK ROOT
+ assertThat(rootProject.getKey()).isEqualTo("example");
+ assertThat(rootProject.getName()).isEqualTo("Example");
+ assertThat(rootProject.getVersion()).isEqualTo("1.0");
+
+ // CHECK MODULES
+ List<ProjectDefinition> modules = rootProject.getSubProjects();
+ assertThat(modules.size()).isEqualTo(2);
+
+ // Module 1
+ ProjectDefinition module1 = modules.get(0);
+ assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"));
+ assertThat(module1.getSourceDirs()).contains("src/main/java");
+ // and module properties must have been cleaned
+ assertThat(module1.getWorkDir().getCanonicalFile())
+ .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_java-module"));
+
+ // Module 2
+ ProjectDefinition module2 = modules.get(1);
+ assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"));
+ assertThat(module2.getSourceDirs()).contains("src/main/groovy");
+ // and module properties must have been cleaned
+ assertThat(module2.getWorkDir().getCanonicalFile())
+ .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_groovy-module"));
+ }
+
@Test
public void shouldDefineMultiModuleProjectWithBaseDir() throws IOException {
ProjectDefinition rootProject = loadProjectDefinition("multi-module-with-basedir");
diff --git a/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-language-definitions-all-in-root/sonar-project.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-language-definitions-all-in-root/sonar-project.properties
new file mode 100644
index 0000000..53aacb5
--- /dev/null
+++ b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-language-definitions-all-in-root/sonar-project.properties
@@ -0,0 +1,13 @@
+sonar.projectKey=example
+sonar.projectName=Example
+sonar.projectVersion=1.0
+
+sonar.modules=java-module,groovy-module
+
+java-module.sonar.language=java
+java-module.sonar.projectBaseDir=.
+java-module.sonar.sources=src/main/java
+
+groovy-module.sonar.language=groovy
+groovy-module.sonar.projectBaseDir=.
+groovy-module.sonar.sources=src/main/groovy
diff --git a/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-language-definitions-all-in-root/src/main/groovy/Fake.groovy b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-language-definitions-all-in-root/src/main/groovy/Fake.groovy
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-language-definitions-all-in-root/src/main/groovy/Fake.groovy
diff --git a/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-language-definitions-all-in-root/src/main/java/Fake.java b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-language-definitions-all-in-root/src/main/java/Fake.java
new file mode 100644
index 0000000..5967658
--- /dev/null
+++ b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-language-definitions-all-in-root/src/main/java/Fake.java
@@ -0,0 +1 @@
+Fake \ No newline at end of file