OPENDJ-2311 Option -V/--version don't work for SDK tools
Implemented "--version" for all sdk tools.
Here is an example output:
$ modrate --version
3.0.0.SNAPSHOT (revision 1bf0c1a7b33e936f1161dc9cd5c505fd341e52cc)
SdkVersionHandler.java: ADDED
Always read the version from opendj-core's MANIFEST.MF file
1 files added
13 files modified
| | |
| | | <opendj.osgi.import.additional> |
| | | com.sun.security.auth*;resolution:=optional |
| | | </opendj.osgi.import.additional> |
| | | <maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format> |
| | | </properties> |
| | | |
| | | |
| | |
| | | </executions> |
| | | </plugin> |
| | | |
| | | <plugin> |
| | | <groupId>org.codehaus.mojo</groupId> |
| | | <artifactId>buildnumber-maven-plugin</artifactId> |
| | | <version>1.4</version> |
| | | <executions> |
| | | <execution> |
| | | <phase>validate</phase> |
| | | <goals> |
| | | <goal>create</goal> |
| | | </goals> |
| | | </execution> |
| | | </executions> |
| | | </plugin> |
| | | |
| | | <!-- Creates opendj-core bundle --> |
| | | <plugin> |
| | | <groupId>org.apache.felix</groupId> |
| | |
| | | org.forgerock.opendj.ldap*, |
| | | org.forgerock.opendj.ldif |
| | | </Export-Package> |
| | | <Build-Maven>Apache Maven ${maven.version}</Build-Maven> |
| | | <SCM-Revision>${buildNumber}</SCM-Revision> |
| | | <SCM-Branch>${scmBranch}</SCM-Branch> |
| | | <Build-Time>${maven.build.timestamp}</Build-Time> |
| | | <Build-Java>${java.version}</Build-Java> |
| | | </instructions> |
| | | </configuration> |
| | | </plugin> |
| | |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.responses.Responses; |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | | import org.forgerock.opendj.ldif.EntryGenerator; |
| | |
| | | super(out, err); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isInteractive() { |
| | | return false; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isScriptFriendly() { |
| | | return scriptFriendly.isPresent(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isVerbose() { |
| | | return verbose.isPresent(); |
| | |
| | | final LocalizableMessage toolDescription = INFO_ADDRATE_TOOL_DESCRIPTION.get(); |
| | | final ArgumentParser argParser = |
| | | new ArgumentParser(AddRate.class.getName(), toolDescription, false, true, 1, 1, "template-file-path"); |
| | | argParser.setVersionHandler(new SdkVersionHandler()); |
| | | argParser.setShortToolDescription(REF_SHORT_DESC_ADDRATE.get()); |
| | | argParser.setDocToolDescriptionSupplement(SUPPLEMENT_DESCRIPTION_RATE_TOOLS.get()); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | private final class BindUpdateStatsResultHandler extends |
| | | UpdateStatsResultHandler<BindResult> { |
| | | private final class BindUpdateStatsResultHandler extends UpdateStatsResultHandler<BindResult> { |
| | | private BindUpdateStatsResultHandler(final long startTime) { |
| | | super(startTime); |
| | | } |
| | |
| | | private final char[] invalidPassword = "invalid-password".toCharArray(); |
| | | |
| | | private final ThreadLocal<Random> rng = new ThreadLocal<Random>() { |
| | | |
| | | @Override |
| | | protected Random initialValue() { |
| | | return new Random(); |
| | | } |
| | | |
| | | }; |
| | | |
| | | private BindWorkerThread(final Connection connection, |
| | | final ConnectionFactory connectionFactory) { |
| | | private BindWorkerThread(final Connection connection, final ConnectionFactory connectionFactory) { |
| | | super(connection, connectionFactory); |
| | | } |
| | | |
| | |
| | | * @param args |
| | | * The command-line arguments provided to this program. |
| | | */ |
| | | |
| | | public static void main(final String[] args) { |
| | | final int retCode = new AuthRate().run(args); |
| | | System.exit(filterExitCode(retCode)); |
| | |
| | | super(out, err); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isInteractive() { |
| | | return false; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isScriptFriendly() { |
| | | return scriptFriendly.isPresent(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isVerbose() { |
| | | return verbose.isPresent(); |
| | |
| | | final ArgumentParser argParser = |
| | | new ArgumentParser(AuthRate.class.getName(), toolDescription, false, true, 0, 0, |
| | | "[filter format string] [attributes ...]"); |
| | | argParser.setVersionHandler(new SdkVersionHandler()); |
| | | argParser.setShortToolDescription(REF_SHORT_DESC_AUTHRATE.get()); |
| | | argParser.setDocToolDescriptionSupplement(SUPPLEMENT_DESCRIPTION_RATE_TOOLS.get()); |
| | | |
| | |
| | | StringArgument propertiesFileArgument; |
| | | BooleanArgument noPropertiesFileArgument; |
| | | IntegerArgument invalidCredPercent; |
| | | |
| | | try { |
| | | setDefaultPerfToolProperties(); |
| | | PerformanceRunnerOptions options = new PerformanceRunnerOptions(argParser, this); |
| | |
| | | try { |
| | | argParser.parseArguments(args); |
| | | |
| | | /* If we should just display usage or version information, |
| | | then print it and exit.*/ |
| | | /* If we should just display usage or version information, then print it and exit. */ |
| | | if (argParser.usageOrVersionDisplayed()) { |
| | | return 0; |
| | | } |
| | |
| | | |
| | | final List<String> attributes = new LinkedList<>(); |
| | | final ArrayList<String> filterAndAttributeStrings = argParser.getTrailingArguments(); |
| | | if (filterAndAttributeStrings.size() > 0) { |
| | | if (!filterAndAttributeStrings.isEmpty()) { |
| | | /*The list of trailing arguments should be structured as follow: |
| | | the first trailing argument is considered the filter, the other |
| | | as attributes.*/ |
| | |
| | | } |
| | | |
| | | int run(final String[] args) { |
| | | // Create the command-line argument parser for use with this |
| | | // program. |
| | | // Create the command-line argument parser for use with this program. |
| | | final LocalizableMessage toolDescription = INFO_LDAPCOMPARE_TOOL_DESCRIPTION.get(); |
| | | final ArgumentParser argParser = |
| | | new ArgumentParser(LDAPCompare.class.getName(), toolDescription, false, true, 1, 0, |
| | | "attribute:value [DN ...]"); |
| | | final ArgumentParser argParser = new ArgumentParser( |
| | | LDAPCompare.class.getName(), toolDescription, false, true, 1, 0, "attribute:value [DN ...]"); |
| | | argParser.setVersionHandler(new SdkVersionHandler()); |
| | | argParser.setShortToolDescription(REF_SHORT_DESC_LDAPCOMPARE.get()); |
| | | |
| | | ConnectionFactoryProvider connectionFactoryProvider; |
| | | ConnectionFactory connectionFactory; |
| | | BindRequest bindRequest; |
| | |
| | | StringArgument proxyAuthzID; |
| | | StringArgument propertiesFileArgument; |
| | | BooleanArgument noPropertiesFileArgument; |
| | | |
| | | try { |
| | | connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this); |
| | | |
| | |
| | | if (r.getResultCode() != ResultCode.SUCCESS && r.getResultCode() != ResultCode.REFERRAL) { |
| | | final LocalizableMessage msg = INFO_OPERATION_FAILED.get(operationType); |
| | | errPrintln(msg); |
| | | errPrintln(ERR_TOOL_RESULT_CODE.get(r.getResultCode().intValue(), r.getResultCode() |
| | | .toString())); |
| | | errPrintln(ERR_TOOL_RESULT_CODE.get(r.getResultCode().intValue(), r.getResultCode())); |
| | | if (r.getDiagnosticMessage() != null && r.getDiagnosticMessage().length() > 0) { |
| | | errPrintln(LocalizableMessage.raw(r.getDiagnosticMessage())); |
| | | } |
| | |
| | | errPrintln(ERR_TOOL_MATCHED_DN.get(r.getMatchedDN())); |
| | | } |
| | | } else { |
| | | final LocalizableMessage msg = INFO_OPERATION_SUCCESSFUL.get(operationType, name); |
| | | println(msg); |
| | | println(INFO_OPERATION_SUCCESSFUL.get(operationType, name)); |
| | | if (r.getDiagnosticMessage() != null && r.getDiagnosticMessage().length() > 0) { |
| | | errPrintln(LocalizableMessage.raw(r.getDiagnosticMessage())); |
| | | } |
| | |
| | | * @param args |
| | | * The command-line arguments provided to this program. |
| | | */ |
| | | |
| | | public static void main(final String[] args) { |
| | | final int retCode = new LDAPModify().run(args); |
| | | System.exit(filterExitCode(retCode)); |
| | |
| | | final LocalizableMessage toolDescription = INFO_LDAPMODIFY_TOOL_DESCRIPTION.get(); |
| | | final ArgumentParser argParser = |
| | | new ArgumentParser(LDAPModify.class.getName(), toolDescription, false); |
| | | argParser.setVersionHandler(new SdkVersionHandler()); |
| | | argParser.setShortToolDescription(REF_SHORT_DESC_LDAPMODIFY.get()); |
| | | |
| | | ConnectionFactoryProvider connectionFactoryProvider; |
| | | ConnectionFactory connectionFactory; |
| | | BindRequest bindRequest; |
| | |
| | | } |
| | | |
| | | private int run(final String[] args) { |
| | | // Create the command-line argument parser for use with this |
| | | // program. |
| | | // Create the command-line argument parser for use with this program. |
| | | final LocalizableMessage toolDescription = INFO_LDAPPWMOD_TOOL_DESCRIPTION.get(); |
| | | final ArgumentParser argParser = |
| | | new ArgumentParser(LDAPPasswordModify.class.getName(), toolDescription, false); |
| | | argParser.setVersionHandler(new SdkVersionHandler()); |
| | | argParser.setShortToolDescription(REF_SHORT_DESC_LDAPPASSWORDMODIFY.get()); |
| | | |
| | | ConnectionFactoryProvider connectionFactoryProvider; |
| | | ConnectionFactory connectionFactory; |
| | | |
| | |
| | | final ArgumentParser argParser = |
| | | new ArgumentParser(LDAPSearch.class.getName(), toolDescription, false, true, 0, 0, |
| | | "[filter] [attributes ...]"); |
| | | argParser.setVersionHandler(new SdkVersionHandler()); |
| | | argParser.setShortToolDescription(REF_SHORT_DESC_LDAPSEARCH.get()); |
| | | |
| | | ConnectionFactoryProvider connectionFactoryProvider; |
| | | ConnectionFactory connectionFactory; |
| | | BindRequest bindRequest; |
| | |
| | | } |
| | | |
| | | private int run(final String[] args) { |
| | | // Create the command-line argument parser for use with this |
| | | // program. |
| | | |
| | | // Create the command-line argument parser for use with this program. |
| | | final LocalizableMessage toolDescription = INFO_LDIFDIFF_TOOL_DESCRIPTION.get(); |
| | | final ArgumentParser argParser = |
| | | new ArgumentParser(LDIFDiff.class.getName(), toolDescription, false, true, 2, 2, |
| | | "source target"); |
| | | final ArgumentParser argParser = new ArgumentParser( |
| | | LDIFDiff.class.getName(), toolDescription, false, true, 2, 2, "source target"); |
| | | argParser.setVersionHandler(new SdkVersionHandler()); |
| | | argParser.setShortToolDescription(REF_SHORT_DESC_LDIFDIFF.get()); |
| | | |
| | | final BooleanArgument showUsage; |
| | | final StringArgument outputFilename; |
| | | |
| | | try { |
| | | outputFilename = |
| | | new StringArgument("outputFilename", OPTION_SHORT_OUTPUT_LDIF_FILENAME, |
| | |
| | | try { |
| | | argParser.parseArguments(args); |
| | | |
| | | /* If we should just display usage or version information, |
| | | then print it and exit.*/ |
| | | /* If we should just display usage or version information, then print it and exit. */ |
| | | if (argParser.usageOrVersionDisplayed()) { |
| | | return ResultCode.SUCCESS.intValue(); |
| | | } |
| | |
| | | outputStream = System.out; |
| | | } |
| | | |
| | | /* Check that we are not attempting to read both the source and |
| | | target from stdin.*/ |
| | | /* Check that we are not attempting to read both the source and target from stdin. */ |
| | | if (sourceInputStream == targetInputStream) { |
| | | final LocalizableMessage message = ERR_LDIFDIFF_MULTIPLE_USES_OF_STDIN.get(); |
| | | errPrintln(message); |
| | |
| | | * to a set of entries contained in an LDIF file. |
| | | */ |
| | | public final class LDIFModify extends ConsoleApplication { |
| | | |
| | | /** |
| | | * The main method for LDIFModify tool. |
| | | * |
| | |
| | | } |
| | | |
| | | private int run(final String[] args) { |
| | | // Create the command-line argument parser for use with this |
| | | // program. |
| | | |
| | | // Create the command-line argument parser for use with this program. |
| | | final LocalizableMessage toolDescription = INFO_LDIFMODIFY_TOOL_DESCRIPTION.get(); |
| | | final ArgumentParser argParser = |
| | | new ArgumentParser(LDIFModify.class.getName(), toolDescription, false, true, 1, 2, |
| | | "source [changes]"); |
| | | final ArgumentParser argParser = new ArgumentParser( |
| | | LDIFModify.class.getName(), toolDescription, false, true, 1, 2, "source [changes]"); |
| | | argParser.setVersionHandler(new SdkVersionHandler()); |
| | | argParser.setShortToolDescription(REF_SHORT_DESC_LDIFMODIFY.get()); |
| | | |
| | | final BooleanArgument continueOnError; |
| | | final BooleanArgument showUsage; |
| | | final StringArgument outputFilename; |
| | | |
| | | try { |
| | | outputFilename = |
| | | new StringArgument("outputFilename", OPTION_SHORT_OUTPUT_LDIF_FILENAME, |
| | |
| | | outputStream = System.out; |
| | | } |
| | | |
| | | /* Check that we are not attempting to read both the source and |
| | | changes from stdin.*/ |
| | | /* Check that we are not attempting to read both the source and changes from stdin. */ |
| | | if (sourceInputStream == changesInputStream) { |
| | | final LocalizableMessage message = ERR_LDIFMODIFY_MULTIPLE_USES_OF_STDIN.get(); |
| | | errPrintln(message); |
| | |
| | | import com.forgerock.opendj.cli.MultiChoiceArgument; |
| | | import com.forgerock.opendj.cli.StringArgument; |
| | | |
| | | /** |
| | | * This utility can be used to perform search operations against data in an LDIF |
| | | * file. |
| | | */ |
| | | /** This utility can be used to perform search operations against data in an LDIF file. */ |
| | | public final class LDIFSearch extends ConsoleApplication { |
| | | |
| | | /** |
| | | * The main method for LDIFSearch tool. |
| | | * |
| | |
| | | } |
| | | |
| | | private int run(final String[] args) { |
| | | /* Create the command-line argument parser for use with this |
| | | program.*/ |
| | | |
| | | /* Create the command-line argument parser for use with this program. */ |
| | | final LocalizableMessage toolDescription = INFO_LDIFSEARCH_TOOL_DESCRIPTION.get(); |
| | | final ArgumentParser argParser = |
| | | new ArgumentParser(LDIFSearch.class.getName(), toolDescription, false, true, 1, 0, |
| | | "source [filter] [attributes ...]"); |
| | | final ArgumentParser argParser = new ArgumentParser( |
| | | LDIFSearch.class.getName(), toolDescription, false, true, 1, 0, "source [filter] [attributes ...]"); |
| | | argParser.setVersionHandler(new SdkVersionHandler()); |
| | | argParser.setShortToolDescription(REF_SHORT_DESC_LDIFSEARCH.get()); |
| | | |
| | | final BooleanArgument showUsage; |
| | |
| | | final StringArgument baseDN; |
| | | final MultiChoiceArgument<SearchScope> searchScope; |
| | | final IntegerArgument sizeLimit; |
| | | |
| | | try { |
| | | outputFilename = |
| | | new StringArgument("outputFilename", OPTION_SHORT_OUTPUT_LDIF_FILENAME, |
| | |
| | | try { |
| | | argParser.parseArguments(args); |
| | | |
| | | /* If we should just display usage or version information, |
| | | then print it and exit.*/ |
| | | /* If we should just display usage or version information, then print it and exit. */ |
| | | if (argParser.usageOrVersionDisplayed()) { |
| | | return ResultCode.SUCCESS.intValue(); |
| | | } |
| | |
| | | import org.forgerock.opendj.ldif.EntryGenerator; |
| | | import org.forgerock.opendj.ldif.LDIFEntryWriter; |
| | | |
| | | /** |
| | | * Program that generate LDIF content based on a template. |
| | | */ |
| | | /** Program that generate LDIF content based on a template. */ |
| | | public final class MakeLDIF extends ConsoleApplication { |
| | | |
| | | /** |
| | | * The value for the constant option in LDIF generator tools. |
| | | */ |
| | | /** The value for the constant option in LDIF generator tools. */ |
| | | public static final String OPTION_LONG_CONSTANT = "constant"; |
| | | |
| | | /** |
| | | * The value for the path to look for LDIF resources (e.g data files). |
| | | */ |
| | | /** The value for the path to look for LDIF resources (e.g data files). */ |
| | | public static final String OPTION_LONG_RESOURCE_PATH = "resourcePath"; |
| | | |
| | | private static final int EXIT_CODE_SUCCESS = 0; |
| | |
| | | final LocalizableMessage toolDescription = INFO_MAKELDIF_TOOL_DESCRIPTION.get(); |
| | | final ArgumentParser argParser = new ArgumentParser(MakeLDIF.class.getName(), toolDescription, |
| | | false, true, 1, 1, "template-file-path"); |
| | | argParser.setVersionHandler(new SdkVersionHandler()); |
| | | argParser.setShortToolDescription(REF_SHORT_DESC_MAKELDIF.get()); |
| | | argParser.setDocToolDescriptionSupplement(SUPPLEMENT_DESCRIPTION_MAKELDIF.get()); |
| | | |
| | |
| | | /** Run Make LDIF with provided arguments. */ |
| | | private int run(final String templatePath, final StringArgument resourcePath, |
| | | final StringArgument ldifFile, final IntegerArgument randomSeedArg, final StringArgument constants) { |
| | | EntryGenerator generator = null; |
| | | LDIFEntryWriter writer = null; |
| | | try { |
| | | generator = createGenerator(templatePath, resourcePath, randomSeedArg, constants); |
| | | try (EntryGenerator generator = createGenerator(templatePath, resourcePath, randomSeedArg, constants)) { |
| | | if (generator == null) { |
| | | return EXIT_CODE_FAILURE; |
| | | } |
| | |
| | | |
| | | errPrintln(INFO_MAKELDIF_PROCESSING_COMPLETE.get(numberOfEntriesWritten)); |
| | | |
| | | } finally { |
| | | closeSilently(generator, writer); |
| | | } |
| | | |
| | | return EXIT_CODE_SUCCESS; |
| | | } finally { |
| | | closeSilently(writer); |
| | | } |
| | | } |
| | | |
| | | static EntryGenerator createGenerator(final String templatePath, final StringArgument resourcePath, |
| | |
| | | return generator; |
| | | } |
| | | |
| | | /** |
| | | * Returns true if all constants are added to generator, false otherwise. |
| | | */ |
| | | /** Returns true if all constants are added to generator, false otherwise. */ |
| | | private static boolean addConstantsToGenerator(StringArgument constants, EntryGenerator generator, |
| | | final ConsoleApplication app) { |
| | | for (final String constant : constants.getValues()) { |
| | |
| | | return true; |
| | | } |
| | | |
| | | |
| | | private EntryGenerator createGenerator(final String templatePath, final StringArgument resourcePath, |
| | | final IntegerArgument randomSeedArg, final StringArgument constants) { |
| | | return createGenerator(templatePath, resourcePath, randomSeedArg, constants, true, this); |
| | | } |
| | | |
| | | /** |
| | | * Returns true if generation is successful, false otherwise. |
| | | */ |
| | | /** Returns true if generation is successful, false otherwise. */ |
| | | private boolean generateEntries(final EntryGenerator generator, final LDIFEntryWriter writer, |
| | | final StringArgument ldifFile) { |
| | | try { |
| | |
| | | MakeLDIF(PrintStream out, PrintStream err) { |
| | | super(out, err); |
| | | } |
| | | |
| | | } |
| | |
| | | * @param args |
| | | * The command-line arguments provided to this program. |
| | | */ |
| | | |
| | | public static void main(final String[] args) { |
| | | final int retCode = new ModRate().run(args); |
| | | System.exit(filterExitCode(retCode)); |
| | |
| | | // Nothing to do. |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isInteractive() { |
| | | return false; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isScriptFriendly() { |
| | | return scriptFriendly.isPresent(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isVerbose() { |
| | | return verbose.isPresent(); |
| | | } |
| | | |
| | | private int run(final String[] args) { |
| | | /* Creates the command-line argument parser for use with this |
| | | program*/ |
| | | // Creates the command-line argument parser for use with this program |
| | | final LocalizableMessage toolDescription = INFO_MODRATE_TOOL_DESCRIPTION.get(); |
| | | final ArgumentParser argParser = |
| | | new ArgumentParser(ModRate.class.getName(), toolDescription, false, true, 1, 0, |
| | | "[(attribute:value format string) ...]"); |
| | | argParser.setVersionHandler(new SdkVersionHandler()); |
| | | argParser.setShortToolDescription(REF_SHORT_DESC_MODRATE.get()); |
| | | argParser.setDocToolDescriptionSupplement(SUPPLEMENT_DESCRIPTION_RATE_TOOLS.get()); |
| | | |
| | | ConnectionFactoryProvider connectionFactoryProvider; |
| | | ConnectionFactory connectionFactory; |
| | | ModifyPerformanceRunner runner; |
| | |
| | | StringArgument propertiesFileArgument; |
| | | BooleanArgument noPropertiesFileArgument; |
| | | StringArgument baseDN; |
| | | |
| | | try { |
| | | Utils.setDefaultPerfToolProperties(); |
| | | |
| | |
| | | try { |
| | | argParser.parseArguments(args); |
| | | |
| | | /* If we should just display usage or version information, |
| | | then print it and exit.*/ |
| | | /* If we should just display usage or version information, then print it and exit. */ |
| | | if (argParser.usageOrVersionDisplayed()) { |
| | | return 0; |
| | | } |
| | |
| | | runner.baseDN = baseDN.getValue(); |
| | | |
| | | try { |
| | | |
| | | /* Try it out to make sure the format string and data sources |
| | | match.*/ |
| | | /* Try it out to make sure the format string and data sources match. */ |
| | | final Object[] data = DataSource.generateData(runner.getDataSources(), null); |
| | | for (final String modString : runner.modStrings) { |
| | | String.format(modString, data); |
| New file |
| | |
| | | /* |
| | | * CDDL HEADER START |
| | | * |
| | | * The contents of this file are subject to the terms of the |
| | | * Common Development and Distribution License, Version 1.0 only |
| | | * (the "License"). You may not use this file except in compliance |
| | | * with the License. |
| | | * |
| | | * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt |
| | | * or http://forgerock.org/license/CDDLv1.0.html. |
| | | * See the License for the specific language governing permissions |
| | | * and limitations under the License. |
| | | * |
| | | * When distributing Covered Code, include this CDDL HEADER in each |
| | | * file and include the License file at legal-notices/CDDLv1_0.txt. |
| | | * If applicable, add the following below this CDDL HEADER, with the |
| | | * fields enclosed by brackets "[]" replaced with your own identifying |
| | | * information: |
| | | * Portions Copyright [yyyy] [name of copyright owner] |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * Copyright 2015 ForgeRock AS |
| | | */ |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.URL; |
| | | import java.util.Enumeration; |
| | | import java.util.jar.Attributes; |
| | | import java.util.jar.Manifest; |
| | | |
| | | import com.forgerock.opendj.cli.VersionHandler; |
| | | |
| | | /** Class that prints the version of the SDK to System.out. */ |
| | | public class SdkVersionHandler implements VersionHandler { |
| | | |
| | | @Override |
| | | public void printVersion() { |
| | | System.out.println(getVersion()); |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return getClass().getSimpleName() + "(" + getVersion() + ")"; |
| | | } |
| | | |
| | | private String getVersion() { |
| | | try { |
| | | final Enumeration<URL> manifests = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF"); |
| | | while (manifests.hasMoreElements()) { |
| | | final URL manifestUrl = manifests.nextElement(); |
| | | if (manifestUrl.toString().contains("/opendj-core-")) { |
| | | try (InputStream manifestStream = manifestUrl.openStream()) { |
| | | final Attributes attrs = new Manifest(manifestStream).getMainAttributes(); |
| | | return attrs.getValue("Bundle-Version") + " (revision " + attrs.getValue("SCM-Revision") + ")"; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("IOException while determining SDK version", e); |
| | | } |
| | | } |
| | | } |
| | |
| | | // Nothing to do. |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isInteractive() { |
| | | return false; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isScriptFriendly() { |
| | | return scriptFriendly.isPresent(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isVerbose() { |
| | | return verbose.isPresent(); |
| | | } |
| | | |
| | | private int run(final String[] args) { |
| | | // Create the command-line argument parser for use with this |
| | | // program. |
| | | // Create the command-line argument parser for use with this program. |
| | | final LocalizableMessage toolDescription = INFO_SEARCHRATE_TOOL_DESCRIPTION.get(); |
| | | final ArgumentParser argParser = |
| | | new ArgumentParser(SearchRate.class.getName(), toolDescription, false, true, 1, 0, |
| | | "[filter format string] [attributes ...]"); |
| | | argParser.setVersionHandler(new SdkVersionHandler()); |
| | | argParser.setShortToolDescription(REF_SHORT_DESC_SEARCHRATE.get()); |
| | | argParser.setDocToolDescriptionSupplement(SUPPLEMENT_DESCRIPTION_RATE_TOOLS.get()); |
| | | |
| | |
| | | BooleanArgument showUsage; |
| | | StringArgument propertiesFileArgument; |
| | | BooleanArgument noPropertiesFileArgument; |
| | | |
| | | try { |
| | | Utils.setDefaultPerfToolProperties(); |
| | | |
| | |
| | | |
| | | final List<String> attributes = new LinkedList<>(); |
| | | final ArrayList<String> filterAndAttributeStrings = argParser.getTrailingArguments(); |
| | | if (filterAndAttributeStrings.size() > 0) { |
| | | if (!filterAndAttributeStrings.isEmpty()) { |
| | | /* The list of trailing arguments should be structured as follow: |
| | | the first trailing argument is considered the filter, the other as attributes.*/ |
| | | runner.filter = filterAndAttributeStrings.remove(0); |
| | |
| | | } |
| | | |
| | | try { |
| | | /* Try it out to make sure the format string and data sources |
| | | match.*/ |
| | | /* Try it out to make sure the format string and data sources match. */ |
| | | final Object[] data = DataSource.generateData(runner.getDataSources(), null); |
| | | String.format(runner.filter, data); |
| | | String.format(runner.baseDN, data); |