Adding more error-reporting unit tests.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@612920 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2008-01-17 18:26:35 +00:00
parent 4bcfd7c5a5
commit 724b3db3c4
7 changed files with 137 additions and 46 deletions

View File

@ -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 ):

View File

@ -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 );

View File

@ -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 )

View File

@ -0,0 +1,55 @@
<?xml version='1.0' encoding='UTF-8'?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.errortest</groupId>
<artifactId>testReportErrorLoadingPlugin-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>nothing</groupId>
<artifactId>nothing</artifactId>
<version>1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.3.1</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
</plugin>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1,45 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven</groupId>
<artifactId>testReportErrorLoadingPlugin</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.errortest</groupId>
<artifactId>testReportErrorLoadingPlugin-maven-plugin</artifactId>
<version>1</version>
<executions>
<execution>
<id>test-run</id>
<phase>initialize</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -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();
}