Remove geode-joptsimple. Change geode to use joptsimple. Detailed detection of extra or missing options and arguments is lost. The geode-joptsimple module enhanced joptsimple to provide details in exceptions when option is missing or unknown option is found (same for arguments).
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/7115ab79 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/7115ab79 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/7115ab79 Branch: refs/heads/feature/GEODE-835 Commit: 7115ab79e1ab40c404e8930965a722e6b5cd007d Parents: ce2ac68 Author: Kirk Lund <kl...@pivotal.io> Authored: Fri May 20 17:33:48 2016 -0700 Committer: Kirk Lund <kl...@pivotal.io> Committed: Fri May 20 17:33:48 2016 -0700 ---------------------------------------------------------------------- .../exceptions/CliCommandOptionException.java | 4 + .../cli/exceptions/ExceptionGenerator.java | 16 +- .../cli/parser/jopt/JoptOptionParser.java | 10 +- .../java/joptsimple/AbstractOptionSpec.java | 127 ----- .../joptsimple/AlternativeLongOptionSpec.java | 54 -- .../joptsimple/ArgumentAcceptingOptionSpec.java | 349 ------------ .../src/main/java/joptsimple/ArgumentList.java | 59 -- .../java/joptsimple/BuiltinHelpFormatter.java | 149 ----- .../src/main/java/joptsimple/HelpFormatter.java | 45 -- .../IllegalOptionSpecificationException.java | 52 -- .../MissingRequiredOptionException.java | 52 -- .../MultipleArgumentsForOptionException.java | 52 -- .../java/joptsimple/NoArgumentOptionSpec.java | 82 --- .../OptionArgumentConversionException.java | 63 -- .../main/java/joptsimple/OptionDescriptor.java | 94 --- .../main/java/joptsimple/OptionException.java | 111 ---- .../OptionMissingRequiredArgumentException.java | 52 -- .../src/main/java/joptsimple/OptionParser.java | 568 ------------------- .../main/java/joptsimple/OptionParserState.java | 81 --- .../src/main/java/joptsimple/OptionSet.java | 309 ---------- .../src/main/java/joptsimple/OptionSpec.java | 98 ---- .../main/java/joptsimple/OptionSpecBuilder.java | 96 ---- .../java/joptsimple/OptionSpecTokenizer.java | 127 ----- .../joptsimple/OptionalArgumentOptionSpec.java | 69 --- .../src/main/java/joptsimple/ParserRules.java | 84 --- .../joptsimple/RequiredArgumentOptionSpec.java | 54 -- .../joptsimple/UnrecognizedOptionException.java | 52 -- .../joptsimple/ValueConversionException.java | 54 -- .../main/java/joptsimple/ValueConverter.java | 58 -- .../joptsimple/internal/AbbreviationMap.java | 233 -------- .../main/java/joptsimple/internal/Classes.java | 74 --- .../main/java/joptsimple/internal/Column.java | 133 ----- .../internal/ColumnWidthCalculator.java | 41 -- .../java/joptsimple/internal/ColumnarData.java | 163 ------ .../ConstructorInvokingValueConverter.java | 58 -- .../internal/MethodInvokingValueConverter.java | 60 -- .../main/java/joptsimple/internal/Objects.java | 46 -- .../java/joptsimple/internal/Reflection.java | 143 ----- .../internal/ReflectionException.java | 39 -- .../main/java/joptsimple/internal/Strings.java | 117 ---- .../java/joptsimple/util/DateConverter.java | 104 ---- .../main/java/joptsimple/util/KeyValuePair.java | 83 --- .../main/java/joptsimple/util/RegexMatcher.java | 88 --- 43 files changed, 16 insertions(+), 4387 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionException.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionException.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionException.java index 3fdec10..9a2cee8 100644 --- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionException.java +++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionException.java @@ -36,6 +36,10 @@ public class CliCommandOptionException extends CliCommandException { this(commandTarget, option, null, cause); } + public CliCommandOptionException(final Throwable cause) { + this(null, null, null, cause); + } + public CliCommandOptionException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet, final Throwable cause) { super(commandTarget, optionSet, cause); this.setOption(option); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/ExceptionGenerator.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/ExceptionGenerator.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/ExceptionGenerator.java index 61af7a4..2b329f1 100644 --- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/ExceptionGenerator.java +++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/ExceptionGenerator.java @@ -16,34 +16,32 @@ */ package com.gemstone.gemfire.management.internal.cli.exceptions; -import joptsimple.MissingRequiredOptionException; -import joptsimple.MultipleArgumentsForOptionException; import joptsimple.OptionException; -import joptsimple.OptionMissingRequiredArgumentException; -import joptsimple.UnrecognizedOptionException; import com.gemstone.gemfire.management.internal.cli.parser.Option; /** * Converts joptsimple exceptions into corresponding exceptions for cli + * + * TODO: delete this class */ public class ExceptionGenerator { public static CliCommandOptionException generate(Option option, OptionException e) { - if (MissingRequiredOptionException.class.isInstance(e)) { + if (e.getClass().getSimpleName().contains("MissingRequiredOptionException")) { return new CliCommandOptionMissingException(e); - } else if (OptionMissingRequiredArgumentException.class.isInstance(e)) { + } else if (e.getClass().getSimpleName().contains("OptionMissingRequiredArgumentException")) { return new CliCommandOptionValueMissingException(e); - } else if (UnrecognizedOptionException.class.isInstance(e)) { + } else if (e.getClass().getSimpleName().contains("UnrecognizedOptionException")) { return new CliCommandOptionNotApplicableException(e); - } else if (MultipleArgumentsForOptionException.class.isInstance(e)) { + } else if (e.getClass().getSimpleName().contains("MultipleArgumentsForOptionException")) { return new CliCommandOptionHasMultipleValuesException(e); } else { - return null; + return new CliCommandOptionException(e); } } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/jopt/JoptOptionParser.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/jopt/JoptOptionParser.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/jopt/JoptOptionParser.java index 4ea9516..8c15173 100644 --- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/jopt/JoptOptionParser.java +++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/jopt/JoptOptionParser.java @@ -22,7 +22,6 @@ import java.util.LinkedList; import java.util.List; import joptsimple.ArgumentAcceptingOptionSpec; -import joptsimple.MultipleArgumentsForOptionException; import joptsimple.OptionException; import joptsimple.OptionParser; import joptsimple.OptionSpecBuilder; @@ -123,21 +122,22 @@ public class JoptOptionParser implements GfshOptionParser { joptOptionSet = parser.parse(preProcessedInput); } catch (OptionException e) { ce = processException(e); - joptOptionSet = e.getDetected(); + // KIRK: joptOptionSet = e.getDetected(); } if (joptOptionSet != null) { // Make sure there are no miscellaneous, unknown strings that cannot be identified as // either options or arguments. if (joptOptionSet.nonOptionArguments().size() > arguments.size()) { - String unknownString = joptOptionSet.nonOptionArguments().get(arguments.size()); + // KIRK: String unknownString = joptOptionSet.nonOptionArguments().get(arguments.size()); + String unknownString = (String)joptOptionSet.nonOptionArguments().get(arguments.size()); // If the first option is un-parseable then it will be returned as "<option>=<value>" since it's // been interpreted as an argument. However, all subsequent options will be returned as "<option>". // This hack splits off the string before the "=" sign if it's the first case. if (unknownString.matches("^-*\\w+=.*$")) { unknownString = unknownString.substring(0, unknownString.indexOf('=')); } - ce = processException(OptionException.createUnrecognizedOptionException(unknownString, joptOptionSet)); + // KIRK: ce = processException(OptionException.createUnrecognizedOptionException(unknownString, joptOptionSet)); } // First process the arguments @@ -199,7 +199,7 @@ public class JoptOptionParser implements GfshOptionParser { if (arguments.size() > 1 && !(option.getConverter() instanceof MultipleValueConverter) && option.getValueSeparator() == null) { List<String> optionList = new ArrayList<String>(1); optionList.add(string); - ce = processException(new MultipleArgumentsForOptionException(optionList, joptOptionSet)); + // KIRK: ce = processException(new MultipleArgumentsForOptionException(optionList, joptOptionSet)); } else if ((arguments.size() == 1 && !(option.getConverter() instanceof MultipleValueConverter)) || option.getValueSeparator() == null) { optionSet.put(option, arguments.get(0).toString().trim()); } else { http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/AbstractOptionSpec.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/AbstractOptionSpec.java b/geode-joptsimple/src/main/java/joptsimple/AbstractOptionSpec.java deleted file mode 100644 index e365d4c..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/AbstractOptionSpec.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import static java.util.Collections.*; - -import static joptsimple.internal.Strings.*; - - -/** - * @param <V> represents the type of the arguments this option accepts - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -abstract class AbstractOptionSpec<V> implements OptionSpec<V>, OptionDescriptor { - private final List<String> options = new ArrayList<String>(); - private final String description; - private boolean forHelp; - - protected AbstractOptionSpec( String option ) { - this( singletonList( option ), EMPTY ); - } - - protected AbstractOptionSpec( Collection<String> options, String description ) { - arrangeOptions( options ); - - this.description = description; - } - - public final Collection<String> options() { - return unmodifiableCollection( options ); - } - - public final List<V> values( OptionSet detectedOptions ) { - return detectedOptions.valuesOf( this ); - } - - public final V value( OptionSet detectedOptions ) { - return detectedOptions.valueOf( this ); - } - - public String description() { - return description; - } - - public final AbstractOptionSpec<V> forHelp() { - forHelp = true; - return this; - } - - public final boolean isForHelp() { - return forHelp; - } - - protected abstract V convert( String argument ); - - abstract void handleOption( OptionParser parser, ArgumentList arguments, OptionSet detectedOptions, - String detectedArgument ); - - private void arrangeOptions( Collection<String> unarranged ) { - if ( unarranged.size() == 1 ) { - options.addAll( unarranged ); - return; - } - - List<String> shortOptions = new ArrayList<String>(); - List<String> longOptions = new ArrayList<String>(); - - for ( String each : unarranged ) { - if ( each.length() == 1 ) - shortOptions.add( each ); - else - longOptions.add( each ); - } - - sort( shortOptions ); - sort( longOptions ); - - options.addAll( shortOptions ); - options.addAll( longOptions ); - } - - @Override - public boolean equals( Object that ) { - if ( !( that instanceof AbstractOptionSpec<?> ) ) - return false; - - AbstractOptionSpec<?> other = (AbstractOptionSpec<?>) that; - return options.equals( other.options ); - } - - @Override - public int hashCode() { - return options.hashCode(); - } - - @Override - public String toString() { - return options.toString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/AlternativeLongOptionSpec.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/AlternativeLongOptionSpec.java b/geode-joptsimple/src/main/java/joptsimple/AlternativeLongOptionSpec.java deleted file mode 100644 index 21d2502..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/AlternativeLongOptionSpec.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import static java.util.Collections.*; - -import static joptsimple.ParserRules.*; - - -/** - * Represents the <kbd>"-W"</kbd> form of long option specification. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - * @author Nikhil Jadhav - */ -class AlternativeLongOptionSpec extends ArgumentAcceptingOptionSpec<String> { - AlternativeLongOptionSpec() { - super( singletonList( RESERVED_FOR_EXTENSIONS ), true, "Alternative form of long options" ); - - describedAs( "opt=value" ); - } - - @Override - protected void detectOptionArgument( OptionParser parser, ArgumentList arguments, OptionSet detectedOptions ) { - if ( !arguments.hasMore() ) - // GemFire Addition: Changed to include OptionSet - throw new OptionMissingRequiredArgumentException( options(), detectedOptions ); - - arguments.treatNextAsLongOption(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/ArgumentAcceptingOptionSpec.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/ArgumentAcceptingOptionSpec.java b/geode-joptsimple/src/main/java/joptsimple/ArgumentAcceptingOptionSpec.java deleted file mode 100644 index deea27f..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/ArgumentAcceptingOptionSpec.java +++ /dev/null @@ -1,349 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.StringTokenizer; - -import joptsimple.internal.ReflectionException; - -import static java.util.Collections.*; - -import static joptsimple.internal.Objects.*; -import static joptsimple.internal.Reflection.*; -import static joptsimple.internal.Strings.*; - - - -/** - * <p>Specification of an option that accepts an argument.</p> - * - * <p>Instances are returned from {@link OptionSpecBuilder} methods to allow the formation of parser directives as - * sentences in a "fluent interface" language. For example:</p> - * - * <pre> - * <code> - * OptionParser parser = new OptionParser(); - * parser.accepts( "c" ).withRequiredArg().<strong>ofType( Integer.class )</strong>; - * </code> - * </pre> - * - * <p>If no methods are invoked on an instance of this class, then that instance's option will treat its argument as - * a {@link String}.</p> - * - * @param <V> represents the type of the arguments this option accepts - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public abstract class ArgumentAcceptingOptionSpec<V> extends AbstractOptionSpec<V> { - private static final char NIL_VALUE_SEPARATOR = '\u0000'; - - private boolean optionRequired; - private final boolean argumentRequired; - private ValueConverter<V> converter; - private String argumentDescription = ""; - private String valueSeparator = String.valueOf( NIL_VALUE_SEPARATOR ); - private final List<V> defaultValues = new ArrayList<V>(); - - ArgumentAcceptingOptionSpec( String option, boolean argumentRequired ) { - super( option ); - - this.argumentRequired = argumentRequired; - } - - ArgumentAcceptingOptionSpec( Collection<String> options, boolean argumentRequired, String description ) { - super( options, description ); - - this.argumentRequired = argumentRequired; - } - - /** - * <p>Specifies a type to which arguments of this spec's option are to be converted.</p> - * - * <p>JOpt Simple accepts types that have either:</p> - * - * <ol> - * <li>a public static method called {@code valueOf} which accepts a single argument of type {@link String} - * and whose return type is the same as the class on which the method is declared. The {@code java.lang} - * primitive wrapper classes have such methods.</li> - * - * <li>a public constructor which accepts a single argument of type {@link String}.</li> - * </ol> - * - * <p>This class converts arguments using those methods in that order; that is, {@code valueOf} would be invoked - * before a one-{@link String}-arg constructor would.</p> - * - * <p>Invoking this method will trump any previous calls to this method or to - * {@link #withValuesConvertedBy(ValueConverter)}. - * - * @param <T> represents the runtime class of the desired option argument type - * @param argumentType desired type of arguments to this spec's option - * @return self, so that the caller can add clauses to the fluent interface sentence - * @throws NullPointerException if the type is {@code null} - * @throws IllegalArgumentException if the type does not have the standard conversion methods - */ - public final <T> ArgumentAcceptingOptionSpec<T> ofType( Class<T> argumentType ) { - return withValuesConvertedBy( findConverter( argumentType ) ); - } - - /** - * <p>Specifies a converter to use to translate arguments of this spec's option into Java objects. This is useful - * when converting to types that do not have the requisite factory method or constructor for - * {@link #ofType(Class)}.</p> - * - * <p>Invoking this method will trump any previous calls to this method or to {@link #ofType(Class)}. - * - * @param <T> represents the runtime class of the desired option argument type - * @param aConverter the converter to use - * @return self, so that the caller can add clauses to the fluent interface sentence - * @throws NullPointerException if the converter is {@code null} - */ - @SuppressWarnings( "unchecked" ) - public final <T> ArgumentAcceptingOptionSpec<T> withValuesConvertedBy( ValueConverter<T> aConverter ) { - if ( aConverter == null ) - throw new NullPointerException( "illegal null converter" ); - - converter = (ValueConverter<V>) aConverter; - return (ArgumentAcceptingOptionSpec<T>) this; - } - - /** - * <p>Specifies a description for the argument of the option that this spec represents. This description is used - * when generating help information about the parser.</p> - * - * @param description describes the nature of the argument of this spec's option - * @return self, so that the caller can add clauses to the fluent interface sentence - */ - public final ArgumentAcceptingOptionSpec<V> describedAs( String description ) { - argumentDescription = description; - return this; - } - - /** - * <p>Specifies a value separator for the argument of the option that this spec represents. This allows a single - * option argument to represent multiple values for the option. For example:</p> - * - * <pre> - * <code> - * parser.accepts( "z" ).withRequiredArg() - * .<strong>withValuesSeparatedBy( ',' )</strong>; - * OptionSet options = parser.parse( new String[] { "-z", "foo,bar,baz", "-z", - * "fizz", "-z", "buzz" } ); - * </code> - * </pre> - * - * <p>Then {@code options.valuesOf( "z" )} would yield the list {@code [foo, bar, baz, fizz, buzz]}.</p> - * - * <p>You cannot use Unicode U+0000 as the separator.</p> - * - * @param separator a character separator - * @return self, so that the caller can add clauses to the fluent interface sentence - * @throws IllegalArgumentException if the separator is Unicode U+0000 - */ - public final ArgumentAcceptingOptionSpec<V> withValuesSeparatedBy( char separator ) { - if ( separator == NIL_VALUE_SEPARATOR ) - throw new IllegalArgumentException( "cannot use U+0000 as separator" ); - - valueSeparator = String.valueOf( separator ); - return this; - } - - /** - * <p>Specifies a value separator for the argument of the option that this spec represents. This allows a single - * option argument to represent multiple values for the option. For example:</p> - * - * <pre> - * <code> - * parser.accepts( "z" ).withRequiredArg() - * .<strong>withValuesSeparatedBy( ":::" )</strong>; - * OptionSet options = parser.parse( new String[] { "-z", "foo:::bar:::baz", "-z", - * "fizz", "-z", "buzz" } ); - * </code> - * </pre> - * - * <p>Then {@code options.valuesOf( "z" )} would yield the list {@code [foo, bar, baz, fizz, buzz]}.</p> - * - * <p>You cannot use Unicode U+0000 in the separator.</p> - * - * @param separator a string separator - * @return self, so that the caller can add clauses to the fluent interface sentence - * @throws IllegalArgumentException if the separator contains Unicode U+0000 - */ - public final ArgumentAcceptingOptionSpec<V> withValuesSeparatedBy( String separator ) { - if ( separator.indexOf( NIL_VALUE_SEPARATOR ) != -1 ) - throw new IllegalArgumentException( "cannot use U+0000 in separator" ); - - valueSeparator = separator; - return this; - } - - /** - * Specifies a set of default values for the argument of the option that this spec represents. - * - * @param value the first in the set of default argument values for this spec's option - * @param values the (optional) remainder of the set of default argument values for this spec's option - * @return self, so that the caller can add clauses to the fluent interface sentence - * @throws NullPointerException if {@code value}, {@code values}, or any elements of {@code values} are - * {@code null} - */ - public ArgumentAcceptingOptionSpec<V> defaultsTo( V value, V... values ) { - addDefaultValue( value ); - defaultsTo( values ); - - return this; - } - - /** - * Specifies a set of default values for the argument of the option that this spec represents. - * - * @param values the set of default argument values for this spec's option - * @return self, so that the caller can add clauses to the fluent interface sentence - * @throws NullPointerException if {@code values} or any elements of {@code values} are {@code null} - */ - public ArgumentAcceptingOptionSpec<V> defaultsTo( V[] values ) { - for ( V each : values ) - addDefaultValue( each ); - - return this; - } - - /** - * Marks this option as required. An {@link OptionException} will be thrown when - * {@link OptionParser#parse(java.lang.String...)} is called, if an option is marked as required and not specified - * on the command line. - * - * @return self, so that the caller can add clauses to the fluent interface sentence - */ - public ArgumentAcceptingOptionSpec<V> required() { - optionRequired = true; - return this; - } - - public boolean isRequired() { - return optionRequired; - } - - private void addDefaultValue( V value ) { - ensureNotNull( value ); - defaultValues.add( value ); - } - - @Override - final void handleOption( OptionParser parser, ArgumentList arguments, OptionSet detectedOptions, - String detectedArgument ) { - - if ( isNullOrEmpty( detectedArgument ) ) - detectOptionArgument( parser, arguments, detectedOptions ); - else - addArguments( detectedOptions, detectedArgument ); - } - - protected void addArguments( OptionSet detectedOptions, String detectedArgument ) { - StringTokenizer lexer = new StringTokenizer( detectedArgument, valueSeparator ); - if ( !lexer.hasMoreTokens() ) - detectedOptions.addWithArgument( this, detectedArgument ); - else { - while ( lexer.hasMoreTokens() ) - detectedOptions.addWithArgument( this, lexer.nextToken() ); - } - } - - protected abstract void detectOptionArgument( OptionParser parser, ArgumentList arguments, - OptionSet detectedOptions ); - - @SuppressWarnings( "unchecked" ) - @Override - protected final V convert( String argument ) { - if ( converter == null ) - return (V) argument; - - try { - return converter.convert( argument ); - } - catch ( ReflectionException ex ) { - throw new OptionArgumentConversionException( options(), argument, converter.valueType(), ex ); - } - catch ( ValueConversionException ex ) { - throw new OptionArgumentConversionException( options(), argument, converter.valueType(), ex ); - } - } - - protected boolean canConvertArgument( String argument ) { - StringTokenizer lexer = new StringTokenizer( argument, valueSeparator ); - - try { - while ( lexer.hasMoreTokens() ) - convert( lexer.nextToken() ); - return true; - } - catch ( OptionException ignored ) { - return false; - } - } - - protected boolean isArgumentOfNumberType() { - return converter != null && Number.class.isAssignableFrom( converter.valueType() ); - } - - public boolean acceptsArguments() { - return true; - } - - public boolean requiresArgument() { - return argumentRequired; - } - - public String argumentDescription() { - return argumentDescription; - } - - public String argumentTypeIndicator() { - if ( converter == null ) - return null; - - String pattern = converter.valuePattern(); - return pattern == null ? converter.valueType().getName() : pattern; - } - - public List<V> defaultValues() { - return unmodifiableList( defaultValues ); - } - - @Override - public boolean equals( Object that ) { - if ( !super.equals( that ) ) - return false; - - ArgumentAcceptingOptionSpec<?> other = (ArgumentAcceptingOptionSpec<?>) that; - return requiresArgument() == other.requiresArgument(); - } - - @Override - public int hashCode() { - return super.hashCode() ^ ( argumentRequired ? 0 : 1 ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/ArgumentList.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/ArgumentList.java b/geode-joptsimple/src/main/java/joptsimple/ArgumentList.java deleted file mode 100644 index 3e7c547..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/ArgumentList.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import static joptsimple.ParserRules.*; - -/** - * <p>Wrapper for an array of command line arguments.</p> - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -class ArgumentList { - private final String[] arguments; - private int currentIndex; - - ArgumentList( String... arguments ) { - this.arguments = arguments.clone(); - } - - boolean hasMore() { - return currentIndex < arguments.length; - } - - String next() { - return arguments[ currentIndex++ ]; - } - - String peek() { - return arguments[ currentIndex ]; - } - - void treatNextAsLongOption() { - if ( HYPHEN_CHAR != arguments[ currentIndex ].charAt( 0 ) ) - arguments[ currentIndex ] = DOUBLE_HYPHEN + arguments[ currentIndex ]; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/BuiltinHelpFormatter.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/BuiltinHelpFormatter.java b/geode-joptsimple/src/main/java/joptsimple/BuiltinHelpFormatter.java deleted file mode 100644 index 134d6e0..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/BuiltinHelpFormatter.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; - -import joptsimple.internal.ColumnarData; - -import static joptsimple.ParserRules.*; -import static joptsimple.internal.Classes.*; -import static joptsimple.internal.Strings.*; - - - -/** - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -class BuiltinHelpFormatter implements HelpFormatter { - private ColumnarData grid; - - public String format( Map<String, ? extends OptionDescriptor> options ) { - if ( options.isEmpty() ) - return "No options specified"; - - grid = new ColumnarData( optionHeader( options ), "Description" ); - - Comparator<OptionDescriptor> comparator = - new Comparator<OptionDescriptor>() { - public int compare( OptionDescriptor first, OptionDescriptor second ) { - return first.options().iterator().next().compareTo( second.options().iterator().next() ); - } - }; - - Set<OptionDescriptor> sorted = new TreeSet<OptionDescriptor>( comparator ); - sorted.addAll( options.values() ); - - for ( OptionDescriptor each : sorted ) - addHelpLineFor( each ); - - return grid.format(); - } - - private String optionHeader( Map<String, ? extends OptionDescriptor> options ) { - for ( OptionDescriptor each : options.values() ) { - if ( each.isRequired() ) - return "Option (* = required)"; - } - - return "Option"; - } - - private void addHelpLineFor( OptionDescriptor descriptor ) { - if ( descriptor.acceptsArguments() ) { - if ( descriptor.requiresArgument() ) - addHelpLineWithArgument( descriptor, '<', '>' ); - else - addHelpLineWithArgument( descriptor, '[', ']' ); - } else { - addHelpLineFor( descriptor, "" ); - } - } - - void addHelpLineFor( OptionDescriptor descriptor, String additionalInfo ) { - grid.addRow( createOptionDisplay( descriptor ) + additionalInfo, createDescriptionDisplay( descriptor ) ); - } - - private void addHelpLineWithArgument( OptionDescriptor descriptor, char begin, char end ) { - String argDescription = descriptor.argumentDescription(); - String typeIndicator = typeIndicator( descriptor ); - StringBuilder collector = new StringBuilder(); - - if ( typeIndicator.length() > 0 ) { - collector.append( typeIndicator ); - - if ( argDescription.length() > 0 ) - collector.append( ": " ).append( argDescription ); - } - else if ( argDescription.length() > 0 ) - collector.append( argDescription ); - - String helpLine = collector.length() == 0 - ? "" - : ' ' + surround( collector.toString(), begin, end ); - addHelpLineFor( descriptor, helpLine ); - } - - private String createOptionDisplay( OptionDescriptor descriptor ) { - StringBuilder buffer = new StringBuilder( descriptor.isRequired() ? "* " : "" ); - - for ( Iterator<String> iter = descriptor.options().iterator(); iter.hasNext(); ) { - String option = iter.next(); - buffer.append( option.length() > 1 ? DOUBLE_HYPHEN : HYPHEN ); - buffer.append( option ); - - if ( iter.hasNext() ) - buffer.append( ", " ); - } - - return buffer.toString(); - } - - private String createDescriptionDisplay( OptionDescriptor descriptor ) { - List<?> defaultValues = descriptor.defaultValues(); - if ( defaultValues.isEmpty() ) - return descriptor.description(); - - String defaultValuesDisplay = createDefaultValuesDisplay( defaultValues ); - return descriptor.description() + ' ' + surround( "default: " + defaultValuesDisplay, '(', ')' ); - } - - private String createDefaultValuesDisplay( List<?> defaultValues ) { - return defaultValues.size() == 1 ? defaultValues.get( 0 ).toString() : defaultValues.toString(); - } - - private static String typeIndicator( OptionDescriptor descriptor ) { - String indicator = descriptor.argumentTypeIndicator(); - return indicator == null || String.class.getName().equals( indicator ) - ? "" - : shortNameOf( indicator ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/HelpFormatter.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/HelpFormatter.java b/geode-joptsimple/src/main/java/joptsimple/HelpFormatter.java deleted file mode 100644 index e685ddc..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/HelpFormatter.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.Map; - -/** - * <p>Represents objects charged with taking a set of option descriptions and producing some help text from them.</p> - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public interface HelpFormatter { - /** - * Produces help text, given a set of option descriptors. - * - * @param options descriptors for the configured options of a parser - * @return text to be used as help - * @see OptionParser#printHelpOn(java.io.Writer) - * @see OptionParser#formatHelpWith(HelpFormatter) - */ - String format( Map<String, ? extends OptionDescriptor> options ); -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/IllegalOptionSpecificationException.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/IllegalOptionSpecificationException.java b/geode-joptsimple/src/main/java/joptsimple/IllegalOptionSpecificationException.java deleted file mode 100644 index 2568e25..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/IllegalOptionSpecificationException.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import static java.util.Collections.*; - -/** - * Thrown when the option parser is asked to recognize an option with illegal characters in it. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - * @author Nikhil Jadhav - */ -public class IllegalOptionSpecificationException extends OptionException { - private static final long serialVersionUID = -1L; - - IllegalOptionSpecificationException( String option ) { - super( singletonList( option ) ); - } - - // GemFire Addition: Added to include OptionSet - IllegalOptionSpecificationException( String option, OptionSet detected ) { - super( singletonList( option ), detected ); - } - - @Override - public String getMessage() { - return singleOptionMessage() + " is not a legal option character"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/MissingRequiredOptionException.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/MissingRequiredOptionException.java b/geode-joptsimple/src/main/java/joptsimple/MissingRequiredOptionException.java deleted file mode 100644 index eb3cc04..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/MissingRequiredOptionException.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.Collection; - -/** - * Thrown when an option is marked as required, but not specified on the command line. - * - * @author <a href="https://github.com/TC1">Emils Solmanis</a> - * @author Nikhil Jadhav - */ -public class MissingRequiredOptionException extends OptionException { - private static final long serialVersionUID = -1L; - - protected MissingRequiredOptionException( Collection<String> options ) { - super( options ); - } - - // GemFire Addition: Added to include OptionSet - MissingRequiredOptionException( Collection<String> options, OptionSet detected ) { - super( options, detected ); - } - - @Override - public String getMessage() { - return "Missing required option " + multipleOptionMessage(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/MultipleArgumentsForOptionException.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/MultipleArgumentsForOptionException.java b/geode-joptsimple/src/main/java/joptsimple/MultipleArgumentsForOptionException.java deleted file mode 100644 index 0aae386..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/MultipleArgumentsForOptionException.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.Collection; - -/** - * Thrown when asking an {@link OptionSet} for a single argument of an option when many have been specified. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - * @author Nikhil Jadhav - */ -public class MultipleArgumentsForOptionException extends OptionException { - private static final long serialVersionUID = -1L; - - MultipleArgumentsForOptionException( Collection<String> options ) { - super( options ); - } - - // GemFire Addition: Added to include OptionSet - public MultipleArgumentsForOptionException( Collection<String> options, OptionSet detected ) { - super( options, detected ); - } - - @Override - public String getMessage() { - return "Found multiple arguments for option " + multipleOptionMessage() + ", but you asked for only one"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/NoArgumentOptionSpec.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/NoArgumentOptionSpec.java b/geode-joptsimple/src/main/java/joptsimple/NoArgumentOptionSpec.java deleted file mode 100644 index 0d443e5..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/NoArgumentOptionSpec.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.Collection; -import java.util.List; - -import static java.util.Collections.*; - -/** - * A specification for an option that does not accept arguments. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -class NoArgumentOptionSpec extends AbstractOptionSpec<Void> { - NoArgumentOptionSpec( String option ) { - this( singletonList( option ), "" ); - } - - NoArgumentOptionSpec( Collection<String> options, String description ) { - super( options, description ); - } - - @Override - void handleOption( OptionParser parser, ArgumentList arguments, OptionSet detectedOptions, - String detectedArgument ) { - - detectedOptions.add( this ); - } - - public boolean acceptsArguments() { - return false; - } - - public boolean requiresArgument() { - return false; - } - - public boolean isRequired() { - return false; - } - - public String argumentDescription() { - return ""; - } - - public String argumentTypeIndicator() { - return ""; - } - - @Override - protected Void convert( String argument ) { - return null; - } - - public List<Void> defaultValues() { - return emptyList(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/OptionArgumentConversionException.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/OptionArgumentConversionException.java b/geode-joptsimple/src/main/java/joptsimple/OptionArgumentConversionException.java deleted file mode 100644 index bcc6dcd..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/OptionArgumentConversionException.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.Collection; - -/** - * Thrown when a problem occurs converting an argument of an option from {@link String} to another type. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - * @author Nikhil Jadhav - */ -public class OptionArgumentConversionException extends OptionException { - private static final long serialVersionUID = -1L; - - private final String argument; - private final Class<?> valueType; - - OptionArgumentConversionException( Collection<String> options, String argument, Class<?> valueType, - Throwable cause ) { - - super( options, cause ); - - this.argument = argument; - this.valueType = valueType; - } - - // GemFire Addition: Added to include OptionSet - public OptionArgumentConversionException( Collection<String> options, String argument, Class<?> valueType, - OptionSet detected, Throwable cause ) { - super( options, detected ); - this.argument = argument; - this.valueType = valueType; - } - - @Override - public String getMessage() { - return "Cannot convert argument '" + argument + "' of option " + multipleOptionMessage() + " to " + valueType; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/OptionDescriptor.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/OptionDescriptor.java b/geode-joptsimple/src/main/java/joptsimple/OptionDescriptor.java deleted file mode 100644 index 98a39b1..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/OptionDescriptor.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.Collection; -import java.util.List; - -/** - * Describes options that an option parser recognizes, in ways that might be useful to {@linkplain HelpFormatter - * help screens}. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public interface OptionDescriptor { - /** - * A set of options that are mutually synonymous. - * - * @return synonymous options - */ - Collection<String> options(); - - /** - * Description of this option's purpose. - * - * @return a description for the option - */ - String description(); - - /** - * What values will the option take if none are specified on the command line? - * - * @return any default values for the option - */ - List<?> defaultValues(); - - /** - * Is this option {@linkplain ArgumentAcceptingOptionSpec#required() required} on a command line? - * - * @return whether the option is required - */ - boolean isRequired(); - - /** - * Does this option {@linkplain ArgumentAcceptingOptionSpec accept arguments}? - * - * @return whether the option accepts arguments - */ - boolean acceptsArguments(); - - /** - * Does this option {@linkplain OptionSpecBuilder#withRequiredArg() require an argument}? - * - * @return whether the option requires an argument - */ - boolean requiresArgument(); - - /** - * Gives a short {@linkplain ArgumentAcceptingOptionSpec#describedAs(String) description} of the option's argument. - * - * @return a description for the option's argument - */ - String argumentDescription(); - - /** - * Gives an indication of the {@linkplain ArgumentAcceptingOptionSpec#ofType(Class) expected type} of the option's - * argument. - * - * @return a description for the option's argument type - */ - String argumentTypeIndicator(); -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/OptionException.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/OptionException.java b/geode-joptsimple/src/main/java/joptsimple/OptionException.java deleted file mode 100644 index 1937fd4..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/OptionException.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import static java.util.Collections.*; - -import static joptsimple.internal.Strings.*; - - -/** - * Thrown when a problem occurs during option parsing. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - * @author Nikhil Jadhav - */ -public abstract class OptionException extends RuntimeException { - private static final long serialVersionUID = -1L; - - // GemFire Addition: To store detected option before OptionException - private OptionSet detected; - - private final List<String> options = new ArrayList<String>(); - - protected OptionException( Collection<String> options ) { - this.options.addAll( options ); - } - - protected OptionException( Collection<String> options, Throwable cause ) { - super( cause ); - - this.options.addAll( options ); - } - - // GemFire Addition: Added setting OptionSet detected so far - protected OptionException(Collection<String> options, OptionSet detected) { - this.options.addAll(options); - this.detected = detected; - } - - /** - * Gives the option being considered when the exception was created. - * - * @return the option being considered when the exception was created - */ - public Collection<String> options() { - return unmodifiableCollection( options ); - } - - protected final String singleOptionMessage() { - return singleOptionMessage( options.get( 0 ) ); - } - - protected final String singleOptionMessage( String option ) { - return SINGLE_QUOTE + option + SINGLE_QUOTE; - } - - protected final String multipleOptionMessage() { - StringBuilder buffer = new StringBuilder( "[" ); - - for ( Iterator<String> iter = options.iterator(); iter.hasNext(); ) { - buffer.append( singleOptionMessage( iter.next() ) ); - if ( iter.hasNext() ) - buffer.append( ", " ); - } - - buffer.append( ']' ); - - return buffer.toString(); - } - - // GemFire Addition: Added to include OptionSet - public static OptionException createUnrecognizedOptionException( String option, OptionSet detected ) { - return new UnrecognizedOptionException( option, detected ); - } - - // GemFire Addition: Added to get the detected OptionSet - /** - * @return the detected OptionSet - */ - public OptionSet getDetected() { - return detected; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/OptionMissingRequiredArgumentException.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/OptionMissingRequiredArgumentException.java b/geode-joptsimple/src/main/java/joptsimple/OptionMissingRequiredArgumentException.java deleted file mode 100644 index 556536f..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/OptionMissingRequiredArgumentException.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.Collection; - -/** - * Thrown when the option parser discovers an option that requires an argument, but that argument is missing. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - * @author Nikhil Jadhav - */ -public class OptionMissingRequiredArgumentException extends OptionException { - private static final long serialVersionUID = -1L; - - OptionMissingRequiredArgumentException( Collection<String> options ) { - super( options ); - } - - // GemFire Addition: Added to include OptionSet - OptionMissingRequiredArgumentException( Collection<String> options, OptionSet detected ) { - super( options, detected ); - } - - @Override - public String getMessage() { - return "Option " + multipleOptionMessage() + " requires an argument"; - } -}