]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18850 update branch mapper to use is main and update test framework
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Fri, 31 Mar 2023 08:48:41 +0000 (10:48 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 4 Apr 2023 20:03:16 +0000 (20:03 +0000)
68 files changed:
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/SiblingComponentsWithOpenIssuesIT.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/step/LoadCrossProjectDuplicationsRepositoryStepIT.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/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/projectexport/analysis/ExportAnalysesStepIT.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/steps/ExportMeasuresStepIT.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/PullRequestSourceBranchMergerTest.java
server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentKeyUpdaterDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueMapperIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIndexerIT.java
server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityHotspotsTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSortTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.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/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/ce/ws/DismissAnalysisWarningActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentCleanerServiceIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentFinderIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentServiceUpdateKeyIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/ShowActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/DuplicationsParserIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowResponseBuilderIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/AssignActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ShowActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/BulkChangeActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/IssueUpdaterIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionComponentsIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/SearchHistoryActionIT.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/projectanalysis/ws/SearchActionIT.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/RawActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ScmActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ShowActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java

index f77eb52d62476703837e91adbf3f0bc8c5cba21a..8da1da4efe25f60bf41f9157b2d5e6beede77879 100644 (file)
@@ -156,7 +156,7 @@ public class BranchPersisterImplIT {
     ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setKey(MAIN.getKey()).setUuid(MAIN.getUuid()));
     ComponentDto component = ComponentTesting.newBranchComponent(mainComponent,
       new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH));
-    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component);
+    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component, false);
     dbTester.commit();
 
     underTest.persist(dbTester.getSession());
@@ -174,7 +174,7 @@ public class BranchPersisterImplIT {
     ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setKey(MAIN.getKey()).setUuid(MAIN.getUuid()));
     ComponentDto component = ComponentTesting.newBranchComponent(mainComponent,
       new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH));
-    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component);
+    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component, false);
     settings.setProperty(BRANCHES_TO_KEEP_WHEN_INACTIVE, "BRANCH.*");
     dbTester.commit();
 
@@ -193,7 +193,7 @@ public class BranchPersisterImplIT {
     ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setKey(MAIN.getKey()).setUuid(MAIN.getUuid()));
     ComponentDto component = ComponentTesting.newBranchComponent(mainComponent,
       new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH));
-    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component);
+    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component, false);
     settings.setProperty(BRANCHES_TO_KEEP_WHEN_INACTIVE, "abc.*");
 
     dbTester.commit();
@@ -220,7 +220,7 @@ public class BranchPersisterImplIT {
       .setProjectUuid(MAIN.getUuid())
       .setBranchType(PULL_REQUEST)
       .setMergeBranchUuid(MAIN.getUuid()));
-    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component);
+    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component, false);
     dbTester.commit();
 
     underTest.persist(dbTester.getSession());
@@ -239,7 +239,7 @@ public class BranchPersisterImplIT {
     ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setKey(MAIN.getKey()).setUuid(MAIN.getUuid()));
     ComponentDto component = ComponentTesting.newBranchComponent(mainComponent,
       new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH));
-    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component);
+    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component, false);
     dbTester.commit();
 
     underTest.persist(dbTester.getSession());
index b35f634bd3e2ec49631128401e84bc81971ab86c..1e9fa01615b5c806876b1ec98dfd13e75f9fb162 100644 (file)
@@ -77,26 +77,26 @@ public class SiblingComponentsWithOpenIssuesIT {
       b -> b.setBranchType(BranchType.PULL_REQUEST),
       b -> b.setMergeBranchUuid(branch1.uuid()));
 
-    fileWithNoIssuesOnBranch1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1, null));
+    fileWithNoIssuesOnBranch1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1));
 
     RuleDto rule = db.rules().insert();
 
-    fileWithOneOpenIssueOnBranch1Pr1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1pr1, null));
+    fileWithOneOpenIssueOnBranch1Pr1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1pr1));
     db.issues().insert(rule, branch1pr1, fileWithOneOpenIssueOnBranch1Pr1);
 
-    fileWithOneResolvedIssueOnBranch1Pr1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1pr1, null));
+    fileWithOneResolvedIssueOnBranch1Pr1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1pr1));
     db.issues().insert(rule, branch1pr1, fileWithOneResolvedIssueOnBranch1Pr1, i -> i.setStatus("RESOLVED"));
 
-    fileWithOneOpenTwoResolvedIssuesOnBranch1Pr1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1pr1, null));
+    fileWithOneOpenTwoResolvedIssuesOnBranch1Pr1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1pr1));
     db.issues().insert(rule, branch1pr1, fileWithOneOpenTwoResolvedIssuesOnBranch1Pr1);
     db.issues().insert(rule, branch1pr1, fileWithOneOpenTwoResolvedIssuesOnBranch1Pr1, i -> i.setStatus("RESOLVED"));
 
     String fileKey = "file-x";
-    fileXWithOneResolvedIssueOnBranch1Pr1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1pr1, null)
+    fileXWithOneResolvedIssueOnBranch1Pr1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1pr1)
       .setKey(fileKey));
     db.issues().insert(rule, branch1pr1, fileXWithOneResolvedIssueOnBranch1Pr1, i -> i.setStatus("RESOLVED"));
 
