use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class LoadReportAnalysisMetadataHolderStep method toOrganization.
private Organization toOrganization(String organizationUuid) {
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<OrganizationDto> organizationDto = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid);
checkState(organizationDto.isPresent(), "Organization with uuid '{}' can't be found", organizationUuid);
return Organization.from(organizationDto.get());
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class FileMoveDetectionStep method computeScoreMatrix.
private ScoreMatrix computeScoreMatrix(Map<String, DbComponent> dtosByKey, Set<String> dbFileKeys, Map<String, File> reportFileSourcesByKey) {
int[][] scoreMatrix = new int[dbFileKeys.size()][reportFileSourcesByKey.size()];
int maxScore = 0;
try (DbSession dbSession = dbClient.openSession(false)) {
int dbFileIndex = 0;
for (String removedFileKey : dbFileKeys) {
File fileInDb = getFile(dbSession, dtosByKey.get(removedFileKey));
if (fileInDb == null) {
continue;
}
int reportFileIndex = 0;
for (Map.Entry<String, File> reportFileSourceAndKey : reportFileSourcesByKey.entrySet()) {
File unmatchedFile = reportFileSourceAndKey.getValue();
int score = fileSimilarity.score(fileInDb, unmatchedFile);
scoreMatrix[dbFileIndex][reportFileIndex] = score;
if (score > maxScore) {
maxScore = score;
}
reportFileIndex++;
}
dbFileIndex++;
}
}
return new ScoreMatrix(dbFileKeys, reportFileSourcesByKey, scoreMatrix, maxScore);
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class BuildComponentTreeStep method execute.
@Override
public void execute() {
String branch = analysisMetadataHolder.getBranch();
ScannerReport.Component reportProject = reportReader.readComponent(analysisMetadataHolder.getRootComponentRef());
String projectKey = createKey(reportProject.getKey(), branch);
UuidFactory uuidFactory = new UuidFactory(dbClient, projectKey);
try (DbSession dbSession = dbClient.openSession(false)) {
BaseAnalysisSupplier baseAnalysisSupplier = new BaseAnalysisSupplier(dbClient, dbSession);
ComponentRootBuilder rootBuilder = new ComponentRootBuilder(branch, uuidFactory::getOrCreateForKey, reportReader::readComponent, () -> dbClient.componentDao().selectByKey(dbSession, projectKey), baseAnalysisSupplier);
Component project = rootBuilder.build(reportProject, projectKey);
treeRootHolder.setRoot(project);
analysisMetadataHolder.setBaseAnalysis(toAnalysis(baseAnalysisSupplier.apply(project.getUuid())));
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class ComputeMeasureVariationsStep method execute.
@Override
public void execute() {
try (DbSession dbSession = dbClient.openSession(false)) {
List<Metric> metrics = StreamSupport.stream(metricRepository.getAll().spliterator(), false).filter(isNumeric()).collect(Collectors.toList());
new DepthTraversalTypeAwareCrawler(new VariationMeasuresVisitor(dbSession, metrics)).visit(treeRootHolder.getRoot());
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class NewEffortAggregator method beforeComponent.
@Override
public void beforeComponent(Component component) {
try (DbSession dbSession = dbClient.openSession(false)) {
List<IssueChangeDto> changes = dbClient.issueChangeDao().selectChangelogOfNonClosedIssuesByComponent(dbSession, component.getUuid());
for (IssueChangeDto change : changes) {
changesByIssueUuid.put(change.getIssueKey(), change);
}
}
counter = new NewEffortCounter(calculator);
counterByComponentRef.put(component.getReportAttributes().getRef(), counter);
for (Component child : component.getChildren()) {
NewEffortCounter childSum = counterByComponentRef.remove(child.getReportAttributes().getRef());
if (childSum != null) {
counter.add(childSum);
}
}
}
Aggregations