summaryrefslogtreecommitdiffstats
path: root/sonar-application/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-07-22 23:30:39 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-07-23 15:34:06 +0200
commit5976c31b87f3e021a6dbf3f8cf71f886a16b0f28 (patch)
treef4faf97dca64a81cda935d3e2da20ebf37c29723 /sonar-application/src
parent7ca148110a79d656b3a4340f726032322f11c382 (diff)
downloadsonarqube-5976c31b87f3e021a6dbf3f8cf71f886a16b0f28.tar.gz
sonarqube-5976c31b87f3e021a6dbf3f8cf71f886a16b0f28.zip
SONAR-4898 remove duplicated classes and usage of SONAR_HOME
Diffstat (limited to 'sonar-application/src')
-rw-r--r--sonar-application/src/main/java/org/sonar/application/ConfigurationUtils.java49
-rw-r--r--sonar-application/src/main/java/org/sonar/application/Installation.java41
-rw-r--r--sonar-application/src/main/java/org/sonar/application/StartServer.java8
-rw-r--r--sonar-application/src/test/java/org/sonar/application/ConfigurationUtilsTest.java55
-rw-r--r--sonar-application/src/test/resources/org/sonar/application/AesCipherTest/aes_secret_key.txt1
-rw-r--r--sonar-application/src/test/resources/org/sonar/application/AesCipherTest/bad_secret_key.txt1
-rw-r--r--sonar-application/src/test/resources/org/sonar/application/AesCipherTest/non_trimmed_secret_key.txt3
-rw-r--r--sonar-application/src/test/resources/org/sonar/application/AesCipherTest/other_secret_key.txt1
-rw-r--r--sonar-application/src/test/resources/org/sonar/application/LoggingTest/logback-access.xml1
-rw-r--r--sonar-application/src/test/resources/org/sonar/application/PropsTest/sonar.properties3
10 files changed, 10 insertions, 153 deletions
diff --git a/sonar-application/src/main/java/org/sonar/application/ConfigurationUtils.java b/sonar-application/src/main/java/org/sonar/application/ConfigurationUtils.java
deleted file mode 100644
index a5a563a168c..00000000000
--- a/sonar-application/src/main/java/org/sonar/application/ConfigurationUtils.java
+++ /dev/null
@@ -1,49 +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.apache.commons.lang.text.StrSubstitutor;
-
-import java.util.Enumeration;
-import java.util.Map;
-import java.util.Properties;
-
-public final class ConfigurationUtils {
-
- private ConfigurationUtils() {
- // Utility class
- }
-
- static Properties interpolateEnvVariables(Properties properties) {
- return interpolateVariables(properties, System.getenv());
- }
-
- static Properties interpolateVariables(Properties properties, Map<String, String> variables) {
- Properties result = new Properties();
- Enumeration keys = properties.keys();
- while (keys.hasMoreElements()) {
- String key = (String) keys.nextElement();
- String value = (String) properties.get(key);
- String interpolatedValue = StrSubstitutor.replace(value, variables, "${env:", "}");
- result.setProperty(key, interpolatedValue);
- }
- return result;
- }
-}
diff --git a/sonar-application/src/main/java/org/sonar/application/Installation.java b/sonar-application/src/main/java/org/sonar/application/Installation.java
index 924c4f4eb38..c6b0f2693fb 100644
--- a/sonar-application/src/main/java/org/sonar/application/Installation.java
+++ b/sonar-application/src/main/java/org/sonar/application/Installation.java
@@ -24,6 +24,7 @@ import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.process.ConfigurationUtils;
import org.sonar.process.NetworkUtils;
import javax.annotation.CheckForNull;
@@ -39,20 +40,18 @@ import java.util.Properties;
public class Installation {
private static final Logger LOG = LoggerFactory.getLogger(Installation.class);
- // guessed from location of sonar-application.jar
private final File homeDir;
private final File tempDir, dataDir, logsDir, webDir;
private final Map<String, String> props;
Installation() throws URISyntaxException, IOException {
- // lib/sonar-application.jar
+ // home dir guessed with location of lib/sonar-application.jar
File appJar = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI());
homeDir = appJar.getParentFile().getParentFile();
props = initProps(homeDir);
// init file system
- props.put("sonar.path.home", homeDir.getAbsolutePath());
this.dataDir = existingDir("sonar.path.data", "data");
this.tempDir = freshDir("sonar.path.temp", "temp");
this.logsDir = existingDir("sonar.path.logs", "logs");
@@ -87,12 +86,13 @@ public class Installation {
result.put(entry.getKey().toString(), val.toString());
}
}
+ result.put("sonar.path.home", homeDir.getAbsolutePath());
return result;
}
private void initElasticsearch() {
- // init Elasticsearch
- if (props.get("sonar.es.port") == null) {
+ String port = props.get("sonar.es.port");
+ if (port == null || "".equals(port) || "0".equals(port)) {
props.put("sonar.es.port", String.valueOf(NetworkUtils.freePort()));
}
if (props.get("sonar.es.cluster.name") == null) {
@@ -105,12 +105,8 @@ public class Installation {
return homeDir;
}
- File esDir() {
- return new File(homeDir, "data/es");
- }
-
- File webDir() {
- return webDir;
+ File logsDir() {
+ return logsDir;
}
File tempDir() {
@@ -132,11 +128,9 @@ public class Installation {
private File existingDir(String propKey, String defaultRelativePath) throws IOException {
File dir = configuredDir(propKey, defaultRelativePath);
if (!dir.exists()) {
- // TODO replace by MessageException
throw new IllegalStateException(String.format("Directory does not exist: %s. Please check property %s", dir.getAbsolutePath(), propKey));
}
if (!dir.isDirectory()) {
- // TODO replace by MessageException
throw new IllegalStateException(String.format("Not a directory: %s. Please check property %s", dir.getAbsolutePath(), propKey));
}
return dir;
@@ -156,33 +150,12 @@ public class Installation {
return props;
}
- String prop(String key) {
- return props.get(key);
- }
-
@CheckForNull
String prop(String key, @Nullable String defaultValue) {
String s = props.get(key);
return s != null ? s : defaultValue;
}
- @CheckForNull
- Integer propAsInt(String key) {
- String s = prop(key, null);
- if (s != null && !"".equals(s)) {
- try {
- return Integer.parseInt(s);
- } catch (NumberFormatException e) {
- throw new IllegalStateException(String.format("Value of property %s is not an integer: %s", key, s), e);
- }
- }
- return null;
- }
-
- void setProp(String key, String value) {
- props.put(key, value);
- }
-
void logInfo(String message) {
System.out.println(message);
}
diff --git a/sonar-application/src/main/java/org/sonar/application/StartServer.java b/sonar-application/src/main/java/org/sonar/application/StartServer.java
index bb856695260..851c69070a1 100644
--- a/sonar-application/src/main/java/org/sonar/application/StartServer.java
+++ b/sonar-application/src/main/java/org/sonar/application/StartServer.java
@@ -27,20 +27,18 @@ import javax.annotation.Nullable;
public class StartServer {
private Monitor monitor;
- private final Thread shutdownHook;
private ProcessWrapper elasticsearch;
private ProcessWrapper server;
public StartServer() throws Exception {
Installation installation = new Installation();
- shutdownHook = new Thread(new Runnable() {
+ Thread shutdownHook = new Thread(new Runnable() {
@Override
public void run() {
stop();
}
});
-
Runtime.getRuntime().addShutdownHook(shutdownHook);
monitor = new Monitor();
@@ -51,7 +49,7 @@ public class StartServer {
.setJmxPort(NetworkUtils.freePort())
.addJavaOpts(opts)
.addJavaOpts("-Djava.io.tmpdir=" + installation.tempDir().getAbsolutePath())
- .setEnvProperty("SONAR_HOME", installation.homeDir().getAbsolutePath())
+ .addJavaOpts("-Dsonar.path.logs=" + installation.logsDir().getAbsolutePath())
.setClassName("org.sonar.search.ElasticSearch")
.setProperties(installation.props())
.addClasspath(installation.starPath("lib/common"))
@@ -67,8 +65,8 @@ public class StartServer {
.addJavaOpts(opts)
.addJavaOpts("-Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djruby.management.enabled=false")
.addJavaOpts("-Djava.io.tmpdir=" + installation.tempDir().getAbsolutePath())
+ .addJavaOpts("-Dsonar.path.logs=" + installation.logsDir().getAbsolutePath())
.setClassName("org.sonar.server.app.ServerProcess")
- .setEnvProperty("SONAR_HOME", installation.homeDir().getAbsolutePath())
.setProperties(installation.props())
.addClasspath(installation.starPath("extensions/jdbc-driver/mysql"))
.addClasspath(installation.starPath("extensions/jdbc-driver/mssql"))
diff --git a/sonar-application/src/test/java/org/sonar/application/ConfigurationUtilsTest.java b/sonar-application/src/test/java/org/sonar/application/ConfigurationUtilsTest.java
deleted file mode 100644
index 133505a51c7..00000000000
--- a/sonar-application/src/test/java/org/sonar/application/ConfigurationUtilsTest.java
+++ /dev/null
@@ -1,55 +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 com.google.common.collect.Maps;
-import org.junit.Test;
-
-import java.util.Map;
-import java.util.Properties;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-public class ConfigurationUtilsTest {
- @Test
- public void shouldInterpolateVariables() {
- Properties input = new Properties();
- input.setProperty("hello", "world");
- input.setProperty("url", "${env:SONAR_JDBC_URL}");
- input.setProperty("do_not_change", "${SONAR_JDBC_URL}");
- Map<String, String> variables = Maps.newHashMap();
- variables.put("SONAR_JDBC_URL", "jdbc:h2:mem");
-
- Properties output = ConfigurationUtils.interpolateVariables(input, variables);
-
- assertThat(output.size(), is(3));
- assertThat(output.getProperty("hello"), is("world"));
- assertThat(output.getProperty("url"), is("jdbc:h2:mem"));
- assertThat(output.getProperty("do_not_change"), is("${SONAR_JDBC_URL}"));
-
- // input is not changed
- assertThat(input.size(), is(3));
- assertThat(input.getProperty("hello"), is("world"));
- assertThat(input.getProperty("url"), is("${env:SONAR_JDBC_URL}"));
- assertThat(input.getProperty("do_not_change"), is("${SONAR_JDBC_URL}"));
- }
-
-}
diff --git a/sonar-application/src/test/resources/org/sonar/application/AesCipherTest/aes_secret_key.txt b/sonar-application/src/test/resources/org/sonar/application/AesCipherTest/aes_secret_key.txt
deleted file mode 100644
index 65b98c522da..00000000000
--- a/sonar-application/src/test/resources/org/sonar/application/AesCipherTest/aes_secret_key.txt
+++ /dev/null
@@ -1 +0,0 @@
-0PZz+G+f8mjr3sPn4+AhHg== \ No newline at end of file
diff --git a/sonar-application/src/test/resources/org/sonar/application/AesCipherTest/bad_secret_key.txt b/sonar-application/src/test/resources/org/sonar/application/AesCipherTest/bad_secret_key.txt
deleted file mode 100644
index b33e179e5c8..00000000000
--- a/sonar-application/src/test/resources/org/sonar/application/AesCipherTest/bad_secret_key.txt
+++ /dev/null
@@ -1 +0,0 @@
-badbadbad== \ No newline at end of file
diff --git a/sonar-application/src/test/resources/org/sonar/application/AesCipherTest/non_trimmed_secret_key.txt b/sonar-application/src/test/resources/org/sonar/application/AesCipherTest/non_trimmed_secret_key.txt
deleted file mode 100644
index ab83e4adc03..00000000000
--- a/sonar-application/src/test/resources/org/sonar/application/AesCipherTest/non_trimmed_secret_key.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-
- 0PZz+G+f8mjr3sPn4+AhHg==
-
diff --git a/sonar-application/src/test/resources/org/sonar/application/AesCipherTest/other_secret_key.txt b/sonar-application/src/test/resources/org/sonar/application/AesCipherTest/other_secret_key.txt
deleted file mode 100644
index 23f5ecf5104..00000000000
--- a/sonar-application/src/test/resources/org/sonar/application/AesCipherTest/other_secret_key.txt
+++ /dev/null
@@ -1 +0,0 @@
-IBxEUxZ41c8XTxyaah1Qlg== \ No newline at end of file
diff --git a/sonar-application/src/test/resources/org/sonar/application/LoggingTest/logback-access.xml b/sonar-application/src/test/resources/org/sonar/application/LoggingTest/logback-access.xml
deleted file mode 100644
index 298193e01fa..00000000000
--- a/sonar-application/src/test/resources/org/sonar/application/LoggingTest/logback-access.xml
+++ /dev/null
@@ -1 +0,0 @@
-<configuration/>
diff --git a/sonar-application/src/test/resources/org/sonar/application/PropsTest/sonar.properties b/sonar-application/src/test/resources/org/sonar/application/PropsTest/sonar.properties
deleted file mode 100644
index 5c06e58a32e..00000000000
--- a/sonar-application/src/test/resources/org/sonar/application/PropsTest/sonar.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-hello: world
-foo=bar
-java.io.tmpdir=/should/be/overridden