You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/10/27 13:00:50 UTC

svn commit: r830142 - /maven/maven-3/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java

Author: bentmann
Date: Tue Oct 27 12:00:49 2009
New Revision: 830142

URL: http://svn.apache.org/viewvc?rev=830142&view=rev
Log:
[MNG-4410] [regression] Maven execution does not end after showing usage help
[MNG-4411] [regression] Maven execution does not stop after showing version

Modified:
    maven/maven-3/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java

Modified: maven/maven-3/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java?rev=830142&r1=830141&r2=830142&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java (original)
+++ maven/maven-3/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java Tue Oct 27 12:00:49 2009
@@ -91,8 +91,6 @@
     
     private DefaultSecDispatcher dispatcher;
 
-    private enum Exit { EXIT_WITHOUT_ERROR, EXIT_WITH_ERROR }
-    
     public static void main( String[] args )
     {
         int result = main( args, null );
@@ -113,7 +111,7 @@
         MavenCli cli = new MavenCli();
         return cli.doMain( new CliRequest( args, classWorld ) );
     }
-        
+
     // TODO: need to externalize CliRequest
     public int doMain( CliRequest cliRequest )
     {
@@ -130,8 +128,12 @@
             encryption( cliRequest );                                    
             return execute( cliRequest );
         }
+        catch( ExitException e )
+        {
+            return e.exitCode;
+        }
         catch( Exception e )
-        {            
+        {
             CLIReportingUtils.showError( logger, "Error executing Maven.", e, cliRequest.showErrors );
             
             return 1;
@@ -154,14 +156,14 @@
         if ( cliRequest.stderr == null )
         {
             cliRequest.stderr = System.err;
-        }       
+        }
         
         logger = new PrintStreamLogger( cliRequest.stdout );
 
         if ( cliRequest.workingDirectory == null )
         {
             cliRequest.workingDirectory = System.getProperty( "user.dir" );
-        }                               
+        }
         
         //
         // Make sure the Maven home directory is an absolute path to save us from confusion with say drive-relative
@@ -172,14 +174,14 @@
         if ( mavenHome != null )
         {
             System.setProperty( "maven.home", new File( mavenHome ).getAbsolutePath() );
-        }        
+        }
     }
     
     //
     // Logging needs to be handled in a standard way at the container level.
     //
     private void logging( CliRequest cliRequest )
-    {   
+    {
         cliRequest.debug = cliRequest.commandLine.hasOption( CLIManager.DEBUG );
         cliRequest.quiet = !cliRequest.debug && cliRequest.commandLine.hasOption( CLIManager.QUIET );
         cliRequest.showErrors = cliRequest.debug || cliRequest.commandLine.hasOption( CLIManager.ERRORS );
@@ -230,6 +232,7 @@
     // Every bit of information taken from the CLI should be processed here.
     //
     private void cli( CliRequest cliRequest )
+        throws Exception
     {
         CLIManager cliManager = new CLIManager();
 
@@ -241,7 +244,7 @@
         {
             cliRequest.stderr.println( "Unable to parse command line options: " + e.getMessage() );
             cliManager.displayHelp( cliRequest.stdout );
-            cliRequest.exit = Exit.EXIT_WITH_ERROR;
+            throw e;
         }
 
         // TODO: these should be moved out of here. Wrong place.
@@ -249,15 +252,15 @@
         if ( cliRequest.commandLine.hasOption( CLIManager.HELP ) )
         {
             cliManager.displayHelp( cliRequest.stdout );
-            cliRequest.exit = Exit.EXIT_WITHOUT_ERROR;
+            throw new ExitException( 0 );
         }
 
         if ( cliRequest.commandLine.hasOption( CLIManager.VERSION ) )
         {
             CLIReportingUtils.showVersion( cliRequest.stdout );
-            cliRequest.exit = Exit.EXIT_WITHOUT_ERROR;
-        }        
-    }    
+            throw new ExitException( 0 );
+        }
+    }
         
     private void commands( CliRequest cliRequest )
     {
@@ -282,7 +285,7 @@
         {
             logger.info( "Enabling strict checksum verification on all artifact downloads." );
         }
-    }   
+    }
     
     private void container( CliRequest cliRequest )
         throws Exception
@@ -317,7 +320,7 @@
     
     protected void customizeContainer( PlexusContainer container )
     {
-    }    
+    }
     
     //
     // This should probably be a separate tool and not be baked into Maven.
@@ -332,6 +335,8 @@
             DefaultPlexusCipher cipher = new DefaultPlexusCipher();
 
             cliRequest.stdout.println( cipher.encryptAndDecorate( passwd, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION ) );
+
+            throw new ExitException( 0 );
         }
         else if ( cliRequest.commandLine.hasOption( CLIManager.ENCRYPT_PASSWORD ) )
         {
@@ -356,12 +361,14 @@
 
             if ( master == null )
             {
-                cliRequest.stderr.println( "Master password is not set in the setting security file." );
+                throw new IllegalStateException( "Master password is not set in the setting security file: " + file );
             }
 
             DefaultPlexusCipher cipher = new DefaultPlexusCipher();
             String masterPasswd = cipher.decryptDecorated( master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION );
             cliRequest.stdout.println( cipher.encryptAndDecorate( passwd, masterPasswd ) );
+
+            throw new ExitException( 0 );
         }
     }
     
@@ -877,7 +884,7 @@
     }
     
     static class CliRequest
-    {    
+    {
         String[] args;
         CommandLine commandLine;
         PrintStream stdout;
@@ -889,13 +896,26 @@
         boolean showErrors; 
         PrintStream fileStream;
         MavenExecutionRequest request;
-        Exit exit;
         
         CliRequest( String[] args, ClassWorld classWorld )
         {
             this.args = args;
             this.classWorld = classWorld;
             this.request = new DefaultMavenExecutionRequest();
-        }        
-    }    
+        }
+    }
+
+    static class ExitException
+        extends Exception
+    {
+
+        public int exitCode;
+
+        public ExitException( int exitCode )
+        {
+            this.exitCode = exitCode;
+        }
+
+    }
+
 }