Cleaning up reporting some more.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@604750 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2007-12-17 00:15:21 +00:00
parent b511c734a6
commit fbb4833982
6 changed files with 44 additions and 128 deletions

View File

@ -112,12 +112,12 @@ public class DefaultMaven
} }
catch ( ProjectBuildingException e ) catch ( ProjectBuildingException e )
{ {
result.addProjectBuildingException( e ); result.addException( e );
return null; return null;
} }
catch ( MavenExecutionException e ) catch ( MavenExecutionException e )
{ {
result.addMavenExecutionException( e ); result.addException( e );
return null; return null;
} }
@ -138,13 +138,13 @@ public class DefaultMaven
ProjectCycleException error = new ProjectCycleException( projects, message, e ); ProjectCycleException error = new ProjectCycleException( projects, message, e );
result.addBuildFailureException( error ); result.addException( error );
return null; return null;
} }
catch ( DuplicateProjectException e ) catch ( DuplicateProjectException e )
{ {
result.addDuplicateProjectException( e ); result.addException( e );
return null; return null;
} }
@ -194,7 +194,7 @@ public class DefaultMaven
if ( !tvr.isTaskValid() ) if ( !tvr.isTaskValid() )
{ {
result.addBuildFailureException( tvr.generateInvalidTaskException() ); result.addException( tvr.generateInvalidTaskException() );
return result; return result;
} }
@ -223,12 +223,12 @@ public class DefaultMaven
} }
catch ( LifecycleExecutionException e ) catch ( LifecycleExecutionException e )
{ {
result.addLifecycleExecutionException( e ); result.addException( e );
return result; return result;
} }
catch ( BuildFailureException e ) catch ( BuildFailureException e )
{ {
result.addBuildFailureException( e ); result.addException( e );
return result; return result;
} }

View File

@ -19,14 +19,8 @@ package org.apache.maven.execution;
* under the License. * under the License.
*/ */
import org.apache.maven.BuildFailureException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.extension.ExtensionScanningException;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.project.DuplicateProjectException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.reactor.MavenExecutionException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -87,56 +81,7 @@ public class DefaultMavenExecutionResult
return exceptions == null ? Collections.EMPTY_LIST : exceptions; return exceptions == null ? Collections.EMPTY_LIST : exceptions;
} }
public MavenExecutionResult addExtensionScanningException( ExtensionScanningException e ) public MavenExecutionResult addException( Throwable t )
{
addException( e );
return this;
}
public MavenExecutionResult addProjectBuildingException( ProjectBuildingException e )
{
addException( e );
return this;
}
public MavenExecutionResult addMavenExecutionException( MavenExecutionException e )
{
addException( e );
return this;
}
public MavenExecutionResult addBuildFailureException( BuildFailureException e )
{
addException( e );
return this;
}
public MavenExecutionResult addDuplicateProjectException( DuplicateProjectException e )
{
addException( e );
return this;
}
public MavenExecutionResult addLifecycleExecutionException( LifecycleExecutionException e )
{
addException( e );
return this;
}
public MavenExecutionResult addUnknownException( Throwable t )
{
addException( t );
return this;
}
private void addException( Throwable t )
{ {
if ( exceptions == null ) if ( exceptions == null )
{ {
@ -144,6 +89,8 @@ public class DefaultMavenExecutionResult
} }
exceptions.add( t ); exceptions.add( t );
return this;
} }
public boolean hasExceptions() public boolean hasExceptions()

View File

@ -19,14 +19,8 @@ package org.apache.maven.execution;
* under the License. * under the License.
*/ */
import org.apache.maven.BuildFailureException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.extension.ExtensionScanningException;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.project.DuplicateProjectException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.reactor.MavenExecutionException;
import java.util.List; import java.util.List;
@ -54,13 +48,7 @@ public interface MavenExecutionResult
// - xmlpull parser exception // - xmlpull parser exception
List getExceptions(); List getExceptions();
MavenExecutionResult addLifecycleExecutionException( LifecycleExecutionException e ); MavenExecutionResult addException( Throwable e );
MavenExecutionResult addDuplicateProjectException( DuplicateProjectException duplicateProjectException );
MavenExecutionResult addBuildFailureException( BuildFailureException buildFailureException );
MavenExecutionResult addMavenExecutionException( MavenExecutionException e );
MavenExecutionResult addProjectBuildingException (ProjectBuildingException e );
MavenExecutionResult addExtensionScanningException( ExtensionScanningException e );
MavenExecutionResult addUnknownException( Throwable t );
boolean hasExceptions(); boolean hasExceptions();
} }

View File

