]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5753 Save empty string instead of null for root projects
authorJulien HENRY <julien.henry@sonarsource.com>
Mon, 5 Jan 2015 15:29:27 +0000 (16:29 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Mon, 5 Jan 2015 15:30:10 +0000 (16:30 +0100)
sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml
sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldUpdateExistingResource-result.xml

index 0f7faddb25fe7c248bce40dee53c86a4d5c615fe..84e486f605e3035f1309e597a7ff172eb6cbb617 100644 (file)
@@ -338,15 +338,16 @@ public final class DefaultResourcePersister implements ResourcePersister {
       if (Scopes.isProject(parentResource)) {
         model.setModuleUuid(parentResource.getUuid());
         String parentModuleUuidPath = parentModel.getModuleUuidPath();
-        model.setModuleUuidPath(parentModuleUuidPath != null ? parentModuleUuidPath + "." + parentModel.getUuid() : parentModel.getUuid());
+        model.setModuleUuidPath(StringUtils.isNotBlank(parentModuleUuidPath) ? parentModuleUuidPath + "." + parentModel.getUuid() : parentModel.getUuid());
       } else {
         model.setModuleUuid(parentModel.getModuleUuid());
         String parentModuleUuidPath = parentModel.getModuleUuidPath();
-        model.setModuleUuidPath(parentModuleUuidPath != null ? parentModuleUuidPath : parentModel.getUuid());
+        model.setModuleUuidPath(StringUtils.isNotBlank(parentModuleUuidPath) ? parentModuleUuidPath : parentModel.getUuid());
       }
     } else {
       // Root module && libraries
       model.setProjectUuid(model.getUuid());
+      model.setModuleUuidPath("");
     }
   }
 
index 23ad3689cf6a9b2f25e9d2854cda87b9ce795286..7f54b3d5ebbfd15d2a1ce36ff9d7f894115c33fa 100644 (file)
@@ -122,7 +122,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
       assertThat(newProject.uuid()).isNotNull();
       assertThat(newProject.projectUuid()).isEqualTo(newProject.uuid());
       assertThat(newProject.moduleUuid()).isNull();
-      assertThat(newProject.moduleUuidPath()).isNull();
+      assertThat(newProject.moduleUuidPath()).isEqualTo("");
       // SONAR-3636 : created_at must be fed when inserting a new entry in the 'projects' table
       assertThat(newProject.getCreatedAt()).isNotNull();
     } finally {
@@ -147,7 +147,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
       assertThat(newProject.uuid()).isNotNull();
       assertThat(newProject.projectUuid()).isEqualTo(newProject.uuid());
       assertThat(newProject.moduleUuid()).isNull();
-      assertThat(newProject.moduleUuidPath()).isNull();
+      assertThat(newProject.moduleUuidPath()).isEqualTo("");
     } finally {
       MyBatis.closeQuietly(session);
     }
@@ -183,7 +183,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
       assertThat(root.uuid()).isNotNull();
       assertThat(root.projectUuid()).isEqualTo(root.uuid());
       assertThat(root.moduleUuid()).isNull();
-      assertThat(root.moduleUuidPath()).isNull();
+      assertThat(root.moduleUuidPath()).isEqualTo("");
       ComponentDto a = session.getMapper(ComponentMapper.class).selectByKey("a");
       assertThat(a.uuid()).isNotNull();
       assertThat(a.projectUuid()).isEqualTo(root.uuid());
@@ -262,7 +262,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
       assertThat(root.uuid()).isNotNull();
       assertThat(root.projectUuid()).isEqualTo(root.uuid());
       assertThat(root.moduleUuid()).isNull();
-      assertThat(root.moduleUuidPath()).isNull();
+      assertThat(root.moduleUuidPath()).isEqualTo("");
       ComponentDto a = session.getMapper(ComponentMapper.class).selectByKey("a");
       System.out.println("A: " + a.uuid());
       assertThat(a.uuid()).isNotNull();
@@ -355,7 +355,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
       assertThat(newLib.uuid()).isNotNull();
       assertThat(newLib.projectUuid()).isEqualTo(newLib.uuid());
       assertThat(newLib.moduleUuid()).isNull();
-      assertThat(newLib.moduleUuidPath()).isNull();
+      assertThat(newLib.moduleUuidPath()).isEqualTo("");
     } finally {
       MyBatis.closeQuietly(session);
     }
index f36a8e48f964bc9d7281648890198e3eac0f283e..283baaf3ddef0de867fdcf24841ececcee942439 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="[null]"
+  <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 cca8b5570dc5df5fb23c9d577b0144a65932f0b8..d04674f42b8e89181a9460a0c1a3216acd463159 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="[null]"
+  <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" />