]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5883 Improve /batch/project WS in order to not always use snapshots in query...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 14 Jan 2015 17:16:44 +0000 (18:16 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 14 Jan 2015 17:16:44 +0000 (18:16 +0100)
15 files changed:
server/sonar-server/src/main/java/org/sonar/server/batch/ProjectRepositoryLoader.java
server/sonar-server/src/main/java/org/sonar/server/component/db/SnapshotDao.java
server/sonar-server/src/test/java/org/sonar/server/batch/ProjectRepositoryLoaderMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java
server/sonar-server/src/test/java/org/sonar/server/component/db/SnapshotDaoTest.java
server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/files_hashes.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/find_files_from_module.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/multi-modules.xml
sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java
sonar-core/src/main/java/org/sonar/core/component/db/SnapshotMapper.java
sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml
sonar-core/src/main/resources/org/sonar/core/component/db/SnapshotMapper.xml
sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml
sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java
sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/select_children_module_properties.xml

index d3b5a31998c482574f502ca777f00992d893b209..90c10f94b5a807193ae129608bfed2acea94c71c 100644 (file)
@@ -92,16 +92,11 @@ public class ProjectRepositoryLoader implements ServerComponent {
           }
 
           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());
@@ -274,7 +269,7 @@ public class ProjectRepositoryLoader implements ServerComponent {
     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();
@@ -283,7 +278,6 @@ public class ProjectRepositoryLoader implements ServerComponent {
       for (PropertyDto settings : moduleChildrenSettings) {
         propertiesByModuleId.put(settings.getResourceId(), settings);
       }
-      propertiesByModuleId.putAll(module.getId(), moduleSettings);
 
       for (ComponentDto componentDto : moduleChildren) {
         String moduleUuid = componentDto.moduleUuid();
index f0afc447e2604279423cd02b4f0f3c6c24b0b64b..5379396bcae59d86cb551d2223621aeef945e604 100644 (file)
@@ -66,13 +66,6 @@ public class SnapshotDao extends BaseDao<SnapshotMapper, SnapshotDto, Long> impl
     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() + ".%";
index 152e50282378c4e56a1b82df7bc44fe7270cb2d5..7e5b2f6cd1f02d8bba074ade2c1a7f8052fccd29 100644 (file)
@@ -90,7 +90,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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
@@ -116,7 +115,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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
@@ -141,8 +139,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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
@@ -153,7 +149,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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(
@@ -181,8 +176,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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
@@ -193,7 +186,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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
 
@@ -216,8 +208,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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
@@ -228,8 +218,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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(
@@ -239,7 +227,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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(
@@ -270,8 +257,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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
@@ -280,7 +265,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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);
@@ -289,7 +273,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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()
@@ -341,20 +324,15 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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);
@@ -497,7 +475,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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));
@@ -522,7 +499,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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));
@@ -547,7 +523,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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));
@@ -634,7 +609,6 @@ public class ProjectRepositoryLoaderMediumTest {
 
     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));
@@ -702,28 +676,16 @@ public class ProjectRepositoryLoaderMediumTest {
   }
 
   @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&#13;&#10;,,,,,,,,,,,,,,,content&#13;&#10;")
-      .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();
 
@@ -733,6 +695,34 @@ public class ProjectRepositoryLoaderMediumTest {
     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()));
@@ -740,4 +730,16 @@ public class ProjectRepositoryLoaderMediumTest {
     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&#13;&#10;,,,,,,,,,,,,,,,content&#13;&#10;")
+      .setDataHash("0263047cd758c68c27683625f072f010")
+      .setLineHashes("8d7b3d6b83c0a517eac07e1aac94b773")
+      .setCreatedAt(new Date().getTime())
+      .setUpdatedAt(new Date().getTime())
+      .setSrcHash("123456");
+  }
+
 }
index aa300d52e2df1445a15de9234adbed1731f4747b..c106145ca0dba37311d5cf92fe90e6211ab5908a 100644 (file)
@@ -337,43 +337,49 @@ public class ComponentDaoTest extends AbstractDaoTestCase {
 
     // 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();
   }
 
index 897b9cf7102566bae0431e39573420d2c1586c72..4b175bf8f449eeaad1b824bd79dea0329b437db0 100644 (file)
@@ -183,26 +183,6 @@ public class SnapshotDaoTest extends AbstractDaoTestCase {
     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");
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/files_hashes.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/files_hashes.xml
deleted file mode 100644 (file)
index 5766f85..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<dataset>
-
-  <file_sources id="101" project_uuid="ABCD" file_uuid="HIJK"
-                data=",,,,,,,,,,,,,,,unchanged&#13;&#10;,,,,,,,,,,,,,,,content&#13;&#10;"
-                line_hashes="8d7b3d6b83c0a517eac07e1aac94b773&#10;9a0364b9e99bb480dd25e1f0284c8555"
-                data_hash="0263047cd758c68c27683625f072f010"
-                src_hash="123456"
-                created_at="1412952242000" updated_at="1412952242000"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/find_files_from_module.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/find_files_from_module.xml
new file mode 100644 (file)
index 0000000..bba672e
--- /dev/null
@@ -0,0 +1,56 @@
+<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&#13;&#10;,,,,,,,,,,,,,,,content&#13;&#10;"
+                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&#13;&#10;,,,,,,,,,,,,,,,content&#13;&#10;"
+                line_hashes="lineHIJK"
+                data_hash="dataHIJK"
+                src_hash="srcHIJK"
+                created_at="1412952242000" updated_at="1412952242000"/>
+
+</dataset>
index dbcb59acd3a399acf856caf78091e1b5838b8661..d5c533536a9fa6d84f6c15cba04450742c36b2cd 100644 (file)
@@ -1,9 +1,5 @@
 <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]"
index 2e6d8c97265b880a6879c32ce0d9f917dacec67f..2c6cfe91be451cfb443700aa37f671f0838a30ad 100644 (file)
@@ -81,7 +81,7 @@ public interface ComponentMapper {
   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);
 
index e47960c5855586f3bfcae69ae565ddcde4493ff9..31e36878ec9a95000bf9275a96f8fa097b9303a5 100644 (file)
@@ -43,8 +43,6 @@ public interface SnapshotMapper {
 
   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);
 
index ce4f09ea4838c9b3186ff26e1947ec3f0a74d24a..78dd1160a114fde3de41e3d3b10e8a0ddbd50b54 100644 (file)
   <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">
index e205fd9e4d32071623798f3fefb417e48e907dde..c0112194bcf1759a74e9a15790b876f5581be5e4 100644 (file)
     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,
index d86d22e817cafd5c4975f0802c1c6477847f45f6..644714e1a07a0e2606eabb654f5f6ed03fcc252f 100644 (file)
@@ -48,7 +48,7 @@
   <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>
index ea73c7b1357226475b88ae73a7b694048d5f5355..aef21c58c111bd3cdbfa406bb521e17322ab134a 100644 (file)
@@ -158,15 +158,19 @@ public class PropertiesDaoTest extends AbstractDaoTestCase {
     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
index 5aec43d93154ae0c376607dd719e84a7ad7545db..aca9e6b505ce013fd30ec65199c24671e313764e 100644 (file)
             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>