-    fileXWithOneResolvedIssueOnBranch1Pr2 = db.components().insertComponent(ComponentTesting.newFileDto(branch1pr2, null)
+    fileXWithOneResolvedIssueOnBranch1Pr2 = db.components().insertComponent(ComponentTesting.newFileDto(branch1pr2)
       .setKey(fileKey));
     db.issues().insert(rule, branch1pr2, fileXWithOneResolvedIssueOnBranch1Pr2, i -> i.setStatus("RESOLVED"));
 
@@ -106,10 +106,10 @@ public class SiblingComponentsWithOpenIssuesIT {
       b -> b.setBranchType(BranchType.PULL_REQUEST),
       b -> b.setMergeBranchUuid(branch2.uuid()));
 
-    fileWithOneOpenIssueOnBranch2Pr1 = db.components().insertComponent(ComponentTesting.newFileDto(branch2pr1, null));
+    fileWithOneOpenIssueOnBranch2Pr1 = db.components().insertComponent(ComponentTesting.newFileDto(branch2pr1));
     db.issues().insert(rule, branch2pr1, fileWithOneOpenIssueOnBranch2Pr1);
 
-    fileWithOneResolvedIssueOnBranch2Pr1 = db.components().insertComponent(ComponentTesting.newFileDto(branch2pr1, null));
+    fileWithOneResolvedIssueOnBranch2Pr1 = db.components().insertComponent(ComponentTesting.newFileDto(branch2pr1));
     db.issues().insert(rule, branch2pr1, fileWithOneResolvedIssueOnBranch2Pr1, i -> i.setStatus("RESOLVED"));
     setRoot(branch1);
     underTest = new SiblingComponentsWithOpenIssues(treeRootHolder, metadataHolder, db.getDbClient());
@@ -168,7 +168,7 @@ public class SiblingComponentsWithOpenIssuesIT {
 
     RuleDto rule = db.rules().insert();
 
-    ComponentDto fileWithResolvedIssueOnPullrequest = db.components().insertComponent(ComponentTesting.newFileDto(pullRequest, null));
+    ComponentDto fileWithResolvedIssueOnPullrequest = db.components().insertComponent(ComponentTesting.newFileDto(pullRequest));
     db.issues().insert(rule, pullRequest, fileWithResolvedIssueOnPullrequest, i -> i.setStatus("RESOLVED"));
     underTest = new SiblingComponentsWithOpenIssues(treeRootHolder, metadataHolder, db.getDbClient());
 
@@ -187,7 +187,7 @@ public class SiblingComponentsWithOpenIssuesIT {
 
     RuleDto rule = db.rules().insert();
 
-    ComponentDto fileWithResolvedIssueOnDerivedBranch = db.components().insertComponent(ComponentTesting.newFileDto(derivedBranch, null));
+    ComponentDto fileWithResolvedIssueOnDerivedBranch = db.components().insertComponent(ComponentTesting.newFileDto(derivedBranch));
     db.issues().insert(rule, derivedBranch, fileWithResolvedIssueOnDerivedBranch, i -> i.setStatus("RESOLVED"));
 
     underTest = new SiblingComponentsWithOpenIssues(treeRootHolder, metadataHolder, db.getDbClient());
index 870e352dcdb896809c8bb1372240bd8f3811a92a..ccc993af92fcae05b53bcbcafffaf94de9f9d604 100644 (file)
@@ -115,9 +115,9 @@ public class SiblingsIssueMergerIT {
     branch3Dto = db.components().insertProjectBranch(projectDto, b -> b.setKey("myBranch3")
       .setBranchType(BranchType.PULL_REQUEST)
       .setMergeBranchUuid(projectDto.uuid()));
-    fileOnBranch1Dto = db.components().insertComponent(newFileDto(branch1Dto).setKey(FILE_1_KEY));
-    fileOnBranch2Dto = db.components().insertComponent(newFileDto(branch2Dto).setKey(FILE_1_KEY));
-    fileOnBranch3Dto = db.components().insertComponent(newFileDto(branch3Dto).setKey(FILE_1_KEY));
+    fileOnBranch1Dto = db.components().insertComponent(newFileDto(branch1Dto, projectDto.uuid()).setKey(FILE_1_KEY));
+    fileOnBranch2Dto = db.components().insertComponent(newFileDto(branch2Dto, projectDto.uuid()).setKey(FILE_1_KEY));
+    fileOnBranch3Dto = db.components().insertComponent(newFileDto(branch3Dto, projectDto.uuid()).setKey(FILE_1_KEY));
     rule = db.rules().insert();
     when(branch.getReferenceBranchUuid()).thenReturn(projectDto.uuid());
     metadataHolder.setBranch(branch);
index 1816523c11148d749ef322ae6ddfa5bae7e14e19..1db962d0d157a34f89f34261c7687d2e3571a3ef 100644 (file)
@@ -327,10 +327,10 @@ public class LoadCrossProjectDuplicationsRepositoryStepIT {
   }
 
   private ComponentDto createFile(String fileKey, ComponentDto project) {
-    ComponentDto file = ComponentTesting.newFileDto(project, null)
+    ComponentDto file = ComponentTesting.newFileDto(project)
       .setKey(fileKey)
       .setLanguage(XOO_LANGUAGE);
-    dbClient.componentDao().insert(dbSession, file);
+    dbClient.componentDao().insert(dbSession, file, false);
     dbSession.commit();
     return file;
   }
index 99d9bac1ebca821bb2cf564fb9f87f803a0ee74a..ed30205c8abfae97954834c45cec40190fe5933a 100644 (file)
@@ -121,7 +121,7 @@ public class PersistIssuesStepIT extends BaseStepTest {
     RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
     db.rules().insert(rule);
     ComponentDto project = db.components().insertPrivateProject();
-    ComponentDto file = db.components().insertComponent(newFileDto(project, null));
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
     when(system2.now()).thenReturn(NOW);
     String issueKey = "ISSUE-1";
 
@@ -185,7 +185,7 @@ public class PersistIssuesStepIT extends BaseStepTest {
     RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
     db.rules().insert(rule);
     ComponentDto project = db.components().insertPrivateProject();
-    ComponentDto file = db.components().insertComponent(newFileDto(project, null));
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
     when(system2.now()).thenReturn(NOW);
     String issueKey = "ISSUE-2";
 
@@ -231,7 +231,7 @@ public class PersistIssuesStepIT extends BaseStepTest {
     RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
     db.rules().insert(rule);
     ComponentDto project = db.components().insertPrivateProject();
-    ComponentDto file = db.components().insertComponent(newFileDto(project, null));
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
     when(system2.now()).thenReturn(NOW);
     String issueKey = "ISSUE-3";
 
@@ -290,7 +290,7 @@ public class PersistIssuesStepIT extends BaseStepTest {
     RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
     db.rules().insert(rule);
     ComponentDto project = db.components().insertPrivateProject();
-    ComponentDto file = db.components().insertComponent(newFileDto(project, null));
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
     IssueDto issue = db.issues().insert(rule, project, file,
       i -> i.setStatus(STATUS_OPEN)
         .setResolution(null)
@@ -325,7 +325,7 @@ public class PersistIssuesStepIT extends BaseStepTest {
     RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
     db.rules().insert(rule);
     ComponentDto project = db.components().insertPrivateProject();
-    ComponentDto file = db.components().insertComponent(newFileDto(project, null));
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
     session.commit();
     String issueKey = "ISSUE-4";
 
@@ -397,7 +397,7 @@ public class PersistIssuesStepIT extends BaseStepTest {
     RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
     db.rules().insert(rule);
     ComponentDto project = db.components().insertPrivateProject();
-    ComponentDto file = db.components().insertComponent(newFileDto(project, null));
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
     when(system2.now()).thenReturn(NOW);
     String issueKey = "ISSUE-5";
 
@@ -450,7 +450,7 @@ public class PersistIssuesStepIT extends BaseStepTest {
     RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
     db.rules().insert(rule);
     ComponentDto project = db.components().insertPrivateProject();
-    ComponentDto file = db.components().insertComponent(newFileDto(project, null));
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
     when(system2.now()).thenReturn(NOW);
     String issueKey = "ISSUE-6";
 
@@ -499,7 +499,7 @@ public class PersistIssuesStepIT extends BaseStepTest {
     RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
     db.rules().insert(rule);
     ComponentDto project = db.components().insertPrivateProject();
-    ComponentDto file = db.components().insertComponent(newFileDto(project, null));
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
     when(system2.now()).thenReturn(NOW);
     String issueKey = "ISSUE-7";
 
index 1a4c4c031ccdb127bcde6e3be13c378bc338459f..68390b461345df67cb0ba5027fa096232b1720d5 100644 (file)
@@ -21,7 +21,9 @@ package org.sonar.ce.task.projectanalysis.step;
 
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.List;
 import java.util.Optional;
+import java.util.Set;
 import java.util.function.Consumer;
 import java.util.stream.Stream;
 import org.junit.Before;
@@ -248,7 +250,7 @@ public class ReportPersistComponentsStepIT extends BaseStepTest {
     ComponentDto directory = ComponentTesting.newDirectory(project, "src").setUuid("CDEF").setKey("PROJECT_KEY:src");
     ComponentDto file = ComponentTesting.newFileDto(project, directory, "DEFG").setPath("src/foo").setName("foo")
       .setKey("PROJECT_KEY:src/foo");
-    dbClient.componentDao().insert(db.getSession(), directory, file);
+    dbClient.componentDao().insert(db.getSession(), Set.of(directory, file), true);
     db.getSession().commit();
 
     assertThat(dbClient.componentDao().selectByKey(db.getSession(), PROJECT_KEY + ":src/foo").get().scope()).isEqualTo("FIL");
@@ -326,7 +328,7 @@ public class ReportPersistComponentsStepIT extends BaseStepTest {
     ComponentDto directory = ComponentTesting.newDirectory(project, "src/main/java/dir").setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir");
     ComponentDto file = ComponentTesting.newFileDto(project, directory, "DEFG").setPath("src/main/java/dir/Foo.java").setName("Foo.java")
       .setKey("PROJECT_KEY:src/main/java/dir/Foo.java");
-    dbClient.componentDao().insert(db.getSession(), directory, file);
+    dbClient.componentDao().insert(db.getSession(), Set.of(directory, file), true);
     db.getSession().commit();
 
     treeRootHolder.setRoot(
@@ -399,7 +401,7 @@ public class ReportPersistComponentsStepIT extends BaseStepTest {
       .setName("Foo.java")
       .setKey("PROJECT_KEY:src/main/java/dir/Foo.java")
       .setEnabled(false);
-    dbClient.componentDao().insert(db.getSession(), removedDirectory, removedFile);
+    dbClient.componentDao().insert(db.getSession(), Set.of(removedDirectory, removedFile), true);
     db.getSession().commit();
 
     treeRootHolder.setRoot(
index 5b315e9dbda8845d2b700603a2c84a7a4cdb56b9..0f898673c436f9f423041d3d8fa3e4cc139d8340 100644 (file)
@@ -104,6 +104,7 @@ import static org.sonar.db.component.BranchType.PULL_REQUEST;
 import static org.sonar.db.component.ComponentTesting.newBranchComponent;
 import static org.sonar.db.component.ComponentTesting.newBranchDto;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
+import static org.sonar.db.component.ComponentTesting.newMainBranchDto;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.db.issue.IssueTesting.newIssue;
 import static org.sonar.db.rule.RuleTesting.newRule;
@@ -568,7 +569,7 @@ public class SendIssueNotificationsStepIT extends BaseStepTest {
   private void sendIssueChangeNotificationOnBranch(long issueCreatedAt) {
     ComponentDto project = newPrivateProjectDto();
     ComponentDto branch = newBranchComponent(project, newBranchDto(project).setKey(BRANCH_NAME));
-    ComponentDto file = newFileDto(branch);
+    ComponentDto file = newFileDto(branch, project.uuid());
     treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(branch.getKey()).setName(branch.longName()).setUuid(branch.uuid()).addChildren(
       builder(Type.FILE, 11).setKey(file.getKey()).setName(file.longName()).build()).build());
     analysisMetadataHolder.setProject(Project.from(project));
@@ -700,8 +701,13 @@ public class SendIssueNotificationsStepIT extends BaseStepTest {
   }
 
   private ComponentDto setUpBranch(ComponentDto project, BranchType branchType) {
-    ComponentDto branch = newBranchComponent(project, newBranchDto(project, branchType).setKey(BRANCH_NAME));
-    ComponentDto file = newFileDto(branch);
+    ComponentDto branch = null;
+    if(branchType == PULL_REQUEST) {
+      branch = newBranchComponent(project, newBranchDto(project, PULL_REQUEST, project.uuid()));
+    } else {
+      branch = newBranchComponent(project, newMainBranchDto(project).setKey(BRANCH_NAME));
+    }
+    ComponentDto file = newFileDto(branch, project.uuid());
     treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(branch.getKey()).setName(branch.longName()).setUuid(branch.uuid()).addChildren(
       builder(Type.FILE, 11).setKey(file.getKey()).setName(file.longName()).build()).build());
     return branch;
index c69ac17598240a1ca60015675187e778e2d70771..95a7f770898134c147401aeba67cda1c7413e78d 100644 (file)
@@ -24,6 +24,7 @@ import com.tngtech.java.junit.dataprovider.DataProvider;
 import com.tngtech.java.junit.dataprovider.DataProviderRunner;
 import com.tngtech.java.junit.dataprovider.UseDataProvider;
 import java.util.List;
+import java.util.Set;
 import javax.annotation.Nullable;
 import org.junit.Before;
 import org.junit.Rule;
@@ -108,7 +109,7 @@ public class ExportAnalysesStepIT {
   public void setUp() {
     ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT);
     componentRepository.register(1, projectDto.uuid(), false);
-    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), DIR, FILE);
+    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), Set.of(DIR, FILE), true);
     dbTester.commit();
     when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(projectDto));
   }
index 4b3d12f2be80a4f5943e2a2d1b606bfac3b43dd1..e39789dfffc1dcb2a63ce9ee5cd249660858924c 100644 (file)
@@ -94,7 +94,7 @@ public class ExportComponentsStepIT {
   @Test
   public void export_components_including_project() {
     dbTester.components().insertPublicProject(PROJECT);
-    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), FILE);
+    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), FILE, true);
     dbTester.commit();
     when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(PROJECT));
 
@@ -111,7 +111,7 @@ public class ExportComponentsStepIT {
   @Test
   public void execute_register_all_components_uuids_as_their_id_in_ComponentRepository() {
     dbTester.components().insertPublicProject(PROJECT);
-    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), FILE);
+    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), FILE, true);
     dbTester.commit();
     when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(PROJECT));
 
@@ -125,7 +125,7 @@ public class ExportComponentsStepIT {
   @Test
   public void throws_ISE_if_error() {
     dbTester.components().insertPublicProject(PROJECT);
-    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), FILE);
+    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), FILE, true);
     dbTester.commit();
     when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(PROJECT));
     dumpWriter.failIfMoreThan(1, DumpElement.COMPONENTS);
index 4bed242c8de2f8e40f5a2cec497366baa273ee3a..8d16133ac45f9494e3af256a1f4da376ebf13b25 100644 (file)
@@ -109,7 +109,7 @@ public class ExportMeasuresStepIT {
   public void setUp() {
     String projectUuid = dbTester.components().insertPublicProject(PROJECT).uuid();
     componentRepository.register(1, projectUuid, false);
-    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), FILE, ANOTHER_PROJECT);
+    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), List.of(FILE, ANOTHER_PROJECT), true);
     dbTester.getDbClient().metricDao().insert(dbTester.getSession(), NCLOC, DISABLED_METRIC, NEW_NCLOC);
     dbTester.commit();
     when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(PROJECT));
index 8e591b95e8168e8def24024a974b9c6aa9a3d979..6b16eab20682ada925959c7f254cadc78da2da53 100644 (file)
@@ -110,10 +110,6 @@ public class PersistComponentsStep implements ComputationStep {
     }
   }
 
-  /**
-   * See {@link ComponentDto#mainBranchProjectUuid} : value is null on main branches, otherwise it is
-   * the uuid of the main branch.
-   */
   @CheckForNull
   private String loadProjectUuidOfMainBranch() {
     if (!analysisMetadataHolder.getBranch().isMain()) {
@@ -225,7 +221,7 @@ public class PersistComponentsStep implements ComputationStep {
     private ComponentDto persistComponent(ComponentDto componentDto) {
       ComponentDto existingComponent = existingComponentDtosByUuids.remove(componentDto.uuid());
       if (existingComponent == null) {
-        dbClient.componentDao().insert(dbSession, componentDto);
+        dbClient.componentDao().insert(dbSession, componentDto, analysisMetadataHolder.getBranch().isMain());
         return componentDto;
       }
       Optional<ComponentUpdateDto> update = compareForUpdate(existingComponent, componentDto);
index f351eb644b20d519e0e432572abdbeca3428b2d1..f6a5d6dfdf267a5a049745583654906896185ec3 100644 (file)
@@ -98,9 +98,9 @@ public class PullRequestSourceBranchMergerTest {
     ComponentDto branch3Dto = db.components().insertProjectBranch(projectDto, b -> b.setKey("myBranch3")
       .setBranchType(BranchType.PULL_REQUEST)
       .setMergeBranchUuid(projectDto.uuid()));
-    db.components().insertComponent(newFileDto(branch1Dto).setKey(FILE_1_KEY + ":PULL_REQUEST:myBranch1"));
-    db.components().insertComponent(newFileDto(branch2Dto).setKey(FILE_1_KEY + ":PULL_REQUEST:myBranch2"));
-    db.components().insertComponent(newFileDto(branch3Dto).setKey(FILE_1_KEY + ":PULL_REQUEST:myBranch3"));
+    db.components().insertComponent(newFileDto(branch1Dto, projectDto.uuid()).setKey(FILE_1_KEY + ":PULL_REQUEST:myBranch1"));
+    db.components().insertComponent(newFileDto(branch2Dto, projectDto.uuid()).setKey(FILE_1_KEY + ":PULL_REQUEST:myBranch2"));
+    db.components().insertComponent(newFileDto(branch3Dto, projectDto.uuid()).setKey(FILE_1_KEY + ":PULL_REQUEST:myBranch3"));
     rule = db.rules().insert();
     rawIssue = createIssue("issue1", rule.getKey(), Issue.STATUS_OPEN, new Date());
     rawIssuesInput = new DefaultTrackingInput(singletonList(rawIssue), mock(LineHashSequence.class), mock(BlockHashSequence.class));
index 5bb1d10d941e4f41e961134fb2e5849e55ed3ed2..9a08ca17b6c087887c5e64df18d72c19d35bb6b7 100644 (file)
@@ -228,7 +228,7 @@ public class ComponentDaoIT {
   public void select_by_key_and_branch() {
     ComponentDto project = db.components().insertPublicProject();
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch").setBranchType(BRANCH));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
 
     assertThat(underTest.selectByKeyAndBranch(dbSession, project.getKey(), DEFAULT_MAIN_BRANCH_NAME).get().uuid()).isEqualTo(project.uuid());
     assertThat(underTest.selectByKeyAndBranch(dbSession, branch.getKey(), "my_branch").get().uuid()).isEqualTo(branch.uuid());
@@ -305,8 +305,8 @@ public class ComponentDaoIT {
     String branchKey = "my_branch";
     ComponentDto project = db.components().insertPublicProject();
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchKey));
-    ComponentDto file1 = db.components().insertComponent(newFileDto(branch));
-    ComponentDto file2 = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file1 = db.components().insertComponent(newFileDto(branch, project.uuid()));
+    ComponentDto file2 = db.components().insertComponent(newFileDto(branch, project.uuid()));
     ComponentDto anotherBranch = db.components().insertProjectBranch(project, b -> b.setKey("another_branch"));
     ComponentDto fileOnAnotherBranch = db.components().insertComponent(newFileDto(anotherBranch));
 
@@ -1117,7 +1117,7 @@ public class ComponentDaoIT {
     ComponentDto dto1 = newPrivateProjectDto("U1");
     ComponentDto dto2 = newPrivateProjectDto("U2");
     ComponentDto dto3 = newPrivateProjectDto("U3");
-    underTest.insert(dbSession, dto1, dto2, dto3);
+    underTest.insert(dbSession, List.of(dto1, dto2, dto3), true);
 
     underTest.updateBEnabledToFalse(dbSession, asList("U1", "U2"));
     dbSession.commit();
@@ -1789,7 +1789,7 @@ public class ComponentDaoIT {
   public void insert_auditPersisterIsCalled() {
     ComponentDto app = ComponentTesting.newApplication();
 
-    underTestWithAuditPersister.insert(dbSession, app);
+    underTestWithAuditPersister.insert(dbSession, app, true);
 
     verify(auditPersister).addComponent(any(DbSession.class), any(ComponentNewValue.class));
   }
@@ -1800,7 +1800,7 @@ public class ComponentDaoIT {
     BranchDto branch = newBranchDto(project);
     ComponentDto branchComponent = newBranchComponent(project, branch);
 
-    underTestWithAuditPersister.insert(dbSession, branchComponent);
+    underTestWithAuditPersister.insert(dbSession, branchComponent, false);
 
     verifyNoInteractions(auditPersister);
   }
index 8e62ecd2c1267ce50079f479ab2a4e4b0a9579ce..b2a5fff2f8f35746665703074d81eedacd697ee4 100644 (file)
@@ -98,8 +98,8 @@ public class ComponentKeyUpdaterDaoIT {
     ComponentDto project = db.components().insertPublicProject();
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
-    db.components().insertComponent(newFileDto(branch));
-    db.components().insertComponent(newFileDto(branch));
+    db.components().insertComponent(newFileDto(branch, project.uuid()));
+    db.components().insertComponent(newFileDto(branch, project.uuid()));
     int prComponentCount = 3;
 
     String oldProjectKey = project.getKey();
@@ -159,7 +159,7 @@ public class ComponentKeyUpdaterDaoIT {
   public void updateKey_throws_IAE_when_sub_component_key_is_too_long() {
     ComponentDto project = newPrivateProjectDto("project-uuid").setKey("old-project-key");
     db.components().insertComponent(project);
-    db.components().insertComponent(newFileDto(project, null).setKey("old-project-key:file"));
+    db.components().insertComponent(newFileDto(project).setKey("old-project-key:file"));
     String newLongProjectKey = Strings.repeat("a", 400);
 
     assertThatThrownBy(() -> underTest.updateKey(dbSession, project.uuid(), newLongProjectKey))
index 40af62b9d7a14c30a123eeb1880382479d306361..aae4b56442e9d88efa9d05aa035ed3aa8ad01ecd 100644 (file)
@@ -72,10 +72,10 @@ public class IssueMapperIT {
   @Before
   public void setUp() {
     project = dbTester.components().insertPrivateProject();
-    file = ComponentTesting.newFileDto(project, null);
-    dbTester.getDbClient().componentDao().insert(dbSession, file);
-    file2 = ComponentTesting.newFileDto(project, null).setUuid("file2 uuid");
-    dbTester.getDbClient().componentDao().insert(dbSession, file2);
+    file = ComponentTesting.newFileDto(project);
+    dbTester.getDbClient().componentDao().insert(dbSession, file, true);
+    file2 = ComponentTesting.newFileDto(project).setUuid("file2 uuid");
+    dbTester.getDbClient().componentDao().insert(dbSession, file2, true);
     rule = RuleTesting.newXooX1();
     dbTester.rules().insert(rule);
     dbSession.commit();
index b91b833a53b1fcce3624651f940ba1d0351c2c9e..f63586e9d6ab37422d81bd1551abc557ef31ce7a 100644 (file)
@@ -314,7 +314,7 @@ public class ProjectMeasuresIndexerIteratorIT {
     Consumer<ComponentDto> componentDtoPopulator, Consumer<ProjectDto> projectDtoPopulator) {
     componentDtoPopulator.accept(component);
     checkState(isPrivate == null || component.isPrivate() == isPrivate, "Illegal modification of private flag");
-    dbClient.componentDao().insert(dbSession, component);
+    dbClient.componentDao().insert(dbSession, component, true);
 
     ProjectDto projectDto = toProjectDto(component, System2.INSTANCE.now());
     projectDtoPopulator.accept(projectDto);
index 0a147e4c53ac04323e40777f0437a87dd8c12979..17fd4cc182d23e88199c3875b6432d2eafd2af2a 100644 (file)
@@ -155,13 +155,20 @@ public class PurgeCommandsIT {
   public void deleteNonMainBranchComponentsByProjectUuid_shouldDeletesAllBranchesOfAProjectExceptMainBranch(ComponentDto project) {
     dbTester.components().insertComponent(project);
     ComponentDto branch = dbTester.components().insertProjectBranch(project);
-    Stream.of(project, branch).forEach(prj -> {
-      ComponentDto directory1 = dbTester.components().insertComponent(ComponentTesting.newDirectory(prj, "a"));
-      ComponentDto directory2 = dbTester.components().insertComponent(ComponentTesting.newDirectory(prj, "b"));
-      dbTester.components().insertComponent(newFileDto(prj));
-      dbTester.components().insertComponent(newFileDto(directory1));
-      dbTester.components().insertComponent(newFileDto(directory2));
-    });
+
+    ComponentDto directory1 = dbTester.components().insertComponent(ComponentTesting.newDirectory(project, "a"));
+    ComponentDto directory2 = dbTester.components().insertComponent(ComponentTesting.newDirectory(project, "b"));
+    dbTester.components().insertComponent(newFileDto(project));
+    dbTester.components().insertComponent(newFileDto(directory1));
+    dbTester.components().insertComponent(newFileDto(directory2));
+
+    directory1 = dbTester.components().insertComponent(ComponentTesting.newDirectory(branch, "a")
+      .setMainBranchProjectUuid(project.uuid()));
+    directory2 = dbTester.components().insertComponent(ComponentTesting.newDirectory(branch, "b")
+      .setMainBranchProjectUuid(project.uuid()));
+    dbTester.components().insertComponent(newFileDto(branch, project.uuid()).setMainBranchProjectUuid(project.uuid()));
+    dbTester.components().insertComponent(newFileDto(directory1).setMainBranchProjectUuid(project.uuid()));
+    dbTester.components().insertComponent(newFileDto(directory2).setMainBranchProjectUuid(project.uuid()));
 
     underTest.deleteNonMainBranchComponentsByProjectUuid(project.uuid());
 
@@ -580,11 +587,11 @@ public class PurgeCommandsIT {
 
   @Test
   public void deletePermissions_deletes_permissions_of_view() {
-    ComponentDto project = dbTester.components().insertPublicPortfolio();
-    addPermissions(project);
+    ComponentDto portfolio = dbTester.components().insertPublicPortfolio();
+    addPermissions(portfolio);
 
     PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler, system2);
-    purgeCommands.deletePermissions(project.uuid());
+    purgeCommands.deletePermissions(portfolio.uuid());
 
     assertThat(dbTester.countRowsOfTable("group_roles")).isEqualTo(2);
     assertThat(dbTester.countRowsOfTable("user_roles")).isOne();
index 0d35792599b928bf344485ea7b83f027dcb4c51f..171c524c1a612d56ce199c9c8b19e66a01ec8f48 100644 (file)
@@ -366,7 +366,7 @@ public class PurgeDaoIT {
   @Test
   public void deleteAnalyses_deletes_rows_in_events_and_event_component_changes() {
     ComponentDto project = ComponentTesting.newPrivateProjectDto();
-    dbClient.componentDao().insert(dbSession, project);
+    dbClient.componentDao().insert(dbSession, project, true);
     SnapshotDto projectAnalysis1 = db.components().insertSnapshot(project);
     SnapshotDto projectAnalysis2 = db.components().insertSnapshot(project);
     SnapshotDto projectAnalysis3 = db.components().insertSnapshot(project);
@@ -685,8 +685,7 @@ public class PurgeDaoIT {
   public void delete_row_in_ce_activity_when_deleting_project() {
     ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto();
     ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto();
-    dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject);
-
+    insertComponents(List.of(anotherLivingProject), List.of(projectToBeDeleted));
     // Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project
     CeActivityDto toBeDeletedActivity = insertCeActivity(projectToBeDeleted);
     CeActivityDto notDeletedActivity = insertCeActivity(anotherLivingProject);
@@ -706,7 +705,8 @@ public class PurgeDaoIT {
     ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto();
-    dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
+
+    insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch));
 
     CeActivityDto projectTask = insertCeActivity(project);
     insertCeTaskInput(projectTask.getUuid());
@@ -738,7 +738,8 @@ public class PurgeDaoIT {
     ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto();
-    dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
+
+    insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch));
 
     CeActivityDto projectTask = insertCeActivity(project);
     insertCeScannerContext(projectTask.getUuid());
@@ -770,7 +771,8 @@ public class PurgeDaoIT {
     ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto();
-    dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
+
+    insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch));
 
     CeActivityDto projectTask = insertCeActivity(project);
     insertCeTaskCharacteristics(projectTask.getUuid(), 3);
@@ -802,7 +804,8 @@ public class PurgeDaoIT {
     ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto();
-    dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
+
+    insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch));
 
     CeActivityDto projectTask = insertCeActivity(project);
     insertCeTaskMessages(projectTask.getUuid(), 3);
@@ -872,7 +875,8 @@ public class PurgeDaoIT {
     ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto();
-    dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
+
+    insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch));
 
     CeQueueDto projectTask = insertCeQueue(project);
     insertCeTaskInput(projectTask.getUuid());
@@ -904,7 +908,8 @@ public class PurgeDaoIT {
     ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto();
-    dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
+
+    insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch));
 
     CeQueueDto projectTask = insertCeQueue(project);
     insertCeScannerContext(projectTask.getUuid());
@@ -931,13 +936,19 @@ public class PurgeDaoIT {
     assertThat(taskUuidsIn("ce_scanner_context")).containsOnly(anotherProjectTask.getUuid(), "non existing task");
   }
 
+  private void insertComponents(List<ComponentDto> componentsOnMainBranch, List<ComponentDto> componentsNotOnMainBranch) {
+    componentsOnMainBranch.forEach(c -> dbClient.componentDao().insert(dbSession, c, true));
+    componentsNotOnMainBranch.forEach(c -> dbClient.componentDao().insert(dbSession, c, false));
+  }
+
   @Test
   public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_queue_when_deleting_project() {
     ComponentDto project = ComponentTesting.newPrivateProjectDto();
     ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto();
-    dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
+
+    insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch));
 
     CeQueueDto projectTask = insertCeQueue(project);
     insertCeTaskCharacteristics(projectTask.getUuid(), 3);
@@ -970,7 +981,8 @@ public class PurgeDaoIT {
     ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto();
-    dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
+
+    insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch));
 
     CeQueueDto projectTask = insertCeQueue(project);
     insertCeTaskMessages(projectTask.getUuid(), 3);
@@ -1003,7 +1015,9 @@ public class PurgeDaoIT {
     ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
     ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto();
-    dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
+
+    insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch));
+
     SnapshotDto projectAnalysis1 = db.components().insertSnapshot(project);
     SnapshotDto projectAnalysis2 = db.components().insertSnapshot(project);
     EventDto projectEvent1 = db.events().insertEvent(projectAnalysis1);
index c037d412e671a8018203b4497d6462f4f92d48cd..deb5452010e934fbaa3ef74263a674749259330e 100644 (file)
@@ -70,21 +70,6 @@ public class CeQueueDto {
     return this;
   }
 
-  /**
-   * Helper methods which sets both {@link #componentUuid} and {@link #mainComponentUuid} from the specified
-   * {@link ComponentDto}.
-   */
-  public CeQueueDto setComponent(@Nullable ComponentDto component) {
-    if (component == null) {
-      this.componentUuid = null;
-      this.mainComponentUuid = null;
-    } else {
-      this.componentUuid = requireNonNull(component.uuid());
-      this.mainComponentUuid = firstNonNull(component.getMainBranchProjectUuid(), component.uuid());
-    }
-    return this;
-  }
-
   @CheckForNull
   public String getComponentUuid() {
     return componentUuid;
index 759bea823ed2969895a54562e798c44cc5f1c6fa..39d000faec9e2fad9374ee27cc386940275b8699 100644 (file)
@@ -94,11 +94,11 @@ public class BranchDao implements Dao {
    * Returns collection of branches that are in the same project as the component
    */
   public Collection<BranchDto> selectByComponent(DbSession dbSession, ComponentDto component) {
-    String projectUuid = component.getMainBranchProjectUuid();
-    if (projectUuid == null) {
-      projectUuid = component.branchUuid();
+    BranchDto branchDto = mapper(dbSession).selectByUuid(component.branchUuid());
+    if(branchDto == null) {
+      return List.of();
     }
-    return mapper(dbSession).selectByProjectUuid(projectUuid);
+    return mapper(dbSession).selectByProjectUuid(branchDto.getProjectUuid());
   }
 
   public Collection<BranchDto> selectByProject(DbSession dbSession, ProjectDto project) {
index 1973e29b68734ff03fdbcaa34259ceaf9e2d0f50..3d3a7daa5d29f0b26bc5f69745511e3d4db5ab1c 100644 (file)
@@ -24,7 +24,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
-import javax.annotation.Nullable;
 import org.apache.ibatis.annotations.Param;
 
 public interface BranchMapper {
index 9044d64ad57056cd6d7066d5a81cbe5b9236021a..71dbafe1e4b534fb070611c99ee8c19e7c041279 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.db.component;
 
 import com.google.common.collect.Ordering;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
@@ -319,23 +318,23 @@ public class ComponentDao implements Dao {
   /*
     INSERT / UPDATE
    */
-  public void insert(DbSession session, ComponentDto item) {
+  public void insert(DbSession session, ComponentDto item, boolean isMainBranch) {
     mapper(session).insert(item);
-    if (!isBranchOrPullRequest(item)) {
+    if (isMainBranch) {
       auditPersister.addComponent(session, new ComponentNewValue(item));
     }
   }
 
-  public void insert(DbSession session, Collection<ComponentDto> items) {
-    insert(session, items.stream());
+  public void insertOnMainBranch(DbSession session, ComponentDto item) {
+    insert(session, item, true);
   }
 
-  private void insert(DbSession session, Stream<ComponentDto> items) {
-    items.forEach(item -> insert(session, item));
+  public void insert(DbSession session, Collection<ComponentDto> items, boolean isMainBranch) {
+    insert(session, items.stream(), isMainBranch);
   }
 
-  public void insert(DbSession session, ComponentDto item, ComponentDto... others) {
-    insert(session, Stream.concat(Stream.of(item), Arrays.stream(others)));
+  private void insert(DbSession session, Stream<ComponentDto> items, boolean isMainBranch) {
+    items.forEach(item -> insert(session, item, isMainBranch));
   }
 
   public void update(DbSession session, ComponentUpdateDto component, String qualifier) {
@@ -378,8 +377,4 @@ public class ComponentDao implements Dao {
     checkThatNotTooManyConditions(query.getComponentUuids(), "Too many component UUIDs in query");
   }
 
-  private static boolean isBranchOrPullRequest(ComponentDto item) {
-    return item.getMainBranchProjectUuid() != null;
-  }
-
 }
index 996adb5462a58be203c5ac09696915415e96c6b8..78e92a39d7a118cf2867c104490e50a6a89609a3 100644 (file)
     SELECT
       <include refid="componentColumns"/>
     FROM components p
+    inner join project_branches pb on pb.uuid = p.branch_uuid
     where
       lower(p.kee)=lower(#{key,jdbcType=VARCHAR})
-      and p.main_branch_project_uuid is null
+      and pb.is_main = ${_true}
   </select>
 
   <select id="selectByKeyAndBranchKey" parameterType="String" resultType="Component">
index b27e43e05a0eca5807dad9898d05ed2e168b3348..3d206dafaae1d8b516621dc19aa84c0113e5d80b 100644 (file)
@@ -54,7 +54,7 @@ public class ComponentDbTester {
   }
 
   public SnapshotDto insertPortfolioAndSnapshot(ComponentDto component) {
-    dbClient.componentDao().insert(dbSession, component);
+    dbClient.componentDao().insert(dbSession, component, true);
     return insertSnapshot(component);
   }
 
@@ -402,7 +402,7 @@ public class ComponentDbTester {
     projectDtoPopulator.accept(projectDto);
     dbClient.projectDao().insert(dbSession, projectDto);
 
-    BranchDto branchDto = ComponentTesting.newBranchDto(component, BRANCH);
+    BranchDto branchDto = ComponentTesting.newMainBranchDto(component);
     branchDto.setExcludeFromPurge(true);
     branchPopulator.accept(branchDto);
     branchDto.setIsMain(true);
@@ -449,14 +449,14 @@ public class ComponentDbTester {
   private ComponentDto insertComponentImpl(ComponentDto component, @Nullable Boolean isPrivate, Consumer<ComponentDto> dtoPopulator) {
     dtoPopulator.accept(component);
     checkState(isPrivate == null || component.isPrivate() == isPrivate, "Illegal modification of private flag");
-    dbClient.componentDao().insert(dbSession, component);
+    dbClient.componentDao().insert(dbSession, component, true);
     db.commit();
 
     return component;
   }
 
   public void insertComponents(ComponentDto... components) {
-    dbClient.componentDao().insert(dbSession, asList(components));
+    dbClient.componentDao().insert(dbSession, asList(components), true);
     db.commit();
   }
 
@@ -503,8 +503,7 @@ public class ComponentDbTester {
 
   @SafeVarargs
   public final ComponentDto insertProjectBranch(ComponentDto project, Consumer<BranchDto>... dtoPopulators) {
-    // MainBranchProjectUuid will be null if it's a main branch
-    BranchDto branchDto = ComponentTesting.newBranchDto(firstNonNull(project.getMainBranchProjectUuid(), project.branchUuid()), BRANCH);
+    BranchDto branchDto = ComponentTesting.newBranchDto(project.uuid(), BRANCH);
     Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(branchDto));
     return insertProjectBranch(project, branchDto);
   }
@@ -527,8 +526,6 @@ public class ComponentDbTester {
   }
 
   public final ComponentDto insertProjectBranch(ComponentDto project, BranchDto branchDto) {
-    // MainBranchProjectUuid will be null if it's a main branch
-    checkArgument(branchDto.getProjectUuid().equals(firstNonNull(project.getMainBranchProjectUuid(), project.branchUuid())));
     ComponentDto branch = ComponentTesting.newBranchComponent(project, branchDto);
     insertComponent(branch);
     dbClient.branchDao().insert(dbSession, branchDto);
index 93c2c4417e6308d8f26c32e536f1a39cf7a93048..fd7176c80e789308105fa7933755edca49b7226e 100644 (file)
@@ -36,14 +36,26 @@ import static org.sonar.db.component.ComponentDto.generateBranchKey;
 public class ComponentTesting {
 
   public static ComponentDto newFileDto(ComponentDto project) {
-    return newFileDto(project, null);
+    return newFileDto(project, (ComponentDto) null);
   }
 
   public static ComponentDto newFileDto(ComponentDto project, @Nullable ComponentDto directory) {
     return newFileDto(project, directory, Uuids.createFast());
   }
 
+  public static ComponentDto newFileDto(ComponentDto branch, String mainBranchUuid) {
+    return newFileDto(mainBranchUuid, branch, null);
+  }
+
+  public static ComponentDto newFileDto(String mainBranchUuid, ComponentDto projectOrBranch, @Nullable ComponentDto directory) {
+    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 project, @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)
@@ -52,6 +64,7 @@ public class ComponentTesting {
       .setLongName(path)
       .setScope(Scopes.FILE)
       .setBranchUuid(project.branchUuid())
+      .setMainBranchProjectUuid(mainBranchUuid)
       .setQualifier(Qualifiers.FILE)
       .setPath(path)
       .setCreatedAt(new Date())
@@ -62,18 +75,27 @@ public class ComponentTesting {
     return newDirectory(project, Uuids.createFast(), path);
   }
 
-  public static ComponentDto newDirectory(ComponentDto project, String uuid, String path) {
+  public static ComponentDto newDirectoryOnBranch(ComponentDto project, String path, String mainBranchUuid) {
+    return newDirectory(project, Uuids.createFast(), path, mainBranchUuid);
+  }
+
+  private static ComponentDto newDirectory(ComponentDto project, String uuid, String path, String mainBranchUuid) {
     String key = !path.equals("/") ? project.getKey() + ":" + path : project.getKey() + ":/";
     return newChildComponent(uuid, project, project)
       .setKey(key)
       .setName(path)
       .setLongName(path)
       .setBranchUuid(project.branchUuid())
+      .setMainBranchProjectUuid(mainBranchUuid)
       .setPath(path)
       .setScope(Scopes.DIRECTORY)
       .setQualifier(Qualifiers.DIRECTORY);
   }
 
+  public static ComponentDto newDirectory(ComponentDto project, String uuid, String path) {
+    return newDirectory(project, uuid, path, null);
+  }
+
   public static ComponentDto newSubPortfolio(ComponentDto portfolioOrSubPortfolio, String uuid, String key) {
     return newChildComponent(uuid, portfolioOrSubPortfolio, portfolioOrSubPortfolio)
       .setKey(key)
@@ -175,7 +197,6 @@ public class ComponentTesting {
       .setUuidPath(formatUuidPathFromParent(parent))
       .setKey(uuid)
       .setBranchUuid(project.branchUuid())
-      .setMainBranchProjectUuid(project.getMainBranchProjectUuid())
       .setCreatedAt(new Date())
       .setEnabled(true)
       .setPrivate(project.isPrivate());
@@ -183,12 +204,11 @@ public class ComponentTesting {
 
 
   public static BranchDto newBranchDto(@Nullable String projectUuid, BranchType branchType) {
-    String key = projectUuid == null ? null : "branch_" + randomAlphanumeric(248);
+    String key = "branch_" + randomAlphanumeric(248);
     return new BranchDto()
       .setKey(key)
       .setUuid(Uuids.createFast())
       .setIsMain(false)
-      // MainBranchProjectUuid will be null if it's a main branch
       .setProjectUuid(projectUuid)
       .setBranchType(branchType);
   }
@@ -201,19 +221,26 @@ public class ComponentTesting {
     return newBranchDto(project.branchUuid(), BranchType.BRANCH);
   }
 
-  public static BranchDto newBranchDto(ComponentDto branchComponent, BranchType branchType) {
-    boolean isMain = branchComponent.getMainBranchProjectUuid() == null;
-    String projectUuid = isMain ? branchComponent.uuid() : branchComponent.getMainBranchProjectUuid();
-    String key = isMain ? DEFAULT_MAIN_BRANCH_NAME : "branch_" + randomAlphanumeric(248);
+  public static BranchDto newBranchDto(ComponentDto branchComponent, BranchType branchType, String projectUuid) {
+    String key = "branch_" + randomAlphanumeric(248);
 
     return new BranchDto()
       .setKey(key)
-      .setIsMain(isMain)
+      .setIsMain(false)
       .setUuid(branchComponent.uuid())
       .setProjectUuid(projectUuid)
       .setBranchType(branchType);
   }
 
+  public static BranchDto newMainBranchDto(ComponentDto branchComponent) {
+    return new BranchDto()
+      .setKey(DEFAULT_MAIN_BRANCH_NAME)
+      .setIsMain(true)
+      .setUuid(branchComponent.uuid())
+      .setProjectUuid(branchComponent.uuid())
+      .setBranchType(BranchType.BRANCH);
+  }
+
   public static ComponentDto newBranchComponent(ProjectDto project, BranchDto branchDto) {
     String uuid = branchDto.getUuid();
     return new ComponentDto()
@@ -235,7 +262,6 @@ public class ComponentTesting {
 
   public static ComponentDto newBranchComponent(ComponentDto project, BranchDto branchDto) {
     checkArgument(project.qualifier().equals(Qualifiers.PROJECT) || project.qualifier().equals(Qualifiers.APP));
-    checkArgument(project.getMainBranchProjectUuid() == null);
     String uuid = branchDto.getUuid();
     return new ComponentDto()
       .setUuid(uuid)
index 6664dae2eba1ad30cc2296f8a58ae1edaa08c626..846b20a7c9cc1f1803b9cfdfd13127c56cfceaeb 100644 (file)
@@ -33,6 +33,7 @@ import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.ce.CeTaskMessageType;
+import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.permission.GlobalPermission;
 import org.sonar.db.permission.GroupPermissionDto;
@@ -236,7 +237,9 @@ public class UserDbTester {
     checkArgument(!project.isPrivate(), "No permission to group AnyOne can be granted on a private project");
     checkArgument(!PUBLIC_PERMISSIONS.contains(permission),
       "permission %s can't be granted on a public project", permission);
-    checkArgument(project.getMainBranchProjectUuid() == null, PERMISSIONS_CANT_BE_GRANTED_ON_BRANCHES);
+    Optional<BranchDto> branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.branchUuid());
+    // I don't know if this check is worth it
+    branchDto.ifPresent(dto -> checkArgument(dto.isMain(), PERMISSIONS_CANT_BE_GRANTED_ON_BRANCHES));
     GroupPermissionDto dto = new GroupPermissionDto()
       .setUuid(Uuids.createFast())
       .setGroupUuid(null)
@@ -256,7 +259,9 @@ public class UserDbTester {
   public GroupPermissionDto insertProjectPermissionOnGroup(GroupDto group, String permission, ComponentDto project) {
     checkArgument(project.isPrivate() || !PUBLIC_PERMISSIONS.contains(permission),
       "%s can't be granted on a public project", permission);
-    checkArgument(project.getMainBranchProjectUuid() == null, PERMISSIONS_CANT_BE_GRANTED_ON_BRANCHES);
+    Optional<BranchDto> branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.branchUuid());
+    // I don't know if this check is worth it
+    branchDto.ifPresent(dto -> checkArgument(dto.isMain(), PERMISSIONS_CANT_BE_GRANTED_ON_BRANCHES));
     GroupPermissionDto dto = new GroupPermissionDto()
       .setUuid(Uuids.createFast())
       .setGroupUuid(group.getUuid())
@@ -318,7 +323,9 @@ public class UserDbTester {
   public UserPermissionDto insertProjectPermissionOnUser(UserDto user, String permission, ComponentDto project) {
     checkArgument(project.isPrivate() || !PUBLIC_PERMISSIONS.contains(permission),
       "%s can't be granted on a public project", permission);
-    checkArgument(project.getMainBranchProjectUuid() == null, PERMISSIONS_CANT_BE_GRANTED_ON_BRANCHES);
+    Optional<BranchDto> branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.branchUuid());
+    // I don't know if this check is worth it
+    branchDto.ifPresent(dto -> checkArgument(dto.isMain(), PERMISSIONS_CANT_BE_GRANTED_ON_BRANCHES));
     UserPermissionDto dto = new UserPermissionDto(Uuids.create(), permission, user.getUuid(), project.uuid());
     db.getDbClient().userPermissionDao().insert(db.getSession(), dto, project, user, null);
     db.commit();
index 3f9aea940814caf4f151709e858a23dd8c53dc14..b5fadad5feec6e59492801f4773d68574771cef0 100644 (file)
@@ -483,7 +483,7 @@ public class IssueIndexerIT {
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("feature/foo"));
     BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), branch.uuid()).orElseThrow();
     ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(branch, "src/main/java/foo"));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch, dir, "F1"));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, dir, "F1").setMainBranchProjectUuid(project.uuid()));
     IssueDto issue = db.issues().insert(rule, branch, file);
 
     underTest.indexAllIssues();
index fb5d2047ae36e348e4f0fba8c72e1b1116692709..900743d33f70bafd95f68cad1ee9cdd450ccfe15 100644 (file)
@@ -720,7 +720,7 @@ public class ServerUserSessionTest {
     UserDto user = db.users().insertUser();
     ComponentDto privateProject = db.components().insertPrivateProject();
     ComponentDto branch = db.components().insertProjectBranch(privateProject, b -> b.setKey("feature/foo"));
-    ComponentDto fileInBranch = db.components().insertComponent(newChildComponent("fileUuid", branch, branch));
+    ComponentDto fileInBranch = db.components().insertComponent(newChildComponent("fileUuid", branch, branch).setMainBranchProjectUuid(privateProject.uuid()));
 
     // permissions are defined on the project, not on the branch
     db.users().insertProjectPermissionOnUser(user, "p1", privateProject);
index 207f38d9443f75192039c4f35395d01cfb2b69e4..45875acdbc924bc8133dd86452496fc4d579128a 100644 (file)
@@ -46,9 +46,9 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
     ComponentDto project2 = ComponentTesting.newPrivateProjectDto("EFGH");
 
     indexIssues(
-      IssueDocTesting.newDoc("I1", project.uuid(), ComponentTesting.newFileDto(project, null)).setEffort(10L),
-      IssueDocTesting.newDoc("I2", project.uuid(), ComponentTesting.newFileDto(project, null)).setEffort(10L),
-      IssueDocTesting.newDoc("I3", project2.uuid(), ComponentTesting.newFileDto(project2, null)).setEffort(10L));
+      IssueDocTesting.newDoc("I1", project.uuid(), ComponentTesting.newFileDto(project)).setEffort(10L),
+      IssueDocTesting.newDoc("I2", project.uuid(), ComponentTesting.newFileDto(project)).setEffort(10L),
+      IssueDocTesting.newDoc("I3", project2.uuid(), ComponentTesting.newFileDto(project2)).setEffort(10L));
 
     Facets facets = search("projects");
     assertThat(facets.getNames()).containsOnly("projects", FACET_MODE_EFFORT);
@@ -80,8 +80,8 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_directories() {
     ComponentDto project = ComponentTesting.newPrivateProjectDto();
-    ComponentDto file1 = ComponentTesting.newFileDto(project, null).setPath("src/main/xoo/F1.xoo");
-    ComponentDto file2 = ComponentTesting.newFileDto(project, null).setPath("F2.xoo");
+    ComponentDto file1 = ComponentTesting.newFileDto(project).setPath("src/main/xoo/F1.xoo");
+    ComponentDto file2 = ComponentTesting.newFileDto(project).setPath("F2.xoo");
 
     indexIssues(
       IssueDocTesting.newDoc("I1", project.uuid(), file1).setDirectoryPath("/src/main/xoo").setEffort(10L),
@@ -96,7 +96,7 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_severities() {
     ComponentDto project = ComponentTesting.newPrivateProjectDto();
-    ComponentDto file = ComponentTesting.newFileDto(project, null);
+    ComponentDto file = ComponentTesting.newFileDto(project);
 
     indexIssues(
       IssueDocTesting.newDoc("I1", project.uuid(), file).setSeverity(Severity.INFO).setEffort(10L),
@@ -112,7 +112,7 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_statuses() {
     ComponentDto project = ComponentTesting.newPrivateProjectDto();
-    ComponentDto file = ComponentTesting.newFileDto(project, null);
+    ComponentDto file = ComponentTesting.newFileDto(project);
 
     indexIssues(
       IssueDocTesting.newDoc("I1", project.uuid(), file).setStatus(STATUS_CLOSED).setEffort(10L),
@@ -128,7 +128,7 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_resolutions() {
     ComponentDto project = ComponentTesting.newPrivateProjectDto();
-    ComponentDto file = ComponentTesting.newFileDto(project, null);
+    ComponentDto file = ComponentTesting.newFileDto(project);
 
     indexIssues(
       IssueDocTesting.newDoc("I1", project.uuid(), file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE).setEffort(10L),
@@ -144,7 +144,7 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_languages() {
     ComponentDto project = ComponentTesting.newPrivateProjectDto();
-    ComponentDto file = ComponentTesting.newFileDto(project, null);
+    ComponentDto file = ComponentTesting.newFileDto(project);
 
     indexIssues(IssueDocTesting.newDoc("I1", project.uuid(), file).setLanguage("xoo").setEffort(10L));
 
@@ -157,7 +157,7 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_assignees() {
     ComponentDto project = ComponentTesting.newPrivateProjectDto();
-    ComponentDto file = ComponentTesting.newFileDto(project, null);
+    ComponentDto file = ComponentTesting.newFileDto(project);
 
     indexIssues(
       IssueDocTesting.newDoc("I1", project.uuid(), file).setAssigneeUuid("uuid-steph").setEffort(10L),
@@ -174,7 +174,7 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_author() {
     ComponentDto project = ComponentTesting.newPrivateProjectDto();
-    ComponentDto file = ComponentTesting.newFileDto(project, null);
+    ComponentDto file = ComponentTesting.newFileDto(project);
 
     indexIssues(
       IssueDocTesting.newDoc("I1", project.uuid(), file).setAuthorLogin("steph").setEffort(10L),
@@ -204,7 +204,7 @@ public class IssueIndexDebtTest extends IssueIndexTestCommon {
 
   private SearchOptions fixtureForCreatedAtFacet() {
     ComponentDto project = ComponentTesting.newPrivateProjectDto();
-    ComponentDto file = ComponentTesting.newFileDto(project, null);
+    ComponentDto file = ComponentTesting.newFileDto(project);
 
     IssueDoc issue0 = IssueDocTesting.newDoc("ISSUE0", project.uuid(), file).setEffort(10L).setFuncCreationDate(parseDateTime("2011-04-25T01:05:13+0100"));
     IssueDoc issue1 = IssueDocTesting.newDoc("I1", project.uuid(), file).setEffort(10L).setFuncCreationDate(parseDateTime("2014-09-01T12:34:56+0100"));
index 71136ad4b5e90b4c3d3cc2837a0eb97791a82cbb..ad2a99e4568af227181ea7e2001f6ad811c472d0 100644 (file)
@@ -72,9 +72,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
     ComponentDto project2 = newPrivateProjectDto("EFGH");
 
     indexIssues(
-      newDoc("I1", project.uuid(), newFileDto(project, null)),
-      newDoc("I2", project.uuid(), newFileDto(project, null)),
-      newDoc("I3", project2.uuid(), newFileDto(project2, null)));
+      newDoc("I1", project.uuid(), newFileDto(project)),
+      newDoc("I2", project.uuid(), newFileDto(project)),
+      newDoc("I3", project2.uuid(), newFileDto(project2)));
 
     assertThatFacetHasExactly(IssueQuery.builder(), "projects", entry("ABCD", 2L), entry("EFGH", 1L));
   }
@@ -124,8 +124,8 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_directories() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file1 = newFileDto(project, null).setPath("src/main/xoo/F1.xoo");
-    ComponentDto file2 = newFileDto(project, null).setPath("F2.xoo");
+    ComponentDto file1 = newFileDto(project).setPath("src/main/xoo/F1.xoo");
+    ComponentDto file2 = newFileDto(project).setPath("F2.xoo");
 
     indexIssues(
       newDoc("I1", project.uuid(), file1).setDirectoryPath("/src/main/xoo"),
@@ -149,7 +149,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_cwe() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setCwe(asList("20", "564", "89", "943")),
@@ -166,7 +166,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_pciDss32() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setPciDss32(asList("1", "2")),
@@ -182,7 +182,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_pciDss40() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setPciDss40(asList("1", "2")),
@@ -198,7 +198,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_owaspAsvs40() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("1", "2")),
@@ -214,7 +214,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_owaspTop10() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspTop10(asList("a1", "a2")),
@@ -230,7 +230,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_owaspTop10_2021() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspTop10For2021(asList("a1", "a2")),
@@ -246,7 +246,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_owaspTop10_2021_stay_ordered() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspTop10For2021(asList("a1", "a2")),
@@ -262,7 +262,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_sansTop25() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setSansTop25(asList("porous-defenses", "risky-resource", "insecure-interaction")),
@@ -278,7 +278,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_sonarSourceSecurity() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setSonarSourceSecurityCategory(SQCategory.BUFFER_OVERFLOW),
@@ -293,7 +293,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_severities() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setSeverity(INFO),
@@ -306,7 +306,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facet_on_severities_return_5_entries_max() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I2", project.uuid(), file).setSeverity(INFO),
@@ -322,7 +322,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_statuses() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setStatus(STATUS_CLOSED),
@@ -335,7 +335,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facet_on_statuses_return_5_entries_max() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setStatus(STATUS_OPEN),
@@ -351,7 +351,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_resolutions() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setResolution(RESOLUTION_FALSE_POSITIVE),
@@ -364,7 +364,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_resolutions_return_5_entries_max() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setResolution(RESOLUTION_FIXED),
@@ -379,7 +379,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_languages() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
     RuleDto ruleDefinitionDto = newRule();
     db.rules().insert(ruleDefinitionDto);
 
@@ -391,9 +391,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_languages_return_100_entries_plus_selected_values() {
     ComponentDto project = newPrivateProjectDto();
-    indexIssues(rangeClosed(1, 100).mapToObj(i -> newDoc(newFileDto(project, null), project.uuid()).setLanguage("a" + i)).toArray(IssueDoc[]::new));
-    IssueDoc issue1 = newDoc(newFileDto(project, null), project.uuid()).setLanguage("language1");
-    IssueDoc issue2 = newDoc(newFileDto(project, null), project.uuid()).setLanguage("language2");
+    indexIssues(rangeClosed(1, 100).mapToObj(i -> newDoc(newFileDto(project), project.uuid()).setLanguage("a" + i)).toArray(IssueDoc[]::new));
+    IssueDoc issue1 = newDoc(newFileDto(project), project.uuid()).setLanguage("language1");
+    IssueDoc issue2 = newDoc(newFileDto(project), project.uuid()).setLanguage("language2");
     indexIssues(issue1, issue2);
 
     assertThatFacetHasSize(IssueQuery.builder().build(), "languages", 100);
@@ -403,7 +403,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_assignees() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setAssigneeUuid("steph-uuid"),
@@ -417,9 +417,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_assignees_return_only_100_entries_plus_selected_values() {
     ComponentDto project = newPrivateProjectDto();
-    indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, null), project.uuid()).setAssigneeUuid("a" + i)).toArray(IssueDoc[]::new));
-    IssueDoc issue1 = newDoc(newFileDto(project, null), project.uuid()).setAssigneeUuid("user1");
-    IssueDoc issue2 = newDoc(newFileDto(project, null), project.uuid()).setAssigneeUuid("user2");
+    indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project), project.uuid()).setAssigneeUuid("a" + i)).toArray(IssueDoc[]::new));
+    IssueDoc issue1 = newDoc(newFileDto(project), project.uuid()).setAssigneeUuid("user1");
+    IssueDoc issue2 = newDoc(newFileDto(project), project.uuid()).setAssigneeUuid("user2");
     indexIssues(issue1, issue2);
 
     assertThatFacetHasSize(IssueQuery.builder().build(), "assignees", 100);
@@ -429,7 +429,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_assignees_supports_dashes() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setAssigneeUuid("j-b-uuid"),
@@ -444,7 +444,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_author() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setAuthorLogin("steph"),
@@ -458,9 +458,9 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
   @Test
   public void facets_on_authors_return_100_entries_plus_selected_values() {
     ComponentDto project = newPrivateProjectDto();
-    indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, null), project.uuid()).setAuthorLogin("a" + i)).toArray(IssueDoc[]::new));
-    IssueDoc issue1 = newDoc(newFileDto(project, null), project.uuid()).setAuthorLogin("user1");
-    IssueDoc issue2 = newDoc(newFileDto(project, null), project.uuid()).setAuthorLogin("user2");
+    indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project), project.uuid()).setAuthorLogin("a" + i)).toArray(IssueDoc[]::new));
+    IssueDoc issue1 = newDoc(newFileDto(project), project.uuid()).setAuthorLogin("user1");
+    IssueDoc issue2 = newDoc(newFileDto(project), project.uuid()).setAuthorLogin("user2");
     indexIssues(issue1, issue2);
 
     assertThatFacetHasSize(IssueQuery.builder().build(), "author", 100);
@@ -646,7 +646,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon {
 
   private SearchOptions fixtureForCreatedAtFacet() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     IssueDoc issue0 = newDoc("ISSUE0", project.uuid(), file).setFuncCreationDate(parseDateTime("2011-04-25T00:05:13+0000"));
     IssueDoc issue1 = newDoc("I1", project.uuid(), file).setFuncCreationDate(parseDateTime("2014-09-01T10:34:56+0000"));
index 72753048a65cc60a556062b9c336733d303f01ff..a608ff5e98526570ce0d9c5fc470b22b8f366106 100644 (file)
@@ -56,8 +56,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto project = newPrivateProjectDto();
 
     indexIssues(
-      newDoc("I1", project.uuid(), newFileDto(project, null)),
-      newDoc("I2", project.uuid(), newFileDto(project, null)));
+      newDoc("I1", project.uuid(), newFileDto(project)),
+      newDoc("I2", project.uuid(), newFileDto(project)));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().issueKeys(asList("I1", "I2")), "I1", "I2");
     assertThatSearchReturnsOnly(IssueQuery.builder().issueKeys(singletonList("I1")), "I1");
@@ -70,7 +70,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
 
     indexIssues(
       newDocForProject("I1", project),
-      newDoc("I2", project.uuid(), newFileDto(project, null)));
+      newDoc("I2", project.uuid(), newFileDto(project)));
 
     assertThatSearchReturnsOnly(IssueQuery.builder().projectUuids(singletonList(project.uuid())), "I1", "I2");
     assertThatSearchReturnsEmpty(IssueQuery.builder().projectUuids(singletonList("unknown")));
@@ -79,7 +79,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_components_on_contextualized_search() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file1 = newFileDto(project, null);
+    ComponentDto file1 = newFileDto(project);
     String view = "ABCD";
     indexView(view, singletonList(project.uuid()));
 
@@ -115,8 +115,8 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_directories() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file1 = newFileDto(project, null).setPath("src/main/xoo/F1.xoo");
-    ComponentDto file2 = newFileDto(project, null).setPath("F2.xoo");
+    ComponentDto file1 = newFileDto(project).setPath("src/main/xoo/F1.xoo");
+    ComponentDto file2 = newFileDto(project).setPath("F2.xoo");
 
     indexIssues(
       newDoc("I1", project.uuid(), file1).setDirectoryPath("/src/main/xoo"),
@@ -155,7 +155,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_portfolios_not_having_projects() {
     ComponentDto project1 = newPrivateProjectDto();
-    ComponentDto file1 = newFileDto(project1, null);
+    ComponentDto file1 = newFileDto(project1);
     indexIssues(newDoc("I2", project1.uuid(), file1));
     String view1 = "ABCD";
     indexView(view1, emptyList());
@@ -209,7 +209,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto project = db.components().insertPrivateProject();
     ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
-    ComponentDto branchFile = db.components().insertComponent(newFileDto(branch));
+    ComponentDto branchFile = db.components().insertComponent(newFileDto(branch, project.uuid())).setMainBranchProjectUuid(project.uuid());
 
     indexIssues(
       newDocForProject("I1", project),
@@ -308,7 +308,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch2"));
     ComponentDto project1 = db.components().insertPrivateProject(p -> p.setKey("prj1"));
     ComponentDto project1Branch1 = db.components().insertProjectBranch(project1);
-    ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1));
+    ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1)).setMainBranchProjectUuid(project1.uuid());
     ComponentDto project1Branch2 = db.components().insertProjectBranch(project1);
     ComponentDto project2 = db.components().insertPrivateProject(p -> p.setKey("prj2"));
     indexView(applicationBranch1.uuid(), asList(project1Branch1.uuid(), project2.uuid()));
@@ -471,7 +471,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_severities() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setSeverity(Severity.INFO),
@@ -485,7 +485,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_statuses() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setStatus(Issue.STATUS_CLOSED),
@@ -499,7 +499,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_resolutions() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE),
@@ -513,7 +513,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_resolved() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED),
@@ -528,7 +528,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_rules() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
     RuleDto ruleDefinitionDto = newRule();
     db.rules().insert(ruleDefinitionDto);
 
@@ -541,7 +541,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_languages() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
     RuleDto ruleDefinitionDto = newRule();
     db.rules().insert(ruleDefinitionDto);
 
@@ -554,7 +554,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_assignees() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setAssigneeUuid("steph-uuid"),
@@ -569,7 +569,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_assigned() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setAssigneeUuid("steph-uuid"),
@@ -584,7 +584,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_authors() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setAuthorLogin("steph"),
@@ -599,7 +599,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_created_after() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setFuncCreationDate(parseDate("2014-09-20")),
@@ -615,7 +615,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_created_before() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setFuncCreationDate(parseDate("2014-09-20")),
@@ -631,7 +631,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_created_after_and_before() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setFuncCreationDate(parseDate("2014-09-20")),
@@ -671,7 +671,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_created_after_and_before_take_into_account_timezone() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setFuncCreationDate(parseDateTime("2014-09-20T00:00:00+0100")),
@@ -715,7 +715,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_created_at() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(newDoc("I1", project.uuid(), file).setFuncCreationDate(parseDate("2014-09-20")));
 
@@ -726,7 +726,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_new_code_reference() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(newDoc("I1", project.uuid(), file).setIsNewCodeReference(true),
       newDoc("I2", project.uuid(), file).setIsNewCodeReference(false));
@@ -737,7 +737,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_cwe() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setCwe(asList("20", "564", "89", "943")),
@@ -750,7 +750,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_owaspAsvs40_category() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("1.1.1", "1.2.2", "2.2.2")),
@@ -765,7 +765,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_owaspAsvs40_specific_requirement() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("1.1.1", "1.2.2", "2.2.2")),
@@ -780,7 +780,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_owaspAsvs40_level() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspAsvs40(asList("2.1.1", "1.1.1", "1.11.3")),
@@ -802,7 +802,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_owaspTop10() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setOwaspTop10(asList("a1", "a2")),
@@ -815,7 +815,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_sansTop25() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setSansTop25(asList("porous-defenses", "risky-resource", "insecure-interaction")),
@@ -828,7 +828,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_sonarSecurity() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(RuleType.VULNERABILITY).setSonarSourceSecurityCategory(SQCategory.BUFFER_OVERFLOW),
index 40d490b31c92dad7fc41bf91b1fac5394181bc6a..285715bd3bf64008044d25daf03f83719928d4af 100644 (file)
@@ -50,7 +50,7 @@ public class IssueIndexSecurityHotspotsTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_security_hotspots_type() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setType(BUG),
@@ -68,7 +68,7 @@ public class IssueIndexSecurityHotspotsTest extends IssueIndexTestCommon {
   @Test
   public void filter_by_severities_ignore_hotspots() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setSeverity(Severity.INFO).setType(BUG),
@@ -86,7 +86,7 @@ public class IssueIndexSecurityHotspotsTest extends IssueIndexTestCommon {
   @Test
   public void facet_on_severities_ignore_hotspots() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setSeverity(INFO).setType(BUG),
index db984cdb381ee92a0978f498c66fd01ecbaa2c81..9caf4bffb7cb77e05ee2ca416cdf193403816da0 100644 (file)
@@ -36,7 +36,7 @@ public class IssueIndexSortTest extends IssueIndexTestCommon {
   @Test
   public void sort_by_status() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setStatus(Issue.STATUS_OPEN),
@@ -53,7 +53,7 @@ public class IssueIndexSortTest extends IssueIndexTestCommon {
   @Test
   public void sort_by_severity() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setSeverity(Severity.BLOCKER),
@@ -72,7 +72,7 @@ public class IssueIndexSortTest extends IssueIndexTestCommon {
   @Test
   public void sort_by_creation_date() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
@@ -89,7 +89,7 @@ public class IssueIndexSortTest extends IssueIndexTestCommon {
   @Test
   public void sort_by_update_date() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setFuncUpdateDate(parseDateTime("2014-09-23T00:00:00+0100")),
@@ -106,7 +106,7 @@ public class IssueIndexSortTest extends IssueIndexTestCommon {
   @Test
   public void sort_by_close_date() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
 
     indexIssues(
       newDoc("I1", project.uuid(), file).setFuncCloseDate(parseDateTime("2014-09-23T00:00:00+0100")),
index bac4e99a5886230298fd815ccb348b4869d1a390..6eb1fc47d7f46bcc408f8a3435b7754ebee884a4 100644 (file)
@@ -53,7 +53,7 @@ public class IssueIndexTest extends IssueIndexTestCommon {
   @Test
   public void paging() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
     for (int i = 0; i < 12; i++) {
       indexIssues(newDoc("I" + i, project.uuid(), file));
     }
@@ -76,7 +76,7 @@ public class IssueIndexTest extends IssueIndexTestCommon {
   @Test
   public void search_with_max_limit() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
     List<IssueDoc> issues = new ArrayList<>();
     for (int i = 0; i < 500; i++) {
       String key = "I" + i;
@@ -93,7 +93,7 @@ public class IssueIndexTest extends IssueIndexTestCommon {
   @Test
   public void search_exceeding_default_index_max_window() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
     List<IssueDoc> issues = new ArrayList<>();
     for (int i = 0; i < 11_000; i++) {
       String key = "I" + i;
@@ -111,7 +111,7 @@ public class IssueIndexTest extends IssueIndexTestCommon {
   @Test
   public void search_nine_issues_with_same_creation_date_sorted_by_creation_date_order_is_sorted_also_by_key() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
     List<IssueDoc> issues = new ArrayList<>();
     // we are adding issues in reverse order to see if the sort is actually doing anything
     for (int i = 9; i >= 1; i--) {
@@ -132,7 +132,7 @@ public class IssueIndexTest extends IssueIndexTestCommon {
   @Test
   public void search_nine_issues_5_times_with_same_creation_date_sorted_by_creation_date_returned_issues_same_order() {
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
     List<IssueDoc> issues = new ArrayList<>();
     // we are adding issues in reverse order to see if the sort is actually doing anything
     for (int i = 9; i >= 1; i--) {
@@ -160,9 +160,9 @@ public class IssueIndexTest extends IssueIndexTestCommon {
     ComponentDto project1 = newPrivateProjectDto();
     ComponentDto project2 = newPrivateProjectDto();
     ComponentDto project3 = newPrivateProjectDto();
-    ComponentDto file1 = newFileDto(project1, null);
-    ComponentDto file2 = newFileDto(project2, null);
-    ComponentDto file3 = newFileDto(project3, null);
+    ComponentDto file1 = newFileDto(project1);
+    ComponentDto file2 = newFileDto(project2);
+    ComponentDto file3 = newFileDto(project3);
     GroupDto group1 = newGroupDto();
     GroupDto group2 = newGroupDto();
 
@@ -197,9 +197,9 @@ public class IssueIndexTest extends IssueIndexTestCommon {
     ComponentDto project1 = newPrivateProjectDto();
     ComponentDto project2 = newPrivateProjectDto();
     ComponentDto project3 = newPrivateProjectDto();
-    ComponentDto file1 = newFileDto(project1, null);
-    ComponentDto file2 = newFileDto(project2, null);
-    ComponentDto file3 = newFileDto(project3, null);
+    ComponentDto file1 = newFileDto(project1);
+    ComponentDto file2 = newFileDto(project2);
+    ComponentDto file3 = newFileDto(project3);
     UserDto user1 = newUserDto();
     UserDto user2 = newUserDto();
 
@@ -228,7 +228,7 @@ public class IssueIndexTest extends IssueIndexTestCommon {
     RuleDto r2 = db.rules().insert();
     ruleIndexer.commitAndIndex(db.getSession(), asList(r1.getUuid(), r2.getUuid()));
     ComponentDto project = newPrivateProjectDto();
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
     indexIssues(
       newDoc("I42", project.uuid(), file).setRuleUuid(r1.getUuid()).setTags(of("another")),
       newDoc("I1", project.uuid(), file).setRuleUuid(r1.getUuid()).setTags(of("convention", "java8", "bug")),
index 7f0c3568a45b52453b276f003beb87ecddfdeef7..ddbdef82183b1e5a00394fa76e78bc772a47ab88 100644 (file)
@@ -465,7 +465,7 @@ public class IssueQueryFactoryTest {
     ComponentDto project = db.components().insertPrivateProject();
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
 
     assertThat(underTest.create(new SearchRequest()
       .setComponents(singletonList(file.getKey()))
@@ -493,7 +493,7 @@ public class IssueQueryFactoryTest {
     ComponentDto project = db.components().insertPrivateProject();
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
 
     assertThat(underTest.create(new SearchRequest()
       .setComponents(singletonList(file.getKey()))
@@ -546,7 +546,7 @@ public class IssueQueryFactoryTest {
     ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey(branchName2));
     ComponentDto project1 = db.components().insertPrivateProject(p -> p.setKey("prj1"));
     ComponentDto project1Branch1 = db.components().insertProjectBranch(project1);
-    db.components().insertComponent(newFileDto(project1Branch1));
+    db.components().insertComponent(newFileDto(project1Branch1, project1.uuid()));
     ComponentDto project1Branch2 = db.components().insertProjectBranch(project1);
     ComponentDto project2 = db.components().insertPrivateProject(p -> p.setKey("prj2"));
     db.components().insertComponents(newProjectCopy(project1Branch1, applicationBranch1));
index ee7072004022ae353c2329e3e5cd998bb0bdf2c8..d173fa151e7dada6ab4507db3523ccea85d016f6 100644 (file)
@@ -91,7 +91,7 @@ public class ProjectDataLoaderIT {
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
     userSession.logIn().addProjectPermission(SCAN.getKey(), project);
     // File on branch
-    ComponentDto projectFile = db.components().insertComponent(newFileDto(branch));
+    ComponentDto projectFile = db.components().insertComponent(newFileDto(branch, project.uuid()));
     dbClient.fileSourceDao().insert(dbSession, newFileSourceDto(projectFile).setSrcHash("123456"));
     dbSession.commit();
 
@@ -128,7 +128,7 @@ public class ProjectDataLoaderIT {
   public void fails_with_BRE_if_component_is_not_root() {
     String uuid = "uuid";
     String key = "key";
-    dbClient.componentDao().insert(dbSession, new ComponentDto()
+    dbClient.componentDao().insertOnMainBranch(dbSession, new ComponentDto()
       .setUuid(uuid)
       .setUuidPath(uuid + ".")
       .setBranchUuid("branchUuid")
index 552b0d0b865fbae3af38a682caceb13f878f0b9f..d88faef09c023727a592c1f738c00ebe9addaf31 100644 (file)
@@ -603,7 +603,10 @@ public class ActivityActionIT {
   private CeQueueDto insertQueue(String taskUuid, @Nullable ComponentDto project, CeQueueDto.Status status) {
     CeQueueDto queueDto = new CeQueueDto();
     queueDto.setTaskType(CeTaskTypes.REPORT);
-    queueDto.setComponent(project);
+    if (project != null ) {
+      queueDto.setComponentUuid(project.uuid());
+      queueDto.setMainComponentUuid(project.uuid());
+    }
     queueDto.setUuid(taskUuid);
     queueDto.setStatus(status);
     db.getDbClient().ceQueueDao().insert(db.getSession(), queueDto);
@@ -618,7 +621,8 @@ public class ActivityActionIT {
   private CeActivityDto insertActivity(String taskUuid, ComponentDto project, Status status, @Nullable SnapshotDto analysis) {
     CeQueueDto queueDto = new CeQueueDto();
     queueDto.setTaskType(CeTaskTypes.REPORT);
-    queueDto.setComponent(project);
+    queueDto.setComponentUuid(project.uuid());
+    queueDto.setMainComponentUuid(project.uuid());
     queueDto.setUuid(taskUuid);
     queueDto.setCreatedAt(EXECUTED_AT);
     CeActivityDto activityDto = new CeActivityDto(queueDto);
index 2f1e8e95e912110a18fa3959a84e29bbcc03bb0f..40926311f9b1afbd42d8b8456cdbd4fb26cfd37a 100644 (file)
@@ -172,8 +172,11 @@ public class ActivityStatusActionIT {
 
   private void insertInQueue(CeQueueDto.Status status, @Nullable ComponentDto componentDto, @Nullable Long createdAt) {
     CeQueueDto ceQueueDto = newCeQueueDto(Uuids.createFast())
-      .setStatus(status)
-      .setComponent(componentDto);
+      .setStatus(status);
+    if(componentDto != null) {
+      ceQueueDto.setComponentUuid(componentDto.uuid())
+        .setMainComponentUuid(componentDto.uuid());
+    }
     if (createdAt != null) {
       ceQueueDto.setCreatedAt(createdAt);
     }
@@ -183,7 +186,8 @@ public class ActivityStatusActionIT {
 
   private void insertActivity(CeActivityDto.Status status, @Nullable ComponentDto dto) {
     CeQueueDto ceQueueDto = newCeQueueDto(Uuids.createFast());
-    ceQueueDto.setComponent(dto);
+    ceQueueDto.setComponentUuid(dto.uuid());
+    ceQueueDto.setMainComponentUuid(dto.uuid());
     dbClient.ceActivityDao().insert(dbSession, new CeActivityDto(ceQueueDto)
       .setStatus(status));
     db.commit();
index a66d36fa963b3424ae9f0fe9d517c2466734f0ab..e9289fc9b19f15d8566bc05a5b1d31d7bb2b3aee 100644 (file)
@@ -360,7 +360,8 @@ public class AnalysisStatusActionIT {
   private CeActivityDto insertActivity(String taskUuid, ComponentDto component, CeActivityDto.Status status, @Nullable SnapshotDto analysis, String taskType) {
     CeQueueDto queueDto = new CeQueueDto();
     queueDto.setTaskType(taskType);
-    queueDto.setComponent(component);
+    queueDto.setComponentUuid(component.uuid());
+    queueDto.setMainComponentUuid(component.uuid());
     queueDto.setUuid(taskUuid);
     CeActivityDto activityDto = new CeActivityDto(queueDto);
     activityDto.setStatus(status);
index 52fa6d705169ec6f5bd5ccd8f451bf06e41efb51..e7135a4b9fcec3ac0cd64c860d08b8b1d9691e93 100644 (file)
@@ -304,7 +304,8 @@ public class ComponentActionIT {
   private CeQueueDto insertQueue(String taskUuid, ComponentDto component, CeQueueDto.Status status) {
     CeQueueDto queueDto = new CeQueueDto();
     queueDto.setTaskType(CeTaskTypes.REPORT);
-    queueDto.setComponent(component);
+    queueDto.setComponentUuid(component.uuid());
+    queueDto.setMainComponentUuid(component.uuid());
     queueDto.setUuid(taskUuid);
     queueDto.setStatus(status);
     db.getDbClient().ceQueueDao().insert(db.getSession(), queueDto);
@@ -319,7 +320,8 @@ public class ComponentActionIT {
   private CeActivityDto insertActivity(String taskUuid, ComponentDto component, CeActivityDto.Status status, @Nullable SnapshotDto analysis) {
     CeQueueDto queueDto = new CeQueueDto();
     queueDto.setTaskType(CeTaskTypes.REPORT);
-    queueDto.setComponent(component);
+    queueDto.setComponentUuid(component.uuid());
+    queueDto.setMainComponentUuid(component.uuid());
     queueDto.setUuid(taskUuid);
     CeActivityDto activityDto = new CeActivityDto(queueDto);
     activityDto.setStatus(status);
index a058e511afe88a4d0bacfc5ef6fa686481bcc2c1..5b0bfa1c04b2f5b03869a1eb41ad2f1b52f54b09 100644 (file)
@@ -192,7 +192,8 @@ public class DismissAnalysisWarningActionIT {
   private CeActivityDto insertActivity(String taskUuid, ComponentDto component, CeActivityDto.Status status, @Nullable SnapshotDto analysis, String taskType) {
     CeQueueDto queueDto = new CeQueueDto();
     queueDto.setTaskType(taskType);
-    queueDto.setComponent(component);
+    queueDto.setComponentUuid(component.uuid());
+    queueDto.setComponentUuid(component.uuid());
     queueDto.setUuid(taskUuid);
     CeActivityDto activityDto = new CeActivityDto(queueDto);
     activityDto.setStatus(status);
index cba4c4d9ef610f14132b5f5f02edbb3d75dd2ae8..51fca49833f09431ead135fb601db6d16f8a8c8b 100644 (file)
@@ -183,8 +183,8 @@ public class ComponentCleanerServiceIT {
     mockResourceTypeAsValidProject();
     ComponentDto project = ComponentTesting.newPrivateProjectDto();
     db.components().insertComponent(project);
-    ComponentDto file = newFileDto(project, null);
-    dbClient.componentDao().insert(dbSession, file);
+    ComponentDto file = newFileDto(project);
+    dbClient.componentDao().insertOnMainBranch(dbSession, file);
     dbSession.commit();
 
     assertThatThrownBy(() -> underTest.delete(dbSession, file))
index b197932ea8ccdf83ac3dd09656b0fb11d52cafdb..2451aa92693259f97e8d7f8023b4973533d03a27 100644 (file)
@@ -152,7 +152,7 @@ public class ComponentFinderIT {
     ComponentDto project = db.components().insertPublicProject();
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
     ComponentDto directory = db.components().insertComponent(newDirectory(branch, "scr"));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
 
     assertThat(underTest.getByKeyAndBranch(dbSession, project.getKey(), "my_branch").uuid()).isEqualTo(branch.uuid());
     assertThat(underTest.getByKeyAndBranch(dbSession, file.getKey(), "my_branch").uuid()).isEqualTo(file.uuid());
@@ -164,7 +164,7 @@ public class ComponentFinderIT {
     ComponentDto project = db.components().insertPublicProject();
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST).setMergeBranchUuid(project.uuid()));
     ComponentDto directory = db.components().insertComponent(newDirectory(branch, "scr"));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
 
     assertThat(underTest.getByKeyAndOptionalBranchOrPullRequest(dbSession, project.getKey(), null, "pr-123").uuid()).isEqualTo(branch.uuid());
     assertThat(underTest.getByKeyAndOptionalBranchOrPullRequest(dbSession, file.getKey(), null, "pr-123").uuid()).isEqualTo(file.uuid());
@@ -176,7 +176,7 @@ public class ComponentFinderIT {
     ComponentDto project = db.components().insertPublicProject();
     ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setKey("pr").setBranchType(PULL_REQUEST));
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
-    ComponentDto branchFile = db.components().insertComponent(newFileDto(branch));
+    ComponentDto branchFile = db.components().insertComponent(newFileDto(branch, project.uuid()));
 
     assertThat(underTest.getOptionalByKeyAndOptionalBranchOrPullRequest(dbSession, project.getKey(), null, null)).isPresent();
     assertThat(underTest.getOptionalByKeyAndOptionalBranchOrPullRequest(dbSession, project.getKey(), null, null).get().uuid())
@@ -219,7 +219,7 @@ public class ComponentFinderIT {
   public void fail_to_get_by_key_and_branch_when_branch_does_not_exist() {
     ComponentDto project = db.components().insertPrivateProject();
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
 
     String fileKey = file.getKey();
     assertThatThrownBy(() -> underTest.getByKeyAndBranch(dbSession, fileKey, "other_branch"))
index 82a5d63698ce29ad08b539a3b94696e9d92ca8c8..120d3aa307a93328bf4c29276d31fd75784bdd1d 100644 (file)
@@ -64,8 +64,8 @@ public class ComponentServiceUpdateKeyIT {
   @Test
   public void update_project_key() {
     ComponentDto project = insertSampleProject();
-    ComponentDto file = componentDb.insertComponent(ComponentTesting.newFileDto(project, null).setKey("sample:root:src/File.xoo"));
-    ComponentDto inactiveFile = componentDb.insertComponent(ComponentTesting.newFileDto(project, null).setKey("sample:root:src/InactiveFile.xoo").setEnabled(false));
+    ComponentDto file = componentDb.insertComponent(ComponentTesting.newFileDto(project).setKey("sample:root:src/File.xoo"));
+    ComponentDto inactiveFile = componentDb.insertComponent(ComponentTesting.newFileDto(project).setKey("sample:root:src/InactiveFile.xoo").setEnabled(false));
 
     dbSession.commit();
 
index 55c94ada8c6be6d6f74c8b7e2f699c2a45064aaa..e25d24bb21709c9fa40e1b871572bf4af2f86355 100644 (file)
@@ -255,7 +255,7 @@ public class AppActionIT {
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
     ComponentDto directory = db.components().insertComponent(newDirectory(branch, "src"));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch, directory));
+    ComponentDto file = db.components().insertComponent(newFileDto(project.uuid(), branch, directory));
     MetricDto coverage = db.measures().insertMetric(m -> m.setKey(COVERAGE_KEY));
     db.measures().insertLiveMeasure(file, coverage, m -> m.setValue(95.4d));
 
@@ -297,7 +297,7 @@ public class AppActionIT {
     userSession.logIn("john").addProjectPermission(USER, project);
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
 
     String result = ws.newRequest()
       .setParam("component", file.getKey())
@@ -327,7 +327,7 @@ public class AppActionIT {
     userSession.logIn("john").addProjectPermission(USER, project);
     String pullRequestKey = RandomStringUtils.randomAlphanumeric(100);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
 
     String result = ws.newRequest()
       .setParam("component", file.getKey())
@@ -356,7 +356,7 @@ public class AppActionIT {
     ComponentDto project = db.components().insertPrivateProject();
     userSession.logIn("john").addProjectPermission(USER, project);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
 
     TestRequest request = ws.newRequest()
       .setParam("component", file.getKey())
@@ -382,7 +382,7 @@ public class AppActionIT {
   public void fail_when_branch_not_found() {
     ComponentDto project = db.components().insertPrivateProject();
     ComponentDto branch = db.components().insertProjectBranch(project);
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
 
     TestRequest request = ws.newRequest()
       .setParam("component", file.getKey())
index f220a69a53897bbb7977f5a287f1a7c0250198c6..f05a85e99d810c709d727b2c6012d77379f280b7 100644 (file)
@@ -52,6 +52,7 @@ import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.BranchType.BRANCH;
 import static org.sonar.db.component.BranchType.PULL_REQUEST;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
+import static org.sonar.db.component.ComponentTesting.newDirectoryOnBranch;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.db.component.SnapshotTesting.newAnalysis;
@@ -250,8 +251,8 @@ public class ShowActionIT {
     userSession.addProjectPermission(UserRole.USER, project);
     String branchKey = "my_branch";
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchKey));
-    ComponentDto directory = db.components().insertComponent(newDirectory(branch, "dir"));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch, directory));
+    ComponentDto directory = db.components().insertComponent(newDirectoryOnBranch(branch, "dir", project.uuid()));
+    ComponentDto file = db.components().insertComponent(newFileDto(project.uuid(), branch, directory));
     db.components().insertSnapshot(branch, s -> s.setProjectVersion("1.1"));
 
     ShowWsResponse response = ws.newRequest()
@@ -289,8 +290,8 @@ public class ShowActionIT {
     userSession.addProjectPermission(UserRole.USER, project);
     String pullRequest = "pr-1234";
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(pullRequest).setBranchType(PULL_REQUEST));
-    ComponentDto directory = db.components().insertComponent(newDirectory(branch, "dir"));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch, directory));
+    ComponentDto directory = db.components().insertComponent(newDirectoryOnBranch(branch, "dir", project.uuid()));
+    ComponentDto file = db.components().insertComponent(newFileDto(project.uuid(), branch, directory));
     db.components().insertSnapshot(branch, s -> s.setProjectVersion("1.1"));
 
     ShowWsResponse response = ws.newRequest()
@@ -317,8 +318,8 @@ public class ShowActionIT {
     ComponentDto project1 = db.components().insertPrivateProject();
     ComponentDto branch1 = db.components().insertProjectBranch(project1, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey1)
       .setNeedIssueSync(true));
-    ComponentDto directory = db.components().insertComponent(newDirectory(branch1, "dir"));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch1, directory));
+    ComponentDto directory = db.components().insertComponent(newDirectoryOnBranch(branch1, "dir", project1.uuid()));
+    ComponentDto file = db.components().insertComponent(newFileDto(project1.uuid(), branch1, directory));
 
     ComponentDto project2 = db.components().insertPrivateProject();
     String branchName2 = randomAlphanumeric(248);
@@ -329,8 +330,8 @@ public class ShowActionIT {
     ComponentDto project3 = db.components().insertPrivateProject();
     String pullRequestKey4 = randomAlphanumeric(100);
     ComponentDto branch4 = db.components().insertProjectBranch(project3, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey4).setNeedIssueSync(false));
-    ComponentDto directoryOfBranch4 = db.components().insertComponent(newDirectory(branch4, "dir"));
-    ComponentDto fileOfBranch4 = db.components().insertComponent(newFileDto(branch4, directoryOfBranch4));
+    ComponentDto directoryOfBranch4 = db.components().insertComponent(newDirectoryOnBranch(branch4, "dir", project3.uuid()));
+    ComponentDto fileOfBranch4 = db.components().insertComponent(newFileDto(project3.uuid(), branch4, directoryOfBranch4));
     String branchName5 = randomAlphanumeric(248);
     ComponentDto branch5 = db.components().insertProjectBranch(project3, b -> b.setBranchType(BRANCH).setNeedIssueSync(false).setKey(branchName5));
 
index 9db223da893312e35d8170640e587c55fac67b37..e210a1f8a7f9d0b4e6d9e4d53addfb9a7d6a6337 100644 (file)
@@ -65,6 +65,7 @@ import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.BranchType.PULL_REQUEST;
 import static org.sonar.db.component.ComponentTesting.newChildComponent;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
+import static org.sonar.db.component.ComponentTesting.newDirectoryOnBranch;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.db.component.ComponentTesting.newProjectBranchCopy;
 import static org.sonar.db.component.ComponentTesting.newProjectCopy;
@@ -297,7 +298,7 @@ public class TreeActionIT {
     ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("project-key"));
     ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey(projectBranchName));
     ComponentDto techProjectBranch = db.components().insertComponent(newProjectCopy(projectBranch, applicationBranch)
-      .setKey(applicationBranch.getKey() + project.getKey()));
+      .setKey(applicationBranch.getKey() + project.getKey()).setMainBranchProjectUuid(application.uuid()));
     logInWithBrowsePermission(application);
 
     TreeWsResponse result = ws.newRequest()
@@ -354,8 +355,8 @@ public class TreeActionIT {
     userSession.addProjectPermission(UserRole.USER, project);
     String branchKey = "my_branch";
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchKey));
-    ComponentDto directory = db.components().insertComponent(newDirectory(branch, "dir"));
-    ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(directory));
+    ComponentDto directory = db.components().insertComponent(newDirectoryOnBranch(branch, "dir", project.uuid()));
+    ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(directory, project.uuid()));
 
     TreeWsResponse response = ws.newRequest()
       .setParam(PARAM_COMPONENT, branch.getKey())
@@ -391,8 +392,8 @@ public class TreeActionIT {
     userSession.addProjectPermission(UserRole.USER, project);
     String pullRequestId = "pr-123";
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(pullRequestId).setBranchType(PULL_REQUEST));
-    ComponentDto directory = db.components().insertComponent(newDirectory(branch, "dir"));
-    ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(directory));
+    ComponentDto directory = db.components().insertComponent(newDirectoryOnBranch(branch, "dir", project.uuid()));
+    ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(directory, project.uuid()));
 
     TreeWsResponse response = ws.newRequest()
       .setParam(PARAM_COMPONENT, directory.getKey())
index 8469a0a03545393dff7de943c82b1edeae6282b9..d46f5e6bfc3e2d7dd53499fb6210fdf8fca32c63 100644 (file)
@@ -211,9 +211,9 @@ public class DuplicationsParserIT {
   public void compare_duplications() {
     ComponentDto project1 = db.components().insertPrivateProject();
     ComponentDto project2 = db.components().insertPrivateProject();
-    ComponentDto currentFile = db.components().insertComponent(newFileDto(project1, null));
-    ComponentDto fileOnSameProject = db.components().insertComponent(newFileDto(project1, null));
-    ComponentDto fileOnDifferentProject = db.components().insertComponent(newFileDto(project2, null));
+    ComponentDto currentFile = db.components().insertComponent(newFileDto(project1));
+    ComponentDto fileOnSameProject = db.components().insertComponent(newFileDto(project1));
+    ComponentDto fileOnDifferentProject = db.components().insertComponent(newFileDto(project2));
 
     DuplicationsParser.DuplicationComparator comparator = new DuplicationsParser.DuplicationComparator(currentFile.uuid(), currentFile.branchUuid());
 
@@ -252,8 +252,8 @@ public class DuplicationsParserIT {
     ComponentDto project = db.components().insertPublicProject();
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
-    ComponentDto file1 = db.components().insertComponent(newFileDto(branch));
-    ComponentDto file2 = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file1 = db.components().insertComponent(newFileDto(branch, project.uuid()));
+    ComponentDto file2 = db.components().insertComponent(newFileDto(branch, project.uuid()));
     List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file1, branchName, null,
       format("<duplications>\n" +
         "  <g>\n" +
index b3dd5b79eb385367012e2da23dad8e87dcc8578d..873ac406763ce6b28f2f71c45c28d7796107fc87 100644 (file)
@@ -109,7 +109,7 @@ public class ShowActionIT {
     userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()).setMainBranchProjectUuid(project.uuid()));
     db.measures().insertLiveMeasure(file, dataMetric, m -> m.setData(format("<duplications>\n" +
       "  <g>\n" +
       "    <b s=\"31\" l=\"5\" r=\"%s\"/>\n" +
@@ -162,7 +162,7 @@ public class ShowActionIT {
     userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
     String pullRequestKey = randomAlphanumeric(100);
     ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey));
-    ComponentDto file = db.components().insertComponent(newFileDto(pullRequest));
+    ComponentDto file = db.components().insertComponent(newFileDto(pullRequest, project.uuid()));
     db.measures().insertLiveMeasure(file, dataMetric, m -> m.setData(format("<duplications>\n" +
       "  <g>\n" +
       "    <b s=\"31\" l=\"5\" r=\"%s\"/>\n" +
index 8308c93fda3fa0a515df0e4c3e73882003569aeb..a6b5ad14f8da68f008cc33d17c59eb5d42bd1851 100644 (file)
@@ -206,8 +206,8 @@ public class ShowResponseBuilderIT {
     ComponentDto project = db.components().insertPublicProject();
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
-    ComponentDto file1 = db.components().insertComponent(newFileDto(branch));
-    ComponentDto file2 = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file1 = db.components().insertComponent(newFileDto(branch, project.uuid()));
+    ComponentDto file2 = db.components().insertComponent(newFileDto(branch, project.uuid()));
     List<DuplicationsParser.Block> blocks = newArrayList();
     blocks.add(new DuplicationsParser.Block(newArrayList(
       Duplication.newComponent(file1, 57, 12),
index 25df798fd08c3781c8962a3a2b15c9eaf31f1c6e..57e5e2fcf1fe23a762a008e36e8a47ac22d6923d 100644 (file)
@@ -220,7 +220,7 @@ public class AssignActionIT {
   public void assign_hotspot_to_someone_for_private_project_branch() {
     ComponentDto project = dbTester.components().insertPrivateProject();
     ComponentDto branch = dbTester.components().insertProjectBranch(project);
-    ComponentDto file = dbTester.components().insertComponent(newFileDto(branch));
+    ComponentDto file = dbTester.components().insertComponent(newFileDto(branch, project.uuid()));
     IssueDto hotspot = dbTester.issues().insertHotspot(branch, file);
 
     insertAndLoginAsUserWithProjectUserPermission(randomAlphanumeric(10), project, UserRole.USER);
@@ -254,7 +254,7 @@ public class AssignActionIT {
   public void fail_if_assignee_does_not_have_access_for_private_project_branch() {
     ComponentDto project = dbTester.components().insertPrivateProject();
     ComponentDto branch = dbTester.components().insertProjectBranch(project);
-    ComponentDto file = dbTester.components().insertComponent(newFileDto(branch));
+    ComponentDto file = dbTester.components().insertComponent(newFileDto(branch, project.uuid()));
     IssueDto hotspot = dbTester.issues().insertHotspot(branch, file);
 
     insertAndLoginAsUserWithProjectUserPermission(randomAlphanumeric(10), project, UserRole.USER);
index 271ff6a938c139ad2c5387f6760741a08ad0caea..7201714ab102c314689d93f898f3fca655f5af71 100644 (file)
@@ -108,6 +108,7 @@ import static org.sonar.api.utils.DateUtils.formatDateTime;
 import static org.sonar.api.web.UserRole.USER;
 import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
+import static org.sonar.db.component.ComponentTesting.newDirectoryOnBranch;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.issue.IssueTesting.newCodeReferenceIssue;
 import static org.sonar.db.issue.IssueTesting.newIssue;
@@ -690,8 +691,8 @@ public class SearchActionIT {
     ComponentDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey("branch"));
     ComponentDto pullRequest = dbTester.components().insertProjectBranch(project, t -> t.setBranchType(BranchType.PULL_REQUEST).setKey("prKey"));
     ComponentDto fileProject = dbTester.components().insertComponent(newFileDto(project));
-    ComponentDto fileBranch = dbTester.components().insertComponent(newFileDto(branch));
-    ComponentDto filePR = dbTester.components().insertComponent(newFileDto(pullRequest));
+    ComponentDto fileBranch = dbTester.components().insertComponent(newFileDto(branch, project.uuid()));
+    ComponentDto filePR = dbTester.components().insertComponent(newFileDto(pullRequest, project.uuid()));
     IssueDto[] hotspotProject = IntStream.range(0, 1 + RANDOM.nextInt(10))
       .mapToObj(i -> {
         RuleDto rule = newRule(SECURITY_HOTSPOT);
@@ -1094,8 +1095,8 @@ public class SearchActionIT {
     ComponentDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey(branchName));
     userSessionRule.registerComponents(project, branch);
     indexPermissions();
-    ComponentDto directory = dbTester.components().insertComponent(newDirectory(branch, "donut/acme"));
-    ComponentDto file = dbTester.components().insertComponent(newFileDto(branch));
+    ComponentDto directory = dbTester.components().insertComponent(newDirectoryOnBranch(branch, "donut/acme", project.uuid()));
+    ComponentDto file = dbTester.components().insertComponent(newFileDto(branch, project.uuid()));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto fileHotspot = insertHotspot(branch, file, rule);
     IssueDto dirHotspot = insertHotspot(branch, directory, rule);
@@ -1131,8 +1132,8 @@ public class SearchActionIT {
       .setKey(pullRequestKey));
     userSessionRule.registerComponents(project, pullRequest);
     indexPermissions();
-    ComponentDto directory = dbTester.components().insertComponent(newDirectory(pullRequest, "donut/acme"));
-    ComponentDto file = dbTester.components().insertComponent(newFileDto(pullRequest));
+    ComponentDto directory = dbTester.components().insertComponent(newDirectoryOnBranch(pullRequest, "donut/acme", project.uuid()));
+    ComponentDto file = dbTester.components().insertComponent(newFileDto(pullRequest, project.uuid()));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto fileHotspot = insertHotspot(pullRequest, file, rule);
     IssueDto dirHotspot = insertHotspot(pullRequest, directory, rule);
@@ -1795,7 +1796,7 @@ public class SearchActionIT {
     ComponentDto pr = dbTester.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST).setKey("pr"));
     userSessionRule.registerComponents(project);
     indexPermissions();
-    ComponentDto file = dbTester.components().insertComponent(newFileDto(pr));
+    ComponentDto file = dbTester.components().insertComponent(newFileDto(pr, project.uuid()));
     dbTester.components().insertSnapshot(project, t -> t.setPeriodDate(referenceDate).setLast(true));
     dbTester.components().insertSnapshot(pr, t -> t.setPeriodDate(null).setLast(true));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
index 3d42866a10235401344b201dc9536a17f23c022c..51720ba03dd6321a7cfa7847dcff695fcb7f67b6 100644 (file)
@@ -917,7 +917,7 @@ public class ShowActionIT {
     ComponentDto project = dbTester.components().insertPublicProject();
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey(branchName));
-    ComponentDto file = dbTester.components().insertComponent(newFileDto(branch));
+    ComponentDto file = dbTester.components().insertComponent(newFileDto(branch, project.uuid()));
     userSessionRule.registerComponents(project);
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, branch, file,
index 2a0f523a07d32d7fb38b59243ccc128b4990815a..0ae3fbfc5ae7c8530197f4550143bf021f4f6b19 100644 (file)
@@ -388,7 +388,7 @@ public class BulkChangeActionIT {
     userSession.logIn(user);
     ComponentDto project = db.components().insertPrivateProject();
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("feature").setBranchType(BranchType.BRANCH));
-    ComponentDto fileOnBranch = db.components().insertComponent(newFileDto(branch));
+    ComponentDto fileOnBranch = db.components().insertComponent(newFileDto(branch, project.uuid()));
     addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
     RuleDto rule = db.rules().insertIssueRule();
     IssueDto issue = db.issues().insertIssue(rule, branch, fileOnBranch, i -> i.setType(BUG)
@@ -425,7 +425,7 @@ public class BulkChangeActionIT {
     userSession.logIn(user);
     ComponentDto project = db.components().insertPrivateProject();
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("feature").setBranchType(branchType));
-    ComponentDto fileOnBranch = db.components().insertComponent(newFileDto(branch));
+    ComponentDto fileOnBranch = db.components().insertComponent(newFileDto(branch, project.uuid()));
     addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
     RuleDto rule = db.rules().insertIssueRule();
     IssueDto issue = db.issues().insertIssue(rule, branch, fileOnBranch, i -> i.setType(BUG)
index fa8bd1182c74471e5de2e5dbaeb59b46b0cc7a35..650ca9ad145d5cef1d7ec5636b5e0274c7001ccc 100644 (file)
@@ -164,7 +164,7 @@ public class IssueUpdaterIT {
     RuleDto rule = db.rules().insertIssueRule();
     ComponentDto project = db.components().insertPublicProject();
     ComponentDto branch = db.components().insertProjectBranch(project, t -> t.setBranchType(BRANCH));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
     DefaultIssue issue = db.issues().insertIssue(rule, branch, file,
       t -> t.setSeverity(MAJOR)).toDefaultIssue();
     UserDto changeAuthor = db.users().insertUser();
@@ -192,7 +192,7 @@ public class IssueUpdaterIT {
     RuleDto rule = db.rules().insertIssueRule();
     ComponentDto project = db.components().insertPublicProject();
     ComponentDto branch = db.components().insertProjectBranch(project, t -> t.setBranchType(BranchType.PULL_REQUEST));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
     DefaultIssue issue = db.issues().insertIssue(rule, branch, file, t -> t.setSeverity(MAJOR)).toDefaultIssue();
     IssueChangeContext context = issueChangeContextByUserBuilder(new Date(), "user_uuid").build();
     issueFieldsSetter.setSeverity(issue, BLOCKER, context);
index f54f69655ec61187d5136f31b4e42ccd30f658cc..8d8585e3f38f5cfbb655e3d35126a1f56eac8d55 100644 (file)
@@ -329,7 +329,7 @@ public class SearchActionComponentsIT {
     ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey(appBranch2));
     ComponentDto project1 = db.components().insertPrivateProject(p -> p.setKey("prj1"));
     ComponentDto project1Branch1 = db.components().insertProjectBranch(project1, b -> b.setKey(proj1branch1));
-    ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1));
+    ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1, project1.uuid()));
     ComponentDto project1Branch2 = db.components().insertProjectBranch(project1, b -> b.setKey(proj1branch2));
     ComponentDto project2 = db.components().insertPrivateProject(p -> p.setKey("prj2"));
     db.components().insertComponents(newProjectCopy(project1Branch1, applicationBranch1));
@@ -531,7 +531,7 @@ public class SearchActionComponentsIT {
 
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
-    ComponentDto branchFile = db.components().insertComponent(newFileDto(branch));
+    ComponentDto branchFile = db.components().insertComponent(newFileDto(branch, project.uuid()));
     IssueDto branchIssue = db.issues().insertIssue(rule, branch, branchFile);
     allowAnyoneOnProjects(project);
     indexIssuesAndViews();
@@ -568,7 +568,7 @@ public class SearchActionComponentsIT {
     IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile);
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
-    ComponentDto branchFile = db.components().insertComponent(newFileDto(branch));
+    ComponentDto branchFile = db.components().insertComponent(newFileDto(branch, project.uuid()));
     IssueDto branchIssue = db.issues().insertIssue(rule, branch, branchFile);
     allowAnyoneOnProjects(project);
     indexIssuesAndViews();
@@ -594,7 +594,7 @@ public class SearchActionComponentsIT {
 
     String pullRequestKey = randomAlphanumeric(100);
     ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey));
-    ComponentDto pullRequestFile = db.components().insertComponent(newFileDto(pullRequest));
+    ComponentDto pullRequestFile = db.components().insertComponent(newFileDto(pullRequest, project.uuid()));
     IssueDto pullRequestIssue = db.issues().insertIssue(rule, pullRequest, pullRequestFile);
     allowAnyoneOnProjects(project);
     indexIssuesAndViews();
@@ -645,7 +645,7 @@ public class SearchActionComponentsIT {
     ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
     IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile);
     ComponentDto branch = db.components().insertProjectBranch(project);
-    ComponentDto branchFile = db.components().insertComponent(newFileDto(branch));
+    ComponentDto branchFile = db.components().insertComponent(newFileDto(branch, project.uuid()));
     IssueDto branchIssue = db.issues().insertIssue(rule, branch, branchFile);
     allowAnyoneOnProjects(project);
     indexIssuesAndViews();
index 527981fe0c730131a6913d880930126e310f1b36..efe286f42f08315bc15d7e74f74aa3d7c022b624 100644 (file)
@@ -555,7 +555,7 @@ public class SearchActionIT {
     RuleDto rule = newIssueRule();
     ComponentDto project = db.components().insertPublicProject("PROJECT_ID", c -> c.setKey("PROJECT_KEY").setKey("PROJECT_KEY"));
     indexPermissions();
-    ComponentDto removedFile = db.components().insertComponent(newFileDto(project, null).setUuid("REMOVED_FILE_ID")
+    ComponentDto removedFile = db.components().insertComponent(newFileDto(project).setUuid("REMOVED_FILE_ID")
       .setKey("REMOVED_FILE_KEY")
       .setEnabled(false));
 
@@ -740,7 +740,7 @@ public class SearchActionIT {
     ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST).setKey("pr"));
     SnapshotDto snapshotDto = db.components().insertSnapshot(pr);
     indexPermissions();
-    ComponentDto file = db.components().insertComponent(newFileDto(pr, null, "FILE_ID").setKey("FILE_KEY"));
+    ComponentDto file = db.components().insertComponent(newFileDto(pr, null, "FILE_ID", project.uuid()).setKey("FILE_KEY"));
     RuleDto rule = newIssueRule();
     IssueDto issue1 = newIssue(rule, pr, file)
       .setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100"))
@@ -861,7 +861,7 @@ public class SearchActionIT {
   @Test
   public void search_by_author() {
     ComponentDto project = db.components().insertPublicProject();
-    ComponentDto file = db.components().insertComponent(newFileDto(project, null));
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
     RuleDto rule = db.rules().insertIssueRule();
     IssueDto issue1 = db.issues().insertIssue(rule, project, file, i -> i.setAuthorLogin("leia"));
     IssueDto issue2 = db.issues().insertIssue(rule, project, file, i -> i.setAuthorLogin("luke"));
index 9bad8f9b3e822bd1806aecbdf48096e230de0ea0..d12e3934ea30cb28c01186db45d73d4be0fac638 100644 (file)
@@ -125,7 +125,7 @@ public class ComponentActionIT {
     String branchName = "my_branch";
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
     db.components().insertSnapshot(branch);
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
     MetricDto complexity = db.measures().insertMetric(m1 -> m1.setKey("complexity").setValueType("INT"));
     LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
 
@@ -165,7 +165,7 @@ public class ComponentActionIT {
     userSession.addProjectPermission(USER, project);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
     SnapshotDto analysis = db.components().insertSnapshot(branch);
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
     MetricDto complexity = db.measures().insertMetric(m1 -> m1.setKey("complexity").setValueType("INT"));
     LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
 
@@ -188,7 +188,7 @@ public class ComponentActionIT {
     userSession.addProjectPermission(USER, project);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
     SnapshotDto analysis = db.components().insertSnapshot(branch);
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
     MetricDto bugs = db.measures().insertMetric(m1 -> m1.setKey("bugs").setValueType("INT"));
     MetricDto newBugs = db.measures().insertMetric(m1 -> m1.setKey("new_bugs").setValueType("INT"));
     MetricDto violations = db.measures().insertMetric(m1 -> m1.setKey("violations").setValueType("INT"));
@@ -225,7 +225,7 @@ public class ComponentActionIT {
     userSession.addProjectPermission(USER, project);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
     SnapshotDto analysis = db.components().insertSnapshot(branch);
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
     MetricDto bugs = db.measures().insertMetric(m1 -> m1.setKey("bugs").setOptimizedBestValue(false).setValueType("INT"));
     MetricDto newBugs = db.measures().insertMetric(m1 -> m1.setKey("new_bugs").setOptimizedBestValue(false).setValueType("INT"));
 
index 21ab3a5734d9485500c6faafa7e5a19e43f1dbf8..bdf477370432d57ae2e35f20e9788871174dc13c 100644 (file)
@@ -122,14 +122,14 @@ public class ComponentTreeActionIT {
     SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime())
       .setPeriodMode("previous_version")
       .setPeriodParam("1.0-SNAPSHOT"));
-    ComponentDto file1 = db.components().insertComponent(newFileDto(project, null)
+    ComponentDto file1 = db.components().insertComponent(newFileDto(project)
       .setUuid("AVIwDXE-bJbJqrw6wFv5")
       .setKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/ElementImpl.java")
       .setName("ElementImpl.java")
       .setLanguage("java")
       .setQualifier(FILE)
       .setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java"));
-    ComponentDto file2 = db.components().insertComponent(newFileDto(project, null)
+    ComponentDto file2 = db.components().insertComponent(newFileDto(project)
       .setUuid("AVIwDXE_bJbJqrw6wFwJ")
       .setKey("com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java")
       .setName("ElementImplTest.java")
@@ -269,7 +269,7 @@ public class ComponentTreeActionIT {
     ComponentDto project = db.components().insertPrivateProject();
     db.components().insertSnapshot(project);
     userSession.anonymous().addProjectPermission(USER, project);
-    ComponentDto file = newFileDto(project, null);
+    ComponentDto file = newFileDto(project);
     db.components().insertComponent(file);
 
     MetricDto matchingBestValue = db.measures().insertMetric(m -> m
@@ -506,7 +506,7 @@ public class ComponentTreeActionIT {
     ComponentDto project = db.components().insertPrivateProject();
     userSession.addProjectPermission(USER, project);
     db.components().insertSnapshot(project);
-    db.components().insertComponent(newFileDto(project, null));
+    db.components().insertComponent(newFileDto(project));
     insertNclocMetric();
 
     ComponentTreeWsResponse result = ws.newRequest()
@@ -526,7 +526,7 @@ public class ComponentTreeActionIT {
     String branchName = "my-branch";
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
     db.components().insertSnapshot(branch);
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
     MetricDto complexity = db.measures().insertMetric(m -> m.setValueType(INT.name()));
     LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
 
@@ -563,9 +563,9 @@ public class ComponentTreeActionIT {
   @Test
   public void show_branch_on_empty_response_if_not_main_branch() {
     ComponentDto mainProjectBranch = db.components().insertPrivateProject();
-    ComponentDto project = db.components().insertProjectBranch(mainProjectBranch, b -> b.setKey("develop"));
+    ComponentDto branch = db.components().insertProjectBranch(mainProjectBranch, b -> b.setKey("develop"));
     userSession.addProjectPermission(USER, mainProjectBranch);
-    ComponentDto file = db.components().insertComponent(newFileDto(project));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, mainProjectBranch.uuid()));
     MetricDto complexity = db.measures().insertMetric(m -> m.setValueType(INT.name()));
 
     ComponentTreeWsResponse response = ws.newRequest()
@@ -584,7 +584,7 @@ public class ComponentTreeActionIT {
     userSession.addProjectPermission(USER, project);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
     SnapshotDto analysis = db.components().insertSnapshot(branch);
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()).setMainBranchProjectUuid(project.uuid()));
     MetricDto complexity = db.measures().insertMetric(m -> m.setValueType(INT.name()));
     LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
 
@@ -607,7 +607,7 @@ public class ComponentTreeActionIT {
     userSession.addProjectPermission(USER, project);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
     SnapshotDto analysis = db.components().insertSnapshot(branch);
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
     MetricDto bug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.BUGS_KEY));
     MetricDto newBug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.NEW_BUGS_KEY));
 
@@ -636,7 +636,7 @@ public class ComponentTreeActionIT {
     userSession.addProjectPermission(USER, project);
     ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setKey("pr").setBranchType(PULL_REQUEST));
     SnapshotDto analysis = db.components().insertSnapshot(pr);
-    ComponentDto file = db.components().insertComponent(newFileDto(pr));
+    ComponentDto file = db.components().insertComponent(newFileDto(pr, project.uuid()));
     MetricDto bug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.BUGS_KEY));
     MetricDto newBug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.NEW_BUGS_KEY));
 
index fa74bf8d2d4e99e738dee3edb2a243b8527dd48d..6488d86ca01c0a2d4ab85e98b8c3259edb515f7e 100644 (file)
@@ -296,7 +296,7 @@ public class SearchHistoryActionIT {
     ComponentDto project = db.components().insertPrivateProject();
     userSession.addProjectPermission(UserRole.USER, project);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
     SnapshotDto analysis = db.components().insertSnapshot(branch);
     MeasureDto measure = db.measures().insertMeasure(file, analysis, nclocMetric, m -> m.setValue(2d));
 
@@ -319,7 +319,7 @@ public class SearchHistoryActionIT {
     ComponentDto project = db.components().insertPrivateProject();
     userSession.addProjectPermission(UserRole.USER, project);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
     SnapshotDto analysis = db.components().insertSnapshot(branch);
     MeasureDto measure = db.measures().insertMeasure(file, analysis, nclocMetric, m -> m.setValue(2d));
 
index acd3ce7a1980beaac3463e5d29a343a51cff1f3d..e613a0fbf1cebc56a8d507e35bcb05fb4cf15f94 100644 (file)
@@ -678,7 +678,8 @@ public class UpdateVisibilityActionIT {
   private void insertCeQueueDto(ComponentDto project, CeQueueDto.Status status) {
     dbClient.ceQueueDao().insert(dbTester.getSession(), new CeQueueDto()
       .setUuid("pending" + counter++)
-      .setComponent(project)
+      .setComponentUuid(project.uuid())
+      .setMainComponentUuid(project.uuid())
       .setTaskType("foo")
       .setStatus(status));
     dbTester.commit();
index ef3cc3ff648d96e0b7aa8e9866219f60ac3f36a2..c33b254a8a3fa0f0f655b5b661586d4fb796f5d4 100644 (file)
@@ -75,6 +75,7 @@ import static org.sonar.db.component.BranchType.BRANCH;
 import static org.sonar.db.component.ComponentDbTester.toProjectDto;
 import static org.sonar.db.component.ComponentTesting.newBranchDto;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
+import static org.sonar.db.component.ComponentTesting.newMainBranchDto;
 import static org.sonar.db.component.SnapshotTesting.newAnalysis;
 import static org.sonar.db.event.EventComponentChangeDto.ChangeCategory.ADDED;
 import static org.sonar.db.event.EventComponentChangeDto.ChangeCategory.FAILED_QUALITY_GATE;
@@ -145,7 +146,7 @@ public class SearchActionIT {
       .setKey(CorePropertyDefinitions.SONAR_ANALYSIS_DETECTEDCI)
       .setValue("Jenkins")
       .setCreatedAt(1L));
-    BranchDto branchDto = newBranchDto(project, BRANCH);
+    BranchDto branchDto = newMainBranchDto(project);
     db.getDbClient().branchDao().insert(db.getSession(), branchDto);
     db.newCodePeriods().insert(new NewCodePeriodDto()
       .setProjectUuid(project.uuid())
index d2ebbf8ed237333fa18e4cae755ae939e64841ac..7d5e9a6add6b1b2c2d854070c1e6e7f19e2bbfc4 100644 (file)
@@ -123,7 +123,7 @@ public class LinesActionIT {
     userSession.addProjectPermission(UserRole.USER, project);
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
     db.getDbClient().fileSourceDao().insert(db.getSession(), new FileSourceDto()
       .setUuid(Uuids.createFast())
       .setProjectUuid(branch.uuid())
@@ -147,7 +147,7 @@ public class LinesActionIT {
     userSession.addProjectPermission(UserRole.USER, project);
     String pullRequestKey = randomAlphanumeric(100);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
     db.getDbClient().fileSourceDao().insert(db.getSession(), new FileSourceDto()
       .setUuid(Uuids.createFast())
       .setProjectUuid(branch.uuid())
@@ -398,7 +398,7 @@ public class LinesActionIT {
 
   private ComponentDto insertFile(ComponentDto project) {
     ComponentDto file = newFileDto(project);
-    componentDao.insert(db.getSession(), file);
+    componentDao.insertOnMainBranch(db.getSession(), file);
     db.getSession().commit();
     return file;
   }
index bc995e5845df16439977da3d188a81f2df8f29ff..7eaf4a53ec61860d1bf6ed277eecbb0c2b5f4653 100644 (file)
@@ -79,7 +79,7 @@ public class RawActionIT {
     userSession.addProjectPermission(UserRole.CODEVIEWER, project);
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
     db.fileSources().insertFileSource(file, s -> s.setSourceData(
       Data.newBuilder()
         .addLines(Line.newBuilder().setLine(1).setSource("public class HelloWorld {").build())
@@ -108,7 +108,7 @@ public class RawActionIT {
     ComponentDto project = db.components().insertPrivateProject();
     userSession.addProjectPermission(UserRole.CODEVIEWER, project);
     ComponentDto branch = db.components().insertProjectBranch(project);
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
     db.fileSources().insertFileSource(file);
 
     assertThatThrownBy(() -> ws.newRequest()
@@ -124,7 +124,7 @@ public class RawActionIT {
     ComponentDto project = db.components().insertPrivateProject();
     userSession.addProjectPermission(UserRole.CODEVIEWER, project);
     ComponentDto branch = db.components().insertProjectBranch(project);
-    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
     db.fileSources().insertFileSource(file);
 
     assertThatThrownBy(() -> ws.newRequest()
index ed749b6dc643473d61a9dace91b2df96807de2d1..d570e848e8c3070399ad3913a1153575f034bed6 100644 (file)
@@ -66,7 +66,7 @@ public class ScmActionIT {
   public void setUp() {
     project = dbTester.components().insertPrivateProject(PROJECT_UUID);
     file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY);
-    dbClient.componentDao().insert(dbTester.getSession(), file);
+    dbClient.componentDao().insertOnMainBranch(dbTester.getSession(), file);
     dbTester.getSession().commit();
   }
 
index 3ef0b3dc696e64006a6646c81db8e62451002ec8..ee50e82fe5e82117a9f7008acb9f35d5f4575bc8 100644 (file)
@@ -55,7 +55,7 @@ public class ShowActionIT {
   private DbSession session = mock(DbSession.class);
   private ComponentDao componentDao = mock(ComponentDao.class);
   private ComponentDto project = ComponentTesting.newPrivateProjectDto();
-  private ComponentDto file = ComponentTesting.newFileDto(project, null);
+  private ComponentDto file = ComponentTesting.newFileDto(project);
   private ShowAction underTest = new ShowAction(sourceService, dbClient, userSessionRule,
     new ComponentFinder(dbClient, new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT)));
   private WsActionTester tester = new WsActionTester(underTest);
index e87bf373055e6a4423a41c75d6b2687e4982509f..accf986bb328546d683803a1e2ab6e8791d551b5 100644 (file)
@@ -319,7 +319,7 @@ public class ComponentActionIT {
     userSession.addProjectPermission(UserRole.USER, project);
     init();
     ComponentDto dirDto = componentDbTester.insertComponent(newDirectory(branch, "src"));
-    ComponentDto fileDto = componentDbTester.insertComponent(newFileDto(branch, dirDto)
+    ComponentDto fileDto = componentDbTester.insertComponent(newFileDto(project.uuid(), branch, dirDto)
       .setUuid("abcd")
       .setName("Main.xoo"));
 
index 775cf2874ce739ca0ce6c0aef995f2d924d28f54..e2d9f564ec4ab72a34a6e8a4bced72b6ad0837f6 100644 (file)
@@ -159,7 +159,7 @@ public class ComponentUpdater {
       .setCreatedAt(new Date(now));
 
     componentModifier.accept(component);
-    dbClient.componentDao().insert(session, component);
+    dbClient.componentDao().insert(session, component, true);
 
     if (isRootProject(component)) {
       ProjectDto projectDto = toProjectDto(component, now);