aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-application/src/main/java/org/sonar/application/DefaultSettings.java
blob: 6780ae1ab9431550c0dee5e44b751dc714534884 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * 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.Props;

import java.util.HashMap;
import java.util.Map;

class DefaultSettings {

  private DefaultSettings() {
    // only static stuff
  }

  static final String CLUSTER_MASTER = "sonar.cluster.master";
  static final String CLUSTER_NAME = "sonar.cluster.name";
  static final String PATH_LOGS = "sonar.path.logs";
  static final String SEARCH_PORT = "sonar.search.port";
  static final String SEARCH_JMX_PORT = "sonar.search.jmxPort";
  static final String SEARCH_JAVA_OPTS = "sonar.search.javaOpts";
  static final String WEB_JMX_PORT = "sonar.web.jmxPort";
  static final String WEB_JAVA_OPTS = "sonar.web.javaOpts";
  static final String JDBC_URL = "sonar.jdbc.url";
  static final String JDBC_LOGIN = "sonar.jdbc.username";
  static final String JDBC_PASSWORD = "sonar.jdbc.password";
  static final String SONAR_NODE_NAME = "sonar.node.name";

  static String getNonSetNodeName() {
    return "sonar-" + System.currentTimeMillis();
  }

  static void init(Props props) {
    // forced property
    props.set("sonar.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.intOf(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<String, String>();
    defaults.put(CLUSTER_NAME, "sonarqube");
    defaults.put(SEARCH_JAVA_OPTS, "-Xmx256m -Xms256m -Xss256k -Djava.net.preferIPv4Stack=true " +
      "-XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly " +
      "-XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true");
    defaults.put(WEB_JAVA_OPTS, "-Xmx768m -XX:MaxPermSize=160m -XX:+HeapDumpOnOutOfMemoryError " +
      "-Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djruby.management.enabled=false");
    defaults.put(JDBC_URL, "jdbc:h2:tcp://localhost:9092/sonar");
    defaults.put(JDBC_LOGIN, "sonar");
    defaults.put(JDBC_PASSWORD, "sonar");
    return defaults;
  }

  private static Map<String, Integer> defaultPorts() {
    Map<String, Integer> defaults = new HashMap<String, Integer>();
    defaults.put(SEARCH_PORT, 9001);
    defaults.put(SEARCH_JMX_PORT, 9002);
    defaults.put(WEB_JMX_PORT, 9003);
    return defaults;
  }
}