opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
@@ -74,6 +74,8 @@ public static final String DEFAULT_OPENDJ_PROPERTIES_FILE_EXTENSION = ".properties"; /** The name of a command-line script used to launch a tool. */ public static final String PROPERTY_SCRIPT_NAME = "com.forgerock.opendj.ldap.tools.scriptName"; /** The legacy name of a command-line script used to launch a tool. */ public static final String PROPERTY_SCRIPT_NAME_LEGACY = "org.opends.server.scriptName"; /** The argument that will be used to indicate the file properties. */ private StringArgument filePropertiesPathArgument; @@ -425,7 +427,7 @@ // We have a location for the properties file. final Properties argumentProperties = new Properties(); final String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME); final String scriptName = getScriptName(); try { final Properties p = new Properties(); final FileInputStream fis = new FileInputStream(propertiesFilePath); @@ -651,13 +653,8 @@ */ private void getUsage(final StringBuilder buffer) { usageOrVersionDisplayed = true; final String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME); if (scriptName == null || scriptName.length() == 0) { buffer.append(INFO_ARGPARSER_USAGE_JAVA_CLASSNAME.get(mainClassName)); } else { buffer.append(INFO_ARGPARSER_USAGE_JAVA_SCRIPTNAME.get(scriptName)); } buffer.append(getLocalizableScriptName()); if (allowsTrailingArguments) { buffer.append(" "); if (trailingArgsDisplayName != null) { @@ -741,6 +738,49 @@ } /** * Returns the script name or a Java equivalent command-line string. * * @return the script name or a Java equivalent command-line string */ String getScriptNameOrJava() { final String scriptName = getScriptName(); if (scriptName != null && scriptName.length() != 0) { return scriptName; } return "java " + getMainClassName(); } /** * Returns the script name as a {@link LocalizableMessage}. * * @return the script name as a {@link LocalizableMessage} */ LocalizableMessage getLocalizableScriptName() { final String scriptName = getScriptName(); if (scriptName == null || scriptName.length() == 0) { return INFO_ARGPARSER_USAGE_JAVA_CLASSNAME.get(mainClassName); } return INFO_ARGPARSER_USAGE_JAVA_SCRIPTNAME.get(scriptName); } /** * Returns the script name if set. * * @return the script name, or {@code null} if not set */ String getScriptName() { final String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME); if (scriptName != null && scriptName.length() != 0) { return scriptName; } final String legacyScriptName = System.getProperty(PROPERTY_SCRIPT_NAME_LEGACY); if (legacyScriptName != null && legacyScriptName.length() != 0) { return legacyScriptName; } return null; } /** * Returns the usage argument. * * @return the usageArgument opendj-cli/src/main/java/com/forgerock/opendj/cli/SubCommandArgumentParser.java
@@ -772,11 +772,8 @@ * The subcommand for which to display the usage information. */ public void getSubCommandUsage(StringBuilder buffer, SubCommand subCommand) { String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME); if (scriptName == null || scriptName.length() == 0) { scriptName = "java " + getMainClassName(); } buffer.append(INFO_ARGPARSER_USAGE_JAVA_SCRIPTNAME.get(scriptName)); final String scriptName = getScriptNameOrJava(); buffer.append(getLocalizableScriptName()); buffer.append(" "); buffer.append(scriptName); @@ -867,13 +864,9 @@ */ public LocalizableMessage getHelpUsageReference() { setUsageOrVersionDisplayed(true); String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME); if (scriptName == null || scriptName.length() == 0) { scriptName = "java " + getMainClassName(); } LocalizableMessageBuilder buffer = new LocalizableMessageBuilder(); buffer.append(INFO_GLOBAL_HELP_REFERENCE.get(scriptName)); buffer.append(INFO_GLOBAL_HELP_REFERENCE.get(getScriptNameOrJava())); buffer.append(EOL); return buffer.toMessage(); } @@ -919,13 +912,9 @@ buffer.append(EOL).append(EOL); } String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME); if (scriptName == null || scriptName.length() == 0) { scriptName = "java " + getMainClassName(); } buffer.append(INFO_ARGPARSER_USAGE.get()); buffer.append(" "); buffer.append(scriptName); buffer.append(getScriptNameOrJava()); if (subCommands.isEmpty()) { buffer.append(" ").append(INFO_SUBCMDPARSER_OPTIONS.get()); @@ -1175,10 +1164,14 @@ * @return Refsect2 representation of the subcommand. */ private String toRefSect2(SubCommand sc) { final String toolName = "dsconfig"; final String scriptName = getScriptName(); if (scriptName == null) { throw new RuntimeException("The script name should have been set via the environment property '" + PROPERTY_SCRIPT_NAME + "'."); } final StringBuilder sb = new StringBuilder(); sb.append("<refsect2 xml:id=\"").append(toolName).append("-").append(sc.getName()).append("\">").append(EOL); sb.append("<refsect2 xml:id=\"").append(scriptName).append("-").append(sc.getName()).append("\">").append(EOL); sb.append(" <title>dsconfig ").append(sc.getName()).append("</title>").append(EOL); sb.append(" <para>").append(sc.getDescription()).append("</para>").append(EOL); opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/DSConfig.java
@@ -167,7 +167,7 @@ new ArrayList<PropertyDefinition<?>>(defn.getAllPropertyDefinitions()); Collections.sort(props); final String propPrefix = DSCONFIGTOOLNAME + "-" + sc.getName() + "-" + argLongID + "-"; final String propPrefix = getScriptName() + "-" + sc.getName() + "-" + argLongID + "-"; sb.append(EOL); toSimpleList(props, propPrefix, sb); sb.append(EOL); @@ -1239,7 +1239,7 @@ * @return <T> The builded command. */ <T> CommandBuilder getCommandBuilder(final T subCommand) { final String commandName = getCommandName(); final String commandName = getScriptName(); final String subCommandName; if (subCommand instanceof SubCommandHandler) { subCommandName = ((SubCommandHandler) subCommand).getSubCommand().getName(); @@ -1272,7 +1272,7 @@ return commandBuilder; } private String getCommandName() { private String getScriptName() { final String commandName = System.getProperty(PROPERTY_SCRIPT_NAME); if (commandName != null && commandName.length() != 0) { return commandName; @@ -1338,7 +1338,7 @@ */ private String getSessionStartTimeMessage() { final String date = formatDateTimeStringForEquivalentCommand(new Date(sessionStartTime)); return INFO_DSCFG_SESSION_START_TIME_MESSAGE.get(getCommandName(), date).toString(); return INFO_DSCFG_SESSION_START_TIME_MESSAGE.get(getScriptName(), date).toString(); } private void handleBatchFile(String[] args) {