Adding some unit tests (mostly stubbed out at the moment) to start testing the pointcuts used to shunt build errors off to the appropriate error-reporter method.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@610618 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2008-01-10 00:07:48 +00:00
parent a4a9ae668e
commit dc770e321b
12 changed files with 694 additions and 44 deletions

View File

@ -21,7 +21,6 @@ import org.apache.maven.model.Plugin;
import org.apache.maven.extension.ExtensionScanningException;
import org.apache.maven.extension.DefaultBuildExtensionScanner;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.build.model.ModelLineage;
import org.apache.maven.project.interpolation.ModelInterpolator;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.apache.maven.extension.ExtensionManagerException;
@ -48,18 +47,6 @@ public privileged aspect ExtensionErrorReporterAspect
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 ) );

View File

@ -49,24 +49,6 @@ public aspect MavenExecErrorReporterAspect
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 ) )

View File

@ -99,8 +99,6 @@ public interface CoreErrorReporter
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 );

View File

@ -870,17 +870,6 @@ public class DefaultCoreErrorReporter
registerBuildError( cause, writer.toString(), cause.getCause() );
}
public void handleProjectBuildingError( MavenExecutionRequest request,
File pomFile,
ProjectBuildingException exception )
{
ProjectErrorReporter projectReporter = ProjectReporterManager.getReporter();
Throwable reportedException = projectReporter.findReportedException( exception );
String formattedMessage = projectReporter.getFormattedMessage( reportedException );
registerBuildError( exception, formattedMessage, reportedException );
}
public void reportInvalidMavenVersion( MavenProject project,
ArtifactVersion mavenVersion,
MavenExecutionException err )

View File

@ -407,6 +407,7 @@ public class DefaultBuildExtensionScanner
}
catch ( ProjectBuildingException e )
{
System.out.println( "blah" );
throw new ExtensionScanningException( "Error building model lineage in order to pre-scan for extensions: "
+ e.getMessage(), pom, e );
}

View File

@ -80,6 +80,11 @@ under the License.
<artifactId>aspectjrt</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>easymock</groupId>
<artifactId>easymock</artifactId>
</dependency>
</dependencies>
<distributionManagement>
<site>

View File

@ -0,0 +1,25 @@
<!--
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>testReportErrorParsingProjectModel_XmlPullParserException</artifactId>
<version>1</ver>
</project>

View File

@ -0,0 +1,18 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.test.error</groupId>
<artifactId>test-mojo-failure</artifactId>
<packaging>jar</packaging>
<version>1</version>
<name>test-mojo-failure</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,14 @@
package org.apache.maven.test.error.mojoFailure;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
StringUtils utils;
}
}

View File

@ -0,0 +1,38 @@
package org.apache.maven.test.error.mojoFailure;
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 );
}
}

View File

