]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10441 project is provisioned if no analysis on any branches
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 4 Apr 2018 21:17:58 +0000 (23:17 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 5 Apr 2018 18:20:48 +0000 (20:20 +0200)
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java

index 0473a825eb214ba5346c36c773b0f9264e7ded4b..b3e23af45727f2b5275f71e2cdffe069cfbc427e 100644 (file)
       </if>
       <if test="query.isOnProvisionedOnly()">
         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
+        )
       </if>
   </sql>
 
index 53d327009d46c7b3da458ab1ef9b00ebbb82a8af..95e2aaf1543e1b51c0e40a9a0bf848075d2c2e03 100644 (file)
@@ -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<String> projectQualifiers = newHashSet(Qualifiers.PROJECT);
     Supplier<ComponentQuery.Builder> 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<ComponentQuery.Builder> 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();