use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class ReportSubmitter method submit.
public CeTask submit(String projectKey, @Nullable String projectName, Map<String, String> characteristics, InputStream reportInput) {
try (DbSession dbSession = dbClient.openSession(false)) {
boolean projectCreated = false;
// Note: when the main branch is analyzed, the characteristics may or may not have the branch name, so componentKey#isMainBranch is not
// reliable!
BranchSupport.ComponentKey componentKey = branchSupport.createComponentKey(projectKey, characteristics);
Optional<ComponentDto> mainBranchComponentOpt = dbClient.componentDao().selectByKey(dbSession, componentKey.getKey());
ComponentDto mainBranchComponent;
if (mainBranchComponentOpt.isPresent()) {
mainBranchComponent = mainBranchComponentOpt.get();
validateProject(dbSession, mainBranchComponent, projectKey);
} else {
mainBranchComponent = createProject(dbSession, componentKey.getMainBranchComponentKey(), projectName);
projectCreated = true;
}
BranchDto mainBranch = dbClient.branchDao().selectByUuid(dbSession, mainBranchComponent.projectUuid()).orElseThrow(() -> new IllegalStateException("Couldn't find the main branch of the project"));
ComponentDto branchComponent;
if (isMainBranch(componentKey, mainBranch)) {
branchComponent = mainBranchComponent;
} else {
branchComponent = dbClient.componentDao().selectByKey(dbSession, componentKey.getDbKey()).orElseGet(() -> branchSupport.createBranchComponent(dbSession, componentKey, mainBranchComponent, mainBranch));
}
if (projectCreated) {
componentUpdater.commitAndIndex(dbSession, mainBranchComponent);
} else {
dbSession.commit();
}
checkScanPermission(branchComponent);
return submitReport(dbSession, reportInput, branchComponent, characteristics);
}
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class ComponentUpdater method createMainBranch.
private void createMainBranch(DbSession session, String componentUuid, @Nullable String mainBranch) {
BranchDto branch = new BranchDto().setBranchType(BranchType.BRANCH).setUuid(componentUuid).setKey(Optional.ofNullable(mainBranch).orElse(BranchDto.DEFAULT_MAIN_BRANCH_NAME)).setMergeBranchUuid(null).setExcludeFromPurge(true).setProjectUuid(componentUuid);
dbClient.branchDao().upsert(session, branch);
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class QualityGateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
response.setHeader("Cache-Control", "no-cache");
response.stream().setMediaType(SVG);
try (DbSession dbSession = dbClient.openSession(false)) {
support.validateToken(request);
BranchDto branch = support.getBranch(dbSession, request);
Level qualityGateStatus = getQualityGate(dbSession, branch);
String result = svgGenerator.generateQualityGate(qualityGateStatus);
String eTag = getETag(result);
Optional<String> requestedETag = request.header("If-None-Match");
if (requestedETag.filter(eTag::equals).isPresent()) {
response.stream().setStatus(304);
return;
}
response.setHeader("ETag", eTag);
write(result, response.stream().output(), UTF_8);
} catch (ProjectBadgesException | ForbiddenException | NotFoundException e) {
// There is an issue, so do not return any ETag but make this response expire now
SimpleDateFormat sdf = new SimpleDateFormat(RFC1123_DATE, Locale.US);
response.setHeader("Expires", sdf.format(new Date()));
write(svgGenerator.generateError(e.getMessage()), response.stream().output(), UTF_8);
}
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class ReferenceBranchComponentUuids method lazyInit.
private void lazyInit() {
if (referenceBranchComponentsUuidsByKey == null) {
String referenceBranchUuid = analysisMetadataHolder.getBranch().getReferenceBranchUuid();
referenceBranchComponentsUuidsByKey = new HashMap<>();
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<BranchDto> opt = dbClient.branchDao().selectByUuid(dbSession, referenceBranchUuid);
checkState(opt.isPresent(), "Reference branch '%s' does not exist", referenceBranchUuid);
referenceBranchName = opt.get().getKey();
init(referenceBranchUuid, dbSession);
}
}
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class BranchPersisterImplTest method branch_is_not_excluded_from_purge_when_it_does_not_match_setting.
@Test
public void branch_is_not_excluded_from_purge_when_it_does_not_match_setting() {
analysisMetadataHolder.setProject(PROJECT);
analysisMetadataHolder.setBranch(createBranch(BRANCH, false, "BRANCH_KEY"));
treeRootHolder.setRoot(BRANCH1);
ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setDbKey(MAIN.getDbKey()).setUuid(MAIN.getUuid()));
ComponentDto component = ComponentTesting.newBranchComponent(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH));
dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component);
settings.setProperty(BRANCHES_TO_KEEP_WHEN_INACTIVE, "abc.*");
dbTester.commit();
underTest.persist(dbTester.getSession());
Optional<BranchDto> branchDto = dbTester.getDbClient().branchDao().selectByUuid(dbTester.getSession(), BRANCH1.getUuid());
assertThat(branchDto).isPresent();
assertThat(branchDto.get().isExcludeFromPurge()).isFalse();
}
Aggregations