From f3e1ac2fd1570ed71293fa68673e6e8161aad8de Mon Sep 17 00:00:00 2001 From: Robert Godfrey Date: Mon, 18 Aug 2014 00:32:44 +0000 Subject: QPID-6011 : [Java Broker] provide a mechanism for disabling plugins and implementation types git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1618531 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/org/apache/qpid/server/Main.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'qpid/java/broker/src') diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java index 72550128b7..43b0f9da67 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java @@ -25,6 +25,9 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.HelpFormatter; @@ -94,6 +97,9 @@ public class Main private static final Option OPTION_MM_PASSWORD = OptionBuilder.withArgName("password").hasArg() .withDescription("Set the password for the management mode user " + BrokerOptions.MANAGEMENT_MODE_USER_NAME).withLongOpt("management-mode-password").create("mmpass"); + private static final Option OPTION_INITIAL_SYSTEM_PROPERTIES = OptionBuilder.withArgName("path").hasArg() + .withDescription("set the location of initial properties file to set otherwise unset system properties").withLongOpt("system-properties-file").create("props"); + private static final Options OPTIONS = new Options(); static @@ -114,6 +120,7 @@ public class Main OPTIONS.addOption(OPTION_MM_HTTP_PORT); OPTIONS.addOption(OPTION_MM_PASSWORD); OPTIONS.addOption(OPTION_CONFIGURATION_PROPERTY); + OPTIONS.addOption(OPTION_INITIAL_SYSTEM_PROPERTIES); } protected CommandLine _commandLine; @@ -168,7 +175,11 @@ public class Main protected void execute() throws Exception { + String initialProperties = _commandLine.getOptionValue(OPTION_INITIAL_SYSTEM_PROPERTIES.getOpt()); + populateSystemPropertiesFromDefaults(initialProperties); + BrokerOptions options = new BrokerOptions(); + String initialConfigLocation = _commandLine.getOptionValue(OPTION_INITIAL_CONFIGURATION_PATH.getOpt()); if (initialConfigLocation != null) { @@ -304,6 +315,28 @@ public class Main } } + private void populateSystemPropertiesFromDefaults(final String initialProperties) throws IOException + { + URL initialPropertiesLocation; + if(initialProperties == null) + { + initialPropertiesLocation = getClass().getClassLoader().getResource("system.properties"); + } + else + { + initialPropertiesLocation = (new File(initialProperties)).toURI().toURL(); + } + + Properties props = new Properties(); + props.load(initialPropertiesLocation.openStream()); + Set propertyNames = new HashSet<>(props.stringPropertyNames()); + propertyNames.removeAll(System.getProperties().stringPropertyNames()); + for(String propName : propertyNames) + { + System.setProperty(propName, props.getProperty(propName)); + } + } + private void copyInitialConfigFile(final BrokerOptions options, final File destinationFile) { String initialConfigLocation = options.getInitialConfigurationLocation(); -- cgit v1.2.1