aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-07-09 14:16:47 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-07-16 12:02:21 +0200
commitf934d2e752010579ab72be6ca61993766a2e7951 (patch)
treeb6e4a398737fe7750eb70441644bdfba25a57327 /sonar-db
parentcbc7832b745ae07fee7a1f6200eb9aa8aa0a7c75 (diff)
downloadsonarqube-f934d2e752010579ab72be6ca61993766a2e7951.tar.gz
sonarqube-f934d2e752010579ab72be6ca61993766a2e7951.zip
SONAR-6702 Reactivate previously removed components
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java11
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java13
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml7
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java13
4 files changed, 26 insertions, 18 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java
index 5f4f6817570..6f30ebec41a 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java
@@ -118,12 +118,15 @@ public class ComponentDao implements Dao {
});
}
- public List<ComponentDto> selectComponentsFromProjectKey(DbSession session, String projectKey) {
- return mapper(session).selectComponentsFromProjectKeyAndScope(projectKey, null);
+ /**
+ * Return all components of a project (including disable ones)
+ */
+ public List<ComponentDto> selectAllComponentsFromProjectKey(DbSession session, String projectKey) {
+ return mapper(session).selectComponentsFromProjectKeyAndScope(projectKey, null, false);
}
- public List<ComponentDto> selectModulesFromProjectKey(DbSession session, String projectKey) {
- return mapper(session).selectComponentsFromProjectKeyAndScope(projectKey, Scopes.PROJECT);
+ public List<ComponentDto> selectEnabledModulesFromProjectKey(DbSession session, String projectKey) {
+ return mapper(session).selectComponentsFromProjectKeyAndScope(projectKey, Scopes.PROJECT, true);
}
public List<ComponentDto> selectByKeys(DbSession session, Collection<String> keys) {
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java
index ac38353e9a6..e8440633cd5 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java
@@ -64,7 +64,7 @@ public interface ComponentMapper {
* Return all descendant modules (including itself) from a given component uuid and scope
*/
List<ComponentDto> selectDescendantModules(@Param("moduleUuid") String moduleUuid, @Param(value = "scope") String scope,
- @Param(value = "excludeDisabled") boolean excludeDisabled);
+ @Param(value = "excludeDisabled") boolean excludeDisabled);
/**
* Return all files from a given project uuid and scope
@@ -75,19 +75,22 @@ public interface ComponentMapper {
* Return all descendant files from a given module uuid and scope
*/
List<FilePathWithHashDto> selectDescendantFiles(@Param("moduleUuid") String moduleUuid, @Param(value = "scope") String scope,
- @Param(value = "excludeDisabled") boolean excludeDisabled);
+ @Param(value = "excludeDisabled") boolean excludeDisabled);
/**
* Return uuids and project uuids from list of qualifiers
- *
+ * <p/>
* It's using a join on snapshots in order to use he indexed columns snapshots.qualifier
*/
List<UuidWithProjectUuidDto> selectUuidsForQualifiers(@Param("qualifiers") String... qualifiers);
/**
- * Return all components of a project
+ * Return components of a given scope of a project
+ *
+ * @param scope scope of components to return. If null, all components are returned
*/
- List<ComponentDto> selectComponentsFromProjectKeyAndScope(@Param("projectKey") String projectKey, @Nullable @Param("scope") String scope);
+ List<ComponentDto> selectComponentsFromProjectKeyAndScope(@Param("projectKey") String projectKey, @Nullable @Param("scope") String scope,
+ @Param(value = "excludeDisabled") boolean excludeDisabled);
/**
* Return technical projects from a view or a sub-view
diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index 19740c7f76e..6dfe75658ea 100644
--- a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -139,8 +139,7 @@
</select>
<sql id="modulesTreeQuery">
- INNER JOIN projects module ON module.project_uuid = p.project_uuid AND module.uuid = #{moduleUuid} AND
- module.scope='PRJ' AND module.enabled = ${_true}
+ INNER JOIN projects module ON module.project_uuid = p.project_uuid AND module.uuid = #{moduleUuid} AND module.scope='PRJ' AND module.enabled = ${_true}
<where>
<if test="excludeDisabled">
p.enabled = ${_true}
@@ -215,7 +214,9 @@
FROM projects p
INNER JOIN projects root ON root.uuid=p.project_uuid AND root.kee=#{projectKey}
<where>
- AND p.enabled=${_true}
+ <if test="excludeDisabled">
+ p.enabled = ${_true}
+ </if>
<if test="scope != null">
AND p.scope=#{scope}
</if>
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index 53715a0bf61..b1e97c6ea72 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -420,23 +420,24 @@ public class ComponentDaoTest {
}
@Test
- public void select_components_from_project() {
+ public void select_all_components_from_project() {
db.prepareDbUnit(getClass(), "multi-modules.xml");
- List<ComponentDto> components = sut.selectComponentsFromProjectKey(db.getSession(), "org.struts:struts");
- assertThat(components).hasSize(5);
+ List<ComponentDto> components = sut.selectAllComponentsFromProjectKey(db.getSession(), "org.struts:struts");
+ // Removed components are included
+ assertThat(components).hasSize(8);
- assertThat(sut.selectComponentsFromProjectKey(db.getSession(), "UNKNOWN")).isEmpty();
+ assertThat(sut.selectAllComponentsFromProjectKey(db.getSession(), "UNKNOWN")).isEmpty();
}
@Test
public void select_modules_from_project() {
db.prepareDbUnit(getClass(), "multi-modules.xml");
- List<ComponentDto> components = sut.selectModulesFromProjectKey(db.getSession(), "org.struts:struts");
+ List<ComponentDto> components = sut.selectEnabledModulesFromProjectKey(db.getSession(), "org.struts:struts");
assertThat(components).hasSize(3);
- assertThat(sut.selectModulesFromProjectKey(db.getSession(), "UNKNOWN")).isEmpty();
+ assertThat(sut.selectEnabledModulesFromProjectKey(db.getSession(), "UNKNOWN")).isEmpty();
}
@Test