dion 2004/01/07 22:45:22
Modified: src/java/org/apache/maven/cli Tag: MAVEN-1_0-BRANCH App.java
Log:
Code cleanup:
- shorten doMain method
Revision Changes Path
No revision
No revision
1.37.4.7 +88 -59 maven/src/java/org/apache/maven/cli/App.java
Index: App.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/cli/App.java,v
retrieving revision 1.37.4.6
retrieving revision 1.37.4.7
diff -u -r1.37.4.6 -r1.37.4.7
--- App.java 7 Jan 2004 16:44:18 -0000 1.37.4.6
+++ App.java 8 Jan 2004 06:45:22 -0000 1.37.4.7
@@ -458,68 +458,17 @@
*/
public void doMain( String[] args, Date fullStart )
{
- boolean done = false;
- int returnCode = RC_OK;
-
- try
- {
- initialize( args );
- }
- catch ( ParseException e )
- {
- log.info( e.getLocalizedMessage() );
- CLIManager.displayHelp();
- returnCode = RC_BAD_ARG;
- done = true;
- }
- catch ( IOException e )
- {
- log.info( e.getLocalizedMessage() );
- returnCode = RC_INIT_ERROR;
- done = true;
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- returnCode = RC_INIT_ERROR;
- done = true;
- }
-
- if ( done )
- {
- log.info( "" );
- exit( returnCode );
- return;
- }
-
- if ( getCli().hasOption( DISPLAY_HELP ) )
- {
- CLIManager.displayHelp();
- log.info( "" );
- exit( returnCode );
- return;
- }
+ initializeMain(args);
- if ( getCli().hasOption( DISPLAY_INFO ) )
- {
- CLIManager.displayInfo();
- log.info( "" );
- exit( returnCode );
- return;
- }
+ displayHelp();
+ displayInfo();
+ displayVersion();
- if ( getCli().hasOption( DISPLAY_VERSION ) )
- {
- printConsoleMavenHeader();
- log.info( "" );
- exit( returnCode );
- return;
- }
+ int returnCode = RC_OK;
if ( !getCli().hasOption( CONSOLE_BANNER ) )
{
printConsoleMavenHeader();
- System.out.println();
}
//printConsoleProjectHeader( project );
@@ -534,9 +483,7 @@
if ( getCli().hasOption( DISPLAY_GOALS ) )
{
displayGoals();
- System.out.println( "" );
exit( returnCode );
- return;
}
else
{
@@ -638,6 +585,85 @@
exit( returnCode );
}
+ /**
+ * Intialize main and exit if failures occur
+ * @param args command line args
+ */
+ private void initializeMain(String[] args)
+ {
+ int returnCode = RC_OK;
+
+ try
+ {
+ initialize( args );
+ }
+ catch ( ParseException e )
+ {
+ log.info( e.getLocalizedMessage() );
+ CLIManager.displayHelp();
+ returnCode = RC_BAD_ARG;
+ }
+ catch ( IOException e )
+ {
+ log.info( e.getLocalizedMessage() );
+ returnCode = RC_INIT_ERROR;
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ returnCode = RC_INIT_ERROR;
+ }
+
+ if ( returnCode != RC_OK )
+ {
+ log.info( "" );
+ exit( returnCode );
+ return;
+ }
+
+ }
+
+ /**
+ * Display the command line help if the option is present, then exit
+ */
+ private void displayHelp()
+ {
+ if ( getCli().hasOption( DISPLAY_HELP ) )
+ {
+ CLIManager.displayHelp();
+ log.info( "" );
+ exit( RC_OK );
+ return;
+ }
+ }
+
+ /**
+ * Display the command line info if the option is present, then exit
+ */
+ private void displayInfo()
+ {
+ if ( getCli().hasOption( DISPLAY_INFO ) )
+ {
+ CLIManager.displayInfo();
+ log.info( "" );
+ exit( RC_OK );
+ return;
+ }
+ }
+
+ /**
+ * Display the Maven version info if the option is present, then exit
+ */
+ private void displayVersion()
+ {
+ if ( getCli().hasOption( DISPLAY_VERSION ) )
+ {
+ printConsoleMavenHeader();
+ exit( RC_OK );
+ return;
+ }
+ }
+
/** Handle an <code>UnattainableGoalException</code>.
*
* @param e The exception.
@@ -772,6 +798,8 @@
System.out.println( "| \\/ |__ _Apache__ ___" );
System.out.println( "| |\\/| / _` \\ V / -_) ' \\ ~ intelligent projects
~" );
System.out.println( "|_| |_\\__,_|\\_/\\___|_||_| v. " +
org.apache.maven.MavenSession.APP_VERSION );
+ System.out.println( "" );
+
}
/**
@@ -943,6 +971,7 @@
{
displayGoalsWithoutDescriptions( list );
}
+ log.info("");
}
/** Display goals without descriptions.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]