]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5849 Improve the way to get modules tree by using components.moduleUuid
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 30 Dec 2014 18:20:20 +0000 (19:20 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 30 Dec 2014 18:20:20 +0000 (19:20 +0100)
server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsLoader.java
server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java
server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java
sonar-core/src/main/java/org/sonar/core/component/ProjectRefentialsComponentDto.java [deleted file]
sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java
sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml

index dbff7696929d52e62a29ef0c03fc55be2b8f7a92..4579670fe934e2e6aa477980c06858e84aee6e8e 100644 (file)
@@ -29,7 +29,6 @@ import org.sonar.api.resources.Languages;
 import org.sonar.batch.protocol.input.ProjectReferentials;
 import org.sonar.core.UtcDateUtils;
 import org.sonar.core.component.ComponentDto;
-import org.sonar.core.component.ProjectRefentialsComponentDto;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.persistence.MyBatis;
@@ -91,7 +90,7 @@ public class ProjectReferentialsLoader implements ServerComponent {
           }
 
           List<PropertyDto> moduleSettings = dbClient.propertiesDao().selectProjectProperties(query.getModuleKey(), session);
-          List<ProjectRefentialsComponentDto> moduleChildren = dbClient.componentDao().findChildrenModulesFromModule(session, query.getModuleKey());
+          List<ComponentDto> moduleChildren = dbClient.componentDao().findChildrenModulesFromModule(session, query.getModuleKey());
           List<PropertyDto> moduleChildrenSettings = newArrayList();
           if (!moduleChildren.isEmpty()) {
             moduleChildrenSettings = dbClient.propertiesDao().findChildrenModuleProperties(query.getModuleKey(), session);
@@ -152,7 +151,7 @@ public class ProjectReferentialsLoader implements ServerComponent {
     }
   }
 
-  private Map<String, String> getPropertiesMap(List<? extends PropertyDto> propertyDtos, boolean hasScanPerm) {
+  private Map<String, String> getPropertiesMap(List<PropertyDto> propertyDtos, boolean hasScanPerm) {
     Map<String, String> properties = newHashMap();
     for (PropertyDto propertyDto : propertyDtos) {
       String key = propertyDto.getKey();
@@ -235,27 +234,31 @@ public class ProjectReferentialsLoader implements ServerComponent {
   private static class TreeModuleSettings {
 
     private Map<String, Long> moduleIdsByKey;
+    private Map<String, String> moduleUuidsByKey;
     private Multimap<Long, PropertyDto> propertiesByModuleId;
-    private Multimap<String, ProjectRefentialsComponentDto> moduleChildrenByModuleKey;
+    private Multimap<String, ComponentDto> moduleChildrenByModuleUuid;
 
-    private TreeModuleSettings(List<ProjectRefentialsComponentDto> moduleChildren, List<PropertyDto> moduleChildrenSettings, ComponentDto module, List<PropertyDto> moduleSettings) {
+    private TreeModuleSettings(List<ComponentDto> moduleChildren, List<PropertyDto> moduleChildrenSettings, ComponentDto module, List<PropertyDto> moduleSettings) {
       propertiesByModuleId = ArrayListMultimap.create();
+      moduleIdsByKey = newHashMap();
+      moduleUuidsByKey = newHashMap();
+      moduleChildrenByModuleUuid = ArrayListMultimap.create();
+
       for (PropertyDto settings : moduleChildrenSettings) {
         propertiesByModuleId.put(settings.getResourceId(), settings);
       }
       propertiesByModuleId.putAll(module.getId(), moduleSettings);
-      moduleIdsByKey = newHashMap();
-      for (ProjectRefentialsComponentDto componentDto : moduleChildren) {
-        moduleIdsByKey.put(componentDto.key(), componentDto.getId());
-      }
+
       moduleIdsByKey.put(module.key(), module.getId());
-      moduleChildrenByModuleKey = ArrayListMultimap.create();
-      for (ProjectRefentialsComponentDto componentDto : moduleChildren) {
-        String parentModuleKey = componentDto.getParentModuleKey();
-        if (parentModuleKey != null) {
-          moduleChildrenByModuleKey.put(parentModuleKey, componentDto);
+      moduleUuidsByKey.put(module.key(), module.uuid());
+      for (ComponentDto componentDto : moduleChildren) {
+        moduleIdsByKey.put(componentDto.key(), componentDto.getId());
+        moduleUuidsByKey.put(componentDto.key(), componentDto.uuid());
+        String moduleUuid = componentDto.moduleUuid();
+        if (moduleUuid != null) {
+          moduleChildrenByModuleUuid.put(moduleUuid, componentDto);
         } else {
-          moduleChildrenByModuleKey.put(module.key(), componentDto);
+          moduleChildrenByModuleUuid.put(module.uuid(), componentDto);
         }
       }
     }
@@ -265,9 +268,9 @@ public class ProjectReferentialsLoader implements ServerComponent {
       return newArrayList(propertiesByModuleId.get(moduleId));
     }
 
-    private List<? extends ComponentDto> findChildrenModule(String moduleKey) {
-      return newArrayList(moduleChildrenByModuleKey.get(moduleKey));
+    private List<ComponentDto> findChildrenModule(String moduleKey) {
+      String moduleUuid = moduleUuidsByKey.get(moduleKey);
+      return newArrayList(moduleChildrenByModuleUuid.get(moduleUuid));
     }
-
   }
 }
index 69e3ec3dfa83b6dcbfed8cf8493a390fe5d90d78..d6693eae1c782a3ed8e46277244c900b0717859c 100644 (file)
@@ -24,7 +24,6 @@ import com.google.common.collect.Lists;
 import org.sonar.api.ServerComponent;
 import org.sonar.api.utils.System2;
 import org.sonar.core.component.ComponentDto;
-import org.sonar.core.component.ProjectRefentialsComponentDto;
 import org.sonar.core.component.db.ComponentMapper;
 import org.sonar.core.persistence.DaoComponent;
 import org.sonar.core.persistence.DbSession;
@@ -115,7 +114,7 @@ public class ComponentDao extends BaseDao<ComponentMapper, ComponentDto, String>
     return mapper(session).findSubProjectsByComponentUuids(keys);
   }
 
-  public List<ProjectRefentialsComponentDto> findChildrenModulesFromModule(DbSession session, String moduleKey) {
+  public List<ComponentDto> findChildrenModulesFromModule(DbSession session, String moduleKey) {
     return mapper(session).findChildrenModulesFromModule(moduleKey);
   }
 
index b49a20096456d35bd40cc7c2d987000edaf17f45..8e3532cbe8ecd95093eda4850bd09c013e84970c 100644 (file)
@@ -27,7 +27,6 @@ import org.junit.Test;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.core.component.ComponentDto;
-import org.sonar.core.component.ProjectRefentialsComponentDto;
 import org.sonar.core.persistence.AbstractDaoTestCase;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.server.exceptions.NotFoundException;
@@ -336,16 +335,14 @@ public class ComponentDaoTest extends AbstractDaoTestCase {
     setupData("multi-modules");
 
     // From root project
-    List<ProjectRefentialsComponentDto> modules = dao.findChildrenModulesFromModule(session, "org.struts:struts");
+    List<ComponentDto> modules = dao.findChildrenModulesFromModule(session, "org.struts:struts");
     assertThat(modules).hasSize(2);
     assertThat(modules).onProperty("id").containsOnly(2L, 3L);
-    assertThat(modules).onProperty("parentModuleKey").containsOnly("org.struts:struts", "org.struts:struts-core");
 
     // From module
     modules = dao.findChildrenModulesFromModule(session, "org.struts:struts-core");
     assertThat(modules).hasSize(1);
     assertThat(modules).onProperty("id").containsOnly(3L);
-    assertThat(modules).onProperty("parentModuleKey").containsOnly("org.struts:struts-core");
 
     // From sub module
     modules = dao.findChildrenModulesFromModule(session, "org.struts:struts-data");
diff --git a/sonar-core/src/main/java/org/sonar/core/component/ProjectRefentialsComponentDto.java b/sonar-core/src/main/java/org/sonar/core/component/ProjectRefentialsComponentDto.java
deleted file mode 100644 (file)
index e531993..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.core.component;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-public class ProjectRefentialsComponentDto extends ComponentDto {
-
-  private String parentModuleKey;
-
-  @CheckForNull
-  public String getParentModuleKey() {
-    return parentModuleKey;
-  }
-
-  public void setParentModuleKey(@Nullable String parentModuleKey) {
-    this.parentModuleKey = parentModuleKey;
-  }
-}
index 789af967e652c76f2c8b7a6051cfebb6ba79b4f8..b37a53f6b52c393f2576f1325e46c6b838ec9f07 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.core.component.db;
 
 import org.apache.ibatis.annotations.Param;
 import org.sonar.core.component.ComponentDto;
-import org.sonar.core.component.ProjectRefentialsComponentDto;
 
 import javax.annotation.CheckForNull;
 
@@ -82,7 +81,7 @@ public interface ComponentMapper {
   /**
    * Return all modules children (not returning itself) from a module key
    */
-  List<ProjectRefentialsComponentDto> findChildrenModulesFromModule(@Param("moduleKey") String moduleKey);
+  List<ComponentDto> findChildrenModulesFromModule(@Param("moduleKey") String moduleKey);
 
   long countById(long id);
 
index a06112e2597ad6bacc109de437b2c4bbd1d61f70..2f3fdafe259d6ff54038b9bbfe396514255564d7 100644 (file)
@@ -36,7 +36,6 @@ import org.sonar.core.activity.db.ActivityDto;
 import org.sonar.core.activity.db.ActivityMapper;
 import org.sonar.core.cluster.WorkQueue;
 import org.sonar.core.component.ComponentDto;
-import org.sonar.core.component.ProjectRefentialsComponentDto;
 import org.sonar.core.component.SnapshotDto;
 import org.sonar.core.component.db.ComponentMapper;
 import org.sonar.core.component.db.SnapshotMapper;
@@ -131,7 +130,6 @@ public class MyBatis implements BatchComponent, ServerComponent {
     loadAlias(conf, "ActiveDashboard", ActiveDashboardDto.class);
     loadAlias(conf, "Author", AuthorDto.class);
     loadAlias(conf, "Component", ComponentDto.class);
-    loadAlias(conf, "ProjectRefentialsComponent", ProjectRefentialsComponentDto.class);
     loadAlias(conf, "Dashboard", DashboardDto.class);
     loadAlias(conf, "Dependency", DependencyDto.class);
     loadAlias(conf, "DuplicationUnit", DuplicationUnitDto.class);
index 2af4bfc0438387b4bd6f87c60d27d8b9c56a500f..2fe0703ec1092b18e86dfa67f4680f38261207af 100644 (file)
     </where>
   </select>
 
-  <select id="findChildrenModulesFromModule" parameterType="String" resultType="ProjectRefentialsComponent">
-    SELECT <include refid="componentColumns"/>, parent.kee as parentModuleKey
+  <select id="findChildrenModulesFromModule" parameterType="String" resultType="Component">
+    SELECT <include refid="componentColumns"/>
     FROM projects p
     INNER JOIN (<include refid="org.sonar.core.component.db.SnapshotMapper.selectChildrenModulesFromModuleQuery" />) snapshotModules on snapshotModules.resourceId=p.id
-    LEFT OUTER JOIN snapshots parent_snapshot on parent_snapshot.id = snapshotModules.parentId
-    LEFT OUTER JOIN projects parent on parent.id = parent_snapshot.project_id
   </select>
 
   <select id="findProjectUuids" resultType="String">