From 71fbd220a15c44b6f1451e2a4b9874a55ba40bdd Mon Sep 17 00:00:00 2001 From: Lukasz Jarocki Date: Thu, 6 Apr 2023 14:09:50 +0200 Subject: [PATCH] SONAR-18850 mainBranchProjectUuid refactoring --- .../issue/SourceBranchComponentUuidsIT.java | 2 +- .../issue/TargetBranchComponentUuidsIT.java | 2 +- .../step/LoadPeriodsStepIT.java | 19 +++-- .../step/ReportPersistComponentsStepIT.java | 7 -- .../sonar/db/component/ComponentDaoIT.java | 23 ------ .../java/org/sonar/db/purge/PurgeDaoIT.java | 77 ++++++++++--------- .../org/sonar/db/component/ComponentDao.java | 12 --- .../sonar/db/component/ComponentMapper.java | 7 -- .../sonar/db/component/ComponentMapper.xml | 11 --- .../developers/ws/SearchEventsActionIT.java | 15 ++-- .../ws/SearchEventsActionNewIssuesIT.java | 22 ++++-- .../ws/SearchEventsActionQualityGateIT.java | 20 ++--- .../server/project/ws/CreateActionIT.java | 4 +- 13 files changed, 89 insertions(+), 132 deletions(-) diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuidsIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuidsIT.java index c901b3c8757..e6b60e48f58 100644 --- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuidsIT.java +++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuidsIT.java @@ -66,7 +66,7 @@ public class SourceBranchComponentUuidsIT { ComponentDto pr1branch = db.components().insertProjectBranch(projectDto, b -> b.setKey(PR_KEY) .setBranchType(BranchType.PULL_REQUEST) .setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setBranch(BRANCH_KEY).build()) - .setMergeBranchUuid(projectDto.getMainBranchProjectUuid())); + .setMergeBranchUuid(projectDto.uuid())); branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File"); pr1File = ComponentTesting.newFileDto(pr1branch, null, "file").setUuid("file1"); db.components().insertComponents(branch1File, pr1File); diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuidsIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuidsIT.java index af811e8ec56..9961070a8ed 100644 --- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuidsIT.java +++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuidsIT.java @@ -65,7 +65,7 @@ public class TargetBranchComponentUuidsIT { ComponentDto pr1branch = db.components().insertProjectBranch(projectDto, b -> b.setKey(PR_KEY) .setBranchType(BranchType.PULL_REQUEST) .setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setTarget(BRANCH_KEY).build()) - .setMergeBranchUuid(projectDto.getMainBranchProjectUuid())); + .setMergeBranchUuid(projectDto.uuid())); branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File"); pr1File = ComponentTesting.newFileDto(pr1branch, null, "file").setUuid("file1"); db.components().insertComponents(branch1File, pr1File); diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepIT.java index 7a34a181f89..51b03356334 100644 --- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepIT.java +++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepIT.java @@ -60,7 +60,6 @@ import org.sonar.db.newcodeperiod.NewCodePeriodType; import org.sonar.server.project.Project; import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; -import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.fail; @@ -313,7 +312,7 @@ public class LoadPeriodsStepIT extends BaseStepTest { public void throw_ISE_when_specific_analysis_is_set_but_does_not_exist_in_DB() { ComponentDto project = dbTester.components().insertPublicProject(); setProjectPeriod(project.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "nonexistent"); - setupRoot(project); + setupRoot(project, project.uuid(), "any-string"); assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext())) .isInstanceOf(IllegalStateException.class) @@ -535,23 +534,27 @@ public class LoadPeriodsStepIT extends BaseStepTest { .containsOnly(Stream.concat(Stream.of(log), Arrays.stream(otherLogs)).toArray(String[]::new)); } - private void setupRoot(ComponentDto project) { - setupRoot(project, randomAlphanumeric(3)); + private void setupRoot(ComponentDto branchComponent) { + setupRoot(branchComponent, "any-string"); } - private void setupRoot(ComponentDto projectDto, String version) { + private void setupRoot(ComponentDto branchComponent, String projectUuid, String version) { treeRootHolder.setRoot(ReportComponent .builder(Component.Type.PROJECT, 1) - .setUuid(projectDto.uuid()) - .setKey(projectDto.getKey()) + .setUuid(branchComponent.uuid()) + .setKey(branchComponent.getKey()) .setProjectVersion(version) .build()); Project project = mock(Project.class); - when(project.getUuid()).thenReturn(projectDto.getMainBranchProjectUuid() != null ? projectDto.getMainBranchProjectUuid() : projectDto.uuid()); + when(project.getUuid()).thenReturn(projectUuid); when(analysisMetadataHolder.getProject()).thenReturn(project); } + private void setupRoot(ComponentDto branchComponent, String version) { + setupRoot(branchComponent, project.uuid(), version); + } + private static void verifyInvalidValueMessage(MessageException e, String propertyValue) { assertThat(e).hasMessage("Invalid new code period. '" + propertyValue + "' is not one of: integer > 0, date before current analysis j, \"previous_version\", or version string that exists in the project' \n" + diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java index 68390b46134..2f6d81ff368 100644 --- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java +++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java @@ -124,7 +124,6 @@ public class ReportPersistComponentsStepIT extends BaseStepTest { assertThat(directoryDto.path()).isEqualTo("src/main/java/dir"); assertThat(directoryDto.uuid()).isEqualTo("CDEF"); assertThat(directoryDto.getUuidPath()).isEqualTo(UUID_PATH_SEPARATOR + projectDto.uuid() + UUID_PATH_SEPARATOR); - assertThat(directoryDto.getMainBranchProjectUuid()).isNull(); assertThat(directoryDto.branchUuid()).isEqualTo(projectDto.uuid()); assertThat(directoryDto.qualifier()).isEqualTo("DIR"); assertThat(directoryDto.scope()).isEqualTo("DIR"); @@ -138,7 +137,6 @@ public class ReportPersistComponentsStepIT extends BaseStepTest { assertThat(fileDto.language()).isEqualTo("java"); assertThat(fileDto.uuid()).isEqualTo("DEFG"); assertThat(fileDto.getUuidPath()).isEqualTo(directoryDto.getUuidPath() + directoryDto.uuid() + UUID_PATH_SEPARATOR); - assertThat(fileDto.getMainBranchProjectUuid()).isNull(); assertThat(fileDto.branchUuid()).isEqualTo(projectDto.uuid()); assertThat(fileDto.qualifier()).isEqualTo("FIL"); assertThat(fileDto.scope()).isEqualTo("FIL"); @@ -176,7 +174,6 @@ public class ReportPersistComponentsStepIT extends BaseStepTest { assertThat(directoryDto.path()).isEqualTo("src/main/java/dir"); assertThat(directoryDto.uuid()).isEqualTo("CDEF"); assertThat(directoryDto.getUuidPath()).isEqualTo(UUID_PATH_SEPARATOR + branch.uuid() + UUID_PATH_SEPARATOR); - assertThat(directoryDto.getMainBranchProjectUuid()).isEqualTo(analysisMetadataHolder.getProject().getUuid()); assertThat(directoryDto.branchUuid()).isEqualTo(branch.uuid()); assertThat(directoryDto.qualifier()).isEqualTo("DIR"); assertThat(directoryDto.scope()).isEqualTo("DIR"); @@ -190,7 +187,6 @@ public class ReportPersistComponentsStepIT extends BaseStepTest { assertThat(fileDto.language()).isEqualTo("java"); assertThat(fileDto.uuid()).isEqualTo("DEFG"); assertThat(fileDto.getUuidPath()).isEqualTo(directoryDto.getUuidPath() + directoryDto.uuid() + UUID_PATH_SEPARATOR); - assertThat(fileDto.getMainBranchProjectUuid()).isEqualTo(analysisMetadataHolder.getProject().getUuid()); assertThat(fileDto.branchUuid()).isEqualTo(branch.uuid()); assertThat(fileDto.qualifier()).isEqualTo("FIL"); assertThat(fileDto.scope()).isEqualTo("FIL"); @@ -309,17 +305,14 @@ public class ReportPersistComponentsStepIT extends BaseStepTest { ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getKey()).get(); assertThat(projectReloaded.uuid()).isEqualTo(project.uuid()); assertThat(projectReloaded.getUuidPath()).isEqualTo(UUID_PATH_OF_ROOT); - assertThat(projectReloaded.getMainBranchProjectUuid()).isNull(); ComponentDto directory = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get(); assertThat(directory.getUuidPath()).isEqualTo(directory.getUuidPath()); assertThat(directory.branchUuid()).isEqualTo(project.uuid()); - assertThat(directory.getMainBranchProjectUuid()).isNull(); ComponentDto file = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get(); assertThat(file.getUuidPath()).isEqualTo(file.getUuidPath()); assertThat(file.branchUuid()).isEqualTo(project.uuid()); - assertThat(file.getMainBranchProjectUuid()).isNull(); } @Test diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java index 9a08ca17b6c..e5f5acc66c6 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java @@ -866,29 +866,6 @@ public class ComponentDaoIT { assertThat(underTest.selectProjectsFromView(dbSession, subView2.uuid(), view.uuid())).containsExactlyInAnyOrder(project3.uuid()); } - @Test - public void select_projects() { - ComponentDto provisionedProject = db.components().insertPrivateProject(); - ComponentDto provisionedView = db.components().insertPrivatePortfolio(); - String projectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto()).getComponentUuid(); - String disabledProjectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto().setEnabled(false)).getComponentUuid(); - String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newPortfolio()).getComponentUuid(); - - assertThat(underTest.selectProjects(dbSession)) - .extracting(ComponentDto::uuid) - .containsOnly(provisionedProject.uuid(), projectUuid); - } - - @Test - public void select_projects_does_not_return_branches() { - ComponentDto project = db.components().insertPublicProject(); - ComponentDto branch = db.components().insertProjectBranch(project); - - assertThat(underTest.selectProjects(dbSession)) - .extracting(ComponentDto::uuid) - .containsOnly(project.uuid()); - } - @Test public void selectByQuery_provisioned() { ComponentDto provisionedProject = db.components() diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java index 171c524c1a6..b636205ca39 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java @@ -85,7 +85,6 @@ import org.sonar.db.user.UserDto; import org.sonar.db.webhook.WebhookDeliveryLiteDto; import org.sonar.db.webhook.WebhookDto; -import static com.google.common.base.MoreObjects.firstNonNull; import static java.nio.charset.StandardCharsets.UTF_8; import static java.time.ZoneOffset.UTC; import static java.util.Arrays.asList; @@ -253,7 +252,7 @@ public class PurgeDaoIT { insertPropertyFor(branch3, branch1); // analysing branch1 - underTest.purge(dbSession, newConfigurationWith30Days(System2.INSTANCE, branch1.uuid(), branch1.getMainBranchProjectUuid()), PurgeListener.EMPTY, new PurgeProfiler()); + underTest.purge(dbSession, newConfigurationWith30Days(System2.INSTANCE, branch1.uuid(), project.uuid()), PurgeListener.EMPTY, new PurgeProfiler()); dbSession.commit(); // branch1 wasn't deleted since it was being analyzed! @@ -687,8 +686,8 @@ public class PurgeDaoIT { ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(); insertComponents(List.of(anotherLivingProject), List.of(projectToBeDeleted)); // Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project - CeActivityDto toBeDeletedActivity = insertCeActivity(projectToBeDeleted); - CeActivityDto notDeletedActivity = insertCeActivity(anotherLivingProject); + CeActivityDto toBeDeletedActivity = insertCeActivity(projectToBeDeleted, projectToBeDeleted.uuid()); + CeActivityDto notDeletedActivity = insertCeActivity(anotherLivingProject, anotherLivingProject.uuid()); dbSession.commit(); underTest.deleteProject(dbSession, projectToBeDeleted.uuid(), projectToBeDeleted.qualifier(), projectToBeDeleted.name(), projectToBeDeleted.getKey()); @@ -708,13 +707,13 @@ public class PurgeDaoIT { insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch)); - CeActivityDto projectTask = insertCeActivity(project); + CeActivityDto projectTask = insertCeActivity(project, project.uuid()); insertCeTaskInput(projectTask.getUuid()); - CeActivityDto branchTask = insertCeActivity(branch); + CeActivityDto branchTask = insertCeActivity(branch, project.uuid()); insertCeTaskInput(branchTask.getUuid()); - CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch); + CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch, project.uuid()); insertCeTaskInput(anotherBranchTask.getUuid()); - CeActivityDto anotherProjectTask = insertCeActivity(anotherProject); + CeActivityDto anotherProjectTask = insertCeActivity(anotherProject, anotherProject.uuid()); insertCeTaskInput(anotherProjectTask.getUuid()); insertCeTaskInput("non existing task"); dbSession.commit(); @@ -741,13 +740,13 @@ public class PurgeDaoIT { insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch)); - CeActivityDto projectTask = insertCeActivity(project); + CeActivityDto projectTask = insertCeActivity(project, project.uuid()); insertCeScannerContext(projectTask.getUuid()); - CeActivityDto branchTask = insertCeActivity(branch); + CeActivityDto branchTask = insertCeActivity(branch, project.uuid()); insertCeScannerContext(branchTask.getUuid()); - CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch); + CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch, project.uuid()); insertCeScannerContext(anotherBranchTask.getUuid()); - CeActivityDto anotherProjectTask = insertCeActivity(anotherProject); + CeActivityDto anotherProjectTask = insertCeActivity(anotherProject, anotherProject.uuid()); insertCeScannerContext(anotherProjectTask.getUuid()); insertCeScannerContext("non existing task"); dbSession.commit(); @@ -774,13 +773,13 @@ public class PurgeDaoIT { insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch)); - CeActivityDto projectTask = insertCeActivity(project); + CeActivityDto projectTask = insertCeActivity(project, project.uuid()); insertCeTaskCharacteristics(projectTask.getUuid(), 3); - CeActivityDto branchTask = insertCeActivity(branch); + CeActivityDto branchTask = insertCeActivity(branch, project.uuid()); insertCeTaskCharacteristics(branchTask.getUuid(), 2); - CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch); + CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch, project.uuid()); insertCeTaskCharacteristics(anotherBranchTask.getUuid(), 6); - CeActivityDto anotherProjectTask = insertCeActivity(anotherProject); + CeActivityDto anotherProjectTask = insertCeActivity(anotherProject, anotherProject.uuid()); insertCeTaskCharacteristics(anotherProjectTask.getUuid(), 2); insertCeTaskCharacteristics("non existing task", 5); dbSession.commit(); @@ -807,13 +806,13 @@ public class PurgeDaoIT { insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch)); - CeActivityDto projectTask = insertCeActivity(project); + CeActivityDto projectTask = insertCeActivity(project, project.uuid()); insertCeTaskMessages(projectTask.getUuid(), 3); - CeActivityDto branchTask = insertCeActivity(branch); + CeActivityDto branchTask = insertCeActivity(branch, project.uuid()); insertCeTaskMessages(branchTask.getUuid(), 2); - CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch); + CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch, project.uuid()); insertCeTaskMessages(anotherBranchTask.getUuid(), 6); - CeActivityDto anotherProjectTask = insertCeActivity(anotherProject); + CeActivityDto anotherProjectTask = insertCeActivity(anotherProject, anotherProject.uuid()); insertCeTaskMessages(anotherProjectTask.getUuid(), 2); insertCeTaskMessages("non existing task", 5); dbSession.commit(); @@ -857,9 +856,9 @@ public class PurgeDaoIT { // Insert 3 rows in CE_QUEUE: two for the project that will be deleted (in order to check that status // is not involved in deletion), and one on another project - dbClient.ceQueueDao().insert(dbSession, createCeQueue(projectToBeDeleted, Status.PENDING)); - dbClient.ceQueueDao().insert(dbSession, createCeQueue(projectToBeDeleted, Status.IN_PROGRESS)); - dbClient.ceQueueDao().insert(dbSession, createCeQueue(anotherLivingProject, Status.PENDING)); + dbClient.ceQueueDao().insert(dbSession, createCeQueue(projectToBeDeleted, projectToBeDeleted.uuid(), Status.PENDING)); + dbClient.ceQueueDao().insert(dbSession, createCeQueue(projectToBeDeleted, projectToBeDeleted.uuid(), Status.IN_PROGRESS)); + dbClient.ceQueueDao().insert(dbSession, createCeQueue(anotherLivingProject, anotherLivingProject.uuid(), Status.PENDING)); dbSession.commit(); underTest.deleteProject(dbSession, projectToBeDeleted.uuid(), projectToBeDeleted.qualifier(), projectToBeDeleted.name(), projectToBeDeleted.getKey()); @@ -880,9 +879,9 @@ public class PurgeDaoIT { CeQueueDto projectTask = insertCeQueue(project); insertCeTaskInput(projectTask.getUuid()); - CeQueueDto branchTask = insertCeQueue(branch); + CeQueueDto branchTask = insertCeQueue(branch, project.uuid()); insertCeTaskInput(branchTask.getUuid()); - CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch); + CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch, project.uuid()); insertCeTaskInput(anotherBranchTask.getUuid()); CeQueueDto anotherProjectTask = insertCeQueue(anotherProject); insertCeTaskInput(anotherProjectTask.getUuid()); @@ -913,9 +912,9 @@ public class PurgeDaoIT { CeQueueDto projectTask = insertCeQueue(project); insertCeScannerContext(projectTask.getUuid()); - CeQueueDto branchTask = insertCeQueue(branch); + CeQueueDto branchTask = insertCeQueue(branch, project.uuid()); insertCeScannerContext(branchTask.getUuid()); - CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch); + CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch, project.uuid()); insertCeScannerContext(anotherBranchTask.getUuid()); CeQueueDto anotherProjectTask = insertCeQueue(anotherProject); insertCeScannerContext(anotherProjectTask.getUuid()); @@ -952,9 +951,9 @@ public class PurgeDaoIT { CeQueueDto projectTask = insertCeQueue(project); insertCeTaskCharacteristics(projectTask.getUuid(), 3); - CeQueueDto branchTask = insertCeQueue(branch); + CeQueueDto branchTask = insertCeQueue(branch, project.uuid()); insertCeTaskCharacteristics(branchTask.getUuid(), 1); - CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch); + CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch, project.uuid()); insertCeTaskCharacteristics(anotherBranchTask.getUuid(), 5); CeQueueDto anotherProjectTask = insertCeQueue(anotherProject); insertCeTaskCharacteristics(anotherProjectTask.getUuid(), 2); @@ -986,9 +985,9 @@ public class PurgeDaoIT { CeQueueDto projectTask = insertCeQueue(project); insertCeTaskMessages(projectTask.getUuid(), 3); - CeQueueDto branchTask = insertCeQueue(branch); + CeQueueDto branchTask = insertCeQueue(branch, project.uuid()); insertCeTaskMessages(branchTask.getUuid(), 1); - CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch); + CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch, project.uuid()); insertCeTaskMessages(anotherBranchTask.getUuid(), 5); CeQueueDto anotherProjectTask = insertCeQueue(anotherProject); insertCeTaskMessages(anotherProjectTask.getUuid(), 2); @@ -1797,21 +1796,21 @@ public class PurgeDaoIT { dbSession.commit(); } - private CeQueueDto createCeQueue(ComponentDto component, Status status) { + private CeQueueDto createCeQueue(ComponentDto component, String mainBranch, Status status) { CeQueueDto queueDto = new CeQueueDto(); queueDto.setUuid(Uuids.create()); queueDto.setTaskType(REPORT); queueDto.setComponentUuid(component.uuid()); - queueDto.setMainComponentUuid(firstNonNull(component.getMainBranchProjectUuid(), component.uuid())); + queueDto.setMainComponentUuid(mainBranch); queueDto.setSubmitterUuid("submitter uuid"); queueDto.setCreatedAt(1_300_000_000_000L); queueDto.setStatus(status); return queueDto; } - private CeActivityDto insertCeActivity(ComponentDto component) { + private CeActivityDto insertCeActivity(ComponentDto component, String mainBranch) { Status unusedStatus = Status.values()[RandomUtils.nextInt(Status.values().length)]; - CeQueueDto queueDto = createCeQueue(component, unusedStatus); + CeQueueDto queueDto = createCeQueue(component, mainBranch, unusedStatus); CeActivityDto dto = new CeActivityDto(queueDto); dto.setStatus(CeActivityDto.Status.SUCCESS); @@ -1822,12 +1821,12 @@ public class PurgeDaoIT { return dto; } - private CeQueueDto insertCeQueue(ComponentDto component) { + private CeQueueDto insertCeQueue(ComponentDto component, String mainBranch) { CeQueueDto res = new CeQueueDto() .setUuid(UuidFactoryFast.getInstance().create()) .setTaskType("foo") .setComponentUuid(component.uuid()) - .setMainComponentUuid(firstNonNull(component.getMainBranchProjectUuid(), component.uuid())) + .setMainComponentUuid(mainBranch) .setStatus(Status.PENDING) .setCreatedAt(1_2323_222L) .setUpdatedAt(1_2323_222L); @@ -1836,6 +1835,10 @@ public class PurgeDaoIT { return res; } + private CeQueueDto insertCeQueue(ComponentDto component) { + return insertCeQueue(component, component.uuid()); + } + private void insertCeScannerContext(String uuid) { dbClient.ceScannerContextDao().insert(dbSession, uuid, CloseableIterator.from(Arrays.asList("a", "b", "c").iterator())); dbSession.commit(); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java index 71dbafe1e4b..4a25cfd547f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java @@ -225,18 +225,6 @@ public class ComponentDao implements Dao { return mapper(session).selectUuidsForQualifiers(Qualifiers.APP, Qualifiers.VIEW, Qualifiers.SUBVIEW); } - /** - * Returns all projects (Scope {@link Scopes#PROJECT} and qualifier - * {@link Qualifiers#PROJECT}) which are enabled. - *

- * Branches are not returned. - *

- * Used by Views. - */ - public List selectProjects(DbSession session) { - return mapper(session).selectProjects(); - } - /** * Used by Governance */ diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java index f9a9b632e94..bfa813b6444 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java @@ -62,13 +62,6 @@ public interface ComponentMapper { List selectChildren(@Param("branchUuid") String branchUuid, @Param("uuidPaths") Set uuidPaths); - /** - * Returns all enabled projects (Scope {@link org.sonar.api.resources.Scopes#PROJECT} and qualifier - * {@link org.sonar.api.resources.Qualifiers#PROJECT}) no matter if they are ghost project, provisioned projects or - * regular ones. - */ - List selectProjects(); - /** * Return all descendant views (including itself) from a given root view */ diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml index 1f8f072d7cb..4f301f249f3 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -198,17 +198,6 @@ root.uuid=#{projectUuid,jdbcType=VARCHAR} - -