]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6054 Update the format of PROJECTS.MODULE_UUID_PATH
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 15 Jan 2015 13:56:11 +0000 (14:56 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Thu, 15 Jan 2015 13:56:11 +0000 (14:56 +0100)
sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java
sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java
sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml
sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldUpdateExistingResource-result.xml

index a37032615fd737eb55eb1944fa844fda2964208c..4ed133f21a36e939deaaead85cb62a752d212ea7 100644 (file)
@@ -24,7 +24,13 @@ import org.apache.commons.lang.StringUtils;
 import org.sonar.api.database.DatabaseSession;
 import org.sonar.api.database.model.ResourceModel;
 import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.*;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Library;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.resources.ResourceUtils;
+import org.sonar.api.resources.Scopes;
 import org.sonar.api.security.ResourcePermissions;
 import org.sonar.api.utils.SonarException;
 import org.sonar.api.utils.internal.Uuids;
@@ -279,25 +285,20 @@ public class ResourcePersister implements ScanPersister {
     }
     if (parentResource != null) {
       ResourceModel parentModel = session.getSingleResult(ResourceModel.class, "id", parentResource.getId());
-      // FIXME ProjectUUid should never be null but empty (or now ".")
-      if (parentModel.getProjectUuid() != null) {
-        model.setProjectUuid(parentModel.getProjectUuid());
-      } else {
-        model.setProjectUuid(parentModel.getUuid());
-      }
+      model.setProjectUuid(parentModel.getProjectUuid());
       if (Scopes.isProject(parentResource)) {
         model.setModuleUuid(parentResource.getUuid());
         String parentModuleUuidPath = parentModel.getModuleUuidPath();
-        model.setModuleUuidPath(StringUtils.isNotBlank(parentModuleUuidPath) ? parentModuleUuidPath + "." + parentModel.getUuid() : parentModel.getUuid());
+        model.setModuleUuidPath(parentModuleUuidPath + parentModel.getUuid() + ".");
       } else {
         model.setModuleUuid(parentModel.getModuleUuid());
         String parentModuleUuidPath = parentModel.getModuleUuidPath();
-        model.setModuleUuidPath(StringUtils.isNotBlank(parentModuleUuidPath) ? parentModuleUuidPath : parentModel.getUuid());
+        model.setModuleUuidPath(parentModuleUuidPath);
       }
     } else {
       // Root module && libraries
       model.setProjectUuid(model.getUuid());
-      model.setModuleUuidPath("");
+      model.setModuleUuidPath(".");
     }
   }
 
index 3f9503165ad17bce4e19412cc0c1bc5bb49a18c9..f64ff958846b4297eb3b0548e467b79314a4da61 100644 (file)
@@ -126,7 +126,7 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase {
       assertThat(newProject.uuid()).isNotNull();
       assertThat(newProject.projectUuid()).isEqualTo(newProject.uuid());
       assertThat(newProject.moduleUuid()).isNull();
-      assertThat(newProject.moduleUuidPath()).isEmpty();
+      assertThat(newProject.moduleUuidPath()).isEqualTo(".");
       // SONAR-3636 : created_at must be fed when inserting a new entry in the 'projects' table
       assertThat(newProject.getCreatedAt()).isNotNull();
     }
@@ -147,7 +147,7 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase {
       assertThat(newProject.uuid()).isNotNull();
       assertThat(newProject.projectUuid()).isEqualTo(newProject.uuid());
       assertThat(newProject.moduleUuid()).isNull();
-      assertThat(newProject.moduleUuidPath()).isEmpty();
+      assertThat(newProject.moduleUuidPath()).isEqualTo(".");
     }
   }
 
