From 698e779ba5a3ede463ecfe03302880f91073fc6a Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Mon, 21 May 2012 08:56:50 +0200 Subject: [PATCH] SONAR-3126 Ignore "sonar.core.id" when exporting properties --- .../org/sonar/server/configuration/PropertiesBackup.java | 6 +++++- .../sonar/server/configuration/PropertiesBackupTest.java | 3 ++- .../PropertiesBackupTest/shouldExportProperties.xml | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) 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 85f0a56f243..da419f65b26 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 @@ -44,7 +44,11 @@ public class PropertiesBackup implements Backupable { List 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); } 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 275be22557d..d8f207ac833 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 @@ -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 diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldExportProperties.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldExportProperties.xml index 2067cd1bcd2..0465db20f30 100644 --- a/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldExportProperties.xml +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldExportProperties.xml @@ -1,4 +1,10 @@ + + + + + + \ No newline at end of file -- 2.39.5