From 7c2b1c7891e021adb02e17afc3b85bdbc09719ec Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 21 Sep 2017 18:52:39 +0200 Subject: [PATCH] SONAR-9802 order settings of api/system/info --- .../sonar/server/platform/monitoring/SettingsSection.java | 4 +++- .../java/org/sonar/server/platform/ws/BaseInfoWsAction.java | 6 +++--- .../server/platform/monitoring/SettingsSectionTest.java | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SettingsSection.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SettingsSection.java index 961938a46d2..303135abe95 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SettingsSection.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SettingsSection.java @@ -20,6 +20,7 @@ package org.sonar.server.platform.monitoring; import java.util.Map; +import java.util.TreeMap; import org.sonar.api.PropertyType; import org.sonar.api.config.PropertyDefinition; import org.sonar.api.config.PropertyDefinitions; @@ -52,7 +53,8 @@ public class SettingsSection implements SystemInfoSection, Global { protobuf.setName("Settings"); PropertyDefinitions definitions = settings.getDefinitions(); - for (Map.Entry prop : settings.getProperties().entrySet()) { + TreeMap orderedProps = new TreeMap<>(settings.getProperties()); + for (Map.Entry prop : orderedProps.entrySet()) { String key = prop.getKey(); String value = obfuscateValue(definitions, key, prop.getValue()); setAttribute(protobuf, key, value); diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/BaseInfoWsAction.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/BaseInfoWsAction.java index 4f2607a96cc..f50aebe0c65 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/BaseInfoWsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/BaseInfoWsAction.java @@ -36,9 +36,9 @@ public abstract class BaseInfoWsAction implements SystemWsAction { private static final String[] ORDERED_SECTION_NAMES = { "System", "Database", "Plugins", - "Web JVM State", "Web Logging", "Web JVM Properties", - "Search State", "Search Statistics", - "Compute Engine Database Connection", "Compute Engine JVM State", "Compute Engine Logging", "Compute Engine Tasks", "Compute Engine JVM Properties"}; + "Web JVM State", "Web Database Connection", "Web Logging", "Web JVM Properties", + "Search State", "Search Indexes", + "Compute Engine Tasks", "Compute Engine JVM State", "Compute Engine Database Connection", "Compute Engine Logging", "Compute Engine JVM Properties"}; private final UserSession userSession; private final TelemetryDataLoader telemetry; diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SettingsSectionTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SettingsSectionTest.java index dc6c9c1b16c..02ff00d71a6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SettingsSectionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SettingsSectionTest.java @@ -48,6 +48,11 @@ public class SettingsSectionTest { ProtobufSystemInfo.Section protobuf = underTest.toProtobuf(); assertThatAttributeIs(protobuf, "bar", "bar value"); assertThatAttributeIs(protobuf, "foo", "foo value"); + + // keys are ordered alphabetically + assertThat(protobuf.getAttributesList()) + .extracting(ProtobufSystemInfo.Attribute::getKey) + .containsExactly("bar", "foo"); } @Test -- 2.39.5