Error reporting works properly now.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@604401 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2007-12-15 08:17:21 +00:00
parent fe523d1151
commit 5159c0b4b6
16 changed files with 231 additions and 393 deletions

View File

@ -0,0 +1,28 @@
package org.apache.maven.errors;
import org.apache.maven.errors.DefaultCoreErrorReporter;
import org.apache.maven.errors.CoreErrorReporter;
import org.aspectj.lang.reflect.SourceLocation;
public privileged aspect CoreReporterDebugAspect
{
// before( Throwable key, DefaultCoreErrorReporter reporter ):
// call( void DefaultCoreErrorReporter.registerBuildError( Throwable, .. ) )
// && args( key, .. )
// && target( reporter )
// {
// SourceLocation location = thisJoinPoint.getSourceLocation();
// System.out.println( "Registering: " + key.getClass().getName() + "@" + key.hashCode() + "\nfrom: " + location.getFileName() + ", line: " + location.getLine() + "\nreporter instance hashcode is: " + reporter.hashCode() );
// }
//
// after() returning( Throwable key ):
// execution( Throwable CoreErrorReporter+.findReportedException( Throwable ) )
// {
// if ( key != null )
// {
// System.out.println( "Found reported exception: " + key.getClass().getName() + "@" + key.hashCode() );
// }
// }
}

View File

