use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ProjectStatusActionTest method return_status_by_project_key.
@Test
public void return_status_by_project_key() throws IOException {
ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("project-key"));
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setPeriodMode("last_version").setPeriodParam("2015-12-07").setPeriodDate(956789123987L));
MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDto().setEnabled(true).setKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY));
dbClient.measureDao().insert(dbSession, newMeasureDto(metric, project, snapshot).setData(IOUtils.toString(getClass().getResource("ProjectStatusActionTest/measure_data.json"))));
dbSession.commit();
userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
String response = ws.newRequest().setParam(PARAM_PROJECT_KEY, "project-key").execute().getInput();
assertJson(response).isSimilarTo(getClass().getResource("project_status-example.json"));
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class NewCodePeriodResolver method resolveByDays.
private Period resolveByDays(DbSession dbSession, String rootUuid, Integer days, String value, long referenceDate) {
checkPeriodProperty(days > 0, value, "number of days is <= 0");
List<SnapshotDto> snapshots = dbClient.snapshotDao().selectAnalysesByQuery(dbSession, createCommonQuery(rootUuid).setCreatedBefore(referenceDate).setSort(BY_DATE, ASC));
Instant targetDate = DateUtils.addDays(Instant.ofEpochMilli(referenceDate), -days);
LOG.debug("Resolving new code period by {} days: {}", days, supplierToString(() -> logDate(targetDate)));
SnapshotDto snapshot = findNearestSnapshotToTargetDate(snapshots, targetDate);
return newPeriod(NewCodePeriodType.NUMBER_OF_DAYS, String.valueOf((int) days), snapshot.getCreatedAt());
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class NewCodePeriodResolver method findNearestSnapshotToTargetDate.
private static SnapshotDto findNearestSnapshotToTargetDate(List<SnapshotDto> snapshots, Instant targetDate) {
// FIXME shouldn't this be the first analysis after targetDate?
Duration bestDuration = null;
SnapshotDto nearest = null;
ensureNotOnFirstAnalysis(!snapshots.isEmpty());
for (SnapshotDto snapshot : snapshots) {
Instant createdAt = Instant.ofEpochMilli(snapshot.getCreatedAt());
Duration duration = Duration.between(targetDate, createdAt).abs();
if (bestDuration == null || duration.compareTo(bestDuration) <= 0) {
bestDuration = duration;
nearest = snapshot;
}
}
return nearest;
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class LoadCrossProjectDuplicationsRepositoryStepTest method nothing_to_do_when_cross_project_duplication_is_disabled.
@Test
public void nothing_to_do_when_cross_project_duplication_is_disabled() {
when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(false);
analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
ComponentDto otherProject = createProject("OTHER_PROJECT_KEY");
SnapshotDto otherProjectSnapshot = createProjectSnapshot(otherProject);
ComponentDto otherFIle = createFile("OTHER_FILE_KEY", otherProject);
String hash = "a8998353e96320ec";
DuplicationUnitDto duplicate = new DuplicationUnitDto().setHash(hash).setStartLine(40).setEndLine(55).setIndexInFile(0).setAnalysisUuid(otherProjectSnapshot.getUuid()).setComponentUuid(otherFIle.uuid());
dbClient.duplicationDao().insert(dbSession, duplicate);
dbSession.commit();
ScannerReport.CpdTextBlock originBlock = ScannerReport.CpdTextBlock.newBuilder().setHash(hash).setStartLine(30).setEndLine(45).setStartTokenIndex(0).setEndTokenIndex(10).build();
batchReportReader.putDuplicationBlocks(FILE_REF, singletonList(originBlock));
underTest.execute(new TestComputationStepContext());
verifyZeroInteractions(integrateCrossProjectDuplications);
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class LoadCrossProjectDuplicationsRepositoryStepTest method createProjectSnapshot.
private SnapshotDto createProjectSnapshot(ComponentDto project) {
SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(project);
dbClient.snapshotDao().insert(dbSession, projectSnapshot);
dbSession.commit();
return projectSnapshot;
}
Aggregations