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());
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();
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();
.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());
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());
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"));
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());
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());
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());
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);
}
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;
}
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";
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";
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";
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)
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";
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";
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";
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";
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;
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");
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(
.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(
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;
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));
}
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;
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;
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));
}
@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));
@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));
@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);
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));
}
}
- /**
- * 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()) {
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);
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));
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());
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));
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();
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));
}
BranchDto branch = newBranchDto(project);
ComponentDto branchComponent = newBranchComponent(project, branch);
- underTestWithAuditPersister.insert(dbSession, branchComponent);
+ underTestWithAuditPersister.insert(dbSession, branchComponent, false);
verifyNoInteractions(auditPersister);
}
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();
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))
@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();
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);
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());
@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();
@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);
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);
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());
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());
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);
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);
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());
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());
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);
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);
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);
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;
* 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) {
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 {
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;
/*
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) {
checkThatNotTooManyConditions(query.getComponentUuids(), "Too many component UUIDs in query");
}
- private static boolean isBranchOrPullRequest(ComponentDto item) {
- return item.getMainBranchProjectUuid() != null;
- }
-
}
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">
}
public SnapshotDto insertPortfolioAndSnapshot(ComponentDto component) {
- dbClient.componentDao().insert(dbSession, component);
+ dbClient.componentDao().insert(dbSession, component, true);
return insertSnapshot(component);
}
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);
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();
}
@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);
}
}
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);
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)
.setLongName(path)
.setScope(Scopes.FILE)
.setBranchUuid(project.branchUuid())
+ .setMainBranchProjectUuid(mainBranchUuid)
.setQualifier(Qualifiers.FILE)
.setPath(path)
.setCreatedAt(new Date())
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)
.setUuidPath(formatUuidPathFromParent(parent))
.setKey(uuid)
.setBranchUuid(project.branchUuid())
- .setMainBranchProjectUuid(project.getMainBranchProjectUuid())
.setCreatedAt(new Date())
.setEnabled(true)
.setPrivate(project.isPrivate());
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);
}
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()
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)
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;
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)
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())
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();
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();
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);
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);
@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),
@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),
@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),
@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),
@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));
@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),
@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),
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"));
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));
}
@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"),
@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")),
@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")),
@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")),
@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")),
@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")),
@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")),
@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")),
@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")),
@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),
@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),
@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),
@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),
@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),
@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),
@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),
@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);
@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);
@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"),
@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);
@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"),
@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"),
@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);
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"));
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");
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")));
@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()));
@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"),
@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());
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),
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()));
@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),
@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),
@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),
@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),
@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);
@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);
@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"),
@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"),
@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"),
@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")),
@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")),
@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")),
@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")),
@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")));
@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));
@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")),
@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")),
@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")),
@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")),
@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")),
@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")),
@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),
@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),
@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),
@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),
@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),
@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),
@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")),
@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")),
@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")),
@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));
}
@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;
@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;
@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--) {
@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--) {
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();
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();
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")),
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()))
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()))
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));
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();
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")
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);
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);
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);
}
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();
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);
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);
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);
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);
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))
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());
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());
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())
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"))
@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();
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));
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())
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())
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())
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())
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;
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()
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()
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);
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));
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;
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()
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())
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())
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());
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" +
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" +
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" +
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),
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);
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);
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;
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);
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);
.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);
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);
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,
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)
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)
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();
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);
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));
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();
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();
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();
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();
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));
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"))
@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"));
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));
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));
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"));
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"));
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")
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
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()
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));
@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()
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));
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));
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));
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));
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));
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();
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;
.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())
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())
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())
private ComponentDto insertFile(ComponentDto project) {
ComponentDto file = newFileDto(project);
- componentDao.insert(db.getSession(), file);
+ componentDao.insertOnMainBranch(db.getSession(), file);
db.getSession().commit();
return file;
}
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())
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()
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()
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();
}
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);
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"));
.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);