From 551a7b41125fba4a3603c9367e9bb1c7013bd310 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Mon, 5 Jan 2015 16:29:27 +0100 Subject: [PATCH] SONAR-5753 Save empty string instead of null for root projects --- .../sonar/batch/index/DefaultResourcePersister.java | 5 +++-- .../batch/index/DefaultResourcePersisterTest.java | 10 +++++----- ...shouldRemoveRootIndexIfResourceIsProject-result.xml | 2 +- .../shouldUpdateExistingResource-result.xml | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java index 0f7faddb25f..84e486f605e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java @@ -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(""); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java index 23ad3689cf6..7f54b3d5ebb 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java @@ -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); } diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml index f36a8e48f96..283baaf3dde 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml @@ -1,6 +1,6 @@ - diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldUpdateExistingResource-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldUpdateExistingResource-result.xml index cca8b5570dc..d04674f42b8 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldUpdateExistingResource-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldUpdateExistingResource-result.xml @@ -1,6 +1,6 @@ - -- 2.39.5