Search in sources :

Example 1 with ProjectRepositories

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);
}
Also used : WsProjectResponse(org.sonarqube.ws.WsBatch.WsProjectResponse) ProjectRepositories(org.sonar.scanner.protocol.input.ProjectRepositories)

Example 2 with ProjectRepositories

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;
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) FilePathWithHashDto(org.sonar.db.component.FilePathWithHashDto) Date(java.util.Date) DbSession(org.sonar.db.DbSession) ProjectRepositories(org.sonar.scanner.protocol.input.ProjectRepositories) PropertyDto(org.sonar.db.property.PropertyDto)

Example 3 with ProjectRepositories

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();
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) ProjectRepositories(org.sonar.scanner.protocol.input.ProjectRepositories) Test(org.junit.Test)

Example 4 with ProjectRepositories

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");
}
Also used : FileSourceDao(org.sonar.db.source.FileSourceDao) ComponentDto(org.sonar.db.component.ComponentDto) FileData(org.sonar.scanner.protocol.input.FileData) OrganizationDto(org.sonar.db.organization.OrganizationDto) ProjectRepositories(org.sonar.scanner.protocol.input.ProjectRepositories) Test(org.junit.Test)

Example 5 with ProjectRepositories

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"));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) PropertyDto(org.sonar.db.property.PropertyDto) ProjectRepositories(org.sonar.scanner.protocol.input.ProjectRepositories) Test(org.junit.Test)

Aggregations

ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)21 Test (org.junit.Test)19 ComponentDto (org.sonar.db.component.ComponentDto)18 OrganizationDto (org.sonar.db.organization.OrganizationDto)15 PropertyDto (org.sonar.db.property.PropertyDto)13 FileSourceDao (org.sonar.db.source.FileSourceDao)3 FileData (org.sonar.scanner.protocol.input.FileData)2 TestResponse (org.sonar.server.ws.TestResponse)2 WsProjectResponse (org.sonarqube.ws.WsBatch.WsProjectResponse)2 Date (java.util.Date)1 DbSession (org.sonar.db.DbSession)1 FilePathWithHashDto (org.sonar.db.component.FilePathWithHashDto)1