@ -0,0 +1,565 @@
package org.apache.maven.error;
import org.apache.maven.embedder.Configuration;
import org.apache.maven.embedder.DefaultConfiguration;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.easymock.MockControl;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Arrays;
import junit.framework.TestCase;
public class ErrorReporterPointcutTest
extends TestCase
{
private MockControl reporterCtl;
private CoreErrorReporter reporter;
private MavenEmbedder maven;
private String basedir;
public void setUp()
throws Exception
{
super.setUp();
reporterCtl = MockControl.createStrictControl( CoreErrorReporter.class );
reporter = (CoreErrorReporter) reporterCtl.getMock();
reporter.clearErrors();
reporterCtl.setVoidCallable( MockControl.ONE_OR_MORE );
basedir = System.getProperty( "basedir" );
if ( basedir == null )
{
basedir = new File( "." ).getCanonicalPath();
}
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Configuration configuration = new DefaultConfiguration().setClassLoader( classLoader )
.setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
maven = new MavenEmbedder( configuration );
}
private File prepareProjectDir()
throws URISyntaxException, IOException
{
String method = new Throwable().getStackTrace()[1].getMethodName();
String resource = "error-reporting-projects/" + method;
File testDirectory = new File( basedir, "src/test/" + resource );
File targetDirectory = new File( basedir, "target/" + resource );
if ( targetDirectory.exists() )
{
try
{
FileUtils.deleteDirectory( targetDirectory );
}
catch( IOException e )
{}
}
FileUtils.copyDirectoryStructure( testDirectory, targetDirectory );
return targetDirectory;
}
public void testHandleErrorBuildingExtensionPluginPOM()
throws URISyntaxException
{
// TODO Auto-generated method stub
}
public void testHandleProjectBuildingError()
{
// TODO Auto-generated method stub
}
public void testHandleSuperPomBuildingError_XmlPullParserException()
{
// TODO Auto-generated method stub
}
public void testHandleSuperPomBuildingError_IOException()
{
// TODO Auto-generated method stub
}
public void testReportAggregatedMojoFailureException()
{
// TODO Auto-generated method stub
}
public void testReportAttemptToOverrideUneditableMojoParameter()
{
// TODO Auto-generated method stub
}
public void testReportErrorApplyingMojoConfiguration()
{
// TODO Auto-generated method stub
}
public void testReportErrorConfiguringExtensionPluginRealm()
{
// TODO Auto-generated method stub
}
public void testReportErrorFormulatingBuildPlan()
{
// TODO Auto-generated method stub
}
public void testReportErrorInterpolatingModel_UsingProjectInstance()
{
// TODO Auto-generated method stub
}
public void testReportErrorLoadingPlugin()
{
// TODO Auto-generated method stub
}
public void testReportErrorManagingRealmForExtension()
{
// TODO Auto-generated method stub
}
public void testReportErrorManagingRealmForExtensionPlugin()
{
// TODO Auto-generated method stub
}
public void testReportErrorResolvingExtensionDependencies()
{
// TODO Auto-generated method stub
}
public void testReportErrorResolvingExtensionDirectDependencies()
{
// TODO Auto-generated method stub
}
public void testReportErrorSearchingforCompatibleExtensionPluginVersion()
{
// TODO Auto-generated method stub
}
public void testReportExtensionPluginArtifactNotFound()
{
// TODO Auto-generated method stub
}
public void testReportExtensionPluginVersionNotFound()
{
// TODO Auto-generated method stub
}
public void testReportIncompatibleMavenVersionForExtensionPlugin()
{
// TODO Auto-generated method stub
}
public void testReportInvalidDependencyVersionInExtensionPluginPOM()
{
// TODO Auto-generated method stub
}
public void testReportInvalidMavenVersion()
{
// TODO Auto-generated method stub
}
public void testReportInvalidPluginExecutionEnvironment()
throws URISyntaxException, IOException
{
File projectDir = prepareProjectDir();
reporter.reportInvalidPluginExecutionEnvironment( 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[] {
"compiler:compile"
} ) );
maven.execute( request );
reporterCtl.verify();
}
public void testReportLifecycleLoaderErrorWhileValidatingTask()
{
// TODO Auto-generated method stub
}
public void testReportLifecycleSpecErrorWhileValidatingTask()
{
// TODO Auto-generated method stub
}
public void testReportMissingArtifactWhileAddingExtensionPlugin()
{
// TODO Auto-generated method stub
}
public void testReportMissingPluginDescriptor()
{
// TODO Auto-generated method stub
}
public void testReportMissingRequiredMojoParameter()
{
// TODO Auto-generated method stub
}
public void testReportMojoExecutionException()
{
// TODO Auto-generated method stub
}
public void testReportMojoLookupError()
{
// TODO Auto-generated method stub
}
public void testReportNoGoalsSpecifiedException()
{
// TODO Auto-generated method stub
}
public void testReportPluginErrorWhileValidatingTask()
{
// TODO Auto-generated method stub
}
public void testReportPomFileCanonicalizationError()
{
// TODO Auto-generated method stub
}
public void testReportPomFileScanningError()
{
// TODO Auto-generated method stub
}
public void testReportProjectCycle()
{
// TODO Auto-generated method stub
}
public void testReportProjectDependenciesNotFound()
{
// TODO Auto-generated method stub
}
public void testReportProjectDependenciesUnresolvable()
{
// TODO Auto-generated method stub
}
public void testReportProjectDependencyArtifactNotFound()
{
// TODO Auto-generated method stub
}
public void testReportProjectDependencyArtifactUnresolvable()
{
// TODO Auto-generated method stub
}
public void testReportProjectMojoFailureException()
throws URISyntaxException, IOException
{
File projectDir = prepareProjectDir();
reporter.reportProjectMojoFailureException( 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[] {
"clean",
"package"
} ) );
maven.execute( request );
reporterCtl.verify();
}
public void testReportReflectionErrorWhileEvaluatingMojoParameter()
{
// TODO Auto-generated method stub
}
public void testReportUnresolvableArtifactWhileAddingExtensionPlugin()
{
// TODO Auto-generated method stub
}
public void testReportUnresolvableExtensionPluginPOM()
{
// TODO Auto-generated method stub
}
public void testReportUseOfBannedMojoParameter()
{
// TODO Auto-generated method stub
}
public void clearErrors()
{
// TODO Auto-generated method stub
}
public Throwable findReportedException( Throwable error )
{
// TODO Auto-generated method stub
return null;
}
public String getFormattedMessage( Throwable error )
{
// TODO Auto-generated method stub
return null;
}
public Throwable getRealCause( Throwable error )
{
// TODO Auto-generated method stub
return null;
}
public void testReportActivatorErrorWhileApplyingProfiles()
{
// TODO Auto-generated method stub
}
public void testReportActivatorErrorWhileGettingRepositoriesFromProfiles()
{
// TODO Auto-generated method stub
}
public void testReportActivatorLookupErrorWhileApplyingProfiles()
{
// TODO Auto-generated method stub
}
public void testReportActivatorLookupErrorWhileGettingRepositoriesFromProfiles()
{
// TODO Auto-generated method stub
}
public void testReportBadDependencyVersion()
{
// TODO Auto-generated method stub
}
public void testReportBadManagedDependencyVersion()
{
// TODO Auto-generated method stub
}
public void testReportBadNonDependencyProjectArtifactVersion()
{
// TODO Auto-generated method stub
}
public void testReportErrorCreatingArtifactRepository()
{
// TODO Auto-generated method stub
}
public void testReportErrorCreatingDeploymentArtifactRepository()
{
// TODO Auto-generated method stub
}
public void testReportErrorInterpolatingModel_UsingModelInstance()
{
// TODO Auto-generated method stub
}
public void testReportErrorLoadingExternalProfilesFromFile_XmlPullParserException()
{
// TODO Auto-generated method stub
}
public void testReportErrorLoadingExternalProfilesFromFile_IOException()
{
// TODO Auto-generated method stub
}
public void testReportErrorParsingParentProjectModel_XmlPullParserException()
{
// TODO Auto-generated method stub
}
public void testReportErrorParsingParentProjectModel_IOException()
{
// TODO Auto-generated method stub
}
public void testReportErrorParsingProjectModel_XmlPullParserException()
throws URISyntaxException, IOException
{
File projectDir = prepareProjectDir();
reporter.reportErrorParsingProjectModel( null, null, (XmlPullParserException) null );
reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER );
reporterCtl.setVoidCallable();
reporterCtl.replay();
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( projectDir )
.setLoggingLevel( Logger.LEVEL_DEBUG )
.setShowErrors( true )
.setErrorReporter( reporter )
.setGoals( Arrays.asList( new String[] {
"initialize"
} ) );
maven.execute( request );
reporterCtl.verify();
}
public void testReportErrorParsingProjectModel_IOException()
throws URISyntaxException, IOException
{
File projectDir = prepareProjectDir();
reporter.reportErrorParsingProjectModel( null, null, (IOException) null );
reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER );
reporterCtl.setVoidCallable();
reporterCtl.replay();
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setPom( new File( projectDir, "pom.xml" ) )
.setShowErrors( true )
.setErrorReporter( reporter )
.setGoals( Arrays.asList( new String[] {
"initialize"
} ) );
maven.execute( request );
reporterCtl.verify();
}
public void testReportInvalidRepositoryWhileGettingRepositoriesFromProfiles()
{
// TODO Auto-generated method stub
}
public void testReportParentPomArtifactNotFound()
{
// TODO Auto-generated method stub
}
public void testReportParentPomArtifactUnresolvable()
{
// TODO Auto-generated method stub
}
public void testReportProjectCollision()
{
// TODO Auto-generated method stub
}
public void testReportProjectValidationFailure()
{
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,28 @@
package org.apache.maven.project.aspect;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.DefaultMavenProjectBuilder;
import org.codehaus.plexus.util.StringUtils;
import java.util.List;
public privileged aspect ProjectDebugAspect
{
// before( String dir, MavenProject project ):
// cflow( execution( * DefaultMavenProjectBuilder.buildInternal( .. ) ) )
// && call( void MavenProject.addScriptSourceRoot( String ) )
// && args( dir )
// && target( project )
// {
// System.out.println( "Setting script-source-root from POM to: " + dir + " in project: " + project.getId() );
// }
//
// after( MavenProject project ) returning( List scriptSourceRoots ):
// execution( List MavenProject.getScriptSourceRoots() )
// && this( project )
// {
// System.out.println( "Using script-source-roots:\n\n" + StringUtils.join( scriptSourceRoots.iterator(), "\nfrom project: " + project.getId() ) );
// }
}