From: Julien HENRY Date: Tue, 4 Nov 2014 14:20:04 +0000 (+0100) Subject: SONAR-5755 Don't mess UUIDs when persisting libraries X-Git-Tag: 5.0-RC1~418 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4dccc2d86a3c95abe1932bbc2a4293a5da3c336b;p=sonarqube.git SONAR-5755 Don't mess UUIDs when persisting libraries --- 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 @@ + status="U" islast="false" depth="4" /> 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +