]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3126 Only "sonar.core.id" should remain unchanged
authorFabrice Bellingard <bellingard@gmail.com>
Mon, 21 May 2012 06:02:33 +0000 (08:02 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Mon, 21 May 2012 06:02:33 +0000 (08:02 +0200)
=> See https://github.com/SonarSource/sonar/commit/44ff7e7806469b587c1e3f252ad00d696b2b52db

sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java
sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java
sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldImportProperties-result.xml
sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldImportProperties.xml
sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldNotImportSonarCoreIdProperty-result.xml [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldNotImportSonarCoreIdProperty.xml [new file with mode: 0644]

index 5c08b5e0a846e4463ce5517cfa6bf8ab6f043586..85f0a56f2433097eb879f07977c9f9029a6663ff 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.configuration;
 import com.thoughtworks.xstream.XStream;
 import org.apache.commons.collections.CollectionUtils;
 import org.slf4j.LoggerFactory;
+import org.sonar.api.CoreProperties;
 import org.sonar.api.database.DatabaseSession;
 import org.sonar.api.database.configuration.Property;
 
@@ -55,15 +56,19 @@ public class PropertiesBackup implements Backupable {
 
     if (CollectionUtils.isNotEmpty(sonarConfig.getProperties())) {
       for (Property xmlProperty : sonarConfig.getProperties()) {
-        databaseSession.save(new Property(xmlProperty.getKey(), xmlProperty.getValue()));
+        String propKey = xmlProperty.getKey();
+        if (!CoreProperties.SERVER_ID.equals(propKey)) {
+          // "sonar.core.id" must never be restored, it is unique for a server and it created once at the 1rst server startup
+          databaseSession.save(new Property(propKey, xmlProperty.getValue()));
+        }
       }
     }
   }
 
   private void clearProperties() {
-    // "sonar.core.*" properties should not be cleared, most notably "sonar.core.id" which is the unique key used to identify the server
-    // and which is used by the batch to verify that it connects to the same DB as the remote server (see SONAR-3126).
-    databaseSession.createQuery("delete " + FROM_GLOBAL_PROPERTIES + " and prop_key NOT LIKE 'sonar.core.%'").executeUpdate();
+    // "sonar.core.id" property should not be cleared, because it is the unique key used to identify the server
+    // and it is used by the batch to verify that it connects to the same DB as the remote server (see SONAR-3126).
+    databaseSession.createQuery("delete " + FROM_GLOBAL_PROPERTIES + " and prop_key != '" + CoreProperties.SERVER_ID + "'").executeUpdate();
   }
 
   public void configure(XStream xStream) {
index 1a71aba251e775299ff45401955a7e24847d1111..275be22557d4568784fd9dd2682fd6dcf8768544 100644 (file)
@@ -70,7 +70,6 @@ public class PropertiesBackupTest extends AbstractDbUnitTestCase {
     assertTrue(CollectionUtils.isEqualCollection(sonarConfig.getProperties(), Arrays.asList(prop1, prop2)));
   }
 
-
   @Test
   public void shouldExportAnArrayProperty() {
     setupData("shouldExportAnArrayProperty");
@@ -92,6 +91,18 @@ public class PropertiesBackupTest extends AbstractDbUnitTestCase {
     checkTables("shouldImportProperties", "properties");
   }
 
+  @Test
+  public void shouldNotImportSonarCoreIdProperty() {
+    setupData("shouldNotImportSonarCoreIdProperty");
+
+    Collection<Property> newProperties = Arrays.asList(new Property("sonar.core.id", "11111111"));
+    sonarConfig.setProperties(newProperties);
+
+    new PropertiesBackup(getSession()).importXml(sonarConfig);
+
+    checkTables("shouldNotImportSonarCoreIdProperty", "properties");
+  }
+
   @Test
   public void shouldImportMultilineProperties() throws Exception {
     setupData("shouldImportMultilineProperties");
index ee0bfbe99644a48cde4478515815660fbd7eecae..ef2bf7744389ebf8723970b1dee0bd6b1ed0f648 100644 (file)
   <properties id="4" prop_key="user_prop" text_value="[null]" resource_id="[null]" user_id="3"/>
   <properties id="5" prop_key="favorite" text_value="[null]" resource_id="8" user_id="3"/>
 
-  <!-- Sonar Core properties that were not purged -->
+  <!-- Sonar Core property that was not purged -->
   <properties id="6" prop_key="sonar.core.id" text_value="123456" resource_id="[null]" user_id="[null]"/>
+  
+  <!-- Sonar Core properties that were not purged -->
+  <!--  
   <properties id="7" prop_key="sonar.core.version" text_value="3.1" resource_id="[null]" user_id="[null]"/>
   <properties id="8" prop_key="sonar.core.startTime" text_value="2012-04-19T11:01:45+0200" resource_id="[null]" user_id="[null]"/>
+  -->
 
   <!-- New properties that were imported -->
   <properties id="9" prop_key="key1" text_value="value1" resource_id="[null]" user_id="[null]"/>
index a820b74a25b2679b52cc7d9306965c6ed04159da..70baf106f3c1c73d42e401c8d735d076725a1c55 100644 (file)
   <properties id="4" prop_key="user_prop" text_value="[null]" resource_id="[null]" user_id="3"/>
   <properties id="5" prop_key="favorite" text_value="[null]" resource_id="8" user_id="3"/>
 
-  <!-- Sonar Core properties that must not be purged -->
+  <!-- Sonar Core property that must not be purged -->
   <properties id="6" prop_key="sonar.core.id" text_value="123456" resource_id="[null]" user_id="[null]"/>
+  
+  <!-- Sonar Core properties that can be purged -->
   <properties id="7" prop_key="sonar.core.version" text_value="3.1" resource_id="[null]" user_id="[null]"/>
   <properties id="8" prop_key="sonar.core.startTime" text_value="2012-04-19T11:01:45+0200" resource_id="[null]" user_id="[null]"/>
   
diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldNotImportSonarCoreIdProperty-result.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldNotImportSonarCoreIdProperty-result.xml
new file mode 100644 (file)
index 0000000..6960761
--- /dev/null
@@ -0,0 +1,8 @@
+<dataset>
+  <!-- Only global property left, unchanged -->
+  <properties id="1" prop_key="sonar.core.id" text_value="123456" resource_id="[null]" user_id="[null]"/>
+
+  <!-- project properties -->
+  <properties id="5" prop_key="old2" text_value="value2" resource_id="3" user_id="[null]"/>
+  
+</dataset>
\ No newline at end of file
diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldNotImportSonarCoreIdProperty.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldNotImportSonarCoreIdProperty.xml
new file mode 100644 (file)
index 0000000..67a28cb
--- /dev/null
@@ -0,0 +1,11 @@
+<dataset>
+  <!-- global properties -->
+  <properties id="1" prop_key="sonar.core.id" text_value="123456" resource_id="[null]" user_id="[null]"/>
+  <properties id="2" prop_key="sonar.core.version" text_value="3.1" resource_id="[null]" user_id="[null]"/>
+  <properties id="3" prop_key="sonar.core.startTime" text_value="2012-04-19T11:01:45+0200" resource_id="[null]" user_id="[null]"/>
+  <properties id="4" prop_key="key1" text_value="oldvalue" resource_id="[null]" user_id="[null]"/>
+
+  <!-- project properties -->
+  <properties id="5" prop_key="old2" text_value="value2" resource_id="3" user_id="[null]"/>
+  
+</dataset>
\ No newline at end of file