]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9628 Branches must not appear in administration of projects
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 17 Aug 2017 13:11:07 +0000 (15:11 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 09:01:38 +0000 (11:01 +0200)
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
server/sonar-db-dao/src/test/resources/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest/shared.xml

index d7079ac7a102bf5c4d0dc6f444698ef505321f7a..a30f402448cdac260853984bdddc11e806cc38d9 100644 (file)
     </if>
     where
       p.enabled=${_true}
-      and p.copy_component_uuid is null
+      AND p.main_branch_project_uuid is null
+      AND p.copy_component_uuid is null
       <if test="organizationUuid!=null">
         and p.organization_uuid=#{organizationUuid,jdbcType=VARCHAR}
       </if>
     where
     s2.id is null
     and p.qualifier='TRK'
+    and p.main_branch_project_uuid is null
     and p.copy_component_uuid is null
     <if test="query!=null">
       and (
     from projects p
     <where>
       p.enabled=${_true}
+      AND p.main_branch_project_uuid is null
       AND p.copy_component_uuid is null
       <if test="includeModules == false">
         AND p.qualifier = 'TRK'
index 74c2111e8eff4e0b0de4a8acd37c8f9724a1fed1..14c8cbd1b588f10a8647f7c62e436c6efdbefdde 100644 (file)
@@ -10,6 +10,7 @@
     where
     proj.qualifier = 'TRK'
     and proj.enabled = ${_true}
+    and proj.main_branch_project_uuid is null
     and proj.copy_component_uuid is null
     <choose>
       <when test="query.membership() == 'selected'">
index 1e3276715bef50cbc752e8fa154eb0c079952510..e0aae550a54fa544b9b6fbc17a2d999423c461f1 100644 (file)
     where
       pj.scope = 'PRJ'
       and pj.qualifier = 'TRK'
+      and pj.main_branch_project_uuid is null
       and upper(pj.name) like #{nameQuery, jdbcType=VARCHAR}
       and pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
     order by pj.name ASC
     FROM projects pj
     LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
     AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
-    WHERE pj.scope='PRJ' AND pj.qualifier='TRK'
+    WHERE pj.scope='PRJ' AND pj.qualifier='TRK' AND pj.main_branch_project_uuid is null
       AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
       AND pp.profile_key IS NULL
       AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
     FROM projects pj
     LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
     AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
-    WHERE pj.scope='PRJ' AND pj.qualifier='TRK'
+    WHERE pj.scope='PRJ' AND pj.qualifier='TRK' AND pj.main_branch_project_uuid is null
       AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
       AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
     ORDER BY pj.name ASC
index 21eae5e1253d55b57730752fb719ac2c00e3d11c..96dedef618481d794868e17716699ba4e142173d 100644 (file)
@@ -743,6 +743,24 @@ public class ComponentDaoTest {
     assertThat(underTest.countGhostProjects(dbSession, organization.getUuid(), null)).isEqualTo(3);
   }
 
+  @Test
+  public void dont_select_branch_ghost_projects() {
+    OrganizationDto organization = db.organizations().insert();
+
+    // ghosts because has at least one snapshot with status U but none with status P
+    ComponentDto ghostProject = db.components().insertPrivateProject(organization);
+    db.components().insertSnapshot(ghostProject, dto -> dto.setStatus("U"));
+    db.components().insertSnapshot(ghostProject, dto -> dto.setStatus("U"));
+    ComponentDto ghostBranchProject = db.components().insertProjectBranch(ghostProject);
+
+    db.components().insertSnapshot(ghostBranchProject, dto -> dto.setStatus("U"));
+
+    assertThat(underTest.selectGhostProjects(dbSession, organization.getUuid(), null, 0, 10))
+      .extracting(ComponentDto::uuid)
+      .containsOnly(ghostProject.uuid());
+    assertThat(underTest.countGhostProjects(dbSession, organization.getUuid(), null)).isEqualTo(1);
+  }
+
   @Test
   public void selectByProjectUuid() {
     ComponentDto project = db.components().insertPrivateProject();
@@ -964,6 +982,23 @@ public class ComponentDaoTest {
       .isEmpty();
   }
 
+  @Test
+  public void selectByQuery_should_not_return_branches() {
+    ComponentDto main = db.components().insertMainBranch();
+    ComponentDto branch = db.components().insertProjectBranch(main);
+
+    assertThat(underTest.selectByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY, 0, 2)).hasSize(1);
+    assertThat(underTest.selectByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY, 0, 2).get(0).uuid()).isEqualTo(main.uuid());
+  }
+
+  @Test
+  public void countByQuery_should_not_include_branches() {
+    ComponentDto main = db.components().insertMainBranch();
+    ComponentDto branch = db.components().insertProjectBranch(main);
+
+    assertThat(underTest.countByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY)).isEqualTo(1);
+  }
+
   @Test
   public void countByQuery_with_organization_filters_on_specified_organization() {
     OrganizationDto organization1 = db.organizations().insert();
@@ -1281,6 +1316,26 @@ public class ComponentDaoTest {
     assertThat(components).extracting("organizationUuid").containsOnly(organizationDto.getUuid());
   }
 
+  @Test
+  public void select_projects_by_name_ignore_branches() {
+    OrganizationDto organizationDto = db.organizations().insert();
+    ComponentDto project1 = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setName("project1"));
+    ComponentDto module1 = db.components().insertComponent(newModuleDto(project1).setName("project1"));
+    ComponentDto subModule1 = db.components().insertComponent(newModuleDto(module1).setName("project1"));
+
+    db.components().insertComponent(newFileDto(subModule1).setName("project1"));
+    db.components().insertProjectBranch(project1, b -> b.setKey("branch1"));
+
+    // check that branch is present with same name as main branch
+    assertThat(underTest.selectByKeyAndBranch(dbSession, project1.getKey(), "branch1").get().name()).isEqualTo("project1");
+
+    // branch is not returned
+    assertThat(underTest.selectProjectsByNameQuery(dbSession, null, false)).extracting(ComponentDto::uuid)
+      .containsOnly(project1.uuid());
+    assertThat(underTest.selectProjectsByNameQuery(dbSession, "project", false)).extracting(ComponentDto::uuid)
+      .containsOnly(project1.uuid());
+  }
+
   @Test
   public void select_projects_by_name_query() {
     OrganizationDto organizationDto = db.organizations().insert();
index ac367f963819708f543e940f4fa084273a34efd3..df22238b152519e4224afbbf9dead433625de30f 100644 (file)
  */
 package org.sonar.db.qualitygate;
 
+import static org.assertj.core.api.Assertions.assertThat;
+
 import java.util.List;
 import java.util.Optional;
+
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
@@ -30,8 +33,6 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.property.PropertyDto;
 
-import static org.assertj.core.api.Assertions.assertThat;
-
 public class ProjectQgateAssociationDaoTest {
 
   @Rule
index 97391a80f54004727fe52ccc78b5c83ac682c95f..4583a3bc5cb10d24be5c2d5b102ec81b275b56b6 100644 (file)
@@ -489,6 +489,7 @@ public class QualityProfileDaoTest {
     QProfileDto profileWithProjects = db.qualityProfiles().insert(organization);
     ComponentDto project1 = db.components().insertPrivateProject(organization);
     ComponentDto project2 = db.components().insertPrivateProject(organization);
+
     db.qualityProfiles().associateWithProject(project1, profileWithProjects);
     db.qualityProfiles().associateWithProject(project2, profileWithProjects);
 
@@ -580,6 +581,7 @@ public class QualityProfileDaoTest {
     ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid()));
     OrganizationDto organization2 = db.organizations().insert();
     ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
+    ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
 
     QProfileDto profile1 = newQualityProfileDto();
     db.qualityProfiles().insert(profile1);
@@ -608,6 +610,7 @@ public class QualityProfileDaoTest {
     ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid()));
     OrganizationDto organization2 = db.organizations().insert();
     ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
+    ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
 
     QProfileDto profile1 = newQualityProfileDto();
     db.qualityProfiles().insert(profile1);
@@ -635,6 +638,7 @@ public class QualityProfileDaoTest {
     ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid()));
     OrganizationDto organization2 = db.organizations().insert();
     ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
+    ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
 
     QProfileDto profile1 = newQualityProfileDto();
     db.qualityProfiles().insert(profile1);
index 2c53537979d652e34202f4d4d22e0821bf59bbaa..3b4ee850ea7ad46245190953865fbcca716958c3 100644 (file)
@@ -11,6 +11,7 @@
             root_uuid="A"
             project_uuid="A"
             kee="project-one"
+            main_branch_project_uuid="[null]"
             name="Project One"
             qualifier="TRK"
             scope="PRJ"
@@ -24,6 +25,7 @@
             root_uuid="B"
             project_uuid="B"
             kee="project-two"
+            main_branch_project_uuid="[null]"
             name="Project Two"
             qualifier="TRK"
             scope="PRJ"
@@ -37,6 +39,7 @@
             root_uuid="C"
             project_uuid="C"
             kee="project-three"
+            main_branch_project_uuid="[null]"
             name="Project Three"
             qualifier="TRK"
             scope="PRJ"
@@ -50,6 +53,7 @@
             root_uuid="D"
             project_uuid="D"
             kee="project-four"
+            main_branch_project_uuid="[null]"
             name="Project Four"
             qualifier="TRK"
             scope="PRJ"
@@ -63,6 +67,7 @@
             root_uuid="E"
             project_uuid="E"
             kee="project-five"
+            main_branch_project_uuid="[null]"
             name="Project Five"
             qualifier="TRK"
             scope="PRJ"
@@ -76,6 +81,7 @@
             root_uuid="F"
             project_uuid="F"
             kee="view-six"
+            main_branch_project_uuid="[null]"
             name="View Six"
             qualifier="VW"
             scope="PRJ"
@@ -89,6 +95,7 @@
             root_uuid="G"
             project_uuid="G"
             kee="file-one"
+            main_branch_project_uuid="[null]"
             name="File One"
             qualifier="TRK"
             scope="FIL"
             copy_component_uuid="C"
             id="7"
             private="[false]"/>
+  <projects organization_uuid="org1"
+            uuid="H"
+            uuid_path="NOT_USED"
+            root_uuid="H"
+            project_uuid="H"
+            kee="branch"
+            main_branch_project_uuid="A"
+            name="branch"
+            qualifier="TRK"
+            scope="PRJ"
+            enabled="[true]"
+            copy_component_uuid="[null]"
+            id="8"
+            private="[false]"/>
 
   <properties id="1"
               prop_key="sonar.qualitygate"