Package net.shibboleth.ext.spring.cli
Class AbstractCommandLine<T extends CommandLineArguments>
java.lang.Object
net.shibboleth.ext.spring.cli.AbstractCommandLine<T>
- Type Parameters:
T
- argument object type
A simple driver for a Spring-based CLI.
This class handles a single parameters, the primary Spring configuration resource. Additional parameters may be
handled by subclasses.
All logging is done in accordance with the logback.xml file included in the library. If you wish to use a
different logging configuration you may do so using the
-Dlogback.configurationFile=/path/to/logback.xml
JVM configuration option.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate GenericApplicationContext
Spring context.static final String
Name of system property for command line argument class.private ApplicationContextInitializer<? super FilesystemGenericApplicationContext>
Optional Context initialized.static final int
Return code indicating an initialization error, 1 .static final int
Return code indicating an error reading files, 2 .static final int
Return code indicating command completed successfully, 0 .static final int
Return code indicating an unknown error occurred, -1 . -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected int
The execution method to override.private static void
Prints the error message to STDERR.Return any additional resources that should be prepended to that supplied by the caller.protected GenericApplicationContext
Get the Spring context.Get the class of the argument object to instantiate.protected abstract org.slf4j.Logger
Get logger.protected abstract String
Return an appropriate version value.protected void
initLogging
(T args) Initialize the logging subsystem.protected int
Run method.protected void
setContextInitializer
(ApplicationContextInitializer<? super FilesystemGenericApplicationContext> initializer) Set a context initializer.private void
setLoggingProperty
(String value) Set the logback configuration to a specific location.private void
setLoggingToLocalResource
(String value) Set the logback configuration to a specific package-local resource.
-
Field Details
-
ARGS_PROPERTY
Name of system property for command line argument class.- See Also:
-
RC_OK
public static final int RC_OKReturn code indicating command completed successfully, 0 .- See Also:
-
RC_INIT
public static final int RC_INITReturn code indicating an initialization error, 1 .- See Also:
-
RC_IO
public static final int RC_IOReturn code indicating an error reading files, 2 .- See Also:
-
RC_UNKNOWN
public static final int RC_UNKNOWNReturn code indicating an unknown error occurred, -1 .- See Also:
-
applicationContext
Spring context. -
contextInitializer
@Nullable private ApplicationContextInitializer<? super FilesystemGenericApplicationContext> contextInitializerOptional Context initialized.
-
-
Constructor Details
-
AbstractCommandLine
public AbstractCommandLine()
-
-
Method Details
-
setContextInitializer
protected void setContextInitializer(@Nonnull ApplicationContextInitializer<? super FilesystemGenericApplicationContext> initializer) Set a context initializer.- Parameters:
initializer
- what to set
-
getApplicationContext
Get the Spring context.- Returns:
- Spring context
-
getAdditionalSpringResources
@Nonnull @NonnullElements @Unmodifiable @NotLive protected List<Resource> getAdditionalSpringResources()Return any additional resources that should be prepended to that supplied by the caller.- Returns:
- the resources
-
run
Run method.- Parameters:
args
- command line arguments- Returns:
- exit code
-
setLoggingProperty
Set the logback configuration to a specific location.Note that this must be done before the first logger is retrieved.
- Parameters:
value
- logback configuration location to set
-
setLoggingToLocalResource
Set the logback configuration to a specific package-local resource.- Parameters:
value
- name of resource to use as the logback configuration file
-
initLogging
Initialize the logging subsystem.- Parameters:
args
- command line arguments
-
doRun
The execution method to override. The default implementation handles Spring context creation.- Parameters:
args
- input arguments- Returns:
- exit code
-
getArgumentClass
Get the class of the argument object to instantiate.- Returns:
- argument class
-
getVersion
Return an appropriate version value.- Returns:
- a version string
-
getLogger
@Nonnull protected abstract org.slf4j.Logger getLogger()Get logger.- Returns:
- logger
-
error
Prints the error message to STDERR.- Parameters:
error
- the error message
-