diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..f0138ad
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,27 @@
+#
+# 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.
+#
+version: 2
+updates:
+ - package-ecosystem: "maven"
+ directory: "/"
+ schedule:
+ interval: "daily"
+ - package-ecosystem: "github-actions"
+ directory: "/"
+ schedule:
+ interval: "daily"
+
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
new file mode 100644
index 0000000..09feae4
--- /dev/null
+++ b/.github/workflows/maven.yml
@@ -0,0 +1,31 @@
+# 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.
+
+name: GitHub CI
+
+on: [push, pull_request]
+
+jobs:
+ build:
+ name: Build it
+ uses: codehaus-plexus/.github/.github/workflows/maven.yml@master
+
+ deploy:
+ name: Deploy
+ needs: build
+ uses: codehaus-plexus/.github/.github/workflows/maven-deploy.yml@master
+ secrets: inherit
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ece20be
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+target/
+.project
+.classpath
+.settings/
+bin
+*.iml
+.idea
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..5a5250d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,7 @@
+Plexus-CLI
+===============
+
+[](http://www.apache.org/licenses/)
+[](https://search.maven.org/artifact/org.codehaus.plexus/plexus-cli)
+
+The canonical git repository is located at https://github.com/codehaus-plexus/plexus-cli
diff --git a/pom.xml b/pom.xml
index 9081e57..bda976d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,45 +1,94 @@
-
-
+
4.0.0
- plexus-components
org.codehaus.plexus
- 1.1.20
+ plexus
+ 16
- org.codehaus.plexus
plexus-cli
- 1.6
+ 1.7
Plexus CLI
Easily create CLIs with Plexus components
+
+ scm:git:https://github.com/codehaus-plexus/plexus-cli.git
+ scm:git:https://github.com/codehaus-plexus/plexus-cli.git
+ plexus-cli-1.7
+ https://github.com/codehaus-plexus/plexus-cli/tree/${project.scm.tag}/
+
+
+ github
+ https://github.com/codehaus-plexus/plexus-cli/issues
+
+
+
+ github:gh-pages
+ ${project.scm.developerConnection}
+
+
+
+
+ 2023-12-23T21:44:13Z
+
+
- org.codehaus.plexus
- plexus-container-default
- 1.0-alpha-34
+ org.eclipse.sisu
+ org.eclipse.sisu.plexus
+ 0.3.5
org.codehaus.plexus
plexus-utils
+ 4.0.0
+
+
+ org.codehaus.plexus
+ plexus-xml
+ 3.0.0
commons-cli
commons-cli
- 1.0
-
-
- commons-lang
- commons-lang
-
-
- commons-logging
- commons-logging
-
-
+ 1.6.0
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ test
+
+
+ org.codehaus.plexus
+ plexus-testing
+ 1.3.0
+ test
+
+
+
+
+ org.apache.maven.plugins
+ maven-scm-publish-plugin
+
+
+ ${project.reporting.outputDirectory}
+
+
+
+
+ scm-publish
+
+ publish-scm
+
+ site-deploy
+
+
+
+
+
diff --git a/src/main/java/org/codehaus/plexus/tools/cli/AbstractCli.java b/src/main/java/org/codehaus/plexus/tools/cli/AbstractCli.java
index 1763c5a..505c128 100644
--- a/src/main/java/org/codehaus/plexus/tools/cli/AbstractCli.java
+++ b/src/main/java/org/codehaus/plexus/tools/cli/AbstractCli.java
@@ -16,6 +16,12 @@
* limitations under the License.
*/
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
@@ -31,20 +37,10 @@
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
/**
* @author jason van zyl
- * @version $Id$
- * @noinspection UseOfSystemOutOrSystemErr,ACCESS_STATIC_VIA_INSTANCE
*/
-public abstract class AbstractCli
- implements Cli
-{
+public abstract class AbstractCli implements Cli {
// ----------------------------------------------------------------------------
// These are standard options that we would want to use for all our projects.
// ----------------------------------------------------------------------------
@@ -65,61 +61,51 @@ public abstract class AbstractCli
// Abstract methods
// ----------------------------------------------------------------------------
- public abstract Options buildCliOptions( Options options );
+ public abstract Options buildCliOptions(Options options);
- public abstract void invokePlexusComponent( CommandLine cli,
- PlexusContainer container )
- throws Exception;
+ public abstract void invokePlexusComponent(CommandLine cli, PlexusContainer container) throws Exception;
- public String getPomPropertiesPath()
- {
+ public String getPomPropertiesPath() {
return null;
}
- public int execute( String[] args )
- {
- ClassWorld classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() );
+ public int execute(String[] args) {
+ ClassWorld classWorld =
+ new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader());
- return execute( args, classWorld );
+ return execute(args, classWorld);
}
- public int execute( String[] args,
- ClassWorld classWorld )
- {
+ public int execute(String[] args, ClassWorld classWorld) {
CommandLine cli;
- try
- {
- cli = parse( args );
- }
- catch ( ParseException e )
- {
- System.err.println( "Unable to parse command line options: " + e.getMessage() );
+ try {
+ cli = parse(args);
+ } catch (ParseException e) {
+ System.err.println("Unable to parse command line options: " + e.getMessage());
displayHelp();
return 1;
}
- if ( System.getProperty( "java.class.version", "44.0" ).compareTo( "48.0" ) < 0 )
- {
- System.err.println( "Sorry, but JDK 1.4 or above is required to execute Maven" );
+ if (System.getProperty("java.class.version", "44.0").compareTo("48.0") < 0) {
+ System.err.println("Sorry, but JDK 1.4 or above is required to execute Maven");
System.err.println(
- "You appear to be using Java version: " + System.getProperty( "java.version", "" ) );
+ "You appear to be using Java version: " + System.getProperty("java.version", ""));
return 1;
}
- boolean debug = cli.hasOption( DEBUG );
+ boolean debug = cli.hasOption(DEBUG);
- boolean quiet = !debug && cli.hasOption( QUIET );
+ boolean quiet = !debug && cli.hasOption(QUIET);
- boolean showErrors = debug || cli.hasOption( ERRORS );
+ boolean showErrors = debug || cli.hasOption(ERRORS);
- if ( showErrors )
- {
- System.out.println( "+ Error stacktraces are turned on." );
+ if (showErrors) {
+ System.out.println("+ Error stacktraces are turned on.");
}
// ----------------------------------------------------------------------------
@@ -128,16 +114,11 @@ public int execute( String[] args,
int loggingLevel;
- if ( debug )
- {
+ if (debug) {
loggingLevel = 0;
- }
- else if ( quiet )
- {
+ } else if (quiet) {
loggingLevel = 0;
- }
- else
- {
+ } else {
loggingLevel = 0;
}
@@ -145,21 +126,17 @@ else if ( quiet )
// Process particular command line options
// ----------------------------------------------------------------------
- if ( cli.hasOption( HELP ) )
- {
+ if (cli.hasOption(HELP)) {
displayHelp();
return 0;
}
- if ( cli.hasOption( VERSION ) )
- {
+ if (cli.hasOption(VERSION)) {
showVersion();
return 0;
- }
- else if ( debug )
- {
+ } else if (debug) {
showVersion();
}
@@ -167,66 +144,46 @@ else if ( debug )
// This is what we will generalize for the invocation of the command line.
// ----------------------------------------------------------------------------
- try
- {
- ContainerConfiguration configuration = new DefaultContainerConfiguration()
- .setClassWorld( classWorld );
+ try {
+ ContainerConfiguration configuration = new DefaultContainerConfiguration().setClassWorld(classWorld);
- customizeContainerConfiguration( configuration, cli );
-
- PlexusContainer plexus = new DefaultPlexusContainer( configuration );
+ customizeContainerConfiguration(configuration, cli);
- invokePlexusComponent( cli, plexus );
- }
- catch ( PlexusContainerException e )
- {
- showFatalError( "Cannot create Plexus container.", e, true );
- }
- catch ( ComponentLookupException e )
- {
- showError( "Cannot lookup application component.", e, true );
- }
- catch ( Exception e )
- {
- showError( "Problem executing command line.", e, true );
+ PlexusContainer plexus = new DefaultPlexusContainer(configuration);
+
+ invokePlexusComponent(cli, plexus);
+ } catch (PlexusContainerException e) {
+ showFatalError("Cannot create Plexus container.", e, true);
+ } catch (ComponentLookupException e) {
+ showError("Cannot lookup application component.", e, true);
+ } catch (Exception e) {
+ showError("Problem executing command line.", e, true);
}
return 0;
}
- protected void customizeContainerConfiguration( ContainerConfiguration configuration, CommandLine cli )
- {
- }
-
- protected int showFatalError( String message,
- Exception e,
- boolean show )
- {
- System.err.println( "FATAL ERROR: " + message );
+ protected void customizeContainerConfiguration(ContainerConfiguration configuration, CommandLine cli) {}
- if ( show )
- {
- System.err.println( "Error stacktrace:" );
+ protected int showFatalError(String message, Exception e, boolean show) {
+ System.err.println("FATAL ERROR: " + message);
+
+ if (show) {
+ System.err.println("Error stacktrace:");
e.printStackTrace();
- }
- else
- {
- System.err.println( "For more information, run with the -e flag" );
+ } else {
+ System.err.println("For more information, run with the -e flag");
}
return 1;
}
- protected void showError( String message,
- Exception e,
- boolean show )
- {
- System.err.println( message );
+ protected void showError(String message, Exception e, boolean show) {
+ System.err.println(message);
- if ( show )
- {
- System.err.println( "Error stacktrace:" );
+ if (show) {
+ System.err.println("Error stacktrace:");
e.printStackTrace();
}
@@ -234,47 +191,38 @@ protected void showError( String message,
// Need to get the versions of the application in a general way, so that I need a way to get the
// specifics of the application so that I can do this in a general way.
- private void showVersion()
- {
+ private void showVersion() {
InputStream is;
- try
- {
+ try {
Properties properties = new Properties();
String pomPropertiesPath = getPomPropertiesPath();
- if ( pomPropertiesPath == null )
- {
- System.err.println( "Unable determine version from JAR file." );
+ if (pomPropertiesPath == null) {
+ System.err.println("Unable determine version from JAR file.");
return;
}
- is = AbstractCli.class.getClassLoader().getResourceAsStream( pomPropertiesPath );
+ is = AbstractCli.class.getClassLoader().getResourceAsStream(pomPropertiesPath);
- if ( is == null )
- {
- System.err.println( "Unable determine version from JAR file." );
+ if (is == null) {
+ System.err.println("Unable determine version from JAR file.");
return;
}
- properties.load( is );
+ properties.load(is);
- if ( properties.getProperty( "builtOn" ) != null )
- {
- System.out.println( "Version: " + properties.getProperty( "version", "unknown" ) + " built on " +
- properties.getProperty( "builtOn" ) );
+ if (properties.getProperty("builtOn") != null) {
+ System.out.println("Version: " + properties.getProperty("version", "unknown") + " built on "
+ + properties.getProperty("builtOn"));
+ } else {
+ System.out.println("Version: " + properties.getProperty("version", "unknown"));
}
- else
- {
- System.out.println( "Version: " + properties.getProperty( "version", "unknown" ) );
- }
- }
- catch ( IOException e )
- {
- System.err.println( "Unable determine version from JAR file: " + e.getMessage() );
+ } catch (IOException e) {
+ System.err.println("Unable determine version from JAR file: " + e.getMessage());
}
}
@@ -282,8 +230,7 @@ private void showVersion()
// System properties handling
// ----------------------------------------------------------------------
- private Properties getExecutionProperties( CommandLine commandLine )
- {
+ private Properties getExecutionProperties(CommandLine commandLine) {
Properties executionProperties = new Properties();
// ----------------------------------------------------------------------
@@ -292,142 +239,127 @@ private Properties getExecutionProperties( CommandLine commandLine )
// are most dominant.
// ----------------------------------------------------------------------
- if ( commandLine.hasOption( SET_SYSTEM_PROPERTY ) )
- {
- String[] defStrs = commandLine.getOptionValues( SET_SYSTEM_PROPERTY );
+ if (commandLine.hasOption(SET_SYSTEM_PROPERTY)) {
+ String[] defStrs = commandLine.getOptionValues(SET_SYSTEM_PROPERTY);
- for ( int i = 0; i < defStrs.length; ++i )
- {
- setCliProperty( defStrs[i], executionProperties );
+ for (int i = 0; i < defStrs.length; ++i) {
+ setCliProperty(defStrs[i], executionProperties);
}
}
- executionProperties.putAll( System.getProperties() );
+ executionProperties.putAll(System.getProperties());
return executionProperties;
}
- private void setCliProperty( String property,
- Properties executionProperties )
- {
+ private void setCliProperty(String property, Properties executionProperties) {
String name;
String value;
- int i = property.indexOf( "=" );
+ int i = property.indexOf("=");
- if ( i <= 0 )
- {
+ if (i <= 0) {
name = property.trim();
value = "true";
- }
- else
- {
- name = property.substring( 0, i ).trim();
+ } else {
+ name = property.substring(0, i).trim();
- value = property.substring( i + 1 ).trim();
+ value = property.substring(i + 1).trim();
}
- executionProperties.setProperty( name, value );
+ executionProperties.setProperty(name, value);
// ----------------------------------------------------------------------
// I'm leaving the setting of system properties here as not to break
// the SystemPropertyProfileActivator. This won't harm embedding. jvz.
// ----------------------------------------------------------------------
- System.setProperty( name, value );
+ System.setProperty(name, value);
}
private Options options;
- public Options buildDefaultCliOptions()
- {
+ public Options buildDefaultCliOptions() {
options = new Options();
- options.addOption(
- OptionBuilder.withLongOpt( "define" ).hasArg().withDescription( "Define a system property" ).create(
- SET_SYSTEM_PROPERTY ) );
- options.addOption(
- OptionBuilder.withLongOpt( "help" ).withDescription( "Display help information" ).create( HELP ) );
- options.addOption(
- OptionBuilder.withLongOpt( "version" ).withDescription( "Display version information" ).create( VERSION ) );
- options.addOption(
- OptionBuilder.withLongOpt( "quiet" ).withDescription( "Quiet output - only show errors" ).create( QUIET ) );
- options.addOption(
- OptionBuilder.withLongOpt( "debug" ).withDescription( "Produce execution debug output" ).create( DEBUG ) );
- options.addOption(
- OptionBuilder.withLongOpt( "errors" ).withDescription( "Produce execution error messages" ).create(
- ERRORS ) );
-
- return buildCliOptions( options );
+ options.addOption(OptionBuilder.withLongOpt("define")
+ .hasArg()
+ .withDescription("Define a system property")
+ .create(SET_SYSTEM_PROPERTY));
+ options.addOption(OptionBuilder.withLongOpt("help")
+ .withDescription("Display help information")
+ .create(HELP));
+ options.addOption(OptionBuilder.withLongOpt("version")
+ .withDescription("Display version information")
+ .create(VERSION));
+ options.addOption(OptionBuilder.withLongOpt("quiet")
+ .withDescription("Quiet output - only show errors")
+ .create(QUIET));
+ options.addOption(OptionBuilder.withLongOpt("debug")
+ .withDescription("Produce execution debug output")
+ .create(DEBUG));
+ options.addOption(OptionBuilder.withLongOpt("errors")
+ .withDescription("Produce execution error messages")
+ .create(ERRORS));
+
+ return buildCliOptions(options);
}
- public CommandLine parse( String[] args )
- throws ParseException
- {
+ public CommandLine parse(String[] args) throws ParseException {
// We need to eat any quotes surrounding arguments...
- String[] cleanArgs = cleanArgs( args );
+ String[] cleanArgs = cleanArgs(args);
CommandLineParser parser = new GnuParser();
- return parser.parse( buildDefaultCliOptions(), cleanArgs );
+ return parser.parse(buildDefaultCliOptions(), cleanArgs);
}
- private static String[] cleanArgs( String[] args )
- {
+ private static String[] cleanArgs(String[] args) {
List cleaned = new ArrayList();
StringBuffer currentArg = null;
- for ( int i = 0; i < args.length; i++ )
- {
+ for (int i = 0; i < args.length; i++) {
String arg = args[i];
boolean addedToBuffer = false;
- if ( arg.startsWith( "\"" ) )
- {
+ if (arg.startsWith("\"")) {
// if we're in the process of building up another arg, push it and start over.
// this is for the case: "-Dfoo=bar "-Dfoo2=bar two" (note the first unterminated quote)
- if ( currentArg != null )
- {
- cleaned.add( currentArg.toString() );
+ if (currentArg != null) {
+ cleaned.add(currentArg.toString());
}
// start building an argument here.
- currentArg = new StringBuffer( arg.substring( 1 ) );
+ currentArg = new StringBuffer(arg.substring(1));
addedToBuffer = true;
}
// this has to be a separate "if" statement, to capture the case of: "-Dfoo=bar"
- if ( arg.endsWith( "\"" ) )
- {
- String cleanArgPart = arg.substring( 0, arg.length() - 1 );
+ if (arg.endsWith("\"")) {
+ String cleanArgPart = arg.substring(0, arg.length() - 1);
// if we're building an argument, keep doing so.
- if ( currentArg != null )
- {
+ if (currentArg != null) {
// if this is the case of "-Dfoo=bar", then we need to adjust the buffer.
- if ( addedToBuffer )
- {
- currentArg.setLength( currentArg.length() - 1 );
+ if (addedToBuffer) {
+ currentArg.setLength(currentArg.length() - 1);
}
// otherwise, we trim the trailing " and append to the buffer.
- else
- {
+ else {
// TODO: introducing a space here...not sure what else to do but collapse whitespace
- currentArg.append( ' ' ).append( cleanArgPart );
+ currentArg.append(' ').append(cleanArgPart);
}
// we're done with this argument, so add it.
- cleaned.add( currentArg.toString() );
- }
- else
- {
+ cleaned.add(currentArg.toString());
+ } else {
// this is a simple argument...just add it.
- cleaned.add( cleanArgPart );
+ cleaned.add(cleanArgPart);
}
// the currentArg MUST be finished when this completes.
@@ -440,49 +372,41 @@ private static String[] cleanArgs( String[] args )
// buffer, then append it with a preceding space...again, not sure what else to
// do other than collapse whitespace.
// NOTE: The case of a trailing quote is handled by nullifying the arg buffer.
- if ( !addedToBuffer )
- {
+ if (!addedToBuffer) {
// append to the argument we're building, collapsing whitespace to a single space.
- if ( currentArg != null )
- {
- currentArg.append( ' ' ).append( arg );
+ if (currentArg != null) {
+ currentArg.append(' ').append(arg);
}
// this is a loner, just add it directly.
- else
- {
- cleaned.add( arg );
+ else {
+ cleaned.add(arg);
}
}
}
// clean up.
- if ( currentArg != null )
- {
- cleaned.add( currentArg.toString() );
+ if (currentArg != null) {
+ cleaned.add(currentArg.toString());
}
int cleanedSz = cleaned.size();
String[] cleanArgs = null;
- if ( cleanedSz == 0 )
- {
+ if (cleanedSz == 0) {
// if we didn't have any arguments to clean, simply pass the original array through
cleanArgs = args;
- }
- else
- {
- cleanArgs = (String[]) cleaned.toArray( new String[cleanedSz] );
+ } else {
+ cleanArgs = (String[]) cleaned.toArray(new String[cleanedSz]);
}
return cleanArgs;
}
- public void displayHelp()
- {
+ public void displayHelp() {
System.out.println();
HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp( "mvn [options] [] []", "\nOptions:", options, "\n" );
+ formatter.printHelp("mvn [options] [] []", "\nOptions:", options, "\n");
}
}
diff --git a/src/main/java/org/codehaus/plexus/tools/cli/Cli.java b/src/main/java/org/codehaus/plexus/tools/cli/Cli.java
index 6f5fddf..640a9d1 100644
--- a/src/main/java/org/codehaus/plexus/tools/cli/Cli.java
+++ b/src/main/java/org/codehaus/plexus/tools/cli/Cli.java
@@ -16,20 +16,17 @@
* limitations under the License.
*/
-import org.codehaus.plexus.PlexusContainer;
-import org.apache.commons.cli.Options;
import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+import org.codehaus.plexus.PlexusContainer;
/**
* @author Jason van Zyl
*/
-public interface Cli
-{
- Options buildCliOptions( Options options );
+public interface Cli {
+ Options buildCliOptions(Options options);
- void invokePlexusComponent( CommandLine cli,
- PlexusContainer container )
- throws Exception;
+ void invokePlexusComponent(CommandLine cli, PlexusContainer container) throws Exception;
// this can be calculated
String getPomPropertiesPath();
diff --git a/src/site/site.xml b/src/site/site.xml
index 4597f21..adc4a63 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -1,4 +1,15 @@
-
+
+
+
+
+
+
diff --git a/src/test/java/org/codehaus/plexus/tools/cli/CliTest.java b/src/test/java/org/codehaus/plexus/tools/cli/CliTest.java
index 6a44160..b4db53d 100644
--- a/src/test/java/org/codehaus/plexus/tools/cli/CliTest.java
+++ b/src/test/java/org/codehaus/plexus/tools/cli/CliTest.java
@@ -16,40 +16,38 @@
* limitations under the License.
*/
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.util.FileUtils;
-
+import java.io.File;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.io.File;
+
+import org.codehaus.plexus.util.FileUtils;
+import org.junit.jupiter.api.Test;
+
+import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Jason van Zyl
*/
-public class CliTest
- extends PlexusTestCase
-{
- public void testCli()
- throws Exception
- {
- String[] args = new String[]{"-n", getBasedir()};
+class CliTest {
+ @Test
+ void cli() throws Exception {
+ String[] args = new String[] {"-n", getBasedir()};
Class clazz = TestCli.class;
- Method m = clazz.getMethod( "main", new Class[]{String[].class} );
+ Method m = clazz.getMethod("main", new Class[] {String[].class});
int modifiers = m.getModifiers();
- if ( Modifier.isStatic( modifiers ) && Modifier.isPublic( modifiers ) )
- {
- if ( m.getReturnType() == Integer.TYPE || m.getReturnType() == Void.TYPE )
- {
- m.invoke( clazz, new Object[]{args} );
+ if (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers)) {
+ if (m.getReturnType() == Integer.TYPE || m.getReturnType() == Void.TYPE) {
+ m.invoke(clazz, new Object[] {args});
}
}
- String s = FileUtils.fileRead( new File( getBasedir(), "target/cli.txt" ) );
+ String s = FileUtils.fileRead(new File(getBasedir(), "target/cli.txt"));
- assertEquals( "NAME_OPTION_INVOKED", s );
+ assertEquals("NAME_OPTION_INVOKED", s);
}
}
diff --git a/src/test/java/org/codehaus/plexus/tools/cli/TestCli.java b/src/test/java/org/codehaus/plexus/tools/cli/TestCli.java
index 35b1a31..90f487c 100644
--- a/src/test/java/org/codehaus/plexus/tools/cli/TestCli.java
+++ b/src/test/java/org/codehaus/plexus/tools/cli/TestCli.java
@@ -16,45 +16,38 @@
* limitations under the License.
*/
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.util.FileUtils;
-import org.apache.commons.cli.Options;
+import java.io.File;
+
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
-
-import java.io.File;
+import org.apache.commons.cli.Options;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.util.FileUtils;
/**
* @author Jason van Zyl
*/
-public class TestCli
- extends AbstractCli
-{
- public static void main( String[] args )
- throws Exception
- {
- new TestCli().execute( args );
+public class TestCli extends AbstractCli {
+ public static void main(String[] args) throws Exception {
+ new TestCli().execute(args);
}
- public Options buildCliOptions( Options options )
- {
- options.addOption(
- OptionBuilder.withLongOpt( "name" ).withDescription( "Display name." ).hasArg().create( 'n' ) );
+ public Options buildCliOptions(Options options) {
+ options.addOption(OptionBuilder.withLongOpt("name")
+ .withDescription("Display name.")
+ .hasArg()
+ .create('n'));
return options;
}
- public void invokePlexusComponent( CommandLine cli,
- PlexusContainer container )
- throws Exception
- {
- if ( cli.hasOption( 'n' ) )
- {
- String directory = cli.getOptionValue( 'n' );
+ public void invokePlexusComponent(CommandLine cli, PlexusContainer container) throws Exception {
+ if (cli.hasOption('n')) {
+ String directory = cli.getOptionValue('n');
- FileUtils.mkdir( new File( directory, "target" ).getAbsolutePath() );
+ FileUtils.mkdir(new File(directory, "target").getAbsolutePath());
- FileUtils.fileWrite( new File( directory, "target/cli.txt").getAbsolutePath() , "NAME_OPTION_INVOKED" );
+ FileUtils.fileWrite(new File(directory, "target/cli.txt").getAbsolutePath(), "NAME_OPTION_INVOKED");
}
}
}