[java-metadata-aggregator COMMIT] in /trunk/aggregator-cli: pom.xml src/main/java/net/shibboleth/metadata/cli/SimpleC...
noreply at shibboleth.net
noreply at shibboleth.net
Fri Mar 23 15:41:29 GMT 2012
Author: iay
Date: Fri Mar 23 15:41:29 2012
New Revision: 202
URL: http://svn.shibboleth.net/view/java-metadata-aggregator?rev=202&view=rev
Log:
MDA-39: improve command line interface
Part 1: proper command line parsing in general; logging options and help in particular.
Added:
trunk/aggregator-cli/src/main/java/net/shibboleth/metadata/cli/SimpleCommandLineArguments.java (with props)
trunk/aggregator-cli/src/main/resources/logger-normal.xml (contents, props changed)
- copied, changed from r190, trunk/aggregator-cli/src/main/resources/logback.xml
trunk/aggregator-cli/src/main/resources/logger-quiet.xml (with props)
trunk/aggregator-cli/src/main/resources/logger-verbose.xml (with props)
Removed:
trunk/aggregator-cli/src/main/resources/logback.xml
Modified:
trunk/aggregator-cli/pom.xml
trunk/aggregator-cli/src/main/java/net/shibboleth/metadata/cli/SimpleCommandLine.java
Modified: trunk/aggregator-cli/pom.xml
URL: http://svn.shibboleth.net/view/java-metadata-aggregator/trunk/aggregator-cli/pom.xml?rev=202&r1=201&r2=202&view=diff
==============================================================================
--- trunk/aggregator-cli/pom.xml (original)
+++ trunk/aggregator-cli/pom.xml Fri Mar 23 15:41:29 2012
@@ -31,6 +31,10 @@
<artifactId>spring-extensions</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>jargs</groupId>
+ <artifactId>jargs</artifactId>
+ </dependency>
<!-- Provided Dependencies -->
Modified: trunk/aggregator-cli/src/main/java/net/shibboleth/metadata/cli/SimpleCommandLine.java
URL: http://svn.shibboleth.net/view/java-metadata-aggregator/trunk/aggregator-cli/src/main/java/net/shibboleth/metadata/cli/SimpleCommandLine.java?rev=202&r1=201&r2=202&view=diff
==============================================================================
--- trunk/aggregator-cli/src/main/java/net/shibboleth/metadata/cli/SimpleCommandLine.java (original)
+++ trunk/aggregator-cli/src/main/java/net/shibboleth/metadata/cli/SimpleCommandLine.java Fri Mar 23 15:41:29 2012
@@ -19,6 +19,7 @@
import java.io.File;
import java.util.ArrayList;
+import java.util.Date;
import net.shibboleth.metadata.dom.DomElementItem;
import net.shibboleth.metadata.pipeline.Pipeline;
@@ -44,37 +45,54 @@
*/
public class SimpleCommandLine {
+ /** Return code indicating command completed successfully, {@value} . */
+ public static final int RC_OK = 0;
+
+ /** Return code indicating an initialization error, {@value} . */
+ public static final int RC_INIT = 1;
+
+ /** Return code indicating an error reading files, {@value} . */
+ public static final int RC_IO = 2;
+
+ /** Return code indicating an unknown error occurred, {@value} . */
+ public static final int RC_UNKNOWN = -1;
+
+ /** Class logger. */
+ private static Logger log;
+
/**
* Main method.
*
* @param args command line arguments
*/
public static void main(String[] args) {
- if (args.length != 2) {
- System.err.println("This command line only supports two arguments, "
- + "the file path to the Spring configuration file describing the processing pipeline "
- + "and bean ID of the Pipeline to execute.");
- System.exit(1);
+ SimpleCommandLineArguments cli = new SimpleCommandLineArguments(args);
+ cli.parseCommandLineArguments(args);
+
+ if (cli.doHelp()) {
+ cli.printHelp(System.out);
+ System.exit(RC_OK);
}
-
- Logger log = LoggerFactory.getLogger(SimpleCommandLine.class);
+
+ initLogging(cli);
FileSystemXmlApplicationContext appCtx = null;
try {
- String fileUri = new File(args[0]).toURI().toString();
+ String fileUri = new File(cli.getInputFile()).toURI().toString();
log.debug("Initializing Spring context with configuration file {}", fileUri);
appCtx = new FileSystemXmlApplicationContext(fileUri);
} catch (BeansException e) {
log.error("Unable to initialize Spring context", e);
- System.exit(1);
+ System.exit(RC_INIT);
}
log.debug("Retreiving pipeline from Spring context");
- Pipeline pipeline = appCtx.getBean(args[1], Pipeline.class);
+ String pipelineName = cli.getPipelineName();
+ Pipeline pipeline = appCtx.getBean(pipelineName, Pipeline.class);
if (pipeline == null) {
log.error("No net.shibboleth.metadata.pipeline.Pipeline, with ID {}, defined in Spring configuration",
- args[1]);
- System.exit(1);
+ pipelineName);
+ System.exit(RC_INIT);
}
try {
@@ -85,15 +103,37 @@
log.debug("Retrieved pipeline has already been initialized");
}
- log.debug("Executing pipeline");
[... 58 lines stripped ...]
More information about the commits
mailing list