From 724b3db3c4eeb86aa3282da1a03439a665ab3d55 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Thu, 17 Jan 2008 18:26:35 +0000 Subject: [PATCH] Adding more error-reporting unit tests. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@612920 13f79535-47bb-0310-9956-ffa450edef68 --- .../errors/LifecycleErrorReporterAspect.aj | 17 ++++-- .../maven/errors/CoreErrorReporter.java | 2 - .../errors/DefaultCoreErrorReporter.java | 26 --------- ...eportErrorLoadingPlugin-maven-plugin-1.jar | Bin 0 -> 3333 bytes ...eportErrorLoadingPlugin-maven-plugin-1.pom | 55 ++++++++++++++++++ .../project/pom.xml | 45 ++++++++++++++ .../error/ErrorReporterPointcutTest.java | 38 +++++++----- 7 files changed, 137 insertions(+), 46 deletions(-) create mode 100644 maven-embedder/src/test/error-reporting-projects/testReportErrorLoadingPlugin/local-repo/org/apache/maven/errortest/testReportErrorLoadingPlugin-maven-plugin/1/testReportErrorLoadingPlugin-maven-plugin-1.jar create mode 100644 maven-embedder/src/test/error-reporting-projects/testReportErrorLoadingPlugin/local-repo/org/apache/maven/errortest/testReportErrorLoadingPlugin-maven-plugin/1/testReportErrorLoadingPlugin-maven-plugin-1.pom create mode 100644 maven-embedder/src/test/error-reporting-projects/testReportErrorLoadingPlugin/project/pom.xml 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 fcdde5a49b..9c2a1839b2 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 @@ -9,11 +9,13 @@ import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException; 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.loader.PluginLoader; 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.statemgmt.StateManagementUtils; import org.apache.maven.lifecycle.DefaultLifecycleExecutor; import org.apache.maven.lifecycle.LifecycleException; import org.apache.maven.lifecycle.LifecycleExecutionException; @@ -23,6 +25,7 @@ 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; @@ -54,10 +57,10 @@ public privileged aspect LifecycleErrorReporterAspect 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 ) + after( MojoBinding binding, MavenProject project ) throwing ( PluginLoaderException cause ): + cflow( le_executeGoalAndHandleFailures( MojoBinding ) ) + && call( * PluginLoader+.loadPlugin( MojoBinding, MavenProject, .. ) ) + && args( binding, project, .. ) { getReporter().reportErrorLoadingPlugin( binding, project, cause ); } @@ -68,7 +71,11 @@ public privileged aspect LifecycleErrorReporterAspect && handler( MojoExecutionException ) && args( cause ) { - getReporter().reportMojoExecutionException( binding, project, cause ); + // this will be covered by the reportErrorLoadingPlugin(..) method. + if ( !StateManagementUtils.RESOLVE_LATE_BOUND_PLUGIN_GOAL.equals( binding.getGoal() ) ) + { + getReporter().reportMojoExecutionException( binding, project, cause ); + } } PluginExecutionException around( MojoBinding binding, MavenProject project ): 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 e5845b59b0..478da68ee5 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 @@ -107,8 +107,6 @@ public interface CoreErrorReporter void reportNoGoalsSpecifiedException( MavenProject rootProject, NoGoalsSpecifiedException error ); - void reportPluginErrorWhileValidatingTask( String task, MavenSession session, MavenProject rootProject, PluginLoaderException cause ); - void reportProjectCycle( ProjectCycleException error ); void reportProjectDependenciesNotFound( MavenProject project, String scope, ArtifactNotFoundException cause ); 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 46679511c6..335dcc2fb5 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 @@ -291,32 +291,6 @@ public class DefaultCoreErrorReporter registerBuildError( cause, writer.toString(), cause.getCause() ); } - public void reportPluginErrorWhileValidatingTask( String task, - MavenSession session, - MavenProject rootProject, - PluginLoaderException cause ) - { - StringWriter writer = new StringWriter(); - - writer.write( NEWLINE ); - writer.write( "Invalid mojo or lifecycle phase: " ); - writer.write( task ); - writer.write( NEWLINE ); - writer.write( NEWLINE ); - - writer.write( "Failed to load plugin: " ); - writer.write( cause.getPluginKey() ); - writer.write( NEWLINE ); - writer.write( NEWLINE ); - - writer.write( "Original error message was: " ); - writer.write( cause.getMessage() ); - - addTips( CoreErrorTips.getTaskValidationTips( task, cause ), writer ); - - registerBuildError( cause, writer.toString(), cause.getCause() ); - } - public void reportMissingPluginDescriptor( MojoBinding binding, MavenProject project, LifecycleExecutionException err ) diff --git a/maven-embedder/src/test/error-reporting-projects/testReportErrorLoadingPlugin/local-repo/org/apache/maven/errortest/testReportErrorLoadingPlugin-maven-plugin/1/testReportErrorLoadingPlugin-maven-plugin-1.jar b/maven-embedder/src/test/error-reporting-projects/testReportErrorLoadingPlugin/local-repo/org/apache/maven/errortest/testReportErrorLoadingPlugin-maven-plugin/1/testReportErrorLoadingPlugin-maven-plugin-1.jar new file mode 100644 index 0000000000000000000000000000000000000000..edc812c0ad39cfcb6b85f7b2a953ba0a11ba2215 GIT binary patch literal 3333 zcmWIWW@h1H0D-nx0}C(%N^k;cU)K;vT~9wZ{Q#&k4u)2svUNdImt+8?>ws7US(&e+ zpQoE^aEP9-+h^Z1r+vJ2^)B*y>uQ}lbAEG>!4=~NPm6TC&YjTl)^*}wf3hTOikS8R zm5QBnx`TwhgMv%uYONKK;TD=~93)yJd^+eeP{zx+*z3TfNX?U-M^{c2SSS*^eoD@S zpUbM)KDHg(6SF6V0p>DH5AY+qEH|+%H4p9$OvNlf#rZ|)cvNshRTSiure`9I;s6KS z+hrk(8W|ZF*ns9pV%iJQqgRoeGk5YqzrzMRZSQT4#wGObaJO90xP>`Ms$+NNT^(iL zrpaNqZ%^LBdE3gN>GYEu^Z#4ii+@+5KUL7Yn>GK!^(8R@*Er6d^IxfT@>||r4)0A& z>|gm-^RbzT3Pp0gU`}uKv_e|%~pm!6*GSu^9-5#4lEne;6S%v;u4{ds-vN5f=?OTqWDIBw(!mZ(Qvkh9$F z(>LR$;>sDjtk-R5jbj&F;s2sk@#EaP(eoF{_$SVbe-gTE!;|{I>26IQ7KgXgiPk@w zb|xWPqS59{|JR)d+TPd+{bc<7X3jjbH_x|EDLLrq<-~a~Nb$T;@mcl7QxEP;IVbj` zUweL))$)zb!po+sEBk+275C^=H)~o*=Cy3zqge)cuLySq$H^(HsC&$l^s(=>ROtU!sxqK%Q?M7592QkuWNpnaKR zu(ppv`p?(@Szze}5^qy8E=)ZJjJG0Y1_o)=2o6atE(rj~wO(>gVsUYA&~3ll4g$8X zV|dhZcc@O8=Cp&8S+(wEw04|UMUlRcV354|yK6a5DwNZEf9OnDF~Om!+-}vYH%X=) zK`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RZA%&t(b;9t qG9M8o*vlG(1MjlaH|RhPM3g)M-mJiik%5652;TtPe9WL;4g&yzn4GTw literal 0 HcmV?d00001 diff --git a/maven-embedder/src/test/error-reporting-projects/testReportErrorLoadingPlugin/local-repo/org/apache/maven/errortest/testReportErrorLoadingPlugin-maven-plugin/1/testReportErrorLoadingPlugin-maven-plugin-1.pom b/maven-embedder/src/test/error-reporting-projects/testReportErrorLoadingPlugin/local-repo/org/apache/maven/errortest/testReportErrorLoadingPlugin-maven-plugin/1/testReportErrorLoadingPlugin-maven-plugin-1.pom new file mode 100644 index 0000000000..8420b9fc7b --- /dev/null +++ b/maven-embedder/src/test/error-reporting-projects/testReportErrorLoadingPlugin/local-repo/org/apache/maven/errortest/testReportErrorLoadingPlugin-maven-plugin/1/testReportErrorLoadingPlugin-maven-plugin-1.pom @@ -0,0 +1,55 @@ + + + 4.0.0 + org.apache.maven.errortest + testReportErrorLoadingPlugin-maven-plugin + maven-plugin + 1 + + + + org.apache.maven + maven-plugin-api + 2.0 + + + nothing + nothing + 1 + + + + + + + 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/testReportErrorLoadingPlugin/project/pom.xml b/maven-embedder/src/test/error-reporting-projects/testReportErrorLoadingPlugin/project/pom.xml new file mode 100644 index 0000000000..0afd00fa24 --- /dev/null +++ b/maven-embedder/src/test/error-reporting-projects/testReportErrorLoadingPlugin/project/pom.xml @@ -0,0 +1,45 @@ + + + + 4.0.0 + org.apache.maven + testReportErrorLoadingPlugin + 1 + + + + + org.apache.maven.errortest + testReportErrorLoadingPlugin-maven-plugin + 1 + + + test-run + initialize + + test + + + + + + + + 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 8992d4a38e..cea9754b4d 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 @@ -408,9 +408,33 @@ public class ErrorReporterPointcutTest } public void testReportErrorLoadingPlugin() + throws IOException { - // TODO Auto-generated method stub + File projectDir = prepareProjectDir(); + File localRepo = new File( projectDir, "local-repo" ); + File project = new File( projectDir, "project" ); + Settings settings = new Settings(); + settings.setOffline( true ); + settings.setLocalRepository( localRepo.getAbsolutePath() ); + + reporter.reportErrorLoadingPlugin( null, null, null ); + reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER ); + reporterCtl.setVoidCallable(); + + reporterCtl.replay(); + + MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( project ) + .setSettings( settings ) + .setShowErrors( true ) + .setErrorReporter( reporter ) + .setGoals( Arrays.asList( new String[] { + "initialize" + } ) ); + + maven.execute( request ); + + reporterCtl.verify(); } public void testReportErrorManagingRealmForExtension() @@ -772,12 +796,6 @@ public class ErrorReporterPointcutTest reporterCtl.verify(); } - public void testReportPluginErrorWhileValidatingTask() - { - // TODO Auto-generated method stub - - } - public void testReportProjectCycle() throws IOException { @@ -906,17 +924,11 @@ public class ErrorReporterPointcutTest .setShowErrors( true ) .setSettings( settings ) .setErrorReporter( reporter ) -// .setErrorReporter( new DummyCoreErrorReporter() ) .setGoals( Arrays.asList( new String[] { "initialize" } ) ); maven.execute( request ); -// MavenExecutionResult result = maven.execute( request ); -// if ( result.hasExceptions() ) -// { -// reportExceptions( result, project ); -// } reporterCtl.verify(); }