From 57c683d7042fb519aeacb77362e8da268dbfc5ee Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 5 Jan 2015 12:33:31 +0100 Subject: [PATCH] SONAR-5753 moduleUuidPath of foot projects should be empty instead of NULL --- .../PopulateProjectsUuidColumnsMigration.java | 4 +++ .../server/component/ComponentTesting.java | 2 +- ...ulateProjectsUuidColumnsMigrationTest.java | 28 +++++++++---------- .../migrate_components.xml | 10 +++---- .../migrate_components_without_uuid.xml | 6 ++-- .../migrate_developer.xml | 4 +-- .../migrate_disable_components.xml | 10 +++---- .../migrate_library.xml | 2 +- .../migrate_provisioned_project.xml | 2 +- .../migrate_view.xml | 6 ++-- ...ot_migrate_already_migrated_components.xml | 8 +++--- .../org/sonar/core/resource/ResourceDao.java | 1 + .../sonar/core/resource/ResourceMapper.xml | 5 ++-- .../sonar/core/resource/ResourceDaoTest.java | 6 ++-- .../ResourceDaoTest/insert-result.xml | 4 +-- 15 files changed, 53 insertions(+), 45 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigration.java index f1b414359a5..c1ce39f0b36 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigration.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigration.java @@ -99,6 +99,7 @@ public class PopulateProjectsUuidColumnsMigration implements DatabaseMigration { if (component.getUuid() == null) { component.setUuid(getOrCreateUuid(component, uuidByComponentId)); component.setProjectUuid(getOrCreateUuid(project, uuidByComponentId)); + component.setModuleUuidPath(""); componentsToMigrate.add(component); } } @@ -115,6 +116,7 @@ public class PopulateProjectsUuidColumnsMigration implements DatabaseMigration { for (Component component : readSession.getMapper(Migration50Mapper.class).selectDisabledDirectComponentChildrenForProjects(project.getId())) { component.setUuid(getOrCreateUuid(component, uuidByComponentId)); component.setProjectUuid(projectUuid); + component.setModuleUuidPath(""); writeSession.getMapper(Migration50Mapper.class).updateComponentUuids(component); counter.getAndIncrement(); @@ -122,6 +124,7 @@ public class PopulateProjectsUuidColumnsMigration implements DatabaseMigration { for (Component component : readSession.getMapper(Migration50Mapper.class).selectDisabledNoneDirectComponentChildrenForProjects(project.getId())) { component.setUuid(getOrCreateUuid(component, uuidByComponentId)); component.setProjectUuid(projectUuid); + component.setModuleUuidPath(""); writeSession.getMapper(Migration50Mapper.class).updateComponentUuids(component); counter.getAndIncrement(); @@ -159,6 +162,7 @@ public class PopulateProjectsUuidColumnsMigration implements DatabaseMigration { String uuid = Uuids.create(); component.setUuid(uuid); component.setProjectUuid(uuid); + component.setModuleUuidPath(""); writeSession.getMapper(Migration50Mapper.class).updateComponentUuids(component); counter.getAndIncrement(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentTesting.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentTesting.java index d1a6db4a09a..347a2afb8e1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentTesting.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentTesting.java @@ -54,7 +54,7 @@ public class ComponentTesting { .setUuid(Uuids.create()) .setProjectUuid(subProjectOrProject.projectUuid()) .setModuleUuid(subProjectOrProject.uuid()) - .setModuleUuidPath(subProjectOrProject.moduleUuidPath() == null ? subProjectOrProject.uuid() + "." : subProjectOrProject.moduleUuidPath() + subProjectOrProject.uuid() + ".") + .setModuleUuidPath(subProjectOrProject.moduleUuidPath() == null ? subProjectOrProject.uuid() : subProjectOrProject.moduleUuidPath() + "." + subProjectOrProject.uuid()) .setKey("KEY_" + uuid) .setName("NAME_" + uuid) .setLongName("LONG_NAME_" + uuid) diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest.java index a61d93c52c7..0ec5cfaebcc 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest.java @@ -73,7 +73,7 @@ public class PopulateProjectsUuidColumnsMigrationTest { assertThat(root.getUuid()).isNotNull(); assertThat(root.getProjectUuid()).isEqualTo(root.getUuid()); assertThat(root.getModuleUuid()).isNull(); - assertThat(root.getModuleUuidPath()).isNull(); + assertThat(root.getModuleUuidPath()).isEmpty(); Component module = mapper.selectComponentByKey("org.struts:struts-core"); assertThat(module.getUuid()).isNotNull(); @@ -114,7 +114,7 @@ public class PopulateProjectsUuidColumnsMigrationTest { assertThat(root.getUuid()).isEqualTo("ABCD"); assertThat(root.getProjectUuid()).isEqualTo("ABCD"); assertThat(root.getModuleUuid()).isNull(); - assertThat(root.getModuleUuidPath()).isNull(); + assertThat(root.getModuleUuidPath()).isEmpty(); Component module = mapper.selectComponentByKey("org.struts:struts-core"); assertThat(module.getUuid()).isEqualTo("BCDE"); @@ -162,28 +162,28 @@ public class PopulateProjectsUuidColumnsMigrationTest { assertThat(module.getProjectUuid()).isEqualTo(root.getUuid()); // Module and module path will always be null for removed components assertThat(module.getModuleUuid()).isNull(); - assertThat(module.getModuleUuidPath()).isNull(); + assertThat(module.getModuleUuidPath()).isEmpty(); Component subModule = mapper.selectComponentByKey("org.struts:struts-db"); assertThat(subModule.getUuid()).isNotNull(); assertThat(subModule.getProjectUuid()).isEqualTo(root.getUuid()); // Module and module path will always be null for removed components assertThat(subModule.getModuleUuid()).isNull(); - assertThat(subModule.getModuleUuidPath()).isNull(); + assertThat(subModule.getModuleUuidPath()).isEmpty(); Component directory = mapper.selectComponentByKey("org.struts:struts-core:src/org/struts"); assertThat(directory.getUuid()).isNotNull(); assertThat(directory.getProjectUuid()).isEqualTo(root.getUuid()); // Module and module path will always be null for removed components assertThat(directory.getModuleUuid()).isNull(); - assertThat(directory.getModuleUuidPath()).isNull(); + assertThat(directory.getModuleUuidPath()).isEmpty(); Component file = mapper.selectComponentByKey("org.struts:struts-core:src/org/struts/RequestContext.java"); assertThat(file.getUuid()).isNotNull(); assertThat(file.getProjectUuid()).isEqualTo(root.getUuid()); // Module and module path will always be null for removed components assertThat(file.getModuleUuid()).isNull(); - assertThat(file.getModuleUuidPath()).isNull(); + assertThat(file.getModuleUuidPath()).isEmpty(); } @Test @@ -197,7 +197,7 @@ public class PopulateProjectsUuidColumnsMigrationTest { assertThat(root.getUuid()).isNotNull(); assertThat(root.getProjectUuid()).isEqualTo(root.getUuid()); assertThat(root.getModuleUuid()).isNull(); - assertThat(root.getModuleUuidPath()).isNull(); + assertThat(root.getModuleUuidPath()).isEmpty(); } @Test @@ -211,7 +211,7 @@ public class PopulateProjectsUuidColumnsMigrationTest { assertThat(root.getUuid()).isNotNull(); assertThat(root.getProjectUuid()).isEqualTo(root.getUuid()); assertThat(root.getModuleUuid()).isNull(); - assertThat(root.getModuleUuidPath()).isNull(); + assertThat(root.getModuleUuidPath()).isEmpty(); } @Test @@ -225,7 +225,7 @@ public class PopulateProjectsUuidColumnsMigrationTest { assertThat(view.getUuid()).isNotNull(); assertThat(view.getProjectUuid()).isEqualTo(view.getUuid()); assertThat(view.getModuleUuid()).isNull(); - assertThat(view.getModuleUuidPath()).isNull(); + assertThat(view.getModuleUuidPath()).isEmpty(); Component subView = mapper.selectComponentByKey("subView"); assertThat(subView.getUuid()).isNotNull(); @@ -251,7 +251,7 @@ public class PopulateProjectsUuidColumnsMigrationTest { assertThat(dev.getUuid()).isNotNull(); assertThat(dev.getProjectUuid()).isEqualTo(dev.getUuid()); assertThat(dev.getModuleUuid()).isNull(); - assertThat(dev.getModuleUuidPath()).isNull(); + assertThat(dev.getModuleUuidPath()).isEmpty(); Component techDev = mapper.selectComponentByKey("DEV:developer@company.net:org.struts:struts"); assertThat(techDev.getUuid()).isNotNull(); @@ -272,21 +272,21 @@ public class PopulateProjectsUuidColumnsMigrationTest { assertThat(root.getUuid()).isNotNull(); assertThat(root.getProjectUuid()).isEqualTo(root.getUuid()); assertThat(root.getModuleUuid()).isNull(); - assertThat(root.getModuleUuidPath()).isNull(); + assertThat(root.getModuleUuidPath()).isEmpty(); // Module with a snapshot having no islast=true Component module = mapper.selectComponentByKey("org.struts:struts-core"); assertThat(module.getUuid()).isNotNull(); assertThat(module.getProjectUuid()).isEqualTo(module.getUuid()); assertThat(module.getModuleUuid()).isNull(); - assertThat(module.getModuleUuidPath()).isNull(); + assertThat(module.getModuleUuidPath()).isEmpty(); // File linked on a no more existing project - Component file = mapper.selectComponentByKey("org.struts:struts-core:src/org/struts/RequestContext.java"); + Component file = mapper.selectComponentByKey("org.struts:struts-core:src/org/struts/RequestContext.java"); assertThat(file.getUuid()).isNotNull(); assertThat(file.getProjectUuid()).isEqualTo(file.getUuid()); assertThat(file.getModuleUuid()).isNull(); - assertThat(file.getModuleUuidPath()).isNull(); + assertThat(file.getModuleUuidPath()).isEmpty(); } } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_components.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_components.xml index cff6eb31173..e38e16ae56f 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_components.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_components.xml @@ -2,7 +2,7 @@ @@ -18,7 +18,7 @@ @@ -64,7 +64,7 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_components_without_uuid.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_components_without_uuid.xml index c10e10949b5..4c4c2ec4e28 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_components_without_uuid.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_components_without_uuid.xml @@ -2,7 +2,7 @@ @@ -18,7 +18,7 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_developer.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_developer.xml index 0be69725843..f2a7202514c 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_developer.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_developer.xml @@ -2,7 +2,7 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_disable_components.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_disable_components.xml index fed87fc45a7..a1e51111fc0 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_disable_components.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_disable_components.xml @@ -2,7 +2,7 @@ @@ -18,7 +18,7 @@ @@ -64,7 +64,7 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_library.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_library.xml index d1e8908bf04..bc464dc5264 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_library.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_library.xml @@ -2,7 +2,7 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_provisioned_project.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_provisioned_project.xml index 9e688d16451..0d3962b8d67 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_provisioned_project.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_provisioned_project.xml @@ -2,7 +2,7 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_view.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_view.xml index 5a1a222a2ba..7b20b9d98ee 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_view.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/migrate_view.xml @@ -2,7 +2,7 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/not_migrate_already_migrated_components.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/not_migrate_already_migrated_components.xml index 98471afd445..524a1e3a682 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/not_migrate_already_migrated_components.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest/not_migrate_already_migrated_components.xml @@ -2,7 +2,7 @@ @@ -33,7 +33,7 @@ @@ -64,7 +64,7 @@ diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java index b26f6ff465e..26de7532558 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java @@ -158,6 +158,7 @@ public class ResourceDao implements DaoComponent { String uuid = Uuids.create(); resource.setUuid(uuid); resource.setProjectUuid(uuid); + resource.setModuleUuidPath(""); } resource.setCreatedAt(now); resource.setAuthorizationUpdatedAt(now.getTime()); diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml index 025d5f4deb1..310b42e62ad 100644 --- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml @@ -209,9 +209,10 @@ insert into projects - (uuid, project_uuid, name, long_name, description, scope, qualifier, kee, deprecated_kee, path, language, root_id, copy_resource_id, person_id, enabled, authorization_updated_at, created_at) + (uuid, project_uuid, module_uuid, module_uuid_path, name, long_name, description, scope, qualifier, kee, deprecated_kee, path, language, root_id, copy_resource_id, person_id, + enabled, authorization_updated_at, created_at) values ( - #{uuid}, #{projectUuid}, #{name}, #{longName}, #{description}, #{scope}, #{qualifier}, + #{uuid}, #{projectUuid}, #{moduleUuid}, #{moduleUuidPath}, #{name}, #{longName}, #{description}, #{scope}, #{qualifier}, #{key}, #{deprecatedKey}, #{path}, #{language}, #{rootId}, #{copyResourceId}, #{personId}, #{enabled}, #{authorizationUpdatedAt}, #{createdAt} ) diff --git a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java index b5fdb0c48ac..a071e054929 100644 --- a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java @@ -251,12 +251,12 @@ public class ResourceDaoTest extends AbstractDaoTestCase { setupData("insert"); ResourceDto file1 = new ResourceDto() - .setUuid("ABCD").setProjectUuid("EFGH") + .setUuid("ABCD").setProjectUuid("EFGH").setModuleUuid("EFGH").setModuleUuidPath("EFGH") .setKey("org.struts:struts:/src/main/java/org/struts/Action.java") .setDeprecatedKey("org.struts:struts:org.struts.Action").setScope(Scopes.FILE).setQualifier(Qualifiers.FILE) .setLanguage("java").setName("Action").setLongName("org.struts.Action").setPath("/foo/bar"); ResourceDto file2 = new ResourceDto() - .setUuid("BCDE").setProjectUuid("FGHI") + .setUuid("BCDE").setProjectUuid("FGHI").setModuleUuid("FGHI").setModuleUuidPath("FGHI") .setKey("org.struts:struts:/src/main/java/org/struts/Filter.java") .setDeprecatedKey("org.struts:struts:org.struts.Filter").setScope(Scopes.FILE).setQualifier(Qualifiers.FILE) .setLanguage("java").setName("Filter").setLongName("org.struts.Filter"); @@ -314,9 +314,11 @@ public class ResourceDaoTest extends AbstractDaoTestCase { assertThat(project.getUuid()).isNotNull(); assertThat(project.getProjectUuid()).isEqualTo(project.getUuid()); + assertThat(project.getModuleUuidPath()).isEmpty(); assertThat(file.getUuid()).isNull(); assertThat(file.getProjectUuid()).isNull(); + assertThat(file.getModuleUuidPath()).isNull(); } @Test diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/insert-result.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/insert-result.xml index 08cef5638d4..bbaa53ea1a3 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/insert-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/insert-result.xml @@ -1,12 +1,12 @@ - -