diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-10-24 14:57:00 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-10-24 14:57:41 +0200 |
commit | 9ecb47a39818940fcc47f79b430cd15fc022d8d9 (patch) | |
tree | 20cb64d8e8f2809ba9df44973b178d1d385aa7ba /sonar-batch | |
parent | 613454f015ae236c50033d30a0681ee02e91057d (diff) | |
download | sonarqube-9ecb47a39818940fcc47f79b430cd15fc022d8d9.tar.gz sonarqube-9ecb47a39818940fcc47f79b430cd15fc022d8d9.zip |
SONAR-5755 Fix UUID on libraries and uuid_module_path
Diffstat (limited to 'sonar-batch')
3 files changed, 35 insertions, 7 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 4284dbd9098..45621a3718f 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 @@ -336,7 +336,7 @@ public final class DefaultResourcePersister implements ResourcePersister { } else { model.setModuleUuid(parentModel.getModuleUuid()); } - if (Qualifiers.isProject(resource, true)) { + if (Qualifiers.isProject(parentResource, true)) { String parentModuleUuidPath = parentModel.getModuleUuidPath(); model.setModuleUuidPath(parentModuleUuidPath != null ? parentModuleUuidPath + "." + parentModel.getUuid() : parentModel.getUuid()); } else { @@ -344,10 +344,8 @@ public final class DefaultResourcePersister implements ResourcePersister { model.setModuleUuidPath(parentModuleUuidPath != null ? parentModuleUuidPath : parentModel.getUuid()); } } else { - if (Qualifiers.isProject(resource, false)) { - // Root module - model.setProjectUuid(model.getUuid()); - } + // Root module && libraries + model.setProjectUuid(model.getUuid()); } } 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 3a805fb1d92..bf58b5e61d1 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 @@ -31,6 +31,7 @@ import org.sonar.api.resources.Directory; import org.sonar.api.resources.File; import org.sonar.api.resources.Library; import org.sonar.api.resources.Project; +import org.sonar.api.resources.Resource; import org.sonar.api.security.ResourcePermissions; import org.sonar.core.component.ComponentDto; import org.sonar.core.component.db.ComponentMapper; @@ -150,6 +151,10 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase { persister.saveProject(moduleA, multiModuleProject); persister.saveProject(moduleB, multiModuleProject); persister.saveProject(moduleB1, moduleB); + Resource file = File.create("src/main/java/org/Foo.java").setEffectiveKey("b1:src/main/java/org/Foo.java"); + file.getParent().setEffectiveKey("b1:src/main/java/org"); + persister.saveResource(moduleB1, file.getParent()); + persister.saveResource(moduleB1, file, file.getParent()); checkTables("shouldSaveNewMultiModulesProject", new String[] {"build_date", "created_at", "authorization_updated_at", "uuid", "project_uuid", "module_uuid", "module_uuid_path"}, "projects", "snapshots"); @@ -159,6 +164,8 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase { enableSnapshot(1002); enableSnapshot(1003); enableSnapshot(1004); + enableSnapshot(1005); + enableSnapshot(1006); SqlSession session = getMyBatis().openSession(false); try { ComponentDto root = session.getMapper(ComponentMapper.class).selectByKey("root"); @@ -181,6 +188,16 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase { assertThat(b1.projectUuid()).isEqualTo(root.uuid()); assertThat(b1.moduleUuid()).isEqualTo(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()); + 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()); } finally { MyBatis.closeQuietly(session); } @@ -243,7 +260,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase { // FIXME selectByKey returns duplicates for libraries because of the join on snapshots table ComponentDto newLib = session.getMapper(ComponentMapper.class).findByKeys(Arrays.asList("junit:junit")).get(0); assertThat(newLib.uuid()).isNotNull(); - assertThat(newLib.projectUuid()).isEqualTo(newLib.projectUuid()); + assertThat(newLib.projectUuid()).isEqualTo(newLib.uuid()); assertThat(newLib.moduleUuid()).isNull(); assertThat(newLib.moduleUuidPath()).isNull(); } finally { diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml index a25c1610b2f..51bf3384dad 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml @@ -9,7 +9,6 @@ scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" build_date="2008-11-01 13:58:00.00" version="[null]" path="" status="P" islast="false" depth="0" /> - <!-- new project --> <projects id="1001" scope="PRJ" qualifier="TRK" kee="root" root_id="[null]" uuid="[null]" project_uuid="[null]" module_uuid="[null]" module_uuid_path="[null]" name="Root" long_name="Root" description="[null]" @@ -27,6 +26,13 @@ name="B1" long_name="B1" description="[null]" enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="moduleB1" deprecated_kee="b1" /> + <projects id="1005" scope="DIR" qualifier="DIR" kee="b1:src/main/java/org" root_id="1004" + name="src/main/java/org" long_name="src/main/java/org" description="[null]" + enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/main/java/org" deprecated_kee="[null]" /> + + <projects id="1006" scope="FIL" qualifier="FIL" kee="b1:src/main/java/org/Foo.java" root_id="1004" + name="src/main/java/org/Foo.java" long_name="src/main/java/org/Foo.java" description="[null]" + enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/main/java/org/Foo.java" deprecated_kee="[null]" /> <snapshots 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]" id="3001" project_id="1001" root_project_id="1001" parent_snapshot_id="[null]" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" build_date="2010-12-25 00:00:00.00" version="[null]" path="" @@ -44,5 +50,12 @@ scope="PRJ" qualifier="BRC" created_at="2010-12-25 00:00:00.00" build_date="2010-12-25 00:00:00.00" version="[null]" path="3001.3003." status="U" islast="false" depth="2" /> + <snapshots 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]" id="3005" project_id="1005" root_project_id="1001" parent_snapshot_id="3004" root_snapshot_id="3001" + scope="DIR" qualifier="DIR" created_at="2010-12-25 00:00:00.00" build_date="2010-12-25 00:00:00.00" version="[null]" path="3001.3003.3004." + status="U" islast="false" depth="3" /> + + <snapshots 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]" id="3006" project_id="1006" root_project_id="1001" parent_snapshot_id="3005" root_snapshot_id="3001" + scope="FIL" qualifier="FIL" created_at="2010-12-25 00:00:00.00" build_date="2010-12-25 00:00:00.00" version="[null]" path="3001.3003.3004.3005." + status="U" islast="false" depth="4" /> </dataset> |