maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r584343 [2/3] - in /maven/components/trunk: ./ maven-core/src/main/java/org/apache/maven/ maven-core/src/main/java/org/apache/maven/execution/ maven-core/src/main/java/org/apache/maven/lifecycle/ maven-core/src/main/java/org/apache/maven/pl...
Date Sat, 13 Oct 2007 00:11:02 GMT
Modified: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java?rev=584343&r1=584342&r2=584343&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java (original)
+++ maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java Fri Oct 12 17:10:29 2007
@@ -92,66 +92,52 @@
     {
         options = new Options();
 
-        options.addOption( OptionBuilder.withLongOpt( "file" ).hasArg().withDescription(
-            "Force the use of an alternate POM file." ).create( ALTERNATE_POM_FILE ) );
+        options.addOption( OptionBuilder.hasArg( true ).create( ALTERNATE_POM_FILE ) );
 
         options.addOption(
-            OptionBuilder.withLongOpt( "define" ).hasArg().withDescription( "Define a system property" ).create(
+            OptionBuilder.hasArg( true ).create(
                 SET_SYSTEM_PROPERTY ) );
         options.addOption(
-            OptionBuilder.withLongOpt( "offline" ).withDescription( "Work offline" ).create( OFFLINE ) );
+            OptionBuilder.create( OFFLINE ) );
         options.addOption(
-            OptionBuilder.withLongOpt( "help" ).withDescription( "Display help information" ).create( HELP ) );
+            OptionBuilder.create( HELP ) );
         options.addOption(
-            OptionBuilder.withLongOpt( "version" ).withDescription( "Display version information" ).create(
+            OptionBuilder.create(
                 VERSION ) );
         options.addOption(
-            OptionBuilder.withLongOpt( "quiet" ).withDescription( "Quiet output - only show errors" ).create(
+            OptionBuilder.create(
                 QUIET ) );
         options.addOption(
-            OptionBuilder.withLongOpt( "debug" ).withDescription( "Produce execution debug output" ).create(
+            OptionBuilder.create(
                 DEBUG ) );
         options.addOption(
-            OptionBuilder.withLongOpt( "errors" ).withDescription( "Produce execution error messages" ).create(
+            OptionBuilder.create(
                 ERRORS ) );
-        options.addOption( OptionBuilder.withLongOpt( "reactor" ).withDescription(
-            "Execute goals for project found in the reactor" ).create( REACTOR ) );
-        options.addOption( OptionBuilder.withLongOpt( "non-recursive" ).withDescription(
-            "Do not recurse into sub-projects" ).create( NON_RECURSIVE ) );
-        options.addOption( OptionBuilder.withLongOpt( "update-snapshots" ).withDescription(
-            "Forces a check for updated releases and snapshots on remote repositories" ).create( UPDATE_SNAPSHOTS ) );
-        options.addOption( OptionBuilder.withLongOpt( "activate-profiles" ).withDescription(
-            "Comma-delimited list of profiles to activate" ).hasArg().create( ACTIVATE_PROFILES ) );
-
-        options.addOption( OptionBuilder.withLongOpt( "batch-mode" ).withDescription(
-            "Run in non-interactive (batch) mode" ).create( BATCH_MODE ) );
-
-        options.addOption( OptionBuilder.withLongOpt( "check-plugin-updates" ).withDescription(
-            "Force upToDate check for any relevant registered plugins" ).create( FORCE_PLUGIN_UPDATES ) );
-        options.addOption( OptionBuilder.withLongOpt( "update-plugins" ).withDescription(
-            "Synonym for " + FORCE_PLUGIN_UPDATES ).create( FORCE_PLUGIN_UPDATES2 ) );
-        options.addOption( OptionBuilder.withLongOpt( "no-plugin-updates" ).withDescription(
-            "Suppress upToDate check for any relevant registered plugins" ).create( SUPPRESS_PLUGIN_UPDATES ) );
+        options.addOption( OptionBuilder.create( REACTOR ) );
+        options.addOption( OptionBuilder.create( NON_RECURSIVE ) );
+        options.addOption( OptionBuilder.create( UPDATE_SNAPSHOTS ) );
+        options.addOption( OptionBuilder.hasArg( true ).create( ACTIVATE_PROFILES ) );
+
+        options.addOption( OptionBuilder.create( BATCH_MODE ) );
+
+        options.addOption( OptionBuilder.create( FORCE_PLUGIN_UPDATES ) );
+        options.addOption( OptionBuilder.create( FORCE_PLUGIN_UPDATES2 ) );
+        options.addOption( OptionBuilder.create( SUPPRESS_PLUGIN_UPDATES ) );
 
-        options.addOption(OptionBuilder.withLongOpt("no-snapshot-updates")
-                .withDescription("Supress SNAPSHOT updates")
+        options.addOption(OptionBuilder
                 .create(SUPRESS_SNAPSHOT_UPDATES));
 
-        options.addOption( OptionBuilder.withLongOpt( "no-plugin-registry" ).withDescription(
-            "Don't use ~/.m2/plugin-registry.xml for plugin versions" ).create( SUPPRESS_PLUGIN_REGISTRY ) );
+        options.addOption( OptionBuilder.create( SUPPRESS_PLUGIN_REGISTRY ) );
 
-        options.addOption( OptionBuilder.withLongOpt( "strict-checksums" ).withDescription(
-            "Fail the build if checksums don't match" ).create( CHECKSUM_FAILURE_POLICY ) );
+        options.addOption( OptionBuilder.create( CHECKSUM_FAILURE_POLICY ) );
         options.addOption(
-            OptionBuilder.withLongOpt( "lax-checksums" ).withDescription( "Warn if checksums don't match" ).create(
+            OptionBuilder.create(
                 CHECKSUM_WARNING_POLICY ) );
 
-        options.addOption( OptionBuilder.withLongOpt( "settings" )
-            .withDescription( "Alternate path for the user settings file" ).hasArg()
+        options.addOption( OptionBuilder.hasArg( true )
             .create( ALTERNATE_USER_SETTINGS ) );
 
-        options.addOption( OptionBuilder.withLongOpt( "fail-fast" ).withDescription(
-            "Stop at first failure in reactorized builds" ).create( FAIL_FAST ) );
+        options.addOption( OptionBuilder.create( FAIL_FAST ) );
 
         options.addOption( OptionBuilder.withLongOpt( "fail-at-end" ).withDescription(
             "Only fail the build afterwards; allow all non-impacted builds to continue" ).create( FAIL_AT_END ) );

Added: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java?rev=584343&view=auto
==============================================================================
--- maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java (added)
+++ maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java Fri Oct 12 17:10:29 2007
@@ -0,0 +1,585 @@
+package org.apache.maven.cli;
+
+import org.apache.maven.BuildFailureException;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
+import org.apache.maven.embedder.MavenEmbedderLogger;
+import org.apache.maven.execution.BuildFailure;
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionResult;
+import org.apache.maven.execution.ReactorManager;
+import org.apache.maven.extension.ExtensionScanningException;
+import org.apache.maven.lifecycle.LifecycleExecutionException;
+import org.apache.maven.plugin.AbstractMojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.PluginNotFoundException;
+import org.apache.maven.project.DuplicateProjectException;
+import org.apache.maven.project.InvalidProjectModelException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.reactor.MavenExecutionException;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Properties;
+import java.util.TimeZone;
+
+/**
+ * Utility class used to report errors, statistics, application version info, etc.
+ *
+ * @author jdcasey
+ *
+ */
+public final class CLIReportingUtils
+{
+
+    public static final long MB = 1024 * 1024;
+
+    public static final int MS_PER_SEC = 1000;
+
+    public static final int SEC_PER_MIN = 60;
+
+    public static final String OS_NAME = System.getProperty( "os.name" ).toLowerCase( Locale.US );
+
+    public static final String OS_ARCH = System.getProperty( "os.arch" ).toLowerCase( Locale.US );
+
+    public static final String OS_VERSION = System.getProperty( "os.version" )
+                                                  .toLowerCase( Locale.US );
+
+    private static final String NEWLINE = System.getProperty( "line.separator" );
+
+    private CLIReportingUtils()
+    {
+    }
+
+    static void showVersion()
+    {
+        InputStream resourceAsStream;
+        try
+        {
+            Properties properties = new Properties();
+            resourceAsStream = MavenCli.class.getClassLoader()
+                                             .getResourceAsStream(
+                                                                   "META-INF/maven/org.apache.maven/maven-core/pom.properties" );
+            properties.load( resourceAsStream );
+
+            if ( properties.getProperty( "builtOn" ) != null )
+            {
+                System.out.println( "Maven version: "
+                                    + properties.getProperty( "version", "unknown" ) + " built on "
+                                    + properties.getProperty( "builtOn" ) );
+            }
+            else
+            {
+                System.out.println( "Maven version: "
+                                    + properties.getProperty( "version", "unknown" ) );
+            }
+
+            System.out.println( "Java version: "
+                                + System.getProperty( "java.version", "<unknown java version>" ) );
+
+            //TODO: when plexus can return the family type, add that here because it will make it easier to know what profile activation settings to use.
+            System.out.println( "OS name: \"" + OS_NAME + "\" version: \"" + OS_VERSION
+                                + "\" arch: \"" + OS_ARCH + "\"" );
+        }
+        catch ( IOException e )
+        {
+            System.err.println( "Unable determine version from JAR file: " + e.getMessage() );
+        }
+    }
+
+    static void logResult( MavenExecutionRequest request,
+                           MavenExecutionResult result,
+                           MavenEmbedderLogger logger )
+    {
+        ReactorManager reactorManager = result.getReactorManager();
+
+        logReactorSummary( reactorManager, logger );
+
+        if ( ( reactorManager != null ) && reactorManager.hasBuildFailures() )
+        {
+            logErrors( reactorManager, request.isShowErrors(), logger );
+
+            if ( !ReactorManager.FAIL_NEVER.equals( reactorManager.getFailureBehavior() ) )
+            {
+                logger.info( "BUILD FAILED" );
+
+                line( logger );
+
+                stats( request.getStartTime(), logger );
+
+                line( logger );
+            }
+            else
+            {
+                logger.info( " + Ignoring build failures" );
+            }
+        }
+
+        if ( result.hasExceptions() )
+        {
+            for ( Iterator i = result.getExceptions().iterator(); i.hasNext(); )
+            {
+                Exception e = (Exception) i.next();
+
+                showError( e, request.isShowErrors(), logger );
+            }
+        }
+        else
+        {
+            line( logger );
+
+            logger.info( "BUILD SUCCESSFUL" );
+
+            line( logger );
+
+            stats( request.getStartTime(), logger );
+
+            line( logger );
+        }
+
+        logger.close();
+    }
+
+    private static void logErrors( ReactorManager rm,
+                                   boolean showErrors,
+                                   MavenEmbedderLogger logger )
+    {
+        for ( Iterator it = rm.getSortedProjects().iterator(); it.hasNext(); )
+        {
+            MavenProject project = (MavenProject) it.next();
+
+            if ( rm.hasBuildFailure( project ) )
+            {
+                BuildFailure buildFailure = rm.getBuildFailure( project );
+
+                logger.info( "Error for project: " + project.getName() + " (during "
+                             + buildFailure.getTask() + ")" );
+
+                line( logger );
+            }
+        }
+
+        if ( !showErrors )
+        {
+            logger.info( "For more information, run Maven with the -e switch" );
+
+            line( logger );
+        }
+    }
+
+    static void showError( String message,
+                           Exception e,
+                           boolean showErrors )
+    {
+        showError( message, e, showErrors, new MavenEmbedderConsoleLogger() );
+    }
+
+    static void showError( Exception e, boolean show, MavenEmbedderLogger logger )
+    {
+        showError( null, e, show, logger );
+    }
+
+    static void showError( String message, Exception e,
+                           boolean showStackTraces,
+                           MavenEmbedderLogger logger )
+    {
+        StringWriter writer = new StringWriter();
+
+        writer.write( NEWLINE );
+
+        if ( message != null )
+        {
+            writer.write( message );
+            writer.write( NEWLINE );
+        }
+
+        buildErrorMessage( e, showStackTraces, writer );
+
+        writer.write( NEWLINE );
+
+        if ( showStackTraces )
+        {
+            writer.write( "Error stacktrace:" );
+            writer.write( NEWLINE );
+            e.printStackTrace( new PrintWriter( writer ) );
+
+        }
+        else
+        {
+            writer.write( "For more information, run with the -e flag" );
+        }
+
+        logger.error( writer.toString() );
+    }
+
+    private static void buildErrorMessage( Exception e, boolean showStackTraces, StringWriter writer )
+    {
+        boolean handled = false;
+
+        if ( e instanceof BuildFailureException )
+        {
+            handled = handleBuildFailureException( (BuildFailureException) e, writer );
+        }
+        else if ( e instanceof ProjectBuildingException )
+        {
+            handled = handleProjectBuildingException( (ProjectBuildingException) e, writer );
+        }
+        else if ( e instanceof LifecycleExecutionException )
+        {
+            handled = handleLifecycleExecutionException( (LifecycleExecutionException) e, showStackTraces, writer );
+        }
+        else if ( e instanceof DuplicateProjectException )
+        {
+            handled = handleDuplicateProjectException( (DuplicateProjectException) e, writer );
+        }
+        else if ( e instanceof MavenExecutionException )
+        {
+            handled = handleMavenExecutionException( (MavenExecutionException) e, writer );
+        }
+
+
+        if ( !handled )
+        {
+            handleGenericException( e, writer );
+        }
+    }
+
+    private static boolean handleMavenExecutionException( MavenExecutionException e,
+                                                          StringWriter writer )
+    {
+        writer.write( "While scanning for build extensions:" );
+        writer.write( NEWLINE );
+        writer.write( NEWLINE );
+
+        Throwable cause = e.getCause();
+        if ( cause != null )
+        {
+            if ( cause instanceof IOException )
+            {
+                writer.write( e.getMessage() );
+                writer.write( NEWLINE );
+
+                handleGenericException( cause, writer );
+
+                return true;
+            }
+            else if ( cause instanceof ExtensionScanningException )
+            {
+                Throwable nestedCause = cause.getCause();
+                if ( ( nestedCause != null ) && ( nestedCause instanceof ProjectBuildingException ) )
+                {
+                    return handleProjectBuildingException( (ProjectBuildingException) nestedCause, writer );
+                }
+                else
+                {
+                    handleGenericException( cause, writer );
+
+                    return true;
+                }
+            }
+            else if ( cause instanceof ProjectBuildingException )
+            {
+                return handleProjectBuildingException( (ProjectBuildingException) cause, writer );
+            }
+        }
+
+        return false;
+    }
+
+    private static boolean handleDuplicateProjectException( DuplicateProjectException e,
+                                                            StringWriter writer )
+    {
+        File existing = e.getExistingProjectFile();
+        File conflicting = e.getConflictingProjectFile();
+        String projectId = e.getProjectId();
+
+        writer.write( "Duplicated project detected." );
+        writer.write( NEWLINE );
+        writer.write( NEWLINE );
+        writer.write( "Project: " + projectId );
+        writer.write( NEWLINE );
+        writer.write( "File: " );
+        writer.write( existing.getAbsolutePath() );
+        writer.write( NEWLINE );
+        writer.write( "File: " );
+        writer.write( conflicting.getAbsolutePath() );
+
+        return true;
+    }
+
+    private static void handleGenericException( Throwable exception, StringWriter writer )
+    {
+        writer.write( exception.getMessage() );
+        writer.write( NEWLINE );
+    }
+
+    private static boolean handleLifecycleExecutionException( LifecycleExecutionException e,
+                                                              boolean showStackTraces, StringWriter writer )
+    {
+        Throwable cause = e.getCause();
+        if ( cause != null )
+        {
+            if ( cause instanceof PluginNotFoundException )
+            {
+//                Plugin plugin = ( (PluginNotFoundException) cause ).getPlugin();
+
+                ArtifactNotFoundException artifactException = (ArtifactNotFoundException) ( (PluginNotFoundException) cause ).getCause();
+
+                writer.write( NEWLINE );
+                writer.write( NEWLINE );
+
+                handleGenericException( artifactException, writer );
+
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    private static boolean handleProjectBuildingException( ProjectBuildingException e,
+                                                           StringWriter writer )
+    {
+        boolean result = false;
+
+        Throwable cause = e.getCause();
+        if ( cause instanceof XmlPullParserException )
+        {
+            writer.write( "Error parsing POM:" );
+            writer.write( NEWLINE );
+            writer.write( NEWLINE );
+            writer.write( cause.getMessage() );
+
+            writer.write( NEWLINE );
+            writer.write( NEWLINE );
+            writer.write( "Line: " );
+            writer.write( "" + ( (XmlPullParserException) cause ).getLineNumber() );
+            writer.write( NEWLINE );
+            writer.write( "Column: " );
+            writer.write( "" + ( (XmlPullParserException) cause ).getColumnNumber() );
+
+            result = true;
+        }
+        else if ( e instanceof InvalidProjectModelException )
+        {
+            InvalidProjectModelException error = (InvalidProjectModelException) e;
+            writer.write( error.getMessage() );
+            writer.write( NEWLINE );
+            writer.write( "The following POM validation errors occurred:" );
+            writer.write( NEWLINE );
+
+            for ( Iterator it = error.getValidationResult().getMessages().iterator(); it.hasNext(); )
+            {
+                String message = (String) it.next();
+                writer.write( NEWLINE );
+                writer.write( " - " );
+                writer.write( message );
+            }
+
+            writer.write( NEWLINE );
+            writer.write( NEWLINE );
+
+            result = true;
+        }
+
+        writer.write( NEWLINE );
+        writer.write( "Project Id: " );
+        writer.write( e.getProjectId() );
+        writer.write( NEWLINE );
+        writer.write( "Project File: " );
+        writer.write( e.getPomLocation() );
+        writer.write( NEWLINE );
+
+        return result;
+    }
+
+    private static boolean handleBuildFailureException( BuildFailureException e, StringWriter writer )
+    {
+        Throwable cause = e.getCause();
+        if ( ( cause != null ) && ( cause instanceof MojoFailureException ) )
+        {
+            writer.write( ( (AbstractMojoExecutionException) cause ).getLongMessage() );
+            writer.write( NEWLINE );
+            return true;
+        }
+
+        return false;
+    }
+
+    private static void logReactorSummary( ReactorManager rm,
+                                           MavenEmbedderLogger logger )
+    {
+        if ( ( rm != null ) && rm.hasMultipleProjects() && rm.executedMultipleProjects() )
+        {
+            logger.info( "" );
+            logger.info( "" );
+
+            // -------------------------
+            // Reactor Summary:
+            // -------------------------
+            // o project-name...........FAILED
+            // o project2-name..........SKIPPED (dependency build failed or was skipped)
+            // o project-3-name.........SUCCESS
+
+            line( logger );
+            logger.info( "Reactor Summary:" );
+            line( logger );
+
+            for ( Iterator it = rm.getSortedProjects().iterator(); it.hasNext(); )
+            {
+                MavenProject project = (MavenProject) it.next();
+
+                if ( rm.hasBuildFailure( project ) )
+                {
+                    logReactorSummaryLine( project.getName(), "FAILED",
+                                           rm.getBuildFailure( project ).getTime(), logger );
+                }
+                else if ( rm.isBlackListed( project ) )
+                {
+                    logReactorSummaryLine( project.getName(),
+                                           "SKIPPED (dependency build failed or was skipped)",
+                                           logger );
+                }
+                else if ( rm.hasBuildSuccess( project ) )
+                {
+                    logReactorSummaryLine( project.getName(), "SUCCESS",
+                                           rm.getBuildSuccess( project ).getTime(),
+                                           logger );
+                }
+                else
+                {
+                    logReactorSummaryLine( project.getName(), "NOT BUILT", logger );
+                }
+            }
+            line( logger );
+        }
+    }
+
+    private static void stats( Date start,
+                               MavenEmbedderLogger logger )
+    {
+        Date finish = new Date();
+
+        long time = finish.getTime() - start.getTime();
+
+        logger.info( "Total time: " + formatTime( time ) );
+
+        logger.info( "Finished at: " + finish );
+
+        //noinspection CallToSystemGC
+        System.gc();
+
+        Runtime r = Runtime.getRuntime();
+
+        logger.info( "Final Memory: " + ( r.totalMemory() - r.freeMemory() ) / MB + "M/"
+                     + r.totalMemory() / MB + "M" );
+    }
+
+    private static void line( MavenEmbedderLogger logger )
+    {
+        logger.info( "------------------------------------------------------------------------" );
+    }
+
+    private static String formatTime( long ms )
+    {
+        long secs = ms / MS_PER_SEC;
+
+        long min = secs / SEC_PER_MIN;
+
+        secs = secs % SEC_PER_MIN;
+
+        String msg = "";
+
+        if ( min > 1 )
+        {
+            msg = min + " minutes ";
+        }
+        else if ( min == 1 )
+        {
+            msg = "1 minute ";
+        }
+
+        if ( secs > 1 )
+        {
+            msg += secs + " seconds";
+        }
+        else if ( secs == 1 )
+        {
+            msg += "1 second";
+        }
+        else if ( min == 0 )
+        {
+            msg += "< 1 second";
+        }
+        return msg;
+    }
+
+    private static void logReactorSummaryLine( String name,
+                                               String status,
+                                               MavenEmbedderLogger logger )
+    {
+        logReactorSummaryLine( name, status, -1, logger );
+    }
+
+    private static void logReactorSummaryLine( String name,
+                                               String status,
+                                               long time,
+                                               MavenEmbedderLogger logger )
+    {
+        StringBuffer messageBuffer = new StringBuffer();
+
+        messageBuffer.append( name );
+
+        int dotCount = 54;
+
+        dotCount -= name.length();
+
+        messageBuffer.append( " " );
+
+        for ( int i = 0; i < dotCount; i++ )
+        {
+            messageBuffer.append( '.' );
+        }
+
+        messageBuffer.append( " " );
+
+        messageBuffer.append( status );
+
+        if ( time >= 0 )
+        {
+            messageBuffer.append( " [" );
+
+            messageBuffer.append( getFormattedTime( time ) );
+
+            messageBuffer.append( "]" );
+        }
+
+        logger.info( messageBuffer.toString() );
+    }
+
+    private static String getFormattedTime( long time )
+    {
+        String pattern = "s.SSS's'";
+        if ( time / 60000L > 0 )
+        {
+            pattern = "m:s" + pattern;
+            if ( time / 3600000L > 0 )
+            {
+                pattern = "H:m" + pattern;
+            }
+        }
+        DateFormat fmt = new SimpleDateFormat( pattern );
+        fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
+        return fmt.format( new Date( time ) );
+    }
+}

Propchange: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java?rev=584343&view=auto
==============================================================================
--- maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java (added)
+++ maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java Fri Oct 12 17:10:29 2007
@@ -0,0 +1,281 @@
+package org.apache.maven.cli;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.maven.MavenTransferListener;
+import org.apache.maven.execution.DefaultMavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionRequest;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+public final class CLIRequestUtils
+{
+
+    private CLIRequestUtils()
+    {
+    }
+
+    public static MavenExecutionRequest buildRequest( CommandLine commandLine, boolean debug, boolean quiet, boolean showErrors )
+    {
+        // ----------------------------------------------------------------------
+        // Now that we have everything that we need we will fire up plexus and
+        // bring the maven component to life for use.
+        // ----------------------------------------------------------------------
+
+        boolean interactive = true;
+
+        if ( commandLine.hasOption( CLIManager.BATCH_MODE ) )
+        {
+            interactive = false;
+        }
+
+        boolean pluginUpdateOverride = false;
+
+        if ( commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES ) ||
+            commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES2 ) )
+        {
+            pluginUpdateOverride = true;
+        }
+        else if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_UPDATES ) )
+        {
+            pluginUpdateOverride = false;
+        }
+
+        boolean noSnapshotUpdates = false;
+        if ( commandLine.hasOption( CLIManager.SUPRESS_SNAPSHOT_UPDATES ) )
+        {
+            noSnapshotUpdates = true;
+        }
+
+        // ----------------------------------------------------------------------
+        //
+        // ----------------------------------------------------------------------
+
+        List goals = commandLine.getArgList();
+
+        boolean recursive = true;
+
+        // this is the default behavior.
+        String reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST;
+
+        if ( commandLine.hasOption( CLIManager.NON_RECURSIVE ) )
+        {
+            recursive = false;
+        }
+
+        if ( commandLine.hasOption( CLIManager.FAIL_FAST ) )
+        {
+            reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST;
+        }
+        else if ( commandLine.hasOption( CLIManager.FAIL_AT_END ) )
+        {
+            reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_AT_END;
+        }
+        else if ( commandLine.hasOption( CLIManager.FAIL_NEVER ) )
+        {
+            reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_NEVER;
+        }
+
+        boolean offline = false;
+
+        if ( commandLine.hasOption( CLIManager.OFFLINE ) )
+        {
+            offline = true;
+        }
+
+        boolean updateSnapshots = false;
+
+        if ( commandLine.hasOption( CLIManager.UPDATE_SNAPSHOTS ) )
+        {
+            updateSnapshots = true;
+        }
+
+        String globalChecksumPolicy = null;
+
+        if ( commandLine.hasOption( CLIManager.CHECKSUM_FAILURE_POLICY ) )
+        {
+            // todo; log
+            System.out.println( "+ Enabling strict checksum verification on all artifact downloads." );
+
+            globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_FAIL;
+        }
+        else if ( commandLine.hasOption( CLIManager.CHECKSUM_WARNING_POLICY ) )
+        {
+            // todo: log
+            System.out.println( "+ Disabling strict checksum verification on all artifact downloads." );
+
+            globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN;
+        }
+
+        File baseDirectory = new File( System.getProperty( "user.dir" ) );
+
+        // ----------------------------------------------------------------------
+        // Profile Activation
+        // ----------------------------------------------------------------------
+
+        List activeProfiles = new ArrayList();
+
+        List inactiveProfiles = new ArrayList();
+
+        if ( commandLine.hasOption( CLIManager.ACTIVATE_PROFILES ) )
+        {
+            String profilesLine = commandLine.getOptionValue( CLIManager.ACTIVATE_PROFILES );
+
+            StringTokenizer profileTokens = new StringTokenizer( profilesLine, "," );
+
+            while ( profileTokens.hasMoreTokens() )
+            {
+                String profileAction = profileTokens.nextToken().trim();
+
+                if ( profileAction.startsWith( "-" ) )
+                {
+                    activeProfiles.add( profileAction.substring( 1 ) );
+                }
+                else if ( profileAction.startsWith( "+" ) )
+                {
+                    inactiveProfiles.add( profileAction.substring( 1 ) );
+                }
+                else
+                {
+                    // TODO: deprecate this eventually!
+                    activeProfiles.add( profileAction );
+                }
+            }
+        }
+
+        MavenTransferListener transferListener;
+
+        if ( interactive )
+        {
+            transferListener = new ConsoleDownloadMonitor();
+        }
+        else
+        {
+            transferListener = new BatchModeDownloadMonitor();
+        }
+
+        transferListener.setShowChecksumEvents( false );
+
+        // This means to scan a directory structure for POMs and process them.
+        boolean useReactor = false;
+
+        if ( commandLine.hasOption( CLIManager.REACTOR ) )
+        {
+            useReactor = true;
+        }
+
+        String alternatePomFile = null;
+        if ( commandLine.hasOption( CLIManager.ALTERNATE_POM_FILE ) )
+        {
+            alternatePomFile = commandLine.getOptionValue( CLIManager.ALTERNATE_POM_FILE );
+        }
+
+        int loggingLevel;
+
+        if ( debug )
+        {
+            loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_DEBUG;
+        }
+        else if ( quiet )
+        {
+            // TODO: we need to do some more work here. Some plugins use sys out or log errors at info level.
+            // Ideally, we could use Warn across the board
+            loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_ERROR;
+            // TODO:Additionally, we can't change the mojo level because the component key includes the version and it isn't known ahead of time. This seems worth changing.
+        }
+        else
+        {
+            loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_INFO;
+        }
+
+        Properties executionProperties = getExecutionProperties( commandLine );
+
+        return new DefaultMavenExecutionRequest()
+            .setBaseDirectory( baseDirectory )
+            .setGoals( goals )
+            .setProperties( executionProperties ) // optional
+            .setReactorFailureBehavior( reactorFailureBehaviour ) // default: fail fast
+            .setRecursive( recursive ) // default: true
+            .setUseReactor( useReactor ) // default: false
+            .setPomFile( alternatePomFile ) // optional
+            .setShowErrors( showErrors ) // default: false
+            .setInteractiveMode( interactive ) // default: false
+            .setOffline( offline ) // default: false
+            .setUsePluginUpdateOverride( pluginUpdateOverride )
+            .addActiveProfiles( activeProfiles ) // optional
+            .addInactiveProfiles( inactiveProfiles ) // optional
+            .setLoggingLevel( loggingLevel ) // default: info
+            .setTransferListener( transferListener ) // default: batch mode which goes along with interactive
+            .setUpdateSnapshots( updateSnapshots ) // default: false
+            .setNoSnapshotUpdates( noSnapshotUpdates ) // default: false
+            .setGlobalChecksumPolicy( globalChecksumPolicy ); // default: warn
+    }
+
+    // ----------------------------------------------------------------------
+    // System properties handling
+    // ----------------------------------------------------------------------
+
+    private static Properties getExecutionProperties( CommandLine commandLine )
+    {
+        Properties executionProperties = new Properties();
+
+        // ----------------------------------------------------------------------
+        // Options that are set on the command line become system properties
+        // and therefore are set in the session properties. System properties
+        // are most dominant.
+        // ----------------------------------------------------------------------
+
+        if ( commandLine.hasOption( CLIManager.SET_SYSTEM_PROPERTY ) )
+        {
+            String[] defStrs = commandLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY );
+
+            if ( defStrs != null )
+            {
+                for ( int i = 0; i < defStrs.length; ++i )
+                {
+                    setCliProperty( defStrs[i], executionProperties );
+                }
+            }
+        }
+
+        executionProperties.putAll( System.getProperties() );
+
+        return executionProperties;
+    }
+
+    private static void setCliProperty( String property,
+                                        Properties executionProperties )
+    {
+        String name;
+
+        String value;
+
+        int i = property.indexOf( "=" );
+
+        if ( i <= 0 )
+        {
+            name = property.trim();
+
+            value = "true";
+        }
+        else
+        {
+            name = property.substring( 0, i ).trim();
+
+            value = property.substring( i + 1 ).trim();
+        }
+
+        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 );
+    }
+
+}

Propchange: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java?rev=584343&r1=584342&r2=584343&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java (original)
+++ maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java Fri Oct 12 17:10:29 2007
@@ -21,8 +21,6 @@
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.ParseException;
-import org.apache.maven.BuildFailureException;
-import org.apache.maven.MavenTransferListener;
 import org.apache.maven.embedder.Configuration;
 import org.apache.maven.embedder.ConfigurationValidationResult;
 import org.apache.maven.embedder.DefaultConfiguration;
@@ -31,28 +29,11 @@
 import org.apache.maven.embedder.MavenEmbedderException;
 import org.apache.maven.embedder.MavenEmbedderFileLogger;
 import org.apache.maven.embedder.MavenEmbedderLogger;
-import org.apache.maven.execution.BuildFailure;
-import org.apache.maven.execution.DefaultMavenExecutionRequest;
 import org.apache.maven.execution.MavenExecutionRequest;
 import org.apache.maven.execution.MavenExecutionResult;
-import org.apache.maven.execution.ReactorManager;
-import org.apache.maven.plugin.AbstractMojoExecutionException;
-import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.classworlds.ClassWorld;
 
 import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Properties;
-import java.util.StringTokenizer;
-import java.util.TimeZone;
 
 /**
  * @author jason van zyl
@@ -63,12 +44,6 @@
 {
     public static final String LOCAL_REPO_PROPERTY = "maven.repo.local";
 
-    public static final String OS_NAME = System.getProperty( "os.name" ).toLowerCase( Locale.US );
-
-    public static final String OS_ARCH = System.getProperty( "os.arch" ).toLowerCase( Locale.US );
-
-    public static final String OS_VERSION = System.getProperty( "os.version" ).toLowerCase( Locale.US );
-
     public static void main( String[] args )
     {
         ClassWorld classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() );
@@ -148,262 +123,37 @@
 
         if ( commandLine.hasOption( CLIManager.VERSION ) )
         {
-            showVersion();
+            CLIReportingUtils.showVersion();
 
             return 0;
         }
         else if ( debug )
         {
-            showVersion();
-        }
-
-        // ----------------------------------------------------------------------
-        // Now that we have everything that we need we will fire up plexus and
-        // bring the maven component to life for use.
-        // ----------------------------------------------------------------------
-
-        boolean interactive = true;
-
-        if ( commandLine.hasOption( CLIManager.BATCH_MODE ) )
-        {
-            interactive = false;
-        }
-
-        boolean pluginUpdateOverride = false;
-
-        if ( commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES ) ||
-            commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES2 ) )
-        {
-            pluginUpdateOverride = true;
-        }
-        else if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_UPDATES ) )
-        {
-            pluginUpdateOverride = false;
-        }
-
-        boolean noSnapshotUpdates = false;
-        if ( commandLine.hasOption( CLIManager.SUPRESS_SNAPSHOT_UPDATES ) )
-        {
-            noSnapshotUpdates = true;
-        }
-
-        // ----------------------------------------------------------------------
-        //
-        // ----------------------------------------------------------------------
-
-        List goals = commandLine.getArgList();
-
-        boolean recursive = true;
-
-        // this is the default behavior.
-        String reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST;
-
-        if ( commandLine.hasOption( CLIManager.NON_RECURSIVE ) )
-        {
-            recursive = false;
-        }
-
-        if ( commandLine.hasOption( CLIManager.FAIL_FAST ) )
-        {
-            reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST;
-        }
-        else if ( commandLine.hasOption( CLIManager.FAIL_AT_END ) )
-        {
-            reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_AT_END;
-        }
-        else if ( commandLine.hasOption( CLIManager.FAIL_NEVER ) )
-        {
-            reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_NEVER;
-        }
-
-        boolean offline = false;
-
-        if ( commandLine.hasOption( CLIManager.OFFLINE ) )
-        {
-            offline = true;
-        }
-
-        boolean updateSnapshots = false;
-
-        if ( commandLine.hasOption( CLIManager.UPDATE_SNAPSHOTS ) )
-        {
-            updateSnapshots = true;
-        }
-
-        String globalChecksumPolicy = null;
-
-        if ( commandLine.hasOption( CLIManager.CHECKSUM_FAILURE_POLICY ) )
-        {
-            // todo; log
-            System.out.println( "+ Enabling strict checksum verification on all artifact downloads." );
-
-            globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_FAIL;
-        }
-        else if ( commandLine.hasOption( CLIManager.CHECKSUM_WARNING_POLICY ) )
-        {
-            // todo: log
-            System.out.println( "+ Disabling strict checksum verification on all artifact downloads." );
-
-            globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN;
-        }
-
-        File baseDirectory = new File( System.getProperty( "user.dir" ) );
-
-        // ----------------------------------------------------------------------
-        // Profile Activation
-        // ----------------------------------------------------------------------
-
-        List activeProfiles = new ArrayList();
-
-        List inactiveProfiles = new ArrayList();
-
-        if ( commandLine.hasOption( CLIManager.ACTIVATE_PROFILES ) )
-        {
-            String profilesLine = commandLine.getOptionValue( CLIManager.ACTIVATE_PROFILES );
-
-            StringTokenizer profileTokens = new StringTokenizer( profilesLine, "," );
-
-            while ( profileTokens.hasMoreTokens() )
-            {
-                String profileAction = profileTokens.nextToken().trim();
-
-                if ( profileAction.startsWith( "-" ) )
-                {
-                    activeProfiles.add( profileAction.substring( 1 ) );
-                }
-                else if ( profileAction.startsWith( "+" ) )
-                {
-                    inactiveProfiles.add( profileAction.substring( 1 ) );
-                }
-                else
-                {
-                    // TODO: deprecate this eventually!
-                    activeProfiles.add( profileAction );
-                }
-            }
-        }
-
-        MavenTransferListener transferListener;
-
-        if ( interactive )
-        {
-            transferListener = new ConsoleDownloadMonitor();
-        }
-        else
-        {
-            transferListener = new BatchModeDownloadMonitor();
-        }
-
-        transferListener.setShowChecksumEvents( false );
-
-        // This means to scan a directory structure for POMs and process them.
-        boolean useReactor = false;
-
-        if ( commandLine.hasOption( CLIManager.REACTOR ) )
-        {
-            useReactor = true;
-        }
-
-        String alternatePomFile = null;
-        if ( commandLine.hasOption( CLIManager.ALTERNATE_POM_FILE ) )
-        {
-            alternatePomFile = commandLine.getOptionValue( CLIManager.ALTERNATE_POM_FILE );
-        }
-
-        int loggingLevel;
-
-        if ( debug )
-        {
-            loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_DEBUG;
+            CLIReportingUtils.showVersion();
         }
-        else if ( quiet )
-        {
-            // TODO: we need to do some more work here. Some plugins use sys out or log errors at info level.
-            // Ideally, we could use Warn across the board
-            loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_ERROR;
-            // TODO:Additionally, we can't change the mojo level because the component key includes the version and it isn't known ahead of time. This seems worth changing.
-        }
-        else
-        {
-            loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_INFO;
-        }
-
-        Properties executionProperties = getExecutionProperties( commandLine );
-
-        MavenExecutionRequest request = new DefaultMavenExecutionRequest()
-            .setBaseDirectory( baseDirectory )
-            .setGoals( goals )
-            .setProperties( executionProperties ) // optional
-            .setReactorFailureBehavior( reactorFailureBehaviour ) // default: fail fast
-            .setRecursive( recursive ) // default: true
-            .setUseReactor( useReactor ) // default: false
-            .setPomFile( alternatePomFile ) // optional
-            .setShowErrors( showErrors ) // default: false
-            .setInteractiveMode( interactive ) // default: false
-            .setOffline( offline ) // default: false
-            .setUsePluginUpdateOverride( pluginUpdateOverride )
-            .addActiveProfiles( activeProfiles ) // optional
-            .addInactiveProfiles( inactiveProfiles ) // optional
-            .setLoggingLevel( loggingLevel ) // default: info
-            .setTransferListener( transferListener ) // default: batch mode which goes along with interactive
-            .setUpdateSnapshots( updateSnapshots ) // default: false
-            .setNoSnapshotUpdates( noSnapshotUpdates ) // default: false
-            .setGlobalChecksumPolicy( globalChecksumPolicy ); // default: warn
 
-        File userSettingsFile;
-
-        if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_SETTINGS ) )
-        {
-            userSettingsFile = new File( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_SETTINGS ) );
-        }
-        else
-        {
-            userSettingsFile =  MavenEmbedder.DEFAULT_USER_SETTINGS_FILE;
-        }
+        MavenExecutionRequest request = CLIRequestUtils.buildRequest( commandLine, debug, quiet, showErrors );
 
-        Configuration configuration = new DefaultConfiguration()
-            .setUserSettingsFile( userSettingsFile )
-            .setGlobalSettingsFile( MavenEmbedder.DEFAULT_GLOBAL_SETTINGS_FILE )
-            .setClassWorld( classWorld );
-
-        if ( commandLine.hasOption( CLIManager.LOG_FILE ) )
-        {
-            File logFile = new File(
-                baseDirectory,
-                commandLine.getOptionValue( CLIManager.LOG_FILE ) );
-
-            configuration.setMavenEmbedderLogger( new MavenEmbedderFileLogger( logFile ) );
-        }
-        else
-        {
-            configuration.setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
-        }
+        Configuration configuration = buildEmbedderConfiguration( request, commandLine, classWorld );
 
         ConfigurationValidationResult cvr = MavenEmbedder.validateConfiguration( configuration );
 
         if ( cvr.isUserSettingsFilePresent() && !cvr.isUserSettingsFileParses() )
         {
-            showError( "Error reading user settings: ", cvr.getUserSettingsException(), showErrors );
+            CLIReportingUtils.showError( "Error reading user settings: ", cvr.getUserSettingsException(), showErrors );
 
             return 1;
         }
 
         if ( cvr.isGlobalSettingsFilePresent() && !cvr.isGlobalSettingsFileParses() )
         {
-            showError( "Error reading global settings: ", cvr.getGlobalSettingsException(), showErrors );
+            CLIReportingUtils.showError( "Error reading global settings: ", cvr.getGlobalSettingsException(), showErrors );
 
             return 1;
         }
 
-        String localRepoProperty = executionProperties.getProperty( LOCAL_REPO_PROPERTY );
-
-        if ( localRepoProperty != null )
-        {
-            configuration.setLocalRepository( new File( localRepoProperty ) );
-        }
-
         MavenEmbedder mavenEmbedder;
-
+        MavenEmbedderLogger logger;
         try
         {
             mavenEmbedder = new MavenEmbedder( configuration );
@@ -412,14 +162,14 @@
         }
         catch ( MavenEmbedderException e )
         {
-            showError( "Unable to start the embedder: ", e, showErrors );
+            CLIReportingUtils.showError( "Unable to start the embedder: ", e, showErrors );
 
             return 1;
         }
 
         MavenExecutionResult result = mavenEmbedder.execute( request );
 
-        logResult( request, result );
+        CLIReportingUtils.logResult( request, result, logger );
 
         if ( result.hasExceptions() )
         {
@@ -431,423 +181,45 @@
         }
     }
 
-    private static void showVersion()
-    {
-        InputStream resourceAsStream;
-        try
-        {
-            Properties properties = new Properties();
-            resourceAsStream = MavenCli.class.getClassLoader().getResourceAsStream(
-                "META-INF/maven/org.apache.maven/maven-core/pom.properties" );
-            properties.load( resourceAsStream );
-
-            if ( properties.getProperty( "builtOn" ) != null )
-            {
-                System.out.println( "Maven version: " + properties.getProperty( "version", "unknown" ) + " built on " +
-                    properties.getProperty( "builtOn" ) );
-            }
-            else
-            {
-                System.out.println( "Maven version: " + properties.getProperty( "version", "unknown" ) );
-            }
-
-            System.out.println( "Java version: " + System.getProperty( "java.version", "<unknown java version>" ) );
-
-            //TODO: when plexus can return the family type, add that here because it will make it easier to know what profile activation settings to use.
-            System.out.println( "OS name: \"" + OS_NAME + "\" version: \"" + OS_VERSION + "\" arch: \"" + OS_ARCH + "\"" );
-        }
-        catch ( IOException e )
-        {
-            System.err.println( "Unable determine version from JAR file: " + e.getMessage() );
-        }
-    }
-
-    // ----------------------------------------------------------------------
-    // System properties handling
-    // ----------------------------------------------------------------------
-
-    private static Properties getExecutionProperties( CommandLine commandLine )
-    {
-        Properties executionProperties = new Properties();
-
-        // ----------------------------------------------------------------------
-        // Options that are set on the command line become system properties
-        // and therefore are set in the session properties. System properties
-        // are most dominant.
-        // ----------------------------------------------------------------------
-
-        if ( commandLine.hasOption( CLIManager.SET_SYSTEM_PROPERTY ) )
-        {
-            String[] defStrs = commandLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY );
-
-            for ( int i = 0; i < defStrs.length; ++i )
-            {
-                setCliProperty( defStrs[i], executionProperties );
-            }
-        }
-
-        executionProperties.putAll( System.getProperties() );
-
-        return executionProperties;
-    }
-
-    private static void setCliProperty( String property,
-                                        Properties executionProperties )
-    {
-        String name;
-
-        String value;
-
-        int i = property.indexOf( "=" );
-
-        if ( i <= 0 )
-        {
-            name = property.trim();
-
-            value = "true";
-        }
-        else
-        {
-            name = property.substring( 0, i ).trim();
-
-            value = property.substring( i + 1 ).trim();
-        }
-
-        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 );
-    }
-
-    // ----------------------------------------------------------------------
-    // Reporting / Logging
-    // ----------------------------------------------------------------------
-
-    private static final long MB = 1024 * 1024;
-
-    private static final int MS_PER_SEC = 1000;
-
-    private static final int SEC_PER_MIN = 60;
-
-    private MavenEmbedderLogger logger;
-
-    private MavenEmbedderLogger getLogger()
-    {
-        return logger;
-    }
-
-    private void logResult( MavenExecutionRequest request, MavenExecutionResult result )
+    private Configuration buildEmbedderConfiguration( MavenExecutionRequest request, CommandLine commandLine, ClassWorld classWorld )
     {
-        ReactorManager reactorManager = result.getReactorManager();
-
-        logReactorSummary( reactorManager );
-
-        if ( ( reactorManager != null ) && reactorManager.hasBuildFailures() )
-        {
-            logErrors(
-                reactorManager,
-                request.isShowErrors() );
-
-            if ( !ReactorManager.FAIL_NEVER.equals( reactorManager.getFailureBehavior() ) )
-            {
-                getLogger().info( "BUILD ERRORS" );
-
-                line();
-
-                stats( request.getStartTime() );
-
-                line();
-            }
-            else
-            {
-                getLogger().info( " + Ignoring failures" );
-            }
-        }
-
-        if ( result.hasExceptions() )
-        {
-            for ( Iterator i = result.getExceptions().iterator(); i.hasNext(); )
-            {
-                Exception e = (Exception) i.next();
-
-                if ( e instanceof BuildFailureException )
-                {
-                    showFailure( e, request.isShowErrors() );
-                }
-                else
-                {
-                    showError( e.getMessage(), e, request.isShowErrors() );
-                }
-            }
-        }
-        else
-        {
-            line();
-
-            getLogger().info( "BUILD SUCCESSFUL" );
-
-            line();
-
-            stats( request.getStartTime() );
-
-            line();
-        }
-
-        logger.close();
-    }
-
-    private void logErrors( ReactorManager rm,
-                            boolean showErrors )
-    {
-        for ( Iterator it = rm.getSortedProjects().iterator(); it.hasNext(); )
-        {
-            MavenProject project = (MavenProject) it.next();
-
-            if ( rm.hasBuildFailure( project ) )
-            {
-                BuildFailure buildFailure = rm.getBuildFailure( project );
-
-                getLogger().info(
-                    "Error for project: " + project.getName() + " (during " + buildFailure.getTask() + ")" );
-
-                line();
-            }
-        }
-
-        if ( !showErrors )
-        {
-            getLogger().info( "For more information, run Maven with the -e switch" );
-
-            line();
-        }
-    }
-
-    private static void showFailure( Exception e,
-                                   boolean show )
-    {
-        String message = e.getMessage();
-        Throwable cause = e.getCause();
-        if ( ( cause != null ) && ( cause instanceof AbstractMojoExecutionException ) )
-        {
-            message = ((AbstractMojoExecutionException)cause).getLongMessage();
-            if ( message == null )
-            {
-                message = cause.getMessage();
-            }
-        }
-        else
-        {
-            cause = e;
-        }
-
-        System.err.println();
-        System.err.println( message );
-        System.err.println();
+        File userSettingsFile;
 
-        if ( show )
+        if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_SETTINGS ) )
         {
-            System.err.println( "Error stacktrace:" );
-
-            cause.printStackTrace();
+            userSettingsFile = new File( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_SETTINGS ) );
         }
         else
         {
-            System.err.println( "For more information, run with the -e flag" );
+            userSettingsFile =  MavenEmbedder.DEFAULT_USER_SETTINGS_FILE;
         }
-    }
 
-    private static void showError( String message,
-                                   Exception e,
-                                   boolean show )
-    {
-        System.err.println();
-        System.err.println( message );
-        System.err.println();
+        Configuration configuration = new DefaultConfiguration()
+            .setUserSettingsFile( userSettingsFile )
+            .setGlobalSettingsFile( MavenEmbedder.DEFAULT_GLOBAL_SETTINGS_FILE )
+            .setClassWorld( classWorld );
 
-        if ( show )
+        if ( commandLine.hasOption( CLIManager.LOG_FILE ) )
         {
-            System.err.println( "Error stacktrace:" );
+            File logFile = new File(
+                request.getBaseDirectory(),
+                commandLine.getOptionValue( CLIManager.LOG_FILE ) );
 
-            e.printStackTrace();
+            configuration.setMavenEmbedderLogger( new MavenEmbedderFileLogger( logFile ) );
         }
         else
         {
-            System.err.println( "For more information, run with the -e flag" );
-        }
-    }
-
-    private void logReactorSummary( ReactorManager rm )
-    {
-        if ( ( rm != null ) && rm.hasMultipleProjects() && rm.executedMultipleProjects() )
-        {
-            getLogger().info( "" );
-            getLogger().info( "" );
-
-            // -------------------------
-            // Reactor Summary:
-            // -------------------------
-            // o project-name...........FAILED
-            // o project2-name..........SKIPPED (dependency build failed or was skipped)
-            // o project-3-name.........SUCCESS
-
-            line();
-            getLogger().info( "Reactor Summary:" );
-            line();
-
-            for ( Iterator it = rm.getSortedProjects().iterator(); it.hasNext(); )
-            {
-                MavenProject project = (MavenProject) it.next();
-
-                if ( rm.hasBuildFailure( project ) )
-                {
-                    logReactorSummaryLine(
-                        project.getName(),
-                        "FAILED",
-                        rm.getBuildFailure( project ).getTime() );
-                }
-                else if ( rm.isBlackListed( project ) )
-                {
-                    logReactorSummaryLine(
-                        project.getName(),
-                        "SKIPPED (dependency build failed or was skipped)" );
-                }
-                else if ( rm.hasBuildSuccess( project ) )
-                {
-                    logReactorSummaryLine(
-                        project.getName(),
-                        "SUCCESS",
-                        rm.getBuildSuccess( project ).getTime() );
-                }
-                else
-                {
-                    logReactorSummaryLine(
-                        project.getName(),
-                        "NOT BUILT" );
-                }
-            }
-            line();
-        }
-    }
-
-    private void stats( Date start )
-    {
-        Date finish = new Date();
-
-        long time = finish.getTime() - start.getTime();
-
-        getLogger().info( "Total time: " + formatTime( time ) );
-
-        getLogger().info( "Finished at: " + finish );
-
-        //noinspection CallToSystemGC
-        System.gc();
-
-        Runtime r = Runtime.getRuntime();
-
-        getLogger().info(
-            "Final Memory: " + ( r.totalMemory() - r.freeMemory() ) / MB + "M/" + r.totalMemory() / MB + "M" );
-    }
-
-    private void line()
-    {
-        getLogger().info( "------------------------------------------------------------------------" );
-    }
-
-    private static String formatTime( long ms )
-    {
-        long secs = ms / MS_PER_SEC;
-
-        long min = secs / SEC_PER_MIN;
-
-        secs = secs % SEC_PER_MIN;
-
-        String msg = "";
-
-        if ( min > 1 )
-        {
-            msg = min + " minutes ";
-        }
-        else if ( min == 1 )
-        {
-            msg = "1 minute ";
-        }
-
-        if ( secs > 1 )
-        {
-            msg += secs + " seconds";
-        }
-        else if ( secs == 1 )
-        {
-            msg += "1 second";
-        }
-        else if ( min == 0 )
-        {
-            msg += "< 1 second";
-        }
-        return msg;
-    }
-
-    private void logReactorSummaryLine( String name,
-                                        String status )
-    {
-        logReactorSummaryLine(
-            name,
-            status,
-            -1 );
-    }
-
-    private void logReactorSummaryLine( String name,
-                                        String status,
-                                        long time )
-    {
-        StringBuffer messageBuffer = new StringBuffer();
-
-        messageBuffer.append( name );
-
-        int dotCount = 54;
-
-        dotCount -= name.length();
-
-        messageBuffer.append( " " );
-
-        for ( int i = 0; i < dotCount; i++ )
-        {
-            messageBuffer.append( '.' );
+            configuration.setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
         }
 
-        messageBuffer.append( " " );
+        String localRepoProperty = request.getProperties().getProperty( LOCAL_REPO_PROPERTY );
 
-        messageBuffer.append( status );
-
-        if ( time >= 0 )
+        if ( localRepoProperty != null )
         {
-            messageBuffer.append( " [" );
-
-            messageBuffer.append( getFormattedTime( time ) );
-
-            messageBuffer.append( "]" );
+            configuration.setLocalRepository( new File( localRepoProperty ) );
         }
 
-        getLogger().info( messageBuffer.toString() );
+        return configuration;
     }
 
-    private static String getFormattedTime( long time )
-    {
-        String pattern = "s.SSS's'";
-        if ( time / 60000L > 0 )
-        {
-            pattern = "m:s" + pattern;
-            if ( time / 3600000L > 0 )
-            {
-                pattern = "H:m" + pattern;
-            }
-        }
-        DateFormat fmt = new SimpleDateFormat( pattern );
-        fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
-        return fmt.format( new Date( time ) );
-    }
 }

Modified: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java?rev=584343&r1=584342&r2=584343&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java (original)
+++ maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java Fri Oct 12 17:10:29 2007
@@ -30,7 +30,6 @@
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
-import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 import org.apache.maven.embedder.execution.MavenExecutionRequestPopulator;
 import org.apache.maven.embedder.writer.WriterUtils;
 import org.apache.maven.execution.DefaultMavenExecutionRequest;
@@ -209,7 +208,7 @@
     throws XmlPullParserException, IOException
     {
     	Reader reader = new FileReader( file );
-    	
+
     	try
     	{
     		return readModel( reader );
@@ -319,7 +318,7 @@
     protected void verifyPlugin( Plugin plugin,
                                  MavenProject project )
         throws ComponentLookupException, ArtifactResolutionException, PluginVersionResolutionException,
-        ArtifactNotFoundException, InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException,
+        ArtifactNotFoundException, InvalidPluginException, PluginManagerException,
         PluginNotFoundException, PluginVersionNotFoundException
     {
         PluginManager pluginManager = (PluginManager) container.lookup( PluginManager.ROLE );
@@ -353,7 +352,7 @@
      * @todo Move this sort of thing to the tail end of the project-building process
      */
     private Map findArtifactTypeHandlers( MavenProject project )
-        throws Exception
+        throws MavenEmbedderException
     {
         Map map = new HashMap();
 
@@ -363,9 +362,51 @@
 
             if ( plugin.isExtensions() )
             {
-                verifyPlugin( plugin, project );
+                try
+                {
+                    verifyPlugin( plugin, project );
+                }
+                catch ( ArtifactResolutionException e )
+                {
+                    throw new PluginLookupException( plugin, "Error resolving plugin.", e );
+                }
+                catch ( ArtifactNotFoundException e )
+                {
+                    throw new PluginLookupException( plugin, "Error resolving plugin.", e );
+                }
+                catch ( PluginNotFoundException e )
+                {
+                    throw new PluginLookupException( plugin, "Error resolving plugin.", e );
+                }
+                catch ( ComponentLookupException e )
+                {
+                    throw new PluginLookupException( plugin, "Error resolving plugin.", e );
+                }
+                catch ( PluginVersionResolutionException e )
+                {
+                    throw new PluginLookupException( plugin, "Error resolving plugin.", e );
+                }
+                catch ( InvalidPluginException e )
+                {
+                    throw new PluginLookupException( plugin, "Error resolving plugin.", e );
+                }
+                catch ( PluginManagerException e )
+                {
+                    throw new PluginLookupException( plugin, "Error resolving plugin.", e );
+                }
+                catch ( PluginVersionNotFoundException e )
+                {
+                    throw new PluginLookupException( plugin, "Error resolving plugin.", e );
+                }
 
-                map.putAll( getPluginExtensionComponents( plugin ) );
+                try
+                {
+                    map.putAll( getPluginExtensionComponents( plugin ) );
+                }
+                catch ( PluginManagerException e )
+                {
+                    throw new PluginLookupException( plugin, "Error looking up plugin components.", e );
+                }
 
                 // shudder...
                 for ( Iterator j = map.values().iterator(); j.hasNext(); )
@@ -425,9 +466,13 @@
 
             artifactHandlerManager.addHandlers( handlers );
         }
-        catch ( Exception e )
+        catch ( MavenEmbedderException e )
         {
-            return result.addException( e );
+            return result.addUnknownException( e );
+        }
+        catch ( ProjectBuildingException e )
+        {
+            return result.addProjectBuildingException( e );
         }
 
         ReactorManager reactorManager = maven.createReactorManager( request, result );
@@ -448,7 +493,7 @@
         }
         catch ( ProjectBuildingException e )
         {
-            result.addException( e );
+            return result.addProjectBuildingException( e );
         }
 
         if ( reactorManager.hasMultipleProjects() )
@@ -555,15 +600,15 @@
     // ----------------------------------------------------------------------
     //  LegacyLifecycle
     // ----------------------------------------------------------------------
-    
+
     private MavenExecutionRequest request;
 
     private void start( Configuration configuration )
         throws MavenEmbedderException
     {
-        this.classWorld = configuration.getClassWorld();
+        classWorld = configuration.getClassWorld();
 
-        this.logger = configuration.getMavenEmbedderLogger();
+        logger = configuration.getMavenEmbedderLogger();
 
         // ----------------------------------------------------------------------------
         // Don't override any existing SecurityManager if one has been installed. Our
@@ -572,7 +617,7 @@
 
         try
         {
-            if ( System.getSecurityManager() == null && activateSystemManager )
+            if ( ( System.getSecurityManager() == null ) && activateSystemManager )
             {
                 System.setSecurityManager( new MavenEmbedderSecurityManager() );
             }
@@ -812,7 +857,7 @@
             {
                 MavenExecutionResult result = new DefaultMavenExecutionResult();
 
-                result.addException( e );
+                result.addUnknownException( e );
 
                 return result;
             }

Added: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/PluginLookupException.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/PluginLookupException.java?rev=584343&view=auto
==============================================================================
--- maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/PluginLookupException.java (added)
+++ maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/PluginLookupException.java Fri Oct 12 17:10:29 2007
@@ -0,0 +1,23 @@
+package org.apache.maven.embedder;
+
+import org.apache.maven.model.Plugin;
+
+public class PluginLookupException
+    extends MavenEmbedderException
+{
+
+    private final Plugin plugin;
+
+    public PluginLookupException( Plugin plugin, String message,
+                                  Throwable cause )
+    {
+        super( message, cause );
+        this.plugin = plugin;
+    }
+
+    public Plugin getPlugin()
+    {
+        return plugin;
+    }
+
+}

Propchange: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/PluginLookupException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/PluginLookupException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java?rev=584343&view=auto
==============================================================================
--- maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java (added)
+++ maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java Fri Oct 12 17:10:29 2007
@@ -0,0 +1,136 @@
+package org.apache.maven.cli;
+
+import org.apache.maven.BuildFailureException;
+import org.apache.maven.ProjectBuildFailureException;
+import org.apache.maven.execution.DefaultMavenExecutionRequest;
+import org.apache.maven.execution.DefaultMavenExecutionResult;
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionResult;
+import org.apache.maven.execution.ReactorManager;
+import org.apache.maven.lifecycle.model.MojoBinding;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Model;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.DuplicateProjectException;
+import org.apache.maven.project.InvalidProjectModelException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.validation.ModelValidationResult;
+import org.codehaus.plexus.util.dag.CycleDetectedException;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class CLIReportingUtilsTest
+    extends TestCase
+{
+
+    private TestEmbedderLogger logger = new TestEmbedderLogger();
+
+    public void test_logResult_ShowLongMessageForMojoFailureException()
+        throws CycleDetectedException, DuplicateProjectException
+    {
+        String longMessage = "This is a longer message.";
+
+        MojoFailureException e = new MojoFailureException( "test-id", "Short Message", longMessage );
+
+        MojoBinding binding = new MojoBinding();
+        binding.setGroupId( "plugin.group" );
+        binding.setArtifactId( "plugin-artifact" );
+        binding.setVersion( "10" );
+
+        BuildFailureException buildError = new ProjectBuildFailureException( "test:project:1", binding, e );
+
+        MavenExecutionRequest request = new DefaultMavenExecutionRequest();
+        MavenExecutionResult result = new DefaultMavenExecutionResult();
+
+        request.setStartTime( new Date() );
+
+        MavenProject project = createProject( "test", "project", "1" );
+
+        ReactorManager reactorManager = new ReactorManager( Collections.singletonList( project ),
+                                                            ReactorManager.FAIL_FAST );
+        reactorManager.registerBuildFailure( project, e, "task", 0 );
+
+        result.setReactorManager( reactorManager );
+        result.addBuildFailureException( buildError );
+
+        CLIReportingUtils.logResult( request, result, logger );
+        assertPresent( longMessage, logger.getErrorMessages() );
+    }
+
+    public void test_logResult_ShowReasonableMessageForInvalidProject()
+        throws CycleDetectedException, DuplicateProjectException
+    {
+        String validationMessage = "dependencies.dependency.version is required";
+
+        ModelValidationResult results = new ModelValidationResult();
+        results.addMessage( validationMessage );
+
+        String projectId = "test:project";
+        String projectPath = "/path/to/somewhere";
+        String message = "message";
+
+        InvalidProjectModelException e = new InvalidProjectModelException( projectId, projectPath, message, results );
+
+        MavenExecutionRequest request = new DefaultMavenExecutionRequest();
+        MavenExecutionResult result = new DefaultMavenExecutionResult();
+
+        request.setStartTime( new Date() );
+
+        MavenProject project = createProject( "test", "project", "1" );
+
+        Dependency dep = new Dependency();
+        dep.setGroupId( "test" );
+        dep.setArtifactId( "dep" );
+
+        project.getModel().addDependency( dep );
+
+        ReactorManager reactorManager = new ReactorManager( Collections.singletonList( project ),
+                                                            ReactorManager.FAIL_FAST );
+        reactorManager.registerBuildFailure( project, e, "task", 0 );
+
+        result.setReactorManager( reactorManager );
+        result.addProjectBuildingException( e );
+
+        CLIReportingUtils.logResult( request, result, logger );
+        assertPresent( projectId, logger.getErrorMessages() );
+        assertPresent( projectPath, logger.getErrorMessages() );
+        assertPresent( message, logger.getErrorMessages() );
+        assertPresent( validationMessage, logger.getErrorMessages() );
+    }
+
+    private MavenProject createProject( String groupId,
+                                        String artifactId,
+                                        String version )
+    {
+        Model model = new Model();
+        model.setGroupId( groupId );
+        model.setArtifactId( artifactId );
+        model.setVersion( version );
+
+        return new MavenProject( model );
+    }
+
+    private void assertPresent( String message,
+                                List messages )
+    {
+        for ( Iterator it = messages.iterator(); it.hasNext(); )
+        {
+            String entry = (String) it.next();
+
+            if ( entry.indexOf( message ) > -1 )
+            {
+                return;
+            }
+        }
+
+        fail( "Message not found in output: \'" + message + "\'" );
+        assertTrue( "Message: \'" + message + "\' is missing in output.",
+                    messages.contains( message ) );
+    }
+
+}

Propchange: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/CLIRequestUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/CLIRequestUtilsTest.java?rev=584343&view=auto
==============================================================================
--- maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/CLIRequestUtilsTest.java (added)
+++ maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/CLIRequestUtilsTest.java Fri Oct 12 17:10:29 2007
@@ -0,0 +1,47 @@
+package org.apache.maven.cli;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.ParseException;
+import org.apache.maven.execution.MavenExecutionRequest;
+
+import java.util.List;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+public class CLIRequestUtilsTest
+    extends TestCase
+{
+
+    public void test_buildRequest_ParseCommandLineProperty()
+        throws ParseException
+    {
+        String key = "key";
+        String value = "value";
+
+        CLIManager cliManager = new CLIManager();
+
+        String[] args = {
+            "-D" + key + "=" + value
+        };
+
+        CommandLine commandLine = cliManager.parse( args );
+
+        assertTrue( commandLine.hasOption( CLIManager.SET_SYSTEM_PROPERTY ) );
+
+        System.out.println( commandLine.getOptionValue( CLIManager.SET_SYSTEM_PROPERTY ) );
+        System.out.println( commandLine.getArgList() );
+
+        assertEquals( 1, commandLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY ).length );
+
+        MavenExecutionRequest request = CLIRequestUtils.buildRequest( commandLine, false, false, false );
+
+        Properties execProperties = request.getProperties();
+
+        assertEquals( value, execProperties.getProperty( key ) );
+
+        List goals = request.getGoals();
+        assertTrue( ( goals == null ) || goals.isEmpty() );
+    }
+
+}

Propchange: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/CLIRequestUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/CLIRequestUtilsTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/TestEmbedderLogger.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/TestEmbedderLogger.java?rev=584343&view=auto
==============================================================================
--- maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/TestEmbedderLogger.java (added)
+++ maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/TestEmbedderLogger.java Fri Oct 12 17:10:29 2007
@@ -0,0 +1,134 @@
+package org.apache.maven.cli;
+
+import org.apache.maven.embedder.AbstractMavenEmbedderLogger;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TestEmbedderLogger
+    extends AbstractMavenEmbedderLogger
+{
+
+    private List debugMessages = new ArrayList();
+
+    private List errorMessages = new ArrayList();
+
+    private List fatalErrorMessages = new ArrayList();
+
+    private List infoMessages = new ArrayList();
+
+    private List warnMessages = new ArrayList();
+
+    private List debugErrors = new ArrayList();
+
+    private List errors = new ArrayList();
+
+    private List fatalErrors = new ArrayList();
+
+    private List infoErrors = new ArrayList();
+
+    private List warnErrors = new ArrayList();
+
+    public void close()
+    {
+    }
+
+    public void debug( String message,
+                       Throwable throwable )
+    {
+        log( "[debug] ", message, throwable, debugMessages, debugErrors );
+    }
+
+    private void log( String header,
+                      String message, Throwable throwable,
+                      List messages,
+                      List errors )
+    {
+        if ( message != null )
+        {
+            messages.add( message );
+            System.out.println( header + message );
+        }
+
+        if ( throwable != null )
+        {
+            errors.add( throwable );
+            throwable.printStackTrace( System.out );
+        }
+    }
+
+    public void error( String message,
+                       Throwable throwable )
+    {
+        log( "[error] ", message, throwable, errorMessages, errors );
+    }
+
+    public void fatalError( String message,
+                            Throwable throwable )
+    {
+        log( "[fatal] ", message, throwable, fatalErrorMessages, fatalErrors );
+    }
+
+    public void info( String message,
+                      Throwable throwable )
+    {
+        log( "[info] ", message, throwable, infoMessages, infoErrors );
+    }
+
+    public void warn( String message,
+                      Throwable throwable )
+    {
+        log( "[warn] ", message, throwable, warnMessages, warnErrors );
+    }
+
+    public List getDebugMessages()
+    {
+        return debugMessages;
+    }
+
+    public List getErrorMessages()
+    {
+        return errorMessages;
+    }
+
+    public List getFatalErrorMessages()
+    {
+        return fatalErrorMessages;
+    }
+
+    public List getInfoMessages()
+    {
+        return infoMessages;
+    }
+
+    public List getWarnMessages()
+    {
+        return warnMessages;
+    }
+
+    public List getDebugErrors()
+    {
+        return debugErrors;
+    }
+
+    public List getErrorErrors()
+    {
+        return errors;
+    }
+
+    public List getFatalErrors()
+    {
+        return fatalErrors;
+    }
+
+    public List getInfoErrors()
+    {
+        return infoErrors;
+    }
+
+    public List getWarnErrors()
+    {
+        return warnErrors;
+    }
+
+}

Propchange: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/TestEmbedderLogger.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/cli/TestEmbedderLogger.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message