]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5417 Fix issues when properties on a module were wrongly copied on other modules
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 2 Sep 2014 14:07:33 +0000 (16:07 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 2 Sep 2014 14:07:33 +0000 (16:07 +0200)
server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java
server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_two_modules.json [new file with mode: 0644]

index f39c8a4fb876d8ae00b222d53f49510e43b6aa95..6988fda03b512eaee0047952755582756e94810f 100644 (file)
@@ -168,12 +168,14 @@ public class ProjectReferentialsAction implements RequestHandler {
   }
 
   private void addSettingsToChildrenModules(ProjectReferentials ref, String projectKey, Map<String, String> parentProperties, boolean hasScanPerm, DbSession session) {
-    parentProperties.putAll(getPropertiesMap(propertiesDao.selectProjectProperties(projectKey, session), hasScanPerm));
-    addSettings(ref, projectKey, parentProperties);
+    Map<String, String> currentParentProperties = newHashMap();
+    currentParentProperties.putAll(parentProperties);
+    currentParentProperties.putAll(getPropertiesMap(propertiesDao.selectProjectProperties(projectKey, session), hasScanPerm));
+    addSettings(ref, projectKey, currentParentProperties);
 
     for (ComponentDto module : dbClient.componentDao().findModulesByProject(projectKey, session)) {
-      addSettings(ref, module.key(), parentProperties);
-      addSettingsToChildrenModules(ref, module.key(), parentProperties, hasScanPerm, session);
+      addSettings(ref, module.key(), currentParentProperties);
+      addSettingsToChildrenModules(ref, module.key(), currentParentProperties, hasScanPerm, session);
     }
   }
 
index 12ba20d1c52503243b102b83ea811e9b69c97722..34125be594b8581eee91e7cc8dd80bf6bd92928e 100644 (file)
@@ -158,7 +158,7 @@ public class ProjectReferentialsActionTest {
     when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
       new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR"),
       new PropertyDto().setKey("sonar.jira.login.secured").setValue("john")
-      ));
+    ));
 
     when(propertiesDao.selectProjectProperties(module.key(), session)).thenReturn(newArrayList(
       new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER"),
@@ -212,6 +212,34 @@ public class ProjectReferentialsActionTest {
     request.execute().assertJson(getClass(), "return_project_with_module_with_sub_module.json");
   }
 
+  @Test
+  public void return_project_with_two_modules() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+
+    ComponentDto module2 = new ComponentDto().setKey("org.codehaus.sonar:sonar-application").setQualifier(Qualifiers.MODULE);
+
+    when(componentDao.getNullableRootProjectByKey(project.key(), session)).thenReturn(project);
+    when(componentDao.findModulesByProject(project.key(), session)).thenReturn(newArrayList(module, module2));
+
+    when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
+      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR"),
+      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john")
+    ));
+
+    when(propertiesDao.selectProjectProperties(module.key(), session)).thenReturn(newArrayList(
+      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER"),
+      // This property should not be found on the other module
+      new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java")
+    ));
+
+    when(propertiesDao.selectProjectProperties(module2.key(), session)).thenReturn(newArrayList(
+      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-APPLICATION")
+    ));
+
+    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", project.key());
+    request.execute().assertJson(getClass(), "return_project_with_two_modules.json");
+  }
+
   @Test
   public void return_provisioned_project_settings() throws Exception {
     MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_two_modules.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_two_modules.json
new file mode 100644 (file)
index 0000000..302176c
--- /dev/null
@@ -0,0 +1,27 @@
+{
+  "timestamp": 0,
+  "qprofilesByLanguage": {
+    "java": {
+      "key": "abcd",
+      "name": "Default",
+      "language": "java",
+      "rulesUpdatedAt": "Jan 14, 2014 1:00:00 PM"
+    }
+  },
+  "activeRules": [],
+  "settingsByModule": {
+    "org.codehaus.sonar:sonar": {
+      "sonar.jira.project.key": "SONAR",
+      "sonar.jira.login.secured": "john"
+    },
+    "org.codehaus.sonar:sonar-server": {
+      "sonar.jira.project.key": "SONAR-SERVER",
+      "sonar.jira.login.secured": "john",
+      "sonar.coverage.exclusions": "**/*.java"
+    },
+    "org.codehaus.sonar:sonar-application": {
+      "sonar.jira.project.key": "SONAR-APPLICATION",
+      "sonar.jira.login.secured": "john"
+    }
+  }
+}