]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19556 Refactor use of DB columns referencing projects or branches for Entities
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 7 Jun 2023 10:30:33 +0000 (12:30 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 20 Jun 2023 13:10:18 +0000 (13:10 +0000)
179 files changed:
server/sonar-ce-common/src/it/java/org/sonar/ce/queue/CeQueueImplIT.java
server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueue.java
server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java
server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeTaskSubmit.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryImplIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/ProjectPersisterIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuidsIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/filemove/PullRequestFileMoveDetectionStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoaderIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/DefaultAssigneeIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInputIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/ScmAccountToUserLoaderIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerIT.java
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/issue/TrackerReferenceBranchInputFactoryIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/TrackerSourceBranchInputFactoryIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/TrackerTargetBranchInputFactoryIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImplIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuidsIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/source/DbLineHashVersionIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/source/PersistFileSourcesStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/CleanIssueChangesStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/EnableAnalysisStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadFileHashesAndStatusStepIT.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/LoadReportAnalysisMetadataHolderStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistPushEventsStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistScannerAnalysisCacheStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistScannerContextStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ProjectNclocComputationStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/UpdateNeedIssueSyncStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/taskprocessor/AuditPurgeStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/taskprocessor/IgnoreOrphanBranchStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/taskprocessor/IndexIssuesStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/branches/ExportBranchesStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/file/ExportLineHashesStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/issue/ExportIssuesChangelogStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportEventsStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportLinksStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMetricsStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportNewCodePeriodsStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/LoadProjectStepIT.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/PersistFileSourcesStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/taskprocessor/IgnoreOrphanBranchStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/issue/ExportIssuesChangelogStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectExportTaskProcessor.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java
server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTask.java
server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java
server/sonar-ce/src/it/java/org/sonar/ce/queue/InternalCeQueueImplIT.java
server/sonar-ce/src/it/java/org/sonar/ce/queue/NextPendingTaskPickerIT.java
server/sonar-ce/src/it/java/org/sonar/ce/taskprocessor/CeWorkerImplIT.java
server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CEQueueStatusImpl.java
server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java
server/sonar-ce/src/main/java/org/sonar/ce/queue/NextPendingTaskPicker.java
server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorkerImpl.java
server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryImplTest.java
server/sonar-db-dao/src/it/java/org/sonar/db/ce/CeActivityDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/ce/CeQueueDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/measure/LiveMeasureDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/measure/MeasureDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/pushevent/PushEventDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateConditionDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateGroupPermissionsDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateUserPermissionsDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/qualityprofile/ActiveRuleDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/qualityprofile/DefaultQProfileDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/qualityprofile/QProfileChangeDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/qualityprofile/QProfileEditUsersDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/qualityprofile/QualityProfileDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/qualityprofile/QualityProfileExportDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/source/FileSourceDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskQuery.java
server/sonar-db-dao/src/main/java/org/sonar/db/ce/PrOrBranchTask.java
server/sonar-db-dao/src/main/java/org/sonar/db/ce/QueueCount.java
server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMainBranchLiveMeasureDto.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDtoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDtoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskQueryTest.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/ce/CeQueueTesting.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivity.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueue.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivityTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueueTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivityTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueueTest/schema.sql [new file with mode: 0644]
server/sonar-server-common/src/test/java/org/sonar/server/webhook/CeTaskTest.java
server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java
server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java
server/sonar-webserver-core/src/test/java/org/sonar/server/issue/index/AsyncIssueIndexingImplTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java
server/sonar-webserver-monitoring/src/main/java/org/sonar/server/monitoring/ce/RecentTasksDurationTask.java
server/sonar-webserver-monitoring/src/test/java/org/sonar/server/monitoring/ce/RecentTasksDurationTaskTest.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/batch/ProjectDataLoaderIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/BranchReportSubmitterIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/ReportSubmitterIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityStatusActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/AnalysisStatusActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ComponentActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/live/LiveMeasureComputerImplIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImplIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateVisibilityActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/projectdump/ws/ExportActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/DeselectActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/SelectActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/SourceServiceIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IndexActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ScmActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/DeleteAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ActivityAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ActivityStatusAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ComponentAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/DeleteAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ce/ws/submit-example.json
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/SubmitActionTest.java

index 12195d1aac85f5a3428862208539fb9049ccb700..32f62b399572a1a9bd74170e523547cbd30e5467 100644 (file)
@@ -39,8 +39,11 @@ import org.sonar.db.DbTester;
 import org.sonar.db.ce.CeActivityDto;
 import org.sonar.db.ce.CeQueueDto;
 import org.sonar.db.ce.CeTaskTypes;
+import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
+import org.sonar.db.entity.EntityDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.db.user.UserTesting;
 import org.sonar.server.platform.NodeInformation;
@@ -55,7 +58,7 @@ import static org.assertj.core.api.Assertions.catchThrowable;
 import static org.assertj.core.api.Assertions.tuple;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
-import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT;
+import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_ENTITY;
 import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_TASK_TYPE;
 
 public class CeQueueImplIT {
@@ -86,18 +89,18 @@ public class CeQueueImplIT {
 
     CeTask task = underTest.submit(taskSubmit);
 
-    verifyCeTask(taskSubmit, task, null, userDto);
+    verifyCeTask(taskSubmit, task, null, null, userDto);
     verifyCeQueueDtoForTaskSubmit(taskSubmit);
   }
 
   @Test
   public void submit_populates_component_name_and_key_of_CeTask_if_component_exists() {
-    ComponentDto componentDto = insertComponent(ComponentTesting.newPrivateProjectDto("PROJECT_1"));
-    CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(componentDto.uuid(), componentDto.uuid()), null);
+    ProjectData projectData = db.components().insertPrivateProject("PROJECT_1");
+    CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(projectData.getMainBranchDto()), null);
 
     CeTask task = underTest.submit(taskSubmit);
 
-    verifyCeTask(taskSubmit, task, componentDto, null);
+    verifyCeTask(taskSubmit, task, projectData.getProjectDto(), projectData.getMainBranchDto(), null);
   }
 
   @Test
@@ -106,7 +109,7 @@ public class CeQueueImplIT {
 
     CeTask task = underTest.submit(taskSubmit);
 
-    verifyCeTask(taskSubmit, task, null, null);
+    verifyCeTask(taskSubmit, task, null, null, null);
   }
 
   @Test
@@ -116,7 +119,7 @@ public class CeQueueImplIT {
 
     CeTask task = underTest.submit(taskSubmit);
 
-    verifyCeTask(taskSubmit, task, null, userDto);
+    verifyCeTask(taskSubmit, task, null, null, userDto);
   }
 
   @Test
@@ -124,7 +127,7 @@ public class CeQueueImplIT {
     CeTaskSubmit taskSubmit = createTaskSubmit("no_component");
     CeQueueDto dto = insertPendingInQueue(null);
 
-    Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+    Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);
 
     assertThat(task).isNotEmpty();
     assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -139,7 +142,7 @@ public class CeQueueImplIT {
     CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
     CeQueueDto dto = insertPendingInQueue(newComponent(otherMainComponentUuid));
 
-    Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+    Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);
 
     assertThat(task).isNotEmpty();
     assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -153,7 +156,7 @@ public class CeQueueImplIT {
     CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
     CeQueueDto dto = insertPendingInQueue(newComponent(mainComponentUuid));
 
-    Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+    Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);
 
     assertThat(task).isEmpty();
     assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -170,7 +173,7 @@ public class CeQueueImplIT {
       .map(CeQueueDto::getUuid)
       .toArray(String[]::new);
 
-    Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+    Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);
 
     assertThat(task).isEmpty();
     assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -235,38 +238,38 @@ public class CeQueueImplIT {
     List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
 
     assertThat(tasks).hasSize(2);
-    verifyCeTask(taskSubmit1, tasks.get(0), null, userDto1);
-    verifyCeTask(taskSubmit2, tasks.get(1), null, null);
+    verifyCeTask(taskSubmit1, tasks.get(0), null, null, userDto1);
+    verifyCeTask(taskSubmit2, tasks.get(1), null, null, null);
     verifyCeQueueDtoForTaskSubmit(taskSubmit1);
     verifyCeQueueDtoForTaskSubmit(taskSubmit2);
   }
 
   @Test
   public void massSubmit_populates_component_name_and_key_of_CeTask_if_project_exists() {
-    ComponentDto componentDto1 = insertComponent(ComponentTesting.newPrivateProjectDto("PROJECT_1"));
-    CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(componentDto1.uuid(), componentDto1.uuid()), null);
+    ProjectData projectData = db.components().insertPrivateProject("PROJECT_1");
+    CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(projectData.getMainBranchDto()), null);
     CeTaskSubmit taskSubmit2 = createTaskSubmit("something", newComponent(randomAlphabetic(12)), null);
 
     List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
 
     assertThat(tasks).hasSize(2);
-    verifyCeTask(taskSubmit1, tasks.get(0), componentDto1, null);
-    verifyCeTask(taskSubmit2, tasks.get(1), null, null);
+    verifyCeTask(taskSubmit1, tasks.get(0), projectData.getProjectDto(), projectData.getMainBranchDto(), null);
+    verifyCeTask(taskSubmit2, tasks.get(1), null, null, null);
   }
 
   @Test
   public void massSubmit_populates_component_name_and_key_of_CeTask_if_project_and_branch_exists() {
-    ComponentDto project = db.components().insertPublicProject(p -> p.setUuid("PROJECT_1").setBranchUuid("PROJECT_1")).getMainBranchComponent();
-    ComponentDto branch1 = db.components().insertProjectBranch(project);
-    ComponentDto branch2 = db.components().insertProjectBranch(project);
-    CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(branch1.uuid(), project.uuid()), null);
-    CeTaskSubmit taskSubmit2 = createTaskSubmit("something", Component.fromDto(branch2.uuid(), project.uuid()), null);
+    ProjectDto project = db.components().insertPublicProject(p -> p.setUuid("PROJECT_1").setBranchUuid("PROJECT_1")).getProjectDto();
+    BranchDto branch1 = db.components().insertProjectBranch(project);
+    BranchDto branch2 = db.components().insertProjectBranch(project);
+    CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(branch1.getUuid(), project.getUuid()), null);
+    CeTaskSubmit taskSubmit2 = createTaskSubmit("something", Component.fromDto(branch2.getUuid(), project.getUuid()), null);
 
     List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
 
     assertThat(tasks).hasSize(2);
-    verifyCeTask(taskSubmit1, tasks.get(0), branch1, project, null);
-    verifyCeTask(taskSubmit2, tasks.get(1), branch2, project, null);
+    verifyCeTask(taskSubmit1, tasks.get(0), project, branch1, null);
+    verifyCeTask(taskSubmit2, tasks.get(1), project, branch2, null);
   }
 
   @Test
@@ -274,7 +277,7 @@ public class CeQueueImplIT {
     CeTaskSubmit taskSubmit = createTaskSubmit("no_component");
     CeQueueDto dto = insertPendingInQueue(null);
 
-    List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+    List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);
 
     assertThat(tasks).hasSize(1);
     assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -289,7 +292,7 @@ public class CeQueueImplIT {
     CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
     CeQueueDto dto = insertPendingInQueue(newComponent(otherMainComponentUuid));
 
-    List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+    List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);
 
     assertThat(tasks).hasSize(1);
     assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -303,7 +306,7 @@ public class CeQueueImplIT {
     CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
     CeQueueDto dto = insertPendingInQueue(newComponent(mainComponentUuid));
 
-    List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+    List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);
 
     assertThat(tasks).isEmpty();
     assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -320,7 +323,7 @@ public class CeQueueImplIT {
       .map(CeQueueDto::getUuid)
       .toArray(String[]::new);
 
-    List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+    List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);
 
     assertThat(tasks).isEmpty();
     assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -382,13 +385,13 @@ public class CeQueueImplIT {
     CeTaskSubmit taskSubmit5 = createTaskSubmit("with_pending_2", newComponent(mainComponentUuid5), null);
     CeQueueDto dto5 = insertPendingInQueue(newComponent(mainComponentUuid5));
 
-    List<CeTask> tasks = underTest.massSubmit(of(taskSubmit1, taskSubmit2, taskSubmit3, taskSubmit4, taskSubmit5), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+    List<CeTask> tasks = underTest.massSubmit(of(taskSubmit1, taskSubmit2, taskSubmit3, taskSubmit4, taskSubmit5), UNIQUE_QUEUE_PER_ENTITY);
 
     assertThat(tasks)
       .hasSize(2)
-      .extracting(task -> task.getComponent().get().getUuid(), task -> task.getMainComponent().get().getUuid())
-      .containsOnly(tuple(componentForMainComponentUuid2.getUuid(), componentForMainComponentUuid2.getMainComponentUuid()),
-        tuple(componentForMainComponentUuid4.getUuid(), componentForMainComponentUuid4.getMainComponentUuid()));
+      .extracting(task -> task.getComponent().get().getUuid(), task -> task.getEntity().get().getUuid())
+      .containsOnly(tuple(componentForMainComponentUuid2.getUuid(), componentForMainComponentUuid2.getEntityUuid()),
+        tuple(componentForMainComponentUuid4.getUuid(), componentForMainComponentUuid4.getEntityUuid()));
     assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
       .extracting(CeQueueDto::getUuid)
       .hasSize(1 + uuids3.length + 1 + tasks.size())
@@ -565,31 +568,27 @@ public class CeQueueImplIT {
       .hasMessage("Task is not in-progress and can't be marked as failed [uuid=" + task.getUuid() + "]");
   }
 
-  private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable ComponentDto componentDto, UserDto userDto) {
-    verifyCeTask(taskSubmit, task, componentDto, componentDto, userDto);
-  }
-
-  private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable ComponentDto componentDto, @Nullable ComponentDto mainComponentDto, @Nullable UserDto userDto) {
+  private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable EntityDto entityDto, @Nullable BranchDto branch, @Nullable UserDto userDto) {
     assertThat(task.getUuid()).isEqualTo(taskSubmit.getUuid());
-    if (componentDto != null) {
+    if (branch != null) {
       CeTask.Component component = task.getComponent().get();
-      assertThat(component.getUuid()).isEqualTo(componentDto.uuid());
-      assertThat(component.getKey()).contains(componentDto.getKey());
-      assertThat(component.getName()).contains(componentDto.name());
+      assertThat(component.getUuid()).isEqualTo(branch.getUuid());
+      assertThat(component.getKey()).contains(entityDto.getKey());
+      assertThat(component.getName()).contains(entityDto.getName());
     } else if (taskSubmit.getComponent().isPresent()) {
       assertThat(task.getComponent()).contains(new CeTask.Component(taskSubmit.getComponent().get().getUuid(), null, null));
     } else {
       assertThat(task.getComponent()).isEmpty();
     }
-    if (mainComponentDto != null) {
-      CeTask.Component component = task.getMainComponent().get();
-      assertThat(component.getUuid()).isEqualTo(mainComponentDto.uuid());
-      assertThat(component.getKey()).contains(mainComponentDto.getKey());
-      assertThat(component.getName()).contains(mainComponentDto.name());
+    if (entityDto != null) {
+      CeTask.Component component = task.getEntity().get();
+      assertThat(component.getUuid()).isEqualTo(entityDto.getUuid());
+      assertThat(component.getKey()).contains(entityDto.getKey());
+      assertThat(component.getName()).contains(entityDto.getName());
     } else if (taskSubmit.getComponent().isPresent()) {
-      assertThat(task.getMainComponent()).contains(new CeTask.Component(taskSubmit.getComponent().get().getMainComponentUuid(), null, null));
+      assertThat(task.getEntity()).contains(new CeTask.Component(taskSubmit.getComponent().get().getEntityUuid(), null, null));
     } else {
-      assertThat(task.getMainComponent()).isEmpty();
+      assertThat(task.getEntity()).isEmpty();
     }
     assertThat(task.getType()).isEqualTo(taskSubmit.getType());
     if (taskSubmit.getSubmitterUuid() != null) {
@@ -610,7 +609,7 @@ public class CeQueueImplIT {
     Optional<Component> component = taskSubmit.getComponent();
     if (component.isPresent()) {
       assertThat(queueDto.get().getComponentUuid()).isEqualTo(component.get().getUuid());
-      assertThat(queueDto.get().getMainComponentUuid()).isEqualTo(component.get().getMainComponentUuid());
+      assertThat(queueDto.get().getEntityUuid()).isEqualTo(component.get().getEntityUuid());
     } else {
       assertThat(queueDto.get().getComponentUuid()).isNull();
       assertThat(queueDto.get().getComponentUuid()).isNull();
@@ -653,7 +652,7 @@ public class CeQueueImplIT {
       .setStatus(CeQueueDto.Status.PENDING);
     if (component != null) {
       dto.setComponentUuid(component.getUuid())
-        .setMainComponentUuid(component.getMainComponentUuid());
+        .setEntityUuid(component.getEntityUuid());
     }
     db.getDbClient().ceQueueDao().insert(db.getSession(), dto);
     db.commit();
index adee3c00e93789cdfb85cf7db826abbde74426a9..f0333f07beae8839b1b2966839df68a9488c2cc5 100644 (file)
@@ -59,7 +59,7 @@ public interface CeQueue {
    * <p>
    * This method is equivalent to calling {@code massSubmit(Collections.singletonList(submission))}.
    *
-   * @return empty if {@code options} contains {@link SubmitOption#UNIQUE_QUEUE_PER_MAIN_COMPONENT UNIQUE_QUEUE_PER_MAIN_COMPONENT}
+   * @return empty if {@code options} contains {@link SubmitOption#UNIQUE_QUEUE_PER_ENTITY UNIQUE_QUEUE_PER_MAIN_COMPONENT}
    *         and there's already a queued task, otherwise the created task.
    */
   Optional<CeTask> submit(CeTaskSubmit submission, SubmitOption... options);
@@ -124,7 +124,7 @@ public interface CeQueue {
   int clear();
 
   enum SubmitOption {
-    UNIQUE_QUEUE_PER_MAIN_COMPONENT,
+    UNIQUE_QUEUE_PER_ENTITY,
     UNIQUE_QUEUE_PER_TASK_TYPE
   }
 
index 88b77baec5c0e9f44a0d0a9a639c45da8737eb5c..0a78e1a58041ad6b0471ff447d73322a6de01ad8 100644 (file)
@@ -32,7 +32,6 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.sonar.api.server.ServerSide;
@@ -49,15 +48,15 @@ import org.sonar.db.ce.CeTaskCharacteristicDto;
 import org.sonar.db.ce.CeTaskQuery;
 import org.sonar.db.ce.DeleteIf;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.entity.EntityDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.platform.NodeInformation;
 import org.sonar.server.property.InternalProperties;
 
 import static com.google.common.base.Preconditions.checkState;
-import static java.util.Collections.emptyMap;
 import static java.util.Collections.singleton;
 import static java.util.Optional.ofNullable;
-import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT;
+import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_ENTITY;
 import static org.sonar.core.util.stream.MoreCollectors.toEnumSet;
 import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
 import static org.sonar.db.ce.CeQueueDto.Status.IN_PROGRESS;
@@ -105,14 +104,14 @@ public class CeQueueImpl implements CeQueue {
     CeTaskQuery query = new CeTaskQuery();
     for (SubmitOption option : submitOptions) {
       switch (option) {
-        case UNIQUE_QUEUE_PER_MAIN_COMPONENT -> submission.getComponent()
-          .flatMap(component -> Optional.ofNullable(component.getMainComponentUuid()))
-          .ifPresent(mainComponentUuid -> query.setMainComponentUuid(mainComponentUuid).setStatuses(List.of(PENDING.name())));
+        case UNIQUE_QUEUE_PER_ENTITY -> submission.getComponent()
+          .flatMap(component -> Optional.ofNullable(component.getEntityUuid()))
+          .ifPresent(entityUuid -> query.setEntityUuid(entityUuid).setStatuses(List.of(PENDING.name())));
         case UNIQUE_QUEUE_PER_TASK_TYPE -> query.setType(submission.getType());
       }
     }
 
-    boolean queryNonEmpty = query.getMainComponentUuids() != null || query.getStatuses() != null || query.getType() != null;
+    boolean queryNonEmpty = query.getEntityUuids() != null || query.getStatuses() != null || query.getType() != null;
     if (queryNonEmpty && dbClient.ceQueueDao().countByQuery(dbSession, query) > 0) {
       return Optional.empty();
     }
@@ -121,26 +120,22 @@ public class CeQueueImpl implements CeQueue {
   }
 
   private CeTask convertQueueDtoToTask(DbSession dbSession, CeQueueDto queueDto, CeTaskSubmit submission) {
-    Map<String, ComponentDto> componentsByUuid = loadComponentDtos(dbSession, queueDto);
-    if (componentsByUuid.isEmpty()) {
-      return convertToTask(dbSession, queueDto, submission.getCharacteristics(), null, null);
-    }
-    return convertToTask(dbSession, queueDto, submission.getCharacteristics(),
-      ofNullable(queueDto.getComponentUuid()).map(componentsByUuid::get).orElse(null),
-      ofNullable(queueDto.getMainComponentUuid()).map(componentsByUuid::get).orElse(null));
+    return convertToTask(dbSession, queueDto, submission.getCharacteristics());
   }
 
-  Map<String, ComponentDto> loadComponentDtos(DbSession dbSession, CeQueueDto taskDto) {
-    Set<String> componentUuids = Stream.of(taskDto.getComponentUuid(), taskDto.getMainComponentUuid())
-      .filter(Objects::nonNull)
-      .collect(MoreCollectors.toSet(2));
-    if (componentUuids.isEmpty()) {
-      return emptyMap();
+  protected CeTask convertToTask(DbSession dbSession, CeQueueDto queueDto, Map<String, String> characteristicDto) {
+    ComponentDto component = null;
+    EntityDto entity = null;
+
+    if (queueDto.getComponentUuid() != null) {
+      component = dbClient.componentDao().selectByUuid(dbSession, queueDto.getComponentUuid()).orElse(null);
     }
+    if (queueDto.getEntityUuid() != null) {
+      entity = dbClient.entityDao().selectByUuid(dbSession, queueDto.getEntityUuid()).orElse(null);
+    }
+
+    return convertToTask(dbSession, queueDto, characteristicDto, component, entity);
 
-    return dbClient.componentDao().selectByUuids(dbSession, componentUuids)
-      .stream()
-      .collect(uniqueIndex(ComponentDto::uuid, 2));
   }
 
   @Override
@@ -163,12 +158,12 @@ public class CeQueueImpl implements CeQueue {
   private Predicate<CeTaskSubmit> filterBySubmitOptions(SubmitOption[] options, Collection<CeTaskSubmit> submissions, DbSession dbSession) {
     EnumSet<SubmitOption> submitOptions = toSet(options);
 
-    if (submitOptions.contains(UNIQUE_QUEUE_PER_MAIN_COMPONENT)) {
+    if (submitOptions.contains(UNIQUE_QUEUE_PER_ENTITY)) {
       Set<String> mainComponentUuids = submissions.stream()
         .map(CeTaskSubmit::getComponent)
         .filter(Optional::isPresent)
         .map(Optional::get)
-        .map(CeTaskSubmit.Component::getMainComponentUuid)
+        .map(CeTaskSubmit.Component::getEntityUuid)
         .collect(MoreCollectors.toSet(submissions.size()));
       if (mainComponentUuids.isEmpty()) {
         return t -> true;
@@ -183,13 +178,13 @@ public class CeQueueImpl implements CeQueue {
     private final Map<String, Integer> queuedItemsByMainComponentUuid;
 
     private NoPendingTaskFilter(DbSession dbSession, Set<String> projectUuids) {
-      queuedItemsByMainComponentUuid = dbClient.ceQueueDao().countByStatusAndMainComponentUuids(dbSession, PENDING, projectUuids);
+      queuedItemsByMainComponentUuid = dbClient.ceQueueDao().countByStatusAndEntityUuids(dbSession, PENDING, projectUuids);
     }
 
     @Override
     public boolean test(CeTaskSubmit ceTaskSubmit) {
       return ceTaskSubmit.getComponent()
-        .map(component -> queuedItemsByMainComponentUuid.getOrDefault(component.getMainComponentUuid(), 0) == 0)
+        .map(component -> queuedItemsByMainComponentUuid.getOrDefault(component.getEntityUuid(), 0) == 0)
         .orElse(true);
     }
   }
@@ -217,7 +212,7 @@ public class CeQueueImpl implements CeQueue {
     dto.setTaskType(submission.getType());
     submission.getComponent().ifPresent(component -> dto
       .setComponentUuid(component.getUuid())
-      .setMainComponentUuid(component.getMainComponentUuid()));
+      .setEntityUuid(component.getEntityUuid()));
     dto.setStatus(PENDING);
     dto.setSubmitterUuid(submission.getSubmitterUuid());
     dbClient.ceQueueDao().insert(dbSession, dto);
@@ -228,12 +223,16 @@ public class CeQueueImpl implements CeQueue {
   private List<CeTask> loadTasks(DbSession dbSession, List<CeQueueDto> dtos) {
     // load components, if defined
     Set<String> componentUuids = dtos.stream()
-      .flatMap(dto -> Stream.of(dto.getComponentUuid(), dto.getMainComponentUuid()))
+      .map(CeQueueDto::getComponentUuid)
       .filter(Objects::nonNull)
       .collect(Collectors.toSet());
+    // these components correspond to a branch or a portfolio (analysis target)
     Map<String, ComponentDto> componentsByUuid = dbClient.componentDao()
       .selectByUuids(dbSession, componentUuids).stream()
       .collect(uniqueIndex(ComponentDto::uuid));
+    Set<String> entityUuids = dtos.stream().map(CeQueueDto::getEntityUuid).filter(Objects::nonNull).collect(Collectors.toSet());
+    Map<String, EntityDto> entitiesByUuid = dbClient.entityDao().selectByUuids(dbSession, entityUuids).stream()
+      .collect(Collectors.toMap(EntityDto::getUuid, e -> e));
 
     // load characteristics
     // TODO could be avoided, characteristics are already present in submissions
@@ -247,12 +246,12 @@ public class CeQueueImpl implements CeQueue {
       ComponentDto component = ofNullable(dto.getComponentUuid())
         .map(componentsByUuid::get)
         .orElse(null);
-      ComponentDto mainComponent = ofNullable(dto.getMainComponentUuid())
-        .map(componentsByUuid::get)
+      EntityDto entity = ofNullable(dto.getEntityUuid())
+        .map(entitiesByUuid::get)
         .orElse(null);
       Map<String, String> characteristics = characteristicsByTaskUuid.get(dto.getUuid()).stream()
         .collect(uniqueIndex(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
-      result.add(convertToTask(dbSession, dto, characteristics, component, mainComponent));
+      result.add(convertToTask(dbSession, dto, characteristics, component, entity));
     }
     return result;
   }
@@ -366,7 +365,7 @@ public class CeQueueImpl implements CeQueue {
     return cancelAll(true);
   }
 
-  CeTask convertToTask(DbSession dbSession, CeQueueDto taskDto, Map<String, String> characteristics, @Nullable ComponentDto component, @Nullable ComponentDto mainComponent) {
+  CeTask convertToTask(DbSession dbSession, CeQueueDto taskDto, Map<String, String> characteristics, @Nullable ComponentDto component, @Nullable EntityDto entity) {
     CeTask.Builder builder = new CeTask.Builder()
       .setUuid(taskDto.getUuid())
       .setType(taskDto.getTaskType())
@@ -380,11 +379,11 @@ public class CeQueueImpl implements CeQueue {
       builder.setComponent(new CeTask.Component(componentUuid, null, null));
     }
 
-    String mainComponentUuid = taskDto.getMainComponentUuid();
-    if (mainComponent != null) {
-      builder.setMainComponent(new CeTask.Component(mainComponent.uuid(), mainComponent.getKey(), mainComponent.name()));
-    } else if (mainComponentUuid != null) {
-      builder.setMainComponent(new CeTask.Component(mainComponentUuid, null, null));
+    String entityUuid = taskDto.getEntityUuid();
+    if (entity != null) {
+      builder.setEntity(new CeTask.Component(entity.getUuid(), entity.getKey(), entity.getName()));
+    } else if (entityUuid != null) {
+      builder.setEntity(new CeTask.Component(entityUuid, null, null));
     }
 
     return builder.build();
index a6e45798323615c491b07197e2aaaa96a039e6f5..a9749b01fe6499673d0635db1b0257e2820791c1 100644 (file)
@@ -27,7 +27,6 @@ import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
 import org.sonar.db.component.BranchDto;
 import org.sonar.db.portfolio.PortfolioDto;
-import org.sonar.db.project.ProjectDto;
 
 import static com.google.common.base.Strings.emptyToNull;
 import static com.google.common.base.Strings.nullToEmpty;
@@ -116,20 +115,16 @@ public final class CeTaskSubmit {
   }
 
   public static class Component {
-    private String uuid;
-    private String mainComponentUuid;
+    private final String uuid;
+    private final String entityUuid;
 
-    public Component(String uuid, String mainComponentUuid) {
+    public Component(String uuid, String entityUuid) {
       this.uuid = requireNonNull(nullToEmpty(uuid), "uuid can't be null");
-      this.mainComponentUuid = requireNonNull(nullToEmpty(mainComponentUuid), "mainComponentUuid can't be null");
-    }
-
-    public static Component fromDto(String componentUuid, String mainComponentUuid) {
-      return new Component(componentUuid, mainComponentUuid);
+      this.entityUuid = requireNonNull(nullToEmpty(entityUuid), "mainComponentUuid can't be null");
     }
 
-    public static Component fromDto(ProjectDto dto) {
-      return new Component(dto.getUuid(), dto.getUuid());
+    public static Component fromDto(String componentUuid, String entityUuid) {
+      return new Component(componentUuid, entityUuid);
     }
 
     public static Component fromDto(PortfolioDto dto) {
@@ -140,23 +135,19 @@ public final class CeTaskSubmit {
       return new Component(dto.getUuid(), dto.getProjectUuid());
     }
 
-    public static Component fromProjectUuid(String projectUuid) {
-      return new Component(projectUuid, projectUuid);
-    }
-
     public String getUuid() {
       return uuid;
     }
 
-    public String getMainComponentUuid() {
-      return mainComponentUuid;
+    public String getEntityUuid() {
+      return entityUuid;
     }
 
     @Override
     public String toString() {
       return "Component{" +
         "uuid='" + uuid + '\'' +
-        ", mainComponentUuid='" + mainComponentUuid + '\'' +
+        ", entityUuid='" + entityUuid + '\'' +
         '}';
     }
 
@@ -169,12 +160,12 @@ public final class CeTaskSubmit {
         return false;
       }
       Component component = (Component) o;
-      return uuid.equals(component.uuid) && mainComponentUuid.equals(component.mainComponentUuid);
+      return uuid.equals(component.uuid) && entityUuid.equals(component.entityUuid);
     }
 
     @Override
     public int hashCode() {
-      return Objects.hash(uuid, mainComponentUuid);
+      return Objects.hash(uuid, entityUuid);
     }
   }
 }
index d6cdfd6b6828160626de6e14e530968aaf964c21..be5265cecf4491f9c5fd145453e796c4ad76e2a9 100644 (file)
@@ -63,7 +63,7 @@ public class BranchPersisterImplIT {
   @Rule
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
 
index 6da6104b03880a48e10b87eec033b94977b75f0e..7e911f1a09a68791f04c2249bf8523231f8943f0 100644 (file)
@@ -39,7 +39,7 @@ public class ComponentUuidFactoryImplIT {
   private final Branch mockedBranch = mock(Branch.class);
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
 
   @Test
   public void getOrCreateForKey_when_existingComponentsInDbForMainBranch_should_load() {
index 23e06bc3a77911e304e997b9c00eebfc3ab9ff1e..729c85f9f7e56885ecf8ed685997a596f5513fb3 100644 (file)
@@ -48,7 +48,7 @@ public class ProjectPersisterIT {
   @Rule
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
   public TestSystem2 system2 = new TestSystem2();
@@ -74,8 +74,8 @@ public class ProjectPersisterIT {
 
   @Test
   public void update_description() {
-    ProjectDto p1 = dbTester.components().insertPublicProject(
-      c -> c.setUuid("PROJECT_UUID").setKey(ROOT.getKey()).setName(ROOT.getName()).setDescription("OLD_DESC")).getProjectDto();
+    ProjectDto p1 = dbTester.components().insertPublicProject("PROJECT_UUID",
+      p -> p.setKey(ROOT.getKey()).setName(ROOT.getName()).setDescription("OLD_DESC")).getProjectDto();
 
     assertProject("OLD_DESC", ROOT.getName(), p1.getUpdatedAt());
     underTest.persist(dbTester.getSession());
@@ -84,8 +84,8 @@ public class ProjectPersisterIT {
 
   @Test
   public void update_name() {
-    ProjectDto p1 = dbTester.components().insertPublicProject(
-      c -> c.setUuid("PROJECT_UUID").setKey(ROOT.getKey()).setName("OLD_NAME").setDescription(ROOT.getDescription())).getProjectDto();
+    ProjectDto p1 = dbTester.components().insertPublicProject("PROJECT_UUID",
+      p -> p.setKey(ROOT.getKey()).setName("OLD_NAME").setDescription(ROOT.getDescription())).getProjectDto();
 
     assertProject(ROOT.getDescription(), "OLD_NAME", p1.getUpdatedAt());
     underTest.persist(dbTester.getSession());
index e899db1ea635532c9dbea8cb65c0206b483a9d4c..fbced257b75878b353d53dd5f925cc6eb23dc07b 100644 (file)
@@ -40,7 +40,7 @@ public class ReferenceBranchComponentUuidsIT {
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
 
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
 
   private ReferenceBranchComponentUuids underTest;
   private Branch branch = mock(Branch.class);
index 98d4c7880bc98f834ea7d0da85f587574b220e1f..d2129bcbfd238b34cf5cc52f0a2f45df9431e24a 100644 (file)
@@ -45,7 +45,7 @@ public class SiblingComponentsWithOpenIssuesIT {
   public AnalysisMetadataHolderRule metadataHolder = new AnalysisMetadataHolderRule();
 
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
 
   private SiblingComponentsWithOpenIssues underTest;
 
index 6a83f4ce017c391b097bd80ad3f8e04ef24184df..4efa02ec5f03e9e9d668092a3f5a6d772b1f1dff 100644 (file)
@@ -219,7 +219,7 @@ public class FileMoveDetectionStepIT {
   @Rule
   public MutableMovedFilesRepositoryRule movedFilesRepository = new MutableMovedFilesRepositoryRule();
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public LogTester logTester = new LogTester();
 
index 3effd77ae17b273102a056ac7cb68bd20b673e2f..82c7809cca7a4bec09d905bd917b8b9628b6e073 100644 (file)
@@ -45,6 +45,8 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.source.FileSourceDto;
 import org.sonar.server.project.Project;
 
@@ -84,12 +86,13 @@ public class PullRequestFileMoveDetectionStepIT {
   @Rule
   public MutableMovedFilesRepositoryRule movedFilesRepository = new MutableMovedFilesRepositoryRule();
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public LogTester logTester = new LogTester();
 
   private ComponentDto branch;
-  private ComponentDto project;
+  private ComponentDto mainBranch;
+  private ProjectDto project;
 
   private final DbClient dbClient = dbTester.getDbClient();
   private final AnalysisMetadataHolderRule analysisMetadataHolder = mock(AnalysisMetadataHolderRule.class);
@@ -98,9 +101,11 @@ public class PullRequestFileMoveDetectionStepIT {
 
   @Before
   public void setUp() throws Exception {
-    project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    branch = dbTester.components().insertProjectBranch(project, branchDto -> branchDto.setUuid(BRANCH_UUID).setKey(TARGET_BRANCH));
-    treeRootHolder.setRoot(builder(Component.Type.PROJECT, Integer.parseInt(ROOT_REF)).setUuid(project.uuid()).build());
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    mainBranch = projectData.getMainBranchComponent();
+    project = projectData.getProjectDto();
+    branch = dbTester.components().insertProjectBranch(mainBranch, branchDto -> branchDto.setUuid(BRANCH_UUID).setKey(TARGET_BRANCH));
+    treeRootHolder.setRoot(builder(Component.Type.PROJECT, Integer.parseInt(ROOT_REF)).setUuid(mainBranch.uuid()).build());
   }
 
   @Test
@@ -285,7 +290,7 @@ public class PullRequestFileMoveDetectionStepIT {
   private void insertFileComponentsInReport(Set<Component> files) {
     treeRootHolder
       .setRoot(builder(PROJECT, Integer.parseInt(ROOT_REF))
-      .setUuid(project.uuid())
+      .setUuid(mainBranch.uuid())
       .addChildren(files.toArray(Component[]::new))
       .build());
   }
@@ -306,7 +311,7 @@ public class PullRequestFileMoveDetectionStepIT {
 
   private ComponentDto composeComponentDto(String uuid) {
     return ComponentTesting
-      .newFileDto(project)
+      .newFileDto(mainBranch)
       .setBranchUuid(branch.uuid())
       .setKey("key_" + uuid)
       .setUuid(uuid)
index df05ba8d26832a77d64e61738c7358499e238fd0..65d9b253d0ec35ad236851441c4e7e7973ea2c1c 100644 (file)
@@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class AdHocRuleCreatorIT {
 
   @org.junit.Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
   @org.junit.Rule
   public EsTester es = EsTester.create();
 
index 96e634feadc5676dd61bdd0fc09375f6b16dd8da..2278482e1ffb8c3482cf653dc74561147fd12341 100644 (file)
@@ -69,7 +69,7 @@ public class ComponentIssuesLoaderIT {
   private static final Date DATE_LIMIT_30_DAYS_BACK_MIDNIGHT = parseDateTime("2018-07-18T00:00:00+0000");
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
 
   private final DbClient dbClient = db.getDbClient();
   private final System2 system2 = mock(System2.class);
index e7b36137021538a51374e40f0add15f9dcb1c659..d6494aa8910c163a3600c10f1fc0016228900a4c 100644 (file)
@@ -36,7 +36,7 @@ public class DefaultAssigneeIT {
   public static final String PROJECT_KEY = "PROJECT_KEY";
 
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
 
   private final MapSettings settings = new MapSettings();
   private final ConfigurationRepository settingsRepository = new TestSettingsRepository(settings.asConfig());
index fd2da91f154c7ed1aa7e0c92cace6d96b9307487..38ef3e334bfc8684819383caf25b1f95429c0983 100644 (file)
@@ -103,7 +103,7 @@ public class IntegrateIssuesVisitorIT {
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
   @Rule
index a2b3e3db5cfaddf675e69b3570c9486ea4367053..f6bce05a1073a5ba46fd9376d57298528d25b7f8 100644 (file)
@@ -48,7 +48,7 @@ public class ProjectTrackerBaseLazyInputIT {
   @Rule
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule().setAnalysisDate(ANALYSIS_DATE);
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public ActiveRulesHolderRule activeRulesHolderRule = new ActiveRulesHolderRule();
   @Rule
index 86d15f426d21b9297b9672986619e25c41b2db2f..a65dbf661b331abb86a2280dcae631db699fdce6 100644 (file)
@@ -36,7 +36,7 @@ import static org.junit.Assert.fail;
 public class ScmAccountToUserLoaderIT {
 
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
   @Rule
   public EsTester es = EsTester.create();
   @Rule
index a44ffda6cd1b9679486a0a2442c53452bcc4a4d9..95800f5a6f908f44a3f1a5bb487ff14836f0c02e 100644 (file)
@@ -62,7 +62,7 @@ public class SiblingsIssueMergerIT {
   private final Branch branch = mock(Branch.class);
 
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
 
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule()
index ac0780a87db17131dc071524d48d82c284877494..7267983e3fcfcbb024c6016897d03ff4284d022d 100644 (file)
@@ -28,6 +28,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.protobuf.DbProjectBranches;
 import org.sonar.server.project.Project;
 
@@ -45,7 +46,7 @@ public class SourceBranchComponentUuidsIT {
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
 
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
 
   private SourceBranchComponentUuids underTest;
   private final Branch branch = mock(Branch.class);
@@ -60,8 +61,9 @@ public class SourceBranchComponentUuidsIT {
     analysisMetadataHolder.setProject(project);
     analysisMetadataHolder.setBranch(branch);
 
-    ComponentDto projectDto = db.components().insertPublicProject().getMainBranchComponent();
-    when(project.getUuid()).thenReturn(projectDto.uuid());
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto projectDto = projectData.getMainBranchComponent();
+    when(project.getUuid()).thenReturn(projectData.projectUuid());
     branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey(BRANCH_KEY));
     ComponentDto pr1branch = db.components().insertProjectBranch(projectDto, b -> b.setKey(PR_KEY)
       .setBranchType(BranchType.PULL_REQUEST)
index 14800d42f6402eced023ea7bec84d2b68744a05b..ff9788baf3ddba896b14c098bf3045f3343f8503 100644 (file)
@@ -28,6 +28,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.protobuf.DbProjectBranches;
 import org.sonar.server.project.Project;
 
@@ -44,7 +45,7 @@ public class TargetBranchComponentUuidsIT {
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
 
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
 
   private TargetBranchComponentUuids underTest;
   private final Branch branch = mock(Branch.class);
@@ -59,13 +60,14 @@ public class TargetBranchComponentUuidsIT {
     analysisMetadataHolder.setProject(project);
     analysisMetadataHolder.setBranch(branch);
 
-    ComponentDto projectDto = db.components().insertPublicProject().getMainBranchComponent();
-    when(project.getUuid()).thenReturn(projectDto.uuid());
-    branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey(BRANCH_KEY));
-    ComponentDto pr1branch = db.components().insertProjectBranch(projectDto, b -> b.setKey(PR_KEY)
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto mainBranch = projectData.getMainBranchComponent();
+    when(project.getUuid()).thenReturn(projectData.projectUuid());
+    branch1 = db.components().insertProjectBranch(mainBranch, b -> b.setKey(BRANCH_KEY));
+    ComponentDto pr1branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey(PR_KEY)
       .setBranchType(BranchType.PULL_REQUEST)
       .setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setTarget(BRANCH_KEY).build())
-      .setMergeBranchUuid(projectDto.uuid()));
+      .setMergeBranchUuid(mainBranch.uuid()));
     branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File");
     pr1File = ComponentTesting.newFileDto(pr1branch, null, "file").setUuid("file1");
     db.components().insertComponents(branch1File, pr1File);
index 916a98c57144f9f2cbdd7e080f1f8350cdb0da4d..a361edd235e8c6674a5baad42d08ee740e04afa4 100644 (file)
@@ -40,7 +40,7 @@ public class TrackerReferenceBranchInputFactoryIT {
   private final static String COMPONENT_UUID = "uuid1";
 
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
 
   private ComponentIssuesLoader componentIssuesLoader = mock(ComponentIssuesLoader.class);
   private ReferenceBranchComponentUuids referenceBranchComponentUuids = mock(ReferenceBranchComponentUuids.class);
index 6cf56ee40fbd2e103ed688c5c57c0bfb6b3a9633..89bcb79c356a57ddc030df1cff015caa99750bf1 100644 (file)
@@ -39,7 +39,7 @@ public class TrackerSourceBranchInputFactoryIT {
   private final static String COMPONENT_UUID = "uuid1";
 
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
 
   private final ComponentIssuesLoader componentIssuesLoader = mock(ComponentIssuesLoader.class);
   private final SourceBranchComponentUuids sourceBranchComponentUuids = mock(SourceBranchComponentUuids.class);
index 6bbebc16b2e334bec6cefef82c601fcf01eda7f4..bd1a2eb80a62e4ff614dd1805067a393efd8deaa 100644 (file)
@@ -44,7 +44,7 @@ public class TrackerTargetBranchInputFactoryIT {
   private final static String ORIGINAL_COMPONENT_UUID = "uuid2";
 
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
 
   private final ComponentIssuesLoader componentIssuesLoader = mock(ComponentIssuesLoader.class);
   private final TargetBranchComponentUuids targetBranchComponentUuids = mock(TargetBranchComponentUuids.class);
index 5412d9a16f9dd2e96129bd665f0e77cb02dbd6d7..c9027fed4e31a8f4ccff2822a5aefaffdcbf4343 100644 (file)
@@ -67,7 +67,7 @@ public class MeasureRepositoryImplIT {
 
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public BatchReportReaderRule reportReader = new BatchReportReaderRule();
 
index 5f0aecb379a4204510ce6ec443d64c6d26260426..189eb10d7b4c1d42b9dd146ec7e243b7d360ba5f 100644 (file)
@@ -38,7 +38,7 @@ public class MetricRepositoryImplIT {
   private static final String SOME_UUID = "uuid";
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   private DbClient dbClient = dbTester.getDbClient();
   private MetricRepositoryImpl underTest = new MetricRepositoryImpl(dbClient);
index cfd395fb7c2c8d6bed6deb55adaf221b46559d26..e3d8a739c520769d829dc7abe219cd3e051b2778 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.newcodeperiod.NewCodePeriodType;
 import org.sonar.server.project.Project;
 
@@ -43,7 +44,7 @@ public class NewCodeReferenceBranchComponentUuidsIT {
   @Rule
   public PeriodHolderRule periodHolder = new PeriodHolderRule();
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
 
   private NewCodeReferenceBranchComponentUuids underTest = new NewCodeReferenceBranchComponentUuids(analysisMetadataHolder, periodHolder, db.getDbClient());
 
@@ -61,12 +62,12 @@ public class NewCodeReferenceBranchComponentUuidsIT {
   public void setUp() {
     analysisMetadataHolder.setProject(project);
 
-    ComponentDto projectDto = db.components().insertPublicProject().getMainBranchComponent();
-    when(project.getUuid()).thenReturn(projectDto.uuid());
-    branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey("branch1"));
-    branch2 = db.components().insertProjectBranch(projectDto, b -> b.setKey("branch2"));
-    pr1 = db.components().insertProjectBranch(projectDto, b -> b.setKey("pr1").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
-    pr2 = db.components().insertProjectBranch(projectDto, b -> b.setKey("pr2").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
+    ProjectData projectData = db.components().insertPublicProject();
+    when(project.getUuid()).thenReturn(projectData.projectUuid());
+    branch1 = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("branch1"));
+    branch2 = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("branch2"));
+    pr1 = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("pr1").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
+    pr2 = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("pr2").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
     branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File");
     branch2File = ComponentTesting.newFileDto(branch2, null, "file").setUuid("branch2File");
     pr1File = ComponentTesting.newFileDto(pr1, null, "file").setUuid("file1");
index c647e7f5bace75d8d52d8ddb78621eb3f75dd190..17d60e3010c82fad7307ecbb2a36c1882e8658a7 100644 (file)
@@ -69,7 +69,7 @@ public class ScmInfoDbLoaderIT {
   @Rule
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public BatchReportReaderRule reportReader = new BatchReportReaderRule();
   @Rule
index 3a11cf9fc7681ee353dc68aed3062e0447860d80..b7d7a1b061f72d2a1f69822aefe60fea2a9f39cd 100644 (file)
@@ -37,11 +37,11 @@ import static org.mockito.Mockito.when;
 
 public class DbLineHashVersionIT {
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
 
-  private AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class);
-  private ReferenceBranchComponentUuids referenceBranchComponentUuids = mock(ReferenceBranchComponentUuids.class);
-  private DbLineHashVersion underTest = new DbLineHashVersion(db.getDbClient(), analysisMetadataHolder, referenceBranchComponentUuids);
+  private final AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class);
+  private final ReferenceBranchComponentUuids referenceBranchComponentUuids = mock(ReferenceBranchComponentUuids.class);
+  private final DbLineHashVersion underTest = new DbLineHashVersion(db.getDbClient(), analysisMetadataHolder, referenceBranchComponentUuids);
 
   @Test
   public void hasLineHashWithSignificantCode_should_return_true() {
index eb795c894ed56456b3309cefcba622fa875948ee..0a2c41239c29b4140090bb7afd56b208a9871557 100644 (file)
@@ -66,7 +66,7 @@ public class PersistFileSourcesStepIT extends BaseStepTest {
   private final System2 system2 = mock(System2.class);
 
   @Rule
-  public DbTester dbTester = DbTester.create(system2);
+  public DbTester dbTester = DbTester.create(system2, true);
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
 
index 568abd860bb9f415f6e161427aad9d0a1ce12f06..4850fe1d361fdd517451291a005c67016638350a 100644 (file)
@@ -86,7 +86,7 @@ public class BuildComponentTreeStepIT {
   private static final long ANALYSIS_DATE = 123456789L;
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public BatchReportReaderRule reportReader = new BatchReportReaderRule().setMetadata(createReportMetadata(NO_SCANNER_PROJECT_VERSION, NO_SCANNER_BUILD_STRING));
   @Rule
index 7911b15ac401623d167125e3643db0e6efd22852..45cb83cc282368ddf0901cc19a1ba85d9632174c 100644 (file)
@@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class CleanIssueChangesStepIT {
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
   private final IssueChangesToDeleteRepository repository = new IssueChangesToDeleteRepository();
   private final CleanIssueChangesStep cleanIssueChangesStep = new CleanIssueChangesStep(repository, db.getDbClient());
   private final TestComputationStepContext context = new TestComputationStepContext();
index e96c977b34dcf0b62d7facca4fc66c4ecfb3dbe1..f92e394c9b4e66e6f14aa8b67557391cfcbb983c 100644 (file)
@@ -43,7 +43,7 @@ public class EnableAnalysisStepIT {
   private static final String CURRENT_ANALYSIS_UUID = "ANALYSIS_2";
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
 
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
index ed2499f48ae05d9b6acefd6a61756ffb1c968f3b..73365564da5ab81174b78500a157e7f49aa3bb29 100644 (file)
@@ -55,7 +55,7 @@ public class ExtractReportStepIT {
 
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   private MutableBatchReportDirectoryHolder reportDirectoryHolder = new BatchReportDirectoryHolderImpl();
   private CeTask ceTask = new CeTask.Builder()
index 1db962d0d157a34f89f34261c7687d2e3571a3ef..613c40d17e37dbcd1e37b42eda7a2905ad6d2c54 100644 (file)
@@ -89,7 +89,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepIT {
   private CrossProjectDuplicationStatusHolder crossProjectDuplicationStatusHolder = mock(CrossProjectDuplicationStatusHolder.class);
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   private DbClient dbClient = dbTester.getDbClient();
   private DbSession dbSession = dbTester.getSession();
index a81d08fab7450a391230d7eb447b112583e35aad..2f9c470a280368b91d65c1cfb96096ddfe773f32 100644 (file)
@@ -43,7 +43,7 @@ import static org.mockito.Mockito.when;
 
 public class LoadFileHashesAndStatusStepIT {
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
   public PreviousSourceHashRepositoryImpl previousFileHashesRepository = new PreviousSourceHashRepositoryImpl();
index 3b603c1c0559dbab5dcfdc175b1d7b4941cf35ae..768822c55b13f6456b134c48fd53870ca8305ee6 100644 (file)
@@ -76,7 +76,7 @@ import static org.sonar.db.event.EventTesting.newEvent;
 @RunWith(DataProviderRunner.class)
 public class LoadPeriodsStepIT extends BaseStepTest {
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
   @Rule
index 4abac1ca8f5d02e53f7cb1a6732bbbf7b92e36de..543b2874d46e02a60de1d926f3be4fec0c8f3f6e 100644 (file)
@@ -44,6 +44,7 @@ import org.sonar.core.platform.PluginRepository;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.server.project.DefaultBranchNameResolver;
 import org.sonar.server.project.Project;
@@ -62,7 +63,7 @@ public class LoadReportAnalysisMetadataHolderStepIT {
   private static final long ANALYSIS_DATE = 123456789L;
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
   @Rule
   public BatchReportReaderRule reportReader = new BatchReportReaderRule();
   @Rule
@@ -70,14 +71,14 @@ public class LoadReportAnalysisMetadataHolderStepIT {
 
   private final DbClient dbClient = db.getDbClient();
   private final TestPluginRepository pluginRepository = new TestPluginRepository();
-  private ComponentDto project;
+  private ProjectDto project;
   private ComputationStep underTest;
 
   @Before
   public void setUp() {
     CeTask defaultOrgCeTask = createCeTask(PROJECT_KEY);
     underTest = createStep(defaultOrgCeTask);
-    project = db.components().insertPublicProject(p -> p.setKey(PROJECT_KEY)).getMainBranchComponent();
+    project = db.components().insertPublicProject(p -> p.setKey(PROJECT_KEY)).getProjectDto();
   }
 
   @Test
@@ -127,10 +128,10 @@ public class LoadReportAnalysisMetadataHolderStepIT {
     underTest.execute(new TestComputationStepContext());
 
     Project project = analysisMetadataHolder.getProject();
-    assertThat(project.getUuid()).isEqualTo(this.project.uuid());
+    assertThat(project.getUuid()).isEqualTo(this.project.getUuid());
     assertThat(project.getKey()).isEqualTo(this.project.getKey());
-    assertThat(project.getName()).isEqualTo(this.project.name());
-    assertThat(project.getDescription()).isEqualTo(this.project.description());
+    assertThat(project.getName()).isEqualTo(this.project.getName());
+    assertThat(project.getDescription()).isEqualTo(this.project.getDescription());
   }
 
   @Test
@@ -186,14 +187,14 @@ public class LoadReportAnalysisMetadataHolderStepIT {
     CeTask res = mock(CeTask.class);
     Optional<CeTask.Component> component = Optional.of(new CeTask.Component("main_prj_uuid", null, null));
     when(res.getComponent()).thenReturn(component);
-    when(res.getMainComponent()).thenReturn(component);
+    when(res.getEntity()).thenReturn(component);
     reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build());
 
     ComputationStep underTest = createStep(res);
 
     assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext()))
       .isInstanceOf(MessageException.class)
-      .hasMessage("Compute Engine task main component key is null. Project with UUID main_prj_uuid must have been deleted since report was uploaded. Can not proceed.");
+      .hasMessage("Compute Engine task entity key is null. Project with UUID main_prj_uuid must have been deleted since report was uploaded. Can not proceed.");
   }
 
   @Test
@@ -201,7 +202,7 @@ public class LoadReportAnalysisMetadataHolderStepIT {
     CeTask res = mock(CeTask.class);
     Optional<CeTask.Component> component = Optional.of(new CeTask.Component("prj_uuid", null, null));
     when(res.getComponent()).thenReturn(component);
-    when(res.getMainComponent()).thenReturn(Optional.of(new CeTask.Component("main_prj_uuid", "main_prj_key", null)));
+    when(res.getEntity()).thenReturn(Optional.of(new CeTask.Component("main_prj_uuid", "main_prj_key", null)));
     reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build());
 
     ComputationStep underTest = createStep(res);
@@ -308,9 +309,10 @@ public class LoadReportAnalysisMetadataHolderStepIT {
 
   private CeTask createCeTask(String projectKey) {
     CeTask res = mock(CeTask.class);
-    Optional<CeTask.Component> component = Optional.of(new CeTask.Component(projectKey + "_uuid", projectKey, projectKey + "_name"));
+    Optional<CeTask.Component> entity = Optional.of(new CeTask.Component(projectKey + "_uuid", projectKey, projectKey + "_name"));
+    Optional<CeTask.Component> component = Optional.of(new CeTask.Component(projectKey + "branch_uuid", projectKey, projectKey + "_name"));
     when(res.getComponent()).thenReturn(component);
-    when(res.getMainComponent()).thenReturn(component);
+    when(res.getEntity()).thenReturn(entity);
     return res;
   }
 
index 85319db11870a27f8750943dc7cd21d816ce7723..70c999b7947185fe9ce5e5986fcbb96fabc947b1 100644 (file)
@@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class PersistAdHocRulesStepIT extends BaseStepTest {
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
 
   private DbClient dbClient = db.getDbClient();
 
index 0430fa3d8a343c91093647b0fa863cf24c34c78e..104214d686a771588dbe74d33624df1246838644 100644 (file)
@@ -64,7 +64,7 @@ public class PersistAnalysisPropertiesStepIT {
   private static final String SCM_REV_ID = "sha1";
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   private BatchReportReader batchReportReader = mock(BatchReportReader.class);
   private AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class);
index 003826e72ab27966a11a40e09bb9813355a16f30..5b09bf11a8bd60bf121d275db3bff9c718327f91 100644 (file)
@@ -69,7 +69,7 @@ public class PersistCrossProjectDuplicationIndexStepIT {
   private static final String BASE_ANALYSIS_UUID = "base analysis uuid";
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public BatchReportReaderRule reportReader = new BatchReportReaderRule();
   @Rule
index 169fe2696a0381513ea2acb45ed2f36f90a9b685..d1dc1027bfe72d8eeeb6724ffc25a3ea01972884 100644 (file)
@@ -59,7 +59,7 @@ public class PersistDuplicationDataStepIT extends BaseStepTest {
   private static final String FILE_2_UUID = "u3";
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule()
     .setRoot(
index 49afbd06a902a42901739e3f17c5f5896fcd400d..cdc42a8f8edbf78b81938035e6051485e2dc5a18 100644 (file)
@@ -77,7 +77,7 @@ public class PersistEventsStepIT extends BaseStepTest {
   System2 system2 = mock(System2.class);
 
   @Rule
-  public DbTester dbTester = DbTester.create(system2);
+  public DbTester dbTester = DbTester.create(system2, true);
   @Rule
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
   @Rule
index 4c97694f98bdc2f0c8eb5a31c1d0f50d33f1065f..dc14115141021fad059c23a8fd89ebc2ec956a1c 100644 (file)
@@ -80,7 +80,7 @@ public class PersistIssuesStepIT extends BaseStepTest {
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
   @Rule
   public BatchReportReaderRule reportReader = new BatchReportReaderRule();
   @Rule
index f4829de256fa15436674b62870593ea8b9b07f7d..6f39071550a1827ed852b404e3953b44d2fd6a18 100644 (file)
@@ -73,7 +73,7 @@ public class PersistLiveMeasuresStepIT extends BaseStepTest {
   private static final int REF_4 = 4;
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
   @Rule
index 6064b72700d3a4f0dfdef9f7e36511d9c7f1a99a..055c9376af172ad983caa4d492a60df540c5dd24 100644 (file)
@@ -64,7 +64,7 @@ public class PersistMeasuresStepIT extends BaseStepTest {
   private static final int REF_4 = 4;
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
   @Rule
index ea448818e2993d744a3d3c9ae1db79897e968cb3..5f35be876107a3bc561d86a9032ba63b9f477ef6 100644 (file)
@@ -58,7 +58,7 @@ public class PersistProjectLinksStepIT extends BaseStepTest {
   @Rule
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
   @Rule
index 5d06b6ea3de5374044b8e5baeae99e54f9f25bc8..c6c198340670492251cee1da50ecf89e1f95e68c 100644 (file)
@@ -55,7 +55,7 @@ public class PersistPushEventsStepIT {
   private final TestSystem2 system2 = new TestSystem2().setNow(1L);
 
   @Rule
-  public DbTester db = DbTester.create(system2);
+  public DbTester db = DbTester.create(system2, true);
 
   public final PushEventFactory pushEventFactory = mock(PushEventFactory.class);
   @Rule
@@ -143,7 +143,7 @@ public class PersistPushEventsStepIT {
 
   @Test
   public void store_push_events_for_branch() {
-    var project = db.components().insertPrivateProject().getMainBranchComponent();
+    var project = db.components().insertPrivateProject().getProjectDto();
     db.components().insertProjectBranch(project, b -> b.setUuid("uuid_1"));
 
     protoIssueCache.newAppender()
@@ -155,7 +155,7 @@ public class PersistPushEventsStepIT {
         .setComponentKey("ck2"))
       .close();
 
-    when(pushEventFactory.raiseEventOnIssue(eq(project.uuid()), any(DefaultIssue.class))).thenReturn(
+    when(pushEventFactory.raiseEventOnIssue(eq(project.getUuid()), any(DefaultIssue.class))).thenReturn(
       Optional.of(createPushEvent()),
       Optional.of(createPushEvent()));
 
index b55016055cc489fd73ae85d7956e6e1b1999fc94..33be7c2539d59d8b046d3c180edd5814d3755dd1 100644 (file)
@@ -41,7 +41,7 @@ public class PersistScannerAnalysisCacheStepIT {
   @Rule
   public BatchReportReaderRule reader = new BatchReportReaderRule();
   @Rule
-  public DbTester dbTester = DbTester.create();
+  public DbTester dbTester = DbTester.create(true);
   private final DbClient client = dbTester.getDbClient();
   private final TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
   private final PersistScannerAnalysisCacheStep step = new PersistScannerAnalysisCacheStep(reader, dbTester.getDbClient(), treeRootHolder);
index d85d967f1036d56c98dd97b6a27a7219a886539c..75ffd3be6a2531ea055f07833bf8b8c88bd9c7d1 100644 (file)
@@ -42,7 +42,7 @@ public class PersistScannerContextStepIT {
   private static final String ANALYSIS_UUID = "UUID";
 
   @ClassRule
-  public static final DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public static final DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   @Rule
   public BatchReportReaderRule reportReader = new BatchReportReaderRule();
index 16f47518a2aa80d19ad03585a13317c1602b3315..86f55ee584c97116f804260373f27eb95cc638af 100644 (file)
@@ -25,9 +25,11 @@ import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
 import org.sonar.ce.task.step.TestComputationStepContext;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.metric.MetricDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.server.project.Project;
 
 import static java.util.Collections.emptyList;
@@ -36,7 +38,7 @@ import static org.sonar.api.measures.Metric.ValueType.INT;
 
 public class ProjectNclocComputationStepIT {
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
   private final DbClient dbClient = db.getDbClient();
 
   @Rule
@@ -47,12 +49,12 @@ public class ProjectNclocComputationStepIT {
   @Test
   public void test_computing_branch_ncloc() {
     MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString()));
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
+    ProjectDto project = db.components().insertPublicProject().getProjectDto();
+    BranchDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
     db.measures().insertLiveMeasure(branch1, ncloc, m -> m.setValue(200d));
-    ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
+    BranchDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
     db.measures().insertLiveMeasure(branch2, ncloc, m -> m.setValue(10d));
-    analysisMetadataHolder.setProject(new Project(project.uuid(), project.getKey(), project.name(), project.description(), emptyList()));
+    analysisMetadataHolder.setProject(new Project(project.getUuid(), project.getKey(), project.getName(), project.getDescription(), emptyList()));
     step.execute(TestComputationStepContext.TestStatistics::new);
 
     assertThat(dbClient.projectDao().getNclocSum(db.getSession())).isEqualTo(200L);
index 0bdeef19ed90616c8bf8ed96e14a88698b9944d2..47412e095b3e0a29ad3ca8f09c522a08109b23d7 100644 (file)
@@ -54,7 +54,7 @@ public class ReportPersistAnalysisStepIT extends BaseStepTest {
   private static final String REVISION_ID = "5f6432a1";
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
   @Rule
index 7dd7d3449c901f1dbddf4eb754ed95b2aab004f2..2875e742dcbb1c46e689bd950bf05cea66c74d34 100644 (file)
@@ -67,7 +67,7 @@ public class ReportPersistComponentsStepIT extends BaseStepTest {
   private static final String PROJECT_KEY = "PROJECT_KEY";
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
   @Rule
index c048f544747c61698c4a496d25c9c5bfb9c0d825..2c80401f8d81742fe95c3a0ec5167dd85f52329c 100644 (file)
@@ -134,7 +134,7 @@ public class SendIssueNotificationsStepIT extends BaseStepTest {
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
 
   private final Random random = new Random();
   private final RuleType[] RULE_TYPES_EXCEPT_HOTSPOTS = Stream.of(RuleType.values()).filter(r -> r != SECURITY_HOTSPOT).toArray(RuleType[]::new);
index 99ef5311432e537f9d5aa954e3804b301eb3a56b..ec67cdc0a7641acf9a096839f969e9feeb706550 100644 (file)
@@ -37,7 +37,7 @@ public class UpdateNeedIssueSyncStepIT {
   private static final Component PROJECT = ReportComponent.DUMB_PROJECT;
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
 
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule().setRoot(PROJECT);
index 69bcb33dbb22396d784c97b91f6a8550b506d6fb..aac33312e66238a26a11a7d9997fcbb1f448af78 100644 (file)
@@ -58,7 +58,7 @@ public class UpdateQualityProfilesLastUsedDateStepIT {
 
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
 
   @Rule
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule().setAnalysisDate(ANALYSIS_DATE);
index bdb526425057dd0ad644ae313d66f8cdecf3d43f..ca99be5ec18d752f3a83568a4f37a2732378a0c6 100644 (file)
@@ -52,7 +52,7 @@ public class ValidateProjectStepIT {
   static final Branch DEFAULT_BRANCH = new DefaultBranchImpl(DEFAULT_MAIN_BRANCH_NAME);
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
   @Rule
index 3d0ab973fc8afed6d86755b2c94d57bcb9aaa01b..5f93479a6a580ad434e9f100020b9ad9b0fc3ff6 100644 (file)
@@ -53,7 +53,7 @@ public class ViewsPersistAnalysisStepIT extends BaseStepTest {
   private static final String ANALYSIS_UUID = "U1";
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
   @Rule
index c55441a7fc7093a5cbf15f3be1503cf8b957efc2..bf19e21ea040149c39fbd2c35abb42847ac1c299 100644 (file)
@@ -80,7 +80,7 @@ public class ViewsPersistComponentsStepIT extends BaseStepTest {
   private static final String PROJECT_VIEW_1_UUID = "PV1_UUID";
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
index e24e30454ca49dddd34cfec721ffa3e6a147d859..683dc2e9cd421358e82cf034f68f52b9622c1735 100644 (file)
@@ -51,14 +51,14 @@ public class AuditPurgeStepIT {
     .setValue(MONTHLY.name());
 
   @Rule
-  public final DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public final DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   private final DbClient dbClient = dbTester.getDbClient();
 
   private final System2 system2 = new System2();
 
   @Rule
-  public final DbTester db = DbTester.create(system2);
+  public final DbTester db = DbTester.create(system2, true);
 
   private final AuditHousekeepingFrequencyHelper auditHousekeepingFrequencyHelper = mock(AuditHousekeepingFrequencyHelper.class);
 
index 9bb14e07ee9d5f8d7f99fbe98c900ae28782b13b..79eeea41d04b901c8e922af64dc006661e0af06c 100644 (file)
@@ -33,22 +33,23 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.sonar.db.component.BranchType.BRANCH;
 
 public class IgnoreOrphanBranchStepIT {
-
-  private String BRANCH_UUID = "branch_uuid";
+  private final String ENTITY_UUID = "entity_uuid";
+  private final String BRANCH_UUID = "branch_uuid";
 
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
-  private CeTask.Component component = new CeTask.Component(BRANCH_UUID, "component key", "component name");
-  private CeTask ceTask = new CeTask.Builder()
+  private final CeTask.Component entity = new CeTask.Component(ENTITY_UUID, "component key", "component name");
+  private final CeTask.Component component = new CeTask.Component(BRANCH_UUID, "component key", "component name");
+  private final CeTask ceTask = new CeTask.Builder()
     .setType("type")
     .setUuid("uuid")
     .setComponent(component)
-    .setMainComponent(component)
+    .setEntity(entity)
     .build();
 
-  private DbClient dbClient = dbTester.getDbClient();
-  private IgnoreOrphanBranchStep underTest = new IgnoreOrphanBranchStep(ceTask, dbClient);
+  private final DbClient dbClient = dbTester.getDbClient();
+  private final IgnoreOrphanBranchStep underTest = new IgnoreOrphanBranchStep(ceTask, dbClient);
 
   @Test
   public void execute() {
@@ -94,13 +95,13 @@ public class IgnoreOrphanBranchStepIT {
       .setType("type")
       .setUuid("uuid")
       .setComponent(null)
-      .setMainComponent(null)
+      .setEntity(null)
       .build();
     IgnoreOrphanBranchStep underTest = new IgnoreOrphanBranchStep(ceTask, dbClient);
 
     assertThatThrownBy(() -> underTest.execute(() -> null))
       .isInstanceOf(UnsupportedOperationException.class)
-      .hasMessage("main component not found in task");
+      .hasMessage("entity not found in task");
   }
 
   @Test
index fbd85186c05c307c1f4447733be11b4fa23c7bf4..fe3cbb234b5f3f3f61317a5d556d0e5693514aef 100644 (file)
@@ -38,32 +38,27 @@ import static org.mockito.Mockito.verify;
 import static org.sonar.db.component.BranchType.BRANCH;
 
 public class IndexIssuesStepIT {
-
-  private String BRANCH_UUID = "branch_uuid";
-
+  private final String ENTITY_UUID = "entity_uuid";
+  private final String BRANCH_UUID = "branch_uuid";
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
-  private DbClient dbClient = dbTester.getDbClient();
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
-  private CeTask.Component component = new CeTask.Component(BRANCH_UUID, "component key", "component name");
-  private CeTask ceTask = new CeTask.Builder()
+  private final DbClient dbClient = dbTester.getDbClient();
+  private final CeTask.Component entity = new CeTask.Component(ENTITY_UUID, "component key", "component name");
+  private final CeTask.Component component = new CeTask.Component(BRANCH_UUID, "component key", "component name");
+  private final CeTask ceTask = new CeTask.Builder()
     .setType("type")
     .setUuid("uuid")
     .setComponent(component)
-    .setMainComponent(component)
+    .setEntity(entity)
     .build();
 
   @Rule
   public EsTester es = EsTester.create();
-  private System2 system2 = new System2();
-  @Rule
-  public DbTester db = DbTester.create(system2);
-
-  private IssueIndexer issueIndexer = mock(IssueIndexer.class);
 
-  private IndexIssuesStep underTest = new IndexIssuesStep(ceTask, dbClient, issueIndexer);
+  private final IssueIndexer issueIndexer = mock(IssueIndexer.class);
+  private final IndexIssuesStep underTest = new IndexIssuesStep(ceTask, dbClient, issueIndexer);
 
   @Test
   public void execute() {
@@ -107,7 +102,7 @@ public class IndexIssuesStepIT {
       .setType("type")
       .setUuid("uuid")
       .setComponent(null)
-      .setMainComponent(null)
+      .setEntity(null)
       .build();
     IndexIssuesStep underTest = new IndexIssuesStep(ceTask, dbClient, issueIndexer);
 
index eebf642d89c41db0f916130a76865ac5f6413982..6c96fe0ac008270d44f6fb3807ad2b3be9525090 100644 (file)
@@ -96,7 +96,7 @@ public class ExportAnalysesStepIT {
     .setBranchUuid(PROJECT_UUID);
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public LogTester logTester = new LogTester();
 
index cd0864a80d4c8ba2092988d798d47d4237e31341..662525f15e3081f3f0478824f62ad2f2cc498150 100644 (file)
@@ -42,6 +42,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.project.ProjectExportMapper;
 
 import static java.util.stream.Collectors.toMap;
@@ -53,20 +54,9 @@ import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
 
 public class ExportBranchesStepIT {
   private static final String PROJECT_UUID = "PROJECT_UUID";
-  private static final ComponentDto PROJECT = new ComponentDto()
-    // no id yet
-    .setScope(Scopes.PROJECT)
-    .setQualifier(Qualifiers.PROJECT)
-    .setKey("the_project")
-    .setName("The Project")
-    .setDescription("The project description")
-    .setEnabled(true)
-    .setUuid(PROJECT_UUID)
-    .setUuidPath(UUID_PATH_OF_ROOT)
-    .setBranchUuid(PROJECT_UUID);
 
   @Rule
-  public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, ProjectExportMapper.class);
+  public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, true, ProjectExportMapper.class);
   @Rule
   public LogTester logTester = new LogTester();
 
@@ -109,13 +99,13 @@ public class ExportBranchesStepIT {
   public void setUp() {
     logTester.setLevel(Level.DEBUG);
     Date createdAt = new Date();
-    ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT).getMainBranchComponent().setCreatedAt(createdAt);
+    ProjectData projectData = dbTester.components().insertPublicProject(PROJECT_UUID);
     for (BranchDto branch : branches) {
       createdAt = DateUtils.addMinutes(createdAt, 10);
-      dbTester.components().insertProjectBranch(PROJECT, branch).setCreatedAt(createdAt);
+      dbTester.components().insertProjectBranch(projectData.getProjectDto(), branch).setCreatedAt(createdAt);
     }
     dbTester.commit();
-    when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDtoByMainBranch(projectDto));
+    when(projectHolder.projectDto()).thenReturn(projectData.getProjectDto());
   }
 
   @Test
@@ -127,7 +117,7 @@ public class ExportBranchesStepIT {
       .stream()
       .collect(toMap(ProjectDump.Branch::getUuid, Function.identity()));
     assertThat(branches).hasSize(3);
-    ProjectDump.Branch mainBranch = branches.get(PROJECT_UUID);
+    ProjectDump.Branch mainBranch = branches.values().stream().filter(ProjectDump.Branch::getIsMain).findFirst().get();
     assertThat(mainBranch).isNotNull();
     assertThat(mainBranch.getKee()).isEqualTo(BranchDto.DEFAULT_MAIN_BRANCH_NAME);
     assertThat(mainBranch.getProjectUuid()).isEqualTo(PROJECT_UUID);
index 67a2285b2f5e21e420263bc63ef113b5c997aae0..dd9913cca8a2ab63e883376703c0ef7acb806c84 100644 (file)
@@ -78,7 +78,7 @@ public class ExportComponentsStepIT {
     .setBranchUuid(PROJECT_UUID);
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public LogTester logTester = new LogTester();
 
index 6ca08fc528b052039e70eaace5a46666e60433f8..6e63b776cc31eb2a7ced2d324a4ee08def3ca1fc 100644 (file)
@@ -55,16 +55,15 @@ public class ExportLineHashesStepIT {
   private static final String FILE_UUID_2 = "file-2-uuid";
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public LogTester logTester = new LogTester();
 
-  private DbClient dbClient = dbTester.getDbClient();
-  private DbSession dbSession = dbClient.openSession(false);
-  private FakeDumpWriter dumpWriter = new FakeDumpWriter();
-  private MutableComponentRepository componentRepository = new ComponentRepositoryImpl();
-
-  private ExportLineHashesStep underTest = new ExportLineHashesStep(dbClient, dumpWriter, componentRepository);
+  private final DbClient dbClient = dbTester.getDbClient();
+  private final DbSession dbSession = dbClient.openSession(false);
+  private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
+  private final MutableComponentRepository componentRepository = new ComponentRepositoryImpl();
+  private final ExportLineHashesStep underTest = new ExportLineHashesStep(dbClient, dumpWriter, componentRepository);
 
   @Before
   public void before() {
index 4a6726298292f0105978ee8250fa1391f8f9c03d..94ff9c8d49d7de0a47738b942a03df3fa0c26364 100644 (file)
@@ -39,11 +39,11 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.BranchType;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.issue.IssueChangeDto;
 import org.sonar.db.issue.IssueDto;
+import org.sonar.db.project.ProjectDto;
 
-import static com.google.common.collect.Lists.newArrayList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
@@ -63,7 +63,7 @@ public class ExportIssuesChangelogStepIT {
   private static final String ISSUE_CLOSED_UUID = "issue closed uuid";
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public LogTester logTester = new LogTester();
 
@@ -73,21 +73,22 @@ public class ExportIssuesChangelogStepIT {
   private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
   private final ExportIssuesChangelogStep underTest = new ExportIssuesChangelogStep(dbClient, projectHolder, dumpWriter);
 
+  private BranchDto mainBranch;
   private int issueChangeUuidGenerator = 0;
 
   @Before
   public void setUp() {
     logTester.setLevel(Level.DEBUG);
-    ComponentDto projectDto = dbTester.components().insertPublicProject(p -> p.setUuid(PROJECT_UUID)).getMainBranchComponent();
-    when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDtoByMainBranch(projectDto));
-    when(projectHolder.branches()).thenReturn(newArrayList(
-      new BranchDto().setBranchType(BranchType.BRANCH).setKey("master").setProjectUuid(PROJECT_UUID).setUuid(PROJECT_UUID)));
-
-    insertIssue(PROJECT_UUID, ISSUE_OPEN_UUID, STATUS_OPEN);
-    insertIssue(PROJECT_UUID, ISSUE_CONFIRMED_UUID, STATUS_CONFIRMED);
-    insertIssue(PROJECT_UUID, ISSUE_REOPENED_UUID, STATUS_REOPENED);
-    insertIssue(PROJECT_UUID, ISSUE_RESOLVED_UUID, STATUS_RESOLVED);
-    insertIssue(PROJECT_UUID, ISSUE_CLOSED_UUID, STATUS_CLOSED);
+    ProjectData projectData = dbTester.components().insertPublicProject(PROJECT_UUID);
+    mainBranch = projectData.getMainBranchDto();
+    when(projectHolder.projectDto()).thenReturn(projectData.getProjectDto());
+    when(projectHolder.branches()).thenReturn(List.of(mainBranch));
+
+    insertIssue(mainBranch.getUuid(), ISSUE_OPEN_UUID, STATUS_OPEN);
+    insertIssue(mainBranch.getUuid(), ISSUE_CONFIRMED_UUID, STATUS_CONFIRMED);
+    insertIssue(mainBranch.getUuid(), ISSUE_REOPENED_UUID, STATUS_REOPENED);
+    insertIssue(mainBranch.getUuid(), ISSUE_RESOLVED_UUID, STATUS_RESOLVED);
+    insertIssue(mainBranch.getUuid(), ISSUE_CLOSED_UUID, STATUS_CLOSED);
   }
 
   @After
@@ -145,7 +146,7 @@ public class ExportIssuesChangelogStepIT {
       .setChangeType("change type")
       .setUserUuid("user_uuid")
       .setIssueChangeCreationDate(454135L)
-      .setProjectUuid(PROJECT_UUID);
+      .setProjectUuid(mainBranch.getUuid());
     insertIssueChange(issueChangeDto);
 
     underTest.execute(new TestComputationStepContext());
@@ -193,7 +194,7 @@ public class ExportIssuesChangelogStepIT {
 
   @Test
   public void execute_sets_createAt_to_zero_if_both_createdAt_and_issueChangeDate_are_null() {
-    insertIssueChange(new IssueChangeDto().setUuid(Uuids.createFast()).setIssueKey(ISSUE_REOPENED_UUID).setProjectUuid(PROJECT_UUID));
+    insertIssueChange(new IssueChangeDto().setUuid(Uuids.createFast()).setIssueKey(ISSUE_REOPENED_UUID).setProjectUuid(mainBranch.getUuid()));
 
     underTest.execute(new TestComputationStepContext());
 
@@ -262,10 +263,10 @@ public class ExportIssuesChangelogStepIT {
     return dto;
   }
 
-  private void insertIssue(String projectUuid, String uuid, String status) {
+  private void insertIssue(String branchUuid, String uuid, String status) {
     IssueDto dto = new IssueDto()
       .setKee(uuid)
-      .setProjectUuid(projectUuid)
+      .setProjectUuid(branchUuid)
       .setStatus(status);
     dbClient.issueDao().insert(dbSession, dto);
     dbSession.commit();
index af669dcc2601f9be64d805b43c63016696120318..93e23a07e274658ed1b28f76883b1a24953d202c 100644 (file)
@@ -83,7 +83,7 @@ public class ExportIssuesStepIT {
   public static final DbIssues.MessageFormatting MESSAGE_FORMATTING = DbIssues.MessageFormatting.newBuilder().setStart(0).setEnd(4).setType(MessageFormattingType.CODE).build();
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public LogTester logTester = new LogTester();
 
index d68b74e7cc57146c13e387546c6a1c3c5c2d61c3..6b4bd209228f741ebb69ffbcc1b391a96452655d 100644 (file)
@@ -44,6 +44,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.db.rule.RuleDto;
@@ -56,19 +57,6 @@ import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
 
 public class ExportAdHocRulesStepIT {
   private static final String PROJECT_UUID = "some-uuid";
-
-  private static final ComponentDto PROJECT = new ComponentDto()
-    // no id yet
-    .setScope(Scopes.PROJECT)
-    .setQualifier(Qualifiers.PROJECT)
-    .setKey("the_project")
-    .setName("The Project")
-    .setDescription("The project description")
-    .setEnabled(true)
-    .setUuid(PROJECT_UUID)
-    .setUuidPath(UUID_PATH_OF_ROOT)
-    .setBranchUuid(PROJECT_UUID);
-
   private static final List<BranchDto> BRANCHES = ImmutableList.of(
     new BranchDto().setBranchType(BranchType.PULL_REQUEST).setProjectUuid(PROJECT_UUID).setKey("pr-1").setUuid("pr-1-uuid").setMergeBranchUuid("master").setIsMain(false),
     new BranchDto().setBranchType(BranchType.BRANCH).setProjectUuid(PROJECT_UUID).setKey("branch-2").setUuid("branch-2-uuid").setMergeBranchUuid("master")
@@ -78,14 +66,14 @@ public class ExportAdHocRulesStepIT {
 
   @Rule
   public LogTester logTester = new LogTester();
-
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   private int issueUuidGenerator = 1;
-  private FakeDumpWriter dumpWriter = new FakeDumpWriter();
-  private ProjectHolder projectHolder = mock(ProjectHolder.class);
-  private ExportAdHocRulesStep underTest = new ExportAdHocRulesStep(dbTester.getDbClient(), projectHolder, dumpWriter);
+  private ComponentDto mainBranch;
+  private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
+  private final ProjectHolder projectHolder = mock(ProjectHolder.class);
+  private final ExportAdHocRulesStep underTest = new ExportAdHocRulesStep(dbTester.getDbClient(), projectHolder, dumpWriter);
 
   @Before
   public void setup() {
@@ -110,7 +98,7 @@ public class ExportAdHocRulesStepIT {
     RuleDto rule2 = insertAddHocRule( "rule-2");
     insertAddHocRule( "rule-3");
     insertIssue(rule1, differentProject, differentProject);
-    insertIssue(rule2, PROJECT_UUID, PROJECT_UUID);
+    insertIssue(rule2, mainBranch.uuid(), mainBranch.uuid());
 
     underTest.execute(new TestComputationStepContext());
 
@@ -125,9 +113,9 @@ public class ExportAdHocRulesStepIT {
     RuleDto rule1 = insertStandardRule("rule-1");
     RuleDto rule2 = insertExternalRule("rule-2");
     RuleDto rule3 = insertAddHocRule("rule-3");
-    insertIssue(rule1, PROJECT_UUID, PROJECT_UUID);
-    insertIssue(rule2, PROJECT_UUID, PROJECT_UUID);
-    insertIssue(rule3, PROJECT_UUID, PROJECT_UUID);
+    insertIssue(rule1, mainBranch.uuid(), mainBranch.uuid());
+    insertIssue(rule2, mainBranch.uuid(), mainBranch.uuid());
+    insertIssue(rule3, mainBranch.uuid(), mainBranch.uuid());
 
     underTest.execute(new TestComputationStepContext());
 
@@ -160,9 +148,9 @@ public class ExportAdHocRulesStepIT {
     RuleDto rule1 = insertAddHocRule("rule-1");
     RuleDto rule2 = insertAddHocRule("rule-2");
     RuleDto rule3 = insertAddHocRule("rule-3");
-    insertIssue(rule1, PROJECT_UUID, PROJECT_UUID);
-    insertIssue(rule2, PROJECT_UUID, PROJECT_UUID);
-    insertIssue(rule3, PROJECT_UUID, PROJECT_UUID);
+    insertIssue(rule1, mainBranch.uuid(), mainBranch.uuid());
+    insertIssue(rule2, mainBranch.uuid(), mainBranch.uuid());
+    insertIssue(rule3, mainBranch.uuid(), mainBranch.uuid());
     dumpWriter.failIfMoreThan(2, DumpElement.AD_HOC_RULES);
 
     assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext()))
@@ -177,14 +165,15 @@ public class ExportAdHocRulesStepIT {
 
   private ProjectDto createProject() {
     Date createdAt = new Date();
-    ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT).getMainBranchComponent();
-    BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(projectDto, branch).setCreatedAt(createdAt));
+    ProjectData projectData = dbTester.components().insertPublicProject(PROJECT_UUID);
+    mainBranch = projectData.getMainBranchComponent();
+    BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(projectData.getProjectDto(), branch).setCreatedAt(createdAt));
     dbTester.commit();
-    return dbTester.components().getProjectDtoByMainBranch(projectDto);
+    return projectData.getProjectDto();
   }
 
-  private void insertIssue(RuleDto ruleDto, String projectUuid, String componentUuid) {
-    IssueDto dto = createBaseIssueDto(ruleDto, projectUuid, componentUuid);
+  private void insertIssue(RuleDto ruleDto, String branchUuid, String componentUuid) {
+    IssueDto dto = createBaseIssueDto(ruleDto, branchUuid, componentUuid);
     insertIssue(dto);
   }
 
@@ -193,11 +182,11 @@ public class ExportAdHocRulesStepIT {
     dbTester.commit();
   }
 
-  private IssueDto createBaseIssueDto(RuleDto ruleDto, String projectUuid, String componentUuid) {
+  private IssueDto createBaseIssueDto(RuleDto ruleDto, String branchUuid, String componentUuid) {
     return new IssueDto()
       .setKee("issue_uuid_" + issueUuidGenerator++)
       .setComponentUuid(componentUuid)
-      .setProjectUuid(projectUuid)
+      .setProjectUuid(branchUuid)
       .setRuleUuid(ruleDto.getUuid())
       .setStatus("OPEN");
   }
index 84edae825c0dd39be3990c998f99eadbbdbc8271..b1ffa6fabbf8fb3df2a57ea7cf51abc5adbdc48e 100644 (file)
@@ -58,7 +58,7 @@ public class ExportEventsStepIT {
 
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   @Rule
   public LogTester logTester = new LogTester();
index c4ce226b0020851d134a944f57d8c42efb0e416f..2d54cea746b1e4bcdc241f32be0747e98e6e568d 100644 (file)
@@ -58,7 +58,7 @@ public class ExportLinksStepIT {
     .setBranchUuid(PROJECT_UUID);
 
   @Rule
-  public DbTester db = DbTester.createWithExtensionMappers(System2.INSTANCE, ProjectExportMapper.class);
+  public DbTester db = DbTester.createWithExtensionMappers(System2.INSTANCE, true, ProjectExportMapper.class);
 
 
   @Rule
index 9739cf0d1823f66e3424f260f62db9473c0989e6..a8a874f1b4f08566740192f1f87cd144572f1748 100644 (file)
@@ -47,13 +47,13 @@ public class ExportLiveMeasuresStepIT {
   @Rule
   public LogTester logTester = new LogTester();
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
-  private ComponentRepositoryImpl componentRepository = new ComponentRepositoryImpl();
-  private MutableMetricRepository metricRepository = new MutableMetricRepositoryImpl();
-  private ProjectHolder projectHolder = mock(ProjectHolder.class);
-  private FakeDumpWriter dumpWriter = new FakeDumpWriter();
-  private ExportLiveMeasuresStep underTest = new ExportLiveMeasuresStep(dbTester.getDbClient(), projectHolder, componentRepository, metricRepository, dumpWriter);
+  private final ComponentRepositoryImpl componentRepository = new ComponentRepositoryImpl();
+  private final MutableMetricRepository metricRepository = new MutableMetricRepositoryImpl();
+  private final ProjectHolder projectHolder = mock(ProjectHolder.class);
+  private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
+  private final ExportLiveMeasuresStep underTest = new ExportLiveMeasuresStep(dbTester.getDbClient(), projectHolder, componentRepository, metricRepository, dumpWriter);
 
   @Before
   public void before() {
index 6bc708f93b366830aa733a299a297b1a2f8a44b5..136b2dd1501ceefb418844c8686539b502aad54b 100644 (file)
@@ -97,7 +97,7 @@ public class ExportMeasuresStepIT {
   public LogTester logTester = new LogTester();
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   private ComponentRepositoryImpl componentRepository = new ComponentRepositoryImpl();
   private MutableMetricRepository metricRepository = new MutableMetricRepositoryImpl();
index 4304b5fc353ce880cc374739f5f6849edc3f1fd5..325d91d1fd99c837c4a7da953622c01974942fe1 100644 (file)
@@ -52,7 +52,7 @@ public class ExportMetricsStepIT {
   public LogTester logTester = new LogTester();
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   MutableMetricRepository metricsHolder = new MutableMetricRepositoryImpl();
   FakeDumpWriter dumpWriter = new FakeDumpWriter();
index 8a61f02a780ec81846d5ed4d7e9680c96961cf19..c2921880f7ba71e7fc6c36cbcc5cb582d209238c 100644 (file)
@@ -38,6 +38,7 @@ import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.newcodeperiod.NewCodePeriodDto;
 import org.sonar.db.newcodeperiod.NewCodePeriodType;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.project.ProjectExportMapper;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -50,13 +51,6 @@ public class ExportNewCodePeriodsStepIT {
 
   private static final String PROJECT_UUID = "project_uuid";
   private static final String ANOTHER_PROJECT_UUID = "another_project_uuid";
-  private static final ComponentDto PROJECT = new ComponentDto()
-    .setUuid(PROJECT_UUID)
-    .setUuidPath(UUID_PATH_OF_ROOT)
-    .setBranchUuid(PROJECT_UUID)
-    .setQualifier(Qualifiers.PROJECT)
-    .setName("project")
-    .setKey("the_project");
   private static final ComponentDto ANOTHER_PROJECT = new ComponentDto()
     .setUuid(ANOTHER_PROJECT_UUID)
     .setUuidPath(UUID_PATH_OF_ROOT)
@@ -76,10 +70,12 @@ public class ExportNewCodePeriodsStepIT {
     new BranchDto().setBranchType(BranchType.BRANCH).setProjectUuid(ANOTHER_PROJECT_UUID).setKey("branch-3").setUuid("branch-uuid-3").setMergeBranchUuid("master")
       .setExcludeFromPurge(true).setIsMain(false));
 
+  private ProjectDto project;
+
   @Rule
   public LogTester logTester = new LogTester();
   @Rule
-  public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, ProjectExportMapper.class);
+  public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, true, ProjectExportMapper.class);
 
   private MutableProjectHolder projectHolder = new MutableProjectHolderImpl();
   private FakeDumpWriter dumpWriter = new FakeDumpWriter();
@@ -89,14 +85,14 @@ public class ExportNewCodePeriodsStepIT {
   public void setUp() {
     logTester.setLevel(Level.DEBUG);
     Date createdAt = new Date();
-    ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT).getMainBranchComponent();
-    PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(projectDto, branch).setCreatedAt(createdAt));
+    project = dbTester.components().insertPrivateProject(PROJECT_UUID).getProjectDto();
+    PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(project, branch).setCreatedAt(createdAt));
 
     ComponentDto anotherProjectDto = dbTester.components().insertPublicProject(ANOTHER_PROJECT).getMainBranchComponent();
     ANOTHER_PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(anotherProjectDto, branch).setCreatedAt(createdAt));
 
     dbTester.commit();
-    projectHolder.setProjectDto(dbTester.components().getProjectDtoByMainBranch(PROJECT));
+    projectHolder.setProjectDto(project);
   }
 
   @Test
@@ -109,10 +105,10 @@ public class ExportNewCodePeriodsStepIT {
 
   @Test
   public void export_only_project_new_code_periods_on_branches_excluded_from_purge() {
-    NewCodePeriodDto newCodePeriod1 = newDto("uuid1", PROJECT.uuid(), null, SPECIFIC_ANALYSIS, "analysis-uuid");
-    NewCodePeriodDto newCodePeriod2 = newDto("uuid2", PROJECT.uuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid");
+    NewCodePeriodDto newCodePeriod1 = newDto("uuid1", project.getUuid(), null, SPECIFIC_ANALYSIS, "analysis-uuid");
+    NewCodePeriodDto newCodePeriod2 = newDto("uuid2", project.getUuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid");
     // the following new code periods are not exported
-    NewCodePeriodDto newCodePeriod3 = newDto("uuid3", PROJECT.uuid(), "branch-uuid-2", SPECIFIC_ANALYSIS, "analysis-uuid");
+    NewCodePeriodDto newCodePeriod3 = newDto("uuid3", project.getUuid(), "branch-uuid-2", SPECIFIC_ANALYSIS, "analysis-uuid");
     NewCodePeriodDto anotherProjectNewCodePeriods = newDto("uuid4", ANOTHER_PROJECT.uuid(), "branch-uuid-3", SPECIFIC_ANALYSIS, "analysis-uuid");
     NewCodePeriodDto globalNewCodePeriod = newDto("uuid5", null, null, PREVIOUS_VERSION, null);
     insertNewCodePeriods(newCodePeriod1, newCodePeriod2, newCodePeriod3, anotherProjectNewCodePeriods, globalNewCodePeriod);
@@ -127,7 +123,7 @@ public class ExportNewCodePeriodsStepIT {
 
   @Test
   public void test_exported_fields() {
-    NewCodePeriodDto dto = newDto("uuid1", PROJECT.uuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid");
+    NewCodePeriodDto dto = newDto("uuid1", project.getUuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid");
     insertNewCodePeriods(dto);
 
     underTest.execute(new TestComputationStepContext());
@@ -144,8 +140,8 @@ public class ExportNewCodePeriodsStepIT {
   public void throws_ISE_if_error() {
     dumpWriter.failIfMoreThan(1, DumpElement.NEW_CODE_PERIODS);
     insertNewCodePeriods(
-      newDto("uuid1", PROJECT.uuid(), null, SPECIFIC_ANALYSIS, "analysis-uuid"),
-      newDto("uuid2", PROJECT.uuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid"));
+      newDto("uuid1", project.getUuid(), null, SPECIFIC_ANALYSIS, "analysis-uuid"),
+      newDto("uuid2", project.getUuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid"));
 
     assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext()))
       .isInstanceOf(IllegalStateException.class)
index b2ea92b133e1dbb10b5e1df00fe9a69961cebb56..43e407dbbac80e0a1defd188975ddae6b2f99838 100644 (file)
@@ -58,11 +58,11 @@ public class ExportSettingsStepIT {
   @Rule
   public LogTester logTester = new LogTester();
   @Rule
-  public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, ProjectExportMapper.class);
-  private MutableComponentRepository componentRepository = new ComponentRepositoryImpl();
-  private MutableProjectHolder projectHolder = new MutableProjectHolderImpl();
-  private FakeDumpWriter dumpWriter = new FakeDumpWriter();
-  private ExportSettingsStep underTest = new ExportSettingsStep(dbTester.getDbClient(), projectHolder, componentRepository, dumpWriter);
+  public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, true, ProjectExportMapper.class);
+  private final MutableComponentRepository componentRepository = new ComponentRepositoryImpl();
+  private final MutableProjectHolder projectHolder = new MutableProjectHolderImpl();
+  private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
+  private final ExportSettingsStep underTest = new ExportSettingsStep(dbTester.getDbClient(), projectHolder, componentRepository, dumpWriter);
 
   @Before
   public void setUp() {
index 29e1180b6fcb2127b62815500d21a06741c23840..5fce2aafedb833ad7c822e761e2016122c8490f8 100644 (file)
@@ -37,7 +37,7 @@ public class LoadProjectStepIT {
   private static final String PROJECT_KEY = "project_key";
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   private final ProjectDescriptor descriptor = new ProjectDescriptor("project_uuid", PROJECT_KEY, "Project Name");
   private final MutableProjectHolder definitionHolder = new MutableProjectHolderImpl();
index 1bee87571ad99f181ef886266054cdd1d5817ffd..cdad8bc203b262c4d36822450428bfb4a4c31ed8 100644 (file)
@@ -167,7 +167,7 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor
   }
 
   private static Project createProject(org.sonar.ce.task.CeTask ceTask) {
-    return ceTask.getMainComponent()
+    return ceTask.getEntity()
       .map(c -> new ProjectImpl(
         c.getUuid(),
         c.getKey().orElseThrow(() -> new IllegalStateException("Missing project key")),
index 12af107f1cd2dc85824a0b97934191011b24e90a..918dc9a6bead0fd6b23ad5f08997e7a3436520c3 100644 (file)
@@ -78,7 +78,7 @@ public class PersistFileSourcesStep implements ComputationStep {
 
   private class FileSourceVisitor extends TypeAwareVisitorAdapter {
     private final DbSession session;
-    private String projectUuid;
+    private String branchUuid;
 
     private FileSourceVisitor(DbSession session) {
       super(CrawlerDepthLimit.FILE, PRE_ORDER);
@@ -86,8 +86,8 @@ public class PersistFileSourcesStep implements ComputationStep {
     }
 
     @Override
-    public void visitProject(Component project) {
-      this.projectUuid = project.getUuid();
+    public void visitProject(Component branch) {
+      this.branchUuid = branch.getUuid();
     }
 
     @Override
@@ -113,7 +113,7 @@ public class PersistFileSourcesStep implements ComputationStep {
       if (previousDto == null) {
         FileSourceDto dto = new FileSourceDto()
           .setUuid(uuidFactory.create())
-          .setProjectUuid(projectUuid)
+          .setProjectUuid(branchUuid)
           .setFileUuid(file.getUuid())
           .setBinaryData(binaryData)
           .setSrcHash(srcHash)
index 14ad8283eaa792a2494c29d94f7f049ee7bfc91c..bd98f1f6f527335a2cad51fc2d302b07e188bb8e 100644 (file)
@@ -87,11 +87,11 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
    * @return a {@link Runnable} to execute some checks on the project at the end of the step
    */
   private Runnable loadProject(ScannerReport.Metadata reportMetadata) {
-    CeTask.Component mainComponent = mandatoryComponent(ceTask.getMainComponent());
-    String mainComponentKey = mainComponent.getKey()
+    CeTask.Component entity = mandatoryComponent(ceTask.getEntity());
+    String entityKey = entity.getKey()
       .orElseThrow(() -> MessageException.of(format(
-        "Compute Engine task main component key is null. Project with UUID %s must have been deleted since report was uploaded. Can not proceed.",
-        mainComponent.getUuid())));
+        "Compute Engine task entity key is null. Project with UUID %s must have been deleted since report was uploaded. Can not proceed.",
+        entity.getUuid())));
     CeTask.Component component = mandatoryComponent(ceTask.getComponent());
     if (!component.getKey().isPresent()) {
       throw MessageException.of(format(
@@ -102,18 +102,17 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
     ProjectDto dto = toProject(reportMetadata.getProjectKey());
     analysisMetadata.setProject(Project.fromProjectDtoWithTags(dto));
     return () -> {
-      if (!mainComponentKey.equals(reportMetadata.getProjectKey())) {
+      if (!entityKey.equals(reportMetadata.getProjectKey())) {
         throw MessageException.of(format(
           "ProjectKey in report (%s) is not consistent with projectKey under which the report has been submitted (%s)",
           reportMetadata.getProjectKey(),
-          mainComponentKey));
+          entityKey));
       }
     };
   }
 
-  private static CeTask.Component mandatoryComponent(Optional<CeTask.Component> mainComponent) {
-    return mainComponent
-      .orElseThrow(() -> new IllegalStateException("component missing on ce task"));
+  private static CeTask.Component mandatoryComponent(Optional<CeTask.Component> entity) {
+    return entity.orElseThrow(() -> new IllegalStateException("component missing on ce task"));
   }
 
   private void loadQualityProfiles(ScannerReport.Metadata reportMetadata) {
index 4790834cdd47b87067b73eaf6601a868ce888fd6..c40fee64e5e4f50ec2a0f10fc6da0b4fdb24efea 100644 (file)
@@ -40,11 +40,11 @@ public final class IgnoreOrphanBranchStep implements ComputationStep {
 
   @Override
   public void execute(Context context) {
-    String mainComponentUuid = ceTask.getMainComponent().orElseThrow(() -> new UnsupportedOperationException("main component not found in task")).getUuid();
+    String entityUuid = ceTask.getEntity().orElseThrow(() -> new UnsupportedOperationException("entity not found in task")).getUuid();
     String componentUuid = ceTask.getComponent().orElseThrow(() -> new UnsupportedOperationException("component not found in task")).getUuid();
 
     try (DbSession dbSession = dbClient.openSession(false)) {
-      Optional<ComponentDto> componentDto = dbClient.componentDao().selectByUuid(dbSession, mainComponentUuid);
+      Optional<ComponentDto> componentDto = dbClient.componentDao().selectByUuid(dbSession, entityUuid);
       if(!componentDto.isPresent()){
         LOG.info("reindexation task has been trigger on an orphan branch. removing any exclude_from_purge flag, and skip the indexation");
         dbClient.branchDao().updateExcludeFromPurge(dbSession, componentUuid, false);
index 2bf7818d3dcd0db4f8f1bcaa31a20a4aebd1d990..51945cd28041a72f0ff98066bd99302cfef9c5b2 100644 (file)
@@ -41,11 +41,10 @@ public class ExportIssuesChangelogStep implements ComputationStep {
   private static final String STATUS_CLOSED = "CLOSED";
   private static final String QUERY = "select" +
     " ic.kee, ic.issue_key, ic.change_type, ic.change_data, ic.user_login," +
-    " ic.issue_change_creation_date, ic.created_at, p.uuid" +
+    " ic.issue_change_creation_date, ic.created_at, pb.uuid" +
     " from issue_changes ic" +
     " join issues i on i.kee = ic.issue_key" +
-    " join projects p on p.uuid = i.project_uuid" +
-    " join project_branches pb on pb.uuid = p.uuid" +
+    " join project_branches pb on pb.uuid = i.project_uuid" +
     " where pb.project_uuid = ? and pb.branch_type = 'BRANCH' and pb.exclude_from_purge = ? " +
     " and i.status <> ?" +
     " order by ic.created_at asc";
index e208583103d94ffed37e5230a98580e103c9df94..3383d7258e3bd0351afae5410140ee4f7e3c6680 100644 (file)
@@ -65,8 +65,8 @@ public class ProjectExportTaskProcessor implements CeTaskProcessor {
   }
 
   private static void failIfNotMain(CeTask.Component exportComponent, CeTask task) {
-    task.getMainComponent().filter(mainComponent -> mainComponent.equals(exportComponent))
-      .orElseThrow(() -> new IllegalStateException("Component of task must be the same as main component"));
+    task.getEntity().filter(entity -> entity.equals(exportComponent))
+      .orElseThrow(() -> new IllegalStateException("Component of task must be the same as entity"));
   }
 
   private static CeTask.Component mandatoryComponent(CeTask task, String type) {
index c95b925cceece9d7bc3306eb40e3b9938e3782ec..d7ea7410212b6323dcb742f3908296655fa27820 100644 (file)
@@ -88,11 +88,12 @@ public class PostProjectAnalysisTasksExecutorTest {
 
   private final ArgumentCaptor<PostProjectAnalysisTask.Context> taskContextCaptor = ArgumentCaptor.forClass(PostProjectAnalysisTask.Context.class);
   private final CeTask.Component component = new CeTask.Component("component uuid", "component key", "component name");
+  private final CeTask.Component entity = new CeTask.Component("entity uuid", "component key", "component name");
   private final CeTask ceTask = new CeTask.Builder()
     .setType("type")
     .setUuid("uuid")
     .setComponent(component)
-    .setMainComponent(component)
+    .setEntity(entity)
     .build();
   private final PostProjectAnalysisTask postProjectAnalysisTask = newPostProjectAnalysisTask("PT1");
   private final PostProjectAnalysisTasksExecutor underTest = new PostProjectAnalysisTasksExecutor(
@@ -189,9 +190,9 @@ public class PostProjectAnalysisTasksExecutorTest {
     verify(postProjectAnalysisTask).finished(taskContextCaptor.capture());
 
     Project project = taskContextCaptor.getValue().getProjectAnalysis().getProject();
-    assertThat(project.getUuid()).isEqualTo(ceTask.getComponent().get().getUuid());
-    assertThat(project.getKey()).isEqualTo(ceTask.getComponent().get().getKey().get());
-    assertThat(project.getName()).isEqualTo(ceTask.getComponent().get().getName().get());
+    assertThat(project.getUuid()).isEqualTo(ceTask.getEntity().get().getUuid());
+    assertThat(project.getKey()).isEqualTo(ceTask.getEntity().get().getKey().get());
+    assertThat(project.getName()).isEqualTo(ceTask.getEntity().get().getName().get());
   }
 
   @Test
index 82aed72779c5511b360d2f5a312bf57e0e65e98c..95cc6b2c529a8839c257f934fc846c2d938fe80e 100644 (file)
@@ -40,17 +40,17 @@ public class CeTask {
   private final String type;
   private final String uuid;
   private final Component component;
-  private final Component mainComponent;
+  private final Component entity;
   private final User submitter;
   private final Map<String, String> characteristics;
 
   private CeTask(Builder builder) {
     this.uuid = requireNonNull(emptyToNull(builder.uuid), "uuid can't be null nor empty");
     this.type = requireNonNull(emptyToNull(builder.type), "type can't be null nor empty");
-    checkArgument((builder.component == null) == (builder.mainComponent == null),
-      "None or both component and main component must be non null");
+    checkArgument((builder.component == null) == (builder.entity == null),
+      "None or both component and entity must be non null");
     this.component = builder.component;
-    this.mainComponent = builder.mainComponent;
+    this.entity = builder.entity;
     this.submitter = builder.submitter;
     if (builder.characteristics == null) {
       this.characteristics = emptyMap();
@@ -103,8 +103,8 @@ public class CeTask {
     return Optional.ofNullable(component);
   }
 
-  public Optional<Component> getMainComponent() {
-    return Optional.ofNullable(mainComponent);
+  public Optional<Component> getEntity() {
+    return Optional.ofNullable(entity);
   }
 
   @CheckForNull
@@ -122,7 +122,7 @@ public class CeTask {
       .add("type", type)
       .add("uuid", uuid)
       .add("component", component)
-      .add("mainComponent", mainComponent)
+      .add("entity", entity)
       .add("submitter", submitter)
       .toString();
   }
@@ -148,7 +148,7 @@ public class CeTask {
     private String uuid;
     private String type;
     private Component component;
-    private Component mainComponent;
+    private Component entity;
     private User submitter;
     private Map<String, String> characteristics;
 
@@ -167,8 +167,8 @@ public class CeTask {
       return this;
     }
 
-    public Builder setMainComponent(@Nullable Component mainComponent) {
-      this.mainComponent = mainComponent;
+    public Builder setEntity(@Nullable Component entity) {
+      this.entity = entity;
       return this;
     }
 
index c773ae1c5ce6b593a43f7e8a0feaa1758c311ac9..84ec151ab7d3f191c30db1151a9bac400561afa7 100644 (file)
@@ -35,20 +35,20 @@ public class CeTaskTest {
   private CeTask.Builder underTest = new CeTask.Builder();
 
   @Test
-  @UseDataProvider("oneAndOnlyOneOfComponentAndMainComponent")
-  public void build_fails_with_IAE_if_only_one_of_component_and_main_component_is_non_null(CeTask.Component component, CeTask.Component mainComponent) {
+  @UseDataProvider("oneAndOnlyOneOfComponentAndEntity")
+  public void build_fails_with_IAE_if_only_one_of_component_and_main_component_is_non_null(CeTask.Component component, CeTask.Component entity) {
     underTest.setType("TYPE_1");
     underTest.setUuid("UUID_1");
     underTest.setComponent(component);
-    underTest.setMainComponent(mainComponent);
+    underTest.setEntity(entity);
 
     assertThatThrownBy(() -> underTest.build())
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("None or both component and main component must be non null");
+      .hasMessage("None or both component and entity must be non null");
   }
 
   @DataProvider
-  public static Object[][] oneAndOnlyOneOfComponentAndMainComponent() {
+  public static Object[][] oneAndOnlyOneOfComponentAndEntity() {
     CeTask.Component component = new CeTask.Component("COMPONENT_UUID_1", "COMPONENT_KEY_1", "The component");
     return new Object[][] {
       {component, null},
@@ -59,13 +59,13 @@ public class CeTaskTest {
   @Test
   public void verify_getters() {
     CeTask.Component component = new CeTask.Component("COMPONENT_UUID_1", "COMPONENT_KEY_1", "The component");
-    CeTask.Component mainComponent = new CeTask.Component("MAIN_COMPONENT_UUID_1", "MAIN_COMPONENT_KEY_1", "The main component");
+    CeTask.Component entity = new CeTask.Component("ENTITY_UUID_1", "ENTITY_KEY_1", "The entity");
     CeTask.User submitter = new CeTask.User("UUID_USER_1", "LOGIN_1");
     underTest.setType("TYPE_1");
     underTest.setUuid("UUID_1");
     underTest.setSubmitter(submitter);
     underTest.setComponent(component);
-    underTest.setMainComponent(mainComponent);
+    underTest.setEntity(entity);
     underTest.setCharacteristics(ImmutableMap.of("k1", "v1", "k2", "v2"));
 
     CeTask task = underTest.build();
@@ -74,7 +74,7 @@ public class CeTaskTest {
     assertThat(task.getType()).isEqualTo("TYPE_1");
     assertThat(task.getSubmitter()).isEqualTo(submitter);
     assertThat(task.getComponent()).contains(component);
-    assertThat(task.getMainComponent()).contains(mainComponent);
+    assertThat(task.getEntity()).contains(entity);
     assertThat(task.getCharacteristics())
       .hasSize(2)
       .containsEntry("k1", "v1")
@@ -84,11 +84,11 @@ public class CeTaskTest {
   @Test
   public void verify_toString() {
     CeTask.Component component = new CeTask.Component("COMPONENT_UUID_1", "COMPONENT_KEY_1", "The component");
-    CeTask.Component mainComponent = new CeTask.Component("MAIN_COMPONENT_UUID_1", "MAIN_COMPONENT_KEY_1", "The main component");
+    CeTask.Component entity = new CeTask.Component("ENTITY_UUID_1", "ENTITY_KEY_1", "The entity");
     underTest.setType("TYPE_1");
     underTest.setUuid("UUID_1");
     underTest.setComponent(component);
-    underTest.setMainComponent(mainComponent);
+    underTest.setEntity(entity);
     underTest.setSubmitter(new CeTask.User("UUID_USER_1", "LOGIN_1"));
     underTest.setCharacteristics(ImmutableMap.of("k1", "v1", "k2", "v2"));
 
@@ -99,7 +99,7 @@ public class CeTaskTest {
       "type=TYPE_1, " +
       "uuid=UUID_1, " +
       "component=Component{uuid='COMPONENT_UUID_1', key='COMPONENT_KEY_1', name='The component'}, " +
-      "mainComponent=Component{uuid='MAIN_COMPONENT_UUID_1', key='MAIN_COMPONENT_KEY_1', name='The main component'}, " +
+      "entity=Component{uuid='ENTITY_UUID_1', key='ENTITY_KEY_1', name='The entity'}, " +
       "submitter=User{uuid='UUID_USER_1', login='LOGIN_1'}" +
       "}");
   }
index 5fee41a29038b480d8c518e897758c6f288f8b35..3eb49dbfde1da4c8d1a6fb88c44039319ed9d764 100644 (file)
@@ -45,8 +45,10 @@ import org.sonar.db.ce.CeActivityDto;
 import org.sonar.db.ce.CeQueueDto;
 import org.sonar.db.ce.CeQueueTesting;
 import org.sonar.db.ce.CeTaskTypes;
+import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.platform.NodeInformation;
 
@@ -71,20 +73,19 @@ public class InternalCeQueueImplIT {
   private static final String WORKER_UUID_2 = "worker uuid 2";
   private static final String NODE_NAME = "nodeName1";
 
-  private System2 system2 = new AlwaysIncreasingSystem2();
+  private final System2 system2 = new AlwaysIncreasingSystem2();
 
   @Rule
   public DbTester db = DbTester.create(system2);
 
-  private DbSession session = db.getSession();
-
-  private UuidFactory uuidFactory = UuidFactoryImpl.INSTANCE;
-  private CEQueueStatus queueStatus = new CEQueueStatusImpl(db.getDbClient(), mock(System2.class));
-  private ComputeEngineStatus computeEngineStatus = mock(ComputeEngineStatus.class);
-  private Configuration config = mock(Configuration.class);
-  private NextPendingTaskPicker nextPendingTaskPicker = new NextPendingTaskPicker(config, db.getDbClient());
-  private NodeInformation nodeInformation = mock(NodeInformation.class);
-  private InternalCeQueue underTest = new InternalCeQueueImpl(system2, db.getDbClient(), uuidFactory, queueStatus,
+  private final DbSession session = db.getSession();
+  private final UuidFactory uuidFactory = UuidFactoryImpl.INSTANCE;
+  private final CEQueueStatus queueStatus = new CEQueueStatusImpl(db.getDbClient(), mock(System2.class));
+  private final ComputeEngineStatus computeEngineStatus = mock(ComputeEngineStatus.class);
+  private final Configuration config = mock(Configuration.class);
+  private final NextPendingTaskPicker nextPendingTaskPicker = new NextPendingTaskPicker(config, db.getDbClient());
+  private final NodeInformation nodeInformation = mock(NodeInformation.class);
+  private final InternalCeQueue underTest = new InternalCeQueueImpl(system2, db.getDbClient(), uuidFactory, queueStatus,
     computeEngineStatus, nextPendingTaskPicker, nodeInformation);
 
   @Before
@@ -96,8 +97,7 @@ public class InternalCeQueueImplIT {
 
   @Test
   public void submit_returns_task_populated_from_CeTaskSubmit_and_creates_CeQueue_row() {
-    ComponentDto project1 = newProjectDto("PROJECT_1");
-    CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, project1, project1, "rob");
+    CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, "entity", "component", "rob");
     CeTask task = underTest.submit(taskSubmit);
     UserDto userDto = db.getDbClient().userDao().selectByUuid(db.getSession(), taskSubmit.getSubmitterUuid());
     verifyCeTask(taskSubmit, task, null, userDto);
@@ -106,12 +106,12 @@ public class InternalCeQueueImplIT {
 
   @Test
   public void submit_populates_component_name_and_key_of_CeTask_if_component_exists() {
-    ComponentDto componentDto = insertComponent(newProjectDto("PROJECT_1"));
-    CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, componentDto, componentDto, null);
+    ProjectData projectData = newProject("PROJECT_1");
+    CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, projectData, null);
 
     CeTask task = underTest.submit(taskSubmit);
 
-    verifyCeTask(taskSubmit, task, componentDto, null);
+    verifyCeTask(taskSubmit, task, projectData.getMainBranchComponent(), null);
   }
 
   @Test
@@ -125,8 +125,7 @@ public class InternalCeQueueImplIT {
 
   @Test
   public void massSubmit_returns_tasks_for_each_CeTaskSubmit_populated_from_CeTaskSubmit_and_creates_CeQueue_row_for_each() {
-    ComponentDto project1 = newProjectDto("PROJECT_1");
-    CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, project1, project1, "rob");
+    CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, "entity", "component", "rob");
     CeTaskSubmit taskSubmit2 = createTaskSubmit("some type");
 
     List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
@@ -141,15 +140,14 @@ public class InternalCeQueueImplIT {
 
   @Test
   public void massSubmit_populates_component_name_and_key_of_CeTask_if_component_exists() {
-    ComponentDto componentDto1 = insertComponent(newProjectDto("PROJECT_1"));
-    CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, componentDto1, componentDto1, null);
-    ComponentDto nonExistingComponent = newProjectDto("non existing component uuid");
-    CeTaskSubmit taskSubmit2 = createTaskSubmit("something", nonExistingComponent, nonExistingComponent, null);
+    ProjectData project = newProject("PROJECT_1");
+    CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, project, null);
+    CeTaskSubmit taskSubmit2 = createTaskSubmit("something", project.projectUuid(), "non-existing", null);
 
     List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
 
     assertThat(tasks).hasSize(2);
-    verifyCeTask(taskSubmit1, tasks.get(0), componentDto1, null);
+    verifyCeTask(taskSubmit1, tasks.get(0), project.getMainBranchComponent(), null);
     verifyCeTask(taskSubmit2, tasks.get(1), null, null);
   }
 
@@ -162,7 +160,7 @@ public class InternalCeQueueImplIT {
 
   @Test
   public void test_remove() {
-    CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
     Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
     underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, null, null);
 
@@ -194,7 +192,7 @@ public class InternalCeQueueImplIT {
 
   @Test
   public void remove_does_not_set_analysisUuid_in_CeActivity_when_CeTaskResult_has_no_analysis_uuid() {
-    CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
     Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
     underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, newTaskResult(null), null);
 
@@ -206,7 +204,7 @@ public class InternalCeQueueImplIT {
 
   @Test
   public void remove_sets_analysisUuid_in_CeActivity_when_CeTaskResult_has_analysis_uuid() {
-    CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
 
     Optional<CeTask> peek = underTest.peek(WORKER_UUID_2, true);
     underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, newTaskResult(AN_ANALYSIS_UUID), null);
@@ -220,7 +218,7 @@ public class InternalCeQueueImplIT {
   @Test
   public void remove_sets_nodeName_in_CeActivity_when_nodeInformation_defines_node_name() {
     when(nodeInformation.getNodeName()).thenReturn(Optional.of(NODE_NAME));
-    CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
 
     Optional<CeTask> peek = underTest.peek(WORKER_UUID_2, true);
     underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, newTaskResult(AN_ANALYSIS_UUID), null);
@@ -233,7 +231,7 @@ public class InternalCeQueueImplIT {
   @Test
   public void remove_do_not_set_nodeName_in_CeActivity_when_nodeInformation_does_not_define_node_name() {
     when(nodeInformation.getNodeName()).thenReturn(Optional.empty());
-    CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
 
     Optional<CeTask> peek = underTest.peek(WORKER_UUID_2, true);
     underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, newTaskResult(AN_ANALYSIS_UUID), null);
@@ -247,7 +245,7 @@ public class InternalCeQueueImplIT {
   public void remove_saves_error_message_and_stacktrace_when_exception_is_provided() {
     Throwable error = new NullPointerException("Fake NPE to test persistence to DB");
 
-    CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
     Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
     underTest.remove(peek.get(), CeActivityDto.Status.FAILED, null, error);
 
@@ -263,7 +261,7 @@ public class InternalCeQueueImplIT {
   public void remove_saves_error_when_TypedMessageException_is_provided() {
     Throwable error = new TypedExceptionImpl("aType", "aMessage");
 
-    CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
     Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
     underTest.remove(peek.get(), CeActivityDto.Status.FAILED, null, error);
 
@@ -277,7 +275,7 @@ public class InternalCeQueueImplIT {
   public void remove_updates_queueStatus_success_even_if_task_does_not_exist_in_DB() {
     CEQueueStatus queueStatus = mock(CEQueueStatus.class);
 
-    CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
     db.getDbClient().ceQueueDao().deleteByUuid(db.getSession(), task.getUuid());
     db.commit();
 
@@ -295,7 +293,7 @@ public class InternalCeQueueImplIT {
   public void remove_updates_queueStatus_failure_even_if_task_does_not_exist_in_DB() {
     CEQueueStatus queueStatusMock = mock(CEQueueStatus.class);
 
-    CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
     db.getDbClient().ceQueueDao().deleteByUuid(db.getSession(), task.getUuid());
     db.commit();
     InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatusMock, null, null, nodeInformation);
@@ -313,7 +311,7 @@ public class InternalCeQueueImplIT {
 
     CEQueueStatus queueStatusMock = mock(CEQueueStatus.class);
 
-    CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
     db.executeUpdateSql("update ce_queue set status = 'PENDING', started_at = 123 where uuid = '" + task.getUuid() + "'");
     db.commit();
     InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatusMock, null, null, nodeInformation);
@@ -360,7 +358,7 @@ public class InternalCeQueueImplIT {
 
   @Test
   public void fail_to_remove_if_not_in_queue() {
-    CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
     underTest.remove(task, CeActivityDto.Status.SUCCESS, null, null);
 
     assertThatThrownBy(() -> underTest.remove(task, CeActivityDto.Status.SUCCESS, null, null))
@@ -369,14 +367,16 @@ public class InternalCeQueueImplIT {
 
   @Test
   public void test_peek() {
-    CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    ProjectData projectData = newProject("PROJECT_1");
+    ComponentDto mainBranchComponent = projectData.getMainBranchComponent();
+    CeTask task = submit(CeTaskTypes.REPORT, projectData);
 
     Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
     assertThat(peek).isPresent();
     assertThat(peek.get().getUuid()).isEqualTo(task.getUuid());
     assertThat(peek.get().getType()).isEqualTo(CeTaskTypes.REPORT);
-    assertThat(peek.get().getComponent()).contains(new CeTask.Component("PROJECT_1", null, null));
-    assertThat(peek.get().getMainComponent()).contains(peek.get().getComponent().get());
+    assertThat(peek.get().getComponent()).contains(new CeTask.Component(mainBranchComponent.uuid(), mainBranchComponent.getKey(), mainBranchComponent.name()));
+    assertThat(peek.get().getEntity()).contains(peek.get().getComponent().get());
 
     // no more pending tasks
     peek = underTest.peek(WORKER_UUID_2, true);
@@ -385,16 +385,16 @@ public class InternalCeQueueImplIT {
 
   @Test
   public void peek_populates_name_and_key_for_existing_component_and_main_component() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto branch = db.components().insertProjectBranch(project);
-    CeTask task = submit(CeTaskTypes.REPORT, project, branch);
+    ProjectDto project = db.components().insertPrivateProject().getProjectDto();
+    BranchDto branch = db.components().insertProjectBranch(project);
+    CeTask task = submit(CeTaskTypes.REPORT, branch);
 
     Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
     assertThat(peek).isPresent();
     assertThat(peek.get().getUuid()).isEqualTo(task.getUuid());
     assertThat(peek.get().getType()).isEqualTo(CeTaskTypes.REPORT);
-    assertThat(peek.get().getComponent()).contains(new CeTask.Component(branch.uuid(), branch.getKey(), branch.name()));
-    assertThat(peek.get().getMainComponent()).contains(new CeTask.Component(project.uuid(), project.getKey(), project.name()));
+    assertThat(peek.get().getComponent()).contains(new CeTask.Component(branch.getUuid(), project.getKey(), project.getName()));
+    assertThat(peek.get().getEntity()).contains(new CeTask.Component(project.getUuid(), project.getKey(), project.getName()));
 
     // no more pending tasks
     peek = underTest.peek(WORKER_UUID_2, true);
@@ -403,7 +403,7 @@ public class InternalCeQueueImplIT {
 
   @Test
   public void peek_is_paused_then_resumed() {
-    CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
     underTest.pauseWorkers();
 
     Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
@@ -429,7 +429,7 @@ public class InternalCeQueueImplIT {
 
   @Test
   public void peek_nothing_if_application_status_stopping() {
-    submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
     when(computeEngineStatus.getStatus()).thenReturn(STOPPING);
 
     Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
@@ -512,7 +512,7 @@ public class InternalCeQueueImplIT {
 
   @Test
   public void cancel_pending() {
-    CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
     CeQueueDto queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).get();
 
     underTest.cancel(db.getSession(), queueDto);
@@ -524,7 +524,7 @@ public class InternalCeQueueImplIT {
 
   @Test
   public void fail_to_cancel_if_in_progress() {
-    CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+    CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
     underTest.peek(WORKER_UUID_2, true);
     CeQueueDto queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).get();
 
@@ -535,9 +535,9 @@ public class InternalCeQueueImplIT {
 
   @Test
   public void cancelAll_pendings_but_not_in_progress() {
-    CeTask inProgressTask = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
-    CeTask pendingTask1 = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_2"));
-    CeTask pendingTask2 = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_3"));
+    CeTask inProgressTask = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
+    CeTask pendingTask1 = submit(CeTaskTypes.REPORT, newProject("PROJECT_2"));
+    CeTask pendingTask2 = submit(CeTaskTypes.REPORT, newProject("PROJECT_3"));
     underTest.peek(WORKER_UUID_2, true);
 
     int canceledCount = underTest.cancelAll();
@@ -675,40 +675,43 @@ public class InternalCeQueueImplIT {
     assertThat(dto.getTaskType()).isEqualTo(taskSubmit.getType());
     Optional<CeTaskSubmit.Component> component = taskSubmit.getComponent();
     if (component.isPresent()) {
-      assertThat(dto.getMainComponentUuid()).isEqualTo(component.get().getMainComponentUuid());
+      assertThat(dto.getEntityUuid()).isEqualTo(component.get().getEntityUuid());
       assertThat(dto.getComponentUuid()).isEqualTo(component.get().getUuid());
     } else {
-      assertThat(dto.getMainComponentUuid()).isNull();
+      assertThat(dto.getEntityUuid()).isNull();
       assertThat(dto.getComponentUuid()).isNull();
     }
     assertThat(dto.getSubmitterUuid()).isEqualTo(taskSubmit.getSubmitterUuid());
     assertThat(dto.getCreatedAt()).isEqualTo(dto.getUpdatedAt());
   }
 
-  private ComponentDto newProjectDto(String uuid) {
-    return ComponentTesting.newPublicProjectDto(uuid).setName("name_" + uuid).setKey("key_" + uuid);
+  private ProjectData newProject(String uuid) {
+    return db.components().insertPublicProject(uuid);
   }
 
-  private CeTask submit(String reportType, ComponentDto mainBranchComponent) {
-    return underTest.submit(createTaskSubmit(reportType, mainBranchComponent, mainBranchComponent, null));
+  private CeTask submit(String reportType, BranchDto branchDto) {
+    return underTest.submit(createTaskSubmit(reportType, branchDto.getProjectUuid(), branchDto.getUuid(), null));
   }
 
-  private CeTask submit(String reportType, ComponentDto mainBranchComponent, ComponentDto branchComponent) {
-    return underTest.submit(createTaskSubmit(reportType, mainBranchComponent, branchComponent, null));
+  private CeTask submit(String reportType, ProjectData projectData) {
+    return underTest.submit(createTaskSubmit(reportType, projectData.getProjectDto().getUuid(), projectData.getMainBranchDto().getUuid(), null));
   }
 
   private CeTaskSubmit createTaskSubmit(String type) {
     return createTaskSubmit(type, null, null, null);
   }
 
-  private CeTaskSubmit createTaskSubmit(String type, @Nullable ComponentDto mainBranchComponentDto, @Nullable ComponentDto componentDto,
-    @Nullable String submitterUuid) {
+  private CeTaskSubmit createTaskSubmit(String type, ProjectData projectData, @Nullable String submitterUuid) {
+    return createTaskSubmit(type, projectData.projectUuid(), projectData.getMainBranchDto().getUuid(), submitterUuid);
+  }
+
+  private CeTaskSubmit createTaskSubmit(String type, @Nullable String entityUuid, @Nullable String componentUuid, @Nullable String submitterUuid) {
     CeTaskSubmit.Builder builder = underTest.prepareSubmit()
       .setType(type)
       .setSubmitterUuid(submitterUuid)
       .setCharacteristics(emptyMap());
-    if (componentDto != null && mainBranchComponentDto != null) {
-      builder.setComponent(CeTaskSubmit.Component.fromDto(componentDto.uuid(), mainBranchComponentDto.uuid()));
+    if (componentUuid != null && entityUuid != null) {
+      builder.setComponent(CeTaskSubmit.Component.fromDto(componentUuid, entityUuid));
     }
     return builder.build();
   }
@@ -719,10 +722,6 @@ public class InternalCeQueueImplIT {
     return taskResult;
   }
 
-  private ComponentDto insertComponent(ComponentDto componentDto) {
-    return db.components().insertComponent(componentDto);
-  }
-
   private CeQueueDto makeInProgress(CeQueueDto ceQueueDto, String workerUuid) {
     CeQueueTesting.makeInProgress(session, workerUuid, system2.now(), ceQueueDto);
     return db.getDbClient().ceQueueDao().selectByUuid(session, ceQueueDto.getUuid()).get();
index 86057fc7889ad5379f4678994b19a959e8ec18cd..e4cda8dc5e1d98f1f534334d01f9914b5f270184 100644 (file)
@@ -205,7 +205,7 @@ public class NextPendingTaskPickerIT {
     // we have branch task in progress.
     insertInProgress("1");
     // The PR can run in parallel, but needs to wait for this other project to finish. We dont allow PRs to jump ahead
-    insertPending("2", c -> c.setMainComponentUuid("different project"));
+    insertPending("2", c -> c.setEntityUuid("different project"));
     insertPendingPullRequest("3");
 
     Optional<CeQueueDto> ceQueueDto = underTest.findPendingTask("workerUuid", db.getSession(), true);
@@ -220,7 +220,7 @@ public class NextPendingTaskPickerIT {
     insertInProgress("1");
     // The PR can run in parallel and is ahead of the other project
     insertPendingPullRequest("2");
-    insertPending("3", c -> c.setMainComponentUuid("different project"));
+    insertPending("3", c -> c.setEntityUuid("different project"));
 
     Optional<CeQueueDto> ceQueueDto = underTest.findPendingTask("workerUuid", db.getSession(), true);
 
@@ -247,7 +247,7 @@ public class NextPendingTaskPickerIT {
   public void findPendingTask_excludingViewPickUpOrphanBranches() {
     insertPending("1", dto -> dto
       .setComponentUuid("1")
-      .setMainComponentUuid("non-existing-uuid")
+      .setEntityUuid("non-existing-uuid")
       .setStatus(PENDING)
       .setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC)
       .setCreatedAt(100_000L));
@@ -260,11 +260,11 @@ public class NextPendingTaskPickerIT {
   @Test
   public void exclude_portfolios_computation_when_indexing_issues() {
     String taskUuid1 = "1", taskUuid2 = "2";
-    String mainComponentUuid = "1";
-    insertBranch(mainComponentUuid);
+    String branchUuid = "1";
+    insertBranch(branchUuid);
     insertPending(taskUuid1, dto -> dto
-      .setComponentUuid(mainComponentUuid)
-      .setMainComponentUuid(mainComponentUuid)
+      .setComponentUuid(branchUuid)
+      .setEntityUuid("entity_uuid")
       .setStatus(PENDING)
       .setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC)
       .setCreatedAt(100_000L));
@@ -273,7 +273,7 @@ public class NextPendingTaskPickerIT {
     insertView(view_uuid);
     insertPending(taskUuid2, dto -> dto
       .setComponentUuid(view_uuid)
-      .setMainComponentUuid(view_uuid)
+      .setEntityUuid(view_uuid)
       .setStatus(PENDING)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(100_000L));
@@ -351,7 +351,7 @@ public class NextPendingTaskPickerIT {
     dto.setStatus(status);
     dto.setSubmitterUuid("henri");
     dto.setComponentUuid(UUID.randomUUID().toString());
-    dto.setMainComponentUuid("1");
+    dto.setEntityUuid("1");
     if (ceQueueDtoConsumer != null) {
       ceQueueDtoConsumer.accept(dto);
     }
index 9e98bd98d8176f930a8338b404d6fba01a5133bb..1fbc8fd3a47062474dfb512022c673a9836c001f 100644 (file)
@@ -743,11 +743,12 @@ public class CeWorkerImplIT {
     for (int i = 0; i < characteristics.length; i += 2) {
       characteristicMap.put(characteristics[i], characteristics[i + 1]);
     }
-    CeTask.Component component = new CeTask.Component("PROJECT_1", null, null);
+    CeTask.Component entity = new CeTask.Component("PROJECT_1", null, null);
+    CeTask.Component component = new CeTask.Component("BRANCH_1", null, null);
     return new CeTask.Builder()
       .setUuid("TASK_1").setType(CeTaskTypes.REPORT)
       .setComponent(component)
-      .setMainComponent(component)
+      .setEntity(entity)
       .setSubmitter(submitter)
       .setCharacteristics(characteristicMap)
       .build();
index 8c9335249e1f6ed3d8278286eecef79e5bd87442..aba8eb7378b5bb741d38a6fe3e9e3b95997a60de 100644 (file)
@@ -77,7 +77,7 @@ public class CEQueueStatusImpl implements CEQueueStatus {
   @Override
   public Optional<Long> getLongestTimePending() {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      return dbClient.ceQueueDao().selectCreationDateOfOldestPendingByMainComponentUuid(dbSession, null)
+      return dbClient.ceQueueDao().selectCreationDateOfOldestPendingByEntityUuid(dbSession, null)
         .map(creationDate -> system.now() - creationDate);
     }
   }
index 51092ed94ccfd1e35b7a39d2c65c76aaabb70f88..5e42f5f2f1080e16843febbefb3d795064aaef2b 100644 (file)
@@ -29,7 +29,6 @@ import java.util.Optional;
 import java.util.Set;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-
 import org.sonar.api.ce.ComputeEngineSide;
 import org.sonar.api.utils.System2;
 import org.slf4j.Logger;
@@ -46,14 +45,12 @@ import org.sonar.db.DbSession;
 import org.sonar.db.ce.CeActivityDto;
 import org.sonar.db.ce.CeQueueDto;
 import org.sonar.db.ce.CeTaskCharacteristicDto;
-import org.sonar.db.component.ComponentDto;
 import org.sonar.server.platform.NodeInformation;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.lang.String.format;
 import static java.util.Collections.singletonList;
 import static java.util.Objects.requireNonNull;
-import static java.util.Optional.ofNullable;
 import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
 
 @ComputeEngineSide
@@ -88,13 +85,10 @@ public class InternalCeQueueImpl extends CeQueueImpl implements InternalCeQueue
         return Optional.empty();
       }
       CeQueueDto taskDto = opt.get();
-      Map<String, ComponentDto> componentsByUuid = loadComponentDtos(dbSession, taskDto);
       Map<String, String> characteristics = dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbSession, singletonList(taskDto.getUuid())).stream()
         .collect(uniqueIndex(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
 
-      CeTask task = convertToTask(dbSession, taskDto, characteristics,
-        ofNullable(taskDto.getComponentUuid()).map(componentsByUuid::get).orElse(null),
-        ofNullable(taskDto.getMainComponentUuid()).map(componentsByUuid::get).orElse(null));
+      CeTask task = convertToTask(dbSession, taskDto, characteristics);
       queueStatus.addInProgress();
       return Optional.of(task);
     }
index 897267552eeea19313de0337dddf1abf0dc565bb..4de52967eb51a797df4bce992684621686c1cb60 100644 (file)
@@ -108,8 +108,8 @@ public class NextPendingTaskPicker {
   }
 
   private static List<PrOrBranchTask> filterOldestPerProject(List<PrOrBranchTask> queuedPrOrBranches) {
-    Set<String> mainComponentUuidsSeen = new HashSet<>();
-    return queuedPrOrBranches.stream().filter(t -> mainComponentUuidsSeen.add(t.getMainComponentUuid())).toList();
+    Set<String> entityUuidsSeen = new HashSet<>();
+    return queuedPrOrBranches.stream().filter(t -> entityUuidsSeen.add(t.getEntityUuid())).toList();
   }
 
   /**
@@ -120,9 +120,9 @@ public class NextPendingTaskPicker {
    * This method returns the longest waiting branch in the queue which can be scheduled concurrently with pull requests.
    */
   private static boolean canRunBranch(PrOrBranchTask task, List<PrOrBranchTask> inProgress) {
-    String mainComponentUuid = task.getMainComponentUuid();
+    String entityUuid = task.getEntityUuid();
     List<PrOrBranchTask> sameComponentTasks = inProgress.stream()
-      .filter(t -> t.getMainComponentUuid().equals(mainComponentUuid))
+      .filter(t -> t.getEntityUuid().equals(entityUuid))
       .toList();
     //we can peek branch analysis task only if all the other in progress tasks for this component uuid are pull requests
     return sameComponentTasks.stream().map(PrOrBranchTask::getBranchType).allMatch(s -> Objects.equals(s, PULL_REQUEST));
@@ -135,7 +135,7 @@ public class NextPendingTaskPicker {
   private static boolean canRunPr(PrOrBranchTask task, List<PrOrBranchTask> inProgress) {
     // return true unless the same PR is already in progress
     return inProgress.stream()
-      .noneMatch(pr -> pr.getMainComponentUuid().equals(task.getMainComponentUuid()) && Objects.equals(pr.getBranchType(), PULL_REQUEST) &&
+      .noneMatch(pr -> pr.getEntityUuid().equals(task.getEntityUuid()) && Objects.equals(pr.getBranchType(), PULL_REQUEST) &&
         Objects.equals(pr.getComponentUuid(), (task.getComponentUuid())));
   }
 }
index a5f5d0e728db852a956dca39a3872add7cbecf5a..c396d63749626416ce5c383e7f85ddac35188444 100644 (file)
@@ -270,7 +270,7 @@ public class CeWorkerImpl implements CeWorker {
   private static Profiler startLogProfiler(CeTask task) {
     Profiler profiler = Profiler.create(LOG)
       .logTimeLast(true)
-      .addContext("project", task.getMainComponent().flatMap(CeTask.Component::getKey).orElse(null))
+      .addContext("project", task.getEntity().flatMap(CeTask.Component::getKey).orElse(null))
       .addContext("type", task.getType());
     for (Map.Entry<String, String> characteristic : task.getCharacteristics().entrySet()) {
       profiler.addContext(characteristic.getKey(), characteristic.getValue());
index bf3e7f97514c8f42cf6923c7b37f70654888f1ff..90d96fc361edebc24f493053901832553741cff1 100644 (file)
@@ -105,11 +105,13 @@ public class CeTaskProcessorRepositoryImplTest {
 
   private static CeTask createCeTask(String ceTaskType, String key) {
     CeTask.Component component = new CeTask.Component("uuid_" + key, key, "name_" + key);
+    CeTask.Component entity = new CeTask.Component("uuid_entity_" + key, key, "name_" + key);
+
     return new CeTask.Builder()
       .setType(ceTaskType)
       .setUuid("task_uuid_" + key)
       .setComponent(component)
-      .setMainComponent(component)
+      .setEntity(entity)
       .build();
   }
 
index 5a45c0e42e194e3121cff00fedaf2842fb0bf3a5..bcd4c1160d7b2c969cf3edd2674170a92ea5bb1b 100644 (file)
@@ -67,7 +67,7 @@ import static org.sonar.db.ce.CeTaskTypes.REPORT;
 @RunWith(DataProviderRunner.class)
 public class CeActivityDaoIT {
 
-  private static final String MAINCOMPONENT_1 = randomAlphabetic(12);
+  private static final String ENTITY_1 = randomAlphabetic(12);
   private static final String MAINCOMPONENT_2 = randomAlphabetic(13);
   private static final String COMPONENT_1 = randomAlphabetic(14);
 
@@ -89,14 +89,14 @@ public class CeActivityDaoIT {
 
   @Test
   public void test_insert() {
-    CeActivityDto inserted = insert("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, SUCCESS);
+    CeActivityDto inserted = insert("TASK_1", REPORT, COMPONENT_1, ENTITY_1, SUCCESS);
 
     Optional<CeActivityDto> saved = underTest.selectByUuid(db.getSession(), "TASK_1");
     assertThat(saved).isPresent();
     CeActivityDto dto = saved.get();
     assertThat(dto.getUuid()).isEqualTo("TASK_1");
     assertThat(dto.getNodeName()).isEqualTo(NODE_NAME);
-    assertThat(dto.getMainComponentUuid()).isEqualTo(MAINCOMPONENT_1);
+    assertThat(dto.getEntityUuid()).isEqualTo(ENTITY_1);
     assertThat(dto.getComponentUuid()).isEqualTo(COMPONENT_1);
     assertThat(dto.getStatus()).isEqualTo(SUCCESS);
     assertThat(dto.getSubmitterUuid()).isEqualTo("submitter uuid");
@@ -105,7 +105,7 @@ public class CeActivityDaoIT {
     assertThat(dto.getIsLast()).isTrue();
     assertThat(dto.getMainIsLast()).isTrue();
     assertThat(dto.getIsLastKey()).isEqualTo("REPORT" + COMPONENT_1);
-    assertThat(dto.getMainIsLastKey()).isEqualTo("REPORT" + MAINCOMPONENT_1);
+    assertThat(dto.getMainIsLastKey()).isEqualTo("REPORT" + ENTITY_1);
     assertThat(dto.getCreatedAt()).isEqualTo(INITIAL_TIME + 1);
     assertThat(dto.getStartedAt()).isEqualTo(1_500_000_000_000L);
     assertThat(dto.getExecutedAt()).isEqualTo(1_500_000_000_500L);
@@ -362,7 +362,7 @@ public class CeActivityDaoIT {
 
   @Test
   public void test_insert_of_errorMessage_of_1_000_chars() {
-    CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED)
+    CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, ENTITY_1, FAILED)
       .setErrorMessage(Strings.repeat("x", 1_000));
     underTest.insert(db.getSession(), dto);
 
@@ -373,7 +373,7 @@ public class CeActivityDaoIT {
   @Test
   public void test_insert_of_errorMessage_of_1_001_chars_is_truncated_to_1000() {
     String expected = Strings.repeat("x", 1_000);
-    CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED)
+    CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, ENTITY_1, FAILED)
       .setErrorMessage(expected + "y");
     underTest.insert(db.getSession(), dto);
 
@@ -383,7 +383,7 @@ public class CeActivityDaoIT {
 
   @Test
   public void test_insert_error_message_and_stacktrace() {
-    CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED)
+    CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, ENTITY_1, FAILED)
       .setErrorStacktrace("error stack");
     underTest.insert(db.getSession(), dto);
 
@@ -396,7 +396,7 @@ public class CeActivityDaoIT {
 
   @Test
   public void test_insert_error_message_only() {
-    CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED);
+    CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, ENTITY_1, FAILED);
     underTest.insert(db.getSession(), dto);
 
     Optional<CeActivityDto> saved = underTest.selectByUuid(db.getSession(), "TASK_1");
@@ -408,7 +408,7 @@ public class CeActivityDaoIT {
   @Test
   public void insert_must_set_relevant_is_last_field() {
     // only a single task on MAINCOMPONENT_1 -> is_last=true
-    insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
+    insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
     assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").get().getIsLast()).isTrue();
 
     // only a single task on MAINCOMPONENT_2 -> is_last=true
@@ -416,13 +416,13 @@ public class CeActivityDaoIT {
     assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue();
 
     // two tasks on MAINCOMPONENT_1, the most recent one is TASK_3
-    insert("TASK_3", REPORT, MAINCOMPONENT_1, FAILED);
+    insert("TASK_3", REPORT, ENTITY_1, FAILED);
     assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").get().getIsLast()).isFalse();
     assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue();
     assertThat(underTest.selectByUuid(db.getSession(), "TASK_3").get().getIsLast()).isTrue();
 
     // inserting a cancelled task does not change the last task
-    insert("TASK_4", REPORT, MAINCOMPONENT_1, CANCELED);
+    insert("TASK_4", REPORT, ENTITY_1, CANCELED);
     assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").get().getIsLast()).isFalse();
     assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue();
     assertThat(underTest.selectByUuid(db.getSession(), "TASK_3").get().getIsLast()).isTrue();
@@ -431,8 +431,8 @@ public class CeActivityDaoIT {
 
   @Test
   public void test_selectByQuery() {
-    insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
-    insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
+    insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
+    insert("TASK_2", REPORT, ENTITY_1, FAILED);
     insert("TASK_3", REPORT, MAINCOMPONENT_2, SUCCESS);
     insert("TASK_4", "views", null, SUCCESS);
 
@@ -442,7 +442,7 @@ public class CeActivityDaoIT {
     assertThat(dtos).extracting("uuid").containsExactly("TASK_4", "TASK_3", "TASK_2", "TASK_1");
 
     // select by component uuid
-    query = new CeTaskQuery().setMainComponentUuid(MAINCOMPONENT_1);
+    query = new CeTaskQuery().setEntityUuid(ENTITY_1);
     dtos = underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100));
     assertThat(dtos).extracting("uuid").containsExactly("TASK_2", "TASK_1");
 
@@ -460,7 +460,7 @@ public class CeActivityDaoIT {
     assertThat(dtos).extracting("uuid").containsExactly("TASK_4");
 
     // select by multiple conditions
-    query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setMainComponentUuid(MAINCOMPONENT_1);
+    query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setEntityUuid(ENTITY_1);
     dtos = underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100));
     assertThat(dtos).extracting("uuid").containsExactly("TASK_2");
   }
@@ -468,9 +468,9 @@ public class CeActivityDaoIT {
   @Test
   public void test_selectByQuery_verify_order_if_same_date() {
     system2.setNow(INITIAL_TIME);
-    insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
+    insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
     system2.setNow(INITIAL_TIME);
-    insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
+    insert("TASK_2", REPORT, ENTITY_1, FAILED);
     system2.setNow(INITIAL_TIME);
     insert("TASK_3", REPORT, MAINCOMPONENT_2, SUCCESS);
     system2.setNow(INITIAL_TIME);
@@ -482,7 +482,7 @@ public class CeActivityDaoIT {
     assertThat(dtos).extracting("uuid").containsExactly("TASK_4", "TASK_3", "TASK_2", "TASK_1");
 
     // select by component uuid
-    query = new CeTaskQuery().setMainComponentUuid(MAINCOMPONENT_1);
+    query = new CeTaskQuery().setEntityUuid(ENTITY_1);
     dtos = underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100));
     assertThat(dtos).extracting("uuid").containsExactly("TASK_2", "TASK_1");
 
@@ -500,17 +500,17 @@ public class CeActivityDaoIT {
     assertThat(dtos).extracting("uuid").containsExactly("TASK_4");
 
     // select by multiple conditions
-    query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setMainComponentUuid(MAINCOMPONENT_1);
+    query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setEntityUuid(ENTITY_1);
     dtos = underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100));
     assertThat(dtos).extracting("uuid").containsExactly("TASK_2");
   }
 
   @Test
   public void selectByQuery_does_not_populate_errorStacktrace_field() {
-    insert("TASK_1", REPORT, MAINCOMPONENT_1, FAILED);
-    underTest.insert(db.getSession(), createActivityDto("TASK_2", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED).setErrorStacktrace("some stack"));
+    insert("TASK_1", REPORT, ENTITY_1, FAILED);
+    underTest.insert(db.getSession(), createActivityDto("TASK_2", REPORT, COMPONENT_1, ENTITY_1, FAILED).setErrorStacktrace("some stack"));
 
-    List<CeActivityDto> dtos = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setMainComponentUuid(MAINCOMPONENT_1), forPage(1).andSize(100));
+    List<CeActivityDto> dtos = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setEntityUuid(ENTITY_1), forPage(1).andSize(100));
 
     assertThat(dtos)
       .hasSize(2)
@@ -519,13 +519,13 @@ public class CeActivityDaoIT {
 
   @Test
   public void selectByQuery_populates_hasScannerContext_flag() {
-    insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
+    insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
     CeActivityDto dto2 = insert("TASK_2", REPORT, MAINCOMPONENT_2, SUCCESS);
     insertScannerContext(dto2.getUuid());
 
-    CeActivityDto dto = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setMainComponentUuid(MAINCOMPONENT_1), forPage(1).andSize(100)).iterator().next();
+    CeActivityDto dto = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setEntityUuid(ENTITY_1), forPage(1).andSize(100)).iterator().next();
     assertThat(dto.isHasScannerContext()).isFalse();
-    dto = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setMainComponentUuid(MAINCOMPONENT_2), forPage(1).andSize(100)).iterator().next();
+    dto = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setEntityUuid(MAINCOMPONENT_2), forPage(1).andSize(100)).iterator().next();
     assertThat(dto.isHasScannerContext()).isTrue();
   }
 
@@ -550,7 +550,7 @@ public class CeActivityDaoIT {
       .containsExactly(tuple("TASK_4", 60), tuple("TASK_3", 10), tuple("TASK_2", 30), tuple("TASK_1", moreThan1));
 
     // select by component uuid
-    query = new CeTaskQuery().setMainComponentUuid("PROJECT_1");
+    query = new CeTaskQuery().setEntityUuid("PROJECT_1");
     assertThat(underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100)))
       .extracting(CeActivityDto::getUuid, ceActivityDto -> ceActivityDto.getCeTaskMessageDtos().size())
       .containsExactly(tuple("TASK_2", 30), tuple("TASK_1", moreThan1));
@@ -572,7 +572,7 @@ public class CeActivityDaoIT {
       .containsExactly(tuple("TASK_4", 60));
 
     // select by multiple conditions
-    query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setMainComponentUuid("PROJECT_1");
+    query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setEntityUuid("PROJECT_1");
     assertThat(underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100)))
       .extracting(CeActivityDto::getUuid, ceActivityDto -> ceActivityDto.getCeTaskMessageDtos().size())
       .containsExactly(tuple("TASK_2", 30));
@@ -593,8 +593,8 @@ public class CeActivityDaoIT {
 
   @Test
   public void selectByQuery_is_paginated_and_return_results_sorted_from_last_to_first() {
-    insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
-    insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
+    insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
+    insert("TASK_2", REPORT, ENTITY_1, FAILED);
     insert("TASK_3", REPORT, MAINCOMPONENT_2, SUCCESS);
     insert("TASK_4", "views", null, SUCCESS);
 
@@ -609,10 +609,10 @@ public class CeActivityDaoIT {
 
   @Test
   public void selectByQuery_no_results_if_shortcircuited_by_component_uuids() {
-    insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
+    insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
 
     CeTaskQuery query = new CeTaskQuery();
-    query.setMainComponentUuids(Collections.emptyList());
+    query.setEntityUuids(Collections.emptyList());
     assertThat(underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(1))).isEmpty();
   }
 
@@ -695,8 +695,8 @@ public class CeActivityDaoIT {
 
   @Test
   public void selectOlderThan_does_not_populate_errorStacktrace() {
-    insert("TASK_1", REPORT, MAINCOMPONENT_1, FAILED);
-    underTest.insert(db.getSession(), createActivityDto("TASK_2", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED).setErrorStacktrace("some stack"));
+    insert("TASK_1", REPORT, ENTITY_1, FAILED);
+    underTest.insert(db.getSession(), createActivityDto("TASK_2", REPORT, COMPONENT_1, ENTITY_1, FAILED).setErrorStacktrace("some stack"));
 
     List<CeActivityDto> dtos = underTest.selectOlderThan(db.getSession(), system2.now() + 1_000_000L);
 
@@ -722,9 +722,9 @@ public class CeActivityDaoIT {
 
   @Test
   public void deleteByUuids() {
-    insert("TASK_1", "REPORT", MAINCOMPONENT_1, SUCCESS);
-    insert("TASK_2", "REPORT", MAINCOMPONENT_1, SUCCESS);
-    insert("TASK_3", "REPORT", MAINCOMPONENT_1, SUCCESS);
+    insert("TASK_1", "REPORT", ENTITY_1, SUCCESS);
+    insert("TASK_2", "REPORT", ENTITY_1, SUCCESS);
+    insert("TASK_3", "REPORT", ENTITY_1, SUCCESS);
 
     underTest.deleteByUuids(db.getSession(), ImmutableSet.of("TASK_1", "TASK_3"));
     assertThat(underTest.selectByUuid(db.getSession(), "TASK_1")).isEmpty();
@@ -734,7 +734,7 @@ public class CeActivityDaoIT {
 
   @Test
   public void deleteByUuids_does_nothing_if_uuid_does_not_exist() {
-    insert("TASK_1", "REPORT", MAINCOMPONENT_1, SUCCESS);
+    insert("TASK_1", "REPORT", ENTITY_1, SUCCESS);
 
     // must not fail
     underTest.deleteByUuids(db.getSession(), singleton("TASK_2"));
@@ -743,48 +743,48 @@ public class CeActivityDaoIT {
   }
 
   @Test
-  public void count_last_by_status_and_main_component_uuid() {
-    insert("TASK_1", CeTaskTypes.REPORT, MAINCOMPONENT_1, SUCCESS);
+  public void count_last_by_status_and_entity_uuid() {
+    insert("TASK_1", CeTaskTypes.REPORT, ENTITY_1, SUCCESS);
     // component 2
     insert("TASK_2", CeTaskTypes.REPORT, MAINCOMPONENT_2, SUCCESS);
     // status failed
-    insert("TASK_3", CeTaskTypes.REPORT, MAINCOMPONENT_1, FAILED);
+    insert("TASK_3", CeTaskTypes.REPORT, ENTITY_1, FAILED);
     // status canceled
-    insert("TASK_4", CeTaskTypes.REPORT, MAINCOMPONENT_1, CANCELED);
-    insert("TASK_5", CeTaskTypes.REPORT, MAINCOMPONENT_1, SUCCESS);
+    insert("TASK_4", CeTaskTypes.REPORT, ENTITY_1, CANCELED);
+    insert("TASK_5", CeTaskTypes.REPORT, ENTITY_1, SUCCESS);
     db.commit();
 
-    assertThat(underTest.countLastByStatusAndMainComponentUuid(dbSession, SUCCESS, MAINCOMPONENT_1)).isOne();
-    assertThat(underTest.countLastByStatusAndMainComponentUuid(dbSession, SUCCESS, null)).isEqualTo(2);
+    assertThat(underTest.countLastByStatusAndEntityUuid(dbSession, SUCCESS, ENTITY_1)).isOne();
+    assertThat(underTest.countLastByStatusAndEntityUuid(dbSession, SUCCESS, null)).isEqualTo(2);
   }
 
   @Test
   public void selectLastByComponentUuidAndTaskType_returns_task_of_given_type() {
-    insert("TASK_1", "VIEW_REFRESH", MAINCOMPONENT_1, MAINCOMPONENT_1, SUCCESS);
-    insert("TASK_2", CeTaskTypes.REPORT, MAINCOMPONENT_1, MAINCOMPONENT_1, SUCCESS);
-    insert("TASK_3", "PROJECT_EXPORT", MAINCOMPONENT_1, MAINCOMPONENT_1, SUCCESS);
-    insert("TASK_4", "PROJECT_IMPORT", MAINCOMPONENT_1, MAINCOMPONENT_1, SUCCESS);
+    insert("TASK_1", "VIEW_REFRESH", ENTITY_1, ENTITY_1, SUCCESS);
+    insert("TASK_2", CeTaskTypes.REPORT, ENTITY_1, ENTITY_1, SUCCESS);
+    insert("TASK_3", "PROJECT_EXPORT", ENTITY_1, ENTITY_1, SUCCESS);
+    insert("TASK_4", "PROJECT_IMPORT", ENTITY_1, ENTITY_1, SUCCESS);
     db.commit();
 
-    Optional<CeActivityDto> result = underTest.selectLastByComponentUuidAndTaskType(db.getSession(), MAINCOMPONENT_1, "PROJECT_EXPORT");
+    Optional<CeActivityDto> result = underTest.selectLastByComponentUuidAndTaskType(db.getSession(), ENTITY_1, "PROJECT_EXPORT");
 
     assertThat(result).hasValueSatisfying(value -> assertThat(value.getUuid()).isEqualTo("TASK_3"));
   }
 
   @Test
   public void selectLastByComponentUuidAndTaskType_returns_empty_if_task_of_given_type_does_not_exist() {
-    insert("TASK_1", CeTaskTypes.REPORT, MAINCOMPONENT_1, SUCCESS);
+    insert("TASK_1", CeTaskTypes.REPORT, ENTITY_1, SUCCESS);
     db.commit();
 
-    Optional<CeActivityDto> result = underTest.selectLastByComponentUuidAndTaskType(db.getSession(), MAINCOMPONENT_1, "PROJECT_EXPORT");
+    Optional<CeActivityDto> result = underTest.selectLastByComponentUuidAndTaskType(db.getSession(), ENTITY_1, "PROJECT_EXPORT");
 
     assertThat(result).isEmpty();
   }
 
   @Test
   public void selectByTaskType() {
-    insert("TASK_1", CeTaskTypes.REPORT, MAINCOMPONENT_1, SUCCESS);
-    insert("TASK_2", CeTaskTypes.BRANCH_ISSUE_SYNC, MAINCOMPONENT_1, SUCCESS);
+    insert("TASK_1", CeTaskTypes.REPORT, ENTITY_1, SUCCESS);
+    insert("TASK_2", CeTaskTypes.BRANCH_ISSUE_SYNC, ENTITY_1, SUCCESS);
     db.commit();
 
     assertThat(underTest.selectByTaskType(db.getSession(), CeTaskTypes.REPORT))
@@ -801,8 +801,8 @@ public class CeActivityDaoIT {
   public void hasAnyFailedOrCancelledIssueSyncTask() {
     assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isFalse();
 
-    insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
-    insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
+    insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
+    insert("TASK_2", REPORT, ENTITY_1, FAILED);
 
     ProjectDto projectDto1 = db.components().insertPrivateProject(
       branchDto -> branchDto.setNeedIssueSync(false), c -> {
@@ -855,26 +855,26 @@ public class CeActivityDaoIT {
     return insert(uuid, type, mainComponentUuid, mainComponentUuid, status);
   }
 
-  private CeActivityDto insertAndCommit(String uuid, String type, @Nullable String componentUuid, @Nullable String mainComponentUuid, CeActivityDto.Status status) {
-    CeActivityDto res = insert(uuid, type, componentUuid, mainComponentUuid, status);
+  private CeActivityDto insertAndCommit(String uuid, String type, @Nullable String componentUuid, @Nullable String entityUuid, CeActivityDto.Status status) {
+    CeActivityDto res = insert(uuid, type, componentUuid, entityUuid, status);
     db.commit();
     return res;
   }
 
-  private CeActivityDto insert(String uuid, String type, @Nullable String componentUuid, @Nullable String mainComponentUuid, CeActivityDto.Status status) {
-    CeActivityDto dto = createActivityDto(uuid, type, componentUuid, mainComponentUuid, status);
+  private CeActivityDto insert(String uuid, String type, @Nullable String componentUuid, @Nullable String entityUuid, CeActivityDto.Status status) {
+    CeActivityDto dto = createActivityDto(uuid, type, componentUuid, entityUuid, status);
     system2.tick();
     underTest.insert(db.getSession(), dto);
     return dto;
   }
 
-  private CeActivityDto createActivityDto(String uuid, String type, @Nullable String componentUuid, @Nullable String mainComponentUuid, CeActivityDto.Status status) {
+  private CeActivityDto createActivityDto(String uuid, String type, @Nullable String componentUuid, @Nullable String entityUuid, CeActivityDto.Status status) {
     CeQueueDto creating = new CeQueueDto();
     creating.setUuid(uuid);
     creating.setStatus(PENDING);
     creating.setTaskType(type);
     creating.setComponentUuid(componentUuid);
-    creating.setMainComponentUuid(mainComponentUuid);
+    creating.setEntityUuid(entityUuid);
     creating.setSubmitterUuid("submitter uuid");
     creating.setCreatedAt(system2.now());
 
index 0523341c9b2c387257518367aba2d07cf5c5fc55..6546c6c9c82e86ec34753621e36ddd970ed6d988 100644 (file)
@@ -58,8 +58,8 @@ public class CeQueueDaoIT {
   private static final long INIT_TIME = 1_450_000_000_000L;
   private static final String TASK_UUID_1 = "TASK_1";
   private static final String TASK_UUID_2 = "TASK_2";
-  private static final String MAIN_COMPONENT_UUID_1 = "PROJECT_1";
-  private static final String MAIN_COMPONENT_UUID_2 = "PROJECT_2";
+  private static final String ENTITY_UUID_1 = "PROJECT_1";
+  private static final String ENTITY_UUID_2 = "PROJECT_2";
   private static final String COMPONENT_UUID_1 = "BRANCH_1";
   private static final String TASK_UUID_3 = "TASK_3";
   private static final String SELECT_QUEUE_UUID_AND_STATUS_QUERY = "select uuid,status from ce_queue";
@@ -84,7 +84,7 @@ public class CeQueueDaoIT {
     long now = 1_334_333L;
     CeQueueDto dto = new CeQueueDto()
       .setTaskType(CeTaskTypes.REPORT)
-      .setComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setComponentUuid(ENTITY_UUID_1)
       .setStatus(PENDING)
       .setSubmitterUuid(SUBMITTER_LOGIN);
 
@@ -104,7 +104,7 @@ public class CeQueueDaoIT {
         CeQueueDto saved = underTest.selectByUuid(db.getSession(), uuid).get();
         assertThat(saved.getUuid()).isEqualTo(uuid);
         assertThat(saved.getTaskType()).isEqualTo(CeTaskTypes.REPORT);
-        assertThat(saved.getComponentUuid()).isEqualTo(MAIN_COMPONENT_UUID_1);
+        assertThat(saved.getComponentUuid()).isEqualTo(ENTITY_UUID_1);
         assertThat(saved.getStatus()).isEqualTo(PENDING);
         assertThat(saved.getSubmitterUuid()).isEqualTo(SUBMITTER_LOGIN);
         assertThat(saved.getWorkerUuid()).isNull();
@@ -115,7 +115,7 @@ public class CeQueueDaoIT {
     CeQueueDto saved = underTest.selectByUuid(db.getSession(), uuid4).get();
     assertThat(saved.getUuid()).isEqualTo(uuid4);
     assertThat(saved.getTaskType()).isEqualTo(CeTaskTypes.REPORT);
-    assertThat(saved.getComponentUuid()).isEqualTo(MAIN_COMPONENT_UUID_1);
+    assertThat(saved.getComponentUuid()).isEqualTo(ENTITY_UUID_1);
     assertThat(saved.getStatus()).isEqualTo(PENDING);
     assertThat(saved.getSubmitterUuid()).isEqualTo(SUBMITTER_LOGIN);
     assertThat(saved.getWorkerUuid()).isNull();
@@ -126,13 +126,13 @@ public class CeQueueDaoIT {
 
   @Test
   public void test_selectByUuid() {
-    CeQueueDto ceQueueDto = insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1);
+    CeQueueDto ceQueueDto = insertPending(TASK_UUID_1, ENTITY_UUID_1);
 
     assertThat(underTest.selectByUuid(db.getSession(), "TASK_UNKNOWN")).isEmpty();
     CeQueueDto saved = underTest.selectByUuid(db.getSession(), TASK_UUID_1).get();
     assertThat(saved.getUuid()).isEqualTo(TASK_UUID_1);
     assertThat(saved.getTaskType()).isEqualTo(CeTaskTypes.REPORT);
-    assertThat(saved.getMainComponentUuid()).isEqualTo(MAIN_COMPONENT_UUID_1);
+    assertThat(saved.getEntityUuid()).isEqualTo(ENTITY_UUID_1);
     assertThat(saved.getComponentUuid()).isEqualTo(ceQueueDto.getComponentUuid());
     assertThat(saved.getStatus()).isEqualTo(PENDING);
     assertThat(saved.getSubmitterUuid()).isEqualTo("henri");
@@ -144,19 +144,19 @@ public class CeQueueDaoIT {
 
   @Test
   public void test_selectByMainComponentUuid() {
-    insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1);
-    insertPending(TASK_UUID_2, MAIN_COMPONENT_UUID_1);
+    insertPending(TASK_UUID_1, ENTITY_UUID_1);
+    insertPending(TASK_UUID_2, ENTITY_UUID_1);
     insertPending(TASK_UUID_3, "PROJECT_2");
 
-    assertThat(underTest.selectByMainComponentUuid(db.getSession(), "UNKNOWN")).isEmpty();
-    assertThat(underTest.selectByMainComponentUuid(db.getSession(), MAIN_COMPONENT_UUID_1)).extracting("uuid").containsOnly(TASK_UUID_1, TASK_UUID_2);
-    assertThat(underTest.selectByMainComponentUuid(db.getSession(), "PROJECT_2")).extracting("uuid").containsOnly(TASK_UUID_3);
+    assertThat(underTest.selectByEntityUuid(db.getSession(), "UNKNOWN")).isEmpty();
+    assertThat(underTest.selectByEntityUuid(db.getSession(), ENTITY_UUID_1)).extracting("uuid").containsOnly(TASK_UUID_1, TASK_UUID_2);
+    assertThat(underTest.selectByEntityUuid(db.getSession(), "PROJECT_2")).extracting("uuid").containsOnly(TASK_UUID_3);
   }
 
   @Test
   public void test_selectAllInAscOrder() {
-    insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1);
-    insertPending(TASK_UUID_2, MAIN_COMPONENT_UUID_1);
+    insertPending(TASK_UUID_1, ENTITY_UUID_1);
+    insertPending(TASK_UUID_2, ENTITY_UUID_1);
     insertPending(TASK_UUID_3, "PROJECT_2");
 
     assertThat(underTest.selectAllInAscOrder(db.getSession())).extracting("uuid").containsOnly(TASK_UUID_1, TASK_UUID_2, TASK_UUID_3);
@@ -182,17 +182,17 @@ public class CeQueueDaoIT {
     insertPending("p1", dto -> {
       dto.setCreatedAt(time);
       dto.setUpdatedAt(time + 500);
-      dto.setMainComponentUuid("c1");
+      dto.setEntityUuid("c1");
     });
     insertPending("p2", dto -> {
       dto.setCreatedAt(time + 1000);
       dto.setUpdatedAt(time + 2000);
-      dto.setMainComponentUuid("c2");
+      dto.setEntityUuid("c2");
     });
 
-    makeInProgress("w1", alwaysIncreasingSystem2.now(), insertPending("i1", dto -> dto.setMainComponentUuid("c3")));
+    makeInProgress("w1", alwaysIncreasingSystem2.now(), insertPending("i1", dto -> dto.setEntityUuid("c3")));
 
-    assertThat(underTest.selectCreationDateOfOldestPendingByMainComponentUuid(db.getSession(), null))
+    assertThat(underTest.selectCreationDateOfOldestPendingByEntityUuid(db.getSession(), null))
       .isEqualTo(Optional.of(time));
   }
 
@@ -202,29 +202,29 @@ public class CeQueueDaoIT {
     insertPending("p1", dto -> {
       dto.setCreatedAt(time);
       dto.setUpdatedAt(time + 500);
-      dto.setMainComponentUuid("c2");
+      dto.setEntityUuid("c2");
     });
     insertPending("p2", dto -> {
       dto.setCreatedAt(time + 2000);
       dto.setUpdatedAt(time + 3000);
-      dto.setMainComponentUuid("c1");
+      dto.setEntityUuid("c1");
     });
     insertPending("p3", dto -> {
       dto.setCreatedAt(time + 4000);
       dto.setUpdatedAt(time + 5000);
-      dto.setMainComponentUuid("c1");
+      dto.setEntityUuid("c1");
     });
 
-    makeInProgress("w1", alwaysIncreasingSystem2.now(), insertPending("i1", dto -> dto.setMainComponentUuid("c1")));
+    makeInProgress("w1", alwaysIncreasingSystem2.now(), insertPending("i1", dto -> dto.setEntityUuid("c1")));
 
-    assertThat(underTest.selectCreationDateOfOldestPendingByMainComponentUuid(db.getSession(), "c1"))
+    assertThat(underTest.selectCreationDateOfOldestPendingByEntityUuid(db.getSession(), "c1"))
       .isEqualTo(Optional.of(time + 2000));
   }
 
   @Test
   public void selectCreationDateOfOldestPendingByMainComponentUuid_returns_empty_when_no_pending_tasks() {
     makeInProgress("w1", alwaysIncreasingSystem2.now(), insertPending("i1"));
-    assertThat(underTest.selectCreationDateOfOldestPendingByMainComponentUuid(db.getSession(), null))
+    assertThat(underTest.selectCreationDateOfOldestPendingByEntityUuid(db.getSession(), null))
       .isEmpty();
   }
 
@@ -244,8 +244,8 @@ public class CeQueueDaoIT {
 
   @Test
   public void test_delete() {
-    insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1);
-    insertPending(TASK_UUID_2, MAIN_COMPONENT_UUID_1);
+    insertPending(TASK_UUID_1, ENTITY_UUID_1);
+    insertPending(TASK_UUID_2, ENTITY_UUID_1);
 
     int deletedCount = underTest.deleteByUuid(db.getSession(), "UNKNOWN");
     assertThat(deletedCount).isZero();
@@ -262,7 +262,7 @@ public class CeQueueDaoIT {
 
   @Test
   public void test_delete_with_expected_status() {
-    insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1);
+    insertPending(TASK_UUID_1, ENTITY_UUID_1);
     insertInProgress(TASK_UUID_2, "workerUuid", System2.INSTANCE.now());
 
     int deletedCount = underTest.deleteByUuid(db.getSession(), "UNKNOWN", null);
@@ -425,42 +425,42 @@ public class CeQueueDaoIT {
   public void select_by_query() {
     // task status not in query
     insertPending(newCeQueueDto(TASK_UUID_1)
-      .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setEntityUuid(ENTITY_UUID_1)
       .setStatus(IN_PROGRESS)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(100_000L));
 
     // too early
     insertPending(newCeQueueDto(TASK_UUID_3)
-      .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setEntityUuid(ENTITY_UUID_1)
       .setStatus(PENDING)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(90_000L));
 
     // task type not in query
     insertPending(newCeQueueDto("TASK_4")
-      .setMainComponentUuid("PROJECT_2")
+      .setEntityUuid("PROJECT_2")
       .setStatus(PENDING)
       .setTaskType("ANOTHER_TYPE")
       .setCreatedAt(100_000L));
 
     // correct
     insertPending(newCeQueueDto(TASK_UUID_2)
-      .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setEntityUuid(ENTITY_UUID_1)
       .setStatus(PENDING)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(100_000L));
 
     // correct submitted later
     insertPending(newCeQueueDto("TASK_5")
-      .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setEntityUuid(ENTITY_UUID_1)
       .setStatus(PENDING)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(120_000L));
 
     // select by component uuid, status, task type and minimum submitted at
     CeTaskQuery query = new CeTaskQuery()
-      .setMainComponentUuids(newArrayList(MAIN_COMPONENT_UUID_1, "PROJECT_2"))
+      .setEntityUuids(newArrayList(ENTITY_UUID_1, "PROJECT_2"))
       .setStatuses(singletonList(PENDING.name()))
       .setType(CeTaskTypes.REPORT)
       .setMinSubmittedAt(100_000L);
@@ -475,7 +475,7 @@ public class CeQueueDaoIT {
   @Test
   public void select_by_query_returns_empty_list_when_only_current() {
     insertPending(newCeQueueDto(TASK_UUID_1)
-      .setComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setComponentUuid(ENTITY_UUID_1)
       .setStatus(IN_PROGRESS)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(100_000L));
@@ -492,7 +492,7 @@ public class CeQueueDaoIT {
   @Test
   public void select_by_query_returns_empty_list_when_max_submitted_at() {
     insertPending(newCeQueueDto(TASK_UUID_1)
-      .setComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setComponentUuid(ENTITY_UUID_1)
       .setStatus(IN_PROGRESS)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(100_000L));
@@ -507,14 +507,14 @@ public class CeQueueDaoIT {
   }
 
   @Test
-  public void select_by_query_returns_empty_list_when_empty_list_of_main_component_uuid() {
+  public void select_by_query_returns_empty_list_when_empty_list_of_entity_uuid() {
     insertPending(newCeQueueDto(TASK_UUID_1)
-      .setComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setComponentUuid(ENTITY_UUID_1)
       .setStatus(IN_PROGRESS)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(100_000L));
 
-    CeTaskQuery query = new CeTaskQuery().setMainComponentUuids(Collections.emptyList());
+    CeTaskQuery query = new CeTaskQuery().setEntityUuids(Collections.emptyList());
 
     List<CeQueueDto> result = underTest.selectByQueryInDescOrder(db.getSession(), query, 1_000);
     int total = underTest.countByQuery(db.getSession(), query);
@@ -524,57 +524,57 @@ public class CeQueueDaoIT {
   }
 
   @Test
-  public void count_by_status_and_main_component_uuid() {
+  public void count_by_status_and_entity_uuid() {
     // task retrieved in the queue
     insertPending(newCeQueueDto(TASK_UUID_1)
-      .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setEntityUuid(ENTITY_UUID_1)
       .setStatus(IN_PROGRESS)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(100_000L));
     // on component uuid 2, not returned
     insertPending(newCeQueueDto(TASK_UUID_2)
-      .setMainComponentUuid(MAIN_COMPONENT_UUID_2)
+      .setEntityUuid(ENTITY_UUID_2)
       .setStatus(IN_PROGRESS)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(100_000L));
     // pending status, not returned
     insertPending(newCeQueueDto(TASK_UUID_3)
-      .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setEntityUuid(ENTITY_UUID_1)
       .setStatus(PENDING)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(100_000L));
 
-    assertThat(underTest.countByStatusAndMainComponentUuid(db.getSession(), IN_PROGRESS, MAIN_COMPONENT_UUID_1)).isOne();
+    assertThat(underTest.countByStatusAndEntityUuid(db.getSession(), IN_PROGRESS, ENTITY_UUID_1)).isOne();
     assertThat(underTest.countByStatus(db.getSession(), IN_PROGRESS)).isEqualTo(2);
   }
 
   @Test
-  public void count_by_status_and_main_component_uuids() {
+  public void count_by_status_and_entity_uuids() {
     // task retrieved in the queue
     insertPending(newCeQueueDto(TASK_UUID_1)
-      .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setEntityUuid(ENTITY_UUID_1)
       .setStatus(IN_PROGRESS)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(100_000L));
     // on component uuid 2, not returned
     insertPending(newCeQueueDto(TASK_UUID_2)
-      .setMainComponentUuid(MAIN_COMPONENT_UUID_2)
+      .setEntityUuid(ENTITY_UUID_2)
       .setStatus(IN_PROGRESS)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(100_000L));
     // pending status, not returned
     insertPending(newCeQueueDto(TASK_UUID_3)
-      .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setEntityUuid(ENTITY_UUID_1)
       .setStatus(PENDING)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(100_000L));
 
-    assertThat(underTest.countByStatusAndMainComponentUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of())).isEmpty();
-    assertThat(underTest.countByStatusAndMainComponentUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of("non existing component uuid"))).isEmpty();
-    assertThat(underTest.countByStatusAndMainComponentUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of(MAIN_COMPONENT_UUID_1, MAIN_COMPONENT_UUID_2)))
-      .containsOnly(entry(MAIN_COMPONENT_UUID_1, 1), entry(MAIN_COMPONENT_UUID_2, 1));
-    assertThat(underTest.countByStatusAndMainComponentUuids(db.getSession(), PENDING, ImmutableSet.of(MAIN_COMPONENT_UUID_1, MAIN_COMPONENT_UUID_2)))
-      .containsOnly(entry(MAIN_COMPONENT_UUID_1, 1));
+    assertThat(underTest.countByStatusAndEntityUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of())).isEmpty();
+    assertThat(underTest.countByStatusAndEntityUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of("non existing component uuid"))).isEmpty();
+    assertThat(underTest.countByStatusAndEntityUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of(ENTITY_UUID_1, ENTITY_UUID_2)))
+      .containsOnly(entry(ENTITY_UUID_1, 1), entry(ENTITY_UUID_2, 1));
+    assertThat(underTest.countByStatusAndEntityUuids(db.getSession(), PENDING, ImmutableSet.of(ENTITY_UUID_1, ENTITY_UUID_2)))
+      .containsOnly(entry(ENTITY_UUID_1, 1));
     assertThat(underTest.countByStatus(db.getSession(), IN_PROGRESS)).isEqualTo(2);
   }
 
@@ -603,7 +603,7 @@ public class CeQueueDaoIT {
     assertThat(underTest.hasAnyIssueSyncTaskPendingOrInProgress(db.getSession())).isFalse();
 
     insertPending(newCeQueueDto(TASK_UUID_1)
-      .setComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setComponentUuid(ENTITY_UUID_1)
       .setStatus(PENDING)
       .setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC)
       .setCreatedAt(100_000L));
@@ -616,7 +616,7 @@ public class CeQueueDaoIT {
     assertThat(underTest.hasAnyIssueSyncTaskPendingOrInProgress(db.getSession())).isFalse();
 
     insertPending(newCeQueueDto(TASK_UUID_1)
-      .setComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setComponentUuid(ENTITY_UUID_1)
       .setStatus(IN_PROGRESS)
       .setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC)
       .setCreatedAt(100_000L));
@@ -628,13 +628,13 @@ public class CeQueueDaoIT {
   public void selectOldestPendingPrOrBranch_returns_oldest_100_pr_or_branch_tasks() {
     for (int i = 1; i < 110; i++) {
       insertPending(newCeQueueDto("task" + i)
-        .setComponentUuid(MAIN_COMPONENT_UUID_1).setStatus(PENDING).setTaskType(CeTaskTypes.REPORT).setCreatedAt(i));
+        .setComponentUuid(ENTITY_UUID_1).setStatus(PENDING).setTaskType(CeTaskTypes.REPORT).setCreatedAt(i));
     }
     for (int i = 1; i < 10; i++) {
       insertPending(newCeQueueDto("progress" + i)
-        .setComponentUuid(MAIN_COMPONENT_UUID_1).setStatus(IN_PROGRESS).setTaskType(CeTaskTypes.REPORT).setCreatedAt(i));
+        .setComponentUuid(ENTITY_UUID_1).setStatus(IN_PROGRESS).setTaskType(CeTaskTypes.REPORT).setCreatedAt(i));
       insertPending(newCeQueueDto("sync" + i)
-        .setComponentUuid(MAIN_COMPONENT_UUID_1).setStatus(PENDING).setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC).setCreatedAt(i));
+        .setComponentUuid(ENTITY_UUID_1).setStatus(PENDING).setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC).setCreatedAt(i));
     }
 
     List<PrOrBranchTask> prOrBranchTasks = underTest.selectOldestPendingPrOrBranch(db.getSession());
@@ -647,7 +647,7 @@ public class CeQueueDaoIT {
   public void selectOldestPendingPrOrBranch_returns_branch_branch_type_if_no_characteristics() {
     insertPending(newCeQueueDto(TASK_UUID_1)
       .setComponentUuid(COMPONENT_UUID_1)
-      .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setEntityUuid(ENTITY_UUID_1)
       .setStatus(PENDING)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(123L));
@@ -655,15 +655,15 @@ public class CeQueueDaoIT {
 
     assertThat(prOrBranchTasks).hasSize(1);
     assertThat(prOrBranchTasks.get(0))
-      .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getMainComponentUuid, PrOrBranchTask::getTaskType)
-      .containsExactly(BRANCH_KEY, COMPONENT_UUID_1, MAIN_COMPONENT_UUID_1, CeTaskTypes.REPORT);
+      .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getEntityUuid, PrOrBranchTask::getTaskType)
+      .containsExactly(BRANCH_KEY, COMPONENT_UUID_1, ENTITY_UUID_1, CeTaskTypes.REPORT);
   }
 
   @Test
   public void selectOldestPendingPrOrBranch_returns_branch_branch_type_if_unrelated_characteristics() {
     insertPending(newCeQueueDto(TASK_UUID_1)
       .setComponentUuid(COMPONENT_UUID_1)
-      .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setEntityUuid(ENTITY_UUID_1)
       .setStatus(PENDING)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(123L));
@@ -672,15 +672,15 @@ public class CeQueueDaoIT {
 
     assertThat(prOrBranchTasks).hasSize(1);
     assertThat(prOrBranchTasks.get(0))
-      .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getMainComponentUuid, PrOrBranchTask::getTaskType)
-      .containsExactly(BRANCH_KEY, COMPONENT_UUID_1, MAIN_COMPONENT_UUID_1, CeTaskTypes.REPORT);
+      .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getEntityUuid, PrOrBranchTask::getTaskType)
+      .containsExactly(BRANCH_KEY, COMPONENT_UUID_1, ENTITY_UUID_1, CeTaskTypes.REPORT);
   }
 
   @Test
   public void selectOldestPendingPrOrBranch_returns_all_fields() {
     insertPending(newCeQueueDto(TASK_UUID_1)
       .setComponentUuid(COMPONENT_UUID_1)
-      .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setEntityUuid(ENTITY_UUID_1)
       .setStatus(PENDING)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(123L));
@@ -690,15 +690,15 @@ public class CeQueueDaoIT {
 
     assertThat(prOrBranchTasks).hasSize(1);
     assertThat(prOrBranchTasks.get(0))
-      .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getMainComponentUuid, PrOrBranchTask::getTaskType)
-      .containsExactly(PULL_REQUEST, COMPONENT_UUID_1, MAIN_COMPONENT_UUID_1, CeTaskTypes.REPORT);
+      .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getEntityUuid, PrOrBranchTask::getTaskType)
+      .containsExactly(PULL_REQUEST, COMPONENT_UUID_1, ENTITY_UUID_1, CeTaskTypes.REPORT);
   }
 
   @Test
   public void selectInProgressWithCharacteristics_returns_all_fields() {
     insertPending(newCeQueueDto(TASK_UUID_1)
       .setComponentUuid(COMPONENT_UUID_1)
-      .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setEntityUuid(ENTITY_UUID_1)
       .setStatus(IN_PROGRESS)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(123L));
@@ -708,15 +708,15 @@ public class CeQueueDaoIT {
 
     assertThat(prOrBranchTasks).hasSize(1);
     assertThat(prOrBranchTasks.get(0))
-      .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getMainComponentUuid, PrOrBranchTask::getTaskType)
-      .containsExactly(PULL_REQUEST, COMPONENT_UUID_1, MAIN_COMPONENT_UUID_1, CeTaskTypes.REPORT);
+      .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getEntityUuid, PrOrBranchTask::getTaskType)
+      .containsExactly(PULL_REQUEST, COMPONENT_UUID_1, ENTITY_UUID_1, CeTaskTypes.REPORT);
   }
 
   @Test
   public void selectInProgressWithCharacteristics_returns_branch_branch_type_if_no_characteristics() {
     insertPending(newCeQueueDto(TASK_UUID_1)
       .setComponentUuid(COMPONENT_UUID_1)
-      .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+      .setEntityUuid(ENTITY_UUID_1)
       .setStatus(IN_PROGRESS)
       .setTaskType(CeTaskTypes.REPORT)
       .setCreatedAt(123L));
@@ -725,8 +725,8 @@ public class CeQueueDaoIT {
 
     assertThat(prOrBranchTasks).hasSize(1);
     assertThat(prOrBranchTasks.get(0))
-      .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getMainComponentUuid, PrOrBranchTask::getTaskType)
-      .containsExactly(BRANCH_KEY, COMPONENT_UUID_1, MAIN_COMPONENT_UUID_1, CeTaskTypes.REPORT);
+      .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getEntityUuid, PrOrBranchTask::getTaskType)
+      .containsExactly(BRANCH_KEY, COMPONENT_UUID_1, ENTITY_UUID_1, CeTaskTypes.REPORT);
   }
 
   private void insertPending(CeQueueDto dto) {
@@ -758,7 +758,7 @@ public class CeQueueDaoIT {
     CeQueueDto dto = new CeQueueDto();
     dto.setUuid(uuid);
     dto.setTaskType(CeTaskTypes.REPORT);
-    dto.setMainComponentUuid(mainComponentUuid);
+    dto.setEntityUuid(mainComponentUuid);
     dto.setComponentUuid("uuid_" + pendingComponentUuidGenerator++);
     dto.setStatus(PENDING);
     dto.setSubmitterUuid("henri");
index 674833e209e6514c56b8d0dc02f22713823dd9ae..f59c3b8a3d2041ba3b65db1add8fa41aefc22138 100644 (file)
@@ -34,6 +34,7 @@ import org.junit.Test;
 import org.mockito.internal.util.collections.Sets;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ProjectData;
@@ -55,7 +56,7 @@ import static org.sonar.db.measure.MeasureTesting.newLiveMeasure;
 public class LiveMeasureDaoIT {
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
 
   private final LiveMeasureDao underTest = db.getDbClient().liveMeasureDao();
   private MetricDto metric;
@@ -148,26 +149,27 @@ public class LiveMeasureDaoIT {
   public void selectForProjectsByMetricUuids() {
     MetricDto metric = db.measures().insertMetric();
     MetricDto metric2 = db.measures().insertMetric();
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
-    underTest.insert(db.getSession(), newLiveMeasure(project, metric).setValue(3.14).setData((String) null));
-    underTest.insert(db.getSession(), newLiveMeasure(project, metric2).setValue(4.54).setData((String) null));
-    underTest.insert(db.getSession(), newLiveMeasure(project2, metric).setValue(99.99).setData((String) null));
+    BranchDto projectBranch = db.components().insertPrivateProject().getMainBranchDto();
+    BranchDto project2Branch = db.components().insertPrivateProject().getMainBranchDto();
+    underTest.insert(db.getSession(), newLiveMeasure(projectBranch, metric).setValue(3.14).setData((String) null));
+    underTest.insert(db.getSession(), newLiveMeasure(projectBranch, metric2).setValue(4.54).setData((String) null));
+    underTest.insert(db.getSession(), newLiveMeasure(project2Branch, metric).setValue(99.99).setData((String) null));
 
-    List<LiveMeasureDto> selected = underTest.selectForProjectsByMetricUuids(db.getSession(), List.of(metric.getUuid(), metric2.getUuid()));
+    List<ProjectMainBranchLiveMeasureDto> selected = underTest.selectForProjectMainBranchesByMetricUuids(db.getSession(), List.of(metric.getUuid(), metric2.getUuid()));
     assertThat(selected)
-      .extracting(LiveMeasureDto::getComponentUuid, LiveMeasureDto::getProjectUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue, LiveMeasureDto::getDataAsString)
+      .extracting(ProjectMainBranchLiveMeasureDto::getProjectUuid, ProjectMainBranchLiveMeasureDto::getMetricUuid,
+        ProjectMainBranchLiveMeasureDto::getValue, ProjectMainBranchLiveMeasureDto::getTextValue)
       .containsExactlyInAnyOrder(
-        tuple(project.uuid(), project.uuid(), metric.getUuid(), 3.14, null),
-        tuple(project.uuid(), project.uuid(), metric2.getUuid(), 4.54, null),
-        tuple(project2.uuid(), project2.uuid(), metric.getUuid(), 99.99, null));
+        tuple(projectBranch.getProjectUuid(), metric.getUuid(), 3.14, null),
+        tuple(projectBranch.getProjectUuid(), metric2.getUuid(), 4.54, null),
+        tuple(project2Branch.getProjectUuid(), metric.getUuid(), 99.99, null));
   }
 
   @Test
   public void selectForProjectsByMetricUuids_whenMetricDoesNotMatch_shouldReturnEmptyList() {
     ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
     underTest.insert(db.getSession(), newLiveMeasure(project, metric).setValue(3.14).setData((String) null));
-    List<LiveMeasureDto> selected = underTest.selectForProjectsByMetricUuids(db.getSession(), singletonList("_other_"));
+    List<ProjectMainBranchLiveMeasureDto> selected = underTest.selectForProjectMainBranchesByMetricUuids(db.getSession(), singletonList("_other_"));
     assertThat(selected).isEmpty();
   }
 
@@ -182,10 +184,10 @@ public class LiveMeasureDaoIT {
     underTest.insert(db.getSession(), newLiveMeasure(project.getMainBranchComponent(), metric).setValue(4.54).setData((String) null));
     underTest.insert(db.getSession(), newLiveMeasure(project2.getMainBranchComponent(), metric).setValue(5.56).setData((String) null));
 
-    List<LiveMeasureDto> selected = underTest.selectForProjectsByMetricUuids(db.getSession(), List.of(metric.getUuid()));
+    List<ProjectMainBranchLiveMeasureDto> selected = underTest.selectForProjectMainBranchesByMetricUuids(db.getSession(), List.of(metric.getUuid()));
 
     assertThat(selected)
-      .extracting(LiveMeasureDto::getProjectUuid)
+      .extracting(ProjectMainBranchLiveMeasureDto::getProjectUuid)
       .containsExactlyInAnyOrder(project.projectUuid(), project2.projectUuid());
   }
 
@@ -344,8 +346,8 @@ public class LiveMeasureDaoIT {
     LiveMeasureDto result = underTest.selectMeasure(db.getSession(), file.uuid(), metric.getKey()).orElseThrow(() -> new IllegalArgumentException("Measure not found"));
 
     assertThat(result).as("Fail to map fields of %s", result.toString()).extracting(
-      LiveMeasureDto::getProjectUuid, LiveMeasureDto::getComponentUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue,
-      LiveMeasureDto::getDataAsString, LiveMeasureDto::getTextValue)
+        LiveMeasureDto::getProjectUuid, LiveMeasureDto::getComponentUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue,
+        LiveMeasureDto::getDataAsString, LiveMeasureDto::getTextValue)
       .contains(project.uuid(), file.uuid(), metric.getUuid(), 3.14, "text_value", "text_value");
   }
 
@@ -354,21 +356,21 @@ public class LiveMeasureDaoIT {
     MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString()));
     MetricDto lines = db.measures().insertMetric(m -> m.setKey("lines").setValueType(INT.toString()));
 
-    ComponentDto simpleProject = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData simpleProject = db.components().insertPublicProject();
     db.measures().insertLiveMeasure(simpleProject, ncloc, m -> m.setValue(10d));
 
-    ComponentDto projectWithBiggerBranch = db.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto bigBranch = db.components().insertProjectBranch(projectWithBiggerBranch, b -> b.setBranchType(BranchType.BRANCH));
+    ProjectData projectWithBiggerBranch = db.components().insertPublicProject();
+    BranchDto bigBranch = db.components().insertProjectBranch(projectWithBiggerBranch.getProjectDto(), b -> b.setBranchType(BranchType.BRANCH));
     db.measures().insertLiveMeasure(projectWithBiggerBranch, ncloc, m -> m.setValue(100d));
     db.measures().insertLiveMeasure(bigBranch, ncloc, m -> m.setValue(200d));
 
-    ComponentDto projectWithLinesButNoLoc = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectWithLinesButNoLoc = db.components().insertPublicProject();
     db.measures().insertLiveMeasure(projectWithLinesButNoLoc, lines, m -> m.setValue(365d));
     db.measures().insertLiveMeasure(projectWithLinesButNoLoc, ncloc, m -> m.setValue(0d));
 
-    assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), simpleProject.uuid())).isEqualTo(10L);
-    assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithBiggerBranch.uuid())).isEqualTo(200L);
-    assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithLinesButNoLoc.uuid())).isZero();
+    assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), simpleProject.projectUuid())).isEqualTo(10L);
+    assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithBiggerBranch.projectUuid())).isEqualTo(200L);
+    assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithLinesButNoLoc.projectUuid())).isZero();
   }
 
   @Test
@@ -392,17 +394,25 @@ public class LiveMeasureDaoIT {
     Map<String, MetricDto> metrics = setupMetrics();
     MetricDto ncloc = metrics.get("ncloc");
     MetricDto nclocLanguageDistribution = metrics.get("ncloc_language_distribution");
-    Map<String, ComponentDto> components = setupProjectsWithLoc(ncloc, nclocLanguageDistribution, metrics.get("lines"));
+    setupProjectsWithLoc(ncloc, nclocLanguageDistribution, metrics.get("lines"));
 
     List<ProjectLocDistributionDto> results = underTest.selectLargestBranchesLocDistribution(db.getSession(), ncloc.getUuid(), nclocLanguageDistribution.getUuid());
 
     assertThat(results)
       .containsExactlyInAnyOrder(
-        new ProjectLocDistributionDto(components.get("projectWithTieOnBranchSize").uuid(), components.get("projectWithTieOnBranchSize").uuid(), "java=250;js=0"),
-        new ProjectLocDistributionDto(components.get("projectWithTieOnOtherBranches").uuid(), components.get("tieBranch1").uuid(), "java=230;js=0"),
-        new ProjectLocDistributionDto(components.get("projectWithBranchBiggerThanMaster").uuid(), components.get("notMasterBranch").uuid(), "java=100;js=100"),
-        new ProjectLocDistributionDto(components.get("simpleProject").uuid(), components.get("simpleProject").uuid(), "java=10;js=0"),
-        new ProjectLocDistributionDto(components.get("projectWithLinesButNoLoc").uuid(), components.get("projectWithLinesButNoLoc").uuid(), "java=0;js=0"));
+        new ProjectLocDistributionDto("projectWithTieOnBranchSize", getMainBranchUuid("projectWithTieOnBranchSize"), "java=250;js=0"),
+        new ProjectLocDistributionDto("projectWithTieOnOtherBranches", getBranchUuid("projectWithTieOnOtherBranches", "tieBranch1"), "java=230;js=0"),
+        new ProjectLocDistributionDto("projectWithBranchBiggerThanMaster", getBranchUuid("projectWithBranchBiggerThanMaster", "notMasterBranch"), "java=100;js=100"),
+        new ProjectLocDistributionDto("simpleProject", getMainBranchUuid("simpleProject"), "java=10;js=0"),
+        new ProjectLocDistributionDto("projectWithLinesButNoLoc", getMainBranchUuid("projectWithLinesButNoLoc"), "java=0;js=0"));
+  }
+
+  private String getBranchUuid(String projectUuid, String branchKey) {
+    return db.getDbClient().branchDao().selectByBranchKey(db.getSession(), projectUuid, branchKey).get().getUuid();
+  }
+
+  private String getMainBranchUuid(String projectUuid) {
+    return db.getDbClient().branchDao().selectMainBranchByProjectUuid(db.getSession(), projectUuid).get().getUuid();
   }
 
   @Test
@@ -696,63 +706,58 @@ public class LiveMeasureDaoIT {
       "lines", lines);
   }
 
-  private Map<String, ComponentDto> setupProjectsWithLoc(MetricDto ncloc, MetricDto nclocDistribution, MetricDto lines) {
-    ComponentDto simpleProject = addProjectWithMeasure("simpleProject", ncloc, 10d);
-    addMeasureToComponent(simpleProject, nclocDistribution, "java=10;js=0");
-
-    ComponentDto projectWithBranchBiggerThanMaster = addProjectWithMeasure("projectWithBranchBiggerThanMaster", ncloc, 100d);
-    addMeasureToComponent(projectWithBranchBiggerThanMaster, nclocDistribution, "java=100;js=0");
+  private void setupProjectsWithLoc(MetricDto ncloc, MetricDto nclocDistribution, MetricDto lines) {
+    ProjectData simpleProject = addProjectWithMeasure("simpleProject", ncloc, 10d);
+    addMeasureToMainBranch(simpleProject, nclocDistribution, "java=10;js=0");
 
-    ComponentDto notMasterBranch = addBranchToProjectWithMeasure(projectWithBranchBiggerThanMaster, "notMasterBranch", ncloc, 200d);
-    addMeasureToComponent(notMasterBranch, nclocDistribution, "java=100;js=100");
+    ProjectData projectWithBranchBiggerThanMaster = addProjectWithMeasure("projectWithBranchBiggerThanMaster", ncloc, 100d);
+    addMeasureToMainBranch(projectWithBranchBiggerThanMaster, nclocDistribution, "java=100;js=0");
 
-    ComponentDto projectWithLinesButNoLoc = addProjectWithMeasure("projectWithLinesButNoLoc", lines, 365d);
-    addMeasureToComponent(projectWithLinesButNoLoc, nclocDistribution, "java=0;js=0");
-    addMeasureToComponent(projectWithLinesButNoLoc, ncloc, 0d, false);
+    BranchDto notMasterBranch = addBranchToProjectWithMeasure(projectWithBranchBiggerThanMaster, "notMasterBranch", ncloc, 200d);
+    addMeasureToBranch(notMasterBranch, nclocDistribution, "java=100;js=100");
 
-    ComponentDto projectWithTieOnBranchSize = addProjectWithMeasure("projectWithTieOnBranchSize", ncloc, 250d);
-    addMeasureToComponent(projectWithTieOnBranchSize, nclocDistribution, "java=250;js=0");
-    ComponentDto tieBranch = addBranchToProjectWithMeasure(projectWithTieOnBranchSize, "tieBranch", ncloc, 250d);
-    addMeasureToComponent(tieBranch, nclocDistribution, "java=250;js=0");
+    ProjectData projectWithLinesButNoLoc = addProjectWithMeasure("projectWithLinesButNoLoc", lines, 365d);
+    addMeasureToMainBranch(projectWithLinesButNoLoc, nclocDistribution, "java=0;js=0");
+    addMeasureToBranch(projectWithLinesButNoLoc.getMainBranchDto(), ncloc, 0d, false);
 
-    ComponentDto projectWithTieOnOtherBranches = addProjectWithMeasure("projectWithTieOnOtherBranches", ncloc, 220d);
-    addMeasureToComponent(projectWithTieOnOtherBranches, nclocDistribution, "java=220;js=0");
-    ComponentDto tieBranch1 = addBranchToProjectWithMeasure(projectWithTieOnOtherBranches, "tieBranch1", ncloc, 230d);
-    addMeasureToComponent(tieBranch1, nclocDistribution, "java=230;js=0");
-    ComponentDto tieBranch2 = addBranchToProjectWithMeasure(projectWithTieOnOtherBranches, "tieBranch2", ncloc, 230d);
-    addMeasureToComponent(tieBranch2, nclocDistribution, "java=230;js=0");
+    ProjectData projectWithTieOnBranchSize = addProjectWithMeasure("projectWithTieOnBranchSize", ncloc, 250d);
+    addMeasureToMainBranch(projectWithTieOnBranchSize, nclocDistribution, "java=250;js=0");
+    BranchDto tieBranch = addBranchToProjectWithMeasure(projectWithTieOnBranchSize, "tieBranch", ncloc, 250d);
+    addMeasureToBranch(tieBranch, nclocDistribution, "java=250;js=0");
 
-    return Map.of("simpleProject", simpleProject,
-      "projectWithBranchBiggerThanMaster", projectWithBranchBiggerThanMaster,
-      "notMasterBranch", notMasterBranch,
-      "projectWithLinesButNoLoc", projectWithLinesButNoLoc,
-      "projectWithTieOnBranchSize", projectWithTieOnBranchSize,
-      "tieBranch", tieBranch,
-      "projectWithTieOnOtherBranches", projectWithTieOnOtherBranches,
-      "tieBranch1", tieBranch1,
-      "tieBranch2", tieBranch2);
+    ProjectData projectWithTieOnOtherBranches = addProjectWithMeasure("projectWithTieOnOtherBranches", ncloc, 220d);
+    addMeasureToMainBranch(projectWithTieOnOtherBranches, nclocDistribution, "java=220;js=0");
+    BranchDto tieBranch1 = addBranchToProjectWithMeasure(projectWithTieOnOtherBranches, "tieBranch1", ncloc, 230d);
+    addMeasureToBranch(tieBranch1, nclocDistribution, "java=230;js=0");
+    BranchDto tieBranch2 = addBranchToProjectWithMeasure(projectWithTieOnOtherBranches, "tieBranch2", ncloc, 230d);
+    addMeasureToBranch(tieBranch2, nclocDistribution, "java=230;js=0");
   }
 
-  private ComponentDto addProjectWithMeasure(String projectKey, MetricDto metric, double metricValue) {
-    ComponentDto project = db.components().insertPublicProject(p -> p.setKey(projectKey)).getMainBranchComponent();
-    addMeasureToComponent(project, metric, metricValue, true);
+  private ProjectData addProjectWithMeasure(String projectKey, MetricDto metric, double metricValue) {
+    ProjectData project = db.components().insertPublicProject(projectKey, p -> p.setKey(projectKey));
+    addMeasureToBranch(project.getMainBranchDto(), metric, metricValue, true);
     return project;
   }
 
-  private void addMeasureToComponent(ComponentDto component, MetricDto metric, double metricValue, boolean addSnapshot) {
+  private void addMeasureToBranch(BranchDto component, MetricDto metric, double metricValue, boolean addSnapshot) {
     db.measures().insertLiveMeasure(component, metric, m -> m.setValue(metricValue));
     if (addSnapshot) {
       db.components().insertSnapshot(component, t -> t.setLast(true));
     }
   }
 
-  private void addMeasureToComponent(ComponentDto component, MetricDto metric, String metricValue) {
+  private void addMeasureToMainBranch(ProjectData projectData, MetricDto metric, String metricValue) {
+    addMeasureToBranch(projectData.getMainBranchDto(), metric, metricValue);
+  }
+
+  private void addMeasureToBranch(BranchDto component, MetricDto metric, String metricValue) {
     db.measures().insertLiveMeasure(component, metric, m -> m.setData(metricValue));
   }
 
-  private ComponentDto addBranchToProjectWithMeasure(ComponentDto project, String branchKey, MetricDto metric, double metricValue) {
-    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH).setKey(branchKey));
-    addMeasureToComponent(branch, metric, metricValue, true);
+  private BranchDto addBranchToProjectWithMeasure(ProjectData project, String branchKey, MetricDto metric, double metricValue) {
+    BranchDto branch = db.components()
+      .insertProjectBranch(project.getProjectDto(), b -> b.setBranchType(BranchType.BRANCH).setKey(branchKey));
+    addMeasureToBranch(branch, metric, metricValue, true);
     return branch;
   }
 
index ede1a89672321caaa70bd23822a2e3d2f6e392f0..446e093f2653504cd89db11a927507da91410b3f 100644 (file)
@@ -46,21 +46,19 @@ public class MeasureDaoIT {
   private MetricDto coverage;
   private MetricDto complexity;
   private MetricDto ncloc;
-  private MetricDto nclocDistribution;
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
-  private DbClient dbClient = db.getDbClient();
-  private DbSession dbSession = db.getSession();
-
-  private MeasureDao underTest = db.getDbClient().measureDao();
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
+  private final DbClient dbClient = db.getDbClient();
+  private final DbSession dbSession = db.getSession();
+  private final MeasureDao underTest = db.getDbClient().measureDao();
 
   @Before
   public void before() {
     coverage = db.measures().insertMetric(m -> m.setKey("coverage"));
     complexity = db.measures().insertMetric(m -> m.setKey("complexity"));
     ncloc = db.measures().insertMetric(m -> m.setKey("ncloc"));
-    nclocDistribution = db.measures().insertMetric(m -> m.setKey("ncloc_language_distribution"));
+    db.measures().insertMetric(m -> m.setKey("ncloc_language_distribution"));
   }
 
   @Test
index ddb7efceb08437591140cd77f36fc49465269151..631e5af3e1edb2d41fde9460d6b9179fb6a5c5a4 100644 (file)
@@ -904,7 +904,7 @@ public class PurgeDaoIT {
     dbSession.commit();
 
     assertThat(db.countRowsOfTable("ce_queue")).isOne();
-    assertThat(db.countSql("select count(*) from ce_queue where main_component_uuid='" + projectToBeDeleted.uuid() + "'")).isZero();
+    assertThat(db.countSql("select count(*) from ce_queue where entity_uuid='" + projectToBeDeleted.uuid() + "'")).isZero();
   }
 
   @Test
@@ -1273,9 +1273,9 @@ public class PurgeDaoIT {
   public void delete_ce_analysis_older_than_180_and_scanner_context_older_than_40_days_of_specified_project_when_purging_project() {
     LocalDateTime now = LocalDateTime.now();
     ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
-    Consumer<CeQueueDto> belongsToProject1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(project1.uuid());
+    Consumer<CeQueueDto> belongsToProject1 = t -> t.setEntityUuid(project1.uuid()).setComponentUuid(project1.uuid());
     ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
-    Consumer<CeQueueDto> belongsToProject2 = t -> t.setMainComponentUuid(project2.uuid()).setComponentUuid(project2.uuid());
+    Consumer<CeQueueDto> belongsToProject2 = t -> t.setEntityUuid(project2.uuid()).setComponentUuid(project2.uuid());
 
     insertCeActivityAndChildDataWithDate("VERY_OLD_1", now.minusDays(180).minusMonths(10), belongsToProject1);
     insertCeActivityAndChildDataWithDate("JUST_OLD_ENOUGH_1", now.minusDays(180).minusDays(1), belongsToProject1);
@@ -1332,8 +1332,8 @@ public class PurgeDaoIT {
     LocalDateTime now = LocalDateTime.now();
     ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
     ComponentDto branch1 = db.components().insertProjectBranch(project1, b -> b.setExcludeFromPurge(true));
-    Consumer<CeQueueDto> belongsToProject1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(project1.uuid());
-    Consumer<CeQueueDto> belongsToBranch1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(branch1.uuid());
+    Consumer<CeQueueDto> belongsToProject1 = t -> t.setEntityUuid(project1.uuid()).setComponentUuid(project1.uuid());
+    Consumer<CeQueueDto> belongsToBranch1 = t -> t.setEntityUuid(project1.uuid()).setComponentUuid(branch1.uuid());
 
     insertCeActivityAndChildDataWithDate("VERY_OLD_1", now.minusDays(180).minusMonths(10), belongsToProject1);
     insertCeActivityAndChildDataWithDate("JUST_OLD_ENOUGH_1", now.minusDays(180).minusDays(1), belongsToProject1);
@@ -1390,8 +1390,8 @@ public class PurgeDaoIT {
     LocalDateTime now = LocalDateTime.now();
     ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
     ComponentDto branch1 = db.components().insertProjectBranch(project1);
-    Consumer<CeQueueDto> belongsToProject1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(project1.uuid());
-    Consumer<CeQueueDto> belongsToBranch1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(branch1.uuid());
+    Consumer<CeQueueDto> belongsToProject1 = t -> t.setEntityUuid(project1.uuid()).setComponentUuid(project1.uuid());
+    Consumer<CeQueueDto> belongsToBranch1 = t -> t.setEntityUuid(project1.uuid()).setComponentUuid(branch1.uuid());
 
     insertCeActivityAndChildDataWithDate("VERY_OLD_1", now.minusDays(180).minusMonths(10), belongsToProject1);
     insertCeActivityAndChildDataWithDate("JUST_OLD_ENOUGH_1", now.minusDays(180).minusDays(1), belongsToProject1);
@@ -1873,7 +1873,7 @@ public class PurgeDaoIT {
     queueDto.setUuid(Uuids.create());
     queueDto.setTaskType(REPORT);
     queueDto.setComponentUuid(component.uuid());
-    queueDto.setMainComponentUuid(mainBranch);
+    queueDto.setEntityUuid(mainBranch);
     queueDto.setSubmitterUuid("submitter uuid");
     queueDto.setCreatedAt(1_300_000_000_000L);
     queueDto.setStatus(status);
@@ -1898,7 +1898,7 @@ public class PurgeDaoIT {
       .setUuid(UuidFactoryFast.getInstance().create())
       .setTaskType("foo")
       .setComponentUuid(component.uuid())
-      .setMainComponentUuid(mainBranch)
+      .setEntityUuid(mainBranch)
       .setStatus(Status.PENDING)
       .setCreatedAt(1_2323_222L)
       .setUpdatedAt(1_2323_222L);
index 03a1cde80cba25e0bb9e3faf115c90685bfbdddd..98d81f82575b475ff4229fff0c27f31d9402e813 100644 (file)
@@ -36,7 +36,7 @@ public class PushEventDaoIT {
   private final TestSystem2 system2 = new TestSystem2().setNow(1L);
 
   @Rule
-  public DbTester db = DbTester.create(system2);
+  public DbTester db = DbTester.create(system2, true);
 
   private final DbSession session = db.getSession();
   private final PushEventDao underTest = db.getDbClient().pushEventDao();
index f79113cce4217da313b0548187531fab2eca0946..75074881889e4ec52a970faee81f48e4d8e2f0ef 100644 (file)
@@ -34,21 +34,21 @@ import static org.assertj.core.api.Assertions.tuple;
 public class ProjectQgateAssociationDaoIT {
 
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
 
-  private DbSession dbSession = db.getSession();
-  private ProjectQgateAssociationDao underTest = db.getDbClient().projectQgateAssociationDao();
+  private final DbSession dbSession = db.getSession();
+  private final ProjectQgateAssociationDao underTest = db.getDbClient().projectQgateAssociationDao();
 
   @Test
   public void select_all_projects_by_query() {
     QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate();
     QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate();
-    ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto project3 = db.components().insertPrivateProject().getMainBranchComponent();
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project1), qualityGate1);
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project2), qualityGate1);
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project3), qualityGate2);
+    ProjectDto project1 = db.components().insertPrivateProject().getProjectDto();
+    ProjectDto project2 = db.components().insertPrivateProject().getProjectDto();
+    ProjectDto project3 = db.components().insertPrivateProject().getProjectDto();
+    db.qualityGates().associateProjectToQualityGate(project1, qualityGate1);
+    db.qualityGates().associateProjectToQualityGate(project2, qualityGate1);
+    db.qualityGates().associateProjectToQualityGate(project3, qualityGate2);
 
     List<ProjectQgateAssociationDto> result = underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
       .qualityGate(qualityGate1)
@@ -57,20 +57,20 @@ public class ProjectQgateAssociationDaoIT {
     assertThat(result)
       .extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getKey, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateUuid)
       .containsExactlyInAnyOrder(
-        tuple(project1.uuid(), project1.getKey(), project1.name(), qualityGate1.getUuid()),
-        tuple(project2.uuid(), project2.getKey(), project2.name(), qualityGate1.getUuid()),
-        tuple(project3.uuid(), project3.getKey(), project3.name(), null));
+        tuple(project1.getUuid(), project1.getKey(), project1.getName(), qualityGate1.getUuid()),
+        tuple(project2.getUuid(), project2.getKey(), project2.getName(), qualityGate1.getUuid()),
+        tuple(project3.getUuid(), project3.getKey(), project3.getName(), null));
   }
 
   @Test
   public void select_all_projects_by_query_should_have_deterministic_order() {
     QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate();
-    ComponentDto project1 = db.components().insertPrivateProject(d -> d.setName("p1").setKey("key1")).getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPrivateProject(d -> d.setName("p1").setKey("key2")).getMainBranchComponent();
-    ComponentDto project3 = db.components().insertPrivateProject(d -> d.setName("p2").setKey("key3")).getMainBranchComponent();
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project1), qualityGate1);
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project2), qualityGate1);
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project3), qualityGate1);
+    ProjectDto project1 = db.components().insertPrivateProject(d -> d.setName("p1").setKey("key1")).getProjectDto();
+    ProjectDto project2 = db.components().insertPrivateProject(d -> d.setName("p1").setKey("key2")).getProjectDto();
+    ProjectDto project3 = db.components().insertPrivateProject(d -> d.setName("p2").setKey("key3")).getProjectDto();
+    db.qualityGates().associateProjectToQualityGate(project1, qualityGate1);
+    db.qualityGates().associateProjectToQualityGate(project2, qualityGate1);
+    db.qualityGates().associateProjectToQualityGate(project3, qualityGate1);
 
     List<ProjectQgateAssociationDto> result = underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
       .qualityGate(qualityGate1)
@@ -78,17 +78,17 @@ public class ProjectQgateAssociationDaoIT {
 
     assertThat(result)
       .extracting(ProjectQgateAssociationDto::getUuid)
-      .containsExactlyInAnyOrder(project1.uuid(), project2.uuid(), project3.uuid());
+      .containsExactlyInAnyOrder(project1.getUuid(), project2.getUuid(), project3.getUuid());
   }
 
   @Test
   public void select_projects_by_query() {
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
-    ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto project3 = db.components().insertPrivateProject().getMainBranchComponent();
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project1), qualityGate);
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project2), qualityGate);
+    ProjectDto project1 = db.components().insertPrivateProject().getProjectDto();
+    ProjectDto project2 = db.components().insertPrivateProject().getProjectDto();
+    ProjectDto project3 = db.components().insertPrivateProject().getProjectDto();
+    db.qualityGates().associateProjectToQualityGate(project1, qualityGate);
+    db.qualityGates().associateProjectToQualityGate(project2, qualityGate);
 
     assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
       .qualityGate(qualityGate)
@@ -96,53 +96,53 @@ public class ProjectQgateAssociationDaoIT {
       .build()))
       .extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateUuid)
       .containsExactlyInAnyOrder(
-        tuple(project1.uuid(), project1.name(), qualityGate.getUuid()),
-        tuple(project2.uuid(), project2.name(), qualityGate.getUuid()));
+        tuple(project1.getUuid(), project1.getName(), qualityGate.getUuid()),
+        tuple(project2.getUuid(), project2.getName(), qualityGate.getUuid()));
 
     assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
       .qualityGate(qualityGate)
       .membership(ProjectQgateAssociationQuery.OUT)
       .build()))
       .extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateUuid)
-      .containsExactlyInAnyOrder(tuple(project3.uuid(), project3.name(), null));
+      .containsExactlyInAnyOrder(tuple(project3.getUuid(), project3.getName(), null));
   }
 
   @Test
   public void search_by_project_name() {
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
-    ComponentDto project1 = db.components().insertPrivateProject(p -> p.setName("Project One")).getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPrivateProject(p -> p.setName("Project Two")).getMainBranchComponent();
-    ComponentDto project3 = db.components().insertPrivateProject(p -> p.setName("Project Three")).getMainBranchComponent();
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project1), qualityGate);
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project2), qualityGate);
+    ProjectDto project1 = db.components().insertPrivateProject(p -> p.setName("Project One")).getProjectDto();
+    ProjectDto project2 = db.components().insertPrivateProject(p -> p.setName("Project Two")).getProjectDto();
+    ProjectDto project3 = db.components().insertPrivateProject(p -> p.setName("Project Three")).getProjectDto();
+    db.qualityGates().associateProjectToQualityGate(project1, qualityGate);
+    db.qualityGates().associateProjectToQualityGate(project2, qualityGate);
 
     assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
       .qualityGate(qualityGate)
       .projectSearch("one")
       .build()))
       .extracting(ProjectQgateAssociationDto::getUuid)
-      .containsExactlyInAnyOrder(project1.uuid());
+      .containsExactlyInAnyOrder(project1.getUuid());
 
     assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
       .qualityGate(qualityGate)
       .projectSearch("project")
       .build()))
       .extracting(ProjectQgateAssociationDto::getUuid)
-      .containsExactlyInAnyOrder(project1.uuid(), project2.uuid(), project3.uuid());
+      .containsExactlyInAnyOrder(project1.getUuid(), project2.getUuid(), project3.getUuid());
   }
 
   @Test
   public void sorted_by_project_name() {
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
-    ComponentDto project1 = db.components().insertPrivateProject(p -> p.setName("Project One")).getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPrivateProject(p -> p.setName("Project Two")).getMainBranchComponent();
-    ComponentDto project3 = db.components().insertPrivateProject(p -> p.setName("Project Three")).getMainBranchComponent();
+    ProjectDto project1 = db.components().insertPrivateProject(p -> p.setName("Project One")).getProjectDto();
+    ProjectDto project2 = db.components().insertPrivateProject(p -> p.setName("Project Two")).getProjectDto();
+    ProjectDto project3 = db.components().insertPrivateProject(p -> p.setName("Project Three")).getProjectDto();
 
     assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
       .qualityGate(qualityGate)
       .build()))
       .extracting(ProjectQgateAssociationDto::getUuid)
-      .containsExactly(project1.uuid(), project3.uuid(), project2.uuid());
+      .containsExactly(project1.getUuid(), project3.getUuid(), project2.getUuid());
   }
 
   @Test
@@ -151,34 +151,34 @@ public class ProjectQgateAssociationDaoIT {
 
     QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate();
     QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate();
-    ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto project3 = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto project4 = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto project5 = db.components().insertPrivateProject().getMainBranchComponent();
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project1), qualityGate1);
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project2), qualityGate2);
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project3), qualityGate1);
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project4), qualityGate2);
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project5), qualityGate1);
+    ProjectDto project1 = db.components().insertPrivateProject().getProjectDto();
+    ProjectDto project2 = db.components().insertPrivateProject().getProjectDto();
+    ProjectDto project3 = db.components().insertPrivateProject().getProjectDto();
+    ProjectDto project4 = db.components().insertPrivateProject().getProjectDto();
+    ProjectDto project5 = db.components().insertPrivateProject().getProjectDto();
+    db.qualityGates().associateProjectToQualityGate(project1, qualityGate1);
+    db.qualityGates().associateProjectToQualityGate(project2, qualityGate2);
+    db.qualityGates().associateProjectToQualityGate(project3, qualityGate1);
+    db.qualityGates().associateProjectToQualityGate(project4, qualityGate2);
+    db.qualityGates().associateProjectToQualityGate(project5, qualityGate1);
 
     List<ProjectQgateAssociationDto> result = underTest.selectAll(dbSession);
 
     assertThat(result)
       .extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getGateUuid)
       .containsExactlyInAnyOrder(
-        tuple(project1.uuid(), qualityGate1.getUuid()),
-        tuple(project2.uuid(), qualityGate2.getUuid()),
-        tuple(project3.uuid(), qualityGate1.getUuid()),
-        tuple(project4.uuid(), qualityGate2.getUuid()),
-        tuple(project5.uuid(), qualityGate1.getUuid()));
+        tuple(project1.getUuid(), qualityGate1.getUuid()),
+        tuple(project2.getUuid(), qualityGate2.getUuid()),
+        tuple(project3.getUuid(), qualityGate1.getUuid()),
+        tuple(project4.getUuid(), qualityGate2.getUuid()),
+        tuple(project5.getUuid(), qualityGate1.getUuid()));
   }
 
   @Test
   public void select_qgate_uuid_is_absent() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectDto project = db.components().insertPrivateProject().getProjectDto();
 
-    Optional<String> result = underTest.selectQGateUuidByProjectUuid(dbSession, project.uuid());
+    Optional<String> result = underTest.selectQGateUuidByProjectUuid(dbSession, project.getUuid());
 
     assertThat(result).isEmpty();
   }
@@ -187,12 +187,12 @@ public class ProjectQgateAssociationDaoIT {
   public void select_qgate_uuid() {
     QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate();
     QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate();
-    ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project1), qualityGate1);
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project2), qualityGate2);
+    ProjectDto project1 = db.components().insertPrivateProject().getProjectDto();
+    ProjectDto project2 = db.components().insertPrivateProject().getProjectDto();
+    db.qualityGates().associateProjectToQualityGate(project1, qualityGate1);
+    db.qualityGates().associateProjectToQualityGate(project2, qualityGate2);
 
-    Optional<String> result = underTest.selectQGateUuidByProjectUuid(dbSession, project1.uuid());
+    Optional<String> result = underTest.selectQGateUuidByProjectUuid(dbSession, project1.getUuid());
 
     assertThat(result).contains(qualityGate1.getUuid());
   }
@@ -206,7 +206,7 @@ public class ProjectQgateAssociationDaoIT {
 
     underTest.deleteByProjectUuid(dbSession, project.getUuid());
 
-    Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid());
+    Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByProjectUuid(project.getUuid());
 
     assertThat(deletedQualityGate).isEmpty();
   }
@@ -220,7 +220,7 @@ public class ProjectQgateAssociationDaoIT {
 
     underTest.deleteByQGateUuid(dbSession, qualityGate.getUuid());
 
-    Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid());
+    Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByProjectUuid(project.getUuid());
 
     assertThat(deletedQualityGate).isEmpty();
   }
@@ -235,7 +235,7 @@ public class ProjectQgateAssociationDaoIT {
 
     underTest.updateProjectQGateAssociation(dbSession, project.getUuid(), secondQualityGate.getUuid());
 
-    Optional<String> updatedQualityGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid());
+    Optional<String> updatedQualityGateUuid = db.qualityGates().selectQGateUuidByProjectUuid(project.getUuid());
 
     assertThat(updatedQualityGateUuid).contains(secondQualityGate.getUuid());
   }
index 6a46ce044d4a7c1338416c713c8399a74df3079c..c4aef3ba778991adbdbf69c9e8a8d17223ff0f45 100644 (file)
@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class QualityGateConditionDaoIT {
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   private DbSession dbSession = dbTester.getSession();
   private QualityGateConditionDao underTest = dbTester.getDbClient().gateConditionDao();
index a93511b6e8bcb99bc290c620a58f3734db0af771..42b93bc482aae50c5a5460da03266d9641ed8ba4 100644 (file)
@@ -44,7 +44,7 @@ import static org.sonar.db.qualitygate.QualityGateFindingDto.RATING_VALUE_TYPE;
 public class QualityGateDaoIT {
 
   @Rule
-  public final DbTester db = DbTester.create(System2.INSTANCE);
+  public final DbTester db = DbTester.create(System2.INSTANCE, true);
 
   private final QualityGateDbTester qualityGateDbTester = new QualityGateDbTester(db);
   private final DbSession dbSession = db.getSession();
index b6a160e48b78059bb3583a3e48727e576f14d0d2..db462721a839c75077a2bbbe753bb8a0c9440ebb 100644 (file)
@@ -51,7 +51,7 @@ public class QualityGateGroupPermissionsDaoIT {
   private final ArgumentCaptor<GroupEditorNewValue> newValueCaptor = ArgumentCaptor.forClass(GroupEditorNewValue.class);
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE, auditPersister);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, auditPersister, true);
 
   private DbSession dbSession = dbTester.getSession();
   private QualityGateGroupPermissionsDao underTest = dbTester.getDbClient().qualityGateGroupPermissionsDao();
index beea1928ad2e0a8561485416ff50cb736750dfea..1a9c6a0479b54348533977132b8318945eb70627 100644 (file)
@@ -47,7 +47,7 @@ public class QualityGateUserPermissionsDaoIT {
   private final ArgumentCaptor<UserEditorNewValue> newValueCaptor = ArgumentCaptor.forClass(UserEditorNewValue.class);
 
   @Rule
-  public final DbTester db = DbTester.create(System2.INSTANCE, auditPersister);
+  public final DbTester db = DbTester.create(System2.INSTANCE, auditPersister, true);
 
   private final DbSession dbSession = db.getSession();
   private final UserDbTester userDbTester = new UserDbTester(db);
index 5af54de947d16786bb73d92b37df6fb46c0ce213..eda8fb4abbeabd0d2962f2f5c9ef57ead9ef9530 100644 (file)
@@ -71,7 +71,7 @@ public class ActiveRuleDaoIT {
   private System2 system = new TestSystem2().setNow(NOW);
 
   @Rule
-  public DbTester db = DbTester.create(system);
+  public DbTester db = DbTester.create(system, true);
 
   private DbSession dbSession = db.getSession();
 
index e7428304b37b973707b49c68fbc1ed7a2e2e1ec1..7447f5a4ae330d750e10d6abcb530b139ffd98d8 100644 (file)
@@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class DefaultQProfileDaoIT {
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   private DbSession dbSession = dbTester.getSession();
 
index 0ab04ea2c51445b2f3ab039de8a5c6c543997c05..59bba4c269ef7f77fa2233f2e4ed941fe2e78a47 100644 (file)
@@ -40,7 +40,7 @@ public class QProfileChangeDaoIT {
   private System2 system2 = new AlwaysIncreasingSystem2();
 
   @Rule
-  public DbTester db = DbTester.create(system2);
+  public DbTester db = DbTester.create(system2, true);
 
   private DbSession dbSession = db.getSession();
   private UuidFactory uuidFactory = new SequenceUuidFactory();
index c61b16081628b48b6483f363bfca10097ed82f72..210593d2d1f936b39c8386f411d2a94948a9c023 100644 (file)
@@ -57,7 +57,7 @@ public class QProfileEditGroupsDaoIT {
   private System2 system2 = new TestSystem2().setNow(NOW);
 
   @Rule
-  public DbTester db = DbTester.create(system2, auditPersister);
+  public DbTester db = DbTester.create(system2, auditPersister, true);
 
   private QProfileEditGroupsDao underTest = db.getDbClient().qProfileEditGroupsDao();
 
index ddb126b479d29cb9609b2195b5a5bfc25b19f0ad..da4a526d1cc454beb1fdb8c75f44e6dee323d0c6 100644 (file)
@@ -56,7 +56,7 @@ public class QProfileEditUsersDaoIT {
   private final ArgumentCaptor<UserEditorNewValue> newValueCaptor = ArgumentCaptor.forClass(UserEditorNewValue.class);
 
   @Rule
-  public DbTester db = DbTester.create(system2, auditPersister);
+  public DbTester db = DbTester.create(system2, auditPersister, true);
 
   private final QProfileEditUsersDao underTest = db.getDbClient().qProfileEditUsersDao();
 
index b37a1067bb29a65c3136e411aa940138093e30ae..4f35d90961ea2b73cf631a5c27cb006fabe811bf 100644 (file)
@@ -58,7 +58,7 @@ public class QualityProfileDaoIT {
 
   private final System2 system = mock(System2.class);
   @Rule
-  public DbTester db = DbTester.create(system);
+  public DbTester db = DbTester.create(system, true);
 
   private final DbSession dbSession = db.getSession();
   private final QualityProfileDao underTest = db.getDbClient().qualityProfileDao();
@@ -673,29 +673,6 @@ public class QualityProfileDaoIT {
       .isEmpty();
   }
 
-  @Test
-  public void test_selectQProfileUuidsByProjectUuid() {
-    ProjectDto project1 = db.components().insertPublicProject().getProjectDto();
-    ProjectDto project2 = db.components().insertPublicProject().getProjectDto();
-    ProjectDto project3 = db.components().insertPublicProject().getProjectDto();
-    QProfileDto javaProfile = db.qualityProfiles().insert(p -> p.setLanguage("java"));
-    QProfileDto jsProfile = db.qualityProfiles().insert(p -> p.setLanguage("js"));
-    QProfileDto cProfile = db.qualityProfiles().insert(p -> p.setLanguage("c"));
-    db.qualityProfiles().associateWithProject(project1, javaProfile, cProfile);
-    db.qualityProfiles().associateWithProject(project2, jsProfile);
-
-    assertThat(underTest.selectQProfileUuidsByProjectUuid(dbSession, project1.getUuid()))
-      .hasSize(2)
-      .containsExactly(javaProfile.getKee(), cProfile.getKee());
-
-    assertThat(underTest.selectQProfileUuidsByProjectUuid(dbSession, project2.getUuid()))
-      .hasSize(1)
-      .containsExactly(jsProfile.getKee());
-
-    assertThat(underTest.selectQProfileUuidsByProjectUuid(dbSession, project3.getUuid()))
-      .isEmpty();
-  }
-
   @Test
   public void test_selectQProfilesByProjectUuid() {
     ProjectDto project1 = db.components().insertPublicProject().getProjectDto();
@@ -746,27 +723,27 @@ public class QualityProfileDaoIT {
 
   @Test
   public void select_selected_projects() {
-    ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name")).getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name")).getMainBranchComponent();
-    ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name")).getMainBranchComponent();
+    ProjectDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name")).getProjectDto();
+    ProjectDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name")).getProjectDto();
+    ProjectDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name")).getProjectDto();
     db.components().insertPrivateProject(t -> t.setName("Project4 name")).getMainBranchComponent();
     db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
 
     QProfileDto profile1 = newQualityProfileDto();
     db.qualityProfiles().insert(profile1);
-    db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(project1), profile1);
-    db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(project2), profile1);
+    db.qualityProfiles().associateWithProject(project1, profile1);
+    db.qualityProfiles().associateWithProject(project2, profile1);
 
     QProfileDto profile2 = newQualityProfileDto();
     db.qualityProfiles().insert(profile2);
-    db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(project3), profile2);
+    db.qualityProfiles().associateWithProject(project3, profile2);
     QProfileDto profile3 = newQualityProfileDto();
 
     assertThat(underTest.selectSelectedProjects(dbSession, profile1, null))
       .extracting("projectUuid", "projectKey", "projectName", "profileKey")
       .containsOnly(
-        tuple(project1.uuid(), project1.getKey(), project1.name(), profile1.getKee()),
-        tuple(project2.uuid(), project2.getKey(), project2.name(), profile1.getKee()));
+        tuple(project1.getUuid(), project1.getKey(), project1.getName(), profile1.getKee()),
+        tuple(project2.getUuid(), project2.getKey(), project2.getName(), profile1.getKee()));
 
     assertThat(underTest.selectSelectedProjects(dbSession, profile1, "ect1")).hasSize(1);
     assertThat(underTest.selectSelectedProjects(dbSession, profile3, null)).isEmpty();
@@ -774,24 +751,24 @@ public class QualityProfileDaoIT {
 
   @Test
   public void select_deselected_projects() {
-    ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name")).getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name")).getMainBranchComponent();
-    ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name")).getMainBranchComponent();
+    ProjectDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name")).getProjectDto();
+    ProjectDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name")).getProjectDto();
+    ProjectDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name")).getProjectDto();
 
     QProfileDto profile1 = newQualityProfileDto();
     db.qualityProfiles().insert(profile1);
-    db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(project1), profile1);
+    db.qualityProfiles().associateWithProject(project1, profile1);
 
     QProfileDto profile2 = newQualityProfileDto();
     db.qualityProfiles().insert(profile2);
-    db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(project2), profile2);
+    db.qualityProfiles().associateWithProject(project2, profile2);
     QProfileDto profile3 = newQualityProfileDto();
 
     assertThat(underTest.selectDeselectedProjects(dbSession, profile1, null))
       .extracting("projectUuid", "projectKey", "projectName", "profileKey")
       .containsExactly(
-        tuple(project2.uuid(), project2.getKey(), project2.name(), null),
-        tuple(project3.uuid(), project3.getKey(), project3.name(), null));
+        tuple(project2.getUuid(), project2.getKey(), project2.getName(), null),
+        tuple(project3.getUuid(), project3.getKey(), project3.getName(), null));
 
     assertThat(underTest.selectDeselectedProjects(dbSession, profile1, "ect2")).hasSize(1);
     assertThat(underTest.selectDeselectedProjects(dbSession, profile3, null)).hasSize(3);
@@ -799,26 +776,26 @@ public class QualityProfileDaoIT {
 
   @Test
   public void select_project_associations() {
-    ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name")).getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name")).getMainBranchComponent();
-    ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name")).getMainBranchComponent();
+    ProjectDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name")).getProjectDto();
+    ProjectDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name")).getProjectDto();
+    ProjectDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name")).getProjectDto();
     db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
 
     QProfileDto profile1 = newQualityProfileDto();
     db.qualityProfiles().insert(profile1);
-    db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(project1), profile1);
+    db.qualityProfiles().associateWithProject(project1, profile1);
 
     QProfileDto profile2 = newQualityProfileDto();
     db.qualityProfiles().insert(profile2);
-    db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(project2), profile2);
+    db.qualityProfiles().associateWithProject(project2, profile2);
     QProfileDto profile3 = newQualityProfileDto();
 
     assertThat(underTest.selectProjectAssociations(dbSession, profile1, null))
       .extracting("projectUuid", "projectKey", "projectName", "profileKey")
       .containsOnly(
-        tuple(project1.uuid(), project1.getKey(), project1.name(), profile1.getKee()),
-        tuple(project2.uuid(), project2.getKey(), project2.name(), null),
-        tuple(project3.uuid(), project3.getKey(), project3.name(), null));
+        tuple(project1.getUuid(), project1.getKey(), project1.getName(), profile1.getKee()),
+        tuple(project2.getUuid(), project2.getKey(), project2.getName(), null),
+        tuple(project3.getUuid(), project3.getKey(), project3.getName(), null));
 
     assertThat(underTest.selectProjectAssociations(dbSession, profile1, "ect2")).hasSize(1);
     assertThat(underTest.selectProjectAssociations(dbSession, profile3, null)).hasSize(3);
@@ -879,33 +856,33 @@ public class QualityProfileDaoIT {
 
   @Test
   public void selectProjectAssociations_shouldFindResult_whenQueryMatchingKey() {
-    ComponentDto privateProject = db.components().insertPrivateProject(project -> project.setName("project name"), project -> project.setKey("project_key")).getMainBranchComponent();
+    ProjectDto privateProject = db.components().insertPrivateProject(project -> project.setName("project name"), project -> project.setKey("project_key")).getProjectDto();
     QProfileDto qProfileDto = db.qualityProfiles().insert();
 
     List<ProjectQprofileAssociationDto> results = underTest.selectProjectAssociations(dbSession, qProfileDto, "key");
 
-    assertThat(results).extracting(ProjectQprofileAssociationDto::getProjectUuid).containsOnly(privateProject.uuid());
+    assertThat(results).extracting(ProjectQprofileAssociationDto::getProjectUuid).containsOnly(privateProject.getUuid());
   }
 
   @Test
   public void selectSelectedProjects_shouldFindResult_whenQueryMatchingKey() {
-    ComponentDto privateProject = db.components().insertPrivateProject(project -> project.setName("project name"), project -> project.setKey("project_key")).getMainBranchComponent();
+    ProjectDto privateProject = db.components().insertPrivateProject(project -> project.setName("project name"), project -> project.setKey("project_key")).getProjectDto();
     QProfileDto qProfileDto = db.qualityProfiles().insert();
-    db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(privateProject), qProfileDto);
+    db.qualityProfiles().associateWithProject(privateProject, qProfileDto);
 
     List<ProjectQprofileAssociationDto> results = underTest.selectSelectedProjects(dbSession, qProfileDto, "key");
 
-    assertThat(results).extracting(ProjectQprofileAssociationDto::getProjectUuid).containsOnly(privateProject.uuid());
+    assertThat(results).extracting(ProjectQprofileAssociationDto::getProjectUuid).containsOnly(privateProject.getUuid());
   }
 
   @Test
   public void selectDeselectedProjects_shouldFindResult_whenQueryMatchingKey() {
-    ComponentDto privateProject = db.components().insertPrivateProject(project -> project.setName("project name"), project -> project.setKey("project_key")).getMainBranchComponent();
+    ProjectDto privateProject = db.components().insertPrivateProject(project -> project.setName("project name"), project -> project.setKey("project_key")).getProjectDto();
     QProfileDto qProfileDto = db.qualityProfiles().insert();
 
     List<ProjectQprofileAssociationDto> results = underTest.selectDeselectedProjects(dbSession, qProfileDto, "key");
 
-    assertThat(results).extracting(ProjectQprofileAssociationDto::getProjectUuid).containsOnly(privateProject.uuid());
+    assertThat(results).extracting(ProjectQprofileAssociationDto::getProjectUuid).containsOnly(privateProject.getUuid());
   }
 
   private List<QProfileDto> createSharedData() {
index 22fdbeb3a0b0d02c1b9059833ea25444b739a0b1..cd24aa77e9093c87459b5fafc12fec08805fd590 100644 (file)
@@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class QualityProfileExportDaoIT {
 
   @Rule
-  public DbTester db = DbTester.create(new AlwaysIncreasingSystem2());
+  public DbTester db = DbTester.create(new AlwaysIncreasingSystem2(), true);
 
   private final DbSession dbSession = db.getSession();
   private final QualityProfileExportDao underTest = db.getDbClient().qualityProfileExportDao();
index 301fa88a1dab8ba1b96d8cf0b24d59e40496f84f..818343ac06ad4cd9ca0bbbc94d9a2a18e8392035 100644 (file)
@@ -50,7 +50,7 @@ import static org.sonar.db.component.ComponentTesting.newFileDto;
 public class FileSourceDaoIT {
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   private final DbSession dbSession = dbTester.getSession();
 
index 3a4b17dc73ed0287a44fc281aed0ad335ca7ac02..125b4cdd4e7d7cae553c7803d02a16509352f504 100644 (file)
@@ -77,7 +77,7 @@ public class CeActivityDao implements Dao {
    * Ordered by id desc -> newest to oldest
    */
   public List<CeActivityDto> selectByQuery(DbSession dbSession, CeTaskQuery query, Pagination pagination) {
-    if (query.isShortCircuitedByMainComponentUuids()) {
+    if (query.isShortCircuitedByEntityUuids()) {
       return Collections.emptyList();
     }
 
@@ -88,8 +88,8 @@ public class CeActivityDao implements Dao {
     return mapper(dbSession).countByQuery(query);
   }
 
-  public int countLastByStatusAndMainComponentUuid(DbSession dbSession, CeActivityDto.Status status, @Nullable String mainComponentUuid) {
-    return mapper(dbSession).countLastByStatusAndMainComponentUuid(status, mainComponentUuid);
+  public int countLastByStatusAndEntityUuid(DbSession dbSession, CeActivityDto.Status status, @Nullable String entityUuid) {
+    return mapper(dbSession).countLastByStatusAndEntityUuid(status, entityUuid);
   }
 
   public Optional<CeActivityDto> selectLastByComponentUuidAndTaskType(DbSession dbSession, String componentUuid, String taskType) {
index 1ae1fde50ed6586e862cfaf863ec982499391194..db44f83e0e7205343b153e7870d6e2191fdb71ef 100644 (file)
@@ -40,20 +40,18 @@ public class CeActivityDto {
 
   private String uuid;
   /**
-   * Can be {@code null} when task is not associated to any data in table PROJECTS, but must always be non {@code null}
-   * at the same time as {@link #mainComponentUuid}.
+   * Can be {@code null} when task is not associated to any data in table COMPONENTS, but must always be non {@code null}
+   * at the same time as {@link #entityUuid}.
    * <p>
-   * The component uuid of a any component (project or not) is its own UUID.
+   * The component uuid of any component (project or not) is its own UUID.
    */
   private String componentUuid;
   /**
-   * Can be {@code null} when task is not associated to any data in table PROJECTS, but must always be non {@code null}
+   * Can be {@code null} when task is not associated to any component, but must always be non {@code null}
    * at the same time as {@link #componentUuid}.
    * <p>
-   * The main component uuid of the main branch of project is its own UUID. For other branches of a project, it is the
-   * project UUID of the main branch of that project
    */
-  private String mainComponentUuid;
+  private String entityUuid;
   private String analysisUuid;
   private Status status;
   private String taskType;
@@ -117,9 +115,9 @@ public class CeActivityDto {
     this.uuid = queueDto.getUuid();
     this.taskType = queueDto.getTaskType();
     this.componentUuid = queueDto.getComponentUuid();
-    this.mainComponentUuid = queueDto.getMainComponentUuid();
+    this.entityUuid = queueDto.getEntityUuid();
     this.isLastKey = format("%s%s", taskType, Strings.nullToEmpty(componentUuid));
-    this.mainIsLastKey = format("%s%s", taskType, Strings.nullToEmpty(mainComponentUuid));
+    this.mainIsLastKey = format("%s%s", taskType, Strings.nullToEmpty(entityUuid));
     this.submitterUuid = queueDto.getSubmitterUuid();
     this.workerUuid = queueDto.getWorkerUuid();
     this.submittedAt = queueDto.getCreatedAt();
@@ -157,13 +155,13 @@ public class CeActivityDto {
   }
 
   @CheckForNull
-  public String getMainComponentUuid() {
-    return mainComponentUuid;
+  public String getEntityUuid() {
+    return entityUuid;
   }
 
-  public CeActivityDto setMainComponentUuid(@Nullable String s) {
-    validateUuid(s, "MAIN_COMPONENT_UUID");
-    this.mainComponentUuid = s;
+  public CeActivityDto setEntityUuid(@Nullable String s) {
+    validateUuid(s, "ENTITY_UUID");
+    this.entityUuid = s;
     return this;
   }
 
@@ -351,7 +349,7 @@ public class CeActivityDto {
       "uuid='" + uuid + '\'' +
       ", nodeName='" + nodeName + '\'' +
       ", componentUuid='" + componentUuid + '\'' +
-      ", mainComponentUuid='" + mainComponentUuid + '\'' +
+      ", entityUuid='" + entityUuid + '\'' +
       ", analysisUuid='" + analysisUuid + '\'' +
       ", status=" + status +
       ", taskType='" + taskType + '\'' +
index 3a651818e21a6db3038880a663cb58cc26475274..ec9580714bd7f81c54f98784749e88347fdeb6ee 100644 (file)
@@ -38,7 +38,7 @@ public interface CeActivityMapper {
 
   int countByQuery(@Param("query") CeTaskQuery query);
 
-  int countLastByStatusAndMainComponentUuid(@Param("status") CeActivityDto.Status status, @Nullable @Param("mainComponentUuid") String mainComponentUuid);
+  int countLastByStatusAndEntityUuid(@Param("status") CeActivityDto.Status status, @Nullable @Param("entityUuid") String entityUuid);
 
   void insert(CeActivityDto dto);
 
index 77cf830d594901c1f1bdf7dcc01478c57094a894..e736b5b0b2f16a3fd757d7e994f850312e3977f0 100644 (file)
@@ -59,7 +59,7 @@ public class CeQueueDao implements Dao {
   }
 
   public List<CeQueueDto> selectByQueryInDescOrder(DbSession dbSession, CeTaskQuery query, int page, int pageSize) {
-    if (query.isShortCircuitedByMainComponentUuids()
+    if (query.isShortCircuitedByEntityUuids()
       || query.isOnlyCurrents()
       || query.getMaxExecutedAt() != null) {
       return emptyList();
@@ -72,7 +72,7 @@ public class CeQueueDao implements Dao {
   }
 
   public int countByQuery(DbSession dbSession, CeTaskQuery query) {
-    if (query.isShortCircuitedByMainComponentUuids()
+    if (query.isShortCircuitedByEntityUuids()
       || query.isOnlyCurrents()
       || query.getMaxExecutedAt() != null) {
       return 0;
@@ -84,8 +84,8 @@ public class CeQueueDao implements Dao {
   /**
    * Ordered by ascending id: oldest to newest
    */
-  public List<CeQueueDto> selectByMainComponentUuid(DbSession session, String projectUuid) {
-    return mapper(session).selectByMainComponentUuid(projectUuid);
+  public List<CeQueueDto> selectByEntityUuid(DbSession session, String projectUuid) {
+    return mapper(session).selectByEntityUuid(projectUuid);
   }
 
   public Optional<CeQueueDto> selectByUuid(DbSession session, String uuid) {
@@ -142,23 +142,23 @@ public class CeQueueDao implements Dao {
   }
 
   public int countByStatus(DbSession dbSession, CeQueueDto.Status status) {
-    return mapper(dbSession).countByStatusAndMainComponentUuid(status, null);
+    return mapper(dbSession).countByStatusAndEntityUuid(status, null);
   }
 
-  public int countByStatusAndMainComponentUuid(DbSession dbSession, CeQueueDto.Status status, @Nullable String mainComponentUuid) {
-    return mapper(dbSession).countByStatusAndMainComponentUuid(status, mainComponentUuid);
+  public int countByStatusAndEntityUuid(DbSession dbSession, CeQueueDto.Status status, @Nullable String entityUuid) {
+    return mapper(dbSession).countByStatusAndEntityUuid(status, entityUuid);
   }
 
-  public Optional<Long> selectCreationDateOfOldestPendingByMainComponentUuid(DbSession dbSession, @Nullable String mainComponentUuid) {
-    return Optional.ofNullable(mapper(dbSession).selectCreationDateOfOldestPendingByMainComponentUuid(mainComponentUuid));
+  public Optional<Long> selectCreationDateOfOldestPendingByEntityUuid(DbSession dbSession, @Nullable String entityUuid) {
+    return Optional.ofNullable(mapper(dbSession).selectCreationDateOfOldestPendingByEntityUuid(entityUuid));
   }
 
   /**
-   * Counts entries in the queue with the specified status for each specified main component uuid.
-   * The returned map doesn't contain any entry for main component uuids for which there is no entry in the queue (ie.
+   * Counts entries in the queue with the specified status for each specified entity uuid.
+   * The returned map doesn't contain any entry for entity uuids for which there is no entry in the queue (ie.
    * all entries have a value >= 0).
    */
-  public Map<String, Integer> countByStatusAndMainComponentUuids(DbSession dbSession, CeQueueDto.Status status, Set<String> projectUuids) {
+  public Map<String, Integer> countByStatusAndEntityUuids(DbSession dbSession, CeQueueDto.Status status, Set<String> projectUuids) {
     if (projectUuids.isEmpty()) {
       return emptyMap();
     }
@@ -167,8 +167,8 @@ public class CeQueueDao implements Dao {
     executeLargeUpdates(
       projectUuids,
       partitionOfProjectUuids -> {
-        List<QueueCount> i = mapper(dbSession).countByStatusAndMainComponentUuids(status, partitionOfProjectUuids);
-        i.forEach(o -> builder.put(o.getMainComponentUuid(), o.getTotal()));
+        List<QueueCount> i = mapper(dbSession).countByStatusAndEntityUuids(status, partitionOfProjectUuids);
+        i.forEach(o -> builder.put(o.getEntityUuid(), o.getTotal()));
       });
     return builder.build();
   }
index 266a8f9326f607ca55568a3ab5ab46f51593244e..5560e6ba39195bd8a9678a1e0c8ac32c7e8706d1 100644 (file)
@@ -33,20 +33,18 @@ public class CeQueueDto {
   private String uuid;
   private String taskType;
   /**
-   * Can be {@code null} when task is not associated to any data in table PROJECTS, but must always be non {@code null}
-   * at the same time as {@link #mainComponentUuid}.
+   * Can be {@code null} when task is not associated to any data in the components table, but must always be non {@code null}
+   * at the same time as {@link #entityUuid}.
    * <p>
-   * The component uuid of a any component (project or not) is its own UUID.
+   * The component uuid of any component is its own UUID.
    */
   private String componentUuid;
   /**
-   * Can be {@code null} when task is not associated to any data in table PROJECTS, but must always be non {@code null}
+   * Can be {@code null} when task is not associated to any entity, but must always be non {@code null}
    * at the same time as {@link #componentUuid}.
    * <p>
-   * The main component uuid of the main branch of project is its own UUID. For other branches of a project, it is the
-   * project UUID of the main branch of that project
    */
-  private String mainComponentUuid;
+  private String entityUuid;
   private Status status;
   private String submitterUuid;
   /**
@@ -79,13 +77,13 @@ public class CeQueueDto {
   }
 
   @CheckForNull
-  public String getMainComponentUuid() {
-    return mainComponentUuid;
+  public String getEntityUuid() {
+    return entityUuid;
   }
 
-  public CeQueueDto setMainComponentUuid(@Nullable String s) {
-    checkUuid(s, "MAIN_COMPONENT_UUID");
-    this.mainComponentUuid = s;
+  public CeQueueDto setEntityUuid(@Nullable String s) {
+    checkUuid(s, "ENTITY_UUID");
+    this.entityUuid = s;
     return this;
   }
 
@@ -166,7 +164,7 @@ public class CeQueueDto {
       "uuid='" + uuid + '\'' +
       ", taskType='" + taskType + '\'' +
       ", componentUuid='" + componentUuid + '\'' +
-      ", mainComponentUuid='" + mainComponentUuid + '\'' +
+      ", entityUuid='" + entityUuid + '\'' +
       ", status=" + status +
       ", submitterLogin='" + submitterUuid + '\'' +
       ", workerUuid='" + workerUuid + '\'' +
index 4b991dfcbdb58c0f2def3510f6494d7266d93480..ef578cfc5f29d49985c697ff3c933dd5fdde89e2 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.db.Pagination;
 
 public interface CeQueueMapper {
 
-  List<CeQueueDto> selectByMainComponentUuid(@Param("mainComponentUuid") String mainComponentUuid);
+  List<CeQueueDto> selectByEntityUuid(@Param("entityUuid") String entityUuid);
 
   List<CeQueueDto> selectAllInAscOrder();
 
@@ -71,12 +71,12 @@ public interface CeQueueMapper {
    */
   void resetAllInProgressTasks(@Param("updatedAt") long updatedAt);
 
-  int countByStatusAndMainComponentUuid(@Param("status") CeQueueDto.Status status, @Nullable @Param("mainComponentUuid") String mainComponentUuid);
+  int countByStatusAndEntityUuid(@Param("status") CeQueueDto.Status status, @Nullable @Param("entityUuid") String entityUuid);
 
   @CheckForNull
-  Long selectCreationDateOfOldestPendingByMainComponentUuid(@Nullable @Param("mainComponentUuid") String mainComponentUuid);
+  Long selectCreationDateOfOldestPendingByEntityUuid(@Nullable @Param("entityUuid") String entityUuid);
 
-  List<QueueCount> countByStatusAndMainComponentUuids(@Param("status") CeQueueDto.Status status, @Param("mainComponentUuids") List<String> mainComponentUuids);
+  List<QueueCount> countByStatusAndEntityUuids(@Param("status") CeQueueDto.Status status, @Param("entityUuids") List<String> entityUuids);
 
   void insert(CeQueueDto dto);
 
index f8d7bd5e5fabbe3527f1d226dcbc2d413c645111..eae17ef1c3aed13f49fad5dee38ada2ce3772543 100644 (file)
@@ -37,7 +37,7 @@ public class CeTaskQuery {
   private boolean onlyCurrents = false;
   // SONAR-7681 a public implementation of List must be used in MyBatis - potential concurrency exceptions otherwise
   @Nullable
-  private ArrayList<String> mainComponentUuids;
+  private ArrayList<String> entityUuids;
   @Nullable
   private ArrayList<String> statuses;
   @Nullable
@@ -52,24 +52,24 @@ public class CeTaskQuery {
   private ArrayList<String> errorTypes;
 
   @CheckForNull
-  public List<String> getMainComponentUuids() {
-    return mainComponentUuids;
+  public List<String> getEntityUuids() {
+    return entityUuids;
   }
 
-  public CeTaskQuery setMainComponentUuids(@Nullable List<String> l) {
-    this.mainComponentUuids = l == null ? null : newArrayList(l);
+  public CeTaskQuery setEntityUuids(@Nullable List<String> l) {
+    this.entityUuids = l == null ? null : newArrayList(l);
     return this;
   }
 
-  public boolean isShortCircuitedByMainComponentUuids() {
-    return mainComponentUuids != null && (mainComponentUuids.isEmpty() || mainComponentUuids.size() > MAX_COMPONENT_UUIDS);
+  public boolean isShortCircuitedByEntityUuids() {
+    return entityUuids != null && (entityUuids.isEmpty() || entityUuids.size() > MAX_COMPONENT_UUIDS);
   }
 
-  public CeTaskQuery setMainComponentUuid(@Nullable String s) {
+  public CeTaskQuery setEntityUuid(@Nullable String s) {
     if (s == null) {
-      this.mainComponentUuids = null;
+      this.entityUuids = null;
     } else {
-      this.mainComponentUuids = newArrayList(s);
+      this.entityUuids = newArrayList(s);
     }
     return this;
   }
index c9ba956687517d7ee3c2faa4bcf703e5d4263fe7..75eb778fc910d1f2246776c771ac3215946e22bb 100644 (file)
 package org.sonar.db.ce;
 
 public class PrOrBranchTask extends CeTaskDtoLight {
-  private String mainComponentUuid;
+  private String entityUuid;
   private String taskType;
   private String branchType;
   private String componentUuid;
 
-  public String getMainComponentUuid() {
-    return mainComponentUuid;
+  public String getEntityUuid() {
+    return entityUuid;
   }
 
   public String getBranchType() {
index 2d02ab6406a6b7d52a1cc7889e7d358252f7890d..e2400753d2086d5ebaf0e485c0e81b74ae073284 100644 (file)
@@ -21,11 +21,11 @@ package org.sonar.db.ce;
 
 public class QueueCount {
   // set by reflection by MyBatis
-  private String mainComponentUuid;
+  private String entityUuid;
   private int total;
 
-  public String getMainComponentUuid() {
-    return mainComponentUuid;
+  public String getEntityUuid() {
+    return entityUuid;
   }
 
   public int getTotal() {
index 9dcfb0e72de9806e011db25c9563c6cd07dfc78b..98252f9af48f7764bd4dc9e4c09baff4c90ca517 100644 (file)
@@ -52,8 +52,8 @@ public class LiveMeasureDao implements Dao {
       componentUuids -> mapper(dbSession).selectByComponentUuidsAndMetricUuids(componentUuids, metricUuids));
   }
 
-  public List<LiveMeasureDto> selectForProjectsByMetricUuids(DbSession dbSession, Collection<String> metricUuids) {
-    return mapper(dbSession).selectForProjectsByMetricUuids(metricUuids);
+  public List<ProjectMainBranchLiveMeasureDto> selectForProjectMainBranchesByMetricUuids(DbSession dbSession, Collection<String> metricUuids) {
+    return mapper(dbSession).selectForProjectMainBranchesByMetricUuids(metricUuids);
   }
 
   public void scrollSelectByComponentUuidAndMetricKeys(DbSession dbSession, String componentUuid, Collection<String> metricKeys, ResultHandler<LiveMeasureDto> handler) {
index 9b84c0c3cee3c7146f94610403621250cfb635b8..be9d8f528b4ad415b843f3d8d172b04b56931f29 100644 (file)
@@ -31,7 +31,7 @@ public interface LiveMeasureMapper {
     @Param("componentUuids") Collection<String> componentUuids,
     @Param("metricUuids") Collection<String> metricUuids);
 
-  List<LiveMeasureDto> selectForProjectsByMetricUuids(
+  List<ProjectMainBranchLiveMeasureDto> selectForProjectMainBranchesByMetricUuids(
     @Param("metricUuids") Collection<String> metricUuids);
 
   List<LiveMeasureDto> selectByComponentUuidsAndMetricKeys(
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMainBranchLiveMeasureDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMainBranchLiveMeasureDto.java
new file mode 100644 (file)
index 0000000..17bb8ce
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.measure;
+
+import javax.annotation.Nullable;
+
+public class ProjectMainBranchLiveMeasureDto {
+  private String projectUuid;
+  private String metricUuid;
+  @Nullable
+  private Double value;
+  @Nullable
+  private String textValue;
+
+  public String getProjectUuid() {
+    return projectUuid;
+  }
+
+  @Nullable
+  public Double getValue() {
+    return value;
+  }
+
+  @Nullable
+  public String getTextValue() {
+    return textValue;
+  }
+
+  public String getMetricUuid() {
+    return metricUuid;
+  }
+}
index fd81f85e8099bf89e72c274a2f50b631208f65f6..b3fd50293b55f70ad2e22618e6d9c78f5daa168f 100644 (file)
@@ -164,16 +164,8 @@ public class QualityProfileDao implements Dao {
     return mapper(dbSession).selectAssociatedToProjectUuidAndLanguage(project.getUuid(), language);
   }
 
-  public List<QProfileDto> selectAssociatedToProjectUuidAndLanguages(DbSession dbSession, String projectUuid, Collection<String> languages) {
-    return executeLargeInputs(languages, partition -> mapper(dbSession).selectAssociatedToProjectUuidAndLanguages(projectUuid, partition));
-  }
-
   public List<QProfileDto> selectAssociatedToProjectAndLanguages(DbSession dbSession, ProjectDto project, Collection<String> languages) {
-    return selectAssociatedToProjectUuidAndLanguages(dbSession, project.getUuid(), languages);
-  }
-
-  public List<String> selectQProfileUuidsByProjectUuid(DbSession dbSession, String projectUuid) {
-    return mapper(dbSession).selectQProfileUuidsByProjectUuid(projectUuid);
+    return executeLargeInputs(languages, partition -> mapper(dbSession).selectAssociatedToProjectUuidAndLanguages(project.getUuid(), partition));
   }
 
   public List<QProfileDto> selectQProfilesByProjectUuid(DbSession dbSession, String projectUuid) {
index 3f764cf9aeeb91a1fc370eae162b64cd37ccb34b..13a3e690a1893fb8adcd1703bc57d07fe38c3002 100644 (file)
@@ -94,8 +94,6 @@ public interface QualityProfileMapper {
     @Param("projectUuid") String projectUuid,
     @Param("languages") Collection<String> languages);
 
-  List<String> selectQProfileUuidsByProjectUuid(@Param("projectUuid") String projectUuid);
-
   List<QProfileDto> selectQProfilesByProjectUuid(@Param("projectUuid") String projectUuid);
 
   void insertProjectProfileAssociation(
index 07a3d8e4411436f31a885d989f0883f70469de42..b7761f317710833e18d1f3804ef0340e6cf43826 100644 (file)
@@ -20,7 +20,7 @@
     ca.node_name as nodeName,
     ca.task_type as taskType,
     ca.component_uuid as componentUuid,
-    ca.main_component_uuid as mainComponentUuid,
+    ca.entity_uuid as entityUuid,
     ca.analysis_uuid as analysisUuid,
     ca.status as status,
     ca.submitter_uuid as submitterUuid,
       <if test="query.onlyCurrents">
         and ca.main_is_last=${_true}
       </if>
-      <if test="query.mainComponentUuids != null and query.mainComponentUuids.size()>0">
-        and ca.main_component_uuid in
-        <foreach collection="query.mainComponentUuids" open="(" close=")" item="cUuid" separator=",">
+      <if test="query.entityUuids != null and query.entityUuids.size()>0">
+        and ca.entity_uuid in
+        <foreach collection="query.entityUuids" open="(" close=")" item="cUuid" separator=",">
           #{cUuid,jdbcType=VARCHAR}
         </foreach>
       </if>
       ca.created_at &gt; #{afterDate,jdbcType=BIGINT}
   </select>
 
-  <select id="countLastByStatusAndMainComponentUuid" resultType="int">
+  <select id="countLastByStatusAndEntityUuid" resultType="int">
     select
       count(1)
     from
     where
       main_is_last=${_true}
       and status=#{status,jdbcType=VARCHAR}
-      <if test="mainComponentUuid!=null">
-        and main_component_uuid=#{mainComponentUuid,jdbcType=VARCHAR}
+      <if test="entityUuid!=null">
+        and entity_uuid=#{entityUuid,jdbcType=VARCHAR}
       </if>
   </select>
 
       uuid,
       node_name,
       component_uuid,
-      main_component_uuid,
+      entity_uuid,
       analysis_uuid,
       status,
       task_type,
       #{uuid,jdbcType=VARCHAR},
       #{nodeName,jdbcType=VARCHAR},
       #{componentUuid,jdbcType=VARCHAR},
-      #{mainComponentUuid,jdbcType=VARCHAR},
+      #{entityUuid,jdbcType=VARCHAR},
       #{analysisUuid,jdbcType=VARCHAR},
       #{status,jdbcType=VARCHAR},
       #{taskType,jdbcType=VARCHAR},
index 550aa6789b46ff2792a4ff38b9e99a77e994143a..613d709686bf9af7424b77fe4e4cb56713c92b6b 100644 (file)
@@ -7,7 +7,7 @@
     cq.uuid,
     cq.task_type as taskType,
     cq.component_uuid as componentUuid,
-    cq.main_component_uuid as mainComponentUuid,
+    cq.entity_uuid as entityUuid,
     cq.status as status,
     cq.submitter_uuid as submitterUuid,
     cq.worker_uuid as workerUuid,
       cq.uuid=#{uuid,jdbcType=VARCHAR}
   </select>
 
-  <select id="countByStatusAndMainComponentUuid" parameterType="map" resultType="int">
+  <select id="countByStatusAndEntityUuid" parameterType="map" resultType="int">
     select
       count(1)
     from
       ce_queue
     where
       status=#{status,jdbcType=VARCHAR}
-      <if test="mainComponentUuid!=null">
-        and main_component_uuid=#{mainComponentUuid,jdbcType=VARCHAR}
+      <if test="entityUuid!=null">
+        and entity_uuid=#{entityUuid,jdbcType=VARCHAR}
       </if>
   </select>
 
-  <select id="selectCreationDateOfOldestPendingByMainComponentUuid" parameterType="map" resultType="Long">
+  <select id="selectCreationDateOfOldestPendingByEntityUuid" parameterType="map" resultType="Long">
     select
       min(created_at)
     from
       ce_queue
     where
       status='PENDING'
-      <if test="mainComponentUuid!=null">
-        and main_component_uuid=#{mainComponentUuid,jdbcType=VARCHAR}
+      <if test="entityUuid!=null">
+        and entity_uuid=#{entityUuid,jdbcType=VARCHAR}
       </if>
   </select>
 
-  <select id="countByStatusAndMainComponentUuids" resultType="org.sonar.db.ce.QueueCount">
+  <select id="countByStatusAndEntityUuids" resultType="org.sonar.db.ce.QueueCount">
     select
-      main_component_uuid as mainComponentUuid,
+      entity_uuid as entityUuid,
       count(1) as total
     from
       ce_queue
     where
       status=#{status,jdbcType=VARCHAR}
-      and main_component_uuid in
-      <foreach collection="mainComponentUuids" open="(" close=")" item="mainComponentUuid" separator=",">
-        #{mainComponentUuid,jdbcType=VARCHAR}
+      and entity_uuid in
+      <foreach collection="entityUuids" open="(" close=")" item="entityUuid" separator=",">
+        #{entityUuid,jdbcType=VARCHAR}
       </foreach>
-    group by main_component_uuid
+    group by entity_uuid
   </select>
 
   <select id="countAll" resultType="int">
       ce_queue
   </select>
 
-  <select id="selectByMainComponentUuid" parameterType="String" resultType="org.sonar.db.ce.CeQueueDto">
+  <select id="selectByEntityUuid" parameterType="String" resultType="org.sonar.db.ce.CeQueueDto">
     select
       <include refid="columns"/>
     from
       ce_queue cq
     where
-      cq.main_component_uuid=#{mainComponentUuid,jdbcType=VARCHAR}
+      cq.entity_uuid=#{entityUuid,jdbcType=VARCHAR}
     <include refid="orderByDateAndUuid"/>
   </select>
 
     from
       ce_queue cq
     <where>
-      <if test="query.mainComponentUuids != null and query.mainComponentUuids.size()>0">
-        and cq.main_component_uuid in
-        <foreach collection="query.mainComponentUuids" open="(" close=")" item="mainComponentUuid" separator=",">
-          #{mainComponentUuid,jdbcType=VARCHAR}
+      <if test="query.entityUuids != null and query.entityUuids.size()>0">
+        and cq.entity_uuid in
+        <foreach collection="query.entityUuids" open="(" close=")" item="entityUuid" separator=",">
+          #{entityUuid,jdbcType=VARCHAR}
         </foreach>
       </if>
       <if test="query.statuses != null">
     from
       ce_queue cq
     <if test="excludeViewRefresh">
-        left join components c on c.uuid = cq.main_component_uuid and c.qualifier &lt;&gt; 'VW'
+        left join components c on c.uuid = cq.entity_uuid and c.qualifier &lt;&gt; 'VW'
     </if>
-      left join ce_queue cq2 on cq.main_component_uuid=cq2.main_component_uuid and cq2.status &lt;&gt;'PENDING'
+      left join ce_queue cq2 on cq.entity_uuid=cq2.entity_uuid and cq2.status &lt;&gt;'PENDING'
     where
       cq.status='PENDING'
       and cq.started_at is null
       uuid,
       task_type,
       component_uuid,
-      main_component_uuid,
+      entity_uuid,
       status,
       submitter_uuid,
       worker_uuid,
       #{uuid,jdbcType=VARCHAR},
       #{taskType,jdbcType=VARCHAR},
       #{componentUuid,jdbcType=VARCHAR},
-      #{mainComponentUuid,jdbcType=VARCHAR},
+      #{entityUuid,jdbcType=VARCHAR},
       #{status,jdbcType=VARCHAR},
       #{submitterUuid,jdbcType=VARCHAR},
       #{workerUuid,jdbcType=VARCHAR},
 
   <sql id="oldestPendingPrOrBranch">
     cq.uuid as ceTaskUuid,
-      cq.main_component_uuid as mainComponentUuid,
+      cq.entity_uuid as entityUuid,
       cq.component_uuid as componentUuid,
       cq.created_at as createdAt,
       cq.task_type as taskType,
   <select id="selectInProgressWithCharacteristics" resultType="org.sonar.db.ce.PrOrBranchTask">
     select
       cq.uuid as ceTaskUuid,
-      cq.main_component_uuid as mainComponentUuid,
+      cq.entity_uuid as entityUuid,
       cq.created_at as createdAt,
       coalesce(ctc.kee, 'branch') as branchType,
       cq.task_type as taskType,
index 7a775ff681e30299c053e59a52e3196f0ac3037f..c02a554e319f036bffa5e57cd3d6c92571ebfa5d 100644 (file)
     </foreach>
   </select>
 
-  <select id="selectForProjectsByMetricUuids" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
-    select <include refid="columns"/> from live_measures lm
+  <select id="selectForProjectMainBranchesByMetricUuids" parameterType="map" resultType="org.sonar.db.measure.ProjectMainBranchLiveMeasureDto">
+    select p.uuid as projectUuid, lm.metric_uuid as metricUuid, lm.value as value, lm.text_value as textValue
+    from live_measures lm
+    inner join project_branches pb on pb.uuid = lm.component_uuid
+    inner join projects p on p.uuid = pb.project_uuid
     where
     lm.metric_uuid in <foreach item="metricUuid" collection="metricUuids" open="(" separator=","
                                close=")">#{metricUuid, jdbcType=VARCHAR}</foreach>
-    and component_uuid in (SELECT
-      p.uuid as uuid
-    FROM projects p
-    where p.qualifier = 'TRK')
+    and p.qualifier = 'TRK'
   </select>
 
   <select id="selectByComponentUuidsAndMetricKeys" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
     select count(1)
       from live_measures lm
       inner join metrics m on m.uuid = lm.metric_uuid AND m.name = #{metric, jdbcType=VARCHAR}
-      inner join projects p on p.uuid = lm.project_uuid and p.qualifier = 'TRK'
+      inner join project_branches pb on pb.uuid = lm.project_uuid
+      inner join projects p on p.uuid = pb.project_uuid and p.qualifier = 'TRK'
+
   </select>
 
   <insert id="insert" parameterType="map" useGeneratedKeys="false">
index 4185dc33127a7379e805f1a5352bf46a26e045b3..7e1abf38c5a036c744ba0b7ac35d25284d4ee1f1 100644 (file)
         created_at &lt; #{createdAtBefore,jdbcType=BIGINT}
         and (
           component_uuid=#{rootUuid,jdbcType=VARCHAR}
-          or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
+          or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
         )
       </when>
       <when test="createdAtBefore != null">
       </when>
       <when test="rootUuid != null">
         component_uuid=#{rootUuid,jdbcType=VARCHAR}
-        or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
+        or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
       </when>
       <!-- safety net when both variables are null to never generate a
            delete statement deleting the whole table -->
         from ce_queue
         where
           component_uuid=#{rootUuid,jdbcType=VARCHAR}
-          or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
+          or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
       )
   </delete>
 
         from ce_queue
         where
           component_uuid=#{rootUuid,jdbcType=VARCHAR}
-          or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
+          or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
       )
   </delete>
 
         from ce_queue
         where
           component_uuid=#{rootUuid,jdbcType=VARCHAR}
-          or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
+          or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
       )
   </delete>
 
         from ce_queue
         where
           component_uuid=#{rootUuid,jdbcType=VARCHAR}
-          or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
+          or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
       )
   </delete>
 
     delete from ce_queue
     where
       component_uuid=#{rootUuid,jdbcType=VARCHAR}
-      or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
+      or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
   </delete>
 
   <delete id="deleteNewCodePeriodsByRootUuid">
index a04ee1524d8e0a0d6d1e2a7216dff87707fa6ec7..e68c9261ef41052bf9c11bf8415b8279c399ddbb 100644 (file)
       and pqp.project_uuid = #{projectUuid, jdbcType=VARCHAR}
   </select>
 
-  <select id="selectQProfileUuidsByProjectUuid" parameterType="String" resultType="String">
-    SELECT profile_key
-    FROM project_qprofiles
-    <where>
-      AND project_uuid=#{projectUuid}
-    </where>
-  </select>
-
   <select id="selectQProfilesByProjectUuid" parameterType="String" resultType="org.sonar.db.qualityprofile.QProfileDto">
     select
     <include refid="qProfileColumns"/>
index bc0e9947b3061f6f795bc059b8c1898173799f52..6984619c21264f22b87473a60c52d826257b2d16 100644 (file)
@@ -117,7 +117,7 @@ CREATE INDEX "AUDITS_CREATED_AT" ON "AUDITS"("CREATED_AT" NULLS FIRST);
 CREATE TABLE "CE_ACTIVITY"(
     "UUID" CHARACTER VARYING(40) NOT NULL,
     "TASK_TYPE" CHARACTER VARYING(40) NOT NULL,
-    "MAIN_COMPONENT_UUID" CHARACTER VARYING(40),
+    "ENTITY_UUID" CHARACTER VARYING(40),
     "COMPONENT_UUID" CHARACTER VARYING(40),
     "STATUS" CHARACTER VARYING(15) NOT NULL,
     "MAIN_IS_LAST" BOOLEAN NOT NULL,
@@ -143,14 +143,14 @@ ALTER TABLE "CE_ACTIVITY" ADD CONSTRAINT "PK_CE_ACTIVITY" PRIMARY KEY("UUID");
 CREATE INDEX "CE_ACTIVITY_COMPONENT" ON "CE_ACTIVITY"("COMPONENT_UUID" NULLS FIRST);
 CREATE INDEX "CE_ACTIVITY_ISLAST" ON "CE_ACTIVITY"("IS_LAST" NULLS FIRST, "STATUS" NULLS FIRST);
 CREATE INDEX "CE_ACTIVITY_ISLAST_KEY" ON "CE_ACTIVITY"("IS_LAST_KEY" NULLS FIRST);
-CREATE INDEX "CE_ACTIVITY_MAIN_COMPONENT" ON "CE_ACTIVITY"("MAIN_COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "CE_ACTIVITY_MAIN_COMPONENT" ON "CE_ACTIVITY"("ENTITY_UUID" NULLS FIRST);
 CREATE INDEX "CE_ACTIVITY_MAIN_ISLAST" ON "CE_ACTIVITY"("MAIN_IS_LAST" NULLS FIRST, "STATUS" NULLS FIRST);
 CREATE INDEX "CE_ACTIVITY_MAIN_ISLAST_KEY" ON "CE_ACTIVITY"("MAIN_IS_LAST_KEY" NULLS FIRST);
 
 CREATE TABLE "CE_QUEUE"(
     "UUID" CHARACTER VARYING(40) NOT NULL,
     "TASK_TYPE" CHARACTER VARYING(40) NOT NULL,
-    "MAIN_COMPONENT_UUID" CHARACTER VARYING(40),
+    "ENTITY_UUID" CHARACTER VARYING(40),
     "COMPONENT_UUID" CHARACTER VARYING(40),
     "STATUS" CHARACTER VARYING(15),
     "SUBMITTER_UUID" CHARACTER VARYING(255),
@@ -161,7 +161,7 @@ CREATE TABLE "CE_QUEUE"(
     "UPDATED_AT" BIGINT NOT NULL
 );
 ALTER TABLE "CE_QUEUE" ADD CONSTRAINT "PK_CE_QUEUE" PRIMARY KEY("UUID");
-CREATE INDEX "CE_QUEUE_MAIN_COMPONENT" ON "CE_QUEUE"("MAIN_COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "CE_QUEUE_MAIN_COMPONENT" ON "CE_QUEUE"("ENTITY_UUID" NULLS FIRST);
 CREATE INDEX "CE_QUEUE_COMPONENT" ON "CE_QUEUE"("COMPONENT_UUID" NULLS FIRST);
 
 CREATE TABLE "CE_SCANNER_CONTEXT"(
index 702551ef98e52088e12ffdf8d12b8def7bda0d3f..b7790e5d295f34815396eab3661e4a568c6b06a4 100644 (file)
@@ -44,7 +44,7 @@ public class CeActivityDtoTest {
       .setUuid(randomAlphanumeric(10))
       .setTaskType(randomAlphanumeric(11))
       .setComponentUuid(randomAlphanumeric(12))
-      .setMainComponentUuid(randomAlphanumeric(13))
+      .setEntityUuid(randomAlphanumeric(13))
       .setSubmitterUuid(randomAlphanumeric(14))
       .setWorkerUuid(randomAlphanumeric(15))
       .setCreatedAt(now + 9_999)
@@ -55,10 +55,10 @@ public class CeActivityDtoTest {
     assertThat(underTest.getUuid()).isEqualTo(ceQueueDto.getUuid());
     assertThat(underTest.getTaskType()).isEqualTo(ceQueueDto.getTaskType());
     assertThat(underTest.getComponentUuid()).isEqualTo(ceQueueDto.getComponentUuid());
-    assertThat(underTest.getMainComponentUuid()).isEqualTo(ceQueueDto.getMainComponentUuid());
+    assertThat(underTest.getEntityUuid()).isEqualTo(ceQueueDto.getEntityUuid());
     assertThat(underTest.getIsLastKey()).isEqualTo(ceQueueDto.getTaskType() + ceQueueDto.getComponentUuid());
     assertThat(underTest.getIsLast()).isFalse();
-    assertThat(underTest.getMainIsLastKey()).isEqualTo(ceQueueDto.getTaskType() + ceQueueDto.getMainComponentUuid());
+    assertThat(underTest.getMainIsLastKey()).isEqualTo(ceQueueDto.getTaskType() + ceQueueDto.getEntityUuid());
     assertThat(underTest.getMainIsLast()).isFalse();
     assertThat(underTest.getSubmitterUuid()).isEqualTo(ceQueueDto.getSubmitterUuid());
     assertThat(underTest.getWorkerUuid()).isEqualTo(ceQueueDto.getWorkerUuid());
@@ -86,19 +86,19 @@ public class CeActivityDtoTest {
 
   @Test
   public void setMainComponentUuid_accepts_null_empty_and_string_40_chars_or_less() {
-    underTest.setMainComponentUuid(null);
-    underTest.setMainComponentUuid("");
-    underTest.setMainComponentUuid("bar");
-    underTest.setMainComponentUuid(STR_40_CHARS);
+    underTest.setEntityUuid(null);
+    underTest.setEntityUuid("");
+    underTest.setEntityUuid("bar");
+    underTest.setEntityUuid(STR_40_CHARS);
   }
 
   @Test
-  public void setMainComponentUuid_throws_IAE_if_value_is_41_chars() {
+  public void seEntityUuid_throws_IAE_if_value_is_41_chars() {
     String str_41_chars = STR_40_CHARS + "a";
 
-    assertThatThrownBy(() -> underTest.setMainComponentUuid(str_41_chars))
+    assertThatThrownBy(() -> underTest.setEntityUuid(str_41_chars))
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("Value is too long for column CE_ACTIVITY.MAIN_COMPONENT_UUID: " + str_41_chars);
+      .hasMessage("Value is too long for column CE_ACTIVITY.ENTITY_UUID: " + str_41_chars);
   }
 
   @Test
index 3bdb4f1183ecf2fcebb01209fcad0ca2c8e55a3c..a6f9797922e24b6985c04b10ff5227be8abc7973 100644 (file)
@@ -48,20 +48,20 @@ public class CeQueueDtoTest {
   }
 
   @Test
-  public void setMainComponentUuid_accepts_null_empty_and_string_40_chars_or_less() {
-    underTest.setMainComponentUuid(null);
-    underTest.setMainComponentUuid("");
-    underTest.setMainComponentUuid("bar");
-    underTest.setMainComponentUuid(STR_40_CHARS);
+  public void setEntityUuid_accepts_null_empty_and_string_40_chars_or_less() {
+    underTest.setEntityUuid(null);
+    underTest.setEntityUuid("");
+    underTest.setEntityUuid("bar");
+    underTest.setEntityUuid(STR_40_CHARS);
   }
 
   @Test
-  public void setMainComponentUuid_throws_IAE_if_value_is_41_chars() {
+  public void setEntityUuid_throws_IAE_if_value_is_41_chars() {
     String str_41_chars = STR_40_CHARS + "a";
 
-    assertThatThrownBy(() -> underTest.setMainComponentUuid(str_41_chars))
+    assertThatThrownBy(() -> underTest.setEntityUuid(str_41_chars))
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("Value is too long for column CE_QUEUE.MAIN_COMPONENT_UUID: " + str_41_chars);
+      .hasMessage("Value is too long for column CE_QUEUE.ENTITY_UUID: " + str_41_chars);
   }
 
   @Test
index 01f36a55bab6b0984da75432251cfcddcda72302..46a43adc34ea1bb1eb9451e0083bbb45c89522d5 100644 (file)
@@ -32,49 +32,49 @@ public class CeTaskQueryTest {
   CeTaskQuery underTest = new CeTaskQuery();
 
   @Test
-  public void no_filter_on_component_uuids_by_default() {
-    assertThat(underTest.getMainComponentUuids()).isNull();
-    assertThat(underTest.isShortCircuitedByMainComponentUuids()).isFalse();
+  public void no_filter_on_entity_uuids_by_default() {
+    assertThat(underTest.getEntityUuids()).isNull();
+    assertThat(underTest.isShortCircuitedByEntityUuids()).isFalse();
   }
 
   @Test
-  public void filter_on_component_uuid() {
-    underTest.setMainComponentUuid("UUID1");
-    assertThat(underTest.getMainComponentUuids()).containsOnly("UUID1");
-    assertThat(underTest.isShortCircuitedByMainComponentUuids()).isFalse();
+  public void filter_on_entity_uuid() {
+    underTest.setEntityUuid("UUID1");
+    assertThat(underTest.getEntityUuids()).containsOnly("UUID1");
+    assertThat(underTest.isShortCircuitedByEntityUuids()).isFalse();
   }
 
   @Test
-  public void filter_on_multiple_component_uuids() {
-    underTest.setMainComponentUuids(asList("UUID1", "UUID2"));
-    assertThat(underTest.getMainComponentUuids()).containsOnly("UUID1", "UUID2");
-    assertThat(underTest.isShortCircuitedByMainComponentUuids()).isFalse();
+  public void filter_on_multiple_entity_uuids() {
+    underTest.setEntityUuids(asList("UUID1", "UUID2"));
+    assertThat(underTest.getEntityUuids()).containsOnly("UUID1", "UUID2");
+    assertThat(underTest.isShortCircuitedByEntityUuids()).isFalse();
   }
 
   /**
-   * componentUuid is not null but is set to empty
+   * entityUuid is not null but is set to empty
    * --> no results
    */
   @Test
-  public void short_circuited_if_empty_component_uuid_filter() {
-    underTest.setMainComponentUuids(Collections.emptyList());
-    assertThat(underTest.getMainComponentUuids()).isEmpty();
-    assertThat(underTest.isShortCircuitedByMainComponentUuids()).isTrue();
+  public void short_circuited_if_empty_entity_uuid_filter() {
+    underTest.setEntityUuids(Collections.emptyList());
+    assertThat(underTest.getEntityUuids()).isEmpty();
+    assertThat(underTest.isShortCircuitedByEntityUuids()).isTrue();
   }
 
   /**
-   * too many componentUuids for SQL request. Waiting for ES to improve this use-case
+   * too many entityUuids for SQL request. Waiting for ES to improve this use-case
    * --> no results
    */
   @Test
-  public void short_circuited_if_too_many_component_uuid_filters() {
+  public void short_circuited_if_too_many_entity_uuid_filters() {
     List<String> uuids = new ArrayList<>();
     for (int i = 0; i < CeTaskQuery.MAX_COMPONENT_UUIDS + 2; i++) {
       uuids.add(String.valueOf(i));
     }
-    underTest.setMainComponentUuids(uuids);
-    assertThat(underTest.getMainComponentUuids()).hasSize(CeTaskQuery.MAX_COMPONENT_UUIDS + 2);
-    assertThat(underTest.isShortCircuitedByMainComponentUuids()).isTrue();
+    underTest.setEntityUuids(uuids);
+    assertThat(underTest.getEntityUuids()).hasSize(CeTaskQuery.MAX_COMPONENT_UUIDS + 2);
+    assertThat(underTest.isShortCircuitedByEntityUuids()).isTrue();
   }
 
   @Test
index 9dfcacbb9dd6333eb9782902de6636405d987588..1e05d7d500d8749f00b7105751d4cbb27d6e0e92 100644 (file)
@@ -38,7 +38,7 @@ public class CeQueueTesting {
     return new CeQueueDto()
       .setUuid(uuid)
       .setComponentUuid(randomAlphanumeric(40))
-      .setMainComponentUuid(randomAlphanumeric(39))
+      .setEntityUuid(randomAlphanumeric(39))
       .setStatus(CeQueueDto.Status.PENDING)
       .setTaskType(CeTaskTypes.REPORT)
       .setSubmitterUuid(randomAlphanumeric(255))
index 927d448abf1aba73d06ad3ef9e25a8c3add45eec..845d5a1284fa0761c8734f89df8443fc5cf05784 100644 (file)
@@ -53,19 +53,19 @@ public class ComponentTesting {
     return newFileDto(projectOrBranch, directory, Uuids.createFast(), mainBranchUuid);
   }
 
-  public static ComponentDto newFileDto(ComponentDto project, @Nullable ComponentDto directory, String fileUuid) {
-    return newFileDto(project, directory, fileUuid, null);
+  public static ComponentDto newFileDto(ComponentDto branch, @Nullable ComponentDto directory, String fileUuid) {
+    return newFileDto(branch, directory, fileUuid, null);
   }
 
-  public static ComponentDto newFileDto(ComponentDto project, @Nullable ComponentDto directory, String fileUuid, @Nullable String mainBranchUuid) {
+  public static ComponentDto newFileDto(ComponentDto branch, @Nullable ComponentDto directory, String fileUuid, @Nullable String mainBranchUuid) {
     String filename = "NAME_" + fileUuid;
-    String path = directory != null ? directory.path() + "/" + filename : project.path() + "/" + filename;
-    return newChildComponent(fileUuid, project, directory == null ? project : directory)
+    String path = directory != null ? directory.path() + "/" + filename : branch.path() + "/" + filename;
+    return newChildComponent(fileUuid, branch, directory == null ? branch : directory)
       .setKey("FILE_KEY_" + fileUuid)
       .setName(filename)
       .setLongName(path)
       .setScope(Scopes.FILE)
-      .setBranchUuid(project.branchUuid())
+      .setBranchUuid(branch.branchUuid())
       .setMainBranchProjectUuid(mainBranchUuid)
       .setQualifier(Qualifiers.FILE)
       .setPath(path)
@@ -207,18 +207,18 @@ public class ComponentTesting {
       .setLanguage(null);
   }
 
-  public static ComponentDto newChildComponent(String uuid, ComponentDto project, ComponentDto parent) {
-    checkArgument(project.isPrivate() == parent.isPrivate(),
-      "private flag inconsistent between moduleOrProject (%s) and parent (%s)",
-      project.isPrivate(), parent.isPrivate());
+  public static ComponentDto newChildComponent(String uuid, ComponentDto branch, ComponentDto parent) {
+    checkArgument(branch.isPrivate() == parent.isPrivate(),
+      "private flag inconsistent between branch (%s) and parent (%s)",
+      branch.isPrivate(), parent.isPrivate());
     return new ComponentDto()
       .setUuid(uuid)
       .setUuidPath(formatUuidPathFromParent(parent))
       .setKey(uuid)
-      .setBranchUuid(project.branchUuid())
+      .setBranchUuid(branch.branchUuid())
       .setCreatedAt(new Date())
       .setEnabled(true)
-      .setPrivate(project.isPrivate());
+      .setPrivate(branch.isPrivate());
   }
 
 
index 2538f920ac0bf311add54073e9dd6ca3e436b5cc..597258a9e786e1ac99b8414cd8dd522beb131af5 100644 (file)
@@ -101,8 +101,8 @@ public class QualityGateDbTester {
     return condition;
   }
 
-  public Optional<String> selectQGateUuidByComponentUuid(String componentUuid) {
-    return dbClient.projectQgateAssociationDao().selectQGateUuidByProjectUuid(dbSession, componentUuid);
+  public Optional<String> selectQGateUuidByProjectUuid(String projectUuid) {
+    return dbClient.projectQgateAssociationDao().selectQGateUuidByProjectUuid(dbSession, projectUuid);
   }
 
   public void addGroupPermission(QualityGateDto qualityGateDto, GroupDto group) {
index a306b61bbe540e54f03ff719a3f055d5e29790f6..60008a21274437747f1b91575023a50f8868e3fb 100644 (file)
@@ -41,7 +41,10 @@ public class DbVersion102 implements DbVersion {
   @Override
   public void addSteps(MigrationStepRegistry registry) {
     registry.add(10_2_000, "Rename 'component_uuid' in 'user_roles' table to 'entity_uuid'", RenameComponentUuidInUserRoles.class)
-      .add(10_2_001, "Rename 'component_uuid' in 'group_roles' table to 'entity_uuid'", RenameComponentUuidInGroupRoles.class);
+      .add(10_2_001, "Rename 'component_uuid' in 'group_roles' table to 'entity_uuid'", RenameComponentUuidInGroupRoles.class)
+      .add(10_2_002, "Rename 'main_component_uuid' in 'ce_activity' table to 'entity_uuid'", RenameMainComponentUuidInCeActivity.class)
+      .add(10_2_003, "Rename 'main_component_uuid' in 'ce_queue' table to 'entity_uuid'", RenameMainComponentUuidInCeQueue.class)
+    ;
   }
 
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivity.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivity.java
new file mode 100644 (file)
index 0000000..c41576a
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange;
+
+public class RenameMainComponentUuidInCeActivity extends RenameVarcharColumnChange {
+
+  private static final String TABLE_NAME = "ce_activity";
+  private static final String OLD_COLUMN_NAME = "main_component_uuid";
+  private static final String NEW_COLUMN_NAME = "entity_uuid";
+
+  public RenameMainComponentUuidInCeActivity(Database db) {
+    super(db, TABLE_NAME, OLD_COLUMN_NAME, NEW_COLUMN_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueue.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueue.java
new file mode 100644 (file)
index 0000000..89a357f
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange;
+
+public class RenameMainComponentUuidInCeQueue extends RenameVarcharColumnChange {
+
+  private static final String TABLE_NAME = "ce_queue";
+  private static final String OLD_COLUMN_NAME = "main_component_uuid";
+  private static final String NEW_COLUMN_NAME = "entity_uuid";
+
+  public RenameMainComponentUuidInCeQueue(Database db) {
+    super(db, TABLE_NAME, OLD_COLUMN_NAME, NEW_COLUMN_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivityTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivityTest.java
new file mode 100644 (file)
index 0000000..44b1785
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.VARCHAR;
+
+public class RenameMainComponentUuidInCeActivityTest {
+  public static final String TABLE_NAME = "ce_activity";
+  public static final String NEW_COLUMN_NAME = "entity_uuid";
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(RenameMainComponentUuidInCeActivityTest.class, "schema.sql");
+
+  private final RenameMainComponentUuidInCeActivity underTest = new RenameMainComponentUuidInCeActivity(db.database());
+
+  @Test
+  public void column_is_renamed() throws SQLException {
+    db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+    underTest.execute();
+    db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true);
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+    underTest.execute();
+    underTest.execute();
+    db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueueTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueueTest.java
new file mode 100644 (file)
index 0000000..5274b00
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.VARCHAR;
+
+public class RenameMainComponentUuidInCeQueueTest {
+  public static final String TABLE_NAME = "ce_queue";
+  public static final String NEW_COLUMN_NAME = "entity_uuid";
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(RenameMainComponentUuidInCeQueueTest.class, "schema.sql");
+
+  private final RenameMainComponentUuidInCeQueue underTest = new RenameMainComponentUuidInCeQueue(db.database());
+
+  @Test
+  public void column_is_renamed() throws SQLException {
+    db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+    underTest.execute();
+    db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true);
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+    underTest.execute();
+    underTest.execute();
+    db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivityTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivityTest/schema.sql
new file mode 100644 (file)
index 0000000..dcb9f3a
--- /dev/null
@@ -0,0 +1,32 @@
+CREATE TABLE "CE_ACTIVITY"(
+    "UUID" CHARACTER VARYING(40) NOT NULL,
+    "TASK_TYPE" CHARACTER VARYING(40) NOT NULL,
+    "MAIN_COMPONENT_UUID" CHARACTER VARYING(40),
+    "COMPONENT_UUID" CHARACTER VARYING(40),
+    "STATUS" CHARACTER VARYING(15) NOT NULL,
+    "MAIN_IS_LAST" BOOLEAN NOT NULL,
+    "MAIN_IS_LAST_KEY" CHARACTER VARYING(55) NOT NULL,
+    "IS_LAST" BOOLEAN NOT NULL,
+    "IS_LAST_KEY" CHARACTER VARYING(55) NOT NULL,
+    "SUBMITTER_UUID" CHARACTER VARYING(255),
+    "SUBMITTED_AT" BIGINT NOT NULL,
+    "STARTED_AT" BIGINT,
+    "EXECUTED_AT" BIGINT,
+    "EXECUTION_COUNT" INTEGER NOT NULL,
+    "EXECUTION_TIME_MS" BIGINT,
+    "ANALYSIS_UUID" CHARACTER VARYING(50),
+    "ERROR_MESSAGE" CHARACTER VARYING(1000),
+    "ERROR_STACKTRACE" CHARACTER LARGE OBJECT,
+    "ERROR_TYPE" CHARACTER VARYING(20),
+    "WORKER_UUID" CHARACTER VARYING(40),
+    "CREATED_AT" BIGINT NOT NULL,
+    "UPDATED_AT" BIGINT NOT NULL,
+    "NODE_NAME" CHARACTER VARYING(100)
+);
+ALTER TABLE "CE_ACTIVITY" ADD CONSTRAINT "PK_CE_ACTIVITY" PRIMARY KEY("UUID");
+CREATE INDEX "CE_ACTIVITY_COMPONENT" ON "CE_ACTIVITY"("COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "CE_ACTIVITY_ISLAST" ON "CE_ACTIVITY"("IS_LAST" NULLS FIRST, "STATUS" NULLS FIRST);
+CREATE INDEX "CE_ACTIVITY_ISLAST_KEY" ON "CE_ACTIVITY"("IS_LAST_KEY" NULLS FIRST);
+CREATE INDEX "CE_ACTIVITY_MAIN_COMPONENT" ON "CE_ACTIVITY"("MAIN_COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "CE_ACTIVITY_MAIN_ISLAST" ON "CE_ACTIVITY"("MAIN_IS_LAST" NULLS FIRST, "STATUS" NULLS FIRST);
+CREATE INDEX "CE_ACTIVITY_MAIN_ISLAST_KEY" ON "CE_ACTIVITY"("MAIN_IS_LAST_KEY" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueueTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueueTest/schema.sql
new file mode 100644 (file)
index 0000000..63136b6
--- /dev/null
@@ -0,0 +1,16 @@
+CREATE TABLE "CE_QUEUE"(
+    "UUID" CHARACTER VARYING(40) NOT NULL,
+    "TASK_TYPE" CHARACTER VARYING(40) NOT NULL,
+    "MAIN_COMPONENT_UUID" CHARACTER VARYING(40),
+    "COMPONENT_UUID" CHARACTER VARYING(40),
+    "STATUS" CHARACTER VARYING(15),
+    "SUBMITTER_UUID" CHARACTER VARYING(255),
+    "STARTED_AT" BIGINT,
+    "WORKER_UUID" CHARACTER VARYING(40),
+    "EXECUTION_COUNT" INTEGER NOT NULL,
+    "CREATED_AT" BIGINT NOT NULL,
+    "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "CE_QUEUE" ADD CONSTRAINT "PK_CE_QUEUE" PRIMARY KEY("UUID");
+CREATE INDEX "CE_QUEUE_MAIN_COMPONENT" ON "CE_QUEUE"("MAIN_COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "CE_QUEUE_COMPONENT" ON "CE_QUEUE"("COMPONENT_UUID" NULLS FIRST);
index 533706cc7a3a4fb9aaa0caf7491fcbf13ddeda48..b1fd7dc36bc8d62b77580c6fa68548cf0f97b57d 100644 (file)
@@ -26,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 public class CeTaskTest {
 
-  private CeTask underTest = new CeTask("A", CeTask.Status.SUCCESS);
+  private final CeTask underTest = new CeTask("A", CeTask.Status.SUCCESS);
 
   @Test
   public void constructor_throws_NPE_if_id_is_null() {
index dd0e001b6fe5fd910b0dc42bdae3ef6b73944c3a..6d68b9c1e9b9352f5c2a04e370e7df66c92362a6 100644 (file)
@@ -153,12 +153,12 @@ public class AsyncIssueIndexingImpl implements AsyncIssueIndexing {
   }
 
   private void removeExistingIndexationTasksForProject(DbSession dbSession, String projectUuid) {
-    Set<String> ceQueueUuidsForProject = dbClient.ceQueueDao().selectByMainComponentUuid(dbSession, projectUuid)
+    Set<String> ceQueueUuidsForProject = dbClient.ceQueueDao().selectByEntityUuid(dbSession, projectUuid)
       .stream().filter(p -> p.getTaskType().equals(BRANCH_ISSUE_SYNC))
       .map(CeQueueDto::getUuid).collect(Collectors.toSet());
     Set<String> ceActivityUuidsForProject = dbClient.ceActivityDao().selectByTaskType(dbSession, BRANCH_ISSUE_SYNC)
       .stream()
-      .filter(ceActivityDto -> projectUuid.equals(ceActivityDto.getMainComponentUuid()))
+      .filter(ceActivityDto -> projectUuid.equals(ceActivityDto.getEntityUuid()))
       .map(CeActivityDto::getUuid).collect(Collectors.toSet());
     removeIndexationTasks(dbSession, ceQueueUuidsForProject, ceActivityUuidsForProject);
   }
index c5fe2bfe8f24565e6bdfef7518fc056381b4b866..3a02c634f392b2b1295a4399e90bf9436fb3e36c 100644 (file)
@@ -53,6 +53,7 @@ import org.sonar.db.component.PrBranchAnalyzedLanguageCountByProjectDto;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.measure.LiveMeasureDto;
 import org.sonar.db.measure.ProjectLocDistributionDto;
+import org.sonar.db.measure.ProjectMainBranchLiveMeasureDto;
 import org.sonar.db.metric.MetricDto;
 import org.sonar.db.newcodeperiod.NewCodePeriodDto;
 import org.sonar.db.qualitygate.ProjectQgateAssociationDto;
@@ -413,9 +414,9 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader {
       return Collections.emptyMap();
     }
 
-    return dbClient.liveMeasureDao().selectForProjectsByMetricUuids(dbSession, metricNamesByUuid.keySet())
+    return dbClient.liveMeasureDao().selectForProjectMainBranchesByMetricUuids(dbSession, metricNamesByUuid.keySet())
       .stream()
-      .collect(groupingBy(LiveMeasureDto::getProjectUuid,
+      .collect(groupingBy(ProjectMainBranchLiveMeasureDto::getProjectUuid,
         toMap(lmDto -> metricNamesByUuid.get(lmDto.getMetricUuid()),
           lmDto -> Optional.ofNullable(lmDto.getValue()).orElseGet(() -> Double.valueOf(lmDto.getTextValue())),
           (oldValue, newValue) -> newValue, HashMap::new)));
index a0907e93a353a59846ef0d6364e630a96d1bf1de..73e11b8c33ef6ad38d16948f18e319a63882cd09 100644 (file)
@@ -175,16 +175,16 @@ public class AsyncIssueIndexingImplTest {
     dbTester.components().insertProjectBranch(projectDto, b -> b.setBranchType(BRANCH).setUuid(branchUuid));
 
     CeQueueDto mainBranchTask = new CeQueueDto().setUuid("uuid_2").setTaskType(BRANCH_ISSUE_SYNC)
-      .setMainComponentUuid(projectDto.getUuid()).setComponentUuid(projectDto.getUuid());
+      .setEntityUuid(projectDto.getUuid()).setComponentUuid(projectDto.getUuid());
     dbClient.ceQueueDao().insert(dbTester.getSession(), mainBranchTask);
 
     CeQueueDto branchTask = new CeQueueDto().setUuid("uuid_3").setTaskType(BRANCH_ISSUE_SYNC)
-      .setMainComponentUuid(projectDto.getUuid()).setComponentUuid(branchUuid);
+      .setEntityUuid(projectDto.getUuid()).setComponentUuid(branchUuid);
     dbClient.ceQueueDao().insert(dbTester.getSession(), branchTask);
 
     ProjectDto anotherProjectDto = dbTester.components().insertPrivateProject().getProjectDto();
     CeQueueDto taskOnAnotherProject = new CeQueueDto().setUuid("uuid_4").setTaskType(BRANCH_ISSUE_SYNC)
-      .setMainComponentUuid(anotherProjectDto.getUuid()).setComponentUuid("another-branchUuid");
+      .setEntityUuid(anotherProjectDto.getUuid()).setComponentUuid("another-branchUuid");
     CeActivityDto canceledTaskOnAnotherProject = new CeActivityDto(taskOnAnotherProject).setStatus(Status.CANCELED);
     dbClient.ceActivityDao().insert(dbTester.getSession(), canceledTaskOnAnotherProject);
 
@@ -200,7 +200,7 @@ public class AsyncIssueIndexingImplTest {
     // verify that the canceled tasks on anotherProject is still here, and was not removed by the project reindexation
     assertThat(dbClient.ceActivityDao().selectByTaskType(dbTester.getSession(), BRANCH_ISSUE_SYNC))
       .hasSize(1)
-      .extracting(CeActivityDto::getMainComponentUuid)
+      .extracting(CeActivityDto::getEntityUuid)
       .containsExactly(anotherProjectDto.getUuid());
 
     assertThat(logTester.logs(Level.INFO))
index 01fa2e76dda94b52a165d11d468e82b8f644b150..c9adbb2cede6d4d23d7985c97eeca41595364c5c 100644 (file)
@@ -331,7 +331,7 @@ public class IssueIndexSyncProgressCheckerTest {
 
     CeActivityDto dto = new CeActivityDto(queueDto);
     dto.setComponentUuid(projectDto.getUuid());
-    dto.setMainComponentUuid(projectDto.getUuid());
+    dto.setEntityUuid(projectDto.getUuid());
     dto.setStatus(status);
     dto.setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC);
     dto.setAnalysisUuid(uuid + "_AA");
index 0746b46ce1de52c5995640f5ed831c767bafb9ec..a659c422886e6bb3a8d5defcc68a7723f4a95c68 100644 (file)
@@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.ce.CeActivityDto;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.entity.EntityDto;
 import org.sonar.server.monitoring.ServerMonitoringMetrics;
 
 import static java.util.Objects.requireNonNull;
@@ -54,14 +54,14 @@ public class RecentTasksDurationTask extends ComputeEngineMetricsTask {
     try (DbSession dbSession = dbClient.openSession(false)) {
       List<CeActivityDto> recentSuccessfulTasks = getRecentSuccessfulTasks(dbSession);
 
-      Collection<String> componentUuids = recentSuccessfulTasks.stream()
-        .map(CeActivityDto::getMainComponentUuid)
+      Collection<String> entityUuids = recentSuccessfulTasks.stream()
+        .map(CeActivityDto::getEntityUuid)
         .toList();
-      List<ComponentDto> componentDtos = dbClient.componentDao().selectByUuids(dbSession, componentUuids);
-      Map<String, String> componentUuidAndKeys = componentDtos.stream()
-        .collect(Collectors.toMap(ComponentDto::uuid, ComponentDto::getKey));
+      List<EntityDto> entities = dbClient.entityDao().selectByUuids(dbSession, entityUuids);
+      Map<String, String> entityUuidAndKeys = entities.stream()
+        .collect(Collectors.toMap(EntityDto::getUuid, EntityDto::getKey));
 
-      reportObservedDurationForTasks(recentSuccessfulTasks, componentUuidAndKeys);
+      reportObservedDurationForTasks(recentSuccessfulTasks, entityUuidAndKeys);
     }
     lastUpdatedTimestamp = system.now();
   }
@@ -73,15 +73,15 @@ public class RecentTasksDurationTask extends ComputeEngineMetricsTask {
       .toList();
   }
 
-  private void reportObservedDurationForTasks(List<CeActivityDto> tasks, Map<String, String> componentUuidAndKeys) {
+  private void reportObservedDurationForTasks(List<CeActivityDto> tasks, Map<String, String> entityUuidAndKeys) {
     for (CeActivityDto task : tasks) {
-      String mainComponentUuid = task.getMainComponentUuid();
+      String mainComponentUuid = task.getEntityUuid();
       Long executionTimeMs = task.getExecutionTimeMs();
       try {
         requireNonNull(mainComponentUuid);
         requireNonNull(executionTimeMs);
 
-        String mainComponentKey = componentUuidAndKeys.get(mainComponentUuid);
+        String mainComponentKey = entityUuidAndKeys.get(mainComponentUuid);
         requireNonNull(mainComponentKey);
 
         metrics.observeComputeEngineTaskDuration(executionTimeMs, task.getTaskType(), mainComponentKey);
index 14d3c78b035db2b66037613c4a0eb6baa9e7cf38..cc31fe6a26fd50d0c999722d1cee63057c452b76 100644 (file)
@@ -29,8 +29,10 @@ import org.sonar.db.DbClient;
 import org.sonar.db.ce.CeActivityDao;
 import org.sonar.db.ce.CeActivityDto;
 import org.sonar.db.ce.CeQueueDto;
-import org.sonar.db.component.ComponentDao;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.entity.EntityDao;
+import org.sonar.db.entity.EntityDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.server.monitoring.ServerMonitoringMetrics;
 
 import static org.mockito.ArgumentMatchers.any;
@@ -44,7 +46,7 @@ public class RecentTasksDurationTaskTest {
 
   private final DbClient dbClient = mock(DbClient.class);
   private final CeActivityDao ceActivityDao = mock(CeActivityDao.class);
-  private final ComponentDao componentDao = mock(ComponentDao.class);
+  private final EntityDao entityDao = mock(EntityDao.class);
   private final ServerMonitoringMetrics metrics = mock(ServerMonitoringMetrics.class);
   private final Configuration config = mock(Configuration.class);
   private final System2 system = mock(System2.class);
@@ -52,7 +54,7 @@ public class RecentTasksDurationTaskTest {
   @Before
   public void before() {
     when(dbClient.ceActivityDao()).thenReturn(ceActivityDao);
-    when(dbClient.componentDao()).thenReturn(componentDao);
+    when(dbClient.entityDao()).thenReturn(entityDao);
     ComponentDto componentDto = new ComponentDto();
     componentDto.setKey("key");
   }
@@ -62,7 +64,7 @@ public class RecentTasksDurationTaskTest {
     RecentTasksDurationTask task = new RecentTasksDurationTask(dbClient, metrics, config, system);
     List<CeActivityDto> recentTasks = createTasks(5, 0);
 
-    when(componentDao.selectByUuids(any(), any())).thenReturn(createComponentDtos(5));
+    when(entityDao.selectByUuids(any(), any())).thenReturn(createEntityDtos(5));
     when(ceActivityDao.selectNewerThan(any(), anyLong())).thenReturn(recentTasks);
 
     task.run();
@@ -75,7 +77,7 @@ public class RecentTasksDurationTaskTest {
     RecentTasksDurationTask task = new RecentTasksDurationTask(dbClient, metrics, config, system);
     List<CeActivityDto> recentTasks = createTasks(1, 1);
 
-    when(componentDao.selectByUuids(any(), any())).thenReturn(createComponentDtos(1));
+    when(entityDao.selectByUuids(any(), any())).thenReturn(createEntityDtos(1));
     when(ceActivityDao.selectNewerThan(any(), anyLong())).thenReturn(recentTasks);
 
     task.run();
@@ -89,7 +91,7 @@ public class RecentTasksDurationTaskTest {
     List<CeActivityDto> recentTasks = createTasks(1, 0);
     recentTasks.get(0).setExecutionTimeMs(null);
 
-    when(componentDao.selectByUuids(any(), any())).thenReturn(createComponentDtos(1));
+    when(entityDao.selectByUuids(any(), any())).thenReturn(createEntityDtos(1));
     when(ceActivityDao.selectNewerThan(any(), anyLong())).thenReturn(recentTasks);
 
     task.run();
@@ -111,21 +113,21 @@ public class RecentTasksDurationTaskTest {
     return dtos;
   }
 
-  private List<ComponentDto> createComponentDtos(int number) {
-    List<ComponentDto> componentDtos = new ArrayList<>();
+  private List<EntityDto> createEntityDtos(int number) {
+    List<EntityDto> entityDtos = new ArrayList<>();
     for(int i=0; i<5; i++) {
-      ComponentDto component = new ComponentDto();
-      component.setUuid(i + "");
-      component.setKey(i + "");
-      componentDtos.add(component);
+      ProjectDto entity = new ProjectDto();
+      entity.setUuid(i + "");
+      entity.setKey(i + "");
+      entityDtos.add(entity);
     }
-    return componentDtos;
+    return entityDtos;
   }
 
   private CeActivityDto newCeActivityTask(CeActivityDto.Status status) {
     CeActivityDto dto = new CeActivityDto(new CeQueueDto());
     dto.setStatus(status);
-    dto.setMainComponentUuid("0");
+    dto.setEntityUuid("0");
     dto.setExecutionTimeMs(1000L);
     return dto;
   }
index c0d47cd874971b4265515e5ca8243de0681a14fb..87548ab745e383ffe0880477f95c646b44361f22 100644 (file)
@@ -46,7 +46,7 @@ import static org.sonar.db.permission.GlobalPermission.SCAN;
 
 public class ProjectDataLoaderIT {
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
index 5c4709875b148ca2223399cfd1e81e92d0d915ff..41626448af144e50dd469ca36de4fdc4e4647884 100644 (file)
@@ -260,7 +260,7 @@ public class BranchReportSubmitterIT {
     assertThat(ceTask.getType()).isEqualTo(CeTaskTypes.REPORT);
     assertThat(ceTask.getComponent()).isPresent();
     assertThat(ceTask.getComponent().get().getUuid()).isEqualTo(branch.uuid());
-    assertThat(ceTask.getComponent().get().getMainComponentUuid()).isEqualTo(project.uuid());
+    assertThat(ceTask.getComponent().get().getEntityUuid()).isEqualTo(project.uuid());
   }
 
   private static BranchSupport.ComponentKey createComponentKeyOfBranch(String projectKey) {
index 6c85625757d624c9a6825f2a8c279971a183fb3f..4cccc2498ebd0b432a34f31451ea5b13fe51a69f 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.ce.queue;
 
 import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
 import java.util.Map;
 import java.util.Random;
 import java.util.stream.IntStream;
@@ -28,7 +27,6 @@ import org.apache.commons.io.IOUtils;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.System2;
 import org.sonar.ce.queue.CeQueue;
 import org.sonar.ce.queue.CeQueueImpl;
@@ -149,7 +147,7 @@ public class ReportSubmitterIT {
     verifyReportIsPersisted(TASK_UUID);
     verifyNoInteractions(permissionTemplateService);
     verify(queue).submit(argThat(submit -> submit.getType().equals(CeTaskTypes.REPORT)
-      && submit.getComponent().filter(cpt -> cpt.getUuid().equals(project.uuid()) && cpt.getMainComponentUuid().equals(project.uuid())).isPresent()
+      && submit.getComponent().filter(cpt -> cpt.getUuid().equals(project.uuid()) && cpt.getEntityUuid().equals(project.uuid())).isPresent()
       && submit.getSubmitterUuid().equals(user.getUuid())
       && submit.getUuid().equals(TASK_UUID)));
   }
@@ -168,7 +166,7 @@ public class ReportSubmitterIT {
     ComponentDto createdProject = db.getDbClient().componentDao().selectByKey(db.getSession(), PROJECT_KEY).get();
     verifyReportIsPersisted(TASK_UUID);
     verify(queue).submit(argThat(submit -> submit.getType().equals(CeTaskTypes.REPORT)
-      && submit.getComponent().filter(cpt -> cpt.getUuid().equals(createdProject.uuid()) && cpt.getMainComponentUuid().equals(createdProject.uuid())).isPresent()
+      && submit.getComponent().filter(cpt -> cpt.getUuid().equals(createdProject.uuid()) && cpt.getEntityUuid().equals(createdProject.uuid())).isPresent()
       && submit.getUuid().equals(TASK_UUID)));
   }
 
index 1a993ffed325eb65435ec79c9fd4f4fe2cda6fc8..d75a0e76b2657a31549e945b04ee27dc8a71a25b 100644 (file)
@@ -609,7 +609,7 @@ public class ActivityActionIT {
     queueDto.setTaskType(CeTaskTypes.REPORT);
     if (project != null ) {
       queueDto.setComponentUuid(project.uuid());
-      queueDto.setMainComponentUuid(project.uuid());
+      queueDto.setEntityUuid(project.uuid());
     }
     queueDto.setUuid(taskUuid);
     queueDto.setStatus(status);
@@ -626,7 +626,7 @@ public class ActivityActionIT {
     CeQueueDto queueDto = new CeQueueDto();
     queueDto.setTaskType(CeTaskTypes.REPORT);
     queueDto.setComponentUuid(project.uuid());
-    queueDto.setMainComponentUuid(project.uuid());
+    queueDto.setEntityUuid(project.uuid());
     queueDto.setUuid(taskUuid);
     queueDto.setCreatedAt(EXECUTED_AT);
     CeActivityDto activityDto = new CeActivityDto(queueDto);
index d3733ae5a9a215ba605064869503f9a5ad62ae1b..8e7d053d05e4c126c8cc4f5c44bdb48550b1c579 100644 (file)
@@ -172,7 +172,7 @@ public class ActivityStatusActionIT {
       .setStatus(status);
     if(componentDto != null) {
       ceQueueDto.setComponentUuid(componentDto.uuid())
-        .setMainComponentUuid(componentDto.uuid());
+        .setEntityUuid(componentDto.uuid());
     }
     if (createdAt != null) {
       ceQueueDto.setCreatedAt(createdAt);
@@ -184,7 +184,7 @@ public class ActivityStatusActionIT {
   private void insertActivity(CeActivityDto.Status status, @Nullable ComponentDto dto) {
     CeQueueDto ceQueueDto = newCeQueueDto(Uuids.createFast());
     ceQueueDto.setComponentUuid(dto.uuid());
-    ceQueueDto.setMainComponentUuid(dto.uuid());
+    ceQueueDto.setEntityUuid(dto.uuid());
     dbClient.ceActivityDao().insert(dbSession, new CeActivityDto(ceQueueDto)
       .setStatus(status));
     db.commit();
index dc2fbb6776f0347692d041944a8e159867a9e094..358af795f976e4f4ff67f50955eb84bcf6858fb6 100644 (file)
@@ -367,7 +367,7 @@ public class AnalysisStatusActionIT {
     CeQueueDto queueDto = new CeQueueDto();
     queueDto.setTaskType(taskType);
     queueDto.setComponentUuid(branch.getUuid());
-    queueDto.setMainComponentUuid(branch.getUuid());
+    queueDto.setEntityUuid(branch.getUuid());
     queueDto.setUuid(taskUuid);
     CeActivityDto activityDto = new CeActivityDto(queueDto);
     activityDto.setStatus(status);
index 8884dfa19650a6a77651977187fe82d231f8c654..219ad666f72e67223c8d44d3badf5df0b4566923 100644 (file)
@@ -309,7 +309,7 @@ public class ComponentActionIT {
     CeQueueDto queueDto = new CeQueueDto();
     queueDto.setTaskType(CeTaskTypes.REPORT);
     queueDto.setComponentUuid(component.uuid());
-    queueDto.setMainComponentUuid(component.uuid());
+    queueDto.setEntityUuid(component.uuid());
     queueDto.setUuid(taskUuid);
     queueDto.setStatus(status);
     db.getDbClient().ceQueueDao().insert(db.getSession(), queueDto);
@@ -325,7 +325,7 @@ public class ComponentActionIT {
     CeQueueDto queueDto = new CeQueueDto();
     queueDto.setTaskType(CeTaskTypes.REPORT);
     queueDto.setComponentUuid(component.uuid());
-    queueDto.setMainComponentUuid(component.uuid());
+    queueDto.setEntityUuid(component.uuid());
     queueDto.setUuid(taskUuid);
     CeActivityDto activityDto = new CeActivityDto(queueDto);
     activityDto.setStatus(status);
index e914ffcb6db2f819b843fee1bb594f4dc4f743e3..ca207f02f38f7f13e19a3adab1a84e0e94f88b16 100644 (file)
@@ -59,7 +59,7 @@ import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY;
 public class LiveMeasureComputerImplIT {
 
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
 
   private final TestProjectIndexers projectIndexer = new TestProjectIndexers();
   private MetricDto metric1;
index b15953bf9c1168169fb93f95a028573989ccabe8..1ea8900af6d16d145008cf5f74ef25ca660fbbac 100644 (file)
@@ -54,7 +54,7 @@ import static org.sonar.api.measures.CoreMetrics.SECURITY_HOTSPOTS_TO_REVIEW_STA
 
 public class LiveMeasureTreeUpdaterImplIT {
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
 
   private final Configuration config = new MapSettings().setProperty(RATING_GRID, "0.05,0.1,0.2,0.5").asConfig();
   private LiveMeasureTreeUpdaterImpl treeUpdater;
index 54800a9a8ddec001c7d974c0169d7ced45ce65c6..7d04fff851b41544fc83a1388362b17bee701efe 100644 (file)
@@ -53,7 +53,6 @@ import org.sonar.db.portfolio.PortfolioDto;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
-import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.es.ProjectIndexer;
 import org.sonar.server.es.TestProjectIndexers;
@@ -105,8 +104,7 @@ public class UpdateVisibilityActionIT {
   private final TestProjectIndexers projectIndexers = new TestProjectIndexers();
   private final Configuration configuration = mock(Configuration.class);
 
-  private final UpdateVisibilityAction underTest = new UpdateVisibilityAction(dbClient, TestComponentFinder.from(dbTester),
-    userSessionRule, projectIndexers, new SequenceUuidFactory(), configuration);
+  private final UpdateVisibilityAction underTest = new UpdateVisibilityAction(dbClient, userSessionRule, projectIndexers, new SequenceUuidFactory(), configuration);
   private final WsActionTester ws = new WsActionTester(underTest);
 
   private final Random random = new Random();
@@ -278,7 +276,7 @@ public class UpdateVisibilityActionIT {
   public void execute_throws_BadRequestException_if_specified_component_has_pending_tasks() {
     ProjectData project = randomPublicOrPrivateProject();
     IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
-      .forEach(i -> insertPendingTask(project.getMainBranchComponent().uuid()));
+      .forEach(i -> insertPendingTask(project.getMainBranchDto()));
     request.setParam(PARAM_PROJECT, project.projectKey())
       .setParam(PARAM_VISIBILITY, randomVisibility);
     userSessionRule.addProjectPermission(UserRole.ADMIN, project.getProjectDto());
@@ -292,7 +290,7 @@ public class UpdateVisibilityActionIT {
   public void execute_throws_BadRequestException_if_main_component_of_specified_component_has_in_progress_tasks() {
     ProjectData project = randomPublicOrPrivateProject();
     IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
-      .forEach(i -> insertInProgressTask(project.getMainBranchComponent().uuid()));
+      .forEach(i -> insertInProgressTask(project.getMainBranchDto()));
     request.setParam(PARAM_PROJECT, project.projectKey())
       .setParam(PARAM_VISIBILITY, randomVisibility);
     userSessionRule.addProjectPermission(UserRole.ADMIN, project.getProjectDto());
@@ -670,21 +668,21 @@ public class UpdateVisibilityActionIT {
       .containsAll(permissionService.getAllProjectPermissions());
   }
 
-  private void insertPendingTask(String projectUuid) {
-    insertCeQueueDto(projectUuid, CeQueueDto.Status.PENDING);
+  private void insertPendingTask(BranchDto branch) {
+    insertCeQueueDto(branch, CeQueueDto.Status.PENDING);
   }
 
-  private void insertInProgressTask(String projectUuid) {
-    insertCeQueueDto(projectUuid, CeQueueDto.Status.IN_PROGRESS);
+  private void insertInProgressTask(BranchDto branch) {
+    insertCeQueueDto(branch, CeQueueDto.Status.IN_PROGRESS);
   }
 
   private int counter = 0;
 
-  private void insertCeQueueDto(String projectUuid, CeQueueDto.Status status) {
+  private void insertCeQueueDto(BranchDto branch, CeQueueDto.Status status) {
     dbClient.ceQueueDao().insert(dbTester.getSession(), new CeQueueDto()
       .setUuid("pending" + counter++)
-      .setComponentUuid(projectUuid)
-      .setMainComponentUuid(projectUuid)
+      .setComponentUuid(branch.getUuid())
+      .setEntityUuid(branch.getProjectUuid())
       .setTaskType("foo")
       .setStatus(status));
     dbTester.commit();
index 87c7b0ea792bf643b132ca73fbed1147a5d23b35..c577a5b79fa2f3438e4585626ee7d868e3ac7269 100644 (file)
@@ -137,7 +137,7 @@ public class ExportActionIT {
       .setType(CeTaskTypes.PROJECT_EXPORT)
       .setUuid(TASK_ID)
       .setComponent(component)
-      .setMainComponent(component)
+      .setEntity(component)
       .build();
   }
 }
index 433b7eecc66e3e1098c2ac1a98fcaf38c0fd2c00..a6a8ffa47b732fa51161589467fe7b5579f57c70 100644 (file)
@@ -183,14 +183,14 @@ public class DeselectActionIT {
   }
 
   private void assertDeselected(ProjectDto project) {
-    Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid());
+    Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByProjectUuid(project.getUuid());
     assertThat(qGateUuid)
       .isNotNull()
       .isEmpty();
   }
 
   private void assertSelected(QualityGateDto qualityGate, ProjectDto project) {
-    Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid());
+    Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByProjectUuid(project.getUuid());
     assertThat(qGateUuid)
       .isNotNull()
       .isNotEmpty()
index 276b866050ed8581d6d9d89eab2d1ba458fd4008..6c3c621c024af58d0b6de50cb6a9b79b8b714083 100644 (file)
@@ -199,7 +199,7 @@ public class SelectActionIT {
   }
 
   private void assertSelected(QualityGateDto qualityGate, ComponentDto project) {
-    Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.uuid());
+    Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByProjectUuid(project.uuid());
     assertThat(qGateUuid)
       .isNotNull()
       .isNotEmpty()
index af716867dbf4b989d5c343f7c30ef2985e9c54f2..cea9fbd67bc2c6ab76efaae4b52c7deaf2735988 100644 (file)
@@ -45,7 +45,7 @@ public class SourceServiceIT {
   public static final String FILE_UUID = "FILE_UUID";
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
 
   HtmlSourceDecorator htmlDecorator = mock(HtmlSourceDecorator.class);
index b5a99a69b2b0cdcc8b0a08c3dbb5b83ad8a0384c..54dc83be6071610326ff116c86784f5166ddd2e1 100644 (file)
@@ -47,7 +47,7 @@ public class IndexActionIT {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
 
   WsActionTester tester = new WsActionTester(
     new IndexAction(db.getDbClient(), new SourceService(db.getDbClient(), new HtmlSourceDecorator()), userSession, TestComponentFinder.from(db)));
index 006ce113b4b18f6cac7f31547ec126ff1d3c3f5b..1f6edb4d2f7bafb2793a359d066a8d58bcd535b8 100644 (file)
@@ -59,7 +59,7 @@ import static org.sonar.db.component.ComponentTesting.newFileDto;
 public class LinesActionIT {
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
@@ -351,15 +351,16 @@ public class LinesActionIT {
   @Test
   public void hide_scmAuthors() {
     ProjectData projectData = db.components().insertPublicProject();
-    ComponentDto publicProject = projectData.getMainBranchComponent();
+    ComponentDto mainBranch = projectData.getMainBranchComponent();
 
     userSession.registerProjects(projectData.getProjectDto());
+    userSession.addProjectBranchMapping(projectData.projectUuid(), mainBranch);
 
     DbFileSources.Data data = DbFileSources.Data.newBuilder()
       .addLines(newLineBuilder().setScmAuthor("isaac@asimov.com"))
       .build();
 
-    ComponentDto file = insertFileWithData(data, publicProject);
+    ComponentDto file = insertFileWithData(data, mainBranch);
 
     tester.newRequest()
       .setParam("uuid", file.uuid())
@@ -370,15 +371,16 @@ public class LinesActionIT {
   @Test
   public void show_scmAuthors() {
     ProjectData projectData = db.components().insertPublicProject();
-    ComponentDto publicProject = projectData.getMainBranchComponent();
+    ComponentDto mainBranch = projectData.getMainBranchComponent();
     UserDto user = db.users().insertUser();
     userSession.logIn(user).registerProjects(projectData.getProjectDto());
+    userSession.addProjectBranchMapping(projectData.projectUuid(), mainBranch);
 
     DbFileSources.Data data = DbFileSources.Data.newBuilder()
       .addLines(newLineBuilder().setScmAuthor("isaac@asimov.com"))
       .build();
 
-    ComponentDto file = insertFileWithData(data, publicProject);
+    ComponentDto file = insertFileWithData(data, mainBranch);
 
     tester.newRequest()
       .setParam("uuid", file.uuid())
index 8ec90888d791ae48d52aed13fb7f7d39c9979754..31712ec694e21fe22d6e459e5a4212c048b75251 100644 (file)
@@ -50,7 +50,7 @@ public class ScmActionIT {
   private static final String PROJECT_UUID = "PROJECT_A";
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
 
index aac84f6ad7c45f9cd3ef0d1b84fbd0357addd0bb..b55c94a2ca78de908540e5532c9292c7d00c16cf 100644 (file)
@@ -41,7 +41,6 @@ import static org.sonar.server.branch.ws.ProjectBranchesParameters.ACTION_DELETE
 import static org.sonar.server.branch.ws.ProjectBranchesParameters.PARAM_BRANCH;
 import static org.sonar.server.branch.ws.ProjectBranchesParameters.PARAM_PROJECT;
 import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional;
-import static org.sonar.server.project.Project.from;
 
 public class DeleteAction implements BranchWsAction {
   private final DbClient dbClient;
index be3c1414890a598ed2cfd7b6815dba9be2cc5431..d5020e4663cf8b83757fab6318d5b166c7af4a80 100644 (file)
@@ -285,9 +285,9 @@ public class ActivityAction implements CeWsAction {
 
     String componentQuery = request.getQ();
     if (entity != null) {
-      query.setMainComponentUuid(entity.getUuid());
+      query.setEntityUuid(entity.getUuid());
     } else if (componentQuery != null) {
-      query.setMainComponentUuids(loadComponents(dbSession, componentQuery).stream()
+      query.setEntityUuids(loadComponents(dbSession, componentQuery).stream()
         .map(ComponentDto::uuid)
         .collect(toList()));
     }
index 71c758b8f6decf9788619fb4a30ed4c83adbbda3..9b0bc239cfb584e5f6d2cd5da721fc1b20e202c2 100644 (file)
@@ -83,14 +83,14 @@ public class ActivityStatusAction implements CeWsAction {
 
   private ActivityStatusWsResponse doHandle(Request request) {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      Optional<EntityDto> component = searchComponent(dbSession, request);
-      String componentUuid = component.map(EntityDto::getUuid).orElse(null);
-      checkPermissions(component.orElse(null));
-      int pendingCount = dbClient.ceQueueDao().countByStatusAndMainComponentUuid(dbSession, CeQueueDto.Status.PENDING, componentUuid);
-      int inProgressCount = dbClient.ceQueueDao().countByStatusAndMainComponentUuid(dbSession, CeQueueDto.Status.IN_PROGRESS, componentUuid);
-      int failingCount = dbClient.ceActivityDao().countLastByStatusAndMainComponentUuid(dbSession, CeActivityDto.Status.FAILED, componentUuid);
+      Optional<EntityDto> entity = searchEntity(dbSession, request);
+      String entityUuid = entity.map(EntityDto::getUuid).orElse(null);
+      checkPermissions(entity.orElse(null));
+      int pendingCount = dbClient.ceQueueDao().countByStatusAndEntityUuid(dbSession, CeQueueDto.Status.PENDING, entityUuid);
+      int inProgressCount = dbClient.ceQueueDao().countByStatusAndEntityUuid(dbSession, CeQueueDto.Status.IN_PROGRESS, entityUuid);
+      int failingCount = dbClient.ceActivityDao().countLastByStatusAndEntityUuid(dbSession, CeActivityDto.Status.FAILED, entityUuid);
 
-      Optional<Long> creationDate = dbClient.ceQueueDao().selectCreationDateOfOldestPendingByMainComponentUuid(dbSession, componentUuid);
+      Optional<Long> creationDate = dbClient.ceQueueDao().selectCreationDateOfOldestPendingByEntityUuid(dbSession, entityUuid);
 
       ActivityStatusWsResponse.Builder builder = ActivityStatusWsResponse.newBuilder()
         .setPending(pendingCount)
@@ -106,7 +106,7 @@ public class ActivityStatusAction implements CeWsAction {
     }
   }
 
-  private Optional<EntityDto> searchComponent(DbSession dbSession, Request request) {
+  private Optional<EntityDto> searchEntity(DbSession dbSession, Request request) {
     EntityDto entity = null;
     if (request.getComponentKey() != null) {
       entity = componentFinder.getEntityByKey(dbSession, request.getComponentKey());
index b9178c473ba2be8023b1019a496d54785326b1e7..7ea20e7da03ba8b300461a5afa68de747b95f58b 100644 (file)
@@ -82,9 +82,9 @@ public class ComponentAction implements CeWsAction {
     try (DbSession dbSession = dbClient.openSession(false)) {
       ComponentDto component = loadComponent(dbSession, wsRequest);
       userSession.checkComponentPermission(UserRole.USER, component);
-      List<CeQueueDto> queueDtos = dbClient.ceQueueDao().selectByMainComponentUuid(dbSession, component.uuid());
+      List<CeQueueDto> queueDtos = dbClient.ceQueueDao().selectByEntityUuid(dbSession, component.uuid());
       CeTaskQuery activityQuery = new CeTaskQuery()
-        .setMainComponentUuid(component.uuid())
+        .setEntityUuid(component.uuid())
         .setOnlyCurrents(true);
       List<CeActivityDto> activityDtos = dbClient.ceActivityDao().selectByQuery(dbSession, activityQuery, forPage(1).andSize(1));
 
index ff3ef6ce765acc41316aecc3c54a2c43fc8e52ea..7a05db123a229e85c1953d080afd3cd79853bc99 100644 (file)
@@ -90,10 +90,6 @@ public class PermissionWsSupport {
     return null;
   }
 
-  public ComponentDto getRootComponent(DbSession dbSession, ProjectWsRef projectRef) {
-    return componentFinder.getRootComponentByUuidOrKey(dbSession, projectRef.uuid(), projectRef.key());
-  }
-
   public GroupUuidOrAnyone findGroup(DbSession dbSession, Request request) {
     String groupName = request.mandatoryParam(PARAM_GROUP_NAME);
     return groupWsSupport.findGroupOrAnyone(dbSession, groupName);
index 0417946b83225cfff9dfde0cf2314f6269d6adf5..f6ff00362e50fb05a01b585f5d4c1f54e4eb9b2d 100644 (file)
@@ -34,7 +34,6 @@ import org.sonar.server.project.ProjectLifeCycleListeners;
 import org.sonar.server.user.UserSession;
 
 import static java.util.Collections.singleton;
-import static org.sonar.server.project.Project.from;
 import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT;
 
index aca277a46c0c6239e6290045b0519390a84b48d8..6d0ca25d61fd58649240d46f8e76962fd767bf15 100644 (file)
@@ -29,13 +29,11 @@ import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.BranchDto;
-import org.sonar.db.component.ComponentDto;
 import org.sonar.db.entity.EntityDto;
 import org.sonar.db.permission.GroupPermissionDto;
 import org.sonar.db.permission.UserPermissionDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserId;
-import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.es.ProjectIndexer;
 import org.sonar.server.es.ProjectIndexers;
 import org.sonar.server.exceptions.BadRequestException;
@@ -58,16 +56,13 @@ import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_VISIBIL
 public class UpdateVisibilityAction implements ProjectsWsAction {
 
   private final DbClient dbClient;
-  private final ComponentFinder componentFinder;
   private final UserSession userSession;
   private final ProjectIndexers projectIndexers;
   private final UuidFactory uuidFactory;
   private final Configuration configuration;
 
-  public UpdateVisibilityAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession,
-    ProjectIndexers projectIndexers, UuidFactory uuidFactory, Configuration configuration) {
+  public UpdateVisibilityAction(DbClient dbClient, UserSession userSession, ProjectIndexers projectIndexers, UuidFactory uuidFactory, Configuration configuration) {
     this.dbClient = dbClient;
-    this.componentFinder = componentFinder;
     this.userSession = userSession;
     this.projectIndexers = projectIndexers;
     this.uuidFactory = uuidFactory;
@@ -148,8 +143,8 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
   }
 
   private boolean noPendingTask(DbSession dbSession, String entityKey) {
-    ComponentDto componentDto = componentFinder.getByKey(dbSession, entityKey);
-    return dbClient.ceQueueDao().selectByMainComponentUuid(dbSession, componentDto.uuid()).isEmpty();
+    EntityDto entityDto = dbClient.entityDao().selectByKey(dbSession, entityKey).orElseThrow(() -> new IllegalStateException("Can't find entity " + entityKey));
+    return dbClient.ceQueueDao().selectByEntityUuid(dbSession, entityDto.getUuid()).isEmpty();
   }
 
   private void updatePermissionsToPrivate(DbSession dbSession, EntityDto entity) {
index 423604add1981baabfa2a4fbbb39d70dc57ed278..a888645d3b936555919e3ead203974e84a7a9de3 100644 (file)
@@ -148,7 +148,7 @@ public class SearchAction implements QualityGatesWsAction {
 
   private List<ProjectQgateAssociationDto> keepAuthorizedProjects(DbSession dbSession, List<ProjectQgateAssociationDto> projects) {
     List<String> projectUuids = projects.stream().map(ProjectQgateAssociationDto::getUuid).collect(MoreCollectors.toList());
-    Collection<String> authorizedProjectIds = dbClient.authorizationDao().keepAuthorizedEntityUuids(dbSession, projectUuids, userSession.getUuid(), UserRole.USER);
-    return projects.stream().filter(project -> authorizedProjectIds.contains(project.getUuid())).collect(MoreCollectors.toList());
+    Collection<String> authorizedProjectUuids = dbClient.authorizationDao().keepAuthorizedEntityUuids(dbSession, projectUuids, userSession.getUuid(), UserRole.USER);
+    return projects.stream().filter(project -> authorizedProjectUuids.contains(project.getUuid())).collect(MoreCollectors.toList());
   }
 }
index fee8e85a606c9e16d2d1778aa9c2369bf3171399..4f5c0a1ab3fc18b4b56575cb01ae9b3f331b3d65 100644 (file)
@@ -46,12 +46,14 @@ import static org.mockito.Mockito.when;
 public class SubmitActionTest {
 
   private static final String PROJECT_UUID = "PROJECT_1";
-  private static final CeTask.Component COMPONENT = new CeTask.Component(PROJECT_UUID, "KEY_1", "NAME_1");
+  private static final String BRANCH_UUID = "BRANCH_1";
+  private static final CeTask.Component ENTITY = new CeTask.Component(PROJECT_UUID, "KEY_1", "NAME_1");
+  private static final CeTask.Component COMPONENT = new CeTask.Component(BRANCH_UUID, "KEY_1", "NAME_1");
   private static final CeTask A_CE_TASK = new CeTask.Builder()
     .setUuid("TASK_1")
     .setType(CeTaskTypes.REPORT)
     .setComponent(COMPONENT)
-    .setMainComponent(COMPONENT)
+    .setEntity(ENTITY)
     .setSubmitter(new CeTask.User("UUID_1", "LOGIN_1"))
     .build();
 
@@ -75,7 +77,7 @@ public class SubmitActionTest {
     verify(reportSubmitter).submit(eq("my_project"), eq("My Project"), anyMap(), any());
 
     assertThat(submitResponse.getTaskId()).isEqualTo("TASK_1");
-    assertThat(submitResponse.getProjectId()).isEqualTo(PROJECT_UUID);
+    assertThat(submitResponse.getProjectId()).isEqualTo(BRANCH_UUID);
   }
 
   @Test
@@ -114,7 +116,7 @@ public class SubmitActionTest {
     verify(reportSubmitter).submit(eq("my_project"), eq(expectedName), anyMap(), any());
 
     assertThat(submitResponse.getTaskId()).isEqualTo("TASK_1");
-    assertThat(submitResponse.getProjectId()).isEqualTo(PROJECT_UUID);
+    assertThat(submitResponse.getProjectId()).isEqualTo(BRANCH_UUID);
   }
 
   @Test