Search in sources :

Example 16 with Project

use of org.sonar.server.project.Project in project sonarqube by SonarSource.

the class BulkDeleteAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    SearchRequest searchRequest = toSearchWsRequest(request);
    userSession.checkLoggedIn();
    try (DbSession dbSession = dbClient.openSession(false)) {
        userSession.checkPermission(GlobalPermission.ADMINISTER);
        checkAtLeastOneParameterIsPresent(searchRequest);
        ComponentQuery query = buildDbQuery(searchRequest);
        Set<ComponentDto> componentDtos = new HashSet<>(dbClient.componentDao().selectByQuery(dbSession, query, 0, Integer.MAX_VALUE));
        try {
            componentDtos.forEach(p -> componentCleanerService.delete(dbSession, p));
        } finally {
            projectLifeCycleListeners.onProjectsDeleted(componentDtos.stream().map(Project::from).collect(MoreCollectors.toSet(componentDtos.size())));
        }
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) Project(org.sonar.server.project.Project) ComponentQuery(org.sonar.db.component.ComponentQuery) ComponentDto(org.sonar.db.component.ComponentDto) HashSet(java.util.HashSet)

Example 17 with Project

use of org.sonar.server.project.Project in project sonarqube by SonarSource.

the class SiblingsIssueMergerTest method setUp.

@Before
public void setUp() {
    DbClient dbClient = db.getDbClient();
    ComponentIssuesLoader componentIssuesLoader = new ComponentIssuesLoader(dbClient, null, null, new MapSettings().asConfig(), System2.INSTANCE);
    copier = new SiblingsIssueMerger(new SiblingsIssuesLoader(new SiblingComponentsWithOpenIssues(treeRootHolder, metadataHolder, dbClient), dbClient, componentIssuesLoader), tracker, issueLifecycle);
    projectDto = db.components().insertPublicProject(p -> p.setDbKey(PROJECT_KEY).setUuid(PROJECT_UUID));
    branch1Dto = db.components().insertProjectBranch(projectDto, b -> b.setKey("myBranch1").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(projectDto.uuid()));
    branch2Dto = db.components().insertProjectBranch(projectDto, b -> b.setKey("myBranch2").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(projectDto.uuid()));
    branch3Dto = db.components().insertProjectBranch(projectDto, b -> b.setKey("myBranch3").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(projectDto.uuid()));
    fileOnBranch1Dto = db.components().insertComponent(newFileDto(branch1Dto).setDbKey(FILE_1_KEY + ":PULL_REQUEST:myBranch1"));
    fileOnBranch2Dto = db.components().insertComponent(newFileDto(branch2Dto).setDbKey(FILE_1_KEY + ":PULL_REQUEST:myBranch2"));
    fileOnBranch3Dto = db.components().insertComponent(newFileDto(branch3Dto).setDbKey(FILE_1_KEY + ":PULL_REQUEST:myBranch3"));
    rule = db.rules().insert();
    when(branch.getReferenceBranchUuid()).thenReturn(projectDto.uuid());
    metadataHolder.setBranch(branch);
    metadataHolder.setProject(new Project(projectDto.uuid(), projectDto.getKey(), projectDto.name(), projectDto.description(), Collections.emptyList()));
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SimpleTracker(org.sonar.core.issue.tracking.SimpleTracker) MapSettings(org.sonar.api.config.internal.MapSettings) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ArgumentCaptor(org.mockito.ArgumentCaptor) AnalysisMetadataHolderRule(org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule) ReportComponent.builder(org.sonar.ce.task.projectanalysis.component.ReportComponent.builder) Before(org.junit.Before) DbTester(org.sonar.db.DbTester) BranchType(org.sonar.db.component.BranchType) DefaultIssue(org.sonar.core.issue.DefaultIssue) System2(org.sonar.api.utils.System2) IssueTesting(org.sonar.db.issue.IssueTesting) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Instant(java.time.Instant) Mockito.verify(org.mockito.Mockito.verify) FieldDiffs(org.sonar.core.issue.FieldDiffs) DbClient(org.sonar.db.DbClient) ComponentDto(org.sonar.db.component.ComponentDto) ChronoUnit(java.time.temporal.ChronoUnit) Rule(org.junit.Rule) Issue(org.sonar.api.issue.Issue) RuleKey(org.sonar.api.rule.RuleKey) TreeRootHolderRule(org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule) SiblingComponentsWithOpenIssues(org.sonar.ce.task.projectanalysis.component.SiblingComponentsWithOpenIssues) Collections(java.util.Collections) Project(org.sonar.server.project.Project) Mockito.mock(org.mockito.Mockito.mock) Project(org.sonar.server.project.Project) DbClient(org.sonar.db.DbClient) MapSettings(org.sonar.api.config.internal.MapSettings) SiblingComponentsWithOpenIssues(org.sonar.ce.task.projectanalysis.component.SiblingComponentsWithOpenIssues) Before(org.junit.Before)

Example 18 with Project

use of org.sonar.server.project.Project in project sonarqube by SonarSource.

the class SourceBranchComponentUuidsTest method setup.

@Before
public void setup() {
    underTest = new SourceBranchComponentUuids(analysisMetadataHolder, db.getDbClient());
    Project project = mock(Project.class);
    analysisMetadataHolder.setProject(project);
    analysisMetadataHolder.setBranch(branch);
    ComponentDto projectDto = db.components().insertPublicProject();
    when(project.getUuid()).thenReturn(projectDto.uuid());
    branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey(BRANCH_KEY));
    ComponentDto pr1branch = db.components().insertProjectBranch(projectDto, b -> b.setKey(PR_KEY).setBranchType(BranchType.PULL_REQUEST).setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setBranch(BRANCH_KEY).build()).setMergeBranchUuid(projectDto.getMainBranchProjectUuid()));
    branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File");
    pr1File = ComponentTesting.newFileDto(pr1branch, null, "file").setUuid("file1");
    db.components().insertComponents(branch1File, pr1File);
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) DbTester(org.sonar.db.DbTester) BranchType(org.sonar.db.component.BranchType) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DbProjectBranches(org.sonar.db.protobuf.DbProjectBranches) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) AnalysisMetadataHolderRule(org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule) ComponentTesting(org.sonar.db.component.ComponentTesting) Before(org.junit.Before) Project(org.sonar.server.project.Project) Mockito.mock(org.mockito.Mockito.mock) Project(org.sonar.server.project.Project) ComponentDto(org.sonar.db.component.ComponentDto) Before(org.junit.Before)

Example 19 with Project

use of org.sonar.server.project.Project in project sonarqube by SonarSource.

the class NewCodeReferenceBranchComponentUuidsTest method setUp.

@Before
public void setUp() {
    analysisMetadataHolder.setProject(project);
    ComponentDto projectDto = db.components().insertPublicProject();
    when(project.getUuid()).thenReturn(projectDto.uuid());
    branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey("branch1"));
    branch2 = db.components().insertProjectBranch(projectDto, b -> b.setKey("branch2"));
    pr1 = db.components().insertProjectBranch(projectDto, b -> b.setKey("pr1").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
    pr2 = db.components().insertProjectBranch(projectDto, b -> b.setKey("pr2").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
    branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File");
    branch2File = ComponentTesting.newFileDto(branch2, null, "file").setUuid("branch2File");
    pr1File = ComponentTesting.newFileDto(pr1, null, "file").setUuid("file1");
    pr2File = ComponentTesting.newFileDto(pr2, null, "file").setUuid("file2");
    db.components().insertComponents(branch1File, pr1File, pr2File, branch2File);
}
Also used : DbTester(org.sonar.db.DbTester) BranchType(org.sonar.db.component.BranchType) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) AnalysisMetadataHolderRule(org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule) ComponentTesting(org.sonar.db.component.ComponentTesting) NewCodePeriodType(org.sonar.db.newcodeperiod.NewCodePeriodType) Before(org.junit.Before) Project(org.sonar.server.project.Project) Mockito.mock(org.mockito.Mockito.mock) ComponentDto(org.sonar.db.component.ComponentDto) Before(org.junit.Before)

Example 20 with Project

use of org.sonar.server.project.Project in project sonarqube by SonarSource.

the class LoadReportAnalysisMetadataHolderStepTest method set_project_from_dto.

@Test
public void set_project_from_dto() {
    reportReader.setMetadata(newBatchReportBuilder().setRootComponentRef(1).build());
    underTest.execute(new TestComputationStepContext());
    Project project = analysisMetadataHolder.getProject();
    assertThat(project.getUuid()).isEqualTo(this.project.uuid());
    assertThat(project.getKey()).isEqualTo(this.project.getDbKey());
    assertThat(project.getName()).isEqualTo(this.project.name());
    assertThat(project.getDescription()).isEqualTo(this.project.description());
}
Also used : Project(org.sonar.server.project.Project) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Aggregations

Project (org.sonar.server.project.Project)26 Test (org.junit.Test)21 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)14 ComponentDto (org.sonar.db.component.ComponentDto)14 Before (org.junit.Before)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 Rule (org.junit.Rule)11 Mockito.mock (org.mockito.Mockito.mock)11 Mockito.when (org.mockito.Mockito.when)11 DbTester (org.sonar.db.DbTester)11 AnalysisMetadataHolderRule (org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule)10 Branch (org.sonar.ce.task.projectanalysis.analysis.Branch)10 BranchType (org.sonar.db.component.BranchType)10 Date (java.util.Date)9 Notification (org.sonar.api.notifications.Notification)8 UserDto (org.sonar.db.user.UserDto)8 IssuesChangesNotification (org.sonar.server.issue.notification.IssuesChangesNotification)8 MyNewIssuesNotification (org.sonar.server.issue.notification.MyNewIssuesNotification)8 NewIssuesNotification (org.sonar.server.issue.notification.NewIssuesNotification)8 System2 (org.sonar.api.utils.System2)6