From: Simon Brandhof Date: Wed, 4 Apr 2018 21:17:58 +0000 (+0200) Subject: SONAR-10441 project is provisioned if no analysis on any branches X-Git-Tag: 7.5~1402 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2104453573fa15d1c5c3f8cee703d2cf3ccced55;p=sonarqube.git SONAR-10441 project is provisioned if no analysis on any branches --- diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml index 0473a825eb2..b3e23af4572 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -340,6 +340,11 @@ and not exists(select 1 from snapshots sp where sp.component_uuid=p.uuid) + and not exists( + select 1 from snapshots sp + inner join project_branches pb on sp.component_uuid = pb.uuid + where pb.project_uuid = p.uuid + ) diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java index 53d327009d4..95e2aaf1543 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -903,14 +903,16 @@ public class ComponentDaoTest { @Test public void selectByQuery_provisioned() { OrganizationDto organization = db.organizations().insert(); + ComponentDto provisionedProject = db.components() - .insertComponent(newPrivateProjectDto(organization).setDbKey("provisioned.project").setName("Provisioned Project")); - ComponentDto provisionedView = db.components().insertView(organization); - String projectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)).getComponentUuid(); - String disabledProjectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization).setEnabled(false)).getComponentUuid(); - String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization)).getComponentUuid(); + .insertPrivateProject(organization, p -> p.setDbKey("provisioned.project").setName("Provisioned Project")); + ComponentDto provisionedPortfolio = db.components().insertPrivatePortfolio(organization); + + SnapshotDto analyzedProject = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); + SnapshotDto analyzedDisabledProject = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization) + .setEnabled(false)); + SnapshotDto analyzedPortfolio = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization)); - Set projectQualifiers = newHashSet(Qualifiers.PROJECT); Supplier query = () -> ComponentQuery.builder().setQualifiers(Qualifiers.PROJECT).setOnProvisionedOnly(true); assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 0, 10)) .extracting(ComponentDto::uuid) @@ -926,7 +928,7 @@ public class ComponentDaoTest { .containsOnly(provisionedProject.uuid()); assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW).build(), 0, 10)) .extracting(ComponentDto::uuid) - .containsOnly(provisionedProject.uuid(), provisionedView.uuid()); + .containsOnly(provisionedProject.uuid(), provisionedPortfolio.uuid()); // match key assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setNameOrKeyQuery(provisionedProject.getDbKey()).build(), 0, 10)) @@ -945,6 +947,28 @@ public class ComponentDaoTest { .containsExactly(provisionedProject.uuid()); } + @Test + public void selectByQuery_onProvisionedOnly_filters_projects_with_analysis_on_branch() { + Supplier query = () -> ComponentQuery.builder() + .setQualifiers(Qualifiers.PROJECT) + .setOnProvisionedOnly(true); + + // the project does not have any analysis + OrganizationDto organization = db.organizations().insert(); + ComponentDto project = db.components().insertMainBranch(organization); + assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 0, 10)) + .extracting(ComponentDto::uuid) + .containsOnly(project.uuid()); + + // the project does not have analysis of main branch but only + // analysis of non-main branches + ComponentDto branchWithoutAnalysis = db.components().insertProjectBranch(project); + ComponentDto branchWithAnalysis = db.components().insertProjectBranch(project); + db.components().insertSnapshot(branchWithAnalysis); + assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 0, 10)) + .isEmpty(); + } + @Test public void count_provisioned() { OrganizationDto organization = db.organizations().insert();