use of org.sonar.scanner.protocol.input.ProjectRepositories in project sonarqube by SonarSource.
the class ProjectAction method handle.
@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
ProjectRepositories data = projectDataLoader.load(ProjectDataQuery.create().setModuleKey(wsRequest.mandatoryParam(PARAM_KEY)).setProfileName(wsRequest.param(PARAM_PROFILE)).setIssuesMode(wsRequest.mandatoryParamAsBoolean(PARAM_ISSUES_MODE)));
WsProjectResponse projectResponse = buildResponse(data);
writeProtobuf(projectResponse, wsRequest, wsResponse);
}
use of org.sonar.scanner.protocol.input.ProjectRepositories in project sonarqube by SonarSource.
the class ProjectDataLoader method load.
public ProjectRepositories load(ProjectDataQuery query) {
try (DbSession session = dbClient.openSession(false)) {
ProjectRepositories data = new ProjectRepositories();
ComponentDto module = checkFoundWithOptional(dbClient.componentDao().selectByKey(session, query.getModuleKey()), "Project or module with key '%s' is not found", query.getModuleKey());
checkRequest(isProjectOrModule(module), "Key '%s' belongs to a component which is not a Project", query.getModuleKey());
boolean hasScanPerm = userSession.hasComponentPermission(SCAN_EXECUTION, module) || userSession.hasPermission(OrganizationPermission.SCAN, module.getOrganizationUuid());
boolean hasBrowsePerm = userSession.hasComponentPermission(USER, module);
checkPermission(query.isIssuesMode(), hasScanPerm, hasBrowsePerm);
ComponentDto project = getProject(module, session);
if (!project.key().equals(module.key())) {
addSettings(data, module.getKey(), getSettingsFromParents(module, hasScanPerm, session));
}
List<ComponentDto> modulesTree = dbClient.componentDao().selectEnabledDescendantModules(session, module.uuid());
Map<String, String> moduleUuidsByKey = moduleUuidsByKey(modulesTree);
Map<String, Long> moduleIdsByKey = moduleIdsByKey(modulesTree);
List<PropertyDto> modulesTreeSettings = dbClient.propertiesDao().selectEnabledDescendantModuleProperties(module.uuid(), session);
TreeModuleSettings treeModuleSettings = new TreeModuleSettings(moduleUuidsByKey, moduleIdsByKey, modulesTree, modulesTreeSettings);
addSettingsToChildrenModules(data, query.getModuleKey(), Maps.<String, String>newHashMap(), treeModuleSettings, hasScanPerm);
List<FilePathWithHashDto> files = searchFilesWithHashAndRevision(session, module);
addFileData(data, modulesTree, files);
// FIXME need real value but actually only used to know if there is a previous analysis in local issue tracking mode so any value is
// ok
data.setLastAnalysisDate(new Date());
return data;
}
}
use of org.sonar.scanner.protocol.input.ProjectRepositories in project sonarqube by SonarSource.
the class ProjectActionTest method project_referentials.
@Test
public void project_referentials() throws Exception {
String projectKey = "org.codehaus.sonar:sonar";
ProjectRepositories projectReferentials = mock(ProjectRepositories.class);
when(projectReferentials.toJson()).thenReturn("{\"settingsByModule\": {}}");
ArgumentCaptor<ProjectDataQuery> queryArgumentCaptor = ArgumentCaptor.forClass(ProjectDataQuery.class);
when(projectDataLoader.load(queryArgumentCaptor.capture())).thenReturn(projectReferentials);
TestResponse response = ws.newRequest().setParam("key", projectKey).setParam("profile", "Default").setParam("preview", "false").execute();
assertJson(response.getInput()).isSimilarTo("{\"settingsByModule\": {}}");
assertThat(queryArgumentCaptor.getValue().getModuleKey()).isEqualTo(projectKey);
assertThat(queryArgumentCaptor.getValue().getProfileName()).isEqualTo("Default");
assertThat(queryArgumentCaptor.getValue().isIssuesMode()).isFalse();
}
use of org.sonar.scanner.protocol.input.ProjectRepositories in project sonarqube by SonarSource.
the class ProjectDataLoaderMediumTest method return_file_data_from_single_project.
@Test
public void return_file_data_from_single_project() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
ComponentDto file = ComponentTesting.newFileDto(project, null, "file");
dbClient.componentDao().insert(dbSession, file);
tester.get(FileSourceDao.class).insert(dbSession, newFileSourceDto(file).setSrcHash("123456"));
dbSession.commit();
ProjectRepositories ref = underTest.load(ProjectDataQuery.create().setModuleKey(project.key()));
assertThat(ref.fileDataByPath(project.key())).hasSize(1);
FileData fileData = ref.fileData(project.key(), file.path());
assertThat(fileData.hash()).isEqualTo("123456");
}
use of org.sonar.scanner.protocol.input.ProjectRepositories in project sonarqube by SonarSource.
the class ProjectDataLoaderMediumTest method return_project_settings_with_global_scan_permission.
@Test
public void return_project_settings_with_global_scan_permission() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
// Project properties
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId()));
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId()));
dbSession.commit();
ProjectRepositories ref = underTest.load(ProjectDataQuery.create().setModuleKey(project.key()));
Map<String, String> projectSettings = ref.settings(project.key());
assertThat(projectSettings).isEqualTo(ImmutableMap.of("sonar.jira.project.key", "SONAR", "sonar.jira.login.secured", "john"));
}
Aggregations