You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2021/10/10 07:39:17 UTC
[maven-studies] 02/04: Remove cli, it is not being used
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to branch maven-wrapper
in repository https://gitbox.apache.org/repos/asf/maven-studies.git
commit 480924f690c6ded5f6d525257799f8590078f4a0
Author: rfscholte <rf...@apache.org>
AuthorDate: Thu Apr 16 22:56:30 2020 +0200
Remove cli, it is not being used
---
.../org/apache/maven/wrapper/MavenWrapperMain.java | 48 +-
.../wrapper/cli/AbstractCommandLineConverter.java | 53 --
.../AbstractPropertiesCommandLineConverter.java | 66 --
.../wrapper/cli/CommandLineArgumentException.java | 39 --
.../maven/wrapper/cli/CommandLineConverter.java | 41 --
.../maven/wrapper/cli/CommandLineOption.java | 140 -----
.../maven/wrapper/cli/CommandLineParser.java | 676 ---------------------
.../maven/wrapper/cli/ParsedCommandLine.java | 140 -----
.../maven/wrapper/cli/ParsedCommandLineOption.java | 59 --
.../cli/ProjectPropertiesCommandLineConverter.java | 46 --
.../cli/SystemPropertiesCommandLineConverter.java | 46 --
11 files changed, 17 insertions(+), 1337 deletions(-)
diff --git a/src/main/java/org/apache/maven/wrapper/MavenWrapperMain.java b/src/main/java/org/apache/maven/wrapper/MavenWrapperMain.java
index ad7777c..fd5dd82 100644
--- a/src/main/java/org/apache/maven/wrapper/MavenWrapperMain.java
+++ b/src/main/java/org/apache/maven/wrapper/MavenWrapperMain.java
@@ -25,12 +25,8 @@ import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.AccessControlException;
-import java.util.Map;
import java.util.Properties;
-import org.apache.maven.wrapper.cli.CommandLineParser;
-import org.apache.maven.wrapper.cli.SystemPropertiesCommandLineConverter;
-
/**
* @author Hans Dockter
*/
@@ -66,8 +62,6 @@ public class MavenWrapperMain
try
{
- Properties systemProperties = System.getProperties();
- systemProperties.putAll( parseSystemPropertiesFromArgs( args ) );
addSystemProperties( rootDir );
}
catch ( AccessControlException e )
@@ -81,21 +75,13 @@ public class MavenWrapperMain
new BootstrapMainStarter() );
}
- private static Map<String, String> parseSystemPropertiesFromArgs( String[] args )
- {
- SystemPropertiesCommandLineConverter converter = new SystemPropertiesCommandLineConverter();
- CommandLineParser commandLineParser = new CommandLineParser();
- converter.configure( commandLineParser );
- commandLineParser.allowUnknownOptions();
- return converter.convert( commandLineParser.parse( args ) );
- }
-
private static void addSystemProperties( Path rootDir )
{
- System.getProperties().putAll(
- SystemPropertiesHandler.getSystemProperties( mavenUserHome().resolve( "maven.properties" ) ) );
- System.getProperties().putAll(
- SystemPropertiesHandler.getSystemProperties( rootDir.resolve( "maven.properties" ) ) );
+ SystemPropertiesHandler.getSystemProperties( mavenUserHome().resolve( "maven.properties" ) ).entrySet().stream()
+ .forEach( e -> System.setProperty( e.getKey(), e.getValue() ) );
+
+ SystemPropertiesHandler.getSystemProperties( rootDir.resolve( "maven.properties" ) ).entrySet().stream()
+ .forEach( e -> System.setProperty( e.getKey(), e.getValue() ) );
}
private static Path rootDir( Path wrapperJar )
@@ -131,20 +117,20 @@ public class MavenWrapperMain
MavenWrapperMain.class.getResourceAsStream( POM_PROPERTIES ) )
{
- if ( resourceAsStream == null )
- {
- return "3.7.0-SNAPSHOT";
-// throw new RuntimeException( "No maven properties found." );
- }
- Properties mavenProperties = new Properties();
- mavenProperties.load( resourceAsStream );
- String version = mavenProperties.getProperty( "version" );
- if ( version == null )
+ if ( resourceAsStream == null )
{
- throw new RuntimeException( "No version number specified in build receipt resource." );
+ return "3.7.0-SNAPSHOT";
+ // throw new RuntimeException( "No maven properties found." );
+ }
+ Properties mavenProperties = new Properties();
+ mavenProperties.load( resourceAsStream );
+ String version = mavenProperties.getProperty( "version" );
+ if ( version == null )
+ {
+ throw new RuntimeException( "No version number specified in build receipt resource." );
+ }
+ return version;
}
- return version;
- }
}
catch ( Exception e )
{
diff --git a/src/main/java/org/apache/maven/wrapper/cli/AbstractCommandLineConverter.java b/src/main/java/org/apache/maven/wrapper/cli/AbstractCommandLineConverter.java
deleted file mode 100644
index f33c017..0000000
--- a/src/main/java/org/apache/maven/wrapper/cli/AbstractCommandLineConverter.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package org.apache.maven.wrapper.cli;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * The Abstract CommandLine Converter
- *
- * @param <T>
- */
-public abstract class AbstractCommandLineConverter<T>
- implements CommandLineConverter<T>
-{
- public T convert( Iterable<String> args )
- throws CommandLineArgumentException
- {
- CommandLineParser parser = new CommandLineParser();
- configure( parser );
- return convert( parser.parse( args ) );
- }
-
- public T convert( ParsedCommandLine args )
- throws CommandLineArgumentException
- {
- return convert( args, newInstance() );
- }
-
- public T convert( Iterable<String> args, T target )
- throws CommandLineArgumentException
- {
- CommandLineParser parser = new CommandLineParser();
- configure( parser );
- return convert( parser.parse( args ), target );
- }
-
- protected abstract T newInstance();
-}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/AbstractPropertiesCommandLineConverter.java b/src/main/java/org/apache/maven/wrapper/cli/AbstractPropertiesCommandLineConverter.java
deleted file mode 100644
index 455fd27..0000000
--- a/src/main/java/org/apache/maven/wrapper/cli/AbstractPropertiesCommandLineConverter.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package org.apache.maven.wrapper.cli;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * The Abstract Properties CommandLine Converter
- */
-public abstract class AbstractPropertiesCommandLineConverter
- extends AbstractCommandLineConverter<Map<String, String>>
-{
- protected abstract String getPropertyOption();
-
- protected abstract String getPropertyOptionDetailed();
-
- protected abstract String getPropertyOptionDescription();
-
- public void configure( CommandLineParser parser )
- {
- CommandLineOption option = parser.option( getPropertyOption(), getPropertyOptionDetailed() );
- option = option.hasArguments();
- option.hasDescription( getPropertyOptionDescription() );
- }
-
- protected Map<String, String> newInstance()
- {
- return new HashMap<String, String>();
- }
-
- public Map<String, String> convert( ParsedCommandLine options, Map<String, String> properties )
- throws CommandLineArgumentException
- {
- for ( String keyValueExpression : options.option( getPropertyOption() ).getValues() )
- {
- int pos = keyValueExpression.indexOf( "=" );
- if ( pos < 0 )
- {
- properties.put( keyValueExpression, "" );
- }
- else
- {
- properties.put( keyValueExpression.substring( 0, pos ), keyValueExpression.substring( pos + 1 ) );
- }
- }
- return properties;
- }
-}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/CommandLineArgumentException.java b/src/main/java/org/apache/maven/wrapper/cli/CommandLineArgumentException.java
deleted file mode 100644
index 3363349..0000000
--- a/src/main/java/org/apache/maven/wrapper/cli/CommandLineArgumentException.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.apache.maven.wrapper.cli;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * A {@code CommandLineArgumentException} is thrown when command-line arguments cannot be parsed.
- *
- * @author Hans Dockter
- */
-public class CommandLineArgumentException
- extends RuntimeException
-{
- public CommandLineArgumentException( String message )
- {
- super( message );
- }
-
- public CommandLineArgumentException( String message, Throwable cause )
- {
- super( message, cause );
- }
-}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/CommandLineConverter.java b/src/main/java/org/apache/maven/wrapper/cli/CommandLineConverter.java
deleted file mode 100644
index fe7fbdf..0000000
--- a/src/main/java/org/apache/maven/wrapper/cli/CommandLineConverter.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.apache.maven.wrapper.cli;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * @author Hans Dockter
- * @param <T>
- */
-public interface CommandLineConverter<T>
-{
- T convert( Iterable<String> args )
- throws CommandLineArgumentException;
-
- T convert( Iterable<String> args, T target )
- throws CommandLineArgumentException;
-
- T convert( ParsedCommandLine args )
- throws CommandLineArgumentException;
-
- T convert( ParsedCommandLine args, T target )
- throws CommandLineArgumentException;
-
- void configure( CommandLineParser parser );
-}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/CommandLineOption.java b/src/main/java/org/apache/maven/wrapper/cli/CommandLineOption.java
deleted file mode 100644
index 0a6dc21..0000000
--- a/src/main/java/org/apache/maven/wrapper/cli/CommandLineOption.java
+++ /dev/null
@@ -1,140 +0,0 @@
-package org.apache.maven.wrapper.cli;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * The CommandLine Option
- *
- */
-public class CommandLineOption
-{
- private final Set<String> options = new HashSet<String>();
-
- private Class<?> argumentType = Void.TYPE;
-
- private String description;
-
- private String subcommand;
-
- private String deprecationWarning;
-
- private boolean incubating;
-
- public CommandLineOption( Iterable<String> options )
- {
- for ( String option : options )
- {
- this.options.add( option );
- }
- }
-
- public Set<String> getOptions()
- {
- return options;
- }
-
- public CommandLineOption hasArgument()
- {
- argumentType = String.class;
- return this;
- }
-
- public CommandLineOption hasArguments()
- {
- argumentType = List.class;
- return this;
- }
-
- public String getSubcommand()
- {
- return subcommand;
- }
-
- public CommandLineOption mapsToSubcommand( String command )
- {
- this.subcommand = command;
- return this;
- }
-
- public String getDescription()
- {
- StringBuilder result = new StringBuilder();
- if ( description != null )
- {
- result.append( description );
- }
- if ( deprecationWarning != null )
- {
- if ( result.length() > 0 )
- {
- result.append( ' ' );
- }
- result.append( "[deprecated - " );
- result.append( deprecationWarning );
- result.append( "]" );
- }
- if ( incubating )
- {
- if ( result.length() > 0 )
- {
- result.append( ' ' );
- }
- result.append( "[incubating]" );
- }
- return result.toString();
- }
-
- public CommandLineOption hasDescription( String description )
- {
- this.description = description;
- return this;
- }
-
- public boolean getAllowsArguments()
- {
- return argumentType != Void.TYPE;
- }
-
- public boolean getAllowsMultipleArguments()
- {
- return argumentType == List.class;
- }
-
- public CommandLineOption deprecated( String deprecationWarning )
- {
- this.deprecationWarning = deprecationWarning;
- return this;
- }
-
- public CommandLineOption incubating()
- {
- incubating = true;
- return this;
- }
-
- public String getDeprecationWarning()
- {
- return deprecationWarning;
- }
-}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/CommandLineParser.java b/src/main/java/org/apache/maven/wrapper/cli/CommandLineParser.java
deleted file mode 100644
index 65ebc75..0000000
--- a/src/main/java/org/apache/maven/wrapper/cli/CommandLineParser.java
+++ /dev/null
@@ -1,676 +0,0 @@
-package org.apache.maven.wrapper.cli;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Formatter;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-//CHECKSTYLE_OFF: LineLength
-/**
- * <p>
- * A command-line parser which supports a command/sub-command style command-line interface. Supports the following
- * syntax:
- * </p>
- *
- * <pre>
- * <option>* (<sub-command> <sub-command-option>*)*
- * </pre>
- * <ul>
- * <li>Short options are a '-' followed by a single character. For example: {@code -a}.</li>
- * <li>Long options are '--' followed by multiple characters. For example: {@code --long-option}.</li>
- * <li>Options can take arguments. The argument follows the option. For example: {@code -a arg} or {@code --long arg}.</li>
- * <li>Arguments can be attached to the option using '='. For example: {@code -a=arg} or {@code --long=arg}.</li>
- * <li>Arguments can be attached to short options. For example: {@code -aarg}.</li>
- * <li>Short options can be combined. For example {@code -ab} is equivalent to {@code -a -b}.</li>
- * <li>Anything else is treated as an extra argument. This includes a single {@code -} character.</li>
- * <li>'--' indicates the end of the options. Anything following is not parsed and is treated as extra arguments.</li>
- * <li>The parser is forgiving, and allows '--' to be used with short options and '-' to be used with long options.</li>
- * <li>The set of options must be known at parse time. Sub-commands and their options do not need to be known at parse
- * time. Use {@link ParsedCommandLine#getExtraArguments()} to obtain the non-option command-line arguments.</li>
- * </ul>
- */
-//CHECKSTYLE_ON: LineLength
-public class CommandLineParser
-{
- private Map<String, CommandLineOption> optionsByString = new HashMap<String, CommandLineOption>();
-
- private boolean allowMixedOptions;
-
- private boolean allowUnknownOptions;
-
- private final PrintWriter deprecationPrinter;
-
- public CommandLineParser()
- {
- this( new OutputStreamWriter( System.out ) );
- }
-
- public CommandLineParser( Writer deprecationPrinter )
- {
- this.deprecationPrinter = new PrintWriter( deprecationPrinter );
- }
-
- /**
- * Parses the given command-line.
- *
- * @param commandLine The command-line.
- * @return The parsed command line.
- * @throws org.apache.maven.wrapper.cli.CommandLineArgumentException On parse failure.
- */
- public ParsedCommandLine parse( String... commandLine )
- throws CommandLineArgumentException
- {
- return parse( Arrays.asList( commandLine ) );
- }
-
- /**
- * Parses the given command-line.
- *
- * @param commandLine The command-line.
- * @return The parsed command line.
- * @throws org.apache.maven.wrapper.cli.CommandLineArgumentException On parse failure.
- */
- public ParsedCommandLine parse( Iterable<String> commandLine )
- throws CommandLineArgumentException
- {
- ParsedCommandLine parsedCommandLine =
- new ParsedCommandLine( new HashSet<CommandLineOption>( optionsByString.values() ) );
- ParserState parseState = new BeforeFirstSubCommand( parsedCommandLine );
- for ( String arg : commandLine )
- {
- if ( parseState.maybeStartOption( arg ) )
- {
- if ( arg.equals( "--" ) )
- {
- parseState = new AfterOptions( parsedCommandLine );
- }
- else if ( arg.matches( "--[^=]+" ) )
- {
- OptionParserState parsedOption = parseState.onStartOption( arg, arg.substring( 2 ) );
- parseState = parsedOption.onStartNextArg();
- }
- else if ( arg.matches( "--[^=]+=.*" ) )
- {
- int endArg = arg.indexOf( '=' );
- OptionParserState parsedOption = parseState.onStartOption( arg, arg.substring( 2, endArg ) );
- parseState = parsedOption.onArgument( arg.substring( endArg + 1 ) );
- }
- else if ( arg.matches( "-[^=]=.*" ) )
- {
- OptionParserState parsedOption = parseState.onStartOption( arg, arg.substring( 1, 2 ) );
- parseState = parsedOption.onArgument( arg.substring( 3 ) );
- }
- else
- {
- assert arg.matches( "-[^-].*" );
- String option = arg.substring( 1 );
- if ( optionsByString.containsKey( option ) )
- {
- OptionParserState parsedOption = parseState.onStartOption( arg, option );
- parseState = parsedOption.onStartNextArg();
- }
- else
- {
- String option1 = arg.substring( 1, 2 );
- OptionParserState parsedOption;
- if ( optionsByString.containsKey( option1 ) )
- {
- parsedOption = parseState.onStartOption( "-" + option1, option1 );
- if ( parsedOption.getHasArgument() )
- {
- parseState = parsedOption.onArgument( arg.substring( 2 ) );
- }
- else
- {
- parseState = parsedOption.onComplete();
- for ( int i = 2; i < arg.length(); i++ )
- {
- String optionStr = arg.substring( i, i + 1 );
- parsedOption = parseState.onStartOption( "-" + optionStr, optionStr );
- parseState = parsedOption.onComplete();
- }
- }
- }
- else
- {
- if ( allowUnknownOptions )
- {
- // if we are allowing unknowns, just pass through the whole arg
- parsedOption = parseState.onStartOption( arg, option );
- parseState = parsedOption.onComplete();
- }
- else
- {
- // We are going to throw a CommandLineArgumentException below, but want the message
- // to reflect that we didn't recognise the first char (i.e. the option specifier)
- parsedOption = parseState.onStartOption( "-" + option1, option1 );
- parseState = parsedOption.onComplete();
- }
- }
- }
- }
- }
- else
- {
- parseState = parseState.onNonOption( arg );
- }
- }
-
- parseState.onCommandLineEnd();
- return parsedCommandLine;
- }
-
- public CommandLineParser allowMixedSubcommandsAndOptions()
- {
- allowMixedOptions = true;
- return this;
- }
-
- public CommandLineParser allowUnknownOptions()
- {
- allowUnknownOptions = true;
- return this;
- }
-
- /**
- * Prints a usage message to the given stream.
- *
- * @param out The output stream to write to.
- */
- public void printUsage( Appendable out )
- {
- Formatter formatter = new Formatter( out );
- Set<CommandLineOption> orderedOptions = new TreeSet<CommandLineOption>( new OptionComparator() );
- orderedOptions.addAll( optionsByString.values() );
- Map<String, String> lines = new LinkedHashMap<String, String>();
- for ( CommandLineOption option : orderedOptions )
- {
- Set<String> orderedOptionStrings = new TreeSet<String>( new OptionStringComparator() );
- orderedOptionStrings.addAll( option.getOptions() );
- List<String> prefixedStrings = new ArrayList<String>();
- for ( String optionString : orderedOptionStrings )
- {
- if ( optionString.length() == 1 )
- {
- prefixedStrings.add( "-" + optionString );
- }
- else
- {
- prefixedStrings.add( "--" + optionString );
- }
- }
-
- String key = join( prefixedStrings, ", " );
- String value = option.getDescription();
- if ( value == null || value.length() == 0 )
- {
- value = "";
- }
-
- lines.put( key, value );
- }
- int max = 0;
- for ( String optionStr : lines.keySet() )
- {
- max = Math.max( max, optionStr.length() );
- }
- for ( Map.Entry<String, String> entry : lines.entrySet() )
- {
- if ( entry.getValue().length() == 0 )
- {
- formatter.format( "%s%n", entry.getKey() );
- }
- else
- {
- formatter.format( "%-" + max + "s %s%n", entry.getKey(), entry.getValue() );
- }
- }
- formatter.flush();
- }
-
- private static String join( Collection<?> things, String separator )
- {
- StringBuffer buffer = new StringBuffer();
- boolean first = true;
-
- if ( separator == null )
- {
- separator = "";
- }
-
- for ( Object thing : things )
- {
- if ( !first )
- {
- buffer.append( separator );
- }
- buffer.append( thing.toString() );
- first = false;
- }
- return buffer.toString();
- }
-
- /**
- * Defines a new option. By default, the option takes no arguments and has no description.
- *
- * @param options The options values.
- * @return The option, which can be further configured.
- */
- public CommandLineOption option( String... options )
- {
- for ( String option : options )
- {
- if ( optionsByString.containsKey( option ) )
- {
- throw new IllegalArgumentException( String.format( "Option '%s' is already defined.", option ) );
- }
- if ( option.startsWith( "-" ) )
- {
- throw new IllegalArgumentException(
- String.format( "Can't add option '%s' as an option cannot start with '-'.", option ) );
- }
- }
- CommandLineOption option = new CommandLineOption( Arrays.asList( options ) );
- for ( String optionStr : option.getOptions() )
- {
- this.optionsByString.put( optionStr, option );
- }
- return option;
- }
-
- private static class OptionString
- {
- private final String arg;
-
- private final String option;
-
- private OptionString( String arg, String option )
- {
- this.arg = arg;
- this.option = option;
- }
-
- public String getDisplayName()
- {
- return arg.startsWith( "--" ) ? "--" + option : "-" + option;
- }
-
- @Override
- public String toString()
- {
- return getDisplayName();
- }
- }
-
- private abstract static class ParserState
- {
- public abstract boolean maybeStartOption( String arg );
-
- boolean isOption( String arg )
- {
- return arg.matches( "-.+" );
- }
-
- public abstract OptionParserState onStartOption( String arg, String option );
-
- public abstract ParserState onNonOption( String arg );
-
- public void onCommandLineEnd()
- {
- }
- }
-
- private abstract class OptionAwareParserState
- extends ParserState
- {
- protected final ParsedCommandLine commandLine;
-
- protected OptionAwareParserState( ParsedCommandLine commandLine )
- {
- this.commandLine = commandLine;
- }
-
- @Override
- public boolean maybeStartOption( String arg )
- {
- return isOption( arg );
- }
-
- @Override
- public ParserState onNonOption( String arg )
- {
- commandLine.addExtraValue( arg );
- return allowMixedOptions ? new AfterFirstSubCommand( commandLine ) : new AfterOptions( commandLine );
- }
- }
-
- private class BeforeFirstSubCommand
- extends OptionAwareParserState
- {
- private BeforeFirstSubCommand( ParsedCommandLine commandLine )
- {
- super( commandLine );
- }
-
- @Override
- public OptionParserState onStartOption( String arg, String option )
- {
- OptionString optionString = new OptionString( arg, option );
- CommandLineOption commandLineOption = optionsByString.get( option );
- if ( commandLineOption == null )
- {
- if ( allowUnknownOptions )
- {
- return new UnknownOptionParserState( arg, commandLine, this );
- }
- else
- {
- throw new CommandLineArgumentException( String.format( "Unknown command-line option '%s'.",
- optionString ) );
- }
- }
- return new KnownOptionParserState( optionString, commandLineOption, commandLine, this );
- }
- }
-
- private class AfterFirstSubCommand
- extends OptionAwareParserState
- {
- private AfterFirstSubCommand( ParsedCommandLine commandLine )
- {
- super( commandLine );
- }
-
- @Override
- public OptionParserState onStartOption( String arg, String option )
- {
- CommandLineOption commandLineOption = optionsByString.get( option );
- if ( commandLineOption == null )
- {
- return new UnknownOptionParserState( arg, commandLine, this );
- }
- return new KnownOptionParserState( new OptionString( arg, option ), commandLineOption, commandLine, this );
- }
- }
-
- private static class AfterOptions
- extends ParserState
- {
- private final ParsedCommandLine commandLine;
-
- private AfterOptions( ParsedCommandLine commandLine )
- {
- this.commandLine = commandLine;
- }
-
- @Override
- public boolean maybeStartOption( String arg )
- {
- return false;
- }
-
- @Override
- public OptionParserState onStartOption( String arg, String option )
- {
- return new UnknownOptionParserState( arg, commandLine, this );
- }
-
- @Override
- public ParserState onNonOption( String arg )
- {
- commandLine.addExtraValue( arg );
- return this;
- }
- }
-
- private static class MissingOptionArgState
- extends ParserState
- {
- private final OptionParserState option;
-
- private MissingOptionArgState( OptionParserState option )
- {
- this.option = option;
- }
-
- @Override
- public boolean maybeStartOption( String arg )
- {
- return isOption( arg );
- }
-
- @Override
- public OptionParserState onStartOption( String arg, String option )
- {
- return this.option.onComplete().onStartOption( arg, option );
- }
-
- @Override
- public ParserState onNonOption( String arg )
- {
- return option.onArgument( arg );
- }
-
- @Override
- public void onCommandLineEnd()
- {
- option.onComplete();
- }
- }
-
- private abstract static class OptionParserState
- {
- public abstract ParserState onStartNextArg();
-
- public abstract ParserState onArgument( String argument );
-
- public abstract boolean getHasArgument();
-
- public abstract ParserState onComplete();
- }
-
- private class KnownOptionParserState
- extends OptionParserState
- {
- private final OptionString optionString;
-
- private final CommandLineOption option;
-
- private final ParsedCommandLine commandLine;
-
- private final ParserState state;
-
- private final List<String> values = new ArrayList<String>();
-
- private KnownOptionParserState( OptionString optionString, CommandLineOption option,
- ParsedCommandLine commandLine, ParserState state )
- {
- this.optionString = optionString;
- this.option = option;
- this.commandLine = commandLine;
- this.state = state;
- }
-
- @Override
- public ParserState onArgument( String argument )
- {
- if ( !getHasArgument() )
- {
- throw new CommandLineArgumentException(
- String.format( "Command-line option '%s' does not take an argument.", optionString ) );
- }
- if ( argument.length() == 0 )
- {
- throw new CommandLineArgumentException(
- String.format( "An empty argument was provided for command-line option '%s'.", optionString ) );
- }
- values.add( argument );
- return onComplete();
- }
-
- @Override
- public ParserState onStartNextArg()
- {
- if ( option.getAllowsArguments() && values.isEmpty() )
- {
- return new MissingOptionArgState( this );
- }
- return onComplete();
- }
-
- @Override
- public boolean getHasArgument()
- {
- return option.getAllowsArguments();
- }
-
- @Override
- public ParserState onComplete()
- {
- if ( getHasArgument() && values.isEmpty() )
- {
- throw new CommandLineArgumentException(
- String.format( "No argument was provided for command-line option '%s'.", optionString ) );
- }
-
- ParsedCommandLineOption parsedOption = commandLine.addOption( optionString.option, option );
- if ( values.size() + parsedOption.getValues().size() > 1 && !option.getAllowsMultipleArguments() )
- {
- throw new CommandLineArgumentException(
- String.format( "Multiple arguments were provided for command-line option '%s'.", optionString ) );
- }
- for ( String value : values )
- {
- parsedOption.addArgument( value );
- }
- if ( option.getDeprecationWarning() != null )
- {
- deprecationPrinter.println( "The " + optionString + " option is deprecated - "
- + option.getDeprecationWarning() );
- }
- if ( option.getSubcommand() != null )
- {
- return state.onNonOption( option.getSubcommand() );
- }
-
- return state;
- }
- }
-
- private static class UnknownOptionParserState
- extends OptionParserState
- {
- private final ParserState state;
-
- private final String arg;
-
- private final ParsedCommandLine commandLine;
-
- private UnknownOptionParserState( String arg, ParsedCommandLine commandLine, ParserState state )
- {
- this.arg = arg;
- this.commandLine = commandLine;
- this.state = state;
- }
-
- @Override
- public boolean getHasArgument()
- {
- return true;
- }
-
- @Override
- public ParserState onStartNextArg()
- {
- return onComplete();
- }
-
- @Override
- public ParserState onArgument( String argument )
- {
- return onComplete();
- }
-
- @Override
- public ParserState onComplete()
- {
- commandLine.addExtraValue( arg );
- return state;
- }
- }
-
- private static final class OptionComparator
- implements Comparator<CommandLineOption>
- {
- public int compare( CommandLineOption option1, CommandLineOption option2 )
- {
- String min1 = Collections.min( option1.getOptions(), new OptionStringComparator() );
- String min2 = Collections.min( option2.getOptions(), new OptionStringComparator() );
- return new CaseInsensitiveStringComparator().compare( min1, min2 );
- }
- }
-
- private static final class CaseInsensitiveStringComparator
- implements Comparator<String>
- {
- public int compare( String option1, String option2 )
- {
- int diff = option1.compareToIgnoreCase( option2 );
- if ( diff != 0 )
- {
- return diff;
- }
- return option1.compareTo( option2 );
- }
- }
-
- private static final class OptionStringComparator
- implements Comparator<String>
- {
- public int compare( String option1, String option2 )
- {
- boolean short1 = option1.length() == 1;
- boolean short2 = option2.length() == 1;
- if ( short1 && !short2 )
- {
- return -1;
- }
- if ( !short1 && short2 )
- {
- return 1;
- }
- return new CaseInsensitiveStringComparator().compare( option1, option2 );
- }
- }
-}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/ParsedCommandLine.java b/src/main/java/org/apache/maven/wrapper/cli/ParsedCommandLine.java
deleted file mode 100644
index 833da3d..0000000
--- a/src/main/java/org/apache/maven/wrapper/cli/ParsedCommandLine.java
+++ /dev/null
@@ -1,140 +0,0 @@
-package org.apache.maven.wrapper.cli;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * The Parsed Command Line
- */
-public class ParsedCommandLine
-{
- private final Map<String, ParsedCommandLineOption> optionsByString = new HashMap<String, ParsedCommandLineOption>();
-
- private final Set<String> presentOptions = new HashSet<String>();
-
- private final List<String> extraArguments = new ArrayList<String>();
-
- ParsedCommandLine( Iterable<CommandLineOption> options )
- {
- for ( CommandLineOption option : options )
- {
- ParsedCommandLineOption parsedOption = new ParsedCommandLineOption();
- for ( String optionStr : option.getOptions() )
- {
- optionsByString.put( optionStr, parsedOption );
- }
- }
- }
-
- @Override
- public String toString()
- {
- return String.format( "options: %s, extraArguments: %s", quoteAndJoin( presentOptions ),
- quoteAndJoin( extraArguments ) );
- }
-
- private String quoteAndJoin( Iterable<String> strings )
- {
- StringBuilder output = new StringBuilder();
- boolean isFirst = true;
- for ( String string : strings )
- {
- if ( !isFirst )
- {
- output.append( ", " );
- }
- output.append( "'" );
- output.append( string );
- output.append( "'" );
- isFirst = false;
- }
- return output.toString();
- }
-
- /**
- * Returns true if the given option is present in this command-line.
- *
- * @param option The option, without the '-' or '--' prefix.
- * @return true if the option is present.
- */
- public boolean hasOption( String option )
- {
- option( option );
- return presentOptions.contains( option );
- }
-
- /**
- * See also {@link #hasOption}.
- *
- * @param logLevelOptions the options to check
- * @return true if any of the passed options is present
- */
- public boolean hasAnyOption( Collection<String> logLevelOptions )
- {
- for ( String option : logLevelOptions )
- {
- if ( hasOption( option ) )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Returns the value of the given option.
- *
- * @param option The option, without the '-' or '--' prefix.
- * @return The option. never returns null.
- */
- public ParsedCommandLineOption option( String option )
- {
- ParsedCommandLineOption parsedOption = optionsByString.get( option );
- if ( parsedOption == null )
- {
- throw new IllegalArgumentException( String.format( "Option '%s' not defined.", option ) );
- }
- return parsedOption;
- }
-
- public List<String> getExtraArguments()
- {
- return extraArguments;
- }
-
- void addExtraValue( String value )
- {
- extraArguments.add( value );
- }
-
- ParsedCommandLineOption addOption( String optionStr, CommandLineOption option )
- {
- ParsedCommandLineOption parsedOption = optionsByString.get( optionStr );
- presentOptions.addAll( option.getOptions() );
- return parsedOption;
- }
-}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/ParsedCommandLineOption.java b/src/main/java/org/apache/maven/wrapper/cli/ParsedCommandLineOption.java
deleted file mode 100644
index d75acc0..0000000
--- a/src/main/java/org/apache/maven/wrapper/cli/ParsedCommandLineOption.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package org.apache.maven.wrapper.cli;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * The Parsed Command Line Option
- */
-public class ParsedCommandLineOption
-{
- private final List<String> values = new ArrayList<String>();
-
- public String getValue()
- {
- if ( !hasValue() )
- {
- throw new IllegalStateException( "Option does not have any value." );
- }
- if ( values.size() > 1 )
- {
- throw new IllegalStateException( "Option has multiple values." );
- }
- return values.get( 0 );
- }
-
- public List<String> getValues()
- {
- return values;
- }
-
- public void addArgument( String argument )
- {
- values.add( argument );
- }
-
- public boolean hasValue()
- {
- return !values.isEmpty();
- }
-}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/ProjectPropertiesCommandLineConverter.java b/src/main/java/org/apache/maven/wrapper/cli/ProjectPropertiesCommandLineConverter.java
deleted file mode 100644
index eaa5b11..0000000
--- a/src/main/java/org/apache/maven/wrapper/cli/ProjectPropertiesCommandLineConverter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package org.apache.maven.wrapper.cli;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * The Project Properties CommandLine Converter
- */
-public class ProjectPropertiesCommandLineConverter
- extends AbstractPropertiesCommandLineConverter
-{
-
- @Override
- protected String getPropertyOption()
- {
- return "P";
- }
-
- @Override
- protected String getPropertyOptionDetailed()
- {
- return "project-prop";
- }
-
- @Override
- protected String getPropertyOptionDescription()
- {
- return "Set project property for the build script (e.g. -Pmyprop=myvalue).";
- }
-}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/SystemPropertiesCommandLineConverter.java b/src/main/java/org/apache/maven/wrapper/cli/SystemPropertiesCommandLineConverter.java
deleted file mode 100644
index 6a1fca5..0000000
--- a/src/main/java/org/apache/maven/wrapper/cli/SystemPropertiesCommandLineConverter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package org.apache.maven.wrapper.cli;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * The System Properties Command Line Converter
- */
-public class SystemPropertiesCommandLineConverter
- extends AbstractPropertiesCommandLineConverter
-{
-
- @Override
- protected String getPropertyOption()
- {
- return "D";
- }
-
- @Override
- protected String getPropertyOptionDetailed()
- {
- return "system-prop";
- }
-
- @Override
- protected String getPropertyOptionDescription()
- {
- return "Set system property of the JVM (e.g. -Dmyprop=myvalue).";
- }
-}
\ No newline at end of file