]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18850 mainBranchProjectUuid refactoring
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Thu, 6 Apr 2023 12:09:50 +0000 (14:09 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 6 Apr 2023 20:03:15 +0000 (20:03 +0000)
13 files changed:
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuidsIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuidsIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-webserver-webapi/src/it/java/org/sonar/server/developers/ws/SearchEventsActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/developers/ws/SearchEventsActionNewIssuesIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/developers/ws/SearchEventsActionQualityGateIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/CreateActionIT.java

index c901b3c8757b2649744a23730d573cc2068ddacb..e6b60e48f58efb59305b0ca1aee9a92538bd6c66 100644 (file)
@@ -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);
index af811e8ec5660c1510d0409bfac1ff4de4c4bda1..9961070a8ed568afafafa082821461800b0bc7d8 100644 (file)
@@ -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);
index 7a34a181f8978b23261432ece58588df11f05d12..51b03356334982c6f17317d736e6e340af1576de 100644 (file)
@@ -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" +
index 68390b461345df67cb0ba5027fa096232b1720d5..2f6d81ff368d85a3d05ce8af21753649ea70d014 100644 (file)
@@ -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
index 9a08ca17b6c087887c5e64df18d72c19d35bb6b7..e5f5acc66c65be3364ea2d95c82b41f1c635c559 100644 (file)
@@ -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()
index 171c524c1a612d56ce199c9c8b19e66a01ec8f48..b636205ca39262f11df16e0dc16e74f8abac23a3 100644 (file)
@@ -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();
index 71dbafe1e4b534fb070611c99ee8c19e7c041279..4a25cfd547f10c16513e4e070884be2b16270da0 100644 (file)
@@ -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.
-   * <p>
-   * Branches are not returned.
-   * <p>
-   * Used by Views.
-   */
-  public List<ComponentDto> selectProjects(DbSession session) {
-    return mapper(session).selectProjects();
-  }
-
   /**
    * Used by Governance
    */
index f9a9b632e94c69201b6aea43ac0966f471d8d2a5..bfa813b64440afba00b2b9f8cce08c23b4635961 100644 (file)
@@ -62,13 +62,6 @@ public interface ComponentMapper {
 
   List<ComponentDto> selectChildren(@Param("branchUuid") String branchUuid, @Param("uuidPaths") Set<String> 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<ComponentDto> selectProjects();
-
   /**
    * Return all descendant views (including itself) from a given root view
    */
index 1f8f072d7cb9d5ab846418bb1d315c1ccee457fa..4f301f249f3d9e9e0027554bd0642fba465c01a6 100644 (file)
       root.uuid=#{projectUuid,jdbcType=VARCHAR}
   </select>
 
-  <select id="selectProjects" resultType="Component">
-    select
-    <include refid="componentColumns"/>
-    from components p
-    where
-      p.enabled=${_true}
-      AND p.scope='PRJ'
-      AND p.qualifier='TRK'
-      AND p.main_branch_project_uuid IS NULL
-  </select>
-
   <select id="selectComponentsByQualifiers" resultType="Component">
     SELECT
     <include refid="componentColumns"/>
index cf69fb1bc2758112fefae56d5d38702a1b617814..d9aea861aa49ab27f1ec897b3885e508987f4404 100644 (file)
@@ -134,7 +134,7 @@ public class SearchEventsActionIT {
     db.events().insertEvent(newQualityGateEvent(projectAnalysis).setDate(projectAnalysis.getCreatedAt()).setName("Passed"));
     insertIssue(project, projectAnalysis);
     insertIssue(project, projectAnalysis);
-    SnapshotDto branchAnalysis = insertAnalysis(branch, 1_501_000_000_000L);
+    SnapshotDto branchAnalysis = insertAnalysis(branch, project.uuid(), 1_501_000_000_000L);
     db.events().insertEvent(newQualityGateEvent(branchAnalysis).setDate(branchAnalysis.getCreatedAt()).setName("Failed"));
     insertIssue(branch, branchAnalysis);
     issueIndexer.indexAllIssues();
@@ -259,11 +259,10 @@ public class SearchEventsActionIT {
     return newEvent(analysis).setCategory(EventCategory.QUALITY_GATE.getLabel());
   }
 
-  private CeActivityDto insertActivity(ComponentDto project, SnapshotDto analysis, CeActivityDto.Status status) {
+  private CeActivityDto insertActivity(String mainBranchUuid, SnapshotDto analysis, CeActivityDto.Status status) {
     CeQueueDto queueDto = new CeQueueDto();
     queueDto.setTaskType(CeTaskTypes.REPORT);
-    String mainBranchProjectUuid = project.getMainBranchProjectUuid();
-    queueDto.setComponentUuid(mainBranchProjectUuid == null ? project.uuid() : mainBranchProjectUuid);
+    queueDto.setComponentUuid(mainBranchUuid);
     queueDto.setUuid(randomAlphanumeric(40));
     queueDto.setCreatedAt(nextLong());
     CeActivityDto activityDto = new CeActivityDto(queueDto);
@@ -283,9 +282,15 @@ public class SearchEventsActionIT {
         .setType(randomRuleTypeExceptHotspot()));
   }
 
+  private SnapshotDto insertAnalysis(ComponentDto branch, String mainBranchUuid, long analysisDate) {
+    SnapshotDto analysis = db.components().insertSnapshot(branch, s -> s.setCreatedAt(analysisDate));
+    insertActivity(mainBranchUuid, analysis, CeActivityDto.Status.SUCCESS);
+    return analysis;
+  }
+
   private SnapshotDto insertAnalysis(ComponentDto project, long analysisDate) {
     SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setCreatedAt(analysisDate));
-    insertActivity(project, analysis, CeActivityDto.Status.SUCCESS);
+    insertActivity(project.uuid(), analysis, CeActivityDto.Status.SUCCESS);
     return analysis;
   }
 
index e316065e97189292b53077ef00d3f9d7119c217d..148521e498900fe3aa384567947055fc98744134 100644 (file)
@@ -175,12 +175,12 @@ public class SearchEventsActionNewIssuesIT {
     userSession.addProjectPermission(USER, project);
     String branchName1 = "branch1";
     ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName1));
-    SnapshotDto branch1Analysis = insertAnalysis(branch1, 1_500_000_000_000L);
+    SnapshotDto branch1Analysis = insertAnalysis(branch1, project.uuid(), 1_500_000_000_000L);
     insertIssue(branch1, branch1Analysis);
     insertIssue(branch1, branch1Analysis);
     String branchName2 = "branch2";
     ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH).setKey(branchName2));
