Browse Source

SONAR-5417 Fix issues when properties on a module were wrongly copied on other modules

tags/4.5-RC1
Julien Lancelot 9 years ago
parent
commit
17c62b8bdd

+ 6
- 4
server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java View 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);
}
}


+ 29
- 1
server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java View 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);

+ 27
- 0
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_two_modules.json View File

@@ -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"
}
}
}

Loading…
Cancel
Save