@ -4,7 +4,6 @@ import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
import org.apache.maven.embedder.MavenEmbedderLogger; import org.apache.maven.embedder.MavenEmbedderLogger;
import org.apache.maven.errors.CoreErrorReporter; import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.errors.DefaultCoreErrorReporter; import org.apache.maven.errors.DefaultCoreErrorReporter;
import org.apache.maven.execution.BuildFailure;
import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult; import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.ReactorManager; import org.apache.maven.execution.ReactorManager;
@ -102,9 +101,22 @@ public final class CLIReportingUtils
logReactorSummary( reactorManager, logger ); logReactorSummary( reactorManager, logger );
boolean printSuccess = true;
if ( ( reactorManager != null ) && reactorManager.hasBuildFailures() ) if ( ( reactorManager != null ) && reactorManager.hasBuildFailures() )
{ {
logErrors( reactorManager, request.isShowErrors(), logger ); for ( Iterator i = result.getExceptions().iterator(); i.hasNext(); )
{
Exception e = (Exception) i.next();
showError( e, request.isShowErrors(), request.getErrorReporter(), logger );
}
line( logger );
if ( !request.isShowErrors() )
{
logger.info( "For more information, run with the -e flag" );
line( logger );
}
if ( !ReactorManager.FAIL_NEVER.equals( reactorManager.getFailureBehavior() ) ) if ( !ReactorManager.FAIL_NEVER.equals( reactorManager.getFailureBehavior() ) )
{ {
@ -115,6 +127,7 @@ public final class CLIReportingUtils
stats( request.getStartTime(), logger ); stats( request.getStartTime(), logger );
line( logger ); line( logger );
printSuccess = false;
} }
else else
{ {
@ -122,16 +135,7 @@ public final class CLIReportingUtils
} }
} }
if ( result.hasExceptions() ) if ( printSuccess )
{
for ( Iterator i = result.getExceptions().iterator(); i.hasNext(); )
{
Exception e = (Exception) i.next();
showError( e, request.isShowErrors(), request.getErrorReporter(), logger );
}
}
else
{ {
line( logger ); line( logger );
@ -147,41 +151,21 @@ public final class CLIReportingUtils
logger.close(); 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, static void showError( String message,
Exception e, Exception e,
boolean showErrors ) boolean showErrors )
{ {
showError( message, e, showErrors, new DefaultCoreErrorReporter(), new MavenEmbedderConsoleLogger() ); MavenEmbedderLogger logger = new MavenEmbedderConsoleLogger();
showError( message, e, showErrors, new DefaultCoreErrorReporter(), logger );
if ( !showErrors )
{
logger.info( "For more information, run with the -e flag" );
}
} }
static void showError( Exception e, private static void showError( Exception e,
boolean show, boolean show,
CoreErrorReporter reporter, CoreErrorReporter reporter,
MavenEmbedderLogger logger ) MavenEmbedderLogger logger )
@ -196,7 +180,7 @@ public final class CLIReportingUtils
* @param showStackTraces * @param showStackTraces
* @param logger * @param logger
*/ */
public static void showError( String message, static void showError( String message,
Exception e, Exception e,
boolean showStackTraces, boolean showStackTraces,
CoreErrorReporter reporter, CoreErrorReporter reporter,
@ -223,10 +207,6 @@ public final class CLIReportingUtils
e.printStackTrace( new PrintWriter( writer ) ); e.printStackTrace( new PrintWriter( writer ) );
} }
else
{
writer.write( "For more information, run with the -e flag" );
}
logger.error( writer.toString() ); logger.error( writer.toString() );
} }

View File

@ -395,15 +395,15 @@ public class MavenEmbedder
} }
catch ( MavenEmbedderException e ) catch ( MavenEmbedderException e )
{ {
return result.addUnknownException( e ); return result.addException( e );
} }
catch ( ProjectBuildingException e ) catch ( ProjectBuildingException e )
{ {
return result.addProjectBuildingException( e ); return result.addException( e );
} }
catch ( ExtensionScanningException e ) catch ( ExtensionScanningException e )
{ {
return result.addExtensionScanningException( e ); return result.addException( e );
} }
ReactorManager reactorManager = maven.createReactorManager( request, result ); ReactorManager reactorManager = maven.createReactorManager( request, result );
@ -424,7 +424,7 @@ public class MavenEmbedder
} }
catch ( ProjectBuildingException e ) catch ( ProjectBuildingException e )
{ {
return result.addProjectBuildingException( e ); return result.addException( e );
} }
if ( reactorManager.hasMultipleProjects() ) if ( reactorManager.hasMultipleProjects() )
@ -803,7 +803,7 @@ public class MavenEmbedder
{ {
MavenExecutionResult result = new DefaultMavenExecutionResult(); MavenExecutionResult result = new DefaultMavenExecutionResult();
result.addUnknownException( e ); result.addException( e );
return result; return result;
} }

View File

@ -110,7 +110,8 @@ public class DefaultMavenExecutionRequestPopulator
snapshotPolicy( request, configuration ); snapshotPolicy( request, configuration );
localRepository( request, configuration ); // TODO: Can we remove this second call?
// localRepository( request, configuration );
checksumPolicy( request, configuration ); checksumPolicy( request, configuration );