Search in sources :

Example 1 with ScmInfo

use of org.sonar.server.computation.task.projectanalysis.scm.ScmInfo in project sonarqube by SonarSource.

the class NewMaintainabilityMeasuresVisitor method initNewDebtRatioCounter.

private void initNewDebtRatioCounter(Component file, Path<Counter> path) {
    // first analysis, no period, no differential value to compute, save processing time and return now
    if (!periodHolder.hasPeriod()) {
        return;
    }
    Optional<Measure> nclocDataMeasure = measureRepository.getRawMeasure(file, this.nclocDataMetric);
    if (!nclocDataMeasure.isPresent()) {
        return;
    }
    Optional<ScmInfo> scmInfoOptional = scmInfoRepository.getScmInfo(file);
    if (!scmInfoOptional.isPresent()) {
        LOG.trace(String.format("No changeset for file %s. Dev cost will be zero.", file.getKey()));
        return;
    }
    ScmInfo scmInfo = scmInfoOptional.get();
    initNewDebtRatioCounter(path.current(), file, nclocDataMeasure.get(), scmInfo);
}
Also used : Measure(org.sonar.server.computation.task.projectanalysis.measure.Measure) ScmInfo(org.sonar.server.computation.task.projectanalysis.scm.ScmInfo)

Example 2 with ScmInfo

use of org.sonar.server.computation.task.projectanalysis.scm.ScmInfo in project sonarqube by SonarSource.

the class LastCommitVisitor method visitFile.

@Override
public void visitFile(Component file, Path<LastCommit> path) {
    // load SCM blame information from report. It can be absent when the file was not touched
    // since previous analysis (optimization to decrease execution of blame commands). In this case
    // the date is loaded from database, as it did not change from previous analysis.
    Optional<ScmInfo> scmInfoOptional = scmInfoRepository.getScmInfo(file);
    if (scmInfoOptional.isPresent()) {
        ScmInfo scmInfo = scmInfoOptional.get();
        path.current().addDate(scmInfo.getLatestChangeset().getDate());
    }
    saveAndAggregate(file, path);
}
Also used : ScmInfo(org.sonar.server.computation.task.projectanalysis.scm.ScmInfo)

Example 3 with ScmInfo

use of org.sonar.server.computation.task.projectanalysis.scm.ScmInfo in project sonarqube by SonarSource.

the class ScmLineReaderTest method set_scm_with_minim_fields.

@Test
public void set_scm_with_minim_fields() {
    ScmInfo scmInfo = new ScmInfoImpl(newArrayList(Changeset.newChangesetBuilder().setDate(123456789L).setRevision("rev-1").build()));
    ScmLineReader lineScm = new ScmLineReader(scmInfo);
    DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1);
    lineScm.read(lineBuilder);
    assertThat(lineBuilder.hasScmAuthor()).isFalse();
    assertThat(lineBuilder.getScmDate()).isEqualTo(123456789L);
    assertThat(lineBuilder.getScmRevision()).isEqualTo("rev-1");
}
Also used : ScmInfoImpl(org.sonar.server.computation.task.projectanalysis.scm.ScmInfoImpl) ScmInfo(org.sonar.server.computation.task.projectanalysis.scm.ScmInfo) Test(org.junit.Test)

Example 4 with ScmInfo

use of org.sonar.server.computation.task.projectanalysis.scm.ScmInfo in project sonarqube by SonarSource.

the class ScmLineReaderTest method set_scm.

@Test
public void set_scm() {
    ScmInfo scmInfo = new ScmInfoImpl(newArrayList(Changeset.newChangesetBuilder().setAuthor("john").setDate(123456789L).setRevision("rev-1").build()));
    ScmLineReader lineScm = new ScmLineReader(scmInfo);
    DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1);
    lineScm.read(lineBuilder);
    assertThat(lineBuilder.getScmAuthor()).isEqualTo("john");
    assertThat(lineBuilder.getScmDate()).isEqualTo(123456789L);
    assertThat(lineBuilder.getScmRevision()).isEqualTo("rev-1");
}
Also used : ScmInfoImpl(org.sonar.server.computation.task.projectanalysis.scm.ScmInfoImpl) ScmInfo(org.sonar.server.computation.task.projectanalysis.scm.ScmInfo) Test(org.junit.Test)

Example 5 with ScmInfo

use of org.sonar.server.computation.task.projectanalysis.scm.ScmInfo in project sonarqube by SonarSource.

the class IssueCreationDateCalculatorTest method withScm.

private void withScm(long blame) {
    ScmInfo scmInfo = mock(ScmInfo.class);
    Changeset changeset = Changeset.newChangesetBuilder().setDate(blame).setRevision("1").build();
    when(scmInfoRepository.getScmInfo(component)).thenReturn(Optional.of(scmInfo));
    when(scmInfo.getLatestChangeset()).thenReturn(changeset);
}
Also used : ScmInfo(org.sonar.server.computation.task.projectanalysis.scm.ScmInfo) Changeset(org.sonar.server.computation.task.projectanalysis.scm.Changeset)

Aggregations

ScmInfo (org.sonar.server.computation.task.projectanalysis.scm.ScmInfo)6 Test (org.junit.Test)3 ScmInfoImpl (org.sonar.server.computation.task.projectanalysis.scm.ScmInfoImpl)3 Changeset (org.sonar.server.computation.task.projectanalysis.scm.Changeset)2 Measure (org.sonar.server.computation.task.projectanalysis.measure.Measure)1