maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r836267 - in /maven/maven-3/trunk: maven-compat/src/test/java/org/apache/maven/project/ maven-core/src/main/java/org/apache/maven/ maven-core/src/main/java/org/apache/maven/exception/ maven-core/src/main/java/org/apache/maven/lifecycle/ mav...
Date Sat, 14 Nov 2009 21:36:32 GMT
Author: bentmann
Date: Sat Nov 14 21:36:31 2009
New Revision: 836267

URL: http://svn.apache.org/viewvc?rev=836267&view=rev
Log:
[MNG-4440] error message should clearly indicate the module that failed, and how to continue

Modified:
    maven/maven-3/trunk/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
    maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java
    maven/maven-3/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java

Modified: maven/maven-3/trunk/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java?rev=836267&r1=836266&r2=836267&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java
(original)
+++ maven/maven-3/trunk/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java
Sat Nov 14 21:36:31 2009
@@ -25,6 +25,7 @@
 import java.util.Set;
 
 import org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.LifecycleExecutionException;
 import org.apache.maven.lifecycle.LifecycleExecutor;
 import org.apache.maven.lifecycle.LifecycleNotFoundException;
 import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
@@ -33,12 +34,8 @@
 import org.apache.maven.model.PluginExecution;
 import org.apache.maven.plugin.InvalidPluginDescriptorException;
 import org.apache.maven.plugin.MojoExecution;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.MojoNotFoundException;
-import org.apache.maven.plugin.PluginConfigurationException;
 import org.apache.maven.plugin.PluginDescriptorParsingException;
-import org.apache.maven.plugin.PluginManagerException;
 import org.apache.maven.plugin.PluginNotFoundException;
 import org.apache.maven.plugin.PluginResolutionException;
 import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
@@ -115,7 +112,7 @@
     }
 
     public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution,
MavenSession session )
-        throws MojoFailureException, MojoExecutionException, PluginConfigurationException,
PluginManagerException
+        throws LifecycleExecutionException
     {
         return Collections.emptyList();
     }

Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java?rev=836267&r1=836266&r2=836267&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java (original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java Sat Nov
14 21:36:31 2009
@@ -175,6 +175,10 @@
 
         session.setProjects( projects );
 
+        result.setTopologicallySortedProjects( session.getProjects() );
+        
+        result.setProject( session.getTopLevelProject() );
+
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         try
         {
@@ -224,6 +228,8 @@
             return processResult( result, e );
         }
 
+        result.setTopologicallySortedProjects( session.getProjects() );
+
         // Desired order of precedence for local artifact repositories
         //
         // Reactor
@@ -245,10 +251,6 @@
             return processResult( result, session.getResult().getExceptions().get( 0 ) );
         }
 
-        result.setTopologicallySortedProjects( session.getProjects() );
-        
-        result.setProject( session.getTopLevelProject() );
-
         return result;
     }
 

Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java?rev=836267&r1=836266&r2=836267&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java
(original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java
Sat Nov 14 21:36:31 2009
@@ -23,6 +23,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.maven.lifecycle.LifecycleExecutionException;
 import org.apache.maven.model.building.ModelProblem;
 import org.apache.maven.plugin.AbstractMojoExecutionException;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -181,6 +182,10 @@
                     reference = exception.getClass().getSimpleName();
                 }
             }
