From 441b096e795beb689a9a743a90b99faa522b941c Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Wed, 12 Dec 2007 00:52:26 +0000 Subject: [PATCH] Mapping in most of the rest of the maven-core errors to the error reporter...just need to finish the ExtensionManagerException mappings, then write error reports for the new mappings from today, and we should be in good shape. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@603431 13f79535-47bb-0310-9956-ffa450edef68 --- ...spect.aj => AbstractCoreReporterAspect.aj} | 2 +- .../errors/BuildFailureReporterAspect.aj | 90 ++- .../errors/ExtensionErrorReporterAspect.aj | 68 ++ .../errors/LifecycleErrorReporterAspect.aj | 249 ++++++ .../errors/MavenExecErrorReporterAspect.aj | 102 +++ .../java/org/apache/maven/DefaultMaven.java | 19 +- .../maven/errors/CoreErrorReporter.java | 71 ++ .../apache/maven/errors/CoreErrorTips.java | 130 ++- .../errors/DefaultCoreErrorReporter.java | 744 ++++++++++++++++++ .../DefaultBuildExtensionScanner.java | 26 +- .../extension/DefaultExtensionManager.java | 6 - .../extension/ExtensionManagerException.java | 13 - .../LifecycleExecutionException.java | 40 - .../maven/plugin/DefaultPluginManager.java | 1 + .../reactor/MavenExecutionException.java | 6 - .../embedder/cache/ErrorReportingAspect.aj | 49 +- .../apache/maven/cli/CLIReportingUtils.java | 147 +--- 17 files changed, 1522 insertions(+), 241 deletions(-) rename maven-core/src/main/aspect/org/apache/maven/errors/{AbstractCoreReporterManagerAspect.aj => AbstractCoreReporterAspect.aj} (72%) create mode 100644 maven-core/src/main/aspect/org/apache/maven/errors/ExtensionErrorReporterAspect.aj create mode 100644 maven-core/src/main/aspect/org/apache/maven/errors/LifecycleErrorReporterAspect.aj create mode 100644 maven-core/src/main/aspect/org/apache/maven/errors/MavenExecErrorReporterAspect.aj diff --git a/maven-core/src/main/aspect/org/apache/maven/errors/AbstractCoreReporterManagerAspect.aj b/maven-core/src/main/aspect/org/apache/maven/errors/AbstractCoreReporterAspect.aj similarity index 72% rename from maven-core/src/main/aspect/org/apache/maven/errors/AbstractCoreReporterManagerAspect.aj rename to maven-core/src/main/aspect/org/apache/maven/errors/AbstractCoreReporterAspect.aj index 54f25b3321..9f687d2747 100644 --- a/maven-core/src/main/aspect/org/apache/maven/errors/AbstractCoreReporterManagerAspect.aj +++ b/maven-core/src/main/aspect/org/apache/maven/errors/AbstractCoreReporterAspect.aj @@ -1,6 +1,6 @@ package org.apache.maven.errors; -public abstract aspect AbstractCoreReporterManagerAspect +public abstract aspect AbstractCoreReporterAspect { protected CoreErrorReporter getReporter() diff --git a/maven-core/src/main/aspect/org/apache/maven/errors/BuildFailureReporterAspect.aj b/maven-core/src/main/aspect/org/apache/maven/errors/BuildFailureReporterAspect.aj index 70e005ab08..9e056f12b7 100644 --- a/maven-core/src/main/aspect/org/apache/maven/errors/BuildFailureReporterAspect.aj +++ b/maven-core/src/main/aspect/org/apache/maven/errors/BuildFailureReporterAspect.aj @@ -17,13 +17,24 @@ import org.apache.maven.ProjectBuildFailureException; import org.apache.maven.Maven; public aspect BuildFailureReporterAspect - extends AbstractCoreReporterManagerAspect + extends AbstractCoreReporterAspect { private pointcut le_execute( MavenSession session, ReactorManager reactorManager ): execution( void LifecycleExecutor+.execute( MavenSession, ReactorManager, .. ) ) && args( session, reactorManager, .. ); + /** + * Call stack is: + *
+ *
+     * 
+     * DefaultMaven.execute(MavenExecutionRequest)
+     * --> DefaultLifecycleExecutor.execute(MavenSession, ReactorManager, EventDispatcher)
+     * <-- NoGoalsSpecifiedException
+     * 
+     * 
+ */ after( ReactorManager reactorManager, NoGoalsSpecifiedException err ): cflow( le_execute( MavenSession, reactorManager ) ) && execution( NoGoalsSpecifiedException.new( .. ) ) @@ -33,9 +44,22 @@ public aspect BuildFailureReporterAspect } private pointcut aggregatedBuildFailureException_ctor( MojoBinding binding, MojoFailureException cause ): - execution( AggregatedBuildFailureException.new( .., MojoBinding, MojoFailureException ) ) + call( AggregatedBuildFailureException.new( .., MojoBinding, MojoFailureException ) ) && args( .., binding, cause ); + /** + * Call stack is: + *
+ *
+     * 
+     * DefaultMaven.execute(MavenExecutionRequest)
+     * --> DefaultLifecycleExecutor.execute(MavenSession, ReactorManager, EventDispatcher)
+     *        --> DefaultLifecycleExecutor.executeTaskSegments(List, ReactorManager, MavenSession, MavenProject, EventDispatcher)
+     *               --> (@aggregator plugin execution)
+     * <---------------- AggregatedBuildFailureException
+     * 
+     * 
+ */ after( MavenSession session, MojoBinding binding, MojoFailureException cause ): cflow( le_execute( session, ReactorManager ) ) && aggregatedBuildFailureException_ctor( binding, cause ) @@ -44,9 +68,22 @@ public aspect BuildFailureReporterAspect } private pointcut projectBuildFailureException_ctor( MojoBinding binding, MojoFailureException cause ): - execution( ProjectBuildFailureException.new( .., MojoBinding, MojoFailureException ) ) + call( ProjectBuildFailureException.new( .., MojoBinding, MojoFailureException ) ) && args( .., binding, cause ); + /** + * Call stack is: + *
+ *
+     * 
+     * DefaultMaven.execute(MavenExecutionRequest)
+     * --> DefaultLifecycleExecutor.execute(MavenSession, ReactorManager, EventDispatcher)
+     *        --> DefaultLifecycleExecutor.executeTaskSegments(List, ReactorManager, MavenSession, MavenProject, EventDispatcher)
+     *               --> (normal plugin execution)
+     * <---------------- ProjectBuildFailureException
+     * 
+     * 
+ */ after( MavenSession session, MojoBinding binding, MojoFailureException cause ): cflow( le_execute( session, ReactorManager ) ) && projectBuildFailureException_ctor( binding, cause ) @@ -57,6 +94,17 @@ public aspect BuildFailureReporterAspect private pointcut mvn_createReactorManager(): execution( ReactorManager Maven+.createReactorManager( .. ) ); + /** + * Call stack is: + *
+ *
+     * 
+     * DefaultMaven.execute(MavenExecutionRequest)
+     * --> DefaultMaven.createReactorManager(MavenExecutionRequest, MavenExecutionResult)
+     * <-- ProjectCycleException
+     * 
+     * 
+ */ after( ProjectCycleException err ): cflow( mvn_createReactorManager() ) && execution( ProjectCycleException.new( .. ) ) @@ -69,6 +117,18 @@ public aspect BuildFailureReporterAspect execution( TaskValidationResult LifecycleExecutor+.isTaskValid( .., MavenSession, MavenProject ) ) && args( .., session, rootProject ); + /** + * Call stack is: + *
+ *
+     * 
+     * DefaultMaven.execute(MavenExecutionRequest)
+     * --> DefaultLifecycleExecutor.isTaskValid(String, MavenSession, MavenProject)
+     *        --> catch( PluginLoaderException )
+     * <-- TaskValidationResult
+     * 
+     * 
+ */ before( MavenSession session, MavenProject rootProject, PluginLoaderException cause, TaskValidationResult result ): cflow( le_isTaskValid( session, rootProject ) ) && execution( TaskValidationResult.new( .., PluginLoaderException ) ) @@ -78,6 +138,18 @@ public aspect BuildFailureReporterAspect getReporter().reportPluginErrorWhileValidatingTask( session, rootProject, cause, result ); } + /** + * Call stack is: + *
+ *
+     * 
+     * DefaultMaven.execute(MavenExecutionRequest)
+     * --> DefaultLifecycleExecutor.isTaskValid(String, MavenSession, MavenProject)
+     *        --> catch( LifecycleSpecificationException )
+     * <-- TaskValidationResult
+     * 
+     * 
+ */ before( MavenSession session, MavenProject rootProject, LifecycleSpecificationException cause, TaskValidationResult result ): cflow( le_isTaskValid( session, rootProject ) ) && execution( TaskValidationResult.new( .., LifecycleSpecificationException ) ) @@ -87,6 +159,18 @@ public aspect BuildFailureReporterAspect getReporter().reportLifecycleSpecErrorWhileValidatingTask( session, rootProject, cause, result ); } + /** + * Call stack is: + *
+ *
+     * 
+     * DefaultMaven.execute(MavenExecutionRequest)
+     * --> DefaultLifecycleExecutor.isTaskValid(String, MavenSession, MavenProject)
+     *        --> catch( LifecycleLoaderException )
+     * <-- TaskValidationResult
+     * 
+     * 
+ */ before( MavenSession session, MavenProject rootProject, LifecycleLoaderException cause, TaskValidationResult result ): cflow( le_isTaskValid( session, rootProject ) ) && execution( TaskValidationResult.new( .., LifecycleLoaderException ) ) diff --git a/maven-core/src/main/aspect/org/apache/maven/errors/ExtensionErrorReporterAspect.aj b/maven-core/src/main/aspect/org/apache/maven/errors/ExtensionErrorReporterAspect.aj new file mode 100644 index 0000000000..2a2dab59e5 --- /dev/null +++ b/maven-core/src/main/aspect/org/apache/maven/errors/ExtensionErrorReporterAspect.aj @@ -0,0 +1,68 @@ +package org.apache.maven.errors; + +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.model.Model; +import org.apache.maven.extension.ExtensionScanningException; +import org.apache.maven.extension.DefaultBuildExtensionScanner; +import org.apache.maven.project.build.model.ModelLineage; +import org.apache.maven.project.interpolation.ModelInterpolator; +import org.apache.maven.project.interpolation.ModelInterpolationException; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public aspect ExtensionErrorReporterAspect + extends AbstractCoreReporterAspect +{ + + before( ProjectBuildingException cause ): + withincode( List DefaultBuildExtensionScanner.getInitialRemoteRepositories() ) + && call( ExtensionScanningException.new( String, ProjectBuildingException ) ) + && args( *, cause ) + { + getReporter().handleSuperPomBuildingError( cause ); + } + + private pointcut within_dbes_buildModelLineage( MavenExecutionRequest request ): + withincode( ModelLineage DefaultBuildExtensionScanner.buildModelLineage( File, MavenExecutionRequest, List ) ) + && args( *, request, * ); + + before( MavenExecutionRequest request, File pomFile, ProjectBuildingException cause ): + within_dbes_buildModelLineage( request ) + && call( ExtensionScanningException.new( String, File, ProjectBuildingException ) ) + && args( .., pomFile, cause ) + { + getReporter().handleProjectBuildingError( request, pomFile, cause ); + } + + private pointcut within_dbes_checkModulesForExtensions(): + withincode( * DefaultBuildExtensionScanner.checkModulesForExtensions( File, Model, MavenExecutionRequest, List, List, List ) ); + + before( File pomFile, IOException cause ): + within_dbes_checkModulesForExtensions() + && call( ExtensionScanningException.new( String, File, String, IOException ) ) + && args( *, pomFile, *, cause ) + { + getReporter().reportPomFileCanonicalizationError( pomFile, cause ); + } + + private pointcut dbes_scanInternal( File pomFile, MavenExecutionRequest request ): + execution( void DefaultBuildExtensionScanner.scanInternal( File, MavenExecutionRequest, .. ) ) + && args( pomFile, request, .. ); + + after( File pomFile, MavenExecutionRequest request, Model model, Map inheritedValues ) + throwing( ModelInterpolationException cause ): + cflow( dbes_scanInternal( pomFile, request ) ) + && within( DefaultBuildExtensionScanner ) + && call( Model ModelInterpolator+.interpolate( Model, Map, .. ) ) + && args( model, inheritedValues, .. ) + { + getReporter().reportErrorInterpolatingModel( model, inheritedValues, pomFile, request, cause ); + } + + // TODO: Finish ExtensionManagerException mapping! + +} diff --git a/maven-core/src/main/aspect/org/apache/maven/errors/LifecycleErrorReporterAspect.aj b/maven-core/src/main/aspect/org/apache/maven/errors/LifecycleErrorReporterAspect.aj new file mode 100644 index 0000000000..87f0a0d494 --- /dev/null +++ b/maven-core/src/main/aspect/org/apache/maven/errors/LifecycleErrorReporterAspect.aj @@ -0,0 +1,249 @@ +package org.apache.maven.errors; + +import org.codehaus.plexus.logging.console.ConsoleLogger; +import org.codehaus.plexus.logging.Logger; +import org.apache.maven.project.path.PathTranslator; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.plugin.PluginConfigurationException; +import org.apache.maven.plugin.descriptor.Parameter; +import org.apache.maven.plugin.loader.PluginLoaderException; +import org.apache.maven.plugin.PluginExecutionException; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.model.MojoBinding; +import org.apache.maven.lifecycle.DefaultLifecycleExecutor; +import org.apache.maven.lifecycle.LifecycleException; +import org.apache.maven.lifecycle.LifecycleExecutionException; +import org.apache.maven.project.MavenProject; +import org.apache.maven.plugin.DefaultPluginManager; +import org.apache.maven.plugin.PluginManager; +import org.apache.maven.plugin.PluginParameterExpressionEvaluator; +import org.apache.maven.plugin.PluginParameterException; +import org.apache.maven.plugin.Mojo; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.configuration.PlexusConfiguration; + +import java.util.List; + +public privileged aspect LifecycleErrorReporterAspect + extends AbstractCoreReporterAspect +{ + + private pointcut le_executeGoalAndHandleFailures( MojoBinding binding ): + execution( void DefaultLifecycleExecutor.executeGoalAndHandleFailures( MojoBinding, .. ) ) + && args( binding, .. ); + + private pointcut pm_executeMojo( MavenProject project ): + execution( void PluginManager+.executeMojo( MavenProject, .. ) ) + && args( project, .. ); + + before( MojoBinding binding, MavenProject project, LifecycleExecutionException err ): + cflow( le_executeGoalAndHandleFailures( binding ) ) + && execution( LifecycleExecutionException.new( String, MavenProject ) ) + && args( .., project ) + && this( err ) + { + getReporter().reportMissingPluginDescriptor( binding, project, err ); + } + + before( MojoBinding binding, MavenProject project, PluginLoaderException cause ): + cflow( le_executeGoalAndHandleFailures( binding ) ) + && call( LifecycleExecutionException.new( String, MavenProject, PluginLoaderException ) ) + && args( *, project, cause ) + { + getReporter().reportErrorLoadingPlugin( binding, project, cause ); + } + + before( MojoBinding binding, MavenProject project, MojoExecutionException cause ): + cflow( le_executeGoalAndHandleFailures( binding ) ) + && cflow( pm_executeMojo( project ) ) + && handler( MojoExecutionException ) + && args( cause ) + { + getReporter().reportMojoExecutionException( binding, project, cause ); + } + + before( MojoBinding binding, MavenProject project, PluginExecutionException cause ): + cflow( le_executeGoalAndHandleFailures( binding ) ) + && cflow( pm_executeMojo( project ) ) + && !handler( MojoExecutionException ) + && execution( PluginExecutionException.new( .., String ) ) + && this( cause ) + { + getReporter().reportInvalidPluginExecutionEnvironment( binding, project, cause ); + } + + before( MojoBinding binding, MavenProject project, ComponentLookupException cause ): + cflow( le_executeGoalAndHandleFailures( binding ) ) + && cflow( pm_executeMojo( project ) ) + && withincode( Mojo DefaultPluginManager.getConfiguredMojo( .. ) ) + && handler( ComponentLookupException ) + && args( cause ) + { + getReporter().reportMojoLookupError( binding, project, cause ); + } + + Parameter currentParameter; + + private pointcut paramGetName( Parameter parameter ): + call( String Parameter.getName() ) + && target( parameter ); + + private pointcut pm_validatePomConfig(): + execution( void DefaultPluginManager.validatePomConfiguration( .. ) ); + + private pointcut within_pm_validatePomConfig(): + withincode( void DefaultPluginManager.validatePomConfiguration( .. ) ); + + private pointcut pm_checkRequiredParameters(): + execution( void DefaultPluginManager.checkRequiredParameters( .. ) ); + + private pointcut within_pm_checkRequiredParameters(): + withincode( void DefaultPluginManager.checkRequiredParameters( .. ) ); + + before( Parameter parameter ): + ( within_pm_validatePomConfig() + || within_pm_checkRequiredParameters() ) + && paramGetName( parameter ) + { + currentParameter = parameter; + } + + after() returning: + pm_validatePomConfig() || + pm_checkRequiredParameters() + { + currentParameter = null; + } + + private pointcut pm_executeMojoWithSessionAndExec( MavenProject project, MojoExecution exec, MavenSession session, DefaultPluginManager manager ): + execution( void DefaultPluginManager.executeMojo( MavenProject, MojoExecution, MavenSession ) ) + && args( project, exec, session ) + && this( manager ); + + after( MojoBinding binding, MavenProject project, MojoExecution exec, MavenSession session, DefaultPluginManager manager ) throwing( PluginConfigurationException cause ): + cflow( le_executeGoalAndHandleFailures( binding ) ) + && cflow( pm_executeMojoWithSessionAndExec( project, exec, session, manager ) ) + && pm_validatePomConfig() + { + PathTranslator translator = manager.pathTranslator; + Logger logger = new ConsoleLogger( Logger.LEVEL_INFO, "error reporting" ); + getReporter().reportAttemptToOverrideUneditableMojoParameter( currentParameter, binding, project, session, exec, translator, logger, cause ); + } + + before( MojoBinding binding, MavenProject project, List invalidParameters, PluginParameterException err ): + cflow( le_executeGoalAndHandleFailures( binding ) ) + && cflow( pm_executeMojo( project ) ) + && cflow( pm_checkRequiredParameters() ) + && execution( PluginParameterException.new( .., List ) ) + && args( .., invalidParameters ) + && this( err ) + { + getReporter().reportMissingRequiredMojoParameter( binding, project, invalidParameters, err ); + } + + private pointcut ppee_evaluate( String expression ): + execution( Object PluginParameterExpressionEvaluator.evaluate( String ) ) + && args( expression ); + + private pointcut within_ppee_evaluate( String expression ): + withincode( Object PluginParameterExpressionEvaluator.evaluate( String ) ) + && args( expression ); + + before( MojoBinding binding, MavenProject project, String expression, ExpressionEvaluationException err ): + cflow( le_executeGoalAndHandleFailures( binding ) ) + && cflow( pm_executeMojo( project ) ) + && cflow( pm_checkRequiredParameters() ) + && cflow( ppee_evaluate( expression ) ) + && execution( ExpressionEvaluationException.new( String ) ) + && this( err ) + { + getReporter().reportUseOfBannedMojoParameter( currentParameter, + binding, + project, + expression, + (String) PluginParameterExpressionEvaluator.BANNED_EXPRESSIONS.get( expression ), + err ); + } + + before( MojoBinding binding, MavenProject project, String expression, Exception cause ): + cflow( le_executeGoalAndHandleFailures( binding ) ) + && cflow( pm_executeMojo( project ) ) + && cflow( pm_checkRequiredParameters() ) + && cflow( ppee_evaluate( expression ) ) + && within( PluginParameterExpressionEvaluator ) + && handler( Exception ) + && args( cause ) + { + getReporter().reportReflectionErrorWhileEvaluatingMojoParameter( currentParameter, + binding, + project, + expression, + cause ); + } + + after( MojoBinding binding, MavenProject project, PlexusConfiguration config ) throwing( PluginConfigurationException cause ): + cflow( le_executeGoalAndHandleFailures( binding ) ) + && cflow( pm_executeMojo( project ) ) + && execution( void DefaultPluginManager.populatePluginFields( *, *, PlexusConfiguration, .. ) ) + && args( *, *, config, .. ) + { + getReporter().reportErrorApplyingMojoConfiguration( binding, project, config, cause ); + } + + private pointcut pm_resolveTransitiveDependencies( MavenProject project, String scope ): + execution( void DefaultPluginManager.resolveTransitiveDependencies( *, *, String, *, MavenProject ) ) + && args( *, *, scope, *, project ); + + after( MavenProject project, String scope ) throwing( ArtifactNotFoundException cause ): + pm_resolveTransitiveDependencies( project, scope ) + { + getReporter().reportProjectDependenciesNotFound( project, scope, cause ); + } + + after( MavenProject project, String scope ) throwing( ArtifactResolutionException cause ): + pm_resolveTransitiveDependencies( project, scope ) + { + getReporter().reportProjectDependenciesUnresolvable( project, scope, cause ); + } + + private pointcut within_pm_downloadDependencies( MavenProject project ): + withincode( void DefaultPluginManager.downloadDependencies( MavenProject, .. ) ) + && args( project, .. ); + + private pointcut ar_resolve( Artifact artifact ): + call( * ArtifactResolver+.resolve( Artifact, ..) ) + && args( artifact, .. ); + + after( MavenProject project, Artifact artifact ) throwing( ArtifactNotFoundException cause ): + within_pm_downloadDependencies( project ) + && ar_resolve( artifact ) + { + getReporter().reportProjectDependencyArtifactNotFound( project, artifact, cause ); + } + + after( MavenProject project, Artifact artifact ) throwing( ArtifactResolutionException cause ): + within_pm_downloadDependencies( project ) + && ar_resolve( artifact ) + { + getReporter().reportProjectDependencyArtifactUnresolvable( project, artifact, cause ); + } + + private pointcut le_getLifecycleBindings( List tasks, MavenProject configuringProject, String targetDescription ): + execution( List DefaultLifecycleExecutor.getLifecycleBindings( List, MavenProject, *, String ) ) + && args( tasks, configuringProject, *, targetDescription ); + + before( List tasks, MavenProject configuringProject, String targetDescription, LifecycleException cause ): + cflow( le_getLifecycleBindings( tasks, configuringProject, targetDescription ) ) + && call( LifecycleExecutionException.new( .., LifecycleException ) ) + && args( .., cause ) + { + getReporter().reportErrorFormulatingBuildPlan( tasks, configuringProject, targetDescription, cause ); + } + +} diff --git a/maven-core/src/main/aspect/org/apache/maven/errors/MavenExecErrorReporterAspect.aj b/maven-core/src/main/aspect/org/apache/maven/errors/MavenExecErrorReporterAspect.aj new file mode 100644 index 0000000000..e1d0761328 --- /dev/null +++ b/maven-core/src/main/aspect/org/apache/maven/errors/MavenExecErrorReporterAspect.aj @@ -0,0 +1,102 @@ +package org.apache.maven.errors; + +import org.apache.maven.reactor.MavenExecutionException; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.RuntimeInformation; +import org.apache.maven.profiles.ProfileManager; +import org.apache.maven.DefaultMaven; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.project.ProjectBuildingException; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +public aspect MavenExecErrorReporterAspect + extends AbstractCoreReporterAspect +{ + + private pointcut dm_getProjects( MavenExecutionRequest request ): + execution( List DefaultMaven.getProjects( MavenExecutionRequest ) ) + && args( request ); + + private pointcut dm_collectProjects( ArtifactRepository localRepository, ProfileManager globalProfileManager ): + execution( List DefaultMaven.collectProjects( List, ArtifactRepository, boolean, ProfileManager, boolean ) ) + && args( *, localRepository, *, globalProfileManager, * ); + + private MavenProject currentProject; + private ArtifactVersion mavenVersion; + + before( RuntimeInformation ri ): + call( * RuntimeInformation+.getApplicationVersion() ) + && within( DefaultMaven ) + && target( ri ) + { + mavenVersion = ri.getApplicationVersion(); + } + + MavenProject around() + throws ProjectBuildingException: + cflow( dm_collectProjects( ArtifactRepository, ProfileManager ) ) + && within( DefaultMaven ) + && call( MavenProject MavenProjectBuilder+.build( .. ) ) + { + currentProject = proceed(); + return currentProject; + } + + before( MavenExecutionRequest request, File pomFile, ProjectBuildingException exception ): + cflow( dm_getProjects( request ) ) + && cflow( dm_collectProjects( ArtifactRepository, ProfileManager ) ) + && call( MavenExecutionException.new( .., File, ProjectBuildingException ) ) + && args( .., pomFile, exception ) + { + getReporter().handleProjectBuildingError( request, pomFile, exception ); + } + + before( ProfileManager globalProfileManager, ProjectBuildingException exception ): + cflow( dm_getProjects( MavenExecutionRequest ) ) + && cflow( dm_collectProjects( ArtifactRepository, globalProfileManager ) ) + && call( MavenExecutionException.new( String, ProjectBuildingException ) ) + && args( .., exception ) + { + getReporter().handleSuperPomBuildingError( globalProfileManager, exception ); + } + + before( MavenExecutionException err ): + cflow( dm_getProjects( MavenExecutionRequest ) ) + && cflow( dm_collectProjects( ArtifactRepository, ProfileManager ) ) + && execution( MavenExecutionException.new( String, File ) ) + && this( err ) + { + getReporter().reportInvalidMavenVersion( currentProject, mavenVersion, err ); + } + + after(): dm_collectProjects( ArtifactRepository, ProfileManager ) + { + currentProject = null; + } + + after( File basedir, String includes, String excludes ) throwing( IOException cause ): + cflow( dm_getProjects( MavenExecutionRequest ) ) + && cflow( execution( * DefaultMaven.getProjectFiles( MavenExecutionRequest ) ) ) + && call( * FileUtils.getFiles( File, String, String ) ) + && args( basedir, includes, excludes ) + { + getReporter().reportPomFileScanningError( basedir, includes, excludes, cause ); + } + + after( File pomFile ) throwing( IOException cause ): + cflow( dm_getProjects( MavenExecutionRequest ) ) + && cflow( dm_collectProjects( ArtifactRepository, ProfileManager ) ) + && call( File File.getCanonicalFile() ) + && target( pomFile ) + { + getReporter().reportPomFileCanonicalizationError( pomFile, cause ); + } + +} diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index a7264cfd5a..b445c0a570 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -21,7 +21,6 @@ import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.execution.MavenExecutionRequest; @@ -185,6 +184,12 @@ public MavenExecutionResult execute( MavenExecutionRequest request ) { String goal = (String) i.next(); + if ( goal == null ) + { + i.remove(); + continue; + } + TaskValidationResult tvr = lifecycleExecutor.isTaskValid( goal, session, reactorManager.getTopLevelProject() ); if ( !tvr.isTaskValid() ) @@ -262,15 +267,7 @@ private List getProjects( MavenExecutionRequest request ) throw new MavenExecutionException( "Error scanning for extensions: " + e.getMessage(), e ); } - try - { - projects = collectProjects( files, request.getLocalRepository(), request.isRecursive(), request.getProfileManager(), !request.useReactor() ); - - } - catch ( ArtifactResolutionException e ) - { - throw new MavenExecutionException( e.getMessage(), e ); - } + projects = collectProjects( files, request.getLocalRepository(), request.isRecursive(), request.getProfileManager(), !request.useReactor() ); return projects; } @@ -280,7 +277,7 @@ private List collectProjects( List files, boolean recursive, ProfileManager globalProfileManager, boolean isRoot ) - throws ArtifactResolutionException, MavenExecutionException + throws MavenExecutionException { List projects = new ArrayList( files.size() ); diff --git a/maven-core/src/main/java/org/apache/maven/errors/CoreErrorReporter.java b/maven-core/src/main/java/org/apache/maven/errors/CoreErrorReporter.java index 8c522506f5..bde924daad 100644 --- a/maven-core/src/main/java/org/apache/maven/errors/CoreErrorReporter.java +++ b/maven-core/src/main/java/org/apache/maven/errors/CoreErrorReporter.java @@ -2,14 +2,42 @@ import org.apache.maven.NoGoalsSpecifiedException; import org.apache.maven.ProjectCycleException; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.LifecycleException; +import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.LifecycleLoaderException; import org.apache.maven.lifecycle.LifecycleSpecificationException; import org.apache.maven.lifecycle.TaskValidationResult; import org.apache.maven.lifecycle.model.MojoBinding; +import org.apache.maven.model.Model; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.PluginConfigurationException; +import org.apache.maven.plugin.PluginExecutionException; +import org.apache.maven.plugin.PluginParameterException; +import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.loader.PluginLoaderException; +import org.apache.maven.profiles.ProfileManager; import org.apache.maven.project.MavenProject; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.project.interpolation.ModelInterpolationException; +import org.apache.maven.project.path.PathTranslator; +import org.apache.maven.reactor.MavenExecutionException; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.configuration.PlexusConfiguration; +import org.codehaus.plexus.logging.Logger; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; public interface CoreErrorReporter { @@ -38,4 +66,47 @@ public interface CoreErrorReporter void reportLifecycleLoaderErrorWhileValidatingTask( MavenSession session, MavenProject rootProject, LifecycleLoaderException cause, TaskValidationResult result ); + void reportMissingPluginDescriptor( MojoBinding binding, MavenProject project, LifecycleExecutionException err ); + + void reportMojoExecutionException( MojoBinding binding, MavenProject project, MojoExecutionException cause ); + + void reportInvalidPluginExecutionEnvironment( MojoBinding binding, MavenProject project, PluginExecutionException cause ); + + void reportMojoLookupError( MojoBinding binding, MavenProject project, ComponentLookupException cause ); + + void reportAttemptToOverrideUneditableMojoParameter( Parameter currentParameter, MojoBinding binding, MavenProject project, MavenSession session, MojoExecution exec, PathTranslator translator, Logger logger, PluginConfigurationException cause ); + + void reportMissingRequiredMojoParameter( MojoBinding binding, MavenProject project, List invalidParameters, PluginParameterException err ); + + void reportUseOfBannedMojoParameter( Parameter currentParameter, MojoBinding binding, MavenProject project, String expression, String altExpression, ExpressionEvaluationException err ); + + void reportReflectionErrorWhileEvaluatingMojoParameter( Parameter currentParameter, MojoBinding binding, MavenProject project, String expression, Exception cause ); + + void reportErrorApplyingMojoConfiguration( MojoBinding binding, MavenProject project, PlexusConfiguration config, PluginConfigurationException cause ); + + void reportProjectDependenciesNotFound( MavenProject project, String scope, ArtifactNotFoundException cause ); + + void reportProjectDependenciesUnresolvable( MavenProject project, String scope, ArtifactResolutionException cause ); + + void reportProjectDependencyArtifactNotFound( MavenProject project, Artifact artifact, ArtifactNotFoundException cause ); + + void reportProjectDependencyArtifactUnresolvable( MavenProject project, Artifact artifact, ArtifactResolutionException cause ); + + void reportErrorLoadingPlugin( MojoBinding binding, MavenProject project, PluginLoaderException cause ); + + void reportErrorFormulatingBuildPlan( List tasks, MavenProject configuringProject, String targetDescription, LifecycleException cause ); + + void handleProjectBuildingError( MavenExecutionRequest request, File pomFile, ProjectBuildingException exception ); + + void reportInvalidMavenVersion( MavenProject project, ArtifactVersion mavenVersion, MavenExecutionException err ); + + void reportPomFileScanningError( File basedir, String includes, String excludes, IOException cause ); + + void reportPomFileCanonicalizationError( File pomFile, IOException cause ); + + void handleSuperPomBuildingError( ProfileManager globalProfileManager, ProjectBuildingException exception ); + + void handleSuperPomBuildingError( ProjectBuildingException exception ); + + void reportErrorInterpolatingModel( Model model, Map inheritedValues, File pomFile, MavenExecutionRequest request, ModelInterpolationException cause ); } diff --git a/maven-core/src/main/java/org/apache/maven/errors/CoreErrorTips.java b/maven-core/src/main/java/org/apache/maven/errors/CoreErrorTips.java index 6f5672a2dc..0e42acb523 100644 --- a/maven-core/src/main/java/org/apache/maven/errors/CoreErrorTips.java +++ b/maven-core/src/main/java/org/apache/maven/errors/CoreErrorTips.java @@ -1,9 +1,23 @@ package org.apache.maven.errors; import org.apache.maven.ProjectCycleException; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException; +import org.apache.maven.lifecycle.LifecycleException; import org.apache.maven.lifecycle.TaskValidationResult; import org.apache.maven.lifecycle.model.MojoBinding; +import org.apache.maven.model.Model; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.PluginConfigurationException; +import org.apache.maven.plugin.PluginExecutionException; +import org.apache.maven.plugin.descriptor.Parameter; +import org.apache.maven.plugin.loader.PluginLoaderException; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.interpolation.ModelInterpolationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.configuration.PlexusConfiguration; +import java.io.File; import java.util.Arrays; import java.util.List; @@ -11,7 +25,7 @@ // I was using varargs in listOf(..). I'm not moving them to constants because I'd like // to go back to this someday... -// TODO: Optimize the String[] instances in here to List constants, and remove listOf(..) +// TODO: Fill these out!! public final class CoreErrorTips { @@ -49,4 +63,118 @@ public static List getTaskValidationTips( TaskValidationResult result, Exception return null; } + public static List getMissingPluginDescriptorTips( MojoBinding binding, + MavenProject project ) + { + // TODO Auto-generated method stub + return null; + } + + public static List getInvalidExecutionEnvironmentTips( MojoBinding binding, + MavenProject project, + PluginExecutionException cause ) + { + // TODO Auto-generated method stub + return null; + } + + public static List getMojoExecutionExceptionTips( MojoBinding binding, + MavenProject project, + MojoExecutionException cause ) + { + // TODO Auto-generated method stub + return null; + } + + public static List getMojoLookupErrorTips( MojoBinding binding, + MavenProject project, + ComponentLookupException cause ) + { + // TODO Auto-generated method stub + return null; + } + + public static List getUneditableMojoParameterTips( Parameter currentParameter, + MojoBinding binding, + MavenProject project, + PluginConfigurationException cause ) + { + // TODO Auto-generated method stub + return null; + } + + public static List getBannedParameterExpressionTips( Parameter currentParameter, + MojoBinding binding, + MavenProject project ) + { + // TODO Auto-generated method stub + return null; + } + + public static List getReflectionErrorInParameterExpressionTips( String expression, + Parameter currentParameter, + MojoBinding binding, + MavenProject project ) + { + // TODO Auto-generated method stub + return null; + } + + public static List getMissingRequiredParameterTips( List invalidParameters, + MojoBinding binding, + MavenProject project ) + { + // TODO Auto-generated method stub + return null; + } + + public static List getMojoConfigurationErrorTips( MojoBinding binding, + MavenProject project, + PlexusConfiguration config, + PluginConfigurationException cause ) + { + // TODO Auto-generated method stub + return null; + } + + public static List getBuildPlanningErrorTips( List tasks, + MavenProject configuringProject, + LifecycleException cause ) + { + // TODO Auto-generated method stub + return null; + } + + public static List getErrorLoadingPluginTips( MojoBinding binding, + MavenProject project, + PluginLoaderException cause ) + { + // TODO Auto-generated method stub + return null; + } + + public static List getDependencyArtifactResolutionTips( MavenProject project, + Artifact depArtifact, + AbstractArtifactResolutionException cause ) + { + // TODO Auto-generated method stub + return null; + } + + public static List getDependencyArtifactResolutionTips( MavenProject project, + String scope, + AbstractArtifactResolutionException cause ) + { + // TODO Auto-generated method stub + return null; + } + + public static List getTipsForModelInterpolationError( Model model, + File pomFile, + ModelInterpolationException cause ) + { + // TODO Auto-generated method stub + return null; + } + } diff --git a/maven-core/src/main/java/org/apache/maven/errors/DefaultCoreErrorReporter.java b/maven-core/src/main/java/org/apache/maven/errors/DefaultCoreErrorReporter.java index c9ff1fa838..8edf290658 100644 --- a/maven-core/src/main/java/org/apache/maven/errors/DefaultCoreErrorReporter.java +++ b/maven-core/src/main/java/org/apache/maven/errors/DefaultCoreErrorReporter.java @@ -2,18 +2,47 @@ import org.apache.maven.NoGoalsSpecifiedException; import org.apache.maven.ProjectCycleException; +import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.LifecycleException; +import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.LifecycleLoaderException; import org.apache.maven.lifecycle.LifecycleSpecificationException; import org.apache.maven.lifecycle.MojoBindingUtils; import org.apache.maven.lifecycle.TaskValidationResult; import org.apache.maven.lifecycle.model.MojoBinding; +import org.apache.maven.model.Model; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.PluginConfigurationException; +import org.apache.maven.plugin.PluginExecutionException; +import org.apache.maven.plugin.PluginParameterException; +import org.apache.maven.plugin.PluginParameterExpressionEvaluator; +import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.loader.PluginLoaderException; +import org.apache.maven.profiles.ProfileManager; import org.apache.maven.project.MavenProject; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.project.interpolation.ModelInterpolationException; +import org.apache.maven.project.path.PathTranslator; +import org.apache.maven.reactor.MavenExecutionException; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.configuration.PlexusConfiguration; +import org.codehaus.plexus.configuration.PlexusConfigurationException; +import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.dag.CycleDetectedException; +import java.io.File; +import java.io.IOException; import java.io.StringWriter; import java.util.HashMap; import java.util.Iterator; @@ -324,4 +353,719 @@ public void reportPluginErrorWhileValidatingTask( MavenSession session, registerBuildError( cause, writer.toString(), cause.getCause() ); } + + public void reportMissingPluginDescriptor( MojoBinding binding, + MavenProject project, + LifecycleExecutionException err ) + { + StringWriter writer = new StringWriter(); + + writer.write( NEWLINE ); + writer.write( "Maven cannot find a plugin required by your build:" ); + + writeMojoBinding( binding, writer ); + writer.write( "Referenced from project:" ); + writeProjectCoordinate( project, writer ); + + writer.write( "NOTE: If the above information seems incorrect, check that " + + "the corresponding section in your POM is correct." ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "If you specified this plugin directly using something like " + + "'javadoc:javadoc', check that the section in your " + + "$HOME/.m2/settings.xml contains the proper groupId for the plugin " + + "you are trying to use (each groupId goes in a separate " + + "element within the section." ); + + addTips( CoreErrorTips.getMissingPluginDescriptorTips( binding, project ), writer ); + + registerBuildError( err, writer.toString() ); + } + + public void reportInvalidPluginExecutionEnvironment( MojoBinding binding, + MavenProject project, + PluginExecutionException cause ) + { + StringWriter writer = new StringWriter(); + + writer.write( NEWLINE ); + writer.write( "The following plugin cannot function in the current build environment:" ); + + writeMojoBinding( binding, writer ); + writer.write( "Referenced from project:" ); + writeProjectCoordinate( project, writer ); + + writer.write( "Reason: " ); + writer.write( cause.getMessage() ); + + addTips( CoreErrorTips.getInvalidExecutionEnvironmentTips( binding, project, cause ), writer ); + + registerBuildError( cause, writer.toString() ); + } + + public void reportMojoExecutionException( MojoBinding binding, + MavenProject project, + MojoExecutionException cause ) + { + StringWriter writer = new StringWriter(); + + writer.write( NEWLINE ); + writer.write( "The following mojo encountered an error while executing:" ); + + writeMojoBinding( binding, writer ); + writer.write( "While building project:" ); + writeProjectCoordinate( project, writer ); + + writer.write( "Reason: " ); + writer.write( cause.getMessage() ); + + addTips( CoreErrorTips.getMojoExecutionExceptionTips( binding, project, cause ), writer ); + + registerBuildError( cause, writer.toString(), cause.getCause() ); + } + + public void reportMojoLookupError( MojoBinding binding, + MavenProject project, + ComponentLookupException cause ) + { + StringWriter writer = new StringWriter(); + + writer.write( NEWLINE ); + writer.write( "Maven encountered an error while looking up the following Mojo:" ); + + writeMojoBinding( binding, writer ); + writer.write( "Referenced from project:" ); + writeProjectCoordinate( project, writer ); + + writer.write( "Reason: " ); + writer.write( cause.getMessage() ); + + writer.write( NEWLINE ); + writer.write( NEWLINE ); + + writer.write( "Root cause: " ); + writer.write( getRootCause( cause ).getMessage() ); + + addTips( CoreErrorTips.getMojoLookupErrorTips( binding, project, cause ), writer ); + + registerBuildError( cause, writer.toString(), cause.getCause() ); + } + + private Throwable getRootCause( Throwable cause ) + { + Throwable nested = cause.getCause(); + if ( nested != null ) + { + return getRootCause( nested ); + } + else + { + return cause; + } + } + + public void reportAttemptToOverrideUneditableMojoParameter( Parameter currentParameter, + MojoBinding binding, + MavenProject project, + MavenSession session, + MojoExecution exec, + PathTranslator translator, + Logger logger, + PluginConfigurationException cause ) + { + StringWriter writer = new StringWriter(); + + writer.write( NEWLINE ); + writer.write( "The following mojo parameter cannot be configured:" ); + + writeParameter( currentParameter, writer ); + writer.write( "in mojo:" ); + writeMojoBinding( binding, writer ); + writer.write( "While building project:" ); + writeProjectCoordinate( project, writer ); + + PluginParameterExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator( + session, + exec, + translator, + logger, + session.getExecutionProperties() ); + + Object fromDefaultValue = null; + Object fromExpression = null; + try + { + if ( currentParameter.getDefaultValue() != null ) + { + fromDefaultValue = evaluator.evaluate( currentParameter.getDefaultValue() ); + } + + if ( currentParameter.getExpression() != null ) + { + fromExpression = evaluator.evaluate( currentParameter.getExpression() ); + } + } + catch ( ExpressionEvaluationException e ) + { + // ignored. + } + + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Instead of configuring this parameter directly, try configuring your POM or settings.xml file." ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Using the default-value and expression annotations built into the mojo itself, these values were found in your build:" ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Value: " ); + writer.write( String.valueOf( fromDefaultValue ) ); + writer.write( NEWLINE ); + writer.write( "Using the expression:" ); + writer.write( currentParameter.getDefaultValue() ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Value: " ); + writer.write( String.valueOf( fromExpression ) ); + writer.write( NEWLINE ); + writer.write( "Using the expression:" ); + writer.write( currentParameter.getExpression() ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "If one of the above expressions rendered a valid value, it " + + "may give some indication of which part of the POM or settings.xml " + + "you can modify in order to change this parameter's value." ); + + addTips( CoreErrorTips.getUneditableMojoParameterTips( currentParameter, binding, project, cause ), writer ); + + registerBuildError( cause, writer.toString() ); + } + + public void reportUseOfBannedMojoParameter( Parameter currentParameter, + MojoBinding binding, + MavenProject project, + String expression, + String altExpression, + ExpressionEvaluationException err ) + { + StringWriter writer = new StringWriter(); + + writer.write( NEWLINE ); + writer.write( "The following mojo-parameter expression is banned for use in POM configurations:" ); + writer.write( NEWLINE ); + writer.write( expression ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Please use the following expression instead:" ); + writer.write( NEWLINE ); + writer.write( altExpression ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + + writeParameter( currentParameter, writer ); + writer.write( "in mojo:" ); + writeMojoBinding( binding, writer ); + writer.write( "While building project:" ); + writeProjectCoordinate( project, writer ); + + addTips( CoreErrorTips.getBannedParameterExpressionTips( currentParameter, binding, project ), writer ); + + registerBuildError( err, writer.toString() ); + } + + public void reportReflectionErrorWhileEvaluatingMojoParameter( Parameter currentParameter, + MojoBinding binding, + MavenProject project, + String expression, + Exception cause ) + { + StringWriter writer = new StringWriter(); + + writer.write( NEWLINE ); + writer.write( "The following mojo-parameter expression could not be resolved, due to an erroroneous or empty reference in the object graph:" ); + writer.write( NEWLINE ); + writer.write( expression ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + + writeParameter( currentParameter, writer ); + writer.write( "in mojo:" ); + writeMojoBinding( binding, writer ); + writer.write( "While building project:" ); + writeProjectCoordinate( project, writer ); + + addTips( CoreErrorTips.getReflectionErrorInParameterExpressionTips( expression, currentParameter, binding, project ), writer ); + + registerBuildError( cause, writer.toString(), cause.getCause() ); + } + + public void reportMissingRequiredMojoParameter( MojoBinding binding, + MavenProject project, + List invalidParameters, + PluginParameterException err ) + { + StringWriter writer = new StringWriter(); + + writer.write( NEWLINE ); + writer.write( "One or more required mojo parameters have not been configured." ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + + writer.write( "Mojo:" ); + writeMojoBinding( binding, writer ); + writer.write( "While building project:" ); + writeProjectCoordinate( project, writer ); + + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Missing parameters include:" ); + for ( Iterator it = invalidParameters.iterator(); it.hasNext(); ) + { + Parameter parameter = (Parameter) it.next(); + writer.write( NEWLINE ); + writer.write( parameter.getName() ); + + if ( parameter.getAlias() != null ) + { + writer.write( " (aliased as: " ); + writer.write( parameter.getAlias() ); + } + } + + addTips( CoreErrorTips.getMissingRequiredParameterTips( invalidParameters, binding, project ), writer ); + + registerBuildError( err, writer.toString() ); + } + + public void reportErrorApplyingMojoConfiguration( MojoBinding binding, + MavenProject project, + PlexusConfiguration config, + PluginConfigurationException cause ) + { + StringWriter writer = new StringWriter(); + + writer.write( NEWLINE ); + writer.write( "Maven encountered an error while configuring one of the mojos for your build." ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + + writer.write( "Mojo:" ); + writeMojoBinding( binding, writer ); + writer.write( "While building project:" ); + writeProjectCoordinate( project, writer ); + + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Here is the configuration it attempted to apply to the mojo:" ); + writeConfiguration( config, writer, 0 ); + + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Error message:" ); + writer.write( cause.getMessage() ); + + addTips( CoreErrorTips.getMojoConfigurationErrorTips( binding, project, config, cause ), writer ); + + registerBuildError( cause, writer.toString(), cause.getCause() ); + } + + public void reportProjectDependenciesNotFound( MavenProject project, + String scope, + ArtifactNotFoundException cause ) + { + reportTransitiveResolutionError( project, scope, cause ); + } + + public void reportProjectDependenciesUnresolvable( MavenProject project, + String scope, + ArtifactResolutionException cause ) + { + reportTransitiveResolutionError( project, scope, cause ); + } + + public void reportProjectDependencyArtifactNotFound( MavenProject project, + Artifact artifact, + ArtifactNotFoundException cause ) + { + reportArtifactError( project, artifact, cause ); + } + + public void reportProjectDependencyArtifactUnresolvable( MavenProject project, + Artifact artifact, + ArtifactResolutionException cause ) + { + reportArtifactError( project, artifact, cause ); + } + + private void reportTransitiveResolutionError( MavenProject project, + String scope, + AbstractArtifactResolutionException cause ) + { + StringWriter writer = new StringWriter(); + + writer.write( NEWLINE ); + writer.write( "Transitive dependency resolution for scope: " ); + writer.write( scope ); + writer.write( "has failed for your project." ); + + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Error message: " ); + writer.write( cause.getMessage() ); + writer.write( NEWLINE ); + writer.write( "Root error message: " ); + writer.write( getRootCause( cause ).getMessage() ); + + writeProjectCoordinate( project, writer ); + addTips( CoreErrorTips.getDependencyArtifactResolutionTips( project, scope, cause ), + writer ); + + registerBuildError( cause, writer.toString(), cause.getCause() ); + } + + private void reportArtifactError( MavenProject project, + Artifact depArtifact, + AbstractArtifactResolutionException cause ) + { + StringWriter writer = new StringWriter(); + + writer.write( NEWLINE ); + writer.write( "Maven could not resolve one of your project dependencies from the repository:" ); + + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Group-Id: " ); + writer.write( depArtifact.getGroupId() ); + writer.write( NEWLINE ); + writer.write( "Artifact-Id: " ); + writer.write( depArtifact.getArtifactId() ); + writer.write( NEWLINE ); + writer.write( "Version: " ); + writer.write( depArtifact.getVersion() ); + writer.write( NEWLINE ); + writer.write( "Type: " ); + writer.write( depArtifact.getType() ); + writer.write( NEWLINE ); + writer.write( "Scope: " ); + writer.write( depArtifact.getScope() ); + + if ( depArtifact.getClassifier() != null ) + { + writer.write( NEWLINE ); + writer.write( "Classifier: " ); + writer.write( depArtifact.getClassifier() ); + } + + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Error message: " ); + writer.write( cause.getMessage() ); + writer.write( NEWLINE ); + writer.write( "Root error message: " ); + writer.write( getRootCause( cause ).getMessage() ); + + writeProjectCoordinate( project, writer ); + addTips( CoreErrorTips.getDependencyArtifactResolutionTips( project, depArtifact, cause ), + writer ); + + registerBuildError( cause, writer.toString(), cause.getCause() ); + } + + public void reportErrorLoadingPlugin( MojoBinding binding, + MavenProject project, + PluginLoaderException cause ) + { + StringWriter writer = new StringWriter(); + + writer.write( NEWLINE ); + writer.write( "Maven encountered an error while loading a plugin for use in your build." ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + + writer.write( "Plugin:" ); + writePluginInformation( binding, writer ); + writer.write( "While building project:" ); + writeProjectCoordinate( project, writer ); + + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Error message:" ); + writer.write( cause.getMessage() ); + writer.write( NEWLINE ); + writer.write( "Root error message:" ); + writer.write( getRootCause( cause ).getMessage() ); + + addTips( CoreErrorTips.getErrorLoadingPluginTips( binding, project, cause ), writer ); + + registerBuildError( cause, writer.toString(), cause.getCause() ); + } + + public void reportErrorFormulatingBuildPlan( List tasks, + MavenProject configuringProject, + String targetDescription, + LifecycleException cause ) + { + StringWriter writer = new StringWriter(); + + writer.write( NEWLINE ); + writer.write( "Maven cannot calculate your build plan, given the following information:" ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + + writer.write( "Tasks:" ); + for ( Iterator it = tasks.iterator(); it.hasNext(); ) + { + String task = (String) it.next(); + writer.write( NEWLINE ); + writer.write( "- " ); + writer.write( task ); + } + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Current project:" ); + writeProjectCoordinate( configuringProject, writer ); + + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Build execution sub-segment:" ); + writer.write( targetDescription ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Error message: " ); + writer.write( cause.getMessage() ); + writer.write( NEWLINE ); + writer.write( "Root error message: " ); + writer.write( getRootCause( cause ).getMessage() ); + + addTips( CoreErrorTips.getBuildPlanningErrorTips( tasks, configuringProject, cause ), writer ); + + registerBuildError( cause, writer.toString(), cause.getCause() ); + } + + private void writeParameter( Parameter currentParameter, + StringWriter writer ) + { + writer.write( NEWLINE ); + writer.write( "Uneditable parameter:" ); + writer.write( NEWLINE ); + writer.write( "Name: " ); + writer.write( currentParameter.getName() ); + writer.write( NEWLINE ); + writer.write( "Alias: " ); + writer.write( currentParameter.getAlias() ); + writer.write( NEWLINE ); + } + + private void writeProjectCoordinate( MavenProject project, + StringWriter writer ) + { + writer.write( NEWLINE ); + if ( project == null ) + { + writer.write( "No project is in use." ); + } + else + { + writer.write( "Group-Id: " ); + writer.write( project.getGroupId() ); + writer.write( NEWLINE ); + writer.write( "Artifact-Id: " ); + writer.write( project.getArtifactId() ); + writer.write( NEWLINE ); + writer.write( "Version: " ); + writer.write( project.getVersion() ); + writer.write( NEWLINE ); + writer.write( "From file: " ); + writer.write( String.valueOf( project.getFile() ) ); + } + writer.write( NEWLINE ); + } + + private void writeProjectCoordinate( Model model, + File pomFile, + StringWriter writer ) + { + writer.write( NEWLINE ); + writer.write( "Group-Id: " ); + writer.write( model.getGroupId() ); + writer.write( NEWLINE ); + writer.write( "Artifact-Id: " ); + writer.write( model.getArtifactId() ); + writer.write( NEWLINE ); + writer.write( "Version: " ); + writer.write( model.getVersion() ); + writer.write( NEWLINE ); + writer.write( "From file: " ); + writer.write( String.valueOf( pomFile ) ); + writer.write( NEWLINE ); + } + + private void writePluginInformation( MojoBinding binding, + StringWriter writer ) + { + writer.write( NEWLINE ); + writer.write( "Group-Id: " ); + writer.write( binding.getGroupId() ); + writer.write( NEWLINE ); + writer.write( "Artifact-Id: " ); + writer.write( binding.getArtifactId() ); + writer.write( NEWLINE ); + writer.write( "Version: " ); + writer.write( binding.getVersion() ); + writer.write( NEWLINE ); + writer.write( "Referenced mojo: " ); + writer.write( binding.getGoal() ); + writer.write( NEWLINE ); + writer.write( "brought in via: " ); + writer.write( binding.getOrigin() ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + } + + private void writeMojoBinding( MojoBinding binding, StringWriter writer ) + { + writer.write( NEWLINE ); + writer.write( "Group-Id: " ); + writer.write( binding.getGroupId() ); + writer.write( NEWLINE ); + writer.write( "Artifact-Id: " ); + writer.write( binding.getArtifactId() ); + writer.write( NEWLINE ); + writer.write( "Version: " ); + writer.write( binding.getVersion() ); + writer.write( NEWLINE ); + writer.write( "Mojo: " ); + writer.write( binding.getGoal() ); + writer.write( NEWLINE ); + writer.write( "brought in via: " ); + writer.write( binding.getOrigin() ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + } + + private void writeConfiguration( PlexusConfiguration config, + StringWriter writer, int indent ) + { + indent( writer, indent ); + + writer.write( "<" ); + writer.write( config.getName() ); + writer.write( ">" ); + + try + { + if ( config.getValue() != null ) + { + writer.write( config.getValue() ); + } + } + catch ( PlexusConfigurationException e ) + { + // skip it. + } + + PlexusConfiguration[] children = config.getChildren(); + if ( ( children != null ) && ( children.length > 0 ) ) + { + for ( int i = 0; i < children.length; i++ ) + { + writer.write( NEWLINE ); + writeConfiguration( children[i], writer, indent + 1 ); + } + + indent( writer, indent ); + } + + writer.write( "" ); + writer.write( NEWLINE ); + } + + private void indent( StringWriter writer, + int indent ) + { + for ( int i = 0; i < indent; i++ ) + { + writer.write( " " ); + } + } + + public void handleProjectBuildingError( MavenExecutionRequest request, + File pomFile, + ProjectBuildingException exception ) + { + // TODO Auto-generated method stub + + } + + public void reportInvalidMavenVersion( MavenProject project, + ArtifactVersion mavenVersion, + MavenExecutionException err ) + { + // TODO Auto-generated method stub + + } + + public void reportPomFileScanningError( File basedir, + String includes, + String excludes, + IOException cause ) + { + // TODO Auto-generated method stub + + } + + public void reportPomFileCanonicalizationError( File pomFile, + IOException cause ) + { + // TODO Auto-generated method stub + + } + + public void handleSuperPomBuildingError( MavenExecutionRequest request, + ArtifactRepository localRepository, + ProfileManager globalProfileManager, + ProjectBuildingException exception ) + { + // TODO Auto-generated method stub + + } + + public void handleSuperPomBuildingError( ProfileManager globalProfileManager, + ProjectBuildingException exception ) + { + // TODO Auto-generated method stub + + } + + public void handleSuperPomBuildingError( ProjectBuildingException exception ) + { + // TODO Auto-generated method stub + + } + + public void reportErrorInterpolatingModel( Model model, + Map inheritedValues, + File pomFile, + MavenExecutionRequest request, + ModelInterpolationException cause ) + { + StringWriter writer = new StringWriter(); + + writer.write( NEWLINE ); + writer.write( "You have an invalid expression in your POM (interpolation failed):" ); + writer.write( NEWLINE ); + writer.write( cause.getMessage() ); + + writeProjectCoordinate( model, pomFile, writer ); + addTips( CoreErrorTips.getTipsForModelInterpolationError( model, pomFile, cause ), + writer ); + + registerBuildError( cause, writer.toString(), cause.getCause() ); + } + + } diff --git a/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java b/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java index 99742a16c7..81a96f6783 100644 --- a/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java +++ b/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java @@ -68,6 +68,9 @@ public class DefaultBuildExtensionScanner private ModelInterpolator modelInterpolator; + // cached. + private MavenProject basicSuperProject; + public DefaultBuildExtensionScanner() { } @@ -418,20 +421,21 @@ private ModelLineage buildModelLineage( File pom, MavenExecutionRequest request, private List getInitialRemoteRepositories() throws ExtensionScanningException { - MavenProject superProject; - - try + if ( basicSuperProject == null ) { - superProject = projectBuilder.buildStandaloneSuperProject(); - } - catch ( ProjectBuildingException e ) - { - throw new ExtensionScanningException( - "Error building super-POM for retrieving the default remote repository list: " - + e.getMessage(), e ); + try + { + basicSuperProject = projectBuilder.buildStandaloneSuperProject(); + } + catch ( ProjectBuildingException e ) + { + throw new ExtensionScanningException( + "Error building super-POM for retrieving the default remote repository list: " + + e.getMessage(), e ); + } } - return superProject.getRemoteArtifactRepositories(); + return basicSuperProject.getRemoteArtifactRepositories(); } protected Logger getLogger() diff --git a/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java b/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java index 828ea0c281..e59dd2b1b0 100644 --- a/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java +++ b/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java @@ -366,12 +366,6 @@ private void addExtension( Artifact extensionArtifact, resultArtifacts.add( a ); } - // TODO: This shouldn't be required, now that we're checking the core filter before getting here. - if ( !extensionArtifact.isResolved() || ( extensionArtifact.getFile() == null ) ) - { - throw new ExtensionManagerException( "Extension artifact was not resolved, or has no file associated with it.", extensionArtifact, projectGroupId, projectArtifactId, projectVersion ); - } - if ( !realmManager.hasExtensionRealm( extensionArtifact ) ) { try diff --git a/maven-core/src/main/java/org/apache/maven/extension/ExtensionManagerException.java b/maven-core/src/main/java/org/apache/maven/extension/ExtensionManagerException.java index 00f0189b8a..c0c96031c0 100644 --- a/maven-core/src/main/java/org/apache/maven/extension/ExtensionManagerException.java +++ b/maven-core/src/main/java/org/apache/maven/extension/ExtensionManagerException.java @@ -127,19 +127,6 @@ public ExtensionManagerException( String message, this.projectVersion = projectVersion; } - public ExtensionManagerException( String message, - Artifact extensionArtifact, - String projectGroupId, - String projectArtifactId, - String projectVersion ) - { - super( message ); - this.extensionArtifact = extensionArtifact; - this.projectGroupId = projectGroupId; - this.projectArtifactId = projectArtifactId; - this.projectVersion = projectVersion; - } - public ExtensionManagerException( String message, Artifact extensionArtifact, String projectGroupId, diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java index 1f7cc2d9ca..bfde244020 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java @@ -2,14 +2,9 @@ import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; -import org.apache.maven.plugin.InvalidPluginException; import org.apache.maven.plugin.PluginConfigurationException; import org.apache.maven.plugin.PluginManagerException; -import org.apache.maven.plugin.PluginNotFoundException; import org.apache.maven.plugin.loader.PluginLoaderException; -import org.apache.maven.plugin.version.PluginVersionNotFoundException; -import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.artifact.InvalidDependencyVersionException; @@ -54,34 +49,6 @@ public LifecycleExecutionException( String message, MavenProject project, this.project = project; } - public LifecycleExecutionException( String message, MavenProject project, - PluginNotFoundException cause ) - { - super( message, cause ); - this.project = project; - } - - public LifecycleExecutionException( String message, MavenProject project, - PluginVersionResolutionException cause ) - { - super( message, cause ); - this.project = project; - } - - public LifecycleExecutionException( String message, MavenProject project, - InvalidVersionSpecificationException cause ) - { - super( message, cause ); - this.project = project; - } - - public LifecycleExecutionException( String message, MavenProject project, - InvalidPluginException cause ) - { - super( message, cause ); - this.project = project; - } - public LifecycleExecutionException( String message, MavenProject project, ArtifactNotFoundException cause ) { @@ -124,13 +91,6 @@ public LifecycleExecutionException( String message, MavenProject project, this.project = project; } - public LifecycleExecutionException( String message, MavenProject project, - PluginVersionNotFoundException cause ) - { - super( message, cause ); - this.project = project; - } - public MavenProject getProject() { return project; diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index a79f620bc3..8966a420fa 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -1298,6 +1298,7 @@ private void resolveTransitiveDependencies( MavenSession context, // Don't recreate if already created - for effeciency, and because clover plugin adds to it if ( project.getDependencyArtifacts() == null ) { + // NOTE: Don't worry about covering this case with the error-reporter bindings...it's already handled by the project error reporter. project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) ); } ArtifactResolutionResult result = artifactResolver.resolveTransitively( diff --git a/maven-core/src/main/java/org/apache/maven/reactor/MavenExecutionException.java b/maven-core/src/main/java/org/apache/maven/reactor/MavenExecutionException.java index 2421df8ca3..72b28ffa12 100644 --- a/maven-core/src/main/java/org/apache/maven/reactor/MavenExecutionException.java +++ b/maven-core/src/main/java/org/apache/maven/reactor/MavenExecutionException.java @@ -1,6 +1,5 @@ package org.apache.maven.reactor; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.extension.ExtensionScanningException; import org.apache.maven.project.ProjectBuildingException; @@ -71,11 +70,6 @@ public MavenExecutionException( String message, IOException cause ) super( message, cause ); } - public MavenExecutionException( String message, ArtifactResolutionException cause ) - { - super( message, cause ); - } - public MavenExecutionException( String message, ExtensionScanningException cause ) { super( message, cause ); diff --git a/maven-embedder/src/main/aspect/org/apache/maven/embedder/cache/ErrorReportingAspect.aj b/maven-embedder/src/main/aspect/org/apache/maven/embedder/cache/ErrorReportingAspect.aj index 4af6ec81fa..a1bbb4cd62 100644 --- a/maven-embedder/src/main/aspect/org/apache/maven/embedder/cache/ErrorReportingAspect.aj +++ b/maven-embedder/src/main/aspect/org/apache/maven/embedder/cache/ErrorReportingAspect.aj @@ -1,7 +1,5 @@ package org.apache.maven.embedder.cache; -import org.aspectj.lang.Aspects; - import java.io.StringWriter; import java.io.PrintWriter; @@ -10,7 +8,7 @@ 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.errors.DefaultCoreErrorReporter; +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.ProjectBuildingException; @@ -93,8 +91,51 @@ public privileged aspect ErrorReportingAspect } else { - System.out.println( "Checking core error reporter for help." ); + 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; diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java index 7c9da4067d..7ffc6bb20d 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java @@ -1,7 +1,6 @@ package org.apache.maven.cli; import org.apache.maven.BuildFailureException; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.embedder.MavenEmbedderConsoleLogger; import org.apache.maven.embedder.MavenEmbedderLogger; @@ -11,10 +10,6 @@ import org.apache.maven.execution.ReactorManager; import org.apache.maven.extension.ExtensionScanningException; import org.apache.maven.lifecycle.LifecycleExecutionException; -import org.apache.maven.model.Plugin; -import org.apache.maven.plugin.PluginNotFoundException; -import org.apache.maven.plugin.version.PluginVersionNotFoundException; -import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.project.DuplicateProjectException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingException; @@ -401,145 +396,7 @@ private static boolean handleLifecycleExecutionException( LifecycleExecutionExce boolean showStackTraces, StringWriter writer ) { - - // ===================================================================== - // Cases covered: - // ===================================================================== - // - // LifecycleExecutionException(String, MavenProject, PluginNotFoundException) - // LifecycleExecutionException(String, MavenProject, InvalidDependencyVersionException) - // LifecycleExecutionException(String, MavenProject, InvalidVersionSpecificationException) - // LifecycleExecutionException(String, MavenProject, ArtifactNotFoundException) - // LifecycleExecutionException(String, MavenProject, ArtifactResolutionException) - // LifecycleExecutionException(String, MavenProject, PluginVersionNotFoundException) - // LifecycleExecutionException(String, MavenProject, PluginVersionResolutionException) - // - // ===================================================================== - // Cases left to cover: - // ===================================================================== - // - // LifecycleExecutionException(String, MavenProject, InvalidPluginException) - // LifecycleExecutionException(String, MavenProject, LifecycleException) - // LifecycleExecutionException(String, MavenProject, PluginConfigurationException) - // LifecycleExecutionException(String, MavenProject, PluginLoaderException) - // LifecycleExecutionException(String, MavenProject, PluginManagerException) - // ...this includes PluginExecutionException, which wraps MojoExecutionException - // with MojoExecution and MavenProject context info. - - boolean result = false; - - 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( "Maven cannot find a plugin required by your build:" ); - writer.write( NEWLINE ); - writer.write( "Group-Id: " ); - writer.write( plugin.getGroupId() ); - writer.write( NEWLINE ); - writer.write( "Artifact-Id: " ); - writer.write( plugin.getArtifactId() ); - writer.write( NEWLINE ); - writer.write( "Version: " ); - writer.write( plugin.getVersion() ); - writer.write( NEWLINE ); - writer.write( NEWLINE ); - - handleGenericException( artifactException, showStackTraces, writer ); - - writer.write( NEWLINE ); - writer.write( NEWLINE ); - writer.write( "NOTE: If the above Group-Id or Artifact-Id are incorrect," ); - writer.write( NEWLINE ); - writer.write( "check that the corresponding section in your POM is correct." ); - writer.write( NEWLINE ); - writer.write( "If you specified this plugin directly using something like 'javadoc:javadoc'," ); - writer.write( NEWLINE ); - writer.write( "check that the section in your $HOME/.m2/settings.xml contains the" ); - writer.write( NEWLINE ); - writer.write( "proper groupId for the plugin you are trying to use (each groupId goes in a separate" ); - writer.write( NEWLINE ); - writer.write( " element within the section." ); - writer.write( NEWLINE ); - - result = true; - } - else if ( cause instanceof ProjectBuildingException ) - { - result = handleProjectBuildingException( (ProjectBuildingException) cause, showStackTraces, writer ); - } - else if ( cause instanceof ArtifactNotFoundException ) - { - writer.write( NEWLINE ); - writer.write( "One or more project dependency artifacts are missing." ); - writer.write( NEWLINE ); - writer.write( NEWLINE ); - writer.write( "Reason: " ); - writer.write( cause.getMessage() ); - writer.write( NEWLINE ); - - result = true; - } - else if ( cause instanceof ArtifactNotFoundException ) - { - writer.write( NEWLINE ); - writer.write( "Maven encountered an error while resolving one or more project dependency artifacts." ); - writer.write( NEWLINE ); - writer.write( NEWLINE ); - writer.write( "Reason: " ); - writer.write( cause.getMessage() ); - writer.write( NEWLINE ); - - result = true; - } - else if ( cause instanceof PluginVersionNotFoundException ) - { - writer.write( NEWLINE ); - writer.write( "Cannot find a valid version for plugin: " ); - writer.write( NEWLINE ); - writer.write( "Group-Id: " ); - writer.write( ((PluginVersionNotFoundException)cause).getGroupId() ); - writer.write( NEWLINE ); - writer.write( "Artifact-Id: " ); - writer.write( ((PluginVersionNotFoundException)cause).getArtifactId() ); - writer.write( NEWLINE ); - writer.write( NEWLINE ); - writer.write( "Reason: " ); - writer.write( cause.getMessage() ); - writer.write( NEWLINE ); - writer.write( NEWLINE ); - writer.write( "Please ensure that your proxy information is specified correctly in $HOME/.m2/settings.xml." ); - writer.write( NEWLINE ); - - result = true; - } - else if ( cause instanceof PluginVersionResolutionException ) - { - writer.write( NEWLINE ); - writer.write( "Maven encountered an error while trying to resolve a valid version for plugin: " ); - writer.write( NEWLINE ); - writer.write( "Group-Id: " ); - writer.write( ((PluginVersionNotFoundException)cause).getGroupId() ); - writer.write( NEWLINE ); - writer.write( "Artifact-Id: " ); - writer.write( ((PluginVersionNotFoundException)cause).getArtifactId() ); - writer.write( NEWLINE ); - writer.write( NEWLINE ); - writer.write( "Reason: " ); - writer.write( cause.getMessage() ); - writer.write( NEWLINE ); - writer.write( NEWLINE ); - writer.write( "Please ensure that your proxy information is specified correctly in $HOME/.m2/settings.xml." ); - writer.write( NEWLINE ); - - result = true; - } - } + handleGenericException( e, showStackTraces, writer ); MavenProject project = e.getProject(); @@ -554,7 +411,7 @@ else if ( cause instanceof PluginVersionResolutionException ) } writer.write( NEWLINE ); - return result; + return true; } // NOTE: This method is an aspect target.