]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6293 refactor loading of default values of sonar.properties
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 30 Mar 2015 21:00:55 +0000 (23:00 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 30 Mar 2015 21:02:01 +0000 (23:02 +0200)
49 files changed:
server/sonar-process/src/main/java/org/sonar/process/LogbackHelper.java
server/sonar-process/src/main/java/org/sonar/process/ProcessConstants.java [deleted file]
server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java [new file with mode: 0644]
server/sonar-process/src/test/java/org/sonar/process/LogbackHelperTest.java
server/sonar-process/src/test/java/org/sonar/process/ProcessPropertiesTest.java [new file with mode: 0644]
server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
server/sonar-search/src/main/java/org/sonar/search/SearchSettings.java
server/sonar-search/src/main/java/org/sonar/search/script/ListUpdate.java
server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java
server/sonar-search/src/test/java/org/sonar/search/SearchSettingsTest.java
server/sonar-search/src/test/java/org/sonar/search/script/UpdateListScriptTest.java
server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/app/EmbeddedTomcat.java
server/sonar-server/src/main/java/org/sonar/server/app/Webapp.java
server/sonar-server/src/main/java/org/sonar/server/computation/ReportQueue.java
server/sonar-server/src/main/java/org/sonar/server/db/EmbeddedDatabase.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java
server/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java
server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SonarQubeMonitor.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleNormalizer.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java
server/sonar-server/src/main/java/org/sonar/server/search/SearchClient.java
server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java
server/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexDefinition.java
server/sonar-server/src/test/java/org/sonar/server/activity/index/ActivityIndexDefinitionTest.java
server/sonar-server/src/test/java/org/sonar/server/app/TomcatAccessLogTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/ReportQueueTest.java
server/sonar-server/src/test/java/org/sonar/server/db/EmbeddedDatabaseTest.java
server/sonar-server/src/test/java/org/sonar/server/es/EsServerHolder.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDefinitionTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java
server/sonar-server/src/test/java/org/sonar/server/search/BaseIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineIndexDefinitionTest.java
server/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java
server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexDefinitionTest.java
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexDefinitionTest.java
sonar-application/src/main/assembly/conf/sonar.properties
sonar-application/src/main/java/org/sonar/application/App.java
sonar-application/src/main/java/org/sonar/application/DefaultSettings.java [deleted file]
sonar-application/src/main/java/org/sonar/application/JdbcSettings.java
sonar-application/src/main/java/org/sonar/application/PropsBuilder.java
sonar-application/src/test/java/org/sonar/application/AppLoggingTest.java
sonar-application/src/test/java/org/sonar/application/AppTest.java
sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java [deleted file]
sonar-application/src/test/java/org/sonar/application/JdbcSettingsTest.java

index cb9bb6a80804302bd9c8b4fe723c8da2feddf19b..5ed5459c0c89468f1e89254630fdf17427ad8e24 100644 (file)
@@ -94,7 +94,7 @@ public class LogbackHelper {
   public RollingPolicy createRollingPolicy(Context ctx, Props props, String filenamePrefix) {
     String rollingPolicy = props.value(ROLLING_POLICY_PROPERTY, "time:yyyy-MM-dd");
     int maxFiles = props.valueAsInt(MAX_FILES_PROPERTY, 7);
-    File logsDir = props.nonNullValueAsFile(ProcessConstants.PATH_LOGS);
+    File logsDir = props.nonNullValueAsFile(ProcessProperties.PATH_LOGS);
 
     if (rollingPolicy.startsWith("time:")) {
       return new TimeRollingPolicy(ctx, filenamePrefix, logsDir, maxFiles, StringUtils.substringAfter(rollingPolicy, "time:"));
diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessConstants.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessConstants.java
deleted file mode 100644 (file)
index 4a07836..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.process;
-
-/**
- * Constants shared by search, web server and monitor processes.
- * It represents more or less all the properties commented in conf/sonar.properties
- */
-public interface ProcessConstants {
-
-  String CLUSTER_ACTIVATE = "sonar.cluster.activate";
-  String CLUSTER_MASTER = "sonar.cluster.master";
-  String CLUSTER_MASTER_HOST = "sonar.cluster.masterHost";
-  String CLUSTER_NAME = "sonar.cluster.name";
-  String CLUSTER_NODE_NAME = "sonar.node.name";
-
-  String JDBC_URL = "sonar.jdbc.url";
-  String JDBC_LOGIN = "sonar.jdbc.username";
-  String JDBC_PASSWORD = "sonar.jdbc.password";
-  String JDBC_DRIVER_PATH = "sonar.jdbc.driverPath";
-  String JDBC_MAX_ACTIVE = "sonar.jdbc.maxActive";
-  String JDBC_MAX_IDLE = "sonar.jdbc.maxIdle";
-  String JDBC_MIN_IDLE = "sonar.jdbc.minIdle";
-  String JDBC_MAX_WAIT = "sonar.jdbc.maxWait";
-  String JDBC_MIN_EVICTABLE_IDLE_TIME_MILLIS = "sonar.jdbc.minEvictableIdleTimeMillis";
-  String JDBC_TIME_BETWEEN_EVICTION_RUNS_MILLIS = "sonar.jdbc.timeBetweenEvictionRunsMillis";
-
-  String PATH_DATA = "sonar.path.data";
-  String PATH_HOME = "sonar.path.home";
-  String PATH_LOGS = "sonar.path.logs";
-  String PATH_TEMP = "sonar.path.temp";
-  String PATH_WEB = "sonar.path.web";
-
-  String SEARCH_HOST = "sonar.search.host";
-  String SEARCH_PORT = "sonar.search.port";
-  String SEARCH_JAVA_OPTS = "sonar.search.javaOpts";
-  String SEARCH_JAVA_ADDITIONAL_OPTS = "sonar.search.javaAdditionalOpts";
-  String SEARCH_TYPE = "sonar.search.type";
-
-  String WEB_JAVA_OPTS = "sonar.web.javaOpts";
-  String WEB_JAVA_ADDITIONAL_OPTS = "sonar.web.javaAdditionalOpts";
-
-  /**
-   * Used by Orchestrator to ask for shutdown of monitor process
-   */
-  String ENABLE_STOP_COMMAND = "sonar.enableStopCommand";
-
-  // Constants declared by the ES plugin ListUpdate (see sonar-search)
-  // that are used by sonar-server
-  String ES_PLUGIN_LISTUPDATE_SCRIPT_NAME = "listUpdate";
-  String ES_PLUGIN_LISTUPDATE_ID_FIELD = "idField";
-  String ES_PLUGIN_LISTUPDATE_ID_VALUE = "idValue";
-  String ES_PLUGIN_LISTUPDATE_FIELD = "field";
-  String ES_PLUGIN_LISTUPDATE_VALUE = "value";
-}
diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java
new file mode 100644 (file)
index 0000000..9532d3b
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.process;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Constants shared by search, web server and app processes.
+ * They are almost all the properties defined in conf/sonar.properties.
+ */
+public class ProcessProperties {
+
+  public static final String CLUSTER_ACTIVATE = "sonar.cluster.activate";
+  public static final String CLUSTER_MASTER = "sonar.cluster.master";
+  public static final String CLUSTER_MASTER_HOST = "sonar.cluster.masterHost";
+  public static final String CLUSTER_NAME = "sonar.cluster.name";
+  public static final String CLUSTER_NODE_NAME = "sonar.node.name";
+
+  public static final String JDBC_URL = "sonar.jdbc.url";
+  public static final String JDBC_LOGIN = "sonar.jdbc.username";
+  public static final String JDBC_PASSWORD = "sonar.jdbc.password";
+  public static final String JDBC_DRIVER_PATH = "sonar.jdbc.driverPath";
+  public static final String JDBC_MAX_ACTIVE = "sonar.jdbc.maxActive";
+  public static final String JDBC_MAX_IDLE = "sonar.jdbc.maxIdle";
+  public static final String JDBC_MIN_IDLE = "sonar.jdbc.minIdle";
+  public static final String JDBC_MAX_WAIT = "sonar.jdbc.maxWait";
+  public static final String JDBC_MIN_EVICTABLE_IDLE_TIME_MILLIS = "sonar.jdbc.minEvictableIdleTimeMillis";
+  public static final String JDBC_TIME_BETWEEN_EVICTION_RUNS_MILLIS = "sonar.jdbc.timeBetweenEvictionRunsMillis";
+
+  public static final String PATH_DATA = "sonar.path.data";
+  public static final String PATH_HOME = "sonar.path.home";
+  public static final String PATH_LOGS = "sonar.path.logs";
+  public static final String PATH_TEMP = "sonar.path.temp";
+  public static final String PATH_WEB = "sonar.path.web";
+
+  public static final String SEARCH_HOST = "sonar.search.host";
+  public static final String SEARCH_PORT = "sonar.search.port";
+  public static final String SEARCH_HTTP_PORT = "sonar.search.httpPort";
+  public static final String SEARCH_JAVA_OPTS = "sonar.search.javaOpts";
+  public static final String SEARCH_JAVA_ADDITIONAL_OPTS = "sonar.search.javaAdditionalOpts";
+
+  public static final String WEB_JAVA_OPTS = "sonar.web.javaOpts";
+  public static final String WEB_JAVA_ADDITIONAL_OPTS = "sonar.web.javaAdditionalOpts";
+
+  /**
+   * Used by Orchestrator to ask for shutdown of monitor process
+   */
+  public static final String ENABLE_STOP_COMMAND = "sonar.enableStopCommand";
+
+  // Constants declared by the ES plugin ListUpdate (see sonar-search)
+  // that are used by sonar-server
+  public static final String ES_PLUGIN_LISTUPDATE_SCRIPT_NAME = "listUpdate";
+  public static final String ES_PLUGIN_LISTUPDATE_ID_FIELD = "idField";
+  public static final String ES_PLUGIN_LISTUPDATE_ID_VALUE = "idValue";
+  public static final String ES_PLUGIN_LISTUPDATE_FIELD = "field";
+  public static final String ES_PLUGIN_LISTUPDATE_VALUE = "value";
+
+  public static final String WEB_ENFORCED_JVM_ARGS = "-Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djruby.management.enabled=false " +
+    // jruby is slow with java 8: https://jira.codehaus.org/browse/SONAR-6115
+    "-Djruby.compile.invokedynamic=false";
+
+  private ProcessProperties() {
+    // only static stuff
+  }
+
+  public static void completeDefaults(Props props) {
+    // init string properties
+    for (Map.Entry<String, String> entry : defaults().entrySet()) {
+      props.setDefault(entry.getKey(), entry.getValue());
+    }
+
+    // init ports
+    for (Map.Entry<String, Integer> entry : defaultPorts().entrySet()) {
+      String key = entry.getKey();
+      int port = props.valueAsInt(key, -1);
+      if (port == -1) {
+        // default port
+        props.set(key, String.valueOf((int) entry.getValue()));
+      } else if (port == 0) {
+        // pick one available port
+        props.set(key, String.valueOf(NetworkUtils.freePort()));
+      }
+    }
+  }
+
+  public static Map<String, String> defaults() {
+    Map<String, String> defaults = new HashMap<>();
+    defaults.put(ProcessProperties.CLUSTER_NAME, "sonarqube");
+    defaults.put(ProcessProperties.CLUSTER_NODE_NAME, "sonar-" + System.currentTimeMillis());
+
+    defaults.put(ProcessProperties.SEARCH_HOST, "127.0.0.1");
+    defaults.put(ProcessProperties.SEARCH_JAVA_OPTS, "-Xmx1G -Xms256m -Xss256k -Djava.net.preferIPv4Stack=true " +
+      "-XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly " +
+      "-XX:+HeapDumpOnOutOfMemoryError");
+    defaults.put(ProcessProperties.SEARCH_JAVA_ADDITIONAL_OPTS, "");
+
+    defaults.put(ProcessProperties.WEB_JAVA_OPTS, "-Xmx768m -XX:MaxPermSize=160m -XX:+HeapDumpOnOutOfMemoryError -Djava.net.preferIPv4Stack=true");
+    defaults.put(ProcessProperties.WEB_JAVA_ADDITIONAL_OPTS, "");
+    defaults.put(ProcessProperties.JDBC_URL, "jdbc:h2:tcp://localhost:9092/sonar");
+    defaults.put(ProcessProperties.JDBC_LOGIN, "sonar");
+    defaults.put(ProcessProperties.JDBC_PASSWORD, "sonar");
+    defaults.put(ProcessProperties.JDBC_MAX_ACTIVE, "50");
+    defaults.put(ProcessProperties.JDBC_MAX_IDLE, "5");
+    defaults.put(ProcessProperties.JDBC_MIN_IDLE, "2");
+    defaults.put(ProcessProperties.JDBC_MAX_WAIT, "5000");
+    defaults.put(ProcessProperties.JDBC_MIN_EVICTABLE_IDLE_TIME_MILLIS, "600000");
+    defaults.put(ProcessProperties.JDBC_TIME_BETWEEN_EVICTION_RUNS_MILLIS, "30000");
+    return defaults;
+  }
+
+  private static Map<String, Integer> defaultPorts() {
+    Map<String, Integer> defaults = new HashMap<>();
+    defaults.put(ProcessProperties.SEARCH_PORT, 9001);
+    return defaults;
+  }
+}
index 667a5632ebe66407d5249aac8fe7601b51084845..753d06e67c4116a33303407252b639de2182339d 100644 (file)
@@ -54,7 +54,7 @@ public class LogbackHelperTest {
   @Before
   public void setUp() throws Exception {
     File dir = temp.newFolder();
-    props.set(ProcessConstants.PATH_LOGS, dir.getAbsolutePath());
+    props.set(ProcessProperties.PATH_LOGS, dir.getAbsolutePath());
   }
 
   @AfterClass
diff --git a/server/sonar-process/src/test/java/org/sonar/process/ProcessPropertiesTest.java b/server/sonar-process/src/test/java/org/sonar/process/ProcessPropertiesTest.java
new file mode 100644 (file)
index 0000000..2a8cddd
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.process;
+
+import org.junit.Test;
+import org.sonar.test.TestUtils;
+
+import java.util.Properties;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ProcessPropertiesTest {
+
+  @Test
+  public void init_defaults() throws Exception {
+    Props props = new Props(new Properties());
+    ProcessProperties.completeDefaults(props);
+
+    assertThat(props.value("sonar.search.javaOpts")).contains("-Xmx");
+    assertThat(props.value("sonar.jdbc.username")).isEqualTo("sonar");
+    assertThat(props.valueAsInt("sonar.jdbc.maxActive")).isEqualTo(50);
+  }
+
+  @Test
+  public void do_not_override_existing_properties() throws Exception {
+    Properties p = new Properties();
+    p.setProperty("sonar.jdbc.username", "angela");
+    Props props = new Props(p);
+    ProcessProperties.completeDefaults(props);
+
+    assertThat(props.value("sonar.jdbc.username")).isEqualTo("angela");
+  }
+
+  @Test
+  public void use_random_port_if_zero() throws Exception {
+    Properties p = new Properties();
+    p.setProperty("sonar.search.port", "0");
+    Props props = new Props(p);
+
+    ProcessProperties.completeDefaults(props);
+    assertThat(props.valueAsInt("sonar.search.port")).isGreaterThan(0);
+  }
+
+  @Test
+  public void private_constructor() throws Exception {
+    assertThat(TestUtils.hasOnlyPrivateConstructors(ProcessProperties.class)).isTrue();
+  }
+}
index fdc575277d2e7a5fb59d9b416534ebf98c414e7a..13dde539c1092047d50f80a226a6bea3f9736eea 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.search;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.node.internal.InternalNode;
-import org.slf4j.LoggerFactory;
 import org.sonar.process.MinimumViableSystem;
 import org.sonar.process.Monitored;
 import org.sonar.process.ProcessEntryPoint;
@@ -40,8 +39,6 @@ public class SearchServer implements Monitored {
 
   @Override
   public void start() {
-    LoggerFactory.getLogger(SearchServer.class).info("Starting Elasticsearch[{}] on port {}", settings.clusterName(), settings.tcpPort());
-
     node = new InternalNode(settings.build(), false);
     node.start();
   }
index 6ae77559f277bd7001e6c5bc0870f782bec7f1c9..bab755bc722b0730345f209936bde4dc16edcd1b 100644 (file)
@@ -26,7 +26,7 @@ import org.elasticsearch.common.settings.Settings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.process.MessageException;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 import org.sonar.search.script.ListUpdate;
 
@@ -40,45 +40,22 @@ class SearchSettings {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(SearchSettings.class);
 
-  public static final String PROP_HTTP_PORT = "sonar.search.httpPort";
   public static final String PROP_MARVEL_HOSTS = "sonar.search.marvelHosts";
 
   private final Props props;
-  private final Set<String> masterHosts = new LinkedHashSet<String>();
-  private final String clusterName;
-  private final String hostName;
-  private final int tcpPort;
+  private final Set<String> masterHosts = new LinkedHashSet<>();
 
   SearchSettings(Props props) {
     this.props = props;
-    masterHosts.addAll(Arrays.asList(StringUtils.split(props.value(ProcessConstants.CLUSTER_MASTER_HOST, ""), ",")));
-    clusterName = props.value(ProcessConstants.CLUSTER_NAME);
-    hostName = props.value(ProcessConstants.SEARCH_HOST);
-    Integer port = props.valueAsInt(ProcessConstants.SEARCH_PORT);
-    if (port == null) {
-      throw new MessageException("Property is not set: " + ProcessConstants.SEARCH_PORT);
-    }
-    tcpPort = port.intValue();
+    masterHosts.addAll(Arrays.asList(StringUtils.split(props.value(ProcessProperties.CLUSTER_MASTER_HOST, ""), ",")));
   }
 
   boolean inCluster() {
-    return props.valueAsBoolean(ProcessConstants.CLUSTER_ACTIVATE, false);
+    return props.valueAsBoolean(ProcessProperties.CLUSTER_ACTIVATE, false);
   }
 
   boolean isMaster() {
-    return props.valueAsBoolean(ProcessConstants.CLUSTER_MASTER, false);
-  }
-
-  String clusterName() {
-    return clusterName;
-  }
-
-  int tcpPort() {
-    return tcpPort;
-  }
-  
-  String hostName() {
-    return hostName;
+    return props.valueAsBoolean(ProcessProperties.CLUSTER_MASTER, false);
   }
 
   Settings build() {
@@ -93,11 +70,11 @@ class SearchSettings {
   }
 
   private void configureFileSystem(ImmutableSettings.Builder builder) {
-    File homeDir = props.nonNullValueAsFile(ProcessConstants.PATH_HOME);
+    File homeDir = props.nonNullValueAsFile(ProcessProperties.PATH_HOME);
     File dataDir, workDir, logDir;
 
     // data dir
-    String dataPath = props.value(ProcessConstants.PATH_DATA);
+    String dataPath = props.value(ProcessProperties.PATH_DATA);
     if (StringUtils.isNotEmpty(dataPath)) {
       dataDir = new File(dataPath, "es");
     } else {
@@ -106,7 +83,7 @@ class SearchSettings {
     builder.put("path.data", dataDir.getAbsolutePath());
 
     // working dir
-    String workPath = props.value(ProcessConstants.PATH_TEMP);
+    String workPath = props.value(ProcessProperties.PATH_TEMP);
     if (StringUtils.isNotEmpty(workPath)) {
       workDir = new File(workPath);
     } else {
@@ -116,7 +93,7 @@ class SearchSettings {
     builder.put("path.plugins", workDir.getAbsolutePath());
 
     // log dir
-    String logPath = props.value(ProcessConstants.PATH_LOGS);
+    String logPath = props.value(ProcessProperties.PATH_LOGS);
     if (StringUtils.isNotEmpty(logPath)) {
       logDir = new File(logPath);
     } else {
@@ -128,22 +105,25 @@ class SearchSettings {
   private void configurePlugins(ImmutableSettings.Builder builder) {
     builder
       .put("script.default_lang", "native")
-      .put(String.format("script.native.%s.type", ProcessConstants.ES_PLUGIN_LISTUPDATE_SCRIPT_NAME),
+      .put(String.format("script.native.%s.type", ProcessProperties.ES_PLUGIN_LISTUPDATE_SCRIPT_NAME),
         ListUpdate.UpdateListScriptFactory.class.getName());
   }
 
   private void configureNetwork(ImmutableSettings.Builder builder) {
+    String host = props.value(ProcessProperties.SEARCH_HOST);
+    Integer port = props.valueAsInt(ProcessProperties.SEARCH_PORT);
+    LOGGER.info("Elasticsearch listening on {}:{}", host, port);
+
     // disable multicast
     builder.put("discovery.zen.ping.multicast.enabled", "false");
-    builder.put("transport.tcp.port", tcpPort);
-    if (hostName != null) {
-      builder.put("transport.host", hostName);
-    }
+    builder.put("transport.tcp.port", port);
+    builder.put("transport.host", host);
+
     // Elasticsearch sets the default value of TCP reuse address to true only on non-MSWindows machines, but why ?
     builder.put("network.tcp.reuse_address", true);
 
-    Integer httpPort = props.valueAsInt(PROP_HTTP_PORT);
-    if (httpPort == null) {
+    Integer httpPort = props.valueAsInt(ProcessProperties.SEARCH_HTTP_PORT);
+    if (httpPort == null || httpPort < 0) {
       // standard configuration
       builder.put("http.enabled", false);
     } else {
@@ -152,11 +132,7 @@ class SearchSettings {
       // see https://github.com/lmenezes/elasticsearch-kopf/issues/195
       builder.put("http.cors.enabled", true);
       builder.put("http.enabled", true);
-      if (hostName != null) {
-        builder.put("http.host", hostName);
-      } else {
-        builder.put("http.host", "127.0.0.1");
-      }
+      builder.put("http.host", host);
       builder.put("http.port", httpPort);
     }
   }
@@ -181,18 +157,18 @@ class SearchSettings {
         builder.put("discovery.zen.minimum_master_nodes", 1);
       } else {
         throw new MessageException(String.format("Not an Elasticsearch master nor slave. Please check properties %s and %s",
-          ProcessConstants.CLUSTER_MASTER, ProcessConstants.CLUSTER_MASTER_HOST));
+          ProcessProperties.CLUSTER_MASTER, ProcessProperties.CLUSTER_MASTER_HOST));
       }
     }
     builder.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, replicationFactor);
-    builder.put("cluster.name", clusterName);
+    builder.put("cluster.name", props.value(ProcessProperties.CLUSTER_NAME));
     builder.put("cluster.routing.allocation.awareness.attributes", "rack_id");
-    builder.put("node.rack_id", props.value(ProcessConstants.CLUSTER_NODE_NAME, "unknown"));
-    builder.put("node.name", props.value(ProcessConstants.CLUSTER_NODE_NAME));
+    builder.put("node.rack_id", props.value(ProcessProperties.CLUSTER_NODE_NAME, "unknown"));
+    builder.put("node.name", props.value(ProcessProperties.CLUSTER_NODE_NAME));
   }
 
   private void configureMarvel(ImmutableSettings.Builder builder) {
-    Set<String> marvels = new TreeSet<String>();
+    Set<String> marvels = new TreeSet<>();
     marvels.addAll(Arrays.asList(StringUtils.split(props.value(PROP_MARVEL_HOSTS, ""), ",")));
 
     // If we're collecting indexing data send them to the Marvel host(s)
index 721ba6b2328e7e6d1f331aaaf574572713db71ee..587825f60f59cc14578fca371910ffff08207f20 100644 (file)
@@ -24,7 +24,7 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues;
 import org.elasticsearch.script.AbstractExecutableScript;
 import org.elasticsearch.script.ExecutableScript;
 import org.elasticsearch.script.NativeScriptFactory;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -36,25 +36,25 @@ public class ListUpdate extends AbstractExecutableScript {
   public static class UpdateListScriptFactory implements NativeScriptFactory {
     @Override
     public ExecutableScript newScript(@Nullable Map<String, Object> params) {
-      String idField = XContentMapValues.nodeStringValue(params.get(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD), null);
-      String idValue = XContentMapValues.nodeStringValue(params.get(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE), null);
-      String field = XContentMapValues.nodeStringValue(params.get(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD), null);
+      String idField = XContentMapValues.nodeStringValue(params.get(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_FIELD), null);
+      String idValue = XContentMapValues.nodeStringValue(params.get(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_VALUE), null);
+      String field = XContentMapValues.nodeStringValue(params.get(ProcessProperties.ES_PLUGIN_LISTUPDATE_FIELD), null);
       Map value = null;
       if (idField == null) {
-        throw new IllegalStateException(String.format("Missing '%s' parameter", ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD));
+        throw new IllegalStateException(String.format("Missing '%s' parameter", ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_FIELD));
       }
       if (idValue == null) {
-        throw new IllegalStateException(String.format("Missing '%s' parameter", ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE));
+        throw new IllegalStateException(String.format("Missing '%s' parameter", ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_VALUE));
       }
       if (field == null) {
-        throw new IllegalStateException(String.format("Missing '%s' parameter", ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD));
+        throw new IllegalStateException(String.format("Missing '%s' parameter", ProcessProperties.ES_PLUGIN_LISTUPDATE_FIELD));
       }
 
       //NULL case is deletion of nested item
-      if (params.containsKey(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE)) {
-        Object obj = params.get(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE);
+      if (params.containsKey(ProcessProperties.ES_PLUGIN_LISTUPDATE_VALUE)) {
+        Object obj = params.get(ProcessProperties.ES_PLUGIN_LISTUPDATE_VALUE);
         if (obj != null) {
-          value = XContentMapValues.nodeMapValue(params.get(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE), "Update item");
+          value = XContentMapValues.nodeMapValue(params.get(ProcessProperties.ES_PLUGIN_LISTUPDATE_VALUE), "Update item");
         }
       }
 
index 3b01279891682a84cc55bd2881b89b5bf737154d..bd8f49b511a3d0137cbb4aaa8704cfa405fcf115 100644 (file)
@@ -34,9 +34,10 @@ import org.junit.rules.TemporaryFolder;
 import org.junit.rules.TestRule;
 import org.junit.rules.Timeout;
 import org.sonar.process.NetworkUtils;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 
+import java.net.InetAddress;
 import java.util.Properties;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -70,16 +71,22 @@ public class SearchServerTest {
   @Test
   public void start_stop_server() throws Exception {
     Props props = new Props(new Properties());
-    props.set(ProcessConstants.SEARCH_PORT, String.valueOf(port));
-    props.set(ProcessConstants.CLUSTER_NAME, CLUSTER_NAME);
-    props.set(ProcessConstants.CLUSTER_NODE_NAME, "test");
-    props.set(ProcessConstants.PATH_HOME, temp.newFolder().getAbsolutePath());
+    // the following properties have always default values (see ProcessProperties)
+    String host = InetAddress.getLocalHost().getHostAddress();
+    props.set(ProcessProperties.SEARCH_HOST, host);
+    props.set(ProcessProperties.SEARCH_PORT, String.valueOf(port));
+    props.set(ProcessProperties.CLUSTER_NAME, CLUSTER_NAME);
+    props.set(ProcessProperties.CLUSTER_NODE_NAME, "test");
+    props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath());
 
     searchServer = new SearchServer(props);
     searchServer.start();
     assertThat(searchServer.isReady()).isTrue();
 
-    client = getSearchClient();
+    Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", CLUSTER_NAME).build();
+    client = new TransportClient(settings)
+      .addTransportAddress(new InetSocketTransportAddress(host, port));
+    assertThat(client.admin().cluster().prepareClusterStats().get().getStatus()).isEqualTo(ClusterHealthStatus.GREEN);
 
     searchServer.stop();
     searchServer.awaitStop();
@@ -91,13 +98,4 @@ public class SearchServerTest {
       // ok
     }
   }
-
-  private Client getSearchClient() {
-    Settings settings = ImmutableSettings.settingsBuilder()
-      .put("cluster.name", CLUSTER_NAME).build();
-    Client client = new TransportClient(settings)
-      .addTransportAddress(new InetSocketTransportAddress("localhost", port));
-    assertThat(client.admin().cluster().prepareClusterStats().get().getStatus()).isEqualTo(ClusterHealthStatus.GREEN);
-    return client;
-  }
 }
index 59213c08f4146dd8e1f1c5e90f42b4f7328ffbca..295eb86b94a2cb887ae1ac64efbd0411ada2ff80 100644 (file)
@@ -24,7 +24,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.process.MessageException;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 
 import java.io.File;
@@ -39,31 +39,18 @@ public class SearchSettingsTest {
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  @Test
-  public void fail_if_tcp_port_is_not_set() throws Exception {
-    try {
-      new SearchSettings(new Props(new Properties()));
-      fail();
-    } catch (MessageException e) {
-      assertThat(e).hasMessage("Property is not set: sonar.search.port");
-    }
-  }
-
   @Test
   public void test_default_settings() throws Exception {
     File homeDir = temp.newFolder();
     Props props = new Props(new Properties());
-    props.set(ProcessConstants.SEARCH_PORT, "1234");
-    props.set(ProcessConstants.SEARCH_HOST, "127.0.0.1");
-    props.set(ProcessConstants.PATH_HOME, homeDir.getAbsolutePath());
-    props.set(ProcessConstants.CLUSTER_NAME, "tests");
-    props.set(ProcessConstants.CLUSTER_NODE_NAME, "test");
+    props.set(ProcessProperties.SEARCH_PORT, "1234");
+    props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1");
+    props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
+    props.set(ProcessProperties.CLUSTER_NAME, "tests");
+    props.set(ProcessProperties.CLUSTER_NODE_NAME, "test");
 
     SearchSettings searchSettings = new SearchSettings(props);
     assertThat(searchSettings.inCluster()).isFalse();
-    assertThat(searchSettings.clusterName()).isEqualTo("tests");
-    assertThat(searchSettings.tcpPort()).isEqualTo(1234);
-    assertThat(searchSettings.hostName()).isEqualTo("127.0.0.1");
 
     Settings generated = searchSettings.build();
     assertThat(generated.get("transport.tcp.port")).isEqualTo("1234");
@@ -89,24 +76,21 @@ public class SearchSettingsTest {
 
     SearchSettings searchSettings = new SearchSettings(props);
     assertThat(searchSettings.inCluster()).isFalse();
-    assertThat(searchSettings.clusterName()).isEqualTo("tests");
-    assertThat(searchSettings.tcpPort()).isEqualTo(1234);
-    assertThat(searchSettings.hostName()).isEqualTo(null);
 
     Settings generated = searchSettings.build();
-    assertThat(generated.get("transport.tcp.port")).isEqualTo("1234");
-    assertThat(generated.get("transport.host")).isEqualTo(null);
-    assertThat(generated.get("cluster.name")).isEqualTo("tests");
-    assertThat(generated.get("node.name")).isEqualTo("test");
+    assertThat(generated.get("transport.tcp.port")).isEqualTo("9001");
+    assertThat(generated.get("transport.host")).isEqualTo("127.0.0.1");
+    assertThat(generated.get("cluster.name")).isEqualTo("sonarqube");
+    assertThat(generated.get("node.name")).startsWith("sonar-");
   }
 
   @Test
   public void override_dirs() throws Exception {
     File dataDir = temp.newFolder(), logDir = temp.newFolder(), tempDir = temp.newFolder();
     Props props = minProps();
-    props.set(ProcessConstants.PATH_DATA, dataDir.getAbsolutePath());
-    props.set(ProcessConstants.PATH_LOGS, logDir.getAbsolutePath());
-    props.set(ProcessConstants.PATH_TEMP, tempDir.getAbsolutePath());
+    props.set(ProcessProperties.PATH_DATA, dataDir.getAbsolutePath());
+    props.set(ProcessProperties.PATH_LOGS, logDir.getAbsolutePath());
+    props.set(ProcessProperties.PATH_TEMP, tempDir.getAbsolutePath());
 
     Settings settings = new SearchSettings(props).build();
 
@@ -118,8 +102,8 @@ public class SearchSettingsTest {
   @Test
   public void test_cluster_master() throws Exception {
     Props props = minProps();
-    props.set(ProcessConstants.CLUSTER_ACTIVATE, "true");
-    props.set(ProcessConstants.CLUSTER_MASTER, "true");
+    props.set(ProcessProperties.CLUSTER_ACTIVATE, "true");
+    props.set(ProcessProperties.CLUSTER_MASTER, "true");
     Settings settings = new SearchSettings(props).build();
 
     assertThat(settings.get("index.number_of_replicas")).isEqualTo("1");
@@ -130,8 +114,8 @@ public class SearchSettingsTest {
   @Test
   public void test_cluster_slave() throws Exception {
     Props props = minProps();
-    props.set(ProcessConstants.CLUSTER_ACTIVATE, "true");
-    props.set(ProcessConstants.CLUSTER_MASTER_HOST, "127.0.0.2,127.0.0.3");
+    props.set(ProcessProperties.CLUSTER_ACTIVATE, "true");
+    props.set(ProcessProperties.CLUSTER_MASTER_HOST, "127.0.0.2,127.0.0.3");
     Settings settings = new SearchSettings(props).build();
 
     assertThat(settings.get("discovery.zen.ping.unicast.hosts")).isEqualTo("127.0.0.2,127.0.0.3");
@@ -141,11 +125,12 @@ public class SearchSettingsTest {
   @Test
   public void bad_cluster_configuration() throws Exception {
     Props props = minProps();
-    props.set(ProcessConstants.CLUSTER_ACTIVATE, "true");
+    props.set(ProcessProperties.CLUSTER_ACTIVATE, "true");
     try {
       new SearchSettings(props).build();
       fail();
-    } catch (MessageException e) {
+    } catch (MessageException ignored) {
+      // expected
     }
   }
 
@@ -161,7 +146,7 @@ public class SearchSettingsTest {
   @Test
   public void enable_http_connector() throws Exception {
     Props props = minProps();
-    props.set(SearchSettings.PROP_HTTP_PORT, "9010");
+    props.set(ProcessProperties.SEARCH_HTTP_PORT, "9010");
     Settings settings = new SearchSettings(props).build();
 
     assertThat(settings.get("http.port")).isEqualTo("9010");
@@ -172,8 +157,8 @@ public class SearchSettingsTest {
   @Test
   public void enable_http_connector_different_host() throws Exception {
     Props props = minProps();
-    props.set(SearchSettings.PROP_HTTP_PORT, "9010");
-    props.set(ProcessConstants.SEARCH_HOST, "127.0.0.2");
+    props.set(ProcessProperties.SEARCH_HTTP_PORT, "9010");
+    props.set(ProcessProperties.SEARCH_HOST, "127.0.0.2");
     Settings settings = new SearchSettings(props).build();
 
     assertThat(settings.get("http.port")).isEqualTo("9010");
@@ -184,10 +169,8 @@ public class SearchSettingsTest {
   private Props minProps() throws IOException {
     File homeDir = temp.newFolder();
     Props props = new Props(new Properties());
-    props.set(ProcessConstants.SEARCH_PORT, "1234");
-    props.set(ProcessConstants.PATH_HOME, homeDir.getAbsolutePath());
-    props.set(ProcessConstants.CLUSTER_NAME, "tests");
-    props.set(ProcessConstants.CLUSTER_NODE_NAME, "test");
+    ProcessProperties.completeDefaults(props);
+    props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
     return props;
   }
 }
index d0b6a19da8b0f0a953b0c8f3c8dbb44299809342..0c1f603831cf9a555186138e414d76a896351b0a 100644 (file)
@@ -23,7 +23,7 @@ import com.google.common.collect.ImmutableMap;
 import org.elasticsearch.script.ExecutableScript;
 import org.junit.Before;
 import org.junit.Test;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 
 import java.util.Collection;
 import java.util.HashMap;
@@ -54,7 +54,7 @@ public class UpdateListScriptTest {
     }
 
     // Missing ID_VALUE
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "test");
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_FIELD, "test");
     try {
       factory.newScript(params);
       fail();
@@ -63,7 +63,7 @@ public class UpdateListScriptTest {
     }
 
     // Missing FIELD
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "test");
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_VALUE, "test");
     try {
       factory.newScript(params);
       fail();
@@ -72,12 +72,12 @@ public class UpdateListScriptTest {
     }
 
     // Has all required attributes and Null Value
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, "test");
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_FIELD, "test");
     ExecutableScript script = factory.newScript(params);
     assertThat(script).isNotNull();
 
     // Has all required attributes and VALUE of wrong type
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, new Integer(52));
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_VALUE, new Integer(52));
     try {
       factory.newScript(params);
       fail();
@@ -86,12 +86,12 @@ public class UpdateListScriptTest {
     }
 
     // Has all required attributes and Proper VALUE
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, ImmutableMap.of("key", "value"));
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_VALUE, ImmutableMap.of("key", "value"));
     script = factory.newScript(params);
     assertThat(script).isNotNull();
 
     // Missing ID_FIELD
-    params.remove(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD);
+    params.remove(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_FIELD);
     try {
       factory.newScript(params);
       fail();
@@ -110,10 +110,10 @@ public class UpdateListScriptTest {
 
     // 0 Create list when field does not exists
     Map<String, Object> params = new HashMap<String, Object>();
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, listField);
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "1");
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "1", "value", "A"));
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_FIELD, listField);
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_VALUE, "1");
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "1", "value", "A"));
 
     ExecutableScript script = factory.newScript(params);
     script.setNextVar("ctx", ImmutableMap.of("_source", source));
@@ -125,10 +125,10 @@ public class UpdateListScriptTest {
 
     // Add item to existing list
     params = new HashMap<String, Object>();
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, listField);
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "2");
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "2", "value", "B"));
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_FIELD, listField);
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_VALUE, "2");
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "2", "value", "B"));
     script = factory.newScript(params);
     script.setNextVar("ctx", ImmutableMap.of("_source", source));
     script.run();
@@ -137,10 +137,10 @@ public class UpdateListScriptTest {
 
     // updated first item in list
     params = new HashMap<String, Object>();
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, listField);
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "1");
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "1", "value", "a"));
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_FIELD, listField);
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_VALUE, "1");
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "1", "value", "a"));
     script = factory.newScript(params);
     script.setNextVar("ctx", ImmutableMap.of("_source", source));
     script.run();
@@ -149,10 +149,10 @@ public class UpdateListScriptTest {
 
     // updated second item in list
     params = new HashMap<String, Object>();
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, listField);
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "2");
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "2", "value", "b"));
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_FIELD, listField);
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_VALUE, "2");
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "2", "value", "b"));
     script = factory.newScript(params);
     script.setNextVar("ctx", ImmutableMap.of("_source", source));
     script.run();
