Search in sources :

Example 1 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class FileMoveDetectionStep method getFile.

@CheckForNull
private File getFile(DbSession dbSession, DbComponent dbComponent) {
    if (dbComponent.getPath() == null) {
        return null;
    }
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(dbSession, dbComponent.getUuid());
    if (fileSourceDto == null) {
        return null;
    }
    String lineHashes = firstNonNull(fileSourceDto.getLineHashes(), "");
    return new File(dbComponent.getPath(), LINES_HASHES_SPLITTER.splitToList(lineHashes));
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) File(org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarity.File) CheckForNull(javax.annotation.CheckForNull)

Example 2 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class FileMoveDetectionStepTest method mockContentOfFileInDb.

private void mockContentOfFileInDb(String key, @Nullable String[] content) {
    FileSourceDto dto = new FileSourceDto();
    if (content != null) {
        SourceLinesHashesComputer linesHashesComputer = new SourceLinesHashesComputer();
        stream(content).forEach(linesHashesComputer::addLine);
        dto.setLineHashes(on('\n').join(linesHashesComputer.getLineHashes()));
    }
    when(fileSourceDao.selectSourceByFileUuid(dbSession, componentUuidOf(key))).thenReturn(dto);
}
Also used : SourceLinesHashesComputer(org.sonar.core.hash.SourceLinesHashesComputer) FileSourceDto(org.sonar.db.source.FileSourceDto)

Example 3 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class ScmInfoRepositoryImplTest method addFileSourceInDb.

private void addFileSourceInDb(@Nullable String author, @Nullable Long date, @Nullable String revision, String srcHash) {
    DbFileSources.Data.Builder fileDataBuilder = DbFileSources.Data.newBuilder();
    DbFileSources.Line.Builder builder = fileDataBuilder.addLinesBuilder().setLine(1);
    if (author != null) {
        builder.setScmAuthor(author);
    }
    if (date != null) {
        builder.setScmDate(date);
    }
    if (revision != null) {
        builder.setScmRevision(revision);
    }
    dbTester.getDbClient().fileSourceDao().insert(dbTester.getSession(), new FileSourceDto().setFileUuid(FILE.getUuid()).setProjectUuid("PROJECT_UUID").setSourceData(fileDataBuilder.build()).setSrcHash(srcHash));
    dbTester.commit();
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto)

Example 4 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method not_save_revision.

@Test
public void not_save_revision() {
    initBasicReport(1);
    underTest.execute();
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE_UUID);
    assertThat(fileSourceDto.getRevision()).isNull();
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test)

Example 5 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class PersistTestsStepTest method aggregate_coverage_details.

@Test
public void aggregate_coverage_details() {
    reportReader.putTests(TEST_FILE_REF_1, Arrays.asList(newTest(1)));
    reportReader.putCoverageDetails(TEST_FILE_REF_1, Arrays.asList(newCoverageDetailWithLines(1, MAIN_FILE_REF_1, 1, 3), newCoverageDetailWithLines(1, MAIN_FILE_REF_1, 2, 4)));
    underTest.execute();
    FileSourceDto dto = dbClient.fileSourceDao().selectTest(db.getSession(), TEST_FILE_UUID_1);
    List<Integer> coveredLines = dto.getTestData().get(0).getCoveredFile(0).getCoveredLineList();
    assertThat(coveredLines).containsOnly(1, 2, 3, 4);
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test)

Aggregations

FileSourceDto (org.sonar.db.source.FileSourceDto)58 Test (org.junit.Test)46 DbFileSources (org.sonar.db.protobuf.DbFileSources)19 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)15 BaseStepTest (org.sonar.ce.task.projectanalysis.step.BaseStepTest)14 Changeset (org.sonar.ce.task.projectanalysis.scm.Changeset)5 ComponentDto (org.sonar.db.component.ComponentDto)5 Before (org.junit.Before)3 DbSession (org.sonar.db.DbSession)3 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 DigestUtils (org.apache.commons.codec.digest.DigestUtils)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Rule (org.junit.Rule)2 Mockito (org.mockito.Mockito)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2