Search in sources :

Example 1 with Period

use of org.sonar.server.computation.task.projectanalysis.period.Period in project sonarqube by SonarSource.

the class LoadPeriodsStep method buildPeriod.

@CheckForNull
private Period buildPeriod(Component projectOrView, DbSession session) {
    Optional<ComponentDto> projectDto = dbClient.componentDao().selectByKey(session, projectOrView.getKey());
    // No project on first analysis, no period
    if (!projectDto.isPresent()) {
        return null;
    }
    boolean isReportType = projectOrView.getType().isReportType();
    PeriodResolver periodResolver = new PeriodResolver(dbClient, session, projectDto.get().uuid(), analysisMetadataHolder.getAnalysisDate(), isReportType ? projectOrView.getReportAttributes().getVersion() : null);
    Settings settings = settingsRepository.getSettings(projectOrView);
    Period period = periodResolver.resolve(settings);
    // SONAR-4700 Add a past snapshot only if it exists
    if (period != null) {
        return period;
    }
    return null;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Period(org.sonar.server.computation.task.projectanalysis.period.Period) Settings(org.sonar.api.config.Settings) CheckForNull(javax.annotation.CheckForNull)

Example 2 with Period

use of org.sonar.server.computation.task.projectanalysis.period.Period in project sonarqube by SonarSource.

the class IssueCounter method onIssue.

@Override
public void onIssue(Component component, DefaultIssue issue) {
    currentCounters.add(issue);
    if (!periodHolder.hasPeriod()) {
        return;
    }
    Period period = periodHolder.getPeriod();
    // Add one second to not take into account issues created during current analysis
    if (issue.creationDate().getTime() >= period.getSnapshotDate() + 1000L) {
        currentCounters.addOnPeriod(issue);
    }
}
Also used : Period(org.sonar.server.computation.task.projectanalysis.period.Period)

Example 3 with Period

use of org.sonar.server.computation.task.projectanalysis.period.Period in project sonarqube by SonarSource.

the class PeriodResolver method resolve.

@CheckForNull
public Period resolve(Settings settings) {
    String propertyValue = getPropertyValue(settings);
    if (StringUtils.isBlank(propertyValue)) {
        return null;
    }
    Period period = resolve(propertyValue);
    if (period == null && StringUtils.isNotBlank(propertyValue)) {
        LOG.debug("Property " + LEAK_PERIOD + " is not valid: " + propertyValue);
    }
    return period;
}
Also used : Period(org.sonar.server.computation.task.projectanalysis.period.Period) CheckForNull(javax.annotation.CheckForNull)

Example 4 with Period

use of org.sonar.server.computation.task.projectanalysis.period.Period in project sonarqube by SonarSource.

the class PeriodResolver method findByDays.

@CheckForNull
private Period findByDays(int days) {
    List<SnapshotDto> snapshots = dbClient.snapshotDao().selectAnalysesByQuery(session, createCommonQuery(projectUuid).setCreatedBefore(analysisDate).setSort(BY_DATE, ASC));
    long targetDate = DateUtils.addDays(new Date(analysisDate), -days).getTime();
    SnapshotDto snapshot = findNearestSnapshotToTargetDate(snapshots, targetDate);
    if (snapshot == null) {
        return null;
    }
    LOG.debug("Compare over {} days ({}, analysis of {})", String.valueOf(days), formatDate(targetDate), formatDate(snapshot.getCreatedAt()));
    return new Period(LEAK_PERIOD_MODE_DAYS, String.valueOf(days), snapshot.getCreatedAt(), snapshot.getUuid());
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) Period(org.sonar.server.computation.task.projectanalysis.period.Period) Date(java.util.Date) CheckForNull(javax.annotation.CheckForNull)

Example 5 with Period

use of org.sonar.server.computation.task.projectanalysis.period.Period in project sonarqube by SonarSource.

the class PeriodResolver method findByVersion.

@CheckForNull
private Period findByVersion(String version) {
    SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectUuid).setVersion(version).setSort(BY_DATE, DESC));
    if (snapshot == null) {
        return null;
    }
    LOG.debug("Compare to version ({}) ({})", version, formatDate(snapshot.getCreatedAt()));
    return new Period(LEAK_PERIOD_MODE_VERSION, version, snapshot.getCreatedAt(), snapshot.getUuid());
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) Period(org.sonar.server.computation.task.projectanalysis.period.Period) CheckForNull(javax.annotation.CheckForNull)

Aggregations

Period (org.sonar.server.computation.task.projectanalysis.period.Period)27 Test (org.junit.Test)16 SnapshotDto (org.sonar.db.component.SnapshotDto)9 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)8 CheckForNull (javax.annotation.CheckForNull)7 ComponentDto (org.sonar.db.component.ComponentDto)4 Date (java.util.Date)3 OrganizationDto (org.sonar.db.organization.OrganizationDto)3 Component (org.sonar.server.computation.task.projectanalysis.component.Component)3 ReportComponent (org.sonar.server.computation.task.projectanalysis.component.ReportComponent)2 Settings (org.sonar.api.config.Settings)1 ViewsComponent (org.sonar.server.computation.task.projectanalysis.component.ViewsComponent)1 Changeset (org.sonar.server.computation.task.projectanalysis.scm.Changeset)1