import javax.annotation.Nullable;
-import java.util.*;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;
TreeModuleSettings treeModuleSettings = new TreeModuleSettings(moduleUuidsByKey, moduleIdsByKey, modulesTree, modulesTreeSettings, module);
addSettingsToChildrenModules(ref, query.getModuleKey(), Maps.<String, String>newHashMap(), treeModuleSettings, hasScanPerm, session);
- addFileData(session, ref, modulesTree, module.uuid());
+ List<FilePathWithHashDto> files = module.isRootProject() ?
+ dbClient.componentDao().selectEnabledFilesFromProject(session, module.uuid()) :
+ dbClient.componentDao().selectEnabledDescendantFiles(session, module.uuid());
+ addFileData(session, ref, modulesTree, files);
// FIXME need real value but actually only used to know if there is a previous analysis in local issue tracking mode so any value is
// ok
}
}
- private void addFileData(DbSession session, ProjectRepositories ref, List<ComponentDto> moduleChildren, String moduleKey) {
+ private void addFileData(DbSession session, ProjectRepositories ref, List<ComponentDto> moduleChildren, List<FilePathWithHashDto> files) {
Map<String, String> moduleKeysByUuid = newHashMap();
for (ComponentDto module : moduleChildren) {
moduleKeysByUuid.put(module.uuid(), module.key());
}
- for (FilePathWithHashDto file : dbClient.componentDao().selectEnabledDescendantFiles(session, moduleKey)) {
+ for (FilePathWithHashDto file : files) {
// TODO should query E/S to know if blame is missing on this file
FileData fileData = new FileData(file.getSrcHash(), true);
ref.addFileData(moduleKeysByUuid.get(file.getModuleUuid()), file.getPath(), fileData);
return mapper(session).selectDescendantFiles(rootComponentUuid, Scopes.FILE, true);
}
+ public List<FilePathWithHashDto> selectEnabledFilesFromProject(DbSession session, String rootComponentUuid) {
+ return mapper(session).selectEnabledFilesFromProject(rootComponentUuid);
+ }
+
public List<ComponentDto> getByIds(final DbSession session, Collection<Long> ids) {
return DaoUtils.executeLargeInputs(ids, new Function<List<Long>, List<ComponentDto>>() {
@Override
}
@Test
- public void select_enabled_module_files_tree() throws Exception {
+ public void select_enabled_module_files_tree_from_module() throws Exception {
setupData("select_module_files_tree");
// From root project
assertThat(dao.selectEnabledDescendantFiles(session, "unknown")).isEmpty();
}
+ @Test
+ public void select_enabled_module_files_tree_from_project() throws Exception {
+ setupData("select_module_files_tree");
+
+ // From root project
+ List<FilePathWithHashDto> files = dao.selectEnabledFilesFromProject(session, "ABCD");
+ assertThat(files).extracting("uuid").containsOnly("EFGHI", "HIJK");
+ assertThat(files).extracting("moduleUuid").containsOnly("EFGH", "FGHI");
+ assertThat(files).extracting("srcHash").containsOnly("srcEFGHI", "srcHIJK");
+ assertThat(files).extracting("path").containsOnly("src/org/struts/pom.xml", "src/org/struts/RequestContext.java");
+
+ // From module
+ assertThat(dao.selectEnabledFilesFromProject(session, "EFGH")).isEmpty();
+
+ // From sub module
+ assertThat(dao.selectEnabledFilesFromProject(session, "FGHI")).isEmpty();
+
+ // From directory
+ assertThat(dao.selectEnabledFilesFromProject(session, "GHIJ")).isEmpty();
+
+ assertThat(dao.selectEnabledFilesFromProject(session, "unknown")).isEmpty();
+ }
+
@Test
public void insert() {
when(system2.now()).thenReturn(DateUtils.parseDate("2014-06-18").getTime());
* 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 descendant files from a given component uuid and scope
+ * Return all files from a given project uuid and scope
+ */
+ List<FilePathWithHashDto> selectEnabledFilesFromProject(@Param("projectUuid") String projectUuid);
+
+ /**
+ * 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
</select>
<sql id="modulesTreeQuery">
- INNER JOIN projects root_project ON root_project.uuid = p.project_uuid AND root_project.enabled = ${_true}
- INNER JOIN projects module ON module.project_uuid = root_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}
</where>
</sql>
+ <select id="selectEnabledFilesFromProject" parameterType="map" resultType="FilePathWithHash">
+ SELECT p.uuid, p.path, p.module_uuid as moduleUuid, fs.src_hash as srcHash
+ FROM projects p
+ INNER JOIN file_sources fs ON fs.file_uuid=p.uuid
+ <where>
+ AND p.project_uuid=#{projectUuid}
+ AND p.enabled=${_true}
+ AND p.scope='FIL'
+ </where>
+ </select>
+
<select id="selectDescendantFiles" parameterType="map" resultType="FilePathWithHash">
SELECT p.uuid, p.path, p.module_uuid as moduleUuid, fs.src_hash as srcHash
FROM projects p