@ -37,6 +37,7 @@ import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.error.ProjectErrorReporter;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.reactor.MavenExecutionException;
@ -51,18 +52,9 @@ import java.util.List;
import java.util.Map;
public interface CoreErrorReporter
extends ProjectErrorReporter
{
String NEWLINE = "\n";
void clearErrors();
String getFormattedMessage( Throwable error );
Throwable getRealCause( Throwable error );
Throwable findReportedException( Throwable error );
void reportNoGoalsSpecifiedException( MavenProject rootProject, NoGoalsSpecifiedException error );
void reportAggregatedMojoFailureException( MavenSession session, MojoBinding binding, MojoFailureException cause );

View File

@ -1,5 +1,7 @@
package org.apache.maven.errors;
import org.apache.maven.project.error.ProjectReporterManager;
public final class CoreReporterManager
{
@ -14,6 +16,8 @@ public final class CoreReporterManager
if ( reporter == null )
{
reporter = new DefaultCoreErrorReporter();
// FIXME: Is this correct? What might this isolate and make inaccessible in a running system?
ProjectReporterManager.setReporter( reporter );
}
return reporter;
@ -22,6 +26,7 @@ public final class CoreReporterManager
public static void setReporter( CoreErrorReporter instance )
{
reporter = instance;
ProjectReporterManager.setReporter( instance );
}
public static void clearReporter()

View File

@ -44,6 +44,7 @@ import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.error.DefaultProjectErrorReporter;
import org.apache.maven.project.error.ProjectErrorReporter;
import org.apache.maven.project.error.ProjectReporterManager;
import org.apache.maven.project.interpolation.ModelInterpolationException;
@ -66,70 +67,20 @@ import java.util.List;
import java.util.Map;
public class DefaultCoreErrorReporter
extends DefaultProjectErrorReporter
implements CoreErrorReporter
{
private Map formattedMessages = new HashMap();
private static final String NEWLINE = "\n";
private Map realCauses = new HashMap();
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#clearErrors()
*/
public void clearErrors()
public DefaultCoreErrorReporter( Map formattedMessageStore, Map realCauseStore )
{
formattedMessages.clear();
realCauses.clear();
super( formattedMessageStore, realCauseStore );
}
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#hasInformationFor(java.lang.Throwable)
*/
public Throwable findReportedException( Throwable error )
public DefaultCoreErrorReporter()
{
if ( formattedMessages.containsKey( error ) )
{
return error;
}
else if ( error.getCause() != null )
{
return findReportedException( error.getCause() );
}
return null;
}
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#getFormattedMessage(java.lang.Throwable)
*/
public String getFormattedMessage( Throwable error )
{
return (String) formattedMessages.get( error );
}
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#getRealCause(java.lang.Throwable)
*/
public Throwable getRealCause( Throwable error )
{
return (Throwable) realCauses.get( error );
}
private void registerBuildError( Throwable error,
String formattedMessage,
Throwable realCause )
{
formattedMessages.put( error, formattedMessage );
if ( realCause != null )
{
realCauses.put( error, realCause );
}
}
private void registerBuildError( Throwable error,
String formattedMessage )
{
formattedMessages.put( error, formattedMessage );
}
public void reportNoGoalsSpecifiedException( MavenProject rootProject, NoGoalsSpecifiedException error )

View File

@ -20,6 +20,7 @@ package org.apache.maven.execution;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.settings.Settings;
@ -527,6 +528,8 @@ public class DefaultMavenExecutionRequest
private Settings settings;
private CoreErrorReporter errorReporter;
public MavenExecutionRequest setSettings( Settings settings )
{
this.settings = settings;
@ -623,4 +626,15 @@ public class DefaultMavenExecutionRequest
return this;
}
public CoreErrorReporter getErrorReporter()
{
return errorReporter;
}
public MavenExecutionRequest setErrorReporter( CoreErrorReporter reporter )
{
errorReporter = reporter;
return this;
}
}

View File

@ -21,6 +21,7 @@ package org.apache.maven.execution;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.settings.Settings;
@ -207,4 +208,7 @@ public interface MavenExecutionRequest
MavenRealmManager getRealmManager();
MavenExecutionRequest clearAccumulatedBuildState();
MavenExecutionRequest setErrorReporter( CoreErrorReporter reporter );
CoreErrorReporter getErrorReporter();
}

View File

@ -1,263 +0,0 @@
package org.apache.maven.embedder.cache;
import java.io.StringWriter;
import java.io.PrintWriter;
import org.apache.maven.BuildFailureException;
import org.apache.maven.cli.CLIReportingUtils;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.errors.CoreReporterManager;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.project.error.ProjectReporterManager;
import org.apache.maven.project.error.ProjectErrorReporter;
import org.apache.maven.project.DuplicateProjectException;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.reactor.MavenExecutionException;
public privileged aspect ErrorReportingAspect
{
private pointcut embedderCalls():
execution( public * MavenEmbedder.*( .. ) );
// TODO: Use MavenExecutionRequest to allow configuration of the reporters to be used.
Object around():
embedderCalls() && !cflow( embedderCalls() )
{
try
{
return proceed();
}
finally
{
ProjectReporterManager.clearReporter();
CoreReporterManager.clearReporter();
}
}
boolean around( ProjectBuildingException e, boolean showStackTraces, StringWriter writer ):
execution( private static boolean CLIReportingUtils.handleProjectBuildingException( ProjectBuildingException, boolean, StringWriter ) )
&& args( e, showStackTraces, writer )
{
ProjectErrorReporter projectErrorReporter = ProjectReporterManager.getReporter();
if ( projectErrorReporter == null )
{
return proceed( e, showStackTraces, writer );
}
else
{
Throwable reportingError = projectErrorReporter.findReportedException( e );
boolean result = false;
if ( reportingError != null )
{
writer.write( projectErrorReporter.getFormattedMessage( reportingError ) );
if ( showStackTraces )
{
writer.write( CLIReportingUtils.NEWLINE );
writer.write( CLIReportingUtils.NEWLINE );
Throwable cause = projectErrorReporter.getRealCause( reportingError );
if ( cause != null )
{
cause.printStackTrace( new PrintWriter( writer ) );
}
}
writer.write( CLIReportingUtils.NEWLINE );
writer.write( CLIReportingUtils.NEWLINE );
result = true;
}
else
{
result = proceed( e, showStackTraces, writer );
}
return result;
}
}
boolean around( DuplicateProjectException e, boolean showStackTraces, StringWriter writer ):
execution( private static boolean CLIReportingUtils.handleDuplicateProjectException( DuplicateProjectException, boolean, StringWriter ) )
&& args( e, showStackTraces, writer )
{
ProjectErrorReporter projectErrorReporter = ProjectReporterManager.getReporter();
if ( projectErrorReporter == null )
{
return proceed( e, showStackTraces, writer );
}
else
{
Throwable reportingError = projectErrorReporter.findReportedException( e );
boolean result = false;
if ( reportingError != null )
{
writer.write( projectErrorReporter.getFormattedMessage( reportingError ) );
if ( showStackTraces )
{
writer.write( CLIReportingUtils.NEWLINE );
writer.write( CLIReportingUtils.NEWLINE );
Throwable cause = projectErrorReporter.getRealCause( reportingError );
if ( cause != null )
{
cause.printStackTrace( new PrintWriter( writer ) );
}
}
writer.write( CLIReportingUtils.NEWLINE );
writer.write( CLIReportingUtils.NEWLINE );
result = true;
}
else
{
result = proceed( e, showStackTraces, writer );
}
return result;
}
}
boolean around( BuildFailureException e, boolean showStackTraces, StringWriter writer ):
execution( private static boolean CLIReportingUtils.handleBuildFailureException( BuildFailureException, boolean, StringWriter ) )
&& args( e, showStackTraces, writer )
{
CoreErrorReporter coreErrorReporter = CoreReporterManager.getReporter();
if ( coreErrorReporter == null )
{
return proceed( e, showStackTraces, writer );
}
else
{
Throwable reportingError = coreErrorReporter.findReportedException( e );
boolean result = false;
if ( reportingError != null )
{
writer.write( coreErrorReporter.getFormattedMessage( reportingError ) );
if ( showStackTraces )
{
writer.write( CLIReportingUtils.NEWLINE );
writer.write( CLIReportingUtils.NEWLINE );
Throwable cause = coreErrorReporter.getRealCause( reportingError );
if ( cause != null )
{
cause.printStackTrace( new PrintWriter( writer ) );
}
}
writer.write( CLIReportingUtils.NEWLINE );
writer.write( CLIReportingUtils.NEWLINE );
result = true;
}
else
{
result = proceed( e, showStackTraces, writer );
}
return result;
}
}
boolean around( LifecycleExecutionException e, boolean showStackTraces, StringWriter writer ):
execution( private static boolean CLIReportingUtils.handleLifecycleExecutionException( LifecycleExecutionException, boolean, StringWriter ) )
&& args( e, showStackTraces, writer )
{
CoreErrorReporter coreErrorReporter = CoreReporterManager.getReporter();
if ( coreErrorReporter == null )
{
return proceed( e, showStackTraces, writer );
}
else
{
Throwable reportingError = coreErrorReporter.findReportedException( e );
boolean result = false;
if ( reportingError != null )
{
writer.write( coreErrorReporter.getFormattedMessage( reportingError ) );
if ( showStackTraces )
{
writer.write( CLIReportingUtils.NEWLINE );
writer.write( CLIReportingUtils.NEWLINE );
Throwable cause = coreErrorReporter.getRealCause( reportingError );
if ( cause != null )
{
cause.printStackTrace( new PrintWriter( writer ) );
}
}
writer.write( CLIReportingUtils.NEWLINE );
writer.write( CLIReportingUtils.NEWLINE );
result = true;
}
else
{
result = proceed( e, showStackTraces, writer );
}
return result;
}
}
boolean around( MavenExecutionException e, boolean showStackTraces, StringWriter writer ):
execution( private static boolean CLIReportingUtils.handleMavenExecutionException( MavenExecutionException, boolean, StringWriter ) )
&& args( e, showStackTraces, writer )
{
CoreErrorReporter coreErrorReporter = CoreReporterManager.getReporter();
if ( coreErrorReporter == null )
{
return proceed( e, showStackTraces, writer );
}
else
{
Throwable reportingError = coreErrorReporter.findReportedException( e );
boolean result = false;
if ( reportingError != null )
{
writer.write( coreErrorReporter.getFormattedMessage( reportingError ) );
if ( showStackTraces )
{
writer.write( CLIReportingUtils.NEWLINE );
writer.write( CLIReportingUtils.NEWLINE );
Throwable cause = coreErrorReporter.getRealCause( reportingError );
if ( cause != null )
{
cause.printStackTrace( new PrintWriter( writer ) );
}
}
writer.write( CLIReportingUtils.NEWLINE );
writer.write( CLIReportingUtils.NEWLINE );
result = true;
}
else
{
result = proceed( e, showStackTraces, writer );
}
return result;
}
}
}

View File

@ -1,14 +1,14 @@
package org.apache.maven.cli;
import org.apache.maven.BuildFailureException;
import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
import org.apache.maven.embedder.MavenEmbedderLogger;
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.errors.DefaultCoreErrorReporter;
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.lifecycle.LifecycleExecutionException;
import org.apache.maven.project.DuplicateProjectException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.reactor.MavenExecutionException;
@ -128,7 +128,7 @@ public final class CLIReportingUtils
{
Exception e = (Exception) i.next();
showError( e, request.isShowErrors(), logger );
showError( e, request.isShowErrors(), request.getErrorReporter(), logger );
}
}
else
@ -178,14 +178,15 @@ public final class CLIReportingUtils
Exception e,
boolean showErrors )
{
showError( message, e, showErrors, new MavenEmbedderConsoleLogger() );
showError( message, e, showErrors, new DefaultCoreErrorReporter(), new MavenEmbedderConsoleLogger() );
}
static void showError( Exception e,
boolean show,
CoreErrorReporter reporter,
MavenEmbedderLogger logger )
{
showError( null, e, show, logger );
showError( null, e, show, reporter, logger );
}
/**
@ -198,6 +199,7 @@ public final class CLIReportingUtils
public static void showError( String message,
Exception e,
boolean showStackTraces,
CoreErrorReporter reporter,
MavenEmbedderLogger logger )
{
StringWriter writer = new StringWriter();
@ -210,7 +212,7 @@ public final class CLIReportingUtils
writer.write( NEWLINE );
}
buildErrorMessage( e, showStackTraces, writer );
buildErrorMessage( e, showStackTraces, reporter, writer );
writer.write( NEWLINE );
@ -231,17 +233,38 @@ public final class CLIReportingUtils
public static void buildErrorMessage( Exception e,
boolean showStackTraces,
CoreErrorReporter reporter,
StringWriter writer )
{
if ( reporter != null )
{
Throwable reported = reporter.findReportedException( e );
if ( reported != null )
{
writer.write( reporter.getFormattedMessage( reported ) );
if ( showStackTraces )
{
writer.write( NEWLINE );
writer.write( NEWLINE );
Throwable cause = reporter.getRealCause( reported );
if ( cause != null )
{
cause.printStackTrace( new PrintWriter( writer ) );
}
}
writer.write( NEWLINE );
writer.write( NEWLINE );
return;
}
}
boolean handled = false;
if ( e instanceof BuildFailureException )
{
handled = handleBuildFailureException( (BuildFailureException) e,
showStackTraces,
writer );
}
else if ( e instanceof ProjectBuildingException )
if ( e instanceof ProjectBuildingException )
{
handled = handleProjectBuildingException( (ProjectBuildingException) e,
showStackTraces,
@ -253,12 +276,6 @@ public final class CLIReportingUtils
showStackTraces,
writer );
}
else if ( e instanceof DuplicateProjectException )
{
handled = handleDuplicateProjectException( (DuplicateProjectException) e,
showStackTraces,
writer );
}
else if ( e instanceof MavenExecutionException )
{
handled = handleMavenExecutionException( (MavenExecutionException) e,
@ -291,15 +308,6 @@ public final class CLIReportingUtils
return true;
}
private static boolean handleDuplicateProjectException( DuplicateProjectException e,
boolean showStackTraces,
StringWriter writer )
{
handleGenericException( e, showStackTraces, writer );
return true;
}
private static void handleGenericException( Throwable exception,
boolean showStackTraces,
StringWriter writer )
@ -330,7 +338,6 @@ public final class CLIReportingUtils
return true;
}
// NOTE: This method is an aspect target.
private static boolean handleProjectBuildingException( ProjectBuildingException e,
boolean showStackTraces,
StringWriter writer )
@ -355,16 +362,6 @@ public final class CLIReportingUtils
return true;
}
// NOTE: This method is an aspect target.
private static boolean handleBuildFailureException( BuildFailureException e,
boolean showStackTraces,
StringWriter writer )
{
handleGenericException( e, showStackTraces, writer );
return true;
}
private static void logReactorSummary( ReactorManager rm,
MavenEmbedderLogger logger )
{

View File

@ -29,6 +29,7 @@ import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.embedder.MavenEmbedderFileLogger;
import org.apache.maven.embedder.MavenEmbedderLogger;
import org.apache.maven.errors.DefaultCoreErrorReporter;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.codehaus.plexus.classworlds.ClassWorld;
@ -145,6 +146,8 @@ public class MavenCli
Configuration configuration = buildEmbedderConfiguration( request, commandLine, classWorld );
System.out.println( "Using error reporter: " + configuration.getErrorReporter() );
ConfigurationValidationResult cvr = MavenEmbedder.validateConfiguration( configuration );
if ( cvr.isUserSettingsFilePresent() && !cvr.isUserSettingsFileParses() )
@ -209,6 +212,7 @@ public class MavenCli
}
Configuration configuration = new DefaultConfiguration()
.setErrorReporter( new DefaultCoreErrorReporter() )
.setUserSettingsFile( userSettingsFile )
.setGlobalSettingsFile( MavenEmbedder.DEFAULT_GLOBAL_SETTINGS_FILE )
.setClassWorld( classWorld );

View File

@ -18,6 +18,7 @@ package org.apache.maven.embedder;
* under the License.
*/
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.execution.MavenRealmManager;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.ClassWorld;
@ -131,4 +132,13 @@ public interface Configuration
Configuration setRealmManager( MavenRealmManager realmManager );
MavenRealmManager getRealmManager();
// ----------------------------------------------------------------------------
// Error Reporter
// ----------------------------------------------------------------------------
Configuration setErrorReporter( CoreErrorReporter errorReporter );
CoreErrorReporter getErrorReporter();
}

