import org.sonar.api.ServerComponent;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
+import org.sonar.batch.protocol.input.FileData;
import org.sonar.batch.protocol.input.ProjectReferentials;
import org.sonar.core.UtcDateUtils;
import org.sonar.core.component.ComponentDto;
+import org.sonar.core.component.FilePathWithHashDto;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
projectKey = project.key();
}
- List<PropertyDto> moduleSettings = dbClient.propertiesDao().selectProjectProperties(query.getModuleKey(), session);
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(moduleChildren, moduleChildrenSettings, module, moduleSettings);
+ TreeModuleSettings treeModuleSettings = new TreeModuleSettings(moduleUuidsByKey, moduleIdsByKey, moduleChildren, moduleChildrenSettings, module, moduleSettings);
addSettingsToChildrenModules(ref, query.getModuleKey(), Maps.<String, String>newHashMap(), treeModuleSettings, hasScanPerm, session);
+ addFileData(session, ref, moduleChildren, module.key());
} else {
// Add settings of the provisioned project
addSettings(ref, query.getModuleKey(), getPropertiesMap(dbClient.propertiesDao().selectProjectProperties(query.getModuleKey(), session), hasScanPerm));
}
}
+ private void addFileData(DbSession session, ProjectReferentials ref, List<ComponentDto> moduleChildren, String moduleKey) {
+ Map<String, String> moduleKeysByUuid = newHashMap();
+ for (ComponentDto module : moduleChildren) {
+ moduleKeysByUuid.put(module.uuid(), module.key());
+ }
+
+ for (FilePathWithHashDto file : dbClient.componentDao().findFilesFromModule(session, moduleKey)) {
+ FileData fileData = new FileData(file.getSrcHash(), false, null, null, null);
+ ref.addFileData(moduleKeysByUuid.get(file.getModuleUuid()), file.getPath(), fileData);
+ }
+ }
+
private void checkPermission(boolean preview) {
UserSession userSession = UserSession.get();
boolean hasScanPerm = userSession.hasGlobalPermission(GlobalPermissions.SCAN_EXECUTION);
}
}
+ private Map<String, String> moduleUuidsByKey(ComponentDto module, List<ComponentDto> moduleChildren) {
+ Map<String, String> moduleUuidsByKey = newHashMap();
+ for (ComponentDto componentDto : moduleChildren) {
+ moduleUuidsByKey.put(componentDto.key(), componentDto.uuid());
+ }
+ return moduleUuidsByKey;
+ }
+
+ private Map<String, Long> moduleIdsByKey(ComponentDto module, List<ComponentDto> moduleChildren) {
+ Map<String, Long> moduleIdsByKey = newHashMap();
+ for (ComponentDto componentDto : moduleChildren) {
+ moduleIdsByKey.put(componentDto.key(), componentDto.getId());
+ }
+ return moduleIdsByKey;
+ }
+
private static class TreeModuleSettings {
private Map<String, Long> moduleIdsByKey;
private Multimap<Long, PropertyDto> propertiesByModuleId;
private Multimap<String, ComponentDto> moduleChildrenByModuleUuid;
- private TreeModuleSettings(List<ComponentDto> moduleChildren, List<PropertyDto> moduleChildrenSettings, ComponentDto module, List<PropertyDto> moduleSettings) {
+ private TreeModuleSettings(Map<String, String> moduleUuidsByKey, Map<String, Long> moduleIdsByKey, List<ComponentDto> moduleChildren,
+ List<PropertyDto> moduleChildrenSettings, ComponentDto module, List<PropertyDto> moduleSettings) {
+ this.moduleIdsByKey = moduleIdsByKey;
+ this.moduleUuidsByKey = moduleUuidsByKey;
propertiesByModuleId = ArrayListMultimap.create();
- moduleIdsByKey = newHashMap();
- moduleUuidsByKey = newHashMap();
moduleChildrenByModuleUuid = ArrayListMultimap.create();
for (PropertyDto settings : moduleChildrenSettings) {
}
propertiesByModuleId.putAll(module.getId(), moduleSettings);
- moduleIdsByKey.put(module.key(), module.getId());
- 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 {
- moduleChildrenByModuleUuid.put(module.uuid(), componentDto);
}
}
}
- private List<PropertyDto> findModuleSettings(String moduleKey) {
+ List<PropertyDto> findModuleSettings(String moduleKey) {
Long moduleId = moduleIdsByKey.get(moduleKey);
return newArrayList(propertiesByModuleId.get(moduleId));
}
- private List<ComponentDto> findChildrenModule(String moduleKey) {
+ List<ComponentDto> findChildrenModule(String moduleKey) {
String moduleUuid = moduleUuidsByKey.get(moduleKey);
return newArrayList(moduleChildrenByModuleUuid.get(moduleUuid));
}
import com.google.common.collect.Lists;
import org.sonar.api.ServerComponent;
+import org.sonar.api.resources.Scopes;
import org.sonar.api.utils.System2;
import org.sonar.core.component.ComponentDto;
+import org.sonar.core.component.FilePathWithHashDto;
import org.sonar.core.component.db.ComponentMapper;
import org.sonar.core.persistence.DaoComponent;
import org.sonar.core.persistence.DbSession;
}
public List<ComponentDto> findChildrenModulesFromModule(DbSession session, String moduleKey) {
- return mapper(session).findChildrenModulesFromModule(moduleKey);
+ return mapper(session).findChildrenModulesFromModule(moduleKey, Scopes.PROJECT);
+ }
+
+ public List<FilePathWithHashDto> findFilesFromModule(DbSession session, String moduleKey) {
+ return mapper(session).findFilesFromModule(moduleKey, Scopes.FILE);
}
public List<ComponentDto> getByUuids(DbSession session, Collection<String> uuids) {
* Return all snapshots children (not returning itself) from a module key
*/
public List<SnapshotDto> findChildrenModulesFromModule(DbSession session, String moduleKey) {
- return mapper(session).selectChildrenModulesFromModule(moduleKey);
+ return mapper(session).selectChildrenModulesFromModule(moduleKey, Scopes.PROJECT);
}
public int updateSnapshotAndChildrenLastFlagAndStatus(DbSession session, SnapshotDto snapshot, boolean isLast, String status) {
import org.sonar.api.server.rule.RuleParamType;
import org.sonar.api.utils.DateUtils;
import org.sonar.batch.protocol.input.ActiveRule;
+import org.sonar.batch.protocol.input.FileData;
import org.sonar.batch.protocol.input.ProjectReferentials;
import org.sonar.batch.protocol.input.QProfile;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.qualityprofile.db.QualityProfileDto;
import org.sonar.core.rule.RuleDto;
import org.sonar.core.rule.RuleParamDto;
+import org.sonar.core.source.db.FileSourceDao;
+import org.sonar.core.source.db.FileSourceDto;
import org.sonar.server.component.ComponentTesting;
import org.sonar.server.component.SnapshotTesting;
import org.sonar.server.db.DbClient;
}
}
+ @Test
+ public void add_file_data() 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")
+ );
+
+ dbSession.commit();
+
+ ProjectReferentials ref = loader.load(ProjectRepositoryQuery.create().setModuleKey(project.key()));
+ assertThat(ref.fileDataByPath(project.key())).hasSize(1);
+ FileData fileData = ref.fileData(project.key(), file.path());
+ assertThat(fileData.hash()).isEqualTo("123456");
+ }
+
private void addDefaultProfile() {
QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(
DateUtils.formatDateTime(new Date()));
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.System2;
import org.sonar.core.component.ComponentDto;
+import org.sonar.core.component.FilePathWithHashDto;
import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.persistence.DbSession;
import org.sonar.server.exceptions.NotFoundException;
// From root project
List<ComponentDto> modules = dao.findChildrenModulesFromModule(session, "org.struts:struts");
- assertThat(modules).extracting("id").containsOnly(2L, 3L);
+ assertThat(modules).extracting("uuid").containsOnly("EFGH", "FGHI");
// From module
modules = dao.findChildrenModulesFromModule(session, "org.struts:struts-core");
- assertThat(modules).extracting("id").containsOnly(3L);
+ assertThat(modules).extracting("uuid").containsOnly("FGHI");
// From sub module
modules = dao.findChildrenModulesFromModule(session, "org.struts:struts-data");
assertThat(modules).isEmpty();
}
+ @Test
+ public void findFilesFromModule() throws Exception {
+ setupData("multi-modules", "files_hashes");
+
+ // 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");
+
+ // 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");
+
+ // 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("path").containsOnly("src/org/struts/RequestContext.java");
+
+ // From unknown
+ assertThat(dao.findFilesFromModule(session, "unknown")).isEmpty();
+ }
+
@Test
public void insert() {
when(system2.now()).thenReturn(DateUtils.parseDate("2014-06-18").getTime());
--- /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>
<!-- 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"
<!-- 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"
<!-- 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]" />
<!-- 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="FGHI" 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]" />
<!-- 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"
<!-- 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"
<!-- 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]" />
<!-- 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="FGHI" 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]" />
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
/**
* Container for all project data going from server to batch.
private Map<String, Map<String, FileData>> fileDataByModuleAndPath = new HashMap<String, Map<String, FileData>>();
private Date lastAnalysisDate;
- public Map<String, String> settings(String projectKey) {
- return settingsByModule.containsKey(projectKey) ? settingsByModule.get(projectKey) : Collections.<String, String>emptyMap();
+ public Map<String, String> settings(String moduleKey) {
+ return settingsByModule.containsKey(moduleKey) ? settingsByModule.get(moduleKey) : Collections.<String, String>emptyMap();
}
- public ProjectReferentials addSettings(String projectKey, Map<String, String> settings) {
- Map<String, String> existingSettings = settingsByModule.get(projectKey);
+ public ProjectReferentials addSettings(String moduleKey, Map<String, String> settings) {
+ Map<String, String> existingSettings = settingsByModule.get(moduleKey);
if (existingSettings == null) {
- existingSettings = new HashMap<String, String>();
- settingsByModule.put(projectKey, existingSettings);
+ existingSettings = new HashMap<>();
+ settingsByModule.put(moduleKey, existingSettings);
}
existingSettings.putAll(settings);
return this;
return this;
}
- public Map<String, FileData> fileDataByPath(String projectKey) {
- return fileDataByModuleAndPath.containsKey(projectKey) ? fileDataByModuleAndPath.get(projectKey) : Collections.<String, FileData>emptyMap();
+ public Map<String, FileData> fileDataByPath(String moduleKey) {
+ return fileDataByModuleAndPath.containsKey(moduleKey) ? fileDataByModuleAndPath.get(moduleKey) : Collections.<String, FileData>emptyMap();
}
- public ProjectReferentials addFileData(String projectKey, String path, FileData fileData) {
- Map<String, FileData> existingFileDataByPath = fileDataByModuleAndPath.get(projectKey);
+ public ProjectReferentials addFileData(String moduleKey, String path, FileData fileData) {
+ Map<String, FileData> existingFileDataByPath = fileDataByModuleAndPath.get(moduleKey);
if (existingFileDataByPath == null) {
- existingFileDataByPath = new HashMap<String, FileData>();
- fileDataByModuleAndPath.put(projectKey, existingFileDataByPath);
+ existingFileDataByPath = new HashMap<>();
+ fileDataByModuleAndPath.put(moduleKey, existingFileDataByPath);
}
existingFileDataByPath.put(path, fileData);
return this;
--- /dev/null
+/*
+ * 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;
+
+public class FilePathWithHashDto {
+
+ private String uuid;
+ private String moduleUuid;
+ private String path;
+ private String srcHash;
+
+ public String getSrcHash() {
+ return srcHash;
+ }
+
+ public void setSrcHash(String srcHash) {
+ this.srcHash = srcHash;
+ }
+
+ public String getModuleUuid() {
+ return moduleUuid;
+ }
+
+ public void setModuleUuid(String moduleUuid) {
+ this.moduleUuid = moduleUuid;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+}
import org.apache.ibatis.annotations.Param;
import org.sonar.core.component.ComponentDto;
+import org.sonar.core.component.FilePathWithHashDto;
import javax.annotation.CheckForNull;
* Warning, projectId are always null
*/
List<ComponentDto> findByUuids(@Param("uuids") Collection<String> uuids);
+
/**
* Return all project (PRJ/TRK) uuids
*/
/**
* Return all modules children (not returning itself) from a module key
*/
- List<ComponentDto> findChildrenModulesFromModule(@Param("moduleKey") String moduleKey);
+ List<ComponentDto> findChildrenModulesFromModule(@Param("moduleKey") String moduleKey, @Param(value = "scope") String scope);
+
+ /**
+ * Return all files children from a module key
+ */
+ List<FilePathWithHashDto> findFilesFromModule(@Param("moduleKey") String moduleKey, @Param(value = "scope") String scope);
long countById(long id);
List<SnapshotDto> selectSnapshotAndChildrenOfScope(@Param(value = "snapshot") Long resourceId, @Param(value = "scope") String scope);
- List<SnapshotDto> selectChildrenModulesFromModule(@Param(value = "moduleKey") String moduleKey);
+ 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);
int updateSnapshotAndChildrenLastFlag(@Param(value = "root") Long rootId, @Param(value = "pathRootId") Long pathRootId,
- @Param(value = "path") String path, @Param(value = "isLast") boolean isLast);
+ @Param(value = "path") String path, @Param(value = "isLast") boolean isLast);
}
import org.sonar.core.activity.db.ActivityMapper;
import org.sonar.core.cluster.WorkQueue;
import org.sonar.core.component.ComponentDto;
+import org.sonar.core.component.FilePathWithHashDto;
import org.sonar.core.component.SnapshotDto;
import org.sonar.core.component.db.ComponentMapper;
import org.sonar.core.component.db.SnapshotMapper;
loadAlias(conf, "Activity", ActivityDto.class);
loadAlias(conf, "AnalysisReport", AnalysisReportDto.class);
loadAlias(conf, "IdUuidPair", IdUuidPair.class);
+ loadAlias(conf, "FilePathWithHash", FilePathWithHashDto.class);
// AuthorizationMapper has to be loaded before IssueMapper because this last one used it
loadMapper(conf, "org.sonar.core.user.AuthorizationMapper");
import org.apache.ibatis.session.SqlSession;
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
+import org.sonar.api.resources.Scopes;
import org.sonar.core.persistence.DaoComponent;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
}
public List<PropertyDto> findChildrenModuleProperties(String moduleKey, SqlSession session) {
- return session.getMapper(PropertiesMapper.class).selectChildrenModuleProperties(moduleKey);
+ return session.getMapper(PropertiesMapper.class).selectChildrenModuleProperties(moduleKey, Scopes.PROJECT);
}
public PropertyDto selectProjectProperty(long resourceId, String propertyKey) {
List<PropertyDto> selectByQuery(@Param("query") PropertyQuery query);
- List<PropertyDto> selectChildrenModuleProperties(@Param("moduleKey") String moduleKey);
+ List<PropertyDto> selectChildrenModuleProperties(@Param("moduleKey") String moduleKey, @Param(value = "scope") String scope);
void update(PropertyDto property);
</where>
</select>
- <select id="findChildrenModulesFromModule" parameterType="String" resultType="Component">
+ <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
+ INNER JOIN (<include refid="org.sonar.core.component.db.SnapshotMapper.selectChildrenModulesFromModuleQuery"/>) snapshotModules ON snapshotModules.resourceId=p.id
+ <where>
+ AND p.enabled=${_true}
+ </where>
+ </select>
+
+ <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>
</select>
<select id="findProjectUuids" resultType="String">
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 = 'PRJ'
+ AND s.scope = #{scope}
AND <choose>
<when test="_databaseId == 'mssql'">
s.path LIKE current_snapshot.path + CAST(current_snapshot.id AS varchar(15)) + '.%'