]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9616 Filter out branches in ComponentDao#selectProjects()
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 28 Aug 2017 15:57:49 +0000 (17:57 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 09:34:55 +0000 (11:34 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
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 b6456c4e12de886ba8d1ff3db87a1e07237141d0..5806296250bc81ac1c4fa92d5a92dbdb0b79a24e 100644 (file)
@@ -237,6 +237,8 @@ public class ComponentDao implements Dao {
    * Returns all projects (Scope {@link org.sonar.api.resources.Scopes#PROJECT} and qualifier
    * {@link org.sonar.api.resources.Qualifiers#PROJECT}) which are enabled.
    *
+   * Branches are not returned.
+   *
    * Used by Views.
    */
   public List<ComponentDto> selectProjects(DbSession session) {
index c61e9363f900aff3c267f0d2eaa6432a15c064a4..6031646c260ed22329062b73d990b6826e104c99 100644 (file)
       p.enabled=${_true}
       AND p.scope='PRJ'
       AND p.qualifier='TRK'
+      AND p.main_branch_project_uuid IS NULL
   </select>
 
   <select id="selectAllRootsByOrganization" resultType="Component">
index 96dedef618481d794868e17716699ba4e142173d..ea464ee5f5f719a785a0d93a33e95fce7c8b41fd 100644 (file)
@@ -637,8 +637,7 @@ public class ComponentDaoTest {
   public void select_projects() {
     OrganizationDto organization = db.organizations().insert();
     ComponentDto provisionedProject = db.components().insertPrivateProject();
-    ComponentDto provisionedView = db.components().insertView(organization, (dto) -> {
-    });
+    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();
@@ -648,6 +647,17 @@ public class ComponentDaoTest {
       .containsOnly(provisionedProject.uuid(), projectUuid);
   }
 
+  @Test
+  public void select_projects_does_not_return_branches() {
+    OrganizationDto organization = db.organizations().insert();
+    ComponentDto project = db.components().insertMainBranch();
+    ComponentDto branch = db.components().insertProjectBranch(project);
+
+    assertThat(underTest.selectProjects(dbSession))
+      .extracting(ComponentDto::uuid)
+      .containsOnly(project.uuid());
+  }
+
   @Test
   public void select_provisioned() {
     OrganizationDto organization = db.organizations().insert();