diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-08-07 00:01:38 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-08-07 00:27:14 +0200 |
commit | c36cc4d9b79e3c6b1aaddb07ff959937e39b77fd (patch) | |
tree | 1de506be5fe1c422ef086b2bbeaf50c89fd26feb /server/sonar-process | |
parent | cddd1cb427019625c79133e8f6d9f0d9a64a156f (diff) | |
download | sonarqube-c36cc4d9b79e3c6b1aaddb07ff959937e39b77fd.tar.gz sonarqube-c36cc4d9b79e3c6b1aaddb07ff959937e39b77fd.zip |
SONAR-5499 Do not allow to change the distributed JDBC drivers
Diffstat (limited to 'server/sonar-process')
-rw-r--r-- | server/sonar-process/src/main/java/org/sonar/process/MessageException.java | 36 | ||||
-rw-r--r-- | server/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java (renamed from server/sonar-process/src/main/java/org/sonar/process/MinimumViableEnvironment.java) | 19 | ||||
-rw-r--r-- | server/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java | 53 | ||||
-rw-r--r-- | server/sonar-process/src/main/java/org/sonar/process/Props.java | 17 | ||||
-rw-r--r-- | server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java (renamed from server/sonar-process/src/test/java/org/sonar/process/MinimumViableEnvironmentTest.java) | 14 |
5 files changed, 112 insertions, 27 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/MessageException.java b/server/sonar-process/src/main/java/org/sonar/process/MessageException.java new file mode 100644 index 00000000000..5b86ef66c64 --- /dev/null +++ b/server/sonar-process/src/main/java/org/sonar/process/MessageException.java @@ -0,0 +1,36 @@ +/* + * 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; + +public class MessageException extends RuntimeException { + public MessageException(String message) { + super(message); + } + + /** + * Does not fill in the stack trace + * + * @see Throwable#fillInStackTrace() + */ + @Override + public synchronized Throwable fillInStackTrace() { + return this; + } +} diff --git a/server/sonar-process/src/main/java/org/sonar/process/MinimumViableEnvironment.java b/server/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java index 549b13f38d2..64526f56985 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/MinimumViableEnvironment.java +++ b/server/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java @@ -27,11 +27,11 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; -public class MinimumViableEnvironment { +public class MinimumViableSystem { private final Map<String, String> requiredJavaOptions = new HashMap<String, String>(); - public MinimumViableEnvironment setRequiredJavaOption(String propertyKey, String expectedValue) { + public MinimumViableSystem setRequiredJavaOption(String propertyKey, String expectedValue) { requiredJavaOptions.put(propertyKey, expectedValue); return this; } @@ -81,19 +81,4 @@ public class MinimumViableEnvironment { } } - static class MessageException extends RuntimeException { - private MessageException(String message) { - super(message); - } - - /** - * Does not fill in the stack trace - * - * @see java.lang.Throwable#fillInStackTrace() - */ - @Override - public synchronized Throwable fillInStackTrace() { - return this; - } - } } diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java new file mode 100644 index 00000000000..40b336bbc0b --- /dev/null +++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java @@ -0,0 +1,53 @@ +/* + * 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 ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.joran.JoranConfigurator; +import ch.qos.logback.core.joran.spi.JoranException; +import ch.qos.logback.core.util.StatusPrinter; +import org.slf4j.LoggerFactory; + +public class ProcessLogging { + + private static final String PATH_LOGS_PROPERTY = "sonar.path.logs"; + + public void configure(Props props, String logbackXmlResource) { + LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); + try { + JoranConfigurator configurator = new JoranConfigurator(); + configurator.setContext(context); + context.reset(); + context.putProperty(PATH_LOGS_PROPERTY, props.of(PATH_LOGS_PROPERTY)); + doConfigure(configurator, logbackXmlResource); + } catch (JoranException je) { + // StatusPrinter will handle this + } + StatusPrinter.printInCaseOfErrorsOrWarnings(context); + + } + + /** + * Extracted only for unit testing + */ + void doConfigure(JoranConfigurator configurator, String logbackXmlResource) throws JoranException { + configurator.doConfigure(getClass().getResource(logbackXmlResource)); + } +} 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 665c16af303..df673ff4c25 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,8 +19,12 @@ */ package org.sonar.process; +import org.apache.commons.lang.StringUtils; + import javax.annotation.CheckForNull; import javax.annotation.Nullable; + +import java.io.File; import java.util.Properties; public class Props { @@ -61,6 +65,12 @@ public class Props { return s != null ? Boolean.parseBoolean(s) : defaultValue; } + @CheckForNull + public File fileOf(String key) { + String s = of(key); + return s != null ? new File(s) : null; + } + public Integer intOf(String key) { String s = of(key); if (s != null && !"".equals(s)) { @@ -87,9 +97,10 @@ public class Props { return this; } - public void setDefault(String propKey, String defaultValue) { - if (!props.containsKey(propKey)) { - props.setProperty(propKey, defaultValue); + public void setDefault(String key, String value) { + String s = props.getProperty(key); + if (StringUtils.isBlank(s)) { + props.setProperty(key, value); } } } diff --git a/server/sonar-process/src/test/java/org/sonar/process/MinimumViableEnvironmentTest.java b/server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java index 593187e6d91..11088902b14 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/MinimumViableEnvironmentTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java @@ -24,7 +24,7 @@ import org.junit.Test; import static org.fest.assertions.Fail.fail; -public class MinimumViableEnvironmentTest { +public class MinimumViableSystemTest { /** * Verifies that all checks can be verified without error. @@ -32,19 +32,19 @@ public class MinimumViableEnvironmentTest { */ @Test public void check() throws Exception { - MinimumViableEnvironment mve = new MinimumViableEnvironment(); + MinimumViableSystem mve = new MinimumViableSystem(); try { mve.check(); // ok - } catch (MinimumViableEnvironment.MessageException e) { + } catch (MessageException e) { // also ok. All other exceptions are errors. } } @Test public void checkJavaVersion() throws Exception { - MinimumViableEnvironment mve = new MinimumViableEnvironment(); + MinimumViableSystem mve = new MinimumViableSystem(); // yes, sources are compiled with a supported Java version! mve.checkJavaVersion(); @@ -53,7 +53,7 @@ public class MinimumViableEnvironmentTest { try { mve.checkJavaVersion("1.5.2"); fail(); - } catch (MinimumViableEnvironment.MessageException e) { + } catch (MessageException e) { Assertions.assertThat(e).hasMessage("Minimal required Java version is 1.6. Got 1.5.2."); } } @@ -61,14 +61,14 @@ public class MinimumViableEnvironmentTest { @Test public void checkJavaOption() throws Exception { String key = "MinimumViableEnvironmentTest.test.prop"; - MinimumViableEnvironment mve = new MinimumViableEnvironment() + MinimumViableSystem mve = new MinimumViableSystem() .setRequiredJavaOption(key, "true"); try { System.setProperty(key, "false"); mve.checkJavaOptions(); fail(); - } catch (MinimumViableEnvironment.MessageException e) { + } catch (MessageException e) { Assertions.assertThat(e).hasMessage("JVM option '" + key + "' must be set to 'true'. Got 'false'"); } |