trygvis 2004/04/23 16:01:40
Modified: maven-core/src/main/java/org/apache/maven MavenCli.java
Log:
o Using constants for command line options.
o Added handling of these options:
-h: Prints the help message from commons-cli.
-v: Just prints a stupid message. Needs to get the real
version numer somehow.
-g: Lists all the goals. Very simple and basic listing
for now.
Revision Changes Path
1.2 +50 -11
maven-components/maven-core/src/main/java/org/apache/maven/MavenCli.java
Index: MavenCli.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/MavenCli.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MavenCli.java 16 Apr 2004 13:56:09 -0000 1.1
+++ MavenCli.java 23 Apr 2004 23:01:40 -0000 1.2
@@ -16,6 +16,10 @@
* limitations under the License.
*/
+import java.io.File;
+import java.util.Iterator;
+import java.util.TreeMap;
+
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
@@ -23,10 +27,9 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
-import org.codehaus.classworlds.ClassWorld;
+import org.apache.maven.plugin.descriptor.GoalDescriptor;
-import java.io.File;
-import java.util.Iterator;
+import org.codehaus.classworlds.ClassWorld;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
@@ -42,6 +45,12 @@
private static final String DEBUG = "X";
+ private static final String HELP = "h";
+
+ private static final String VERSION = "v";
+
+ private static final String LIST_GOALS = "g";
+
public static void main( String[] args, ClassWorld classWorld )
throws Exception
{
@@ -55,6 +64,37 @@
File projectFile = new File( System.getProperty( "user.dir" ),
POM_FILE_NAME );
+ if ( commandLine.hasOption( HELP ) )
+ {
+ cliManager.displayHelp();
+
+ return;
+ }
+
+ if ( commandLine.hasOption( VERSION ) )
+ {
+ // TODO: create some sane output.
+ System.out.println( "foo version" );
+
+ return;
+ }
+
+ if ( commandLine.hasOption( LIST_GOALS ) )
+ {
+ Iterator goals = new TreeMap( maven.getGoalDescriptors()
).values().iterator();
+
+ System.out.println( "Goals: " );
+
+ while ( goals.hasNext() )
+ {
+ GoalDescriptor goal = (GoalDescriptor)goals.next();
+
+ System.out.println( " " + goal.getName() );
+ }
+
+ return;
+ }
+
for ( Iterator i = commandLine.getArgList().iterator(); i.hasNext(); )
{
maven.execute( projectFile, (String) i.next() );
@@ -137,7 +177,7 @@
.withLongOpt( "define" )
.hasArg()
.withDescription( "Define a system property" )
- .create( 'D' ) );
+ .create( SET_SYSTEM_PROPERTY ) );
options.addOption( OptionBuilder
.withLongOpt( "dir" )
@@ -153,27 +193,27 @@
options.addOption( OptionBuilder
.withLongOpt( "goalDescriptors" )
.withDescription( "Display available
goalDescriptors" )
- .create( 'g' ) );
+ .create( LIST_GOALS ) );
options.addOption( OptionBuilder
.withLongOpt( "help" )
.withDescription( "Display help information" )
- .create( 'h' ) );
+ .create( HELP ) );
options.addOption( OptionBuilder
.withLongOpt( "offline" )
.withDescription( "Build is happening offline" )
- .create( 'o' ) );
+ .create( WORK_OFFLINE ) );
options.addOption( OptionBuilder
.withLongOpt( "version" )
.withDescription( "Display version information" )
- .create( 'v' ) );
+ .create( VERSION ) );
options.addOption( OptionBuilder
.withLongOpt( "debug" )
.withDescription( "Produce execution debug output" )
- .create( 'X' ) );
+ .create( DEBUG ) );
}
public CommandLine parse( String[] args ) throws ParseException
@@ -188,7 +228,6 @@
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( "maven [options] [goal [goal2 [goal3] ...]]",
"\nOptions:", options, "\n" );
-
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]