aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/main/java/org
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-06-09 14:11:45 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-06-09 14:12:52 +0200
commitdfa2f95f01b348afce27c2cc04a3898f8534e887 (patch)
tree66f0297bb2f5387fd2655ac1adac2502917d1298 /sonar-batch/src/main/java/org
parentcaf24e20db288a44f0e6000d249d64fff8e5c68a (diff)
downloadsonarqube-dfa2f95f01b348afce27c2cc04a3898f8534e887.tar.gz
sonarqube-dfa2f95f01b348afce27c2cc04a3898f8534e887.zip
SONAR-5233 Fix potential resource key conflict during 4.2 migration
Diffstat (limited to 'sonar-batch/src/main/java/org')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java
index 997a66d3645..99eeb05cac9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java
@@ -127,7 +127,7 @@ public class ResourceKeyMigration implements BatchComponent {
logger.warn("Directory with key " + parentOldKey + " matches both " + deprecatedDirectoryKeyMapper.get(parentOldKey) + " and "
+ parentNewKey + ". First match is arbitrary chosen.");
}
- resourceModel.setKey(newEffectiveKey);
+ updateKey(resourceModel, newEffectiveKey);
resourceModel.setDeprecatedKey(oldEffectiveKey);
logger.info(COMPONENT_CHANGED_TO, oldEffectiveKey, newEffectiveKey);
} else {
@@ -136,6 +136,24 @@ public class ResourceKeyMigration implements BatchComponent {
}
}
+ private void updateKey(ResourceModel resourceModel, String newEffectiveKey) {
+ // Look for disabled resource with conflicting key
+ List<ResourceModel> duplicateDisabledResources = session.createQuery(new StringBuilder().append("from ")
+ .append(ResourceModel.class.getSimpleName())
+ .append(" where enabled = false ")
+ .append(" and kee = :kee ")
+ .append(" and qualifier = :qualifier ").toString())
+ .setParameter("kee", newEffectiveKey)
+ .setParameter("qualifier", resourceModel.getQualifier()).getResultList();
+ if (duplicateDisabledResources.size() > 0) {
+ ResourceModel duplicateDisabledResource = duplicateDisabledResources.get(0);
+ String disabledKey = newEffectiveKey + "_renamed_by_resource_key_migration";
+ duplicateDisabledResource.setKey(disabledKey);
+ logger.info(COMPONENT_CHANGED_TO, newEffectiveKey, disabledKey);
+ }
+ resourceModel.setKey(newEffectiveKey);
+ }
+
private StringBuilder newResourceQuery() {
return new StringBuilder().append("from ")
.append(ResourceModel.class.getSimpleName())
@@ -160,7 +178,7 @@ public class ResourceKeyMigration implements BatchComponent {
String oldEffectiveKey = resourceModel.getKey();
if (deprecatedDirectoryKeyMapper.containsKey(oldEffectiveKey)) {
String newEffectiveKey = deprecatedDirectoryKeyMapper.get(oldEffectiveKey);
- resourceModel.setKey(newEffectiveKey);
+ updateKey(resourceModel, newEffectiveKey);
resourceModel.setDeprecatedKey(oldEffectiveKey);
logger.info(COMPONENT_CHANGED_TO, oldEffectiveKey, newEffectiveKey);
} else {