You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DefaultSettings.java 3.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * SonarQube, open source software quality management tool.
  3. * Copyright (C) 2008-2014 SonarSource
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * SonarQube is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * SonarQube is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.application;
  21. import org.sonar.process.NetworkUtils;
  22. import org.sonar.process.Props;
  23. import java.util.HashMap;
  24. import java.util.Map;
  25. class DefaultSettings {
  26. private DefaultSettings() {
  27. // only static stuff
  28. }
  29. static final String CLUSTER_MASTER = "sonar.cluster.master";
  30. static final String CLUSTER_NAME = "sonar.cluster.name";
  31. static final String CLUSTER_NODE_NAME = "sonar.node.name";
  32. static final String SEARCH_PORT = "sonar.search.port";
  33. static final String SEARCH_JAVA_OPTS = "sonar.search.javaOpts";
  34. static final String SEARCH_JAVA_ADDITIONAL_OPTS = "sonar.search.javaAdditionalOpts";
  35. static final String WEB_JAVA_OPTS = "sonar.web.javaOpts";
  36. static final String WEB_JAVA_ADDITIONAL_OPTS = "sonar.web.javaAdditionalOpts";
  37. static final String JDBC_URL = "sonar.jdbc.url";
  38. static final String JDBC_LOGIN = "sonar.jdbc.username";
  39. static final String JDBC_PASSWORD = "sonar.jdbc.password";
  40. static void init(Props props) {
  41. // forced property
  42. props.set("sonar.search.type", "TRANSPORT");
  43. // init string properties
  44. for (Map.Entry<String, String> entry : defaults().entrySet()) {
  45. props.setDefault(entry.getKey(), entry.getValue());
  46. }
  47. // init ports
  48. for (Map.Entry<String, Integer> entry : defaultPorts().entrySet()) {
  49. String key = entry.getKey();
  50. int port = props.valueAsInt(key, -1);
  51. if (port == -1) {
  52. // default port
  53. props.set(key, String.valueOf((int) entry.getValue()));
  54. } else if (port == 0) {
  55. // pick one available port
  56. props.set(key, String.valueOf(NetworkUtils.freePort()));
  57. }
  58. }
  59. }
  60. private static Map<String, String> defaults() {
  61. Map<String, String> defaults = new HashMap<String, String>();
  62. defaults.put(CLUSTER_NAME, "sonarqube");
  63. defaults.put(SEARCH_JAVA_OPTS, "-Xmx256m -Xms256m -Xss256k -Djava.net.preferIPv4Stack=true " +
  64. "-XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly " +
  65. "-XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true");
  66. defaults.put(SEARCH_JAVA_ADDITIONAL_OPTS, "");
  67. defaults.put(CLUSTER_NODE_NAME, "sonar-" + System.currentTimeMillis());
  68. defaults.put(WEB_JAVA_OPTS, "-Xmx768m -XX:MaxPermSize=160m -XX:+HeapDumpOnOutOfMemoryError -Djava.net.preferIPv4Stack=true " +
  69. "-Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djruby.management.enabled=false");
  70. defaults.put(WEB_JAVA_ADDITIONAL_OPTS, "");
  71. defaults.put(JDBC_URL, "jdbc:h2:tcp://localhost:9092/sonar");
  72. defaults.put(JDBC_LOGIN, "sonar");
  73. defaults.put(JDBC_PASSWORD, "sonar");
  74. return defaults;
  75. }
  76. private static Map<String, Integer> defaultPorts() {
  77. Map<String, Integer> defaults = new HashMap<String, Integer>();
  78. defaults.put(SEARCH_PORT, 9001);
  79. return defaults;
  80. }
  81. }