From 4a8aa36a50c817bbda91f809b5cd919cc560482b Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Mon, 21 May 2012 08:02:33 +0200 Subject: [PATCH] SONAR-3126 Only "sonar.core.id" should remain unchanged => See https://github.com/SonarSource/sonar/commit/44ff7e7806469b587c1e3f252ad00d696b2b52db --- .../server/configuration/PropertiesBackup.java | 13 +++++++++---- .../server/configuration/PropertiesBackupTest.java | 13 ++++++++++++- .../shouldImportProperties-result.xml | 6 +++++- .../PropertiesBackupTest/shouldImportProperties.xml | 4 +++- .../shouldNotImportSonarCoreIdProperty-result.xml | 8 ++++++++ .../shouldNotImportSonarCoreIdProperty.xml | 11 +++++++++++ 6 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldNotImportSonarCoreIdProperty-result.xml create mode 100644 sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldNotImportSonarCoreIdProperty.xml diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java b/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java index 5c08b5e0a84..85f0a56f243 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java @@ -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) { diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java index 1a71aba251e..275be22557d 100644 --- a/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java +++ b/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java @@ -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 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"); diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldImportProperties-result.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldImportProperties-result.xml index ee0bfbe9964..ef2bf774438 100644 --- a/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldImportProperties-result.xml +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldImportProperties-result.xml @@ -11,10 +11,14 @@ - + + + + diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldImportProperties.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldImportProperties.xml index a820b74a25b..70baf106f3c 100644 --- a/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldImportProperties.xml +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldImportProperties.xml @@ -10,8 +10,10 @@ - + + + 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 index 00000000000..6960761aeea --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldNotImportSonarCoreIdProperty-result.xml @@ -0,0 +1,8 @@ + + + + + + + + \ 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 index 00000000000..67a28cb033e --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldNotImportSonarCoreIdProperty.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file -- 2.39.5