+            else if ( exception instanceof LifecycleExecutionException )
+            {
+                reference = getReference( exception.getCause() );
+            }
             else if ( !( exception instanceof RuntimeException ) )
             {
                 reference = exception.getClass().getSimpleName();

Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=836267&r1=836266&r2=836267&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
(original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
Sat Nov 14 21:36:31 2009
@@ -367,40 +367,51 @@
     private void resolveProjectDependencies( MavenProject project, Collection<String>
scopesToCollect,
                                              Collection<String> scopesToResolve, MavenSession
session,
                                              boolean aggregating )
-        throws ArtifactResolutionException, ArtifactNotFoundException
+        throws LifecycleExecutionException
     {
         Set<Artifact> artifacts;
 
         try
         {
-            artifacts = projectDependenciesResolver.resolve( project, scopesToCollect, scopesToResolve,
session );
-        }
-        catch ( MultipleArtifactsNotFoundException e )
-        {
-            /*
-             * MNG-2277, the check below compensates for our bad plugin support where we
ended up with aggregator
-             * plugins that require dependency resolution although they usually run in phases
of the build where project
-             * artifacts haven't been assembled yet. The prime example of this is "mvn release:prepare".
-             */
-            if ( aggregating && areAllArtifactsInReactor( session.getProjects(),
e.getMissingArtifacts() ) )
+            try
             {
-                logger.warn( "The following artifacts could not be resolved at this point
of the build"
-                    + " but seem to be part of the reactor:" );
-
-                for ( Artifact artifact : e.getMissingArtifacts() )
+                artifacts = projectDependenciesResolver.resolve( project, scopesToCollect,
scopesToResolve, session );
+            }
+            catch ( MultipleArtifactsNotFoundException e )
+            {
+                /*
+                 * MNG-2277, the check below compensates for our bad plugin support where
we ended up with aggregator
+                 * plugins that require dependency resolution although they usually run in
phases of the build where project
+                 * artifacts haven't been assembled yet. The prime example of this is "mvn
release:prepare".
+                 */
+                if ( aggregating && areAllArtifactsInReactor( session.getProjects(),
e.getMissingArtifacts() ) )
                 {
-                    logger.warn( "o " + artifact.getId() );
-                }
+                    logger.warn( "The following artifacts could not be resolved at this point
of the build"
+                        + " but seem to be part of the reactor:" );
+
+                    for ( Artifact artifact : e.getMissingArtifacts() )
+                    {
+                        logger.warn( "o " + artifact.getId() );
+                    }
 
-                logger.warn( "Try running the build up to the lifecycle phase \"package\""
);
+                    logger.warn( "Try running the build up to the lifecycle phase \"package\""
);
 
-                artifacts = new LinkedHashSet<Artifact>( e.getResolvedArtifacts() );
-            }
-            else
-            {
-                throw e;
+                    artifacts = new LinkedHashSet<Artifact>( e.getResolvedArtifacts()
);
+                }
+                else
+                {
+                    throw e;
+                }
             }
         }
+        catch ( ArtifactResolutionException e )
+        {
+            throw new LifecycleExecutionException( null, project, e );
+        }
+        catch ( ArtifactNotFoundException e )
+        {
+            throw new LifecycleExecutionException( null, project, e );
+        }
 
         project.setArtifacts( artifacts );
 
@@ -488,7 +499,7 @@
         }
 
         void checkForUpdate( MavenSession session )
-            throws ArtifactResolutionException, ArtifactNotFoundException
+            throws LifecycleExecutionException
         {
             if ( lastProject == session.getCurrentProject() )
             {
@@ -509,23 +520,25 @@
 
     private void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex
projectIndex,
                           DependencyContext dependencyContext )
-        throws MojoFailureException, MojoExecutionException, PluginConfigurationException,
PluginManagerException,
-        ArtifactResolutionException, ArtifactNotFoundException
+        throws LifecycleExecutionException
     {
         MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
 
         if ( mojoDescriptor.isProjectRequired() && !session.isUsingPOMsFromFilesystem()
)
         {
-            throw new MojoExecutionException( "Goal " + mojoDescriptor.getId()
-                + " requires a project to execute but there is no POM in this build." );
+            Throwable cause =
+                new IllegalStateException( "Goal requires a project to execute but there
is no POM in this build." );
+            throw new LifecycleExecutionException( mojoExecution, null, cause );
         }
 
         if ( mojoDescriptor.isOnlineRequired() && session.isOffline() )
         {
             if ( MojoExecution.Source.CLI.equals( mojoExecution.getSource() ) )
             {
-                throw new MojoExecutionException( "Goal " + mojoDescriptor.getId()
-                    + " requires online mode for execution but Maven is currently offline."
);
+                Throwable cause =
+                    new IllegalStateException( "Goal requires online mode for execution"
+                        + " but Maven is currently offline." );
+                throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(),
cause );
             }
             else
             {
@@ -544,29 +557,30 @@
 
         try
         {
-            pluginManager.executeMojo( session, mojoExecution );
+            try
+            {
+                pluginManager.executeMojo( session, mojoExecution );
+            }
+            catch ( MojoFailureException e )
+            {
+                throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(),
e );
+            }
+            catch ( MojoExecutionException e )
+            {
+                throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(),
e );
+            }
+            catch ( PluginConfigurationException e )
+            {
+                throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(),
e );
+            }
+            catch ( PluginManagerException e )
+            {
+                throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(),
e );
+            }
 
             fireEvent( session, mojoExecution, LifecycleEventCatapult.MOJO_SUCCEEDED );
         }
-        catch ( MojoFailureException e )
-        {
-            fireEvent( session, mojoExecution, LifecycleEventCatapult.MOJO_FAILED );
-
-            throw e;
-        }
-        catch ( MojoExecutionException e )
-        {
-            fireEvent( session, mojoExecution, LifecycleEventCatapult.MOJO_FAILED );
-
-            throw e;
-        }
-        catch ( PluginConfigurationException e )
-        {
-            fireEvent( session, mojoExecution, LifecycleEventCatapult.MOJO_FAILED );
-
-            throw e;
-        }
-        catch ( PluginManagerException e )
+        catch ( LifecycleExecutionException e )
         {
             fireEvent( session, mojoExecution, LifecycleEventCatapult.MOJO_FAILED );
 
@@ -582,8 +596,7 @@
     }
 
     public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution,
MavenSession session )
-        throws MojoFailureException, MojoExecutionException, PluginConfigurationException,
PluginManagerException,
-        ArtifactResolutionException, ArtifactNotFoundException
+        throws LifecycleExecutionException
     {
         return executeForkedExecutions( mojoExecution, session, new ProjectIndex( session.getProjects()
),
                                         new DependencyContext( mojoExecution ) );
@@ -591,8 +604,7 @@
 
     private List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution,
MavenSession session,
                                                         ProjectIndex projectIndex, DependencyContext
dependencyContext )
-        throws MojoFailureException, MojoExecutionException, PluginConfigurationException,
PluginManagerException,
-        ArtifactResolutionException, ArtifactNotFoundException
+        throws LifecycleExecutionException
     {
         List<MavenProject> forkedProjects = Collections.emptyList();
 
@@ -643,25 +655,7 @@
 
                 fireEvent( session, mojoExecution, LifecycleEventCatapult.FORK_SUCCEEDED
);
             }
