public final class CliUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_HELP_COMMAND_LINE_OPTION
Default help command line option.
|
static String |
DEFAULT_NO_CONFIRM_COMMAND_LINE_OPTION
Default command line option for specifying whether confirmation is required.
|
static String |
DEFAULT_NO_CONFIRM_CONTEXT_COMMAND_LINE_OPTION
Default command line option for specifying whether confirmation is required
for a particular context.
|
static String |
DEFAULT_REFERENCE_PATH_MATCHER_COMMAND_LINE_OPTION
Default
ReferencePathMatcherByElement command line option. |
static String |
DEFAULT_ROOT_MODULE_VERSION_COMMAND_LINE_OPTION
Default root
ModuleVersion command line option. |
static String |
DEFAULT_TOOL_PROPERTIES_COMMAND_LINE_OPTION
Default command line option for specifying the tool properties file.
|
static String |
DEFAULT_USER_PROPERTIES_COMMAND_LINE_OPTION
Default command line option for specifying the user properties file.
|
static String |
DEFAULT_WORKSPACE_PATH_COMMAND_LINE_OPTION
Default command line option for specifying the workspace path.
|
static String |
MSG_PATTERN_KEY_ERROR_PARSING_COMMAND_LINE
See description in ResourceBundle.
|
static String |
MSG_PATTERN_KEY_ERROR_PARSING_COMMAND_LINE_OPTION
See description in ResourceBundle.
|
static String |
MSG_PATTERN_KEY_INVALID_ARGUMENT_COUNT
See description in ResourceBundle.
|
static String |
MSG_PATTERN_KEY_INVALID_COMMAND
See description in ResourceBundle.
|
static String |
MSG_PATTERN_KEY_REFERENCE_PATH_MATCHER_REQUIRED
See description in ResourceBundle.
|
static String |
MSG_PATTERN_KEY_ROOT_MODULE_VERSION_NOT_ALLOWED_WHEN_SPECIFIED_WORKSPACE
See description in ResourceBundle.
|
static String |
MSG_PATTERN_KEY_ROOT_MODULE_VERSION_REQUIRED_WHEN_NOT_SPECIFIED_WORKSPACE
See description in ResourceBundle.
|
static String |
MSG_PATTERN_KEY_ROOT_MODULE_VERSION_REQUIRED_WORKSPACE
See description in ResourceBundle.
|
static String |
MSG_PATTERN_KEY_USER_ERROR_PREFIX
See description in ResourceBundle.
|
static String |
SYS_PROPERTY_DEFAULT_USER_PROPERTIES_FILE
System property that specifies the default user properties file.
|
static String |
SYS_PROPERTY_HELP_COMMAND_LINE_OPTION
System property that specifies the help command line option.
|
static String |
SYS_PROPERTY_IND_SINGLE_TOOL_PROPERTIES
System property that specifies if single tool properties are supported.
|
static String |
SYS_PROPERTY_IND_TOOL_PROPERTIES
System property that specifies if a tool properties file is supported.
|
static String |
SYS_PROPERTY_IND_USER_PROPERTIES
System property that specifies if a user properties file is supported.
|
static String |
SYS_PROPERTY_JAVA_UTIL_LOGGING_CONFIG_FILE
System property defining the Java Util Logging configuration file to use for
initializing the Java Util Logging framework.
|
static String |
SYS_PROPERTY_NO_CONFIRM_COMMAND_LINE_OPTION
System property that specifies the command line option specifying whether
confirmation is required.
|
static String |
SYS_PROPERTY_NO_CONFIRM_CONTEXT_COMMAND_LINE_OPTION
System property that specifies the command line option specifying whether
confirmation is required for a particular context.
|
static String |
SYS_PROPERTY_REFERENCE_PATH_MATCHER_COMMAND_LINE_OPTION
System property that specifies the
ReferencePathMatcherByElement
command line option. |
static String |
SYS_PROPERTY_ROOT_MODULE_VERSION_COMMAND_LINE_OPTION
System property that specifies the root
ModuleVersion command line
option. |
static String |
SYS_PROPERTY_TOOL_PROPERTIES_FILE_COMMAND_LINE_OPTION
System property that specifies the command line option used to specify the tool
properties file.
|
static String |
SYS_PROPERTY_USER_PROPERTIES_FILE_COMMAND_LINE_OPTION
System property that specifies the command line option used to specify the user
properties file.
|
static String |
SYS_PROPERTY_WORKSPACE_PATH_COMMAND_LINE_OPTION
System property that specifies the command line option used to specify the
workspace path.
|
| Constructor and Description |
|---|
CliUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addRootModuleVersionOptions(org.apache.commons.cli.Options options)
Utility method to add Option's related to the root
ModuleVersion. |
static void |
addStandardOptions(org.apache.commons.cli.Options options)
Utility method to add standard Option's.
|
static String |
getHelpCommandLineOption() |
static List<org.azyva.dragom.model.ModuleVersion> |
getListModuleVersionRoot(org.apache.commons.cli.CommandLine commandLine)
Helper method to return the List of root
ModuleVersion's used by many
tools. |
static String |
getLocalizedMsgPattern(String msgPatternKey)
Returns a message pattern corresponding to a key.
|
static InputStream |
getLocalizedResourceAsStream(Class<?> clazz,
String resourceBaseName)
Returns the version of a resource appropriate for the current default Locale.
|
static String |
getNoConfirmCommandLineOption() |
static String |
getNoConfirmContextCommandLineOption() |
static org.azyva.dragom.reference.ReferencePathMatcher |
getReferencePathMatcher(org.apache.commons.cli.CommandLine commandLine)
Helper method to return a ReferencePathMatcherAnd that is built from the
ReferencePathMatcherOr specified by RootManager and a ReferencePathMatcherOr
built from the --reference-path-matcher options that specify
ReferencePathMatcherByElement literals.
|
static String |
getReferencePathMatcherCommandLineOption() |
static String |
getRootModuleVersionCommandLineOption() |
static String |
getToolPropertiesFileCommandLineOption() |
static String |
getUserPropertiesFileCommandLineOption() |
static String |
getWorkspacePathCommandLineOption() |
static boolean |
hasHelpOption(org.apache.commons.cli.CommandLine commandLine)
Indicates if the help command line option is specified.
|
static void |
initJavaUtilLogging()
Initializes the Java Util Logging framework by implementing replaceable
properties in the configuration file.
|
static org.azyva.dragom.execcontext.ExecContext |
setupExecContext(org.apache.commons.cli.CommandLine commandLine,
boolean indSet)
Sets up an
ExecContext assuming an ExecContextFactory that
supports the concept of workspace directory. |
public static final String SYS_PROPERTY_IND_USER_PROPERTIES
public static final String SYS_PROPERTY_DEFAULT_USER_PROPERTIES_FILE
public static final String SYS_PROPERTY_USER_PROPERTIES_FILE_COMMAND_LINE_OPTION
public static final String DEFAULT_USER_PROPERTIES_COMMAND_LINE_OPTION
public static final String SYS_PROPERTY_IND_SINGLE_TOOL_PROPERTIES
public static final String SYS_PROPERTY_IND_TOOL_PROPERTIES
public static final String SYS_PROPERTY_WORKSPACE_PATH_COMMAND_LINE_OPTION
public static final String DEFAULT_WORKSPACE_PATH_COMMAND_LINE_OPTION
public static final String SYS_PROPERTY_TOOL_PROPERTIES_FILE_COMMAND_LINE_OPTION
public static final String DEFAULT_TOOL_PROPERTIES_COMMAND_LINE_OPTION
public static final String SYS_PROPERTY_NO_CONFIRM_COMMAND_LINE_OPTION
public static final String DEFAULT_NO_CONFIRM_COMMAND_LINE_OPTION
public static final String SYS_PROPERTY_NO_CONFIRM_CONTEXT_COMMAND_LINE_OPTION
public static final String DEFAULT_NO_CONFIRM_CONTEXT_COMMAND_LINE_OPTION
public static final String SYS_PROPERTY_HELP_COMMAND_LINE_OPTION
public static final String DEFAULT_HELP_COMMAND_LINE_OPTION
public static final String SYS_PROPERTY_ROOT_MODULE_VERSION_COMMAND_LINE_OPTION
ModuleVersion command line
option.public static final String DEFAULT_ROOT_MODULE_VERSION_COMMAND_LINE_OPTION
ModuleVersion command line option.public static final String SYS_PROPERTY_REFERENCE_PATH_MATCHER_COMMAND_LINE_OPTION
ReferencePathMatcherByElement
command line option.public static final String DEFAULT_REFERENCE_PATH_MATCHER_COMMAND_LINE_OPTION
ReferencePathMatcherByElement command line option.public static final String SYS_PROPERTY_JAVA_UTIL_LOGGING_CONFIG_FILE
initJavaUtilLogging().public static final String MSG_PATTERN_KEY_USER_ERROR_PREFIX
public static final String MSG_PATTERN_KEY_ERROR_PARSING_COMMAND_LINE
public static final String MSG_PATTERN_KEY_ERROR_PARSING_COMMAND_LINE_OPTION
public static final String MSG_PATTERN_KEY_INVALID_ARGUMENT_COUNT
public static final String MSG_PATTERN_KEY_INVALID_COMMAND
public static final String MSG_PATTERN_KEY_ROOT_MODULE_VERSION_NOT_ALLOWED_WHEN_SPECIFIED_WORKSPACE
public static final String MSG_PATTERN_KEY_ROOT_MODULE_VERSION_REQUIRED_WHEN_NOT_SPECIFIED_WORKSPACE
public static final String MSG_PATTERN_KEY_ROOT_MODULE_VERSION_REQUIRED_WORKSPACE
public static final String MSG_PATTERN_KEY_REFERENCE_PATH_MATCHER_REQUIRED
public static String getUserPropertiesFileCommandLineOption()
public static String getToolPropertiesFileCommandLineOption()
public static String getWorkspacePathCommandLineOption()
public static String getNoConfirmCommandLineOption()
public static String getNoConfirmContextCommandLineOption()
public static String getHelpCommandLineOption()
public static String getRootModuleVersionCommandLineOption()
ModuleVersion command line option.public static String getReferencePathMatcherCommandLineOption()
public static void addStandardOptions(org.apache.commons.cli.Options options)
The user properties and tools properties Option's are added depending on whether user properties and tool properties are supported.
The following Option's are also added:
options - Options.public static void addRootModuleVersionOptions(org.apache.commons.cli.Options options)
ModuleVersion.
The following Option's are added:
ModuleVersion
ReferencePathMatcherByElement
ModuleVersion's when initializing Options.options - Options.public static org.azyva.dragom.execcontext.ExecContext setupExecContext(org.apache.commons.cli.CommandLine commandLine,
boolean indSet)
ExecContext assuming an ExecContextFactory that
supports the concept of workspace directory.
ExecContextFactoryHolder is used to get the ExecContextFactory so it
is not guaranteed that it will support the concept of workspace directory and
implement WorkspaceExecContextFactory. In such as case an exception is
raised.
The strategy for setting up the ExecContext supports a user service implementation where a single JVM remains running in the background in the context of a given user account (not system-wide) and can execute Dragom tools for multiple different workspaces while avoiding tool startup overhead. Nailgun can be useful for that purpose.
A user service implementation is supported by differentiating between workspace
initialization Properties passed to ExecContextFactory.getExecContext(java.util.Properties)
and tool initialization Properties passed to
ToolLifeCycleExecContext.startTool(java.util.Properties).
Workspace initialization Properties are constructed in the following way:
Util.applyDragomSystemProperties(). System properties take precedence
over Dragom properties;
Tool initialization Properties are constructed in the following way (if indSet):
It is possible that ExecContextFactory.getExecContext uses a cached ExecContext corresponding to a workspace that has already been initialized previously. In that case workspace initialization Properties will not be considered since ExecContextFactory.getExecContext considers them only when a new ExecContext is created. This is not expected to be a problem or source of confusion since this can happen only if a user service implementation is actually used and in such a case Dragom and system properties are expected to be considered only once when initializing the user service and users are expected to understand that user properties are considered only when initializing a new workspace.
If indSet, ExecContextHolder.setAndStartTool(org.azyva.dragom.execcontext.ExecContext, java.util.Properties) is called with the
ExecContext to make it easier for tools to prepare for execution. But it is
still the tool's responsibility to call
ExecContextHolder.endToolAndUnset() before exiting. This is somewhat
asymmetric, but is sufficiently convenient to be warranted. The case where it
can be useful to set indSet to false is for subsequently calling
ExecContextHolder.forceUnset(org.azyva.dragom.execcontext.ExecContext).
If indSet, the IND_NO_CONFIRM and IND_NO_CONFIRM.<context> runtime
properties are read from the CommandLine.
commandLine - CommandLine where to obtain the user and tool properties
files as well as the workspace path.indSet - Indicates to set the ExecContext in ExecContextHolder.public static boolean hasHelpOption(org.apache.commons.cli.CommandLine commandLine)
commandLine - CommandLine.public static List<org.azyva.dragom.model.ModuleVersion> getListModuleVersionRoot(org.apache.commons.cli.CommandLine commandLine)
ModuleVersion's used by many
tools.
If the command line specifies the --root-module-version option, no root ModuleVersions's must be specified by RootManager, and the List of root ModuleVerion's contains the ModuleVersion's specified by these options that specify ModuleVersion literals.
Otherwise, RootManager must specify at least one root ModuleVersion and this List of root ModuleVersion's specified by RootManager is returned.
commandLine - CommandLine. Can be null to indicate that root
ModuleVersion's cannot be specified on the command line.public static org.azyva.dragom.reference.ReferencePathMatcher getReferencePathMatcher(org.apache.commons.cli.CommandLine commandLine)
commandLine - CommandLine. Can be null to indicate that
ReferencePathMatcherByElement's cannot be specified on the command line. In
this case only the ReferencePathMatcherOr specified by RootManager is
returned, equivalent to as if the one specified on the command line was "**".public static String getLocalizedMsgPattern(String msgPatternKey)
msgPatternKey - Message pattern key within the ResourceBundle.public static InputStream getLocalizedResourceAsStream(Class<?> clazz, String resourceBaseName)
The algorithm used for selecting the appropriate resource is similar to the one implemented by ResourceBundle.getBundle.
The resource base name is split on the last ".", if any, and the candidate variants are inserted before it.
clazz - Class to which the resource belongs.resourceBaseName - Base name of the resource.public static void initJavaUtilLogging()
If the java.util.logging.config.file system property is defined, this method does nothing, leaving the default initialization process be used.
If the java.util.logging.config.file system property is not defined and the org.azyva.dragom.JavaUtilLoggingConfigFile system property is defined, this method calls LogManager.readConfiguration with an InputStream which represents the file but with property references replaced by the corresponding system property.
If none of these two system properties are defined, this method does nothing.
Copyright © 2015–2017 AZYVA INC.. All rights reserved.