@@ -161,10 +161,10 @@ public class UpdateListScriptTest {
 
     // delete first item
     params = new HashMap<String, Object>();
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, listField);
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "1");
-    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, null);
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_FIELD, listField);
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_VALUE, "1");
+    params.put(ProcessProperties.ES_PLUGIN_LISTUPDATE_VALUE, null);
     script = factory.newScript(params);
     script.setNextVar("ctx", ImmutableMap.of("_source", source));
     script.run();
index bac57c0423348485d7734e075dc8276fd361dcc6..38a8fff0a4e81be3cd454eff38d4b79cf1c1900d 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.activity.index;
 import com.google.common.collect.ImmutableMap;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
 import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.NewIndex;
 
@@ -54,7 +54,7 @@ public class ActivityIndexDefinition implements IndexDefinition {
     index.getSettings().put("analysis.analyzer.default.type", "keyword");
 
     // shards
-    boolean clusterMode = settings.getBoolean(ProcessConstants.CLUSTER_ACTIVATE);
+    boolean clusterMode = settings.getBoolean(ProcessProperties.CLUSTER_ACTIVATE);
     if (clusterMode) {
       index.getSettings().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4);
       index.getSettings().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1);
index 1a308b1bfb1e7eb6765754fd7d2d7e9529f72d8e..9cff738819123482064481cf081ab579caa62797 100644 (file)
@@ -25,7 +25,7 @@ import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.commons.io.FileUtils;
 import org.sonar.api.utils.log.Loggers;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 
 import java.io.File;
@@ -86,7 +86,7 @@ class EmbeddedTomcat {
   }
 
   private File tomcatBasedir() {
-    return new File(props.value(ProcessConstants.PATH_TEMP), "tc");
+    return new File(props.value(ProcessProperties.PATH_TEMP), "tc");
   }
 
   void terminate() {
index f2be0473d454a38a036fd5630cb27fe3bf30a194..67c4a0b78b31bdc6e9b9d0a6c9d91d0c754f4ca6 100644 (file)
@@ -24,7 +24,7 @@ import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.utils.log.Loggers;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 
 import java.io.File;
@@ -100,7 +100,7 @@ class Webapp {
   static String webappPath(Props props) {
     String webDir = props.value("sonar.web.dev.sources");
     if (StringUtils.isEmpty(webDir)) {
-      webDir = new File(props.value(ProcessConstants.PATH_HOME), "web").getAbsolutePath();
+      webDir = new File(props.value(ProcessProperties.PATH_HOME), "web").getAbsolutePath();
     }
     Loggers.get(Webapp.class).info(String.format("Webapp directory: %s", webDir));
     return webDir;
index ebddc02357cdcc108ee611c9a5d4c53839d0ca34..51a84f5f356fb9a98b9d20edb47fb190a6b29008 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.api.utils.log.Loggers;
 import org.sonar.core.computation.db.AnalysisReportDto;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.persistence.MyBatis;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.computation.db.AnalysisReportDao;
 import org.sonar.server.db.DbClient;
 
@@ -179,7 +179,7 @@ public class ReportQueue implements ServerComponent {
    * Never return null but the directory may not exist.
    */
   private File reportsDir() {
-    return new File(settings.getString(ProcessConstants.PATH_DATA), "analysis");
+    return new File(settings.getString(ProcessProperties.PATH_DATA), "analysis");
   }
 
   private File reportFileForUuid(String uuid) {
index ef0ab6c5ed1ca37c746b05130c0ad51a43d8d41a..c13017560b43a2909e17bcc3accff6c8753b08bc 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.api.database.DatabaseProperties;
 import org.sonar.api.utils.SonarException;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 
 import java.io.File;
 import java.sql.DriverManager;
@@ -84,7 +84,7 @@ public class EmbeddedDatabase implements Startable {
 
   @VisibleForTesting
   File getDataDirectory(Settings settings) {
-    return new File(settings.getString(ProcessConstants.PATH_DATA));
+    return new File(settings.getString(ProcessProperties.PATH_DATA));
   }
 
   private String getSetting(String name, String defaultValue) {
index 68292b43a93ca9c8b470437546f7d497a610e3ab..9f6b25f6f9695e84125f69662db1814da2b17e97 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.issue.index;
 import com.google.common.collect.ImmutableMap;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
 import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.NewIndex;
 
@@ -97,7 +97,7 @@ public class IssueIndexDefinition implements IndexDefinition {
     index.getSettings().put("index.refresh_interval", "-1");
 
     // shards
-    boolean clusterMode = settings.getBoolean(ProcessConstants.CLUSTER_ACTIVATE);
+    boolean clusterMode = settings.getBoolean(ProcessProperties.CLUSTER_ACTIVATE);
     if (clusterMode) {
       index.getSettings().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4);
       index.getSettings().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1);
index e8e65acbee89c656ab1f8f8d80ee01d48fc0e97f..eecf1e5386ef19b52271fb3891e3de3abe19edd2 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.platform.Server;
 import org.sonar.api.platform.ServerFileSystem;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 
 import java.io.File;
 import java.io.FileFilter;
@@ -50,7 +50,7 @@ public class DefaultServerFileSystem implements ServerFileSystem, Startable {
 
   public DefaultServerFileSystem(Settings settings, Server server) {
     this.server = server;
-    this.homeDir = new File(settings.getString(ProcessConstants.PATH_HOME));
+    this.homeDir = new File(settings.getString(ProcessProperties.PATH_HOME));
   }
 
   /**
index 991ceb18d1db8b445f39569c99b5ca9855d86214..dd961e8c560aa50e4008bfc9cc23eaa061fca916 100644 (file)
@@ -31,7 +31,7 @@ import org.sonar.api.config.Settings;
 import org.sonar.api.platform.Server;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 
 import java.io.File;
 import java.io.IOException;
@@ -78,7 +78,7 @@ public final class ServerImpl extends Server implements Startable {
         // Remove trailing slashes
         .replaceFirst("(\\/+)$", "");
 
-      sonarHome = new File(settings.getString(ProcessConstants.PATH_HOME));
+      sonarHome = new File(settings.getString(ProcessProperties.PATH_HOME));
       if (!sonarHome.isDirectory()) {
         throw new IllegalStateException("SonarQube home directory is not valid");
       }
index a043b8dc5b757b5a3c039040d75bc565bc68595f..930a32c36b63d6b71c810aad288c17b6525a7563 100644 (file)
@@ -24,7 +24,7 @@ import org.sonar.api.CoreProperties;
 import org.sonar.api.config.Settings;
 import org.sonar.api.platform.Server;
 import org.sonar.api.security.SecurityRealm;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.user.SecurityRealmFactory;
 
 import java.util.LinkedHashMap;
@@ -86,10 +86,10 @@ public class SonarQubeMonitor extends BaseMonitorMBean implements SonarQubeMonit
     attributes.put("Automatic User Creation", getAutomaticUserCreation());
     attributes.put("Allow Users to Sign Up", getAllowUsersToSignUp());
     attributes.put("Force authentication", getForceAuthentication());
-    attributes.put("Home Dir", settings.getString(ProcessConstants.PATH_HOME));
-    attributes.put("Data Dir", settings.getString(ProcessConstants.PATH_DATA));
-    attributes.put("Logs Dir", settings.getString(ProcessConstants.PATH_LOGS));
-    attributes.put("Temp Dir", settings.getString(ProcessConstants.PATH_TEMP));
+    attributes.put("Home Dir", settings.getString(ProcessProperties.PATH_HOME));
+    attributes.put("Data Dir", settings.getString(ProcessProperties.PATH_DATA));
+    attributes.put("Logs Dir", settings.getString(ProcessProperties.PATH_LOGS));
+    attributes.put("Temp Dir", settings.getString(ProcessProperties.PATH_TEMP));
     return attributes;
 
   }
index 4dfe45cc78f3b8f6ef07362ca3c3b94c4cf106cd..335991d4448956c2866705600c81e7a55159dd31 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.core.qualityprofile.db.ActiveRuleDto;
 import org.sonar.core.qualityprofile.db.ActiveRuleKey;
 import org.sonar.core.qualityprofile.db.ActiveRuleParamDto;
 import org.sonar.core.qualityprofile.db.QualityProfileDto;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.qualityprofile.ActiveRule;
 import org.sonar.server.search.BaseNormalizer;
@@ -165,11 +165,11 @@ public class ActiveRuleNormalizer extends BaseNormalizer<ActiveRuleDto, ActiveRu
       .replicationType(ReplicationType.ASYNC)
       .routing(key.ruleKey().toString())
       .id(key.toString())
-      .script(ProcessConstants.ES_PLUGIN_LISTUPDATE_SCRIPT_NAME)
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, ActiveRuleField.PARAMS.field())
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, newParam)
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, ActiveRuleParamField.NAME.field())
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, param.getKey())
+      .script(ProcessProperties.ES_PLUGIN_LISTUPDATE_SCRIPT_NAME)
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_FIELD, ActiveRuleField.PARAMS.field())
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_VALUE, newParam)
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_FIELD, ActiveRuleParamField.NAME.field())
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_VALUE, param.getKey())
       );
   }
 
@@ -178,11 +178,11 @@ public class ActiveRuleNormalizer extends BaseNormalizer<ActiveRuleDto, ActiveRu
       .replicationType(ReplicationType.ASYNC)
       .routing(key.ruleKey().toString())
       .id(key.toString())
-      .script(ProcessConstants.ES_PLUGIN_LISTUPDATE_SCRIPT_NAME)
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, ActiveRuleField.PARAMS.field())
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, null)
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, ActiveRuleParamField.NAME.field())
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, param.getKey())
+      .script(ProcessProperties.ES_PLUGIN_LISTUPDATE_SCRIPT_NAME)
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_FIELD, ActiveRuleField.PARAMS.field())
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_VALUE, null)
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_FIELD, ActiveRuleParamField.NAME.field())
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_VALUE, param.getKey())
       );
   }
 }
index 7ce70f0757ce453e16720716df500984efffb7c8..a9d5d828428d51a62adc9324c4c8b4dab8943156 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.core.rule.RuleDto;
 import org.sonar.core.rule.RuleParamDto;
 import org.sonar.core.technicaldebt.db.CharacteristicDto;
 import org.sonar.markdown.Markdown;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.search.BaseNormalizer;
 import org.sonar.server.search.IndexField;
@@ -322,22 +322,22 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
 
     return ImmutableList.of(new UpdateRequest()
       .id(key.toString())
-      .script(ProcessConstants.ES_PLUGIN_LISTUPDATE_SCRIPT_NAME)
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, RuleField.PARAMS.field())
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, newParam)
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, RuleParamField.NAME.field())
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, param.getName())
+      .script(ProcessProperties.ES_PLUGIN_LISTUPDATE_SCRIPT_NAME)
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_FIELD, RuleField.PARAMS.field())
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_VALUE, newParam)
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_FIELD, RuleParamField.NAME.field())
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_VALUE, param.getName())
       );
   }
 
   private List<UpdateRequest> nestedDelete(RuleParamDto param, RuleKey key) {
     return ImmutableList.of(new UpdateRequest()
       .id(key.toString())
-      .script(ProcessConstants.ES_PLUGIN_LISTUPDATE_SCRIPT_NAME)
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, RuleField.PARAMS.field())
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, null)
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, RuleParamField.NAME.field())
-      .addScriptParam(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, param.getName())
+      .script(ProcessProperties.ES_PLUGIN_LISTUPDATE_SCRIPT_NAME)
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_FIELD, RuleField.PARAMS.field())
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_VALUE, null)
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_FIELD, RuleParamField.NAME.field())
+      .addScriptParam(ProcessProperties.ES_PLUGIN_LISTUPDATE_ID_VALUE, param.getName())
       );
   }
 
index 8f03a3a8057e92d84d479e792db4d121b1233f85..2b5973c39413dacb319c3b03450ea6ebc45dc68e 100644 (file)
@@ -53,7 +53,7 @@ import org.elasticsearch.common.transport.InetSocketTransportAddress;
 import org.picocontainer.Startable;
 import org.sonar.api.config.Settings;
 import org.sonar.process.LoopbackAddress;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.request.*;
 
 /**
@@ -63,14 +63,14 @@ public class SearchClient extends TransportClient implements Startable {
 
   public SearchClient(Settings settings) {
     super(ImmutableSettings.settingsBuilder()
-      .put("node.name", StringUtils.defaultIfEmpty(settings.getString(ProcessConstants.CLUSTER_NODE_NAME), "sq_local_client"))
-      .put("network.bind_host", StringUtils.defaultIfEmpty(settings.getString(ProcessConstants.SEARCH_HOST), "localhost"))
-      .put("node.rack_id", StringUtils.defaultIfEmpty(settings.getString(ProcessConstants.CLUSTER_NODE_NAME), "unknown"))
-      .put("cluster.name", StringUtils.defaultIfBlank(settings.getString(ProcessConstants.CLUSTER_NAME), "sonarqube"))
+      .put("node.name", StringUtils.defaultIfEmpty(settings.getString(ProcessProperties.CLUSTER_NODE_NAME), "sq_local_client"))
+      .put("network.bind_host", StringUtils.defaultIfEmpty(settings.getString(ProcessProperties.SEARCH_HOST), "localhost"))
+      .put("node.rack_id", StringUtils.defaultIfEmpty(settings.getString(ProcessProperties.CLUSTER_NODE_NAME), "unknown"))
+      .put("cluster.name", StringUtils.defaultIfBlank(settings.getString(ProcessProperties.CLUSTER_NAME), "sonarqube"))
       .build());
     initLogging();
-    this.addTransportAddress(new InetSocketTransportAddress(StringUtils.defaultIfEmpty(settings.getString(ProcessConstants.SEARCH_HOST), LoopbackAddress.get().getHostAddress()),
-      settings.getInt(ProcessConstants.SEARCH_PORT)));
+    this.addTransportAddress(new InetSocketTransportAddress(StringUtils.defaultIfEmpty(settings.getString(ProcessProperties.SEARCH_HOST), LoopbackAddress.get().getHostAddress()),
+      settings.getInt(ProcessProperties.SEARCH_PORT)));
   }
 
   private void initLogging() {
index 5385b80f1361514ae141f4b56e659dd999976e26..d80f57f6496d417c9136ebc279a2237d18d8dc1a 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.source.index;
 import com.google.common.collect.ImmutableMap;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
 import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.NewIndex;
 
@@ -65,7 +65,7 @@ public class SourceLineIndexDefinition implements IndexDefinition {
     index.getSettings().put("index.refresh_interval", "-1");
 
     // shards
-    boolean clusterMode = settings.getBoolean(ProcessConstants.CLUSTER_ACTIVATE);
+    boolean clusterMode = settings.getBoolean(ProcessProperties.CLUSTER_ACTIVATE);
     if (clusterMode) {
       index.getSettings().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4);
       index.getSettings().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1);
index 289d94cab7ef8bdce3e53ba248d9b46e1aa758f4..8a38ae75e6aec8faed41ebe1245a66568cdd1962 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.startup;
 import org.apache.commons.io.FileUtils;
 import org.sonar.api.config.Settings;
 import org.sonar.home.cache.FileHashes;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.platform.DefaultServerFileSystem;
 
 import javax.annotation.Nullable;
@@ -42,7 +42,7 @@ public class JdbcDriverDeployer {
 
   public void start() {
     // see initialization of this property in sonar-application
-    String driverPath = settings.getString(ProcessConstants.JDBC_DRIVER_PATH);
+    String driverPath = settings.getString(ProcessProperties.JDBC_DRIVER_PATH);
     if (driverPath == null) {
       // Medium tests
       return;
index 0101265cad34f81d7f72132a14c2e33b75270322..555ea7fff67b2d2af48706ee2f62f4b0db374690 100644 (file)
@@ -37,7 +37,7 @@ import org.sonar.api.web.Widget;
 import org.sonar.core.persistence.Database;
 import org.sonar.core.resource.ResourceIndexerDao;
 import org.sonar.core.timemachine.Periods;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.component.ComponentCleanerService;
 import org.sonar.server.db.migrations.DatabaseMigrator;
 import org.sonar.server.measure.MeasureFilterEngine;
@@ -338,7 +338,7 @@ public final class JRubyFacade {
   }
 
   public String getServerHome() {
-    return get(Settings.class).getString(ProcessConstants.PATH_HOME);
+    return get(Settings.class).getString(ProcessProperties.PATH_HOME);
   }
 
   public ComponentContainer getContainer() {
index 6e610ff74b6ac8d9818b47c80f0a1293f38d6211..68a191aab1faec26cda0aeb0a66043fc40c08f98 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.user.index;
 import com.google.common.collect.ImmutableMap;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
 import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.NewIndex;
 
@@ -54,7 +54,7 @@ public class UserIndexDefinition implements IndexDefinition {
     NewIndex index = context.create(INDEX);
 
     // shards
-    boolean clusterMode = settings.getBoolean(ProcessConstants.CLUSTER_ACTIVATE);
+    boolean clusterMode = settings.getBoolean(ProcessProperties.CLUSTER_ACTIVATE);
     if (clusterMode) {
       index.getSettings().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4);
       index.getSettings().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1);
index ce84709be78bb56b518fee3d91693dfaef4dc4b3..3fe2be97a98b3747b32e64cb20816ffd21ece6cb 100644 (file)
@@ -23,7 +23,7 @@ package org.sonar.server.view.index;
 import com.google.common.collect.ImmutableMap;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
 import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.NewIndex;
 
@@ -50,7 +50,7 @@ public class ViewIndexDefinition implements IndexDefinition {
     NewIndex index = context.create(INDEX);
 
     // shards
-    boolean clusterMode = settings.getBoolean(ProcessConstants.CLUSTER_ACTIVATE);
+    boolean clusterMode = settings.getBoolean(ProcessProperties.CLUSTER_ACTIVATE);
     if (clusterMode) {
       index.getSettings().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4);
       index.getSettings().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1);
index 80ef2f2fba002714ce04ead3f5b35bd94f1e057a..3e5336d9194a49863349f7f22cfab9ea28123a71 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.server.activity.index;
 
 import org.junit.Test;
 import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.NewIndex;
 
@@ -49,7 +49,7 @@ public class ActivityIndexDefinitionTest {
   @Test
   public void enable_cluster() throws Exception {
     Settings settings = new Settings();
-    settings.setProperty(ProcessConstants.CLUSTER_ACTIVATE, true);
+    settings.setProperty(ProcessProperties.CLUSTER_ACTIVATE, true);
     ActivityIndexDefinition def = new ActivityIndexDefinition(settings);
     def.define(context);
 
index 0e64c81de60f8660c933368939a6ad47f23ee74a..ac5351bf9fd198ff568c5a66930998c1f76e3d13 100644 (file)
@@ -28,7 +28,7 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.mockito.Mockito;
 import org.sonar.api.utils.log.Logger;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 
 import java.io.File;
@@ -55,7 +55,7 @@ public class TomcatAccessLogTest {
   public void enable_access_logs_by_Default() throws Exception {
     Tomcat tomcat = mock(Tomcat.class, Mockito.RETURNS_DEEP_STUBS);
     Props props = new Props(new Properties());
-    props.set(ProcessConstants.PATH_LOGS, temp.newFolder().getAbsolutePath());
+    props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath());
     sut.configure(tomcat, props);
 
     verify(tomcat.getHost().getPipeline()).addValve(any(ProgrammaticLogbackValve.class));
index 54d29d63e688b62476f0c0ad6caf6bb2a286804a..b7ffeb653116b2952f117c41674ab28273b2c59c 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.computation.db.AnalysisReportDto;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.persistence.DbTester;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.db.ComponentDao;
 import org.sonar.server.computation.db.AnalysisReportDao;
@@ -68,7 +68,7 @@ public class ReportQueueTest {
   @Before
   public void setUp() throws Exception {
     dataDir = temp.newFolder();
-    settings.setProperty(ProcessConstants.PATH_DATA, dataDir.getAbsolutePath());
+    settings.setProperty(ProcessProperties.PATH_DATA, dataDir.getAbsolutePath());
     when(system.now()).thenReturn(NOW);
 
     DbClient dbClient = new DbClient(db.database(), db.myBatis(), new ComponentDao(), new AnalysisReportDao(system));
index 29edb659620628dcc02990aa27745c002e2627e8..954f480dadd2827449faa3b25a0dc49c670c19d3 100644 (file)
@@ -26,7 +26,7 @@ import org.junit.rules.ExpectedException;
 import org.sonar.api.config.Settings;
 import org.sonar.api.database.DatabaseProperties;
 import org.sonar.process.NetworkUtils;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 
 import java.io.File;
 import java.io.IOException;
@@ -73,6 +73,6 @@ public class EmbeddedDatabaseTest {
       .setProperty(DatabaseProperties.PROP_USER, "login")
       .setProperty(DatabaseProperties.PROP_PASSWORD, "pwd")
       .setProperty(DatabaseProperties.PROP_EMBEDDED_PORT, "" + port)
-      .setProperty(ProcessConstants.PATH_DATA, "./target/testDB");
+      .setProperty(ProcessProperties.PATH_DATA, "./target/testDB");
   }
 }
index 5146f5b733a5e1f4ff75e589b4f251222e4963c6..3604426eff2ecfd5855f653de07a4319dd528151 100644 (file)
@@ -25,7 +25,7 @@ import org.elasticsearch.common.settings.ImmutableSettings;
 import org.elasticsearch.common.transport.InetSocketTransportAddress;
 import org.sonar.process.LoopbackAddress;
 import org.sonar.process.NetworkUtils;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 import org.sonar.search.SearchServer;
 import org.sonar.test.TestUtils;
@@ -108,11 +108,11 @@ public class EsServerHolder {
       int port = NetworkUtils.freePort();
 
       Properties properties = new Properties();
-      properties.setProperty(ProcessConstants.CLUSTER_NAME, clusterName);
-      properties.setProperty(ProcessConstants.CLUSTER_NODE_NAME, nodeName);
-      properties.setProperty(ProcessConstants.SEARCH_PORT, String.valueOf(port));
-      properties.setProperty(ProcessConstants.SEARCH_HOST, hostName);
-      properties.setProperty(ProcessConstants.PATH_HOME, homeDir.getAbsolutePath());
+      properties.setProperty(ProcessProperties.CLUSTER_NAME, clusterName);
+      properties.setProperty(ProcessProperties.CLUSTER_NODE_NAME, nodeName);
+      properties.setProperty(ProcessProperties.SEARCH_PORT, String.valueOf(port));
+      properties.setProperty(ProcessProperties.SEARCH_HOST, hostName);
+      properties.setProperty(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
       SearchServer server = new SearchServer(new Props(properties));
       server.start();
       HOLDER = new EsServerHolder(server, clusterName, nodeName, port, hostName, homeDir);
index 0e5b70d0d0b18a3ed4168fd22535fb53defb2924..65b41afdedfa0ced0d885762c6b1487241476aad 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.server.issue.index;
 
 import org.junit.Test;
 import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.NewIndex;
 
@@ -49,7 +49,7 @@ public class IssueIndexDefinitionTest {
   @Test
   public void enable_cluster() throws Exception {
     Settings settings = new Settings();
-    settings.setProperty(ProcessConstants.CLUSTER_ACTIVATE, true);
+    settings.setProperty(ProcessProperties.CLUSTER_ACTIVATE, true);
     IssueIndexDefinition def = new IssueIndexDefinition(settings);
     def.define(context);
 
index 1766cb8245922abd15039508b4d9bf7acaa80d17..68a3f260c517d801c389ed820e1e975207c2f838 100644 (file)
@@ -27,7 +27,7 @@ import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 
 import java.io.File;
 
@@ -48,7 +48,7 @@ public class ServerImplTest {
 
   @Before
   public void setUp() throws Exception {
-    settings = new Settings().setProperty(ProcessConstants.PATH_HOME, sonarHome.getRoot().getAbsolutePath());
+    settings = new Settings().setProperty(ProcessProperties.PATH_HOME, sonarHome.getRoot().getAbsolutePath());
     new File(sonarHome.getRoot(), "web/deploy").mkdirs();
 
     server = new ServerImpl(settings, "/org/sonar/server/platform/ServerImplTest/build.properties", "/org/sonar/server/platform/ServerImplTest/version.txt");
index 53a001331eeb657bc2f1a9204977e51ef3a4cf79..6d772538a171159942ae7be12365dc26a122c779 100644 (file)
@@ -26,7 +26,7 @@ import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.EsServerHolder;
 
 import java.io.IOException;
@@ -47,11 +47,11 @@ public class BaseIndexTest {
   public void setup() throws IOException {
     EsServerHolder holder = EsServerHolder.get();
     Settings settings = new Settings();
-    settings.setProperty(ProcessConstants.CLUSTER_ACTIVATE, false);
-    settings.setProperty(ProcessConstants.CLUSTER_NAME, holder.getClusterName());
-    settings.setProperty(ProcessConstants.CLUSTER_NODE_NAME, holder.getNodeName());
-    settings.setProperty(ProcessConstants.SEARCH_PORT, String.valueOf(holder.getPort()));
-    settings.setProperty(ProcessConstants.SEARCH_HOST, String.valueOf(holder.getHostName()));
+    settings.setProperty(ProcessProperties.CLUSTER_ACTIVATE, false);
+    settings.setProperty(ProcessProperties.CLUSTER_NAME, holder.getClusterName());
+    settings.setProperty(ProcessProperties.CLUSTER_NODE_NAME, holder.getNodeName());
+    settings.setProperty(ProcessProperties.SEARCH_PORT, String.valueOf(holder.getPort()));
+    settings.setProperty(ProcessProperties.SEARCH_HOST, String.valueOf(holder.getHostName()));
     searchClient = new SearchClient(settings);
   }
 
index 4c5af2a2567c4836ac999ff6fc29499e6cd917c9..f33c15c528178a22036bedebcd9f95ec83de8bef 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.server.source.index;
 
 import org.junit.Test;
 import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.NewIndex;
 
@@ -49,7 +49,7 @@ public class SourceLineIndexDefinitionTest {
   @Test
   public void enable_cluster() throws Exception {
     Settings settings = new Settings();
-    settings.setProperty(ProcessConstants.CLUSTER_ACTIVATE, true);
+    settings.setProperty(ProcessProperties.CLUSTER_ACTIVATE, true);
     IndexDefinition def = new SourceLineIndexDefinition(settings);
     def.define(context);
 
index aa08b8db7299936dcf35593c68ac1b1c2074c404..b6c3d6fd85650685e4d7580944b1403db6ada797 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.api.database.DatabaseProperties;
 import org.sonar.api.resources.Language;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.EsServerHolder;
 import org.sonar.server.platform.BackendCleanup;
 import org.sonar.server.platform.Platform;
@@ -81,12 +81,12 @@ public class ServerTester extends ExternalResource {
       Properties properties = new Properties();
       properties.putAll(initialProps);
       esServerHolder = EsServerHolder.get();
-      properties.setProperty(ProcessConstants.CLUSTER_NAME, esServerHolder.getClusterName());
-      properties.setProperty(ProcessConstants.CLUSTER_NODE_NAME, esServerHolder.getNodeName());
-      properties.setProperty(ProcessConstants.SEARCH_PORT, String.valueOf(esServerHolder.getPort()));
-      properties.setProperty(ProcessConstants.SEARCH_HOST, String.valueOf(esServerHolder.getHostName()));
-      properties.setProperty(ProcessConstants.PATH_HOME, homeDir.getAbsolutePath());
-      properties.setProperty(ProcessConstants.PATH_DATA, new File(homeDir, "data").getAbsolutePath());
+      properties.setProperty(ProcessProperties.CLUSTER_NAME, esServerHolder.getClusterName());
+      properties.setProperty(ProcessProperties.CLUSTER_NODE_NAME, esServerHolder.getNodeName());
+      properties.setProperty(ProcessProperties.SEARCH_PORT, String.valueOf(esServerHolder.getPort()));
+      properties.setProperty(ProcessProperties.SEARCH_HOST, String.valueOf(esServerHolder.getHostName()));
+      properties.setProperty(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
+      properties.setProperty(ProcessProperties.PATH_DATA, new File(homeDir, "data").getAbsolutePath());
       properties.setProperty(DatabaseProperties.PROP_URL, "jdbc:h2:" + homeDir.getAbsolutePath() + "/h2");
       for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
         String key = entry.getKey().toString();
index 932c92f98b5233d12ede77f51b8b41253eda7220..8de69b73d93c3e0e5a0199bd62c433f8cc8d523c 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.server.user.index;
 
 import org.junit.Test;
 import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.NewIndex;
 
@@ -49,7 +49,7 @@ public class UserIndexDefinitionTest {
   @Test
   public void enable_cluster() throws Exception {
     Settings settings = new Settings();
-    settings.setProperty(ProcessConstants.CLUSTER_ACTIVATE, true);
+    settings.setProperty(ProcessProperties.CLUSTER_ACTIVATE, true);
     UserIndexDefinition def = new UserIndexDefinition(settings);
     def.define(context);
 
index df48201c599bee7bec35bdb644c0814ca1b7c49f..9da76180dc8091487c20eae4aa5373b3da22ef3d 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.view.index;
 
 import org.junit.Test;
 import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.NewIndex;
 
@@ -50,7 +50,7 @@ public class ViewIndexDefinitionTest {
   @Test
   public void enable_cluster() throws Exception {
     Settings settings = new Settings();
-    settings.setProperty(ProcessConstants.CLUSTER_ACTIVATE, true);
+    settings.setProperty(ProcessProperties.CLUSTER_ACTIVATE, true);
     ViewIndexDefinition def = new ViewIndexDefinition(settings);
     def.define(context);
 
index 9235874fa2e37ea1aaef90280c5e1bca9159647d..d5209054161de457367c3f14fc37ed62d0910530 100644 (file)
 # Elasticsearch port. Default is 9001. Use 0 to get a free port.
 # This port must be private and must not be exposed to the Internet.
 #sonar.search.port=9001
-# Elasticsearch host. The search server will bind this address and the search client will connect to it. Default ist 127.0.0.1.
+# Elasticsearch host. The search server will bind this address and the search client will connect to it.
+# Default is 127.0.0.1.
 #sonar.search.host=127.0.0.1
 
 
 # plugins not supported).
 #sonar.web.dev.sources=/path/to/server/sonar-web/src/main/webapp
 
-# Uncomment to enable the Elasticsearch HTTP connector, so that ES can be directly requested through
+# Elasticsearch HTTP connector, for example for KOPF:
 # http://lmenezes.com/elasticsearch-kopf/?location=http://localhost:9010
-#sonar.search.httpPort=9010
+#sonar.search.httpPort=-1
index 68cb982a8456813ace61b9080e54e73567f73f46..26130401dac1686521dadeac76da5c0cf3c56bc4 100644 (file)
@@ -23,7 +23,7 @@ import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.process.MinimumViableSystem;
 import org.sonar.process.ProcessCommands;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 import org.sonar.process.StopWatcher;
 import org.sonar.process.Stoppable;
@@ -52,8 +52,8 @@ public class App implements Stoppable {
   }
 
   public void start(Props props) {
-    if (props.valueAsBoolean(ProcessConstants.ENABLE_STOP_COMMAND, false)) {
-      File tempDir = props.nonNullValueAsFile(ProcessConstants.PATH_TEMP);
+    if (props.valueAsBoolean(ProcessProperties.ENABLE_STOP_COMMAND, false)) {
+      File tempDir = props.nonNullValueAsFile(ProcessProperties.PATH_TEMP);
       ProcessCommands commands = new ProcessCommands(tempDir, 0);
       stopWatcher = new StopWatcher(commands, this);
       stopWatcher.start();
@@ -64,14 +64,14 @@ public class App implements Stoppable {
 
   List<JavaCommand> createCommands(Props props) {
     List<JavaCommand> commands = new ArrayList<>();
-    File homeDir = props.nonNullValueAsFile(ProcessConstants.PATH_HOME);
-    File tempDir = props.nonNullValueAsFile(ProcessConstants.PATH_TEMP);
+    File homeDir = props.nonNullValueAsFile(ProcessProperties.PATH_HOME);
+    File tempDir = props.nonNullValueAsFile(ProcessProperties.PATH_TEMP);
     JavaCommand elasticsearch = new JavaCommand("search");
     elasticsearch
       .setWorkDir(homeDir)
       .addJavaOptions("-Djava.awt.headless=true")
-      .addJavaOptions(props.nonNullValue(ProcessConstants.SEARCH_JAVA_OPTS))
-      .addJavaOptions(props.nonNullValue(ProcessConstants.SEARCH_JAVA_ADDITIONAL_OPTS))
+      .addJavaOptions(props.nonNullValue(ProcessProperties.SEARCH_JAVA_OPTS))
+      .addJavaOptions(props.nonNullValue(ProcessProperties.SEARCH_JAVA_ADDITIONAL_OPTS))
       .setTempDir(tempDir.getAbsoluteFile())
       .setClassName("org.sonar.search.SearchServer")
       .setArguments(props.rawProperties())
@@ -80,20 +80,20 @@ public class App implements Stoppable {
     commands.add(elasticsearch);
 
     // do not yet start SQ on elasticsearch slaves
-    if (StringUtils.isBlank(props.value(ProcessConstants.CLUSTER_MASTER_HOST))) {
+    if (StringUtils.isBlank(props.value(ProcessProperties.CLUSTER_MASTER_HOST))) {
       JavaCommand webServer = new JavaCommand("web")
         .setWorkDir(homeDir)
-        .addJavaOptions(DefaultSettings.WEB_SERVER_FORCED_JVM_ARGS)
-        .addJavaOptions(props.nonNullValue(ProcessConstants.WEB_JAVA_OPTS))
-        .addJavaOptions(props.nonNullValue(ProcessConstants.WEB_JAVA_ADDITIONAL_OPTS))
+        .addJavaOptions(ProcessProperties.WEB_ENFORCED_JVM_ARGS)
+        .addJavaOptions(props.nonNullValue(ProcessProperties.WEB_JAVA_OPTS))
+        .addJavaOptions(props.nonNullValue(ProcessProperties.WEB_JAVA_ADDITIONAL_OPTS))
         .setTempDir(tempDir.getAbsoluteFile())
           // required for logback tomcat valve
-        .setEnvVariable(ProcessConstants.PATH_LOGS, props.nonNullValue(ProcessConstants.PATH_LOGS))
+        .setEnvVariable(ProcessProperties.PATH_LOGS, props.nonNullValue(ProcessProperties.PATH_LOGS))
         .setClassName("org.sonar.server.app.WebServer")
         .setArguments(props.rawProperties())
         .addClasspath("./lib/common/*")
         .addClasspath("./lib/server/*");
-      String driverPath = props.value(ProcessConstants.JDBC_DRIVER_PATH);
+      String driverPath = props.value(ProcessProperties.JDBC_DRIVER_PATH);
       if (driverPath != null) {
         webServer.addClasspath(driverPath);
       }
diff --git a/sonar-application/src/main/java/org/sonar/application/DefaultSettings.java b/sonar-application/src/main/java/org/sonar/application/DefaultSettings.java
deleted file mode 100644 (file)
index f06d5fe..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.application;
-
-import org.sonar.process.NetworkUtils;
-import org.sonar.process.ProcessConstants;
-import org.sonar.process.Props;
-
-import java.util.HashMap;
-import java.util.Map;
-
-class DefaultSettings {
-
-  public static final String WEB_SERVER_FORCED_JVM_ARGS = "-Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djruby.management.enabled=false " +
-    // jruby is slow with java 8: https://jira.codehaus.org/browse/SONAR-6115
-    "-Djruby.compile.invokedynamic=false";
-
-  private DefaultSettings() {
-    // only static stuff
-  }
-
-  static void init(Props props) {
-    // forced property
-    props.set(ProcessConstants.SEARCH_TYPE, "TRANSPORT");
-
-    // init string properties
-    for (Map.Entry<String, String> entry : defaults().entrySet()) {
-      props.setDefault(entry.getKey(), entry.getValue());
-    }
-
-    // init ports
-    for (Map.Entry<String, Integer> entry : defaultPorts().entrySet()) {
-      String key = entry.getKey();
-      int port = props.valueAsInt(key, -1);
-      if (port == -1) {
-        // default port
-        props.set(key, String.valueOf((int) entry.getValue()));
-      } else if (port == 0) {
-        // pick one available port
-        props.set(key, String.valueOf(NetworkUtils.freePort()));
-      }
-    }
-  }
-
-  private static Map<String, String> defaults() {
-    Map<String, String> defaults = new HashMap<>();
-    defaults.put(ProcessConstants.CLUSTER_NAME, "sonarqube");
-    defaults.put(ProcessConstants.SEARCH_JAVA_OPTS, "-Xmx1G -Xms256m -Xss256k -Djava.net.preferIPv4Stack=true " +
-      "-XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly " +
-      "-XX:+HeapDumpOnOutOfMemoryError");
-    defaults.put(ProcessConstants.SEARCH_JAVA_ADDITIONAL_OPTS, "");
-    defaults.put(ProcessConstants.CLUSTER_NODE_NAME, "sonar-" + System.currentTimeMillis());
-    defaults.put(ProcessConstants.WEB_JAVA_OPTS, "-Xmx768m -XX:MaxPermSize=160m -XX:+HeapDumpOnOutOfMemoryError -Djava.net.preferIPv4Stack=true");
-    defaults.put(ProcessConstants.WEB_JAVA_ADDITIONAL_OPTS, "");
-    defaults.put(ProcessConstants.JDBC_URL, "jdbc:h2:tcp://localhost:9092/sonar");
-    defaults.put(ProcessConstants.JDBC_LOGIN, "sonar");
-    defaults.put(ProcessConstants.JDBC_PASSWORD, "sonar");
-    defaults.put(ProcessConstants.JDBC_MAX_ACTIVE, "50");
-    defaults.put(ProcessConstants.JDBC_MAX_IDLE, "5");
-    defaults.put(ProcessConstants.JDBC_MIN_IDLE, "2");
-    defaults.put(ProcessConstants.JDBC_MAX_WAIT, "5000");
-    defaults.put(ProcessConstants.JDBC_MIN_EVICTABLE_IDLE_TIME_MILLIS, "600000");
-    defaults.put(ProcessConstants.JDBC_TIME_BETWEEN_EVICTION_RUNS_MILLIS, "30000");
-    return defaults;
-  }
-
-  private static Map<String, Integer> defaultPorts() {
-    Map<String, Integer> defaults = new HashMap<>();
-    defaults.put(ProcessConstants.SEARCH_PORT, 9001);
-    return defaults;
-  }
-}
index c949b1fae45ea15552d5359d014079c1d5dbb525..ea867c74b6a946831176add0308061c418052837 100644 (file)
@@ -23,7 +23,7 @@ import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.LoggerFactory;
 import org.sonar.process.MessageException;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 
 import java.io.File;
@@ -46,11 +46,11 @@ public class JdbcSettings {
   }
 
   public void checkAndComplete(File homeDir, Props props) {
-    String url = props.nonNullValue(ProcessConstants.JDBC_URL);
+    String url = props.nonNullValue(ProcessProperties.JDBC_URL);
     Provider provider = driverProvider(url);
     checkUrlParameters(provider, url);
     String driverPath = driverPath(homeDir, provider);
-    props.set(ProcessConstants.JDBC_DRIVER_PATH, driverPath);
+    props.set(ProcessProperties.JDBC_DRIVER_PATH, driverPath);
   }
 
   String driverPath(File homeDir, Provider provider) {
index 652dd4cf81491e4e8f845366f5a0745cf26777ce..167b8a3e0c735fb77e4c8bb28ea8abcdce6090a0 100644 (file)
@@ -21,8 +21,9 @@ package org.sonar.application;
 
 import org.apache.commons.io.Charsets;
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
 import org.sonar.process.ConfigurationUtils;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 
 import java.io.File;
@@ -56,19 +57,19 @@ class PropsBuilder {
   Props build() throws IOException {
     Properties p = loadPropertiesFile(homeDir);
     p.putAll(rawProperties);
-    p.setProperty(ProcessConstants.PATH_HOME, homeDir.getAbsolutePath());
+    p.setProperty(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
     p = ConfigurationUtils.interpolateVariables(p, System.getenv());
 
     // the difference between Properties and Props is that the latter
     // supports decryption of values, so it must be used when values
     // are accessed
     Props props = new Props(p);
-    DefaultSettings.init(props);
+    ProcessProperties.completeDefaults(props);
 
     // init file system
-    initExistingDir(props, ProcessConstants.PATH_DATA, "data");
-    initExistingDir(props, ProcessConstants.PATH_WEB, "web");
-    initExistingDir(props, ProcessConstants.PATH_LOGS, "logs");
+    initExistingDir(props, ProcessProperties.PATH_DATA, "data");
+    initExistingDir(props, ProcessProperties.PATH_WEB, "web");
+    initExistingDir(props, ProcessProperties.PATH_LOGS, "logs");
     initTempDir(props);
 
     // check JDBC properties and set path to driver
@@ -86,15 +87,18 @@ class PropsBuilder {
     Properties p = new Properties();
     File propsFile = new File(homeDir, "conf/sonar.properties");
     if (propsFile.exists()) {
-      try (Reader reader = new InputStreamReader(new FileInputStream(propsFile), Charsets.UTF_8)) {
+      Reader reader = new InputStreamReader(new FileInputStream(propsFile), Charsets.UTF_8);
+      try {
         p.load(reader);
+      } finally {
+        IOUtils.closeQuietly(reader);
       }
     }
     return p;
   }
 
   private void initTempDir(Props props) throws IOException {
-    File dir = configureDir(props, ProcessConstants.PATH_TEMP, "temp");
+    File dir = configureDir(props, ProcessProperties.PATH_TEMP, "temp");
     FileUtils.deleteQuietly(dir);
     FileUtils.forceMkdir(dir);
   }
index e2c902aaf399d54fff6bacee0cb9bc2d16442d66..fc187f3e4a4db5e50d352a91c35ef5b7243657e5 100644 (file)
@@ -31,7 +31,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.process.LogbackHelper;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 
 import java.io.File;
@@ -50,7 +50,7 @@ public class AppLoggingTest {
   @Before
   public void setUp() throws Exception {
     File dir = temp.newFolder();
-    props.set(ProcessConstants.PATH_LOGS, dir.getAbsolutePath());
+    props.set(ProcessProperties.PATH_LOGS, dir.getAbsolutePath());
   }
 
   @AfterClass
index d5bbf56d6bc0acb0dcfe2c92976639c53f725b77..027e00eea97f6074a8d07b668d2b242c91603b50 100644 (file)
@@ -24,7 +24,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.mockito.ArgumentCaptor;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 import org.sonar.process.monitor.JavaCommand;
 import org.sonar.process.monitor.Monitor;
@@ -122,10 +122,10 @@ public class AppTest {
 
   private Props initDefaultProps() throws IOException {
     Props props = new Props(new Properties());
-    DefaultSettings.init(props);
-    props.set(ProcessConstants.PATH_HOME, temp.newFolder().getAbsolutePath());
-    props.set(ProcessConstants.PATH_TEMP, temp.newFolder().getAbsolutePath());
-    props.set(ProcessConstants.PATH_LOGS, temp.newFolder().getAbsolutePath());
+    ProcessProperties.completeDefaults(props);
+    props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath());
+    props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath());
+    props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath());
     return props;
   }
 }
diff --git a/sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java b/sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java
deleted file mode 100644 (file)
index 6582545..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.application;
-
-import org.junit.Test;
-import org.sonar.process.Props;
-import org.sonar.test.TestUtils;
-
-import java.util.Properties;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DefaultSettingsTest {
-
-  @Test
-  public void init_defaults() throws Exception {
-    Props props = new Props(new Properties());
-    DefaultSettings.init(props);
-
-    assertThat(props.value("sonar.search.javaOpts")).contains("-Xmx");
-    assertThat(props.value("sonar.jdbc.username")).isEqualTo("sonar");
-    assertThat(props.valueAsInt("sonar.jdbc.maxActive")).isEqualTo(50);
-  }
-
-  @Test
-  public void do_not_override_existing_properties() throws Exception {
-    Properties p = new Properties();
-    p.setProperty("sonar.jdbc.username", "angela");
-    Props props = new Props(p);
-    DefaultSettings.init(props);
-
-    assertThat(props.value("sonar.jdbc.username")).isEqualTo("angela");
-  }
-
-  @Test
-  public void use_random_port_if_zero() throws Exception {
-    Properties p = new Properties();
-    p.setProperty("sonar.search.port", "0");
-    Props props = new Props(p);
-
-    DefaultSettings.init(props);
-    assertThat(props.valueAsInt("sonar.search.port")).isGreaterThan(0);
-  }
-
-  @Test
-  public void private_constructor() throws Exception {
-    assertThat(TestUtils.hasOnlyPrivateConstructors(DefaultSettings.class)).isTrue();
-  }
-}
index c68e3e1d465deeb69668f912644d4cbd1d4d2015..d6d575bfad1cf2ecf7354ae79a4e23a562041175 100644 (file)
@@ -24,7 +24,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.process.MessageException;
-import org.sonar.process.ProcessConstants;
+import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 
 import java.io.File;
@@ -88,7 +88,7 @@ public class JdbcSettingsTest {
     Props props = new Props(new Properties());
     props.set("sonar.jdbc.url", "jdbc:oracle:thin:@localhost/XE");
     settings.checkAndComplete(home, props);
-    assertThat(props.nonNullValueAsFile(ProcessConstants.JDBC_DRIVER_PATH)).isEqualTo(driverFile);
+    assertThat(props.nonNullValueAsFile(ProcessProperties.JDBC_DRIVER_PATH)).isEqualTo(driverFile);
   }
 
   @Test
@@ -100,7 +100,7 @@ public class JdbcSettingsTest {
     Props props = new Props(new Properties());
     props.set("sonar.jdbc.url", "jdbc:h2:tcp://localhost:9092/sonar");
     settings.checkAndComplete(home, props);
-    assertThat(props.nonNullValueAsFile(ProcessConstants.JDBC_DRIVER_PATH)).isEqualTo(driverFile);
+    assertThat(props.nonNullValueAsFile(ProcessProperties.JDBC_DRIVER_PATH)).isEqualTo(driverFile);
   }
 
   @Test
@@ -112,7 +112,7 @@ public class JdbcSettingsTest {
     Props props = new Props(new Properties());
     props.set("sonar.jdbc.url", "jdbc:postgresql://localhost/sonar");
     settings.checkAndComplete(home, props);
-    assertThat(props.nonNullValueAsFile(ProcessConstants.JDBC_DRIVER_PATH)).isEqualTo(driverFile);
+    assertThat(props.nonNullValueAsFile(ProcessProperties.JDBC_DRIVER_PATH)).isEqualTo(driverFile);
   }
 
   @Test
@@ -124,7 +124,7 @@ public class JdbcSettingsTest {
     Props props = new Props(new Properties());
     props.set("sonar.jdbc.url", "jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor");
     settings.checkAndComplete(home, props);
-    assertThat(props.nonNullValueAsFile(ProcessConstants.JDBC_DRIVER_PATH)).isEqualTo(driverFile);
+    assertThat(props.nonNullValueAsFile(ProcessProperties.JDBC_DRIVER_PATH)).isEqualTo(driverFile);
   }
 
   @Test