-            catch ( MojoFailureException e )
-            {
-                fireEvent( session, mojoExecution, LifecycleEventCatapult.FORK_FAILED );
-
-                throw e;
-            }
-            catch ( MojoExecutionException e )
-            {
-                fireEvent( session, mojoExecution, LifecycleEventCatapult.FORK_FAILED );
-
-                throw e;
-            }
-            catch ( PluginConfigurationException e )
-            {
-                fireEvent( session, mojoExecution, LifecycleEventCatapult.FORK_FAILED );
-
-                throw e;
-            }
-            catch ( PluginManagerException e )
+            catch ( LifecycleExecutionException e )
             {
                 fireEvent( session, mojoExecution, LifecycleEventCatapult.FORK_FAILED );
 

Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java?rev=836267&r1=836266&r2=836267&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java
(original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java
Sat Nov 14 21:36:31 2009
@@ -1,7 +1,5 @@
 package org.apache.maven.lifecycle;
 
-import org.apache.maven.project.MavenProject;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -21,6 +19,9 @@
  * under the License.
  */
 
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.project.MavenProject;
+
 /**
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
  * @version $Id$
@@ -50,9 +51,62 @@
         super( message );
         this.project = project;
     }
-    
+
+    LifecycleExecutionException( String message, MojoExecution execution, MavenProject project
)
+    {
+        super( message );
+        this.project = project;
+    }
+
+    LifecycleExecutionException( String message, MojoExecution execution, MavenProject project,
Throwable cause )
+    {
+        super( message, cause );
+        this.project = project;
+    }
+
+    LifecycleExecutionException( MojoExecution execution, MavenProject project, Throwable
cause )
+    {
+        this( createMessage( execution, project, cause ), execution, project, cause );
+    }
+
     public MavenProject getProject()
     {
         return project;
     }
+
+    private static String createMessage( MojoExecution execution, MavenProject project, Throwable
cause )
+    {
+        StringBuilder buffer = new StringBuilder( 256 );
+
+        buffer.append( "Failed to execute goal" );
+
+        if ( execution != null )
+        {
+            buffer.append( ' ' );
+            buffer.append( execution.getGroupId() );
+            buffer.append( ':' );
+            buffer.append( execution.getArtifactId() );
+            buffer.append( ':' );
+            buffer.append( execution.getVersion() );
+            buffer.append( ':' );
+            buffer.append( execution.getGoal() );
+            buffer.append( " (" );
+            buffer.append( execution.getExecutionId() );
+            buffer.append( ")" );
+        }
+
+        if ( project != null )
+        {
+            buffer.append( " on project " );
+            buffer.append( project.getArtifactId() );
+        }
+
+        if ( cause != null )
+        {
+            buffer.append( ": " ).append( cause.getMessage() );
+        }
+
+        return buffer.toString();
+    }
+
 }

Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java?rev=836267&r1=836266&r2=836267&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
(original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
Sat Nov 14 21:36:31 2009
@@ -22,16 +22,11 @@
 import java.util.List;
 import java.util.Set;
 
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.InvalidPluginDescriptorException;
 import org.apache.maven.plugin.MojoExecution;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.MojoNotFoundException;
-import org.apache.maven.plugin.PluginConfigurationException;
 import org.apache.maven.plugin.PluginDescriptorParsingException;
 import org.apache.maven.plugin.PluginManagerException;
 import org.apache.maven.plugin.PluginNotFoundException;
@@ -109,7 +104,6 @@
      *         will never be {@code null}.
      */
     List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession
session )
-        throws MojoFailureException, MojoExecutionException, PluginConfigurationException,
PluginManagerException,
-        ArtifactResolutionException, ArtifactNotFoundException;
+        throws LifecycleExecutionException;
 
 }