View File

@ -18,6 +18,7 @@ package org.apache.maven.embedder;
* under the License.
*/
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.execution.MavenRealmManager;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.ClassWorld;
@ -61,6 +62,8 @@ public class DefaultConfiguration
private MavenRealmManager realmManager;
private CoreErrorReporter errorReporter;
/** Creates a new instance of DefaultConfiguration */
public DefaultConfiguration()
{
@ -232,4 +235,15 @@ public class DefaultConfiguration
this.realmManager = realmManager;
return this;
}
public CoreErrorReporter getErrorReporter()
{
return errorReporter;
}
public Configuration setErrorReporter( CoreErrorReporter errorReporter )
{
this.errorReporter = errorReporter;
return this;
}
}

View File

@ -31,6 +31,8 @@ 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.embedder.execution.MavenExecutionRequestPopulator;
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.errors.CoreReporterManager;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenExecutionRequest;
@ -330,6 +332,11 @@ public class MavenEmbedder
public MavenProject readProject( File mavenProject )
throws ProjectBuildingException, ExtensionScanningException
{
CoreErrorReporter errorReporter = request.getErrorReporter();
errorReporter.clearErrors();
CoreReporterManager.setReporter( errorReporter );
return readProject( mavenProject, request );
}
@ -358,6 +365,11 @@ public class MavenEmbedder
{
request = populator.populateDefaults( request, configuration );
CoreErrorReporter errorReporter = request.getErrorReporter();
errorReporter.clearErrors();
CoreReporterManager.setReporter( errorReporter );
// This is necessary to make the MavenEmbedderProjectWithExtensionReadingTest work which uses
// a custom type for a dependency like this:
//
@ -796,6 +808,11 @@ public class MavenEmbedder
return result;
}
CoreErrorReporter errorReporter = request.getErrorReporter();
errorReporter.clearErrors();
CoreReporterManager.setReporter( errorReporter );
return maven.execute( request );
}
finally

