From 17c62b8bdda7f882626e0cbec7d5338deb49617d Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 2 Sep 2014 16:07:33 +0200 Subject: [PATCH] SONAR-5417 Fix issues when properties on a module were wrongly copied on other modules --- .../batch/ProjectReferentialsAction.java | 10 ++++--- .../batch/ProjectReferentialsActionTest.java | 30 ++++++++++++++++++- .../return_project_with_two_modules.json | 27 +++++++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_two_modules.json diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java index f39c8a4fb87..6988fda03b5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java @@ -168,12 +168,14 @@ public class ProjectReferentialsAction implements RequestHandler { } private void addSettingsToChildrenModules(ProjectReferentials ref, String projectKey, Map parentProperties, boolean hasScanPerm, DbSession session) { - parentProperties.putAll(getPropertiesMap(propertiesDao.selectProjectProperties(projectKey, session), hasScanPerm)); - addSettings(ref, projectKey, parentProperties); + Map 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); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java index 12ba20d1c52..34125be594b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java @@ -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 index 00000000000..302176c60f1 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_two_modules.json @@ -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" + } + } +} -- 2.39.5