-    SnapshotDto branch2Analysis = insertAnalysis(branch2, 1_300_000_000_000L);
+    SnapshotDto branch2Analysis = insertAnalysis(branch2, project.uuid(), 1_300_000_000_000L);
     insertIssue(branch2, branch2Analysis);
     issueIndexer.indexAllIssues();
 
@@ -211,12 +211,12 @@ public class SearchEventsActionNewIssuesIT {
     userSession.addProjectPermission(USER, project);
     String nonMainBranchName = "nonMain";
     ComponentDto nonMainBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(nonMainBranchName));
-    SnapshotDto nonMainBranchAnalysis = insertAnalysis(nonMainBranch, 1_500_000_000_000L);
+    SnapshotDto nonMainBranchAnalysis = insertAnalysis(nonMainBranch, project.uuid(), 1_500_000_000_000L);
     insertIssue(nonMainBranch, nonMainBranchAnalysis);
     insertIssue(nonMainBranch, nonMainBranchAnalysis);
     String pullRequestKey = "42";
     ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST).setKey(pullRequestKey));
-    SnapshotDto pullRequestAnalysis = insertAnalysis(pullRequest, 1_300_000_000_000L);
+    SnapshotDto pullRequestAnalysis = insertAnalysis(pullRequest, project.uuid(), 1_300_000_000_000L);
     insertIssue(pullRequest, pullRequestAnalysis);
     issueIndexer.indexAllIssues();
 
@@ -285,17 +285,23 @@ public class SearchEventsActionNewIssuesIT {
         .setType(RuleType.SECURITY_HOTSPOT));
   }
 
+
   private SnapshotDto insertAnalysis(ComponentDto project, long analysisDate) {
     SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setCreatedAt(analysisDate));
-    insertActivity(project, analysis, CeActivityDto.Status.SUCCESS);
+    insertActivity(project.uuid(), analysis, CeActivityDto.Status.SUCCESS);
+    return analysis;
+  }
+
+  private SnapshotDto insertAnalysis(ComponentDto branch, String mainBranchUuid, long analysisDate) {
+    SnapshotDto analysis = db.components().insertSnapshot(branch, s -> s.setCreatedAt(analysisDate));
+    insertActivity(mainBranchUuid, analysis, CeActivityDto.Status.SUCCESS);
     return analysis;
   }
 
