Search in sources :

Example 1 with FileData

use of org.sonar.scanner.protocol.input.FileData in project sonarqube by SonarSource.

the class ProjectDataLoader method addFileData.

private static void addFileData(ProjectRepositories data, List<ComponentDto> moduleChildren, List<FilePathWithHashDto> files) {
    Map<String, String> moduleKeysByUuid = newHashMap();
    for (ComponentDto module : moduleChildren) {
        moduleKeysByUuid.put(module.uuid(), module.key());
    }
    for (FilePathWithHashDto file : files) {
        FileData fileData = new FileData(file.getSrcHash(), file.getRevision());
        data.addFileData(moduleKeysByUuid.get(file.getModuleUuid()), file.getPath(), fileData);
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) FilePathWithHashDto(org.sonar.db.component.FilePathWithHashDto) FileData(org.sonar.scanner.protocol.input.FileData)

Example 2 with FileData

use of org.sonar.scanner.protocol.input.FileData 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 3 with FileData

use of org.sonar.scanner.protocol.input.FileData in project sonarqube by SonarSource.

the class ProjectActionTest method do_not_fail_when_a_path_is_null.

/**
   * SONAR-7084
   */
@Test
public void do_not_fail_when_a_path_is_null() throws Exception {
    String projectKey = "org.codehaus.sonar:sonar";
    ProjectRepositories projectRepositories = new ProjectRepositories().addFileData("module-1", null, new FileData(null, null));
    when(projectDataLoader.load(any(ProjectDataQuery.class))).thenReturn(projectRepositories);
    TestResponse result = ws.newRequest().setMediaType(MediaTypes.PROTOBUF).setParam("key", projectKey).setParam("profile", "Default").execute();
    WsProjectResponse wsProjectResponse = WsProjectResponse.parseFrom(result.getInputStream());
    assertThat(wsProjectResponse.getFileDataByModuleAndPath()).isEmpty();
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) WsProjectResponse(org.sonarqube.ws.WsBatch.WsProjectResponse) FileData(org.sonar.scanner.protocol.input.FileData) ProjectRepositories(org.sonar.scanner.protocol.input.ProjectRepositories) Test(org.junit.Test)

Aggregations

FileData (org.sonar.scanner.protocol.input.FileData)3 Test (org.junit.Test)2 ComponentDto (org.sonar.db.component.ComponentDto)2 ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)2 FilePathWithHashDto (org.sonar.db.component.FilePathWithHashDto)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1 FileSourceDao (org.sonar.db.source.FileSourceDao)1 TestResponse (org.sonar.server.ws.TestResponse)1 WsProjectResponse (org.sonarqube.ws.WsBatch.WsProjectResponse)1