aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>2023-03-31 10:48:41 +0200
committersonartech <sonartech@sonarsource.com>2023-04-04 20:03:16 +0000
commit02f358bec4d5636d8c23bf34d4d086b0405f65cf (patch)
tree2ee81f90e86a5d660834a3d7f667750768bb7efe
parentb9f8ca8219d05bccd8f179838365a90f2941451d (diff)
downloadsonarqube-02f358bec4d5636d8c23bf34d4d086b0405f65cf.tar.gz
sonarqube-02f358bec4d5636d8c23bf34d4d086b0405f65cf.zip
SONAR-18850 update branch mapper to use is main and update test framework
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplIT.java10
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesIT.java20
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerIT.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepIT.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepIT.java16
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java8
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepIT.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepIT.java3
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepIT.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepIT.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/PullRequestSourceBranchMergerTest.java6
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java12
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentKeyUpdaterDaoIT.java6
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueMapperIT.java8
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorIT.java2
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java27
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java38
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDto.java15
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java8
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java1
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java21
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml3
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java13
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java48
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java13
-rw-r--r--server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIndexerIT.java2
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ServerUserSessionTest.java2
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java24
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java68
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java62
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityHotspotsTest.java6
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSortTest.java10
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java24
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java6
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/batch/ProjectDataLoaderIT.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityActionIT.java8
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityStatusActionIT.java10
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/AnalysisStatusActionIT.java3
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ComponentActionIT.java6
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/DismissAnalysisWarningActionIT.java3
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentCleanerServiceIT.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentFinderIT.java8
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentServiceUpdateKeyIT.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java10
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/ShowActionIT.java17
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java11
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/DuplicationsParserIT.java10
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowResponseBuilderIT.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/AssignActionIT.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java15
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ShowActionIT.java2
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/BulkChangeActionIT.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/IssueUpdaterIT.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionComponentsIT.java10
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java6
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentActionIT.java8
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java20
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/SearchHistoryActionIT.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateVisibilityActionIT.java3
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/projectanalysis/ws/SearchActionIT.java3
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java6
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/RawActionIT.java6
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ScmActionIT.java2
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ShowActionIT.java2
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java2
68 files changed, 390 insertions, 337 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplIT.java
index f77eb52d624..8da1da4efe2 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplIT.java
@@ -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());
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesIT.java
index b35f634bd3e..1e9fa01615b 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesIT.java
@@ -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());
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerIT.java
index 870e352dcdb..ccc993af92f 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerIT.java
@@ -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);
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepIT.java
index 1816523c111..1db962d0d15 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepIT.java
@@ -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;
}
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepIT.java
index 99d9bac1ebc..ed30205c8ab 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepIT.java
@@ -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";
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java
index 1a4c4c031cc..68390b46134 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java
@@ -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(
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepIT.java
index 5b315e9dbda..0f898673c43 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepIT.java
@@ -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;
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepIT.java
index c69ac175982..95a7f770898 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepIT.java
@@ -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));
}
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepIT.java
index 4b3d12f2be8..e39789dfffc 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepIT.java
@@ -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);
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepIT.java
index 4bed242c8de..8d16133ac45 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepIT.java
@@ -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));
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
index 8e591b95e81..6b16eab2068 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
@@ -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);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/PullRequestSourceBranchMergerTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/PullRequestSourceBranchMergerTest.java
index f351eb644b2..f6a5d6dfdf2 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/PullRequestSourceBranchMergerTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/PullRequestSourceBranchMergerTest.java
@@ -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));
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java
index 5bb1d10d941..9a08ca17b6c 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java
@@ -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);
}
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentKeyUpdaterDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentKeyUpdaterDaoIT.java
index 8e62ecd2c12..b2a5fff2f8f 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentKeyUpdaterDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentKeyUpdaterDaoIT.java
@@ -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))
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueMapperIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueMapperIT.java
index 40af62b9d7a..aae4b56442e 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueMapperIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueMapperIT.java
@@ -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();
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorIT.java
index b91b833a53b..f63586e9d6a 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorIT.java
@@ -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);
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java
index 0a147e4c53a..17fd4cc182d 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java
@@ -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();
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java
index 0d35792599b..171c524c1a6 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java
@@ -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);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDto.java
index c037d412e67..deb5452010e 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDto.java
@@ -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;
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java
index 759bea823ed..39d000faec9 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java
@@ -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) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java
index 1973e29b687..3d3a7daa5d2 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java
@@ -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 {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
index 9044d64ad57..71dbafe1e4b 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
@@ -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;
- }
-
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index 996adb5462a..78e92a39d7a 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -34,9 +34,10 @@
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">
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
index b27e43e05a0..3d206dafaae 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
@@ -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);
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
index 93c2c4417e6..fd7176c80e7 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
@@ -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)
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
index 6664dae2eba..846b20a7c9c 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
@@ -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();
diff --git a/server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIndexerIT.java b/server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIndexerIT.java
index 3f9aea94081..b5fadad5fee 100644
--- a/server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIndexerIT.java
+++ b/server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIndexerIT.java
@@ -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();
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ServerUserSessionTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
index fb5d2047ae3..900743d33f7 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
@@ -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);
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
index 207f38d9443..45875acdbc9 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
@@ -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"));
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java
index 71136ad4b5e..ad2a99e4568 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java
@@ -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"));
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java
index 72753048a65..a608ff5e985 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java
@@ -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),
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityHotspotsTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityHotspotsTest.java
index 40d490b31c9..285715bd3bf 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityHotspotsTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityHotspotsTest.java
@@ -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),
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSortTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSortTest.java
index db984cdb381..9caf4bffb7c 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSortTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSortTest.java
@@ -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")),
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
index bac4e99a588..6eb1fc47d7f 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
@@ -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")),
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java
index 7f0c3568a45..ddbdef82183 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java
@@ -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));
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/batch/ProjectDataLoaderIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/batch/ProjectDataLoaderIT.java
index ee707200402..d173fa151e7 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/batch/ProjectDataLoaderIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/batch/ProjectDataLoaderIT.java
@@ -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")
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityActionIT.java
index 552b0d0b865..d88faef09c0 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityActionIT.java
@@ -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);
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityStatusActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityStatusActionIT.java
index 2f1e8e95e91..40926311f9b 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityStatusActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityStatusActionIT.java
@@ -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();
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/AnalysisStatusActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/AnalysisStatusActionIT.java
index a66d36fa963..e9289fc9b19 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/AnalysisStatusActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/AnalysisStatusActionIT.java
@@ -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);
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ComponentActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ComponentActionIT.java
index 52fa6d70516..e7135a4b9fc 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ComponentActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ComponentActionIT.java
@@ -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);
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/DismissAnalysisWarningActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/DismissAnalysisWarningActionIT.java
index a058e511afe..5b0bfa1c04b 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/DismissAnalysisWarningActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/DismissAnalysisWarningActionIT.java
@@ -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);
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentCleanerServiceIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentCleanerServiceIT.java
index cba4c4d9ef6..51fca49833f 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentCleanerServiceIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentCleanerServiceIT.java
@@ -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))
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentFinderIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentFinderIT.java
index b197932ea8c..2451aa92693 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentFinderIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentFinderIT.java
@@ -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"))
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentServiceUpdateKeyIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentServiceUpdateKeyIT.java
index 82a5d63698c..120d3aa307a 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentServiceUpdateKeyIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentServiceUpdateKeyIT.java
@@ -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();
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java
index 55c94ada8c6..e25d24bb217 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java
@@ -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())
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/ShowActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/ShowActionIT.java
index f220a69a538..f05a85e99d8 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/ShowActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/ShowActionIT.java
@@ -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));
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java
index 9db223da893..e210a1f8a7f 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java
@@ -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())
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/DuplicationsParserIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/DuplicationsParserIT.java
index 8469a0a0354..d46f5e6bfc3 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/DuplicationsParserIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/DuplicationsParserIT.java
@@ -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" +
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java
index b3dd5b79eb3..873ac406763 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java
@@ -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" +
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowResponseBuilderIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowResponseBuilderIT.java
index 8308c93fda3..a6b5ad14f8d 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowResponseBuilderIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowResponseBuilderIT.java
@@ -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),
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/AssignActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/AssignActionIT.java
index 25df798fd08..57e5e2fcf1f 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/AssignActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/AssignActionIT.java
@@ -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);
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java
index 271ff6a938c..7201714ab10 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java
@@ -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);
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ShowActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ShowActionIT.java
index 3d42866a102..51720ba03dd 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ShowActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ShowActionIT.java
@@ -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,
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/BulkChangeActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/BulkChangeActionIT.java
index 2a0f523a07d..0ae3fbfc5ae 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/BulkChangeActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/BulkChangeActionIT.java
@@ -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)
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/IssueUpdaterIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/IssueUpdaterIT.java
index fa8bd1182c7..650ca9ad145 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/IssueUpdaterIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/IssueUpdaterIT.java
@@ -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);
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionComponentsIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionComponentsIT.java
index f54f69655ec..8d8585e3f38 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionComponentsIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionComponentsIT.java
@@ -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();
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java
index 527981fe0c7..efe286f42f0 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java
@@ -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"));
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentActionIT.java
index 9bad8f9b3e8..d12e3934ea3 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentActionIT.java
@@ -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"));
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java
index 21ab3a5734d..bdf47737043 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java
@@ -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));
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/SearchHistoryActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/SearchHistoryActionIT.java
index fa74bf8d2d4..6488d86ca01 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/SearchHistoryActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/SearchHistoryActionIT.java
@@ -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));
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateVisibilityActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateVisibilityActionIT.java
index acd3ce7a198..e613a0fbf1c 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateVisibilityActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateVisibilityActionIT.java
@@ -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();
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/projectanalysis/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/projectanalysis/ws/SearchActionIT.java
index ef3cc3ff648..c33b254a8a3 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/projectanalysis/ws/SearchActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/projectanalysis/ws/SearchActionIT.java
@@ -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())
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java
index d2ebbf8ed23..7d5e9a6add6 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java
@@ -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;
}
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/RawActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/RawActionIT.java
index bc995e5845d..7eaf4a53ec6 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/RawActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/RawActionIT.java
@@ -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()
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ScmActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ScmActionIT.java
index ed749b6dc64..d570e848e8c 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ScmActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ScmActionIT.java
@@ -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();
}
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ShowActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ShowActionIT.java
index 3ef0b3dc696..ee50e82fe5e 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ShowActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ShowActionIT.java
@@ -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);
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java
index e87bf373055..accf986bb32 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java
@@ -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"));
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
index 775cf2874ce..e2d9f564ec4 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
@@ -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);