-  private CeActivityDto insertActivity(ComponentDto project, SnapshotDto analysis, CeActivityDto.Status status) {
+  private CeActivityDto insertActivity(String mainBranchUuid, SnapshotDto analysis, CeActivityDto.Status status) {
     CeQueueDto queueDto = new CeQueueDto();
     queueDto.setTaskType(CeTaskTypes.REPORT);
-    String mainBranchProjectUuid = project.getMainBranchProjectUuid();
-    queueDto.setComponentUuid(mainBranchProjectUuid == null ? project.uuid() : mainBranchProjectUuid);
+    queueDto.setComponentUuid(mainBranchUuid);
     queueDto.setUuid(randomAlphanumeric(40));
     queueDto.setCreatedAt(nextLong());
     CeActivityDto activityDto = new CeActivityDto(queueDto);
index 78603ab0ccd0ead57a51bc15aafbc3cef6ae46fd..aa9181771ac4d2f5647a4712c29100bd4ffe3a64 100644 (file)
@@ -41,7 +41,6 @@ import org.sonarqube.ws.Developers.SearchEventsWsResponse.Event;
 import static java.lang.String.format;
 import static java.lang.String.join;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
-import static org.apache.commons.lang.math.RandomUtils.nextLong;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.tuple;
 import static org.mockito.Mockito.mock;
@@ -63,6 +62,8 @@ public class SearchEventsActionQualityGateIT {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone().logIn();
 
+  private static final long ANY_TIMESTAMP = 1666666666L;
+
   private Server server = mock(Server.class);
   private IssueIndex issueIndex = new IssueIndex(es.client(), null, userSession, null);
   private IssueIndexSyncProgressChecker issueIndexSyncProgressChecker = mock(IssueIndexSyncProgressChecker.class);
@@ -102,7 +103,7 @@ public class SearchEventsActionQualityGateIT {
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
     insertSuccessfulActivity(project, 1_500_000_000_000L);
     SnapshotDto branchAnalysis = insertSuccessfulActivity(branch, 1_500_000_000_000L);
-    insertActivity(branch, branchAnalysis, CeActivityDto.Status.SUCCESS);
+    insertActivity(project.uuid(), branchAnalysis, CeActivityDto.Status.SUCCESS);
     db.events().insertEvent(newQualityGateEvent(branchAnalysis).setDate(branchAnalysis.getCreatedAt()).setName("Failed"));
 
     SearchEventsWsResponse result = ws.newRequest()
@@ -126,7 +127,7 @@ public class SearchEventsActionQualityGateIT {
     ComponentDto project = db.components().insertPrivateProject();
     ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST));
     SnapshotDto prAnalysis = insertSuccessfulActivity(pr, 1_500_000_000_000L);
-    insertActivity(pr, prAnalysis, CeActivityDto.Status.SUCCESS);
+    insertActivity(project.uuid(), prAnalysis, CeActivityDto.Status.SUCCESS);
     db.events().insertEvent(newQualityGateEvent(prAnalysis).setDate(prAnalysis.getCreatedAt()).setName("Failed"));
 
     SearchEventsWsResponse result = ws.newRequest()
@@ -270,21 +271,20 @@ public class SearchEventsActionQualityGateIT {
 
   private SnapshotDto insertSuccessfulActivity(ComponentDto project, long analysisDate) {
     SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setCreatedAt(analysisDate));
-    insertActivity(project, analysis, CeActivityDto.Status.SUCCESS);
+    insertActivity(project.uuid(), analysis, CeActivityDto.Status.SUCCESS);
     return analysis;
   }
 
-  private CeActivityDto insertActivity(ComponentDto project, SnapshotDto analysis, CeActivityDto.Status status) {
+  private CeActivityDto insertActivity(String mainBranchUuid, SnapshotDto analysis, CeActivityDto.Status status) {
     CeQueueDto queueDto = new CeQueueDto();
     queueDto.setTaskType(CeTaskTypes.REPORT);
-    String mainBranchProjectUuid = project.getMainBranchProjectUuid();
-    queueDto.setComponentUuid(mainBranchProjectUuid == null ? project.uuid() : mainBranchProjectUuid);
+    queueDto.setComponentUuid(mainBranchUuid);
     queueDto.setUuid(randomAlphanumeric(40));
-    queueDto.setCreatedAt(nextLong());
+    queueDto.setCreatedAt(ANY_TIMESTAMP);
     CeActivityDto activityDto = new CeActivityDto(queueDto);
     activityDto.setStatus(status);
-    activityDto.setExecutionTimeMs(nextLong());
-    activityDto.setExecutedAt(nextLong());
+    activityDto.setExecutionTimeMs(1000L);
+    activityDto.setExecutedAt(ANY_TIMESTAMP);
     activityDto.setAnalysisUuid(analysis.getUuid());
     db.getDbClient().ceActivityDao().insert(db.getSession(), activityDto);
     db.commit();
index 83043b30284a5dc8dc2b1b8aef0766b22f2fcc9d..366270db444951e21bec3546241e96b49f146dda 100644 (file)
@@ -114,8 +114,8 @@ public class CreateActionIT {
       .containsOnly(DEFAULT_PROJECT_KEY, DEFAULT_PROJECT_NAME, "TRK", "public");
     ComponentDto component = db.getDbClient().componentDao().selectByKey(db.getSession(), DEFAULT_PROJECT_KEY).get();
     assertThat(component)
-      .extracting(ComponentDto::getKey, ComponentDto::name, ComponentDto::qualifier, ComponentDto::scope, ComponentDto::isPrivate, ComponentDto::getMainBranchProjectUuid)
-      .containsOnly(DEFAULT_PROJECT_KEY, DEFAULT_PROJECT_NAME, "TRK", "PRJ", false, null);
+      .extracting(ComponentDto::getKey, ComponentDto::name, ComponentDto::qualifier, ComponentDto::scope, ComponentDto::isPrivate)
+      .containsOnly(DEFAULT_PROJECT_KEY, DEFAULT_PROJECT_NAME, "TRK", "PRJ", false);
 
     assertThat(db.getDbClient().branchDao().selectByUuid(db.getSession(), component.branchUuid()).get())
       .extracting(BranchDto::getKey)