]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5755 Don't mess UUIDs when persisting libraries
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 4 Nov 2014 14:20:04 +0000 (15:20 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 4 Nov 2014 14:30:38 +0000 (15: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/shouldSaveNewMultiModulesProject-result.xml
sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml [new file with mode: 0644]

index 54fb99abf4f692930cde7602014bb4eb28d7ae79..ea6a2d640d73c5887516d7b319da21b4810f2e2d 100644 (file)
@@ -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) {
index bf8bfee3a3ab03807a7286998bee9b7aa2815479..9c2c9aaca436a63b8f60bc4619d6ed1efcfc1487 100644 (file)
@@ -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
index 51bf3384dada93a956f228d500ee4d238766c63e..f25ce3cbece7aef5132f718c48b86d8edaaa0a60 100644 (file)
@@ -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 (file)
index 0000000..c16c139
--- /dev/null
@@ -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>