Modified: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java?rev=836267&r1=836266&r2=836267&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java
(original)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java
Sat Nov 14 21:36:31 2009
@@ -25,6 +25,7 @@
 import java.util.Set;
 
 import org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.LifecycleExecutionException;
 import org.apache.maven.lifecycle.LifecycleExecutor;
 import org.apache.maven.lifecycle.LifecycleNotFoundException;
 import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
@@ -33,12 +34,8 @@
 import org.apache.maven.model.PluginExecution;
 import org.apache.maven.plugin.InvalidPluginDescriptorException;
 import org.apache.maven.plugin.MojoExecution;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.MojoNotFoundException;
-import org.apache.maven.plugin.PluginConfigurationException;
 import org.apache.maven.plugin.PluginDescriptorParsingException;
-import org.apache.maven.plugin.PluginManagerException;
 import org.apache.maven.plugin.PluginNotFoundException;
 import org.apache.maven.plugin.PluginResolutionException;
 import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
@@ -115,7 +112,7 @@
     }
 
     public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution,
MavenSession session )
-        throws MojoFailureException, MojoExecutionException, PluginConfigurationException,
PluginManagerException
+        throws LifecycleExecutionException
     {
         return Collections.emptyList();
     }

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=836267&r1=836266&r2=836267&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 Sat
Nov 14 21:36:31 2009
@@ -38,7 +38,9 @@
 import org.apache.maven.execution.MavenExecutionRequest;
 import org.apache.maven.execution.MavenExecutionRequestPopulator;
 import org.apache.maven.execution.MavenExecutionResult;
+import org.apache.maven.lifecycle.LifecycleExecutionException;
 import org.apache.maven.model.building.ModelProcessor;
+import org.apache.maven.project.MavenProject;
 import org.apache.maven.repository.ArtifactTransferListener;
 import org.apache.maven.settings.building.DefaultSettingsBuildingRequest;
 import org.apache.maven.settings.building.SettingsBuilder;
@@ -426,11 +428,18 @@
 
             Map<String, String> references = new LinkedHashMap<String, String>();
 
+            MavenProject project = null;
+
             for ( Throwable exception : result.getExceptions() )
             {
                 ExceptionSummary summary = handler.handleException( exception );
 
                 logSummary( summary, references, "", cliRequest.showErrors );
+
+                if ( project == null && exception instanceof LifecycleExecutionException
)
+                {
+                    project = ( (LifecycleExecutionException) exception ).getProject();
+                }
             }
 
             logger.error( "" );
@@ -455,6 +464,13 @@
                 }
             }
 
+            if ( project != null && !project.equals( result.getTopologicallySortedProjects().get(
0 ) ) )
+            {
+                logger.error( "" );
+                logger.error( "After correcting the problems, you can resume the build with
the command" );
+                logger.error( "  mvn <goals> -rf :" + project.getArtifactId() );
+            }
+
             if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( cliRequest.request.getReactorFailureBehavior()
) )
             {
                 logger.info( "Build failures were ignored." );



Mime
View raw message