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;
}
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);
}
}
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;
}
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());
}
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());
}
Aggregations