View File

@ -28,6 +28,7 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.embedder.Configuration;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.errors.DefaultCoreErrorReporter;
import org.apache.maven.execution.DefaultMavenRealmManager;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.model.Profile;
@ -97,6 +98,8 @@ public class DefaultMavenExecutionRequestPopulator
Configuration configuration )
throws MavenEmbedderException
{
reporter( request, configuration );
executionProperties( request, configuration );
pom( request, configuration );
@ -124,6 +127,22 @@ public class DefaultMavenExecutionRequestPopulator
return request;
}
private void reporter( MavenExecutionRequest request,
Configuration configuration )
{
if ( request.getErrorReporter() == null )
{
if ( configuration.getErrorReporter() != null )
{
request.setErrorReporter( configuration.getErrorReporter() );
}
else
{
request.setErrorReporter( new DefaultCoreErrorReporter() );
}
}
}
private void executionProperties( MavenExecutionRequest request,
Configuration configuration )
{

View File

@ -0,0 +1,34 @@
package org.apache.maven.project.aspect;
import org.apache.maven.project.error.ProjectErrorReporter;
import org.apache.maven.project.error.DefaultProjectErrorReporter;
import org.aspectj.lang.reflect.SourceLocation;
public privileged aspect ProjectReporterDebugAspect
{
// before( Throwable key, String message, DefaultProjectErrorReporter reporter ):
// call( void DefaultProjectErrorReporter.registerBuildError( Throwable, String, .. ) )
// && args( key, message, .. )
// && target( reporter )
// {
// SourceLocation location = thisJoinPoint.getSourceLocation();
// System.out.println( "Registering: " + key.getClass().getName() + "@" + key.hashCode() + "\nfrom: " + location.getFileName() + ", line: " + location.getLine() + "\nreporter is: " + reporter + "\n\nMessage:\n\n" + message );
// }
//
// before():
// execution( void DefaultProjectErrorReporter.clearErrors() )
// {
// System.out.println( "WARNING: CLEARING ALL ERROR REPORTS." );
// }
//
// after() returning( Throwable key ):
// execution( Throwable ProjectErrorReporter+.findReportedException( Throwable ) )
// {
// if ( key != null )
// {
// System.out.println( "Found reported exception: " + key.getClass().getName() + "@" + key.hashCode() );
// }
// }
}

View File

@ -37,9 +37,23 @@ public class DefaultProjectErrorReporter
implements ProjectErrorReporter
{
private Map formattedMessages = new HashMap();
private static final String NEWLINE = "\n";
private Map realCauses = new HashMap();
private Map formattedMessages;
private Map realCauses;
public DefaultProjectErrorReporter( Map formattedMessageStore, Map realCauseStore )
{
formattedMessages = formattedMessageStore;
realCauses = realCauseStore;
}
public DefaultProjectErrorReporter()
{
formattedMessages = new HashMap();
realCauses = new HashMap();
}
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#clearErrors()
@ -83,7 +97,7 @@ public class DefaultProjectErrorReporter
return (Throwable) realCauses.get( error );
}
private void registerProjectBuildError( Throwable error,
protected void registerBuildError( Throwable error,
String formattedMessage,
Throwable realCause )
{
@ -91,7 +105,7 @@ public class DefaultProjectErrorReporter
realCauses.put( error, realCause );
}
private void registerProjectBuildError( Throwable error,
protected void registerBuildError( Throwable error,
String formattedMessage )
{
formattedMessages.put( error, formattedMessage );
@ -133,7 +147,7 @@ public class DefaultProjectErrorReporter
context,
cause ), writer );
registerProjectBuildError( cause, writer.toString(), cause.getCause() );
registerBuildError( cause, writer.toString(), cause.getCause() );
}
/**
@ -173,7 +187,7 @@ public class DefaultProjectErrorReporter
cause ),
writer );
registerProjectBuildError( cause, writer.toString(), cause.getCause() );
registerBuildError( cause, writer.toString(), cause.getCause() );
}
/**
@ -207,7 +221,7 @@ public class DefaultProjectErrorReporter
cause ),
writer );
registerProjectBuildError( cause, writer.toString(), cause.getCause() );
registerBuildError( cause, writer.toString(), cause.getCause() );
}
/**
@ -241,7 +255,7 @@ public class DefaultProjectErrorReporter
cause ),
writer );
registerProjectBuildError( cause, writer.toString(), cause.getCause() );
registerBuildError( cause, writer.toString(), cause.getCause() );
}
/**
@ -270,7 +284,7 @@ public class DefaultProjectErrorReporter
projectDir,
cause ), writer );
registerProjectBuildError( cause, writer.toString(), cause.getCause() );
registerBuildError( cause, writer.toString(), cause.getCause() );
}
/**
@ -306,7 +320,7 @@ public class DefaultProjectErrorReporter
projectDir,
cause ), writer );
registerProjectBuildError( cause, writer.toString(), cause.getCause() );
registerBuildError( cause, writer.toString(), cause.getCause() );
}
/**
@ -336,7 +350,7 @@ public class DefaultProjectErrorReporter
addTips( ProjectErrorTips.getTipsForInvalidRepositorySpec( repo, projectId, pomFile, cause ),
writer );
registerProjectBuildError( cause, writer.toString(), cause.getCause() );
registerBuildError( cause, writer.toString(), cause.getCause() );
}
private void addStandardInfo( String projectId,
@ -395,7 +409,7 @@ public class DefaultProjectErrorReporter
addTips( ProjectErrorTips.getTipsForInvalidRepositorySpec( repo, project.getId(), pomFile, cause ),
writer );
registerProjectBuildError( cause, writer.toString() );
registerBuildError( cause, writer.toString() );
}
public void reportErrorCreatingDeploymentArtifactRepository( MavenProject project,
@ -421,7 +435,7 @@ public class DefaultProjectErrorReporter
addTips( ProjectErrorTips.getTipsForInvalidRepositorySpec( repo, project.getId(), pomFile, cause ),
writer );
registerProjectBuildError( cause, writer.toString() );
registerBuildError( cause, writer.toString() );
}
public void reportBadNonDependencyProjectArtifactVersion( MavenProject project,
@ -446,7 +460,7 @@ public class DefaultProjectErrorReporter
addTips( ProjectErrorTips.getTipsForBadNonDependencyArtifactSpec( project, pomFile, cause ),
writer );
registerProjectBuildError( cause, writer.toString() );
registerBuildError( cause, writer.toString() );
}
public void reportErrorInterpolatingModel( MavenProject project,
@ -464,7 +478,7 @@ public class DefaultProjectErrorReporter
addTips( ProjectErrorTips.getTipsForProjectInterpolationError( project, pomFile, cause ),
writer );
registerProjectBuildError( cause, writer.toString() );
registerBuildError( cause, writer.toString() );
}
public void reportProjectValidationFailure( MavenProject project,
@ -492,7 +506,7 @@ public class DefaultProjectErrorReporter
addTips( ProjectErrorTips.getTipsForProjectValidationFailure( project, pomFile, error.getValidationResult() ),
writer );
registerProjectBuildError( error, writer.toString() );
registerBuildError( error, writer.toString() );
}
public void reportBadManagedDependencyVersion( MavenProject project,
@ -528,7 +542,7 @@ public class DefaultProjectErrorReporter
addTips( ProjectErrorTips.getTipsForBadDependencySpec( project, pomFile, dep ),
writer );
registerProjectBuildError( cause, writer.toString() );
registerBuildError( cause, writer.toString() );
}
public void reportBadDependencyVersion( MavenProject project,
@ -564,7 +578,7 @@ public class DefaultProjectErrorReporter
addTips( ProjectErrorTips.getTipsForBadDependencySpec( project, pomFile, dep ),
writer );
registerProjectBuildError( cause, writer.toString() );
registerBuildError( cause, writer.toString() );
}
public void reportErrorParsingProjectModel( String projectId,
@ -599,7 +613,7 @@ public class DefaultProjectErrorReporter
addTips( ProjectErrorTips.getTipsForPomParsingError( projectId, pomFile, cause ),
writer );
registerProjectBuildError( cause, writer.toString() );
registerBuildError( cause, writer.toString() );
}
public void reportErrorParsingParentProjectModel( ModelAndFile childInfo,
@ -643,7 +657,7 @@ public class DefaultProjectErrorReporter
addTips( ProjectErrorTips.getTipsForPomParsingError( projectId, parentPomFile, cause ),
writer );
registerProjectBuildError( cause, writer.toString() );
registerBuildError( cause, writer.toString() );
}
public void reportErrorParsingProjectModel( String projectId,
@ -671,7 +685,7 @@ public class DefaultProjectErrorReporter
addTips( ProjectErrorTips.getTipsForPomParsingError( projectId, pomFile, cause ),
writer );
registerProjectBuildError( cause, writer.toString() );
registerBuildError( cause, writer.toString() );
}
public void reportErrorParsingParentProjectModel( ModelAndFile childInfo,
@ -708,7 +722,7 @@ public class DefaultProjectErrorReporter
addTips( ProjectErrorTips.getTipsForPomParsingError( projectId, parentPomFile, cause ),
writer );
registerProjectBuildError( cause, writer.toString() );
registerBuildError( cause, writer.toString() );
}
public void reportParentPomArtifactNotFound( Parent parentRef,
@ -790,7 +804,7 @@ public class DefaultProjectErrorReporter
addTips( ProjectErrorTips.getTipsForPomParsingError( childId, childPomFile, cause ),
writer );
registerProjectBuildError( cause, writer.toString() );
registerBuildError( cause, writer.toString() );
}
public void reportProjectCollision( List allProjectInstances,
@ -820,6 +834,6 @@ public class DefaultProjectErrorReporter
addTips( ProjectErrorTips.getTipsForDuplicateProjectError( allProjectInstances, err ),
writer );
registerProjectBuildError( err, writer.toString() );
registerBuildError( err, writer.toString() );
}
}

View File

@ -30,8 +30,6 @@ import java.util.List;
public interface ProjectErrorReporter
{
String NEWLINE = "\n";
void clearErrors();
String getFormattedMessage( Throwable error );