From be0d578ee788e1a809e16e75aa37d58438a98f54 Mon Sep 17 00:00:00 2001 From: "Mark H. Wood" Date: Tue, 26 Apr 2016 14:39:38 -0400 Subject: [PATCH] [DS-3158] Move the command method somewhere less deprecated. This code no longer has any connection with the deprecated class Configurationmanager, so move it now before we lose it by accident. --- .../org/dspace/app/util/Configuration.java | 110 ++++++++++++++++++ .../org/dspace/core/ConfigurationManager.java | 95 --------------- dspace/config/launcher.xml | 2 +- 3 files changed, 111 insertions(+), 96 deletions(-) create mode 100644 dspace-api/src/main/java/org/dspace/app/util/Configuration.java diff --git a/dspace-api/src/main/java/org/dspace/app/util/Configuration.java b/dspace-api/src/main/java/org/dspace/app/util/Configuration.java new file mode 100644 index 0000000000..10f37116bf --- /dev/null +++ b/dspace-api/src/main/java/org/dspace/app/util/Configuration.java @@ -0,0 +1,110 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ + +package org.dspace.app.util; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; + +/** + * Configuration tools. + * + * @author mwood + */ +public class Configuration +{ + /** + * Command-line interface for running configuration tasks. Possible + * arguments: + * + * If the property does not exist, nothing is written. + * + * @param argv + * command-line arguments + */ + public static void main(String[] argv) + { + // Build a description of the command line + Options options = new Options(); + options.addOption("p", "property", true, "name of the desired property"); + options.addOption("m", "module", true, + "optional name of the module in which 'property' exists"); + options.addOption("r", "raw", false, + "do not do property substitution on the value"); + options.addOption("?", "Get help"); + options.addOption("h", "help", false, "Get help"); + // Analyze the command line + CommandLineParser parser = new DefaultParser(); + CommandLine cmd = null; + try + { + cmd = parser.parse(options, argv); + } catch (ParseException ex) + { + System.err.println(ex.getMessage()); + System.exit(1); + } + // Give help if asked + if (cmd.hasOption('?') || cmd.hasOption('h')) + { + new HelpFormatter().printHelp("dsprop [options]", + "Display the value of a DSpace configuration property", + options, + "If --module is omitted, then --property gives the entire" + + " name of the property. Otherwise the name is" + + " composed of module.property."); + System.exit(0); + } + // Check for missing required values + if (!cmd.hasOption('p')) + { + System.err.println("Error: -p is required"); + System.exit(1); + } + // Figure out the property's full name + StringBuilder propNameBuilder = new StringBuilder(1024); + propNameBuilder.append(cmd.getOptionValue('p')); + if (cmd.hasOption('m')) + { + propNameBuilder.append('.').append(cmd.getOptionValue('m')); + } + String propName = propNameBuilder.toString(); + // Print the property's value, if it exists + ConfigurationService cfg = DSpaceServicesFactory.getInstance().getConfigurationService(); + if (!cfg.hasProperty(propName)) + { + System.out.println(); + } + else + { + String val; + if (cmd.hasOption('r')) + { + val = cfg.getPropertyValue(propName).toString(); + } + else + { + val = cfg.getProperty(propName); + } + System.out.println(val); + } + System.exit(0); + } +} diff --git a/dspace-api/src/main/java/org/dspace/core/ConfigurationManager.java b/dspace-api/src/main/java/org/dspace/core/ConfigurationManager.java index d93007a1a4..6c573cf96d 100644 --- a/dspace-api/src/main/java/org/dspace/core/ConfigurationManager.java +++ b/dspace-api/src/main/java/org/dspace/core/ConfigurationManager.java @@ -9,17 +9,10 @@ package org.dspace.core; import java.util.Enumeration; import java.util.Properties; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationConverter; import org.apache.log4j.Logger; -import org.dspace.services.ConfigurationService; import org.dspace.services.factory.DSpaceServicesFactory; /** @@ -419,92 +412,4 @@ public class ConfigurationManager // Get property keys beginning with this prefix, and convert into an Enumeration return java.util.Collections.enumeration(DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyKeys(module)); } - - /** - * Command-line interface for running configuration tasks. Possible - * arguments: - * - * If the property does not exist, nothing is written. - * - * @param argv - * command-line arguments - */ - public static void main(String[] argv) - { - // Build a description of the command line - Options options = new Options(); - - options.addOption("p", "property", true, - "name of the desired property"); - - options.addOption("m", "module", true, - "optional name of the module in which 'property' exists"); - - options.addOption("r", "raw", false, - "do not do property substitution on the value"); - - options.addOption("?", "Get help"); - options.addOption("h", "help", false, "Get help"); - - // Analyze the command line - CommandLineParser parser = new DefaultParser(); - CommandLine cmd = null; - try { - cmd = parser.parse(options, argv); - } catch (ParseException ex) { - System.err.println(ex.getMessage()); - System.exit(1); - } - - // Give help if asked - if (cmd.hasOption('?') || cmd.hasOption('h')) - { - new HelpFormatter().printHelp( - "dsprop [options]", - "Display the value of a DSpace configuration property", - options, - "If --module is omitted, then --property gives the entire" - + " name of the property. Otherwise the name is" - + " composed of module.property."); - System.exit(0); - } - - // Check for missing required values - if (!cmd.hasOption('p')) - { - System.err.println("Error: -p is required"); - System.exit(1); - } - - // Figure out the property's full name - StringBuilder propNameBuilder = new StringBuilder(1024); - propNameBuilder.append(cmd.getOptionValue('p')); - if (cmd.hasOption('m')) - propNameBuilder.append('.') - .append(cmd.getOptionValue('m')); - String propName = propNameBuilder.toString(); - - // Print the property's value, if it exists - ConfigurationService cfg - = DSpaceServicesFactory.getInstance().getConfigurationService(); - if (!cfg.hasProperty(propName)) - { - System.out.println(); - } - else - { - String val; - if (cmd.hasOption('r')) - val = cfg.getPropertyValue(propName).toString(); - else - val = cfg.getProperty(propName); - System.out.println(val); - } - - System.exit(0); - } } diff --git a/dspace/config/launcher.xml b/dspace/config/launcher.xml index 970eb480a4..1b607e2ccd 100644 --- a/dspace/config/launcher.xml +++ b/dspace/config/launcher.xml @@ -79,7 +79,7 @@ dsprop View a DSpace property from dspace.cfg - org.dspace.core.ConfigurationManager + org.dspace.app.util.Configuration