aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-12-30 19:20:20 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-12-30 19:20:20 +0100
commitfaea9ba2b320ddbce864c5f3f0c4e29cc477f800 (patch)
treefd42f67e9b563f960aebf362c26921bf82ec9456
parent5fdff45fc6e56b5240e619d296d9975a317b94ea (diff)
downloadsonarqube-faea9ba2b320ddbce864c5f3f0c4e29cc477f800.tar.gz
sonarqube-faea9ba2b320ddbce864c5f3f0c4e29cc477f800.zip
SONAR-5849 Improve the way to get modules tree by using components.moduleUuid
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsLoader.java39
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java3
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java5
-rw-r--r--sonar-core/src/main/java/org/sonar/core/component/ProjectRefentialsComponentDto.java37
-rw-r--r--sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java3
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java2
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml6
7 files changed, 26 insertions, 69 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsLoader.java b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsLoader.java
index dbff7696929..4579670fe93 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsLoader.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsLoader.java
@@ -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));
}
-
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java b/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java
index 69e3ec3dfa8..d6693eae1c7 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java
@@ -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);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java
index b49a2009645..8e3532cbe8e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java
@@ -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
index e531993ce5d..00000000000
--- a/sonar-core/src/main/java/org/sonar/core/component/ProjectRefentialsComponentDto.java
+++ /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;
- }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java b/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java
index 789af967e65..b37a53f6b52 100644
--- a/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java
@@ -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);
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
index a06112e2597..2f3fdafe259 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
@@ -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);
diff --git a/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml b/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml
index 2af4bfc0438..2fe0703ec10 100644
--- a/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml
@@ -132,12 +132,10 @@
</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">