From 89f482ac378c716eada8182375c4dbac2fcbc09e Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Fri, 18 Jan 2008 01:27:23 +0000 Subject: [PATCH] last of the error-reporting unit tests, and an additional error type to handle modules that are referenced but don't exist, which should stop the build. All tests pass. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@613032 13f79535-47bb-0310-9956-ffa450edef68 --- .../errors/BuildFailureReporterAspect.aj | 26 ---- .../errors/LifecycleErrorReporterAspect.aj | 20 +-- .../errors/MavenExecErrorReporterAspect.aj | 8 ++ .../java/org/apache/maven/DefaultMaven.java | 10 +- .../maven/errors/CoreErrorReporter.java | 6 +- .../apache/maven/errors/CoreErrorTips.java | 8 ++ .../errors/DefaultCoreErrorReporter.java | 57 ++++---- .../extension/BuildExtensionScanner.java | 5 +- .../DefaultBuildExtensionScanner.java | 15 +- .../lifecycle/DefaultLifecycleExecutor.java | 97 ++++++------- .../maven/plugin/DefaultPluginManager.java | 9 +- .../maven/plugin/PluginManagerException.java | 12 ++ .../maven/reactor/MissingModuleException.java | 30 ++++ .../plugin/pom.xml | 49 +++++++ .../src/main/java/org/plugin/TestPlugin.java | 33 +++++ .../main/resources/META-INF/maven/plugin.xml | 38 ++++++ .../project/pom.xml | 45 ++++++ .../testReportMissingModulePom/child1/pom.xml | 19 +++ .../child1/src/main/java/org/test/App.java | 13 ++ .../src/test/java/org/test/AppTest.java | 38 ++++++ .../testReportMissingModulePom/pom.xml | 13 ++ .../testReportMojoLookupError/plugin/pom.xml | 54 ++++++++ .../src/main/java/org/plugin/TestPlugin.java | 42 ++++++ .../testReportMojoLookupError/project/pom.xml | 25 ++++ .../error/ErrorReporterPointcutTest.java | 129 +++++++++++++++--- .../maven/realm/DefaultMavenRealmManager.java | 19 +++ .../apache/maven/realm/MavenRealmManager.java | 2 + 27 files changed, 662 insertions(+), 160 deletions(-) create mode 100644 maven-core/src/main/java/org/apache/maven/reactor/MissingModuleException.java create mode 100644 maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/plugin/pom.xml create mode 100644 maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/plugin/src/main/java/org/plugin/TestPlugin.java create mode 100644 maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/plugin/src/main/resources/META-INF/maven/plugin.xml create mode 100644 maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/project/pom.xml create mode 100644 maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/child1/pom.xml create mode 100644 maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/child1/src/main/java/org/test/App.java create mode 100644 maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/child1/src/test/java/org/test/AppTest.java create mode 100644 maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/pom.xml create mode 100644 maven-embedder/src/test/error-reporting-projects/testReportMojoLookupError/plugin/pom.xml create mode 100644 maven-embedder/src/test/error-reporting-projects/testReportMojoLookupError/plugin/src/main/java/org/plugin/TestPlugin.java create mode 100644 maven-embedder/src/test/error-reporting-projects/testReportMojoLookupError/project/pom.xml 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 7bfe43cd30..947f08bb7f 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 @@ -125,32 +125,6 @@ public privileged aspect BuildFailureReporterAspect private pointcut within_le_getMojoDescriptorForDirectInvocation(): withincode( * DefaultLifecycleExecutor.getMojoDescriptorForDirectInvocation( String, MavenSession, MavenProject ) ); - /** - * Call stack is: - *
- *
-     * 
-     * DefaultMaven.execute(MavenExecutionRequest)
-     * --> DefaultLifecycleExecutor.isTaskValid(String, MavenSession, MavenProject)
-     *        --> catch( PluginLoaderException )
-     * <-- TaskValidationResult
-     * 
-     * 
- */ - after( MojoBinding binding, MavenSession session, MavenProject rootProject ) throwing ( PluginLoaderException cause ): - within_le_getMojoDescriptorForDirectInvocation() - && call( * PluginLoader+.loadPlugin( MojoBinding, MavenProject, MavenSession ) ) - && args( binding, rootProject, session ) - { - getReporter().reportPluginErrorWhileValidatingTask( binding.getGoal(), session, rootProject, cause ); - } - -// before(): -// call( * MojoBindingFactory+.parseMojoBinding( String, MavenProject, MavenSession, boolean ) ) -// { -// System.out.println( "Boo" ); -// } - /** * Call stack is: *
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 index 9c2a1839b2..6119a7c021 100644 --- a/maven-core/src/main/aspect/org/apache/maven/errors/LifecycleErrorReporterAspect.aj +++ b/maven-core/src/main/aspect/org/apache/maven/errors/LifecycleErrorReporterAspect.aj @@ -25,10 +25,10 @@ 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.apache.maven.lifecycle.statemgmt.ResolveLateBoundPluginMojo; 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.PlexusContainer; import java.util.List; @@ -40,6 +40,10 @@ public privileged aspect LifecycleErrorReporterAspect execution( void DefaultLifecycleExecutor.executeGoalAndHandleFailures( MojoBinding, .. ) ) && args( binding, .. ); + private pointcut le_executeGoalAndHandleFailures_withSession( MojoBinding binding, MavenSession session ): + execution( void DefaultLifecycleExecutor.executeGoalAndHandleFailures( MojoBinding, MavenSession, .. ) ) + && args( binding, session, .. ); + private pointcut pm_executeMojo( MavenProject project ): execution( void PluginManager+.executeMojo( MavenProject, .. ) ) && args( project, .. ); @@ -48,15 +52,6 @@ public privileged aspect LifecycleErrorReporterAspect withincode( 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 ); - } - after( MojoBinding binding, MavenProject project ) throwing ( PluginLoaderException cause ): cflow( le_executeGoalAndHandleFailures( MojoBinding ) ) && call( * PluginLoader+.loadPlugin( MojoBinding, MavenProject, .. ) ) @@ -89,12 +84,11 @@ public privileged aspect LifecycleErrorReporterAspect return cause; } - before( MojoBinding binding, MavenProject project, ComponentLookupException cause ): + after( MojoBinding binding, MavenProject project ) throwing ( ComponentLookupException cause ): cflow( le_executeGoalAndHandleFailures( binding ) ) && cflow( pm_executeMojo( project ) ) && withincode( Mojo DefaultPluginManager.getConfiguredMojo( .. ) ) - && handler( ComponentLookupException ) - && args( cause ) + && call( Object PlexusContainer+.lookup( .. ) ) { getReporter().reportMojoLookupError( binding, project, 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 index 6b115a9c16..dc3b084bb5 100644 --- a/maven-core/src/main/aspect/org/apache/maven/errors/MavenExecErrorReporterAspect.aj +++ b/maven-core/src/main/aspect/org/apache/maven/errors/MavenExecErrorReporterAspect.aj @@ -1,6 +1,7 @@ package org.apache.maven.errors; import org.apache.maven.reactor.MavenExecutionException; +import org.apache.maven.reactor.MissingModuleException; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.execution.MavenExecutionRequest; @@ -59,6 +60,13 @@ public aspect MavenExecErrorReporterAspect return err; } + after( MissingModuleException err ): + execution( MissingModuleException.new( String, File, File ) ) + && this( err ) + { + getReporter().reportMissingModulePom( err ); + } + after(): dm_collectProjects( ArtifactRepository, ProfileManager ) { currentProject = null; 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 6b617c08c8..4721563ff5 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -42,6 +42,7 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.reactor.MavenExecutionException; +import org.apache.maven.reactor.MissingModuleException; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.context.Context; @@ -369,7 +370,14 @@ public class DefaultMaven } } - moduleFiles.add( moduleFile ); + if ( !moduleFile.exists() ) + { + throw new MissingModuleException( name, moduleFile, file ); + } + else + { + moduleFiles.add( moduleFile ); + } } List collectedProjects = collectProjects( moduleFiles, localRepository, recursive, 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 478da68ee5..4914a4dbff 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 @@ -15,7 +15,6 @@ import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; import org.apache.maven.extension.ExtensionManagerException; 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.model.MojoBinding; @@ -39,6 +38,7 @@ 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; +import org.apache.maven.reactor.MissingModuleException; import org.apache.maven.realm.RealmManagementException; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; @@ -97,8 +97,6 @@ public interface CoreErrorReporter void reportLifecycleSpecErrorWhileValidatingTask( String task, MavenSession session, MavenProject rootProject, LifecycleSpecificationException cause ); - void reportMissingPluginDescriptor( MojoBinding binding, MavenProject project, LifecycleExecutionException err ); - void reportMissingRequiredMojoParameter( MojoBinding binding, MavenProject project, List invalidParameters, PluginParameterException err ); void reportMojoExecutionException( MojoBinding binding, MavenProject project, MojoExecutionException cause ); @@ -125,4 +123,6 @@ public interface CoreErrorReporter void reportUseOfBannedMojoParameter( Parameter currentParameter, MojoBinding binding, MavenProject project, String expression, String altExpression, ExpressionEvaluationException err ); + void reportMissingModulePom( MissingModuleException err ); + } 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 e710a7df10..570a3dea86 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 @@ -299,4 +299,12 @@ public final class CoreErrorTips return null; } + public static List getMissingModuleTips( File pomFile, + File moduleFile, + String moduleName ) + { + // 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 335dcc2fb5..635868d098 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 @@ -17,7 +17,6 @@ import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; import org.apache.maven.extension.ExtensionManagerException; 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; @@ -46,6 +45,7 @@ import org.apache.maven.project.error.ProjectReporterManager; import org.apache.maven.project.interpolation.ModelInterpolationException; import org.apache.maven.project.path.PathTranslator; import org.apache.maven.reactor.MavenExecutionException; +import org.apache.maven.reactor.MissingModuleException; import org.apache.maven.realm.RealmManagementException; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; @@ -291,34 +291,6 @@ public class DefaultCoreErrorReporter 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 ) @@ -1667,4 +1639,31 @@ public class DefaultCoreErrorReporter } } + public void reportMissingModulePom( MissingModuleException err ) + { + StringWriter writer = new StringWriter(); + + writer.write( NEWLINE ); + writer.write( "The module: " ); + writer.write( err.getModuleName() ); + writer.write( " cannot be found." ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Module's expected path: " ); + writer.write( NEWLINE ); + writer.write( err.getModuleFile().getAbsolutePath() ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( "Referenced by POM: " ); + writer.write( NEWLINE ); + writer.write( err.getPomFile().getAbsolutePath() ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + writer.write( NEWLINE ); + + addTips( CoreErrorTips.getMissingModuleTips( err.getPomFile(), err.getModuleFile(), err.getModuleName() ), writer ); + + registerBuildError( err, writer.toString() ); + } + } diff --git a/maven-core/src/main/java/org/apache/maven/extension/BuildExtensionScanner.java b/maven-core/src/main/java/org/apache/maven/extension/BuildExtensionScanner.java index 94a1137395..070a08b1ff 100644 --- a/maven-core/src/main/java/org/apache/maven/extension/BuildExtensionScanner.java +++ b/maven-core/src/main/java/org/apache/maven/extension/BuildExtensionScanner.java @@ -20,6 +20,7 @@ package org.apache.maven.extension; */ import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.reactor.MissingModuleException; import java.io.File; import java.util.List; @@ -31,10 +32,10 @@ public interface BuildExtensionScanner void scanForBuildExtensions( List files, MavenExecutionRequest request ) - throws ExtensionScanningException; + throws ExtensionScanningException, MissingModuleException; void scanForBuildExtensions( File pom, MavenExecutionRequest request ) - throws ExtensionScanningException; + throws ExtensionScanningException, MissingModuleException; } 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 81a96f6783..cc6f4b7896 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 @@ -38,6 +38,7 @@ import org.apache.maven.project.build.model.ModelLineageBuilder; import org.apache.maven.project.build.model.ModelLineageIterator; import org.apache.maven.project.interpolation.ModelInterpolationException; import org.apache.maven.project.interpolation.ModelInterpolator; +import org.apache.maven.reactor.MissingModuleException; import org.codehaus.plexus.logging.LogEnabled; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.console.ConsoleLogger; @@ -90,7 +91,7 @@ public class DefaultBuildExtensionScanner public void scanForBuildExtensions( List files, MavenExecutionRequest request ) - throws ExtensionScanningException + throws ExtensionScanningException, MissingModuleException { List visited = new ArrayList(); @@ -104,7 +105,7 @@ public class DefaultBuildExtensionScanner public void scanForBuildExtensions( File pom, MavenExecutionRequest request ) - throws ExtensionScanningException + throws ExtensionScanningException, MissingModuleException { scanInternal( pom, request, new ArrayList(), Collections.singletonList( pom ) ); } @@ -113,7 +114,7 @@ public class DefaultBuildExtensionScanner MavenExecutionRequest request, List visitedModelIds, List reactorFiles ) - throws ExtensionScanningException + throws ExtensionScanningException, MissingModuleException { try @@ -244,7 +245,7 @@ public class DefaultBuildExtensionScanner List originalRemoteRepositories, List visitedModelIds, List reactorFiles ) - throws ExtensionScanningException + throws ExtensionScanningException, MissingModuleException { // FIXME: This gets a little sticky, because modules can be added by profiles that require // an extension in place before they can be activated. @@ -302,11 +303,7 @@ public class DefaultBuildExtensionScanner if ( !modulePomDirectory.exists() ) { - getLogger().debug( - "Cannot find POM for module: " + moduleSubpath - + "; continuing scan with next module. (Full path was: " - + modulePomDirectory + ")" ); - continue; + throw new MissingModuleException( moduleSubpath, modulePomDirectory, containingPom ); } scanInternal( modulePomDirectory, request, visitedModelIds, reactorFiles ); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index 91de544c2b..b0f966398e 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -462,7 +462,7 @@ public class DefaultLifecycleExecutor // using both the PluginDescriptor and the MojoBinding. try { - PluginDescriptor pluginDescriptor = null; + PluginDescriptor pluginDescriptor; try { pluginDescriptor = pluginLoader.loadPlugin( @@ -487,62 +487,53 @@ public class DefaultLifecycleExecutor } } - if ( pluginDescriptor != null ) + MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( mojoBinding.getGoal() ); + MojoExecution mojoExecution = new MojoExecution( mojoDescriptor ); + + mojoExecution.setConfiguration( (Xpp3Dom) mojoBinding.getConfiguration() ); + + try { - MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( mojoBinding.getGoal() ); - MojoExecution mojoExecution = new MojoExecution( mojoDescriptor ); - - mojoExecution.setConfiguration( (Xpp3Dom) mojoBinding.getConfiguration() ); - - try - { - pluginManager.executeMojo( - project, - mojoExecution, - session ); - } - catch ( PluginManagerException e ) - { - throw new LifecycleExecutionException( - "Internal error in the plugin manager executing goal '" - + mojoDescriptor.getId() + "': " + e.getMessage(), - project, - e ); - } - catch ( ArtifactNotFoundException e ) - { - throw new LifecycleExecutionException( - e.getMessage(), - project, - e ); - } - catch ( InvalidDependencyVersionException e ) - { - throw new LifecycleExecutionException( - e.getMessage(), - project, - e ); - } - catch ( ArtifactResolutionException e ) - { - throw new LifecycleExecutionException( - e.getMessage(), - project, - e ); - } - catch ( PluginConfigurationException e ) - { - throw new LifecycleExecutionException( - e.getMessage(), - project, - e ); - } + pluginManager.executeMojo( + project, + mojoExecution, + session ); } - else + catch ( PluginManagerException e ) { throw new LifecycleExecutionException( - "Failed to load plugin for: " - + MojoBindingUtils.toString( mojoBinding ) + ". Reason: unknown", project ); + "Internal error in the plugin manager executing goal '" + + mojoDescriptor.getId() + "': " + e.getMessage(), + project, + e ); + } + catch ( ArtifactNotFoundException e ) + { + throw new LifecycleExecutionException( + e.getMessage(), + project, + e ); + } + catch ( InvalidDependencyVersionException e ) + { + throw new LifecycleExecutionException( + e.getMessage(), + project, + e ); + } + catch ( ArtifactResolutionException e ) + { + throw new LifecycleExecutionException( + e.getMessage(), + project, + e ); + } + catch ( PluginConfigurationException e ) + { + throw new LifecycleExecutionException( + e.getMessage(), + project, + e ); } } catch ( LifecycleExecutionException e ) 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 7e672af02f..89af1b421e 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 @@ -418,8 +418,11 @@ public class DefaultPluginManager pluginRealm.display(); } - throw new IllegalStateException( "The PluginDescriptor for the plugin " - + projectPlugin.getKey() + " was not found. Should have been in realm: " + pluginRealm ); + getLogger().debug( "Removing invalid plugin realm." ); + realmManager.disposePluginRealm( projectPlugin ); + + throw new PluginManagerException( projectPlugin, "The PluginDescriptor for the plugin " + + projectPlugin.getKey() + " was not found. Should have been in realm: " + pluginRealm, project ); } pluginDescriptor.setPluginArtifact( pluginArtifact ); @@ -854,7 +857,7 @@ public class DefaultPluginManager mergedConfiguration, mojoDescriptor ); - checkDeprecatedParameters( mojoDescriptor, extractedMojoConfiguration ); + checkDeprecatedParameters( mojoDescriptor, pomConfiguration ); checkRequiredParameters( mojoDescriptor, extractedMojoConfiguration, expressionEvaluator ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerException.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerException.java index 8735d1474d..da71197419 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerException.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerException.java @@ -195,6 +195,18 @@ public class PluginManagerException pluginVersion = plugin.getVersion(); } + public PluginManagerException( Plugin plugin, + String message, + MavenProject project ) + { + super( message ); + + pluginGroupId = plugin.getGroupId(); + pluginArtifactId = plugin.getArtifactId(); + pluginVersion = plugin.getVersion(); + this.project = project; + } + public String getPluginGroupId() { return pluginGroupId; diff --git a/maven-core/src/main/java/org/apache/maven/reactor/MissingModuleException.java b/maven-core/src/main/java/org/apache/maven/reactor/MissingModuleException.java new file mode 100644 index 0000000000..2632677a7d --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/reactor/MissingModuleException.java @@ -0,0 +1,30 @@ +package org.apache.maven.reactor; + + +import java.io.File; + +public class MissingModuleException + extends MavenExecutionException +{ + + private File moduleFile; + private final String moduleName; + + public MissingModuleException( String moduleName, File moduleFile, File pomFile ) + { + super( "The module: " + moduleName + " cannot be found in file: " + moduleFile, pomFile ); + this.moduleName = moduleName; + this.moduleFile = moduleFile; + } + + public File getModuleFile() + { + return moduleFile; + } + + public String getModuleName() + { + return moduleName; + } + +} diff --git a/maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/plugin/pom.xml b/maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/plugin/pom.xml new file mode 100644 index 0000000000..4be291cf46 --- /dev/null +++ b/maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/plugin/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + org.apache.maven.errortest + testReportErrorApplyingMojoConfiguration-maven-plugin + 1 + + + + org.apache.maven + maven-plugin-api + 2.0 + + + + + + + maven-surefire-plugin + 2.3.1 + + + maven-deploy-plugin + 2.3 + + + maven-install-plugin + 2.2 + + + maven-resources-plugin + 2.2 + + + maven-jar-plugin + 2.1 + + + maven-compiler-plugin + 2.0.2 + + + maven-plugin-plugin + 2.3 + + + + + \ No newline at end of file diff --git a/maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/plugin/src/main/java/org/plugin/TestPlugin.java b/maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/plugin/src/main/java/org/plugin/TestPlugin.java new file mode 100644 index 0000000000..703166df7c --- /dev/null +++ b/maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/plugin/src/main/java/org/plugin/TestPlugin.java @@ -0,0 +1,33 @@ +package org.plugin; + +import org.apache.maven.plugin.Mojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.Log; + +/** + * @goal test + */ +public class TestPlugin + implements Mojo +{ + + private Log log; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + throw new MojoExecutionException( "This is meant to fail." ); + } + + public Log getLog() + { + return log; + } + + public void setLog( Log log ) + { + this.log = log; + } + +} diff --git a/maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/plugin/src/main/resources/META-INF/maven/plugin.xml b/maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/plugin/src/main/resources/META-INF/maven/plugin.xml new file mode 100644 index 0000000000..d0a45700de --- /dev/null +++ b/maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/plugin/src/main/resources/META-INF/maven/plugin.xml @@ -0,0 +1,38 @@ + + + org.apache.maven.errortest + testReportErrorApplyingMojoConfiguration-maven-plugin + 1 + testReportErrorApplyingMojoConfiguration + false + true + + + test + + false + true + false + false + false + true + org.plugin.TestPlugin + java + per-lookup + once-per-session + + + param + java.lang.String + true + false + + + + + + + + + + \ No newline at end of file diff --git a/maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/project/pom.xml b/maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/project/pom.xml new file mode 100644 index 0000000000..206c42689c --- /dev/null +++ b/maven-embedder/src/test/error-reporting-projects/testReportErrorApplyingMojoConfiguration/project/pom.xml @@ -0,0 +1,45 @@ + + + + 4.0.0 + org.apache.maven + testReportErrorApplyingMojoConfiguration + 1 + + + + + org.apache.maven.errortest + testReportErrorApplyingMojoConfiguration-maven-plugin + 1 + + + test-run + initialize + + test + + + + + + + + diff --git a/maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/child1/pom.xml b/maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/child1/pom.xml new file mode 100644 index 0000000000..16b801ef1c --- /dev/null +++ b/maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/child1/pom.xml @@ -0,0 +1,19 @@ + + + + testReportMissingModulePom + org.apache.maven.errortest + 1 + + 4.0.0 + testReportMissingModulePom-child1 + + + + junit + junit + 3.8.1 + test + + + \ No newline at end of file diff --git a/maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/child1/src/main/java/org/test/App.java b/maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/child1/src/main/java/org/test/App.java new file mode 100644 index 0000000000..0b3975ddcf --- /dev/null +++ b/maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/child1/src/main/java/org/test/App.java @@ -0,0 +1,13 @@ +package org.test; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/child1/src/test/java/org/test/AppTest.java b/maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/child1/src/test/java/org/test/AppTest.java new file mode 100644 index 0000000000..b84ebc68eb --- /dev/null +++ b/maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/child1/src/test/java/org/test/AppTest.java @@ -0,0 +1,38 @@ +package org.test; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/pom.xml b/maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/pom.xml new file mode 100644 index 0000000000..aa0fe2a846 --- /dev/null +++ b/maven-embedder/src/test/error-reporting-projects/testReportMissingModulePom/pom.xml @@ -0,0 +1,13 @@ + + + 4.0.0 + org.apache.maven.errortest + testReportMissingModulePom + pom + 1 + + + child1 + child2 + + \ No newline at end of file diff --git a/maven-embedder/src/test/error-reporting-projects/testReportMojoLookupError/plugin/pom.xml b/maven-embedder/src/test/error-reporting-projects/testReportMojoLookupError/plugin/pom.xml new file mode 100644 index 0000000000..3100481491 --- /dev/null +++ b/maven-embedder/src/test/error-reporting-projects/testReportMojoLookupError/plugin/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + org.apache.maven.errortest + testReportMojoLookupError-maven-plugin + maven-plugin + 1 + + + org.apache.maven + maven-plugin-api + 2.0 + + + org.apache.maven + maven-project + 2.0 + + + + + + + maven-surefire-plugin + 2.3.1 + + + maven-deploy-plugin + 2.3 + + + maven-install-plugin + 2.2 + + + maven-resources-plugin + 2.2 + + + maven-jar-plugin + 2.1 + + + maven-compiler-plugin + 2.0.2 + + + maven-plugin-plugin + 2.3 + + + + + \ No newline at end of file diff --git a/maven-embedder/src/test/error-reporting-projects/testReportMojoLookupError/plugin/src/main/java/org/plugin/TestPlugin.java b/maven-embedder/src/test/error-reporting-projects/testReportMojoLookupError/plugin/src/main/java/org/plugin/TestPlugin.java new file mode 100644 index 0000000000..a1507b091c --- /dev/null +++ b/maven-embedder/src/test/error-reporting-projects/testReportMojoLookupError/plugin/src/main/java/org/plugin/TestPlugin.java @@ -0,0 +1,42 @@ +package org.plugin; + +import org.apache.maven.plugin.Mojo; +import org.apache.maven.project.MavenProject; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.Log; + +/** + * @goal test + * @requiresProject false + * + * @author jdcasey + */ +public class TestPlugin + implements Mojo +{ + + private Log log; + + /** + * @component role-hint="nonexistant" + */ + private MavenProject project; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + throw new MojoExecutionException( "THIS SHOULD NEVER BE CALLED." ); + } + + public Log getLog() + { + return log; + } + + public void setLog( Log log ) + { + this.log = log; + } + +} diff --git a/maven-embedder/src/test/error-reporting-projects/testReportMojoLookupError/project/pom.xml b/maven-embedder/src/test/error-reporting-projects/testReportMojoLookupError/project/pom.xml new file mode 100644 index 0000000000..6b8138d1ba --- /dev/null +++ b/maven-embedder/src/test/error-reporting-projects/testReportMojoLookupError/project/pom.xml @@ -0,0 +1,25 @@ + + + + 4.0.0 + org.apache.maven + testReportAggregatedMojoFailureException + 1 + diff --git a/maven-embedder/src/test/java/org/apache/maven/error/ErrorReporterPointcutTest.java b/maven-embedder/src/test/java/org/apache/maven/error/ErrorReporterPointcutTest.java index cea9754b4d..75b07e0d53 100644 --- a/maven-embedder/src/test/java/org/apache/maven/error/ErrorReporterPointcutTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/error/ErrorReporterPointcutTest.java @@ -197,7 +197,8 @@ public class ErrorReporterPointcutTest } } - private void reportExceptions( MavenExecutionResult result, File basedir ) + private void reportExceptions( MavenExecutionResult result, + File basedir ) { StringWriter writer = new StringWriter(); PrintWriter pWriter = new PrintWriter( writer ); @@ -293,7 +294,14 @@ public class ErrorReporterPointcutTest File basedir = new File( projectDir, "project" ); - reporter.reportAttemptToOverrideUneditableMojoParameter( null, null, null, null, null, null, null, null ); + reporter.reportAttemptToOverrideUneditableMojoParameter( null, + null, + null, + null, + null, + null, + null, + null ); reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER ); reporterCtl.setVoidCallable(); @@ -312,9 +320,35 @@ public class ErrorReporterPointcutTest } public void testReportErrorApplyingMojoConfiguration() + throws IOException { - // TODO Auto-generated method stub + if ( !checkOnline() ) + { + return; + } + File projectDir = prepareProjectDir(); + File plugin = new File( projectDir, "plugin" ); + File project = new File( projectDir, "project" ); + + buildTestAccessory( plugin ); + + reporter.reportErrorApplyingMojoConfiguration( null, null, null, null ); + reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER ); + reporterCtl.setVoidCallable(); + + reporterCtl.replay(); + + MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( project ) + .setShowErrors( true ) + .setErrorReporter( reporter ) + .setGoals( Arrays.asList( new String[] { + "org.apache.maven.errortest:testReportErrorApplyingMojoConfiguration-maven-plugin:1:test" + } ) ); + + maven.execute( request ); + + reporterCtl.verify(); } public void testReportErrorConfiguringExtensionPluginRealm() @@ -326,7 +360,11 @@ public class ErrorReporterPointcutTest File project = new File( projectDir, "project" ); - reporter.reportErrorConfiguringExtensionPluginRealm( null, null, null, null, (PluginManagerException) null ); + reporter.reportErrorConfiguringExtensionPluginRealm( null, + null, + null, + null, + (PluginManagerException) null ); reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER ); reporterCtl.setVoidCallable(); @@ -559,7 +597,13 @@ public class ErrorReporterPointcutTest File localRepo = new File( projectDir, "local-repo" ); File project = new File( projectDir, "project" ); - reporter.reportIncompatibleMavenVersionForExtensionPlugin( null, null, null, null, null, null, null ); + reporter.reportIncompatibleMavenVersionForExtensionPlugin( null, + null, + null, + null, + null, + null, + null ); reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER ); reporterCtl.setVoidCallable(); @@ -703,12 +747,6 @@ public class ErrorReporterPointcutTest reporterCtl.verify(); } - public void testReportMissingPluginDescriptor() - { - // TODO Auto-generated method stub - - } - public void testReportMissingRequiredMojoParameter() throws IOException { @@ -774,9 +812,33 @@ public class ErrorReporterPointcutTest } public void testReportMojoLookupError() + throws IOException { - // TODO Auto-generated method stub + if ( !checkOnline() ) + { + return; + } + File projectDir = prepareProjectDir(); + + buildTestAccessory( new File( projectDir, "plugin" ) ); + + reporter.reportMojoLookupError( null, null, null ); + reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER ); + reporterCtl.setVoidCallable(); + + reporterCtl.replay(); + + MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( projectDir ) + .setShowErrors( true ) + .setErrorReporter( reporter ) + .setGoals( Arrays.asList( new String[] { + "org.apache.maven.errortest:testReportMojoLookupError-maven-plugin:1:test" + } ) ); + + maven.execute( request ); + + reporterCtl.verify(); } public void testReportNoGoalsSpecifiedException() @@ -824,7 +886,9 @@ public class ErrorReporterPointcutTest { File projectDir = prepareProjectDir(); - reporter.reportProjectDependenciesNotFound( null, null, (MultipleArtifactsNotFoundException) null ); + reporter.reportProjectDependenciesNotFound( null, + null, + (MultipleArtifactsNotFoundException) null ); reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER ); reporterCtl.setVoidCallable(); @@ -897,12 +961,6 @@ public class ErrorReporterPointcutTest reporterCtl.verify(); } - public void testReportReflectionErrorWhileEvaluatingMojoParameter() - { - // TODO Auto-generated method stub - - } - public void testReportUnresolvableArtifactWhileAddingExtensionPlugin() throws IOException { @@ -1131,7 +1189,10 @@ public class ErrorReporterPointcutTest { File projectDir = prepareProjectDir(); - reporter.reportErrorLoadingExternalProfilesFromFile( null, null, null, (XmlPullParserException) null ); + reporter.reportErrorLoadingExternalProfilesFromFile( null, + null, + null, + (XmlPullParserException) null ); reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER ); reporterCtl.setVoidCallable(); @@ -1273,7 +1334,10 @@ public class ErrorReporterPointcutTest { File projectDir = prepareProjectDir(); - reporter.reportInvalidRepositoryWhileGettingRepositoriesFromProfiles( null, null, null, null ); + reporter.reportInvalidRepositoryWhileGettingRepositoriesFromProfiles( null, + null, + null, + null ); reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER ); reporterCtl.setVoidCallable(); @@ -1366,4 +1430,27 @@ public class ErrorReporterPointcutTest reporterCtl.verify(); } + public void testReportMissingModulePom() + throws IOException + { + File projectDir = prepareProjectDir(); + + reporter.reportMissingModulePom( null ); + reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER ); + reporterCtl.setVoidCallable(); + + reporterCtl.replay(); + + MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( projectDir ) + .setShowErrors( true ) + .setErrorReporter( reporter ) + .setGoals( Arrays.asList( new String[] { + "initialize" + } ) ); + + maven.execute( request ); + + reporterCtl.verify(); + } + } diff --git a/maven-project/src/main/java/org/apache/maven/realm/DefaultMavenRealmManager.java b/maven-project/src/main/java/org/apache/maven/realm/DefaultMavenRealmManager.java index 1ee59e14a9..8303bcb33f 100644 --- a/maven-project/src/main/java/org/apache/maven/realm/DefaultMavenRealmManager.java +++ b/maven-project/src/main/java/org/apache/maven/realm/DefaultMavenRealmManager.java @@ -339,6 +339,25 @@ public class DefaultMavenRealmManager } } + public void disposePluginRealm( Plugin plugin ) + { + String id = RealmUtils.createPluginRealmId( plugin ); + + logger.debug( "Disposing realm for plugin with id: " + id ); + + try + { + world.disposeRealm( id ); + } + catch ( NoSuchRealmException e ) + { + logger.debug( "Plugin realm: " + id + " didn't exist in ClassWorld instance." ); + } + + managedRealmIds.remove( id ); + pluginArtifacts.remove( id ); + } + public ClassRealm createPluginRealm( Plugin plugin, Artifact pluginArtifact, Collection artifacts ) diff --git a/maven-project/src/main/java/org/apache/maven/realm/MavenRealmManager.java b/maven-project/src/main/java/org/apache/maven/realm/MavenRealmManager.java index 1d6aa5c940..994c8ce4f8 100644 --- a/maven-project/src/main/java/org/apache/maven/realm/MavenRealmManager.java +++ b/maven-project/src/main/java/org/apache/maven/realm/MavenRealmManager.java @@ -37,6 +37,8 @@ public interface MavenRealmManager Collection artifacts ) throws RealmManagementException; + void disposePluginRealm( Plugin plugin ); + void setPluginArtifacts( Plugin plugin, Collection artifacts ); }