]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3126 Ignore "sonar.core.id" when exporting properties
authorFabrice Bellingard <bellingard@gmail.com>
Mon, 21 May 2012 06:56:50 +0000 (08:56 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Mon, 21 May 2012 06:56:50 +0000 (08:56 +0200)
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/shouldExportProperties.xml

index 85f0a56f2433097eb879f07977c9f9029a6663ff..da419f65b2624e8846a52000538a86002d3f774a 100644 (file)
@@ -44,7 +44,11 @@ public class PropertiesBackup implements Backupable {
     List<Property> dbProperties = databaseSession.createQuery(FROM_GLOBAL_PROPERTIES).getResultList();
     if (dbProperties != null) {
       for (Property dbProperty : dbProperties) {
-        xmlProperties.add(new Property(dbProperty.getKey(), dbProperty.getValue()));
+        String propKey = dbProperty.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
+          xmlProperties.add(new Property(dbProperty.getKey(), dbProperty.getValue()));
+        }
       }
       sonarConfig.setProperties(xmlProperties);
     }
index 275be22557d4568784fd9dd2682fd6dcf8768544..d8f207ac8339ba597424fadff132e867e78ddfce 100644 (file)
@@ -54,8 +54,9 @@ public class PropertiesBackupTest extends AbstractDbUnitTestCase {
 
     Property prop1 = new Property("key1", "value1");
     Property prop2 = new Property("key2", "value2");
+    Property prop3 = new Property("sonar.core.version", "3.1");
 
-    assertTrue(CollectionUtils.isEqualCollection(sonarConfig.getProperties(), Arrays.asList(prop1, prop2)));
+    assertTrue(CollectionUtils.isEqualCollection(sonarConfig.getProperties(), Arrays.asList(prop1, prop2, prop3)));
   }
 
   @Test
index 2067cd1bcd29f29f9fd9ef47606b60745f72e9f4..0465db20f30d7c1846a2b8c13728765e71c32518 100644 (file)
@@ -1,4 +1,10 @@
 <dataset>
   <properties id="1" prop_key="key1" text_value="value1" resource_id="[null]" user_id="[null]"/>
   <properties id="2" prop_key="key2" text_value="value2" resource_id="[null]" user_id="[null]"/>
+  
+  <!-- Sonar Core property that should not be exported -->
+  <properties id="3" prop_key="sonar.core.id" text_value="123456" resource_id="[null]" user_id="[null]"/>
+  
+  <!-- Sonar Core property that should be exported -->
+  <properties id="4" prop_key="sonar.core.version" text_value="3.1" resource_id="[null]" user_id="[null]"/>
 </dataset>
\ No newline at end of file