diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-11-04 15:20:04 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-11-04 15:30:38 +0100 |
commit | 4dccc2d86a3c95abe1932bbc2a4293a5da3c336b (patch) | |
tree | e9701eda9a247e35516b22b56e745447d73a4f56 /sonar-batch | |
parent | da9bceca35dc17a106933498e061870ad5f9e7a9 (diff) | |
download | sonarqube-4dccc2d86a3c95abe1932bbc2a4293a5da3c336b.tar.gz sonarqube-4dccc2d86a3c95abe1932bbc2a4293a5da3c336b.zip |
SONAR-5755 Don't mess UUIDs when persisting libraries
Diffstat (limited to 'sonar-batch')
4 files changed, 74 insertions, 2 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 54fb99abf4f..ea6a2d640d7 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 @@ -324,6 +324,10 @@ public final class DefaultResourcePersister implements ResourcePersister { } private void updateUuids(Resource resource, Resource parentResource, ResourceModel model) { + // Don't override uuids when persisting a library and a project already exists + if (ResourceUtils.isLibrary(resource) && !Qualifiers.LIBRARY.equals(model.getQualifier())) { + return; + } if (parentResource != null) { ResourceModel parentModel = session.getSingleResult(ResourceModel.class, "id", parentResource.getId()); if (parentModel.getProjectUuid() != null) { 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 bf8bfee3a3a..9c2c9aaca43 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 @@ -242,7 +242,10 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase { index.setCurrentProject(moduleB1, null); index.index(file); - checkTables("shouldSaveNewMultiModulesProject", + // Emulate another project having library dependency on moduleA + index.addResource(new Library(moduleA.getKey(), "1.0")); + + checkTables("shouldSaveNewMultiModulesProjectAndLibrary", new String[] {"build_date", "created_at", "authorization_updated_at", "uuid", "project_uuid", "module_uuid", "module_uuid_path"}, "projects", "snapshots"); // Need to enable snapshot to make resource visible using ComponentMapper 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 51bf3384dad..f25ce3cbece 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 @@ -56,6 +56,6 @@ <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" /> + status="U" islast="false" depth="4" /> </dataset> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml new file mode 100644 index 00000000000..c16c139570f --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml @@ -0,0 +1,65 @@ +<dataset> + + <!-- other project --> + <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="[null]" + name="Other project" long_name="Other" description="[null]" + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="my:key" /> + + <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="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]" + 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]" + enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="root" /> + + <projects id="1002" scope="PRJ" qualifier="BRC" kee="a" root_id="1001" uuid="[null]" project_uuid="[null]" module_uuid="[null]" module_uuid_path="[null]" + name="A" long_name="A" description="[null]" + enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="moduleA" deprecated_kee="a" /> + + <projects id="1003" scope="PRJ" qualifier="BRC" kee="b" root_id="1001" uuid="[null]" project_uuid="[null]" module_uuid="[null]" module_uuid_path="[null]" + name="B" long_name="B" description="[null]" + enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="moduleB" deprecated_kee="b" /> + + <projects id="1004" scope="PRJ" qualifier="BRC" kee="b1" root_id="1001" uuid="[null]" project_uuid="[null]" module_uuid="[null]" module_uuid_path="[null]" + 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="" + status="U" islast="false" depth="0" /> + + <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="3002" project_id="1002" root_project_id="1001" parent_snapshot_id="3001" root_snapshot_id="3001" + 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." + status="U" islast="false" depth="1" /> + + <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="3003" project_id="1003" root_project_id="1001" parent_snapshot_id="3001" root_snapshot_id="3001" + 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." + status="U" islast="false" depth="1" /> + + <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="3004" project_id="1004" root_project_id="1001" parent_snapshot_id="3003" root_snapshot_id="3001" + 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" /> + + <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="3007" project_id="1002" parent_snapshot_id="[null]" root_project_id="1002" root_snapshot_id="[null]" + scope="PRJ" qualifier="LIB" created_at="2010-12-25 00:00:00.00" build_date="2010-12-25 00:00:00.00" version="1.0" path="" + status="P" islast="false" depth="0" /> + +</dataset> |