diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-07-23 00:32:58 +0200 |
---|---|---|
committer | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-07-23 15:34:06 +0200 |
commit | 39ecd1902afc8922811f97524dfa77a86912508f (patch) | |
tree | 1ba2f7256d1e5e25e6b6031b609b570b7d7df1ae /server | |
parent | 5976c31b87f3e021a6dbf3f8cf71f886a16b0f28 (diff) | |
download | sonarqube-39ecd1902afc8922811f97524dfa77a86912508f.tar.gz sonarqube-39ecd1902afc8922811f97524dfa77a86912508f.zip |
SONAR-4898 few improvements
Diffstat (limited to 'server')
8 files changed, 27 insertions, 66 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/Process.java b/server/sonar-process/src/main/java/org/sonar/process/Process.java index b3824c79606..cc064b758b7 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/Process.java +++ b/server/sonar-process/src/main/java/org/sonar/process/Process.java @@ -19,6 +19,7 @@ */ package org.sonar.process; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,24 +42,16 @@ import java.util.concurrent.TimeUnit; public abstract class Process implements ProcessMXBean { - public static final String SONAR_HOME = "SONAR_HOME"; - - public static final String JAVA_OPS = "javaOps"; public static final String NAME_PROPERTY = "pName"; public static final String PORT_PROPERTY = "pPort"; - public static final String MISSING_NAME_ARGUMENT = "Missing Name argument"; - public static final String SONAR_HOME_IS_NOT_SET = "variable SONAR_HOME is not set."; - public static final String SONAR_HOME_DOES_NOT_EXIST = "Directory SONAR_HOME does not exist"; - public static final String SONAR_HOME_IS_NOT_WRITABLE = "Directory SONAR_HOME is not writable"; - private final static Logger LOGGER = LoggerFactory.getLogger(Process.class); - protected Long lastPing; + private Long lastPing; - String name; - Integer port; + private String name; + private Integer port; protected final Props props; private Thread shutdownHook; @@ -89,10 +82,14 @@ public abstract class Process implements ProcessMXBean { } Properties properties = new Properties(); + FileReader reader = null; try { - properties.load(new FileReader(propertyFile)); + reader = new FileReader(propertyFile); + properties.load(reader); } catch (IOException e) { throw new IllegalStateException("Could not read properties from file '" + args[0] + "'", e); + } finally { + IOUtils.closeQuietly(reader); } props = new Props(properties); init(); @@ -104,7 +101,6 @@ public abstract class Process implements ProcessMXBean { } private void init() { - // Loading all Properties from file this.name = props.of(NAME_PROPERTY, null); this.port = props.intOf(PORT_PROPERTY); @@ -124,7 +120,6 @@ public abstract class Process implements ProcessMXBean { throw new IllegalStateException("Process is not a compliant MBean", e); } - shutdownHook = new Thread(new Runnable() { @Override public void run() { diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java index 435c84ca355..cb1f77c11f6 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java +++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java @@ -60,7 +60,7 @@ public class ProcessWrapper extends Thread { private final List<String> javaOpts = new ArrayList<String>(); private final List<String> classpath = new ArrayList<String>(); private final Map<String, String> envProperties = new HashMap<String, String>(); - private final Map<String, String> properties = new HashMap<String, String>(); + private final Properties properties = new Properties(); private File workDir; private File propertiesFile; private java.lang.Process process; @@ -82,21 +82,9 @@ public class ProcessWrapper extends Thread { return this; } - public ProcessWrapper setProperty(String key, String value) { - properties.put(key, value); - return this; - } - - public ProcessWrapper setProperties(Map<String, String> args) { + public ProcessWrapper setProperties(Properties p) { properties.clear(); - properties.putAll(args); - return this; - } - - public ProcessWrapper setJavaOpts(List<String> opts) { - for (String command : opts) { - addJavaOpts(command); - } + properties.putAll(p); return this; } diff --git a/server/sonar-process/src/main/java/org/sonar/process/Props.java b/server/sonar-process/src/main/java/org/sonar/process/Props.java index 506f6b927f1..21bd8842e3a 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/Props.java +++ b/server/sonar-process/src/main/java/org/sonar/process/Props.java @@ -19,20 +19,27 @@ */ package org.sonar.process; +import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import java.util.Map; import java.util.Properties; public class Props { private final Properties props; + private final Encryption encryption; public Props(Properties props) { this.props = props; + this.encryption = new Encryption(props.getProperty(AesCipher.ENCRYPTION_SECRET_KEY_PATH)); } + @CheckForNull public String of(String key) { - return props.getProperty(key); + String value = props.getProperty(key); + if (value != null && encryption.isEncrypted(value)) { + value = encryption.decrypt(value); + } + return value; } public String of(String key, @Nullable String defaultValue) { @@ -67,23 +74,12 @@ public class Props { return i == null ? defaultValue : i; } - public Properties properties() { + public Properties cryptedProperties() { return props; } - - static Properties decrypt(Properties properties) { - Encryption encryption = new Encryption(properties.getProperty(AesCipher.ENCRYPTION_SECRET_KEY_PATH)); - Properties result = new Properties(); - - for (Map.Entry<Object, Object> entry : properties.entrySet()) { - String key = (String) entry.getKey(); - String value = (String) entry.getValue(); - if (encryption.isEncrypted(value)) { - value = encryption.decrypt(value); - } - result.setProperty(key, value); - } - return result; + public Props set(String key, @Nullable String value) { + props.setProperty(key, value); + return this; } } diff --git a/server/sonar-search/src/main/resources/logback.xml b/server/sonar-search/src/main/resources/logback.xml index 281bccb3d09..25d1932da9d 100644 --- a/server/sonar-search/src/main/resources/logback.xml +++ b/server/sonar-search/src/main/resources/logback.xml @@ -41,7 +41,7 @@ </appender> <root> - <level value="DEBUG"/> + <level value="INFO"/> <appender-ref ref="LOGFILE"/> <appender-ref ref="CONSOLE"/> </root> diff --git a/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java b/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java index a53268205bd..e8185c549a4 100644 --- a/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java +++ b/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java @@ -82,7 +82,6 @@ public class ElasticSearchTest { @Test public void can_connect() throws SocketException { Properties properties = new Properties(); - properties.setProperty(Process.SONAR_HOME, FileUtils.getTempDirectoryPath()); properties.setProperty(Process.NAME_PROPERTY, "ES"); properties.setProperty("sonar.path.data", tempDirectory.getAbsolutePath()); properties.setProperty(ElasticSearch.ES_PORT_PROPERTY, Integer.toString(freeESPort)); diff --git a/server/sonar-server-app/src/main/java/org/sonar/server/app/Env.java b/server/sonar-server-app/src/main/java/org/sonar/server/app/Env.java index 885fbbad7b1..a9b9f7c278c 100644 --- a/server/sonar-server-app/src/main/java/org/sonar/server/app/Env.java +++ b/server/sonar-server-app/src/main/java/org/sonar/server/app/Env.java @@ -23,7 +23,6 @@ import org.apache.commons.io.FileUtils; import org.sonar.process.Props; import java.io.File; -import java.io.IOException; class Env { @@ -51,19 +50,4 @@ class Env { dir.mkdirs(); return dir; } - - /** - * This check is required in order to provide more meaningful message than JRuby - see SONAR-2715 - */ - void verifyWritableTempDir() { - File file = null; - try { - file = File.createTempFile("sonarqube-check", "tmp"); - } catch (IOException e) { - throw new IllegalStateException("Unable to create file in temporary directory, please check existence " + - "and permissions of: " + FileUtils.getTempDirectory(), e); - } finally { - FileUtils.deleteQuietly(file); - } - } } diff --git a/server/sonar-server-app/src/main/java/org/sonar/server/app/ServerProcess.java b/server/sonar-server-app/src/main/java/org/sonar/server/app/ServerProcess.java index 287176a828d..9006705365e 100644 --- a/server/sonar-server-app/src/main/java/org/sonar/server/app/ServerProcess.java +++ b/server/sonar-server-app/src/main/java/org/sonar/server/app/ServerProcess.java @@ -27,7 +27,6 @@ public class ServerProcess extends org.sonar.process.Process { super(args); Logging.init(); Env env = new Env(props); - env.verifyWritableTempDir(); this.tomcat = new EmbeddedTomcat(env); } diff --git a/server/sonar-server-app/src/main/java/org/sonar/server/app/Webapp.java b/server/sonar-server-app/src/main/java/org/sonar/server/app/Webapp.java index e20500f15bd..9f98faf2ec6 100644 --- a/server/sonar-server-app/src/main/java/org/sonar/server/app/Webapp.java +++ b/server/sonar-server-app/src/main/java/org/sonar/server/app/Webapp.java @@ -40,7 +40,7 @@ class Webapp { context.setConfigFile(env.file("web/META-INF/context.xml").toURI().toURL()); context.addParameter(PROPERTY_LOG_PROFILING_LEVEL, props.of(PROPERTY_LOG_PROFILING_LEVEL, "NONE")); context.addParameter(PROPERTY_LOG_CONSOLE, props.of(PROPERTY_LOG_CONSOLE, "false")); - for (Map.Entry<Object, Object> entry : props.properties().entrySet()) { + for (Map.Entry<Object, Object> entry : props.cryptedProperties().entrySet()) { String key = entry.getKey().toString(); if (key.startsWith("sonar.")) { context.addParameter(key, entry.getValue().toString()); |