@@ -179,32 +179,32 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase {
       assertThat(root.uuid()).isNotNull();
       assertThat(root.projectUuid()).isEqualTo(root.uuid());
       assertThat(root.moduleUuid()).isNull();
-      assertThat(root.moduleUuidPath()).isEmpty();
+      assertThat(root.moduleUuidPath()).isEqualTo(".");
       ComponentDto a = session.getMapper(ComponentMapper.class).selectByKey("a");
       assertThat(a.uuid()).isNotNull();
       assertThat(a.projectUuid()).isEqualTo(root.uuid());
       assertThat(a.moduleUuid()).isEqualTo(root.uuid());
-      assertThat(a.moduleUuidPath()).isEqualTo(root.uuid());
+      assertThat(a.moduleUuidPath()).isEqualTo("." + root.uuid() + ".");
       ComponentDto b = session.getMapper(ComponentMapper.class).selectByKey("b");
       assertThat(b.uuid()).isNotNull();
       assertThat(b.projectUuid()).isEqualTo(root.uuid());
       assertThat(b.moduleUuid()).isEqualTo(root.uuid());
-      assertThat(b.moduleUuidPath()).isEqualTo(root.uuid());
+      assertThat(b.moduleUuidPath()).isEqualTo("." + root.uuid() + ".");
       ComponentDto b1 = session.getMapper(ComponentMapper.class).selectByKey("b1");
       assertThat(b1.uuid()).isNotNull();
       assertThat(b1.projectUuid()).isEqualTo(root.uuid());
       assertThat(b1.moduleUuid()).isEqualTo(b.uuid());
-      assertThat(b1.moduleUuidPath()).isEqualTo(root.uuid() + "." + b.uuid());
+      assertThat(b1.moduleUuidPath()).isEqualTo("." + root.uuid() + "." + b.uuid() + ".");
       ComponentDto dir = session.getMapper(ComponentMapper.class).selectByKey("b1:src/main/java/org");
       assertThat(dir.uuid()).isNotNull();
       assertThat(dir.projectUuid()).isEqualTo(root.uuid());
       assertThat(dir.moduleUuid()).isEqualTo(b1.uuid());
-      assertThat(dir.moduleUuidPath()).isEqualTo(root.uuid() + "." + b.uuid() + "." + b1.uuid());
+      assertThat(dir.moduleUuidPath()).isEqualTo("." + root.uuid() + "." + b.uuid() + "." + b1.uuid() + ".");
       ComponentDto fileComp = session.getMapper(ComponentMapper.class).selectByKey("b1:src/main/java/org/Foo.java");
       assertThat(fileComp.uuid()).isNotNull();
       assertThat(fileComp.projectUuid()).isEqualTo(root.uuid());
       assertThat(fileComp.moduleUuid()).isEqualTo(b1.uuid());
-      assertThat(fileComp.moduleUuidPath()).isEqualTo(root.uuid() + "." + b.uuid() + "." + b1.uuid());
+      assertThat(fileComp.moduleUuidPath()).isEqualTo("." + root.uuid() + "." + b.uuid() + "." + b1.uuid() + ".");
     }
   }
 
@@ -253,35 +253,35 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase {
       assertThat(root.uuid()).isNotNull();
       assertThat(root.projectUuid()).isEqualTo(root.uuid());
       assertThat(root.moduleUuid()).isNull();
-      assertThat(root.moduleUuidPath()).isEmpty();
+      assertThat(root.moduleUuidPath()).isEqualTo(".");
       ComponentDto a = session.getMapper(ComponentMapper.class).selectByKey("a");
       System.out.println("A: " + a.uuid());
       assertThat(a.uuid()).isNotNull();
       assertThat(a.projectUuid()).isEqualTo(root.uuid());
       assertThat(a.moduleUuid()).isEqualTo(root.uuid());
-      assertThat(a.moduleUuidPath()).isEqualTo(root.uuid());
+      assertThat(a.moduleUuidPath()).isEqualTo("." + root.uuid() + ".");
       ComponentDto b = session.getMapper(ComponentMapper.class).selectByKey("b");
       System.out.println("B: " + b.uuid());
       assertThat(b.uuid()).isNotNull();
       assertThat(b.projectUuid()).isEqualTo(root.uuid());
       assertThat(b.moduleUuid()).isEqualTo(root.uuid());
-      assertThat(b.moduleUuidPath()).isEqualTo(root.uuid());
+      assertThat(b.moduleUuidPath()).isEqualTo("." + root.uuid() + ".");
       ComponentDto b1 = session.getMapper(ComponentMapper.class).selectByKey("b1");
       System.out.println("B1: " + b1.uuid());
       assertThat(b1.uuid()).isNotNull();
       assertThat(b1.projectUuid()).isEqualTo(root.uuid());
       assertThat(b1.moduleUuid()).isEqualTo(b.uuid());
-      assertThat(b1.moduleUuidPath()).isEqualTo(root.uuid() + "." + b.uuid());
+      assertThat(b1.moduleUuidPath()).isEqualTo("." + root.uuid() + "." + b.uuid() + ".");
       ComponentDto dir = session.getMapper(ComponentMapper.class).selectByKey("b1:src/main/java/org");
       assertThat(dir.uuid()).isNotNull();
       assertThat(dir.projectUuid()).isEqualTo(root.uuid());
       assertThat(dir.moduleUuid()).isEqualTo(b1.uuid());
-      assertThat(dir.moduleUuidPath()).isEqualTo(root.uuid() + "." + b.uuid() + "." + b1.uuid());
+      assertThat(dir.moduleUuidPath()).isEqualTo("." + root.uuid() + "." + b.uuid() + "." + b1.uuid() + ".");
       ComponentDto fileComp = session.getMapper(ComponentMapper.class).selectByKey("b1:src/main/java/org/Foo.java");
       assertThat(fileComp.uuid()).isNotNull();
       assertThat(fileComp.projectUuid()).isEqualTo(root.uuid());
       assertThat(fileComp.moduleUuid()).isEqualTo(b1.uuid());
-      assertThat(fileComp.moduleUuidPath()).isEqualTo(root.uuid() + "." + b.uuid() + "." + b1.uuid());
+      assertThat(fileComp.moduleUuidPath()).isEqualTo("." + root.uuid() + "." + b.uuid() + "." + b1.uuid() + ".");
     }
   }
 
@@ -304,7 +304,7 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase {
       assertThat(newDir.uuid()).isNotNull();
       assertThat(newDir.projectUuid()).isEqualTo(newProject.uuid());
       assertThat(newDir.moduleUuid()).isEqualTo(newProject.uuid());
-      assertThat(newDir.moduleUuidPath()).isEqualTo(newProject.uuid());
+      assertThat(newDir.moduleUuidPath()).isEqualTo("." + newProject.uuid() + ".");
     }
   }
 
@@ -338,7 +338,7 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase {
       assertThat(newLib.uuid()).isNotNull();
       assertThat(newLib.projectUuid()).isEqualTo(newLib.uuid());
       assertThat(newLib.moduleUuid()).isNull();
-      assertThat(newLib.moduleUuidPath()).isEmpty();
+      assertThat(newLib.moduleUuidPath()).isEqualTo(".");
     }
   }
 
index 283baaf3ddef0de867fdcf24841ececcee942439..9b7ee4aad2e3a3099c092bd6f3427843e7060e80 100644 (file)
@@ -1,6 +1,6 @@
 <dataset>
 
-  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]" uuid="BCDE" project_uuid="BCDE" module_uuid="[null]" module_uuid_path=""
+  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]" uuid="BCDE" project_uuid="BCDE" module_uuid="[null]" module_uuid_path="."
             name="Foo" long_name="Foo" description="some description"
             enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="foo"/>
 
index d04674f42b8e89181a9460a0c1a3216acd463159..14edf7cb5fa92695d867450cb1824b9399a44d35 100644 (file)
@@ -1,6 +1,6 @@
 <dataset>
 
-  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]" uuid="BCDE" project_uuid="BCDE" module_uuid="[null]" module_uuid_path=""
+  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]" uuid="BCDE" project_uuid="BCDE" module_uuid="[null]" module_uuid_path="."
             name="new name" long_name="new name" description="new description"
             enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="foo" />