]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6119 Handle orphan components
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 12 Feb 2015 14:23:57 +0000 (15:23 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 13 Feb 2015 13:39:55 +0000 (14:39 +0100)
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/UpdateProjectsModuleUuidPath.java

index 9aba4c963a219c6dc8363f258a1a9deec422e40c..28fe41810ff78ab4ebb4854c3360a598d31d94f6 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.sonar.server.db.migrations.v51;
 
+import org.apache.commons.lang.StringUtils;
 import org.sonar.core.persistence.Database;
 import org.sonar.server.db.migrations.*;
 import org.sonar.server.db.migrations.MassUpdate.Handler;
@@ -61,8 +62,13 @@ public class UpdateProjectsModuleUuidPath extends BaseDataChange {
       boolean needUpdate = false;
       String newModuleUuidPath = moduleUuidPath;
 
-      if (needUpdateForSeparators(moduleUuidPath)) {
-        newModuleUuidPath = newModuleUuidPathWithSeparators(moduleUuidPath);
+      if (needUpdateForEmptyPath(newModuleUuidPath)) {
+        newModuleUuidPath = SEP + uuid + SEP;
+        needUpdate = true;
+      }
+
+      if (needUpdateForSeparators(newModuleUuidPath)) {
+        newModuleUuidPath = newModuleUuidPathWithSeparators(newModuleUuidPath);
         needUpdate = true;
       }
 
@@ -78,19 +84,19 @@ public class UpdateProjectsModuleUuidPath extends BaseDataChange {
       return needUpdate;
     }
 
-    private static boolean needUpdateForSeparators(@Nullable String moduleUuidPath) {
-      return moduleUuidPath == null || !(moduleUuidPath.startsWith(SEP) && moduleUuidPath.endsWith(SEP));
+    private static boolean needUpdateForEmptyPath(@Nullable String moduleUuidPath) {
+      return StringUtils.isEmpty(moduleUuidPath) || SEP.equals(moduleUuidPath);
     }
 
-    private static String newModuleUuidPathWithSeparators(@Nullable String oldModuleUuidPath) {
-      if (oldModuleUuidPath == null || oldModuleUuidPath.isEmpty()) {
-        return SEP;
-      } else {
-        StringBuilder newModuleUuidPath = new StringBuilder(oldModuleUuidPath);
-        newModuleUuidPath.insert(0, SEP);
-        newModuleUuidPath.append(SEP);
-        return newModuleUuidPath.toString();
-      }
+    private static boolean needUpdateForSeparators(String moduleUuidPath) {
+      return !(moduleUuidPath.startsWith(SEP) && moduleUuidPath.endsWith(SEP));
+    }
+
+    private static String newModuleUuidPathWithSeparators(String oldModuleUuidPath) {
+      StringBuilder newModuleUuidPath = new StringBuilder(oldModuleUuidPath);
+      newModuleUuidPath.insert(0, SEP);
+      newModuleUuidPath.append(SEP);
+      return newModuleUuidPath.toString();
     }
 
     private static boolean needUpdateToIncludeItself(String moduleUuidPath, @Nullable String uuid, @Nullable String scope, @Nullable String qualifier) {