}
List<ComponentDto> moduleChildren = dbClient.componentDao().findChildrenModulesFromModule(session, query.getModuleKey());
- moduleChildren.add(module);
Map<String, String> moduleUuidsByKey = moduleUuidsByKey(module, moduleChildren);
Map<String, Long> moduleIdsByKey = moduleIdsByKey(module, moduleChildren);
- List<PropertyDto> moduleSettings = dbClient.propertiesDao().selectProjectProperties(query.getModuleKey(), session);
- List<PropertyDto> moduleChildrenSettings = newArrayList();
- if (!moduleChildren.isEmpty()) {
- moduleChildrenSettings = dbClient.propertiesDao().findChildrenModuleProperties(query.getModuleKey(), session);
- }
- TreeModuleSettings treeModuleSettings = new TreeModuleSettings(moduleUuidsByKey, moduleIdsByKey, moduleChildren, moduleChildrenSettings, module, moduleSettings);
+ List<PropertyDto> moduleChildrenSettings = dbClient.propertiesDao().findChildrenModuleProperties(query.getModuleKey(), session);
+ TreeModuleSettings treeModuleSettings = new TreeModuleSettings(moduleUuidsByKey, moduleIdsByKey, moduleChildren, moduleChildrenSettings, module);
addSettingsToChildrenModules(ref, query.getModuleKey(), Maps.<String, String>newHashMap(), treeModuleSettings, hasScanPerm, session);
addFileData(session, ref, moduleChildren, module.key());
private Multimap<String, ComponentDto> moduleChildrenByModuleUuid;
private TreeModuleSettings(Map<String, String> moduleUuidsByKey, Map<String, Long> moduleIdsByKey, List<ComponentDto> moduleChildren,
- List<PropertyDto> moduleChildrenSettings, ComponentDto module, List<PropertyDto> moduleSettings) {
+ List<PropertyDto> moduleChildrenSettings, ComponentDto module) {
this.moduleIdsByKey = moduleIdsByKey;
this.moduleUuidsByKey = moduleUuidsByKey;
propertiesByModuleId = ArrayListMultimap.create();
for (PropertyDto settings : moduleChildrenSettings) {
propertiesByModuleId.put(settings.getResourceId(), settings);
}
- propertiesByModuleId.putAll(module.getId(), moduleSettings);
for (ComponentDto componentDto : moduleChildren) {
String moduleUuid = componentDto.moduleUuid();
return mapper(session).selectSnapshotAndChildrenOfScope(snapshot.getId(), Scopes.PROJECT);
}
- /**
- * Return all snapshots children (not returning itself) from a module key
- */
- public List<SnapshotDto> findChildrenModulesFromModule(DbSession session, String moduleKey) {
- return mapper(session).selectChildrenModulesFromModule(moduleKey, Scopes.PROJECT);
- }
-
public int updateSnapshotAndChildrenLastFlagAndStatus(DbSession session, SnapshotDto snapshot, boolean isLast, String status) {
Long rootId = snapshot.getId();
String path = snapshot.getPath() + snapshot.getId() + ".%";
ComponentDto project = ComponentTesting.newProjectDto();
tester.get(DbClient.class).componentDao().insert(dbSession, project);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForProject(project));
addDefaultProfile();
// Project properties
ComponentDto project = ComponentTesting.newProjectDto();
tester.get(DbClient.class).componentDao().insert(dbSession, project);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForProject(project));
addDefaultProfile();
// Project properties
ComponentDto project = ComponentTesting.newProjectDto();
tester.get(DbClient.class).componentDao().insert(dbSession, project);
- SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, projectSnapshot);
addDefaultProfile();
// Project properties
ComponentDto module = ComponentTesting.newModuleDto(project);
tester.get(DbClient.class).componentDao().insert(dbSession, module);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module, projectSnapshot));
// Module properties
tester.get(DbClient.class).propertiesDao().setProperty(
ComponentDto project = ComponentTesting.newProjectDto();
tester.get(DbClient.class).componentDao().insert(dbSession, project);
- SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, projectSnapshot);
addDefaultProfile();
// Project properties
ComponentDto module = ComponentTesting.newModuleDto(project);
tester.get(DbClient.class).componentDao().insert(dbSession, module);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module, projectSnapshot));
// No property on module -> should have the same as project
ComponentDto project = ComponentTesting.newProjectDto();
tester.get(DbClient.class).componentDao().insert(dbSession, project);
- SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, projectSnapshot);
addDefaultProfile();
// Project properties
ComponentDto module = ComponentTesting.newModuleDto(project);
tester.get(DbClient.class).componentDao().insert(dbSession, module);
- SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, projectSnapshot);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
// Module properties
tester.get(DbClient.class).propertiesDao().setProperty(
ComponentDto subModule = ComponentTesting.newModuleDto(module);
tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, moduleSnapshot));
// Sub module properties
tester.get(DbClient.class).propertiesDao().setProperty(
ComponentDto project = ComponentTesting.newProjectDto();
tester.get(DbClient.class).componentDao().insert(dbSession, project);
- SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, projectSnapshot);
addDefaultProfile();
// Project properties
ComponentDto module1 = ComponentTesting.newModuleDto(project);
tester.get(DbClient.class).componentDao().insert(dbSession, module1);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module1, projectSnapshot));
// Module 1 properties
tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module1.getId()), dbSession);
ComponentDto module2 = ComponentTesting.newModuleDto(project);
tester.get(DbClient.class).componentDao().insert(dbSession, module2);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module2, projectSnapshot));
// Module 2 property
tester.get(DbClient.class).propertiesDao()
ComponentDto project = ComponentTesting.newProjectDto();
tester.get(DbClient.class).componentDao().insert(dbSession, project);
- SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, projectSnapshot);
addDefaultProfile();
// No project properties
ComponentDto module = ComponentTesting.newModuleDto(project);
tester.get(DbClient.class).componentDao().insert(dbSession, module);
- SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, projectSnapshot);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
// No module properties
ComponentDto subModule = ComponentTesting.newModuleDto(module);
tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, moduleSnapshot));
// Sub module properties
tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(subModule.getId()), dbSession);
ComponentDto project = ComponentTesting.newProjectDto();
tester.get(DbClient.class).componentDao().insert(dbSession, project);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForProject(project));
QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(
DateUtils.formatDateTime(ruleUpdatedAt));
ComponentDto project = ComponentTesting.newProjectDto();
tester.get(DbClient.class).componentDao().insert(dbSession, project);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForProject(project));
QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(
DateUtils.formatDateTime(ruleUpdatedAt));
ComponentDto project = ComponentTesting.newProjectDto();
tester.get(DbClient.class).componentDao().insert(dbSession, project);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForProject(project));
QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(
DateUtils.formatDateTime(ruleUpdatedAt));
ComponentDto project = ComponentTesting.newProjectDto();
tester.get(DbClient.class).componentDao().insert(dbSession, project);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForProject(project));
QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(
DateUtils.formatDateTime(ruleUpdatedAt));
}
@Test
- public void add_file_data() throws Exception {
+ public void add_file_data_on_single_project() throws Exception {
MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
ComponentDto project = ComponentTesting.newProjectDto();
tester.get(DbClient.class).componentDao().insert(dbSession, project);
- SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, projectSnapshot);
addDefaultProfile();
ComponentDto file = ComponentTesting.newFileDto(project, "file");
tester.get(DbClient.class).componentDao().insert(dbSession, file);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(file, projectSnapshot));
- tester.get(FileSourceDao.class).insert(new FileSourceDto()
- .setFileUuid(file.uuid())
- .setProjectUuid(project.uuid())
- .setData(",,,,,,,,,,,,,,,unchanged ,,,,,,,,,,,,,,,content ")
- .setDataHash("0263047cd758c68c27683625f072f010")
- .setLineHashes("8d7b3d6b83c0a517eac07e1aac94b773")
- .setCreatedAt(new Date().getTime())
- .setUpdatedAt(new Date().getTime())
- .setSrcHash("123456")
- );
+ tester.get(FileSourceDao.class).insert(newFileSourceDto(file).setSrcHash("123456"));
dbSession.commit();
assertThat(fileData.hash()).isEqualTo("123456");
}
+ @Test
+ public void add_file_data_on_multi_modules() throws Exception {
+ MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+
+ ComponentDto project = ComponentTesting.newProjectDto();
+ tester.get(DbClient.class).componentDao().insert(dbSession, project);
+ addDefaultProfile();
+
+ // File on project
+ ComponentDto projectFile = ComponentTesting.newFileDto(project, "projectFile");
+ tester.get(DbClient.class).componentDao().insert(dbSession, projectFile);
+ tester.get(FileSourceDao.class).insert(newFileSourceDto(projectFile).setSrcHash("123456"));
+
+ ComponentDto module = ComponentTesting.newModuleDto(project);
+ tester.get(DbClient.class).componentDao().insert(dbSession, module);
+
+ // File on module
+ ComponentDto moduleFile = ComponentTesting.newFileDto(module, "moduleFile");
+ tester.get(DbClient.class).componentDao().insert(dbSession, moduleFile);
+ tester.get(FileSourceDao.class).insert(newFileSourceDto(moduleFile).setSrcHash("789456"));
+
+ dbSession.commit();
+
+ ProjectReferentials ref = loader.load(ProjectRepositoryQuery.create().setModuleKey(project.key()));
+ assertThat(ref.fileData(project.key(), projectFile.path()).hash()).isEqualTo("123456");
+ assertThat(ref.fileData(module.key(), moduleFile.path()).hash()).isEqualTo("789456");
+ }
+
private void addDefaultProfile() {
QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(
DateUtils.formatDateTime(new Date()));
tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.profile.xoo").setValue("SonarQube way"), dbSession);
}
+ private FileSourceDto newFileSourceDto(ComponentDto file) {
+ return new FileSourceDto()
+ .setFileUuid(file.uuid())
+ .setProjectUuid(file.projectUuid())
+ .setData(",,,,,,,,,,,,,,,unchanged ,,,,,,,,,,,,,,,content ")
+ .setDataHash("0263047cd758c68c27683625f072f010")
+ .setLineHashes("8d7b3d6b83c0a517eac07e1aac94b773")
+ .setCreatedAt(new Date().getTime())
+ .setUpdatedAt(new Date().getTime())
+ .setSrcHash("123456");
+ }
+
}
// From root project
List<ComponentDto> modules = dao.findChildrenModulesFromModule(session, "org.struts:struts");
- assertThat(modules).extracting("uuid").containsOnly("EFGH", "FGHI");
+ assertThat(modules).extracting("uuid").containsOnly("ABCD", "EFGH", "FGHI");
// From module
modules = dao.findChildrenModulesFromModule(session, "org.struts:struts-core");
- assertThat(modules).extracting("uuid").containsOnly("FGHI");
+ assertThat(modules).extracting("uuid").containsOnly("EFGH", "FGHI");
// From sub module
modules = dao.findChildrenModulesFromModule(session, "org.struts:struts-data");
- assertThat(modules).isEmpty();
+ assertThat(modules).extracting("uuid").containsOnly("FGHI");
+
+ // Folder
+ assertThat(dao.findChildrenModulesFromModule(session, "org.struts:struts-core:src/org/struts")).isEmpty();
+ assertThat(dao.findChildrenModulesFromModule(session, "unknown")).isEmpty();
}
@Test
- public void findFilesFromModule() throws Exception {
- setupData("multi-modules", "files_hashes");
+ public void find_files_from_module() throws Exception {
+ setupData("find_files_from_module");
// From root project
List<FilePathWithHashDto> files = dao.findFilesFromModule(session, "org.struts:struts");
- assertThat(files).extracting("uuid").containsOnly("HIJK");
- assertThat(files).extracting("moduleUuid").containsOnly("FGHI");
- assertThat(files).extracting("srcHash").containsOnly("123456");
- assertThat(files).extracting("path").containsOnly("src/org/struts/RequestContext.java");
+ 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
files = dao.findFilesFromModule(session, "org.struts:struts-core");
- assertThat(files).extracting("uuid").containsOnly("HIJK");
- assertThat(files).extracting("moduleUuid").containsOnly("FGHI");
- assertThat(files).extracting("srcHash").containsOnly("123456");
- assertThat(files).extracting("path").containsOnly("src/org/struts/RequestContext.java");
+ 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 sub module
files = dao.findFilesFromModule(session, "org.struts:struts-data");
assertThat(files).extracting("uuid").containsOnly("HIJK");
assertThat(files).extracting("moduleUuid").containsOnly("FGHI");
- assertThat(files).extracting("srcHash").containsOnly("123456");
+ assertThat(files).extracting("srcHash").containsOnly("srcHIJK");
assertThat(files).extracting("path").containsOnly("src/org/struts/RequestContext.java");
- // From unknown
+ // From directory
+ assertThat(dao.findFilesFromModule(session, "org.struts:struts-core:src/org/struts")).isEmpty();
+
assertThat(dao.findFilesFromModule(session, "unknown")).isEmpty();
}
assertThat(snapshots).extracting("id").containsOnly(1L, 6L);
}
- @Test
- public void find_children_modules() {
- setupData("modules");
-
- // From root project
- List<SnapshotDto> snapshots = sut.findChildrenModulesFromModule(session, "org.struts:struts");
- assertThat(snapshots).hasSize(2);
- assertThat(snapshots).extracting("id").containsOnly(2L, 3L);
- assertThat(snapshots).extracting("last").containsOnly(true);
-
- // From module
- snapshots = sut.findChildrenModulesFromModule(session, "org.struts:struts-core");
- assertThat(snapshots).hasSize(1);
- assertThat(snapshots).extracting("id").containsOnly(3L);
-
- // From sub module
- snapshots = sut.findChildrenModulesFromModule(session, "org.struts:struts-data");
- assertThat(snapshots).isEmpty();
- }
-
@Test
public void set_snapshot_and_children_to_false_and_status_processed() {
setupData("snapshots");
+++ /dev/null
-<dataset>
-
- <file_sources id="101" project_uuid="ABCD" file_uuid="HIJK"
- data=",,,,,,,,,,,,,,,unchanged ,,,,,,,,,,,,,,,content "
- line_hashes="8d7b3d6b83c0a517eac07e1aac94b773 9a0364b9e99bb480dd25e1f0284c8555"
- data_hash="0263047cd758c68c27683625f072f010"
- src_hash="123456"
- created_at="1412952242000" updated_at="1412952242000"/>
-
-</dataset>
--- /dev/null
+<dataset>
+
+ <!-- root project -->
+ <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+ uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="[null]"
+ description="the description" long_name="Apache Struts"
+ enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]" authorization_updated_at="[null]"/>
+
+ <!-- module -->
+ <projects id="2" root_id="1" kee="org.struts:struts-core" name="Struts Core"
+ uuid="EFGH" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="ABCD"
+ scope="PRJ" qualifier="BRC" long_name="Struts Core"
+ description="[null]" enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" authorization_updated_at="[null]"/>
+
+ <!-- file attached directly on module -->
+ <projects id="3" scope="FIL" qualifier="FIL" kee="org.struts:struts-core:pom.xml"
+ uuid="EFGHI" project_uuid="ABCD" module_uuid="EFGH" module_uuid_path="ABCD.EFGH"
+ name="pom.xml" long_name="pom.xml" root_id="3"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="src/org/struts/pom.xml" authorization_updated_at="[null]"/>
+
+ <file_sources id="101" project_uuid="ABCD" file_uuid="EFGHI"
+ data=",,,,,,,,,,,,,,,unchanged ,,,,,,,,,,,,,,,content "
+ line_hashes="lineEFGHI"
+ data_hash="dataEFGHI"
+ src_hash="srcEFGHI"
+ created_at="1412952242000" updated_at="1412952242000"/>
+
+ <!-- sub module -->
+ <projects id="4" root_id="1" kee="org.struts:struts-data" name="Struts Data"
+ uuid="FGHI" project_uuid="ABCD" module_uuid="EFGH" module_uuid_path="ABCD.EFGH"
+ scope="PRJ" qualifier="BRC" long_name="Struts Data"
+ description="[null]" enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" authorization_updated_at="[null]"/>
+
+ <!-- directory -->
+ <projects id="5" scope="DIR" qualifier="DIR" kee="org.struts:struts-core:src/org/struts"
+ uuid="GHIJ" project_uuid="ABCD" module_uuid="FGHI" module_uuid_path="ABCD.EFGH.FGHI"
+ name="src/org/struts" long_name="org.struts" root_id="3"
+ description="[null]"
+ enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/org/struts" authorization_updated_at="[null]"/>
+
+ <!-- file -->
+ <projects id="6" scope="FIL" qualifier="FIL" kee="org.struts:struts-core:src/org/struts/RequestContext.java"
+ uuid="HIJK" project_uuid="ABCD" module_uuid="FGHI" module_uuid_path="ABCD.EFGH.FGHI"
+ name="RequestContext.java" long_name="org.struts.RequestContext" root_id="3"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="src/org/struts/RequestContext.java" authorization_updated_at="[null]"/>
+
+ <file_sources id="102" project_uuid="ABCD" file_uuid="HIJK"
+ data=",,,,,,,,,,,,,,,unchanged ,,,,,,,,,,,,,,,content "
+ line_hashes="lineHIJK"
+ data_hash="dataHIJK"
+ src_hash="srcHIJK"
+ created_at="1412952242000" updated_at="1412952242000"/>
+
+</dataset>
<dataset>
- <!-- Struts projects is authorized for all user -->
- <group_roles id="1" group_id="[null]" resource_id="1" role="user"/>
-
-
<!-- root project -->
<projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="[null]"
List<String> findProjectUuids();
/**
- * Return all modules children (not returning itself) from a module key
+ * Return all modules children (including itself) from a module key
*/
List<ComponentDto> findChildrenModulesFromModule(@Param("moduleKey") String moduleKey, @Param(value = "scope") String scope);
List<SnapshotDto> selectSnapshotAndChildrenOfScope(@Param(value = "snapshot") Long resourceId, @Param(value = "scope") String scope);
- List<SnapshotDto> selectChildrenModulesFromModule(@Param(value = "moduleKey") String moduleKey, @Param(value = "scope") String scope);
-
int updateSnapshotAndChildrenLastFlagAndStatus(@Param(value = "root") Long rootId, @Param(value = "pathRootId") Long pathRootId,
@Param(value = "path") String path, @Param(value = "isLast") boolean isLast, @Param(value = "status") String status);
<select id="findChildrenModulesFromModule" parameterType="map" 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
+ <include refid="childrenModuleQuery"/>
+ </select>
+
+ <sql id="childrenModuleQuery">
+ 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.enabled = TRUE AND module.kee = #{moduleKey}
<where>
- AND p.enabled=${_true}
+ p.enabled = ${_true}
+ AND p.scope = #{scope}
+ AND (p.uuid = module.uuid OR p.project_uuid = module.uuid
+ OR
+ <choose>
+ <when test="_databaseId == 'mssql'">
+ p.module_uuid_path LIKE module.module_uuid_path + '.' + module.uuid + '%'
+ </when>
+ <when test="_databaseId == 'mysql'">
+ p.module_uuid_path LIKE concat(module.module_uuid_path, '.', module.uuid, '%')
+ </when>
+ <otherwise>
+ p.module_uuid_path LIKE module.module_uuid_path || '.' || module.uuid || '%'
+ </otherwise>
+ </choose>
+ )
</where>
- </select>
+ </sql>
<select id="findFilesFromModule" parameterType="map" resultType="FilePathWithHash">
SELECT p.uuid, p.path, p.module_uuid as moduleUuid, fs.src_hash as srcHash
FROM projects p
- INNER JOIN (<include refid="org.sonar.core.component.db.SnapshotMapper.selectChildrenModulesFromModuleQuery"/>) snapshotModules ON snapshotModules.resourceId=p.id
INNER JOIN file_sources fs ON fs.file_uuid=p.uuid
- <where>
- AND p.enabled=${_true}
- </where>
+ <include refid="childrenModuleQuery"/>
</select>
<select id="findProjectUuids" resultType="String">
AND (s.id = #{snapshot} or s.root_snapshot_id = #{snapshot})
</select>
- <select id="selectChildrenModulesFromModule" parameterType="map" resultType="Snapshot">
- <include refid="selectChildrenModulesFromModuleQuery" />
- </select>
-
- <sql id="selectChildrenModulesFromModuleQuery">
- SELECT <include refid="org.sonar.core.component.db.SnapshotMapper.snapshotColumns"/>
- FROM snapshots s
- INNER JOIN snapshots root_snapshot ON root_snapshot.id = s.root_snapshot_id AND root_snapshot.islast = ${_true}
- INNER JOIN snapshots current_snapshot ON current_snapshot.root_project_id = root_snapshot.project_id AND s.islast = ${_true}
- INNER JOIN projects module ON module.id = current_snapshot.project_id AND module.enabled = ${_true} AND module.kee = #{moduleKey}
- <where>
- AND s.islast = ${_true}
- AND s.scope = #{scope}
- AND <choose>
- <when test="_databaseId == 'mssql'">
- s.path LIKE current_snapshot.path + CAST(current_snapshot.id AS varchar(15)) + '.%'
- </when>
- <when test="_databaseId == 'mysql'">
- s.path LIKE concat(current_snapshot.path, current_snapshot.id, '.%')
- </when>
- <otherwise>
- s.path LIKE current_snapshot.path || current_snapshot.id || '.%'
- </otherwise>
- </choose>
- </where>
- </sql>
-
<sql id="insertColumns">
(parent_snapshot_id, root_snapshot_id, root_project_id, project_id, created_at, build_date, status, purge_status,
islast, scope, qualifier, version, path, depth,
<select id="selectChildrenModuleProperties" parameterType="String" resultType="Property">
SELECT prop.id as id, prop.prop_key as "key", prop.text_value as value, prop.resource_id as resourceId, prop.user_id as userId
FROM properties prop
- INNER JOIN (<include refid="org.sonar.core.component.db.SnapshotMapper.selectChildrenModulesFromModuleQuery" />) snapshotModules on snapshotModules.resourceId=prop.resource_id
+ INNER JOIN (SELECT p.id FROM projects p<include refid="org.sonar.core.component.db.ComponentMapper.childrenModuleQuery"/>) modules on modules.id=prop.resource_id
INNER JOIN projects p on p.id = prop.resource_id
WHERE prop.user_id IS NULL
</select>
setupData("select_children_module_properties");
List<PropertyDto> properties = dao.findChildrenModuleProperties("org.struts:struts", session);
- assertThat(properties.size(), is(3));
- assertThat(properties).extracting("key").containsOnly("core.one", "core.two", "data.one");
+ assertThat(properties.size(), is(4));
+ assertThat(properties).extracting("key").containsOnly("struts.one", "core.one", "core.two", "data.one");
assertThat(properties).extracting("value").containsOnly("one", "two");
properties = dao.findChildrenModuleProperties("org.struts:struts-core", session);
+ assertThat(properties.size(), is(3));
+ assertThat(properties).extracting("key").containsOnly("core.one", "core.two", "data.one");
+
+ properties = dao.findChildrenModuleProperties("org.struts:struts-data", session);
assertThat(properties.size(), is(1));
assertThat(properties).extracting("key").containsOnly("data.one");
- assertThat(dao.findChildrenModuleProperties("org.struts:struts-data", session).size(), is(0));
+ assertThat(dao.findChildrenModuleProperties("unknown", session).size(), is(0));
}
@Test
uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="[null]"
description="the description" long_name="Apache Struts"
enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]" authorization_updated_at="[null]" />
- <snapshots id="1" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- status="P" islast="[true]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
- version="[null]" path=""/>
- <snapshots id="10" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- status="P" islast="[false]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-01 13:58:00.00" build_date="2008-12-01 13:58:00.00"
- version="[null]" path=""/>
<!-- module -->
<projects id="2" root_id="1" kee="org.struts:struts-core" name="Struts Core"
- uuid="EFGH" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="ABCD."
+ uuid="EFGH" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="ABCD"
scope="PRJ" qualifier="BRC" long_name="Struts Core"
description="[null]" enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" authorization_updated_at="[null]" />
- <snapshots id="2" project_id="2" parent_snapshot_id="1" root_project_id="1" root_snapshot_id="1"
- status="P" islast="[true]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="PRJ" qualifier="BRC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
- version="[null]" path="1."/>
<!-- sub module -->
<projects id="3" root_id="1" kee="org.struts:struts-data" name="Struts Data"
- uuid="FGHI" project_uuid="ABCD" module_uuid="EFGH" module_uuid_path="ABCD.EFGH."
+ uuid="FGHI" project_uuid="ABCD" module_uuid="EFGH" module_uuid_path="ABCD.EFGH"
scope="PRJ" qualifier="BRC" long_name="Struts Data"
description="[null]" enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" authorization_updated_at="[null]" />
- <snapshots id="3" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
- status="P" islast="[true]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="PRJ" qualifier="BRC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
- version="[null]" path="1.2."/>
<!-- directory -->
<projects long_name="org.struts" id="4" scope="DIR" qualifier="DIR" kee="org.struts:struts-core:src/org/struts"
- uuid="GHIJ" project_uuid="ABCD" module_uuid="FGHI" module_uuid_path="ABCD.EFGH.FGHI."
+ uuid="GHIJ" project_uuid="ABCD" module_uuid="FGHI" module_uuid_path="ABCD.EFGH.FGHI"
name="src/org/struts" root_id="3"
description="[null]"
enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/org/struts" authorization_updated_at="[null]" />
- <snapshots id="4" project_id="4" parent_snapshot_id="3" root_project_id="1" root_snapshot_id="1"
- status="P" islast="[true]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="DIR" qualifier="PAC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
- version="[null]" path="1.2.3."/>
<!-- file -->
<projects long_name="org.struts.RequestContext" id="5" scope="FIL" qualifier="FIL" kee="org.struts:struts-core:src/org/struts/RequestContext.java"
- uuid="HIJK" project_uuid="ABCD" module_uuid="GHIJ" module_uuid_path="ABCD.EFGH.FGHI.GHIJ."
+ uuid="HIJK" project_uuid="ABCD" module_uuid="GHIJ" module_uuid_path="ABCD.EFGH.FGHI"
name="RequestContext.java" root_id="3"
description="[null]"
enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="src/org/struts/RequestContext.java" authorization_updated_at="[null]" />
- <snapshots id="5" project_id="5" parent_snapshot_id="4" root_project_id="1" root_snapshot_id="1"
- status="P" islast="[true]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
- version="[null]" path="1.2.3.4."/>
</dataset>