mirror of
https://github.com/apache/maven.git
synced 2025-02-28 05:39:15 +00:00
two more unit tests, and a little simplification to take care of duplicated error reporting coverage.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@611974 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c3983894ab
commit
6e230d611a
@ -4,9 +4,8 @@ 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.artifact.resolver.MultipleArtifactsNotFoundException;
|
||||
import org.apache.maven.plugin.PluginConfigurationException;
|
||||
import org.apache.maven.plugin.descriptor.Parameter;
|
||||
import org.apache.maven.plugin.loader.PluginLoaderException;
|
||||
@ -216,30 +215,15 @@ public privileged aspect LifecycleErrorReporterAspect
|
||||
|
||||
after( MavenProject project, String scope ) throwing( ArtifactResolutionException cause ):
|
||||
pm_resolveTransitiveDependencies( project, scope )
|
||||
{
|
||||
if ( cause instanceof MultipleArtifactsNotFoundException )
|
||||
{
|
||||
getReporter().reportProjectDependenciesNotFound( project, scope, (MultipleArtifactsNotFoundException) cause );
|
||||
}
|
||||
else
|
||||
{
|
||||
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 ):
|
||||
|
@ -7,6 +7,7 @@
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException;
|
||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
@ -112,12 +113,10 @@ public interface CoreErrorReporter
|
||||
|
||||
void reportProjectDependenciesNotFound( MavenProject project, String scope, ArtifactNotFoundException cause );
|
||||
|
||||
void reportProjectDependenciesNotFound( MavenProject project, String scope, MultipleArtifactsNotFoundException 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 reportProjectMojoFailureException( MavenSession session, MojoBinding binding, MojoFailureException cause );
|
||||
|
||||
void reportReflectionErrorWhileEvaluatingMojoParameter( Parameter currentParameter, MojoBinding binding, MavenProject project, String expression, Exception cause );
|
||||
|
@ -10,6 +10,7 @@
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.artifact.resolver.CyclicDependencyException;
|
||||
import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException;
|
||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
@ -643,6 +644,13 @@ public void reportProjectDependenciesNotFound( MavenProject project,
|
||||
reportTransitiveResolutionError( project, scope, cause );
|
||||
}
|
||||
|
||||
public void reportProjectDependenciesNotFound( MavenProject project,
|
||||
String scope,
|
||||
MultipleArtifactsNotFoundException cause )
|
||||
{
|
||||
reportTransitiveResolutionError( project, scope, cause );
|
||||
}
|
||||
|
||||
public void reportProjectDependenciesUnresolvable( MavenProject project,
|
||||
String scope,
|
||||
ArtifactResolutionException cause )
|
||||
@ -650,20 +658,6 @@ public void reportProjectDependenciesUnresolvable( MavenProject project,
|
||||
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 )
|
||||
@ -692,24 +686,6 @@ private void reportTransitiveResolutionError( MavenProject project,
|
||||
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:" );
|
||||
|
||||
writeArtifactInfo( depArtifact, cause, writer, true );
|
||||
|
||||
writeProjectCoordinate( project, writer );
|
||||
addTips( CoreErrorTips.getDependencyArtifactResolutionTips( project, depArtifact, cause ),
|
||||
writer );
|
||||
|
||||
registerBuildError( cause, writer.toString(), cause.getCause() );
|
||||
}
|
||||
|
||||
private void writeArtifactError( AbstractArtifactResolutionException cause,
|
||||
StringWriter writer )
|
||||
{
|
||||
|
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven.errortest</groupId>
|
||||
<artifactId>testReportProjectDependenciesNotFound</artifactId>
|
||||
<version>1</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>central</id>
|
||||
<url>file://${java.io.tmpdir}</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>not</groupId>
|
||||
<artifactId>found</artifactId>
|
||||
<version>3.8.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,13 @@
|
||||
package org.apache.maven.test.error.mojoFailure;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
@ -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 );
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven.errortest</groupId>
|
||||
<artifactId>testReportProjectDependenciesUnresolvable</artifactId>
|
||||
<version>1</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>central</id>
|
||||
<url>test://host/path</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>not</groupId>
|
||||
<artifactId>found</artifactId>
|
||||
<version>3.8.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,13 @@
|
||||
package org.apache.maven.test.error.mojoFailure;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
@ -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 );
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
import org.apache.commons.httpclient.HttpException;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException;
|
||||
import org.apache.maven.embedder.Configuration;
|
||||
import org.apache.maven.embedder.DefaultConfiguration;
|
||||
import org.apache.maven.embedder.MavenEmbedder;
|
||||
@ -216,31 +217,35 @@ private void reportExceptions( MavenExecutionResult result, File basedir )
|
||||
fail( writer.toString() );
|
||||
}
|
||||
|
||||
// FIXME: Figure out how to keep the project-build error report from being the primary report...
|
||||
public void testReportErrorResolvingExtensionDirectDependencies()
|
||||
throws URISyntaxException, IOException
|
||||
{
|
||||
// File projectDir = prepareProjectDir();
|
||||
// File localRepo = new File( projectDir, "local-repo" );
|
||||
// File project = new File( projectDir, "project" );
|
||||
//
|
||||
// reporter.reportErrorResolvingExtensionDirectDependencies( null, null, null, null, null );
|
||||
// reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
// reporterCtl.setVoidCallable();
|
||||
//
|
||||
// reporterCtl.replay();
|
||||
//
|
||||
// MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( project )
|
||||
// .setLocalRepositoryPath( localRepo )
|
||||
// .setShowErrors( true )
|
||||
// .setErrorReporter( reporter )
|
||||
// .setGoals( Arrays.asList( new String[] {
|
||||
// "initialize"
|
||||
// } ) );
|
||||
//
|
||||
// maven.execute( request );
|
||||
//
|
||||
// reporterCtl.verify();
|
||||
File projectDir = prepareProjectDir();
|
||||
File localRepo = new File( projectDir, "local-repo" );
|
||||
File project = new File( projectDir, "project" );
|
||||
|
||||
// TODO: Verify that the actual error reported is the one that identified the failing project as an extension POM.
|
||||
reporter.reportBadDependencyVersion( null, null, null );
|
||||
reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
reporterCtl.setVoidCallable();
|
||||
|
||||
reporter.reportErrorResolvingExtensionDirectDependencies( null, null, null, null, null );
|
||||
reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
reporterCtl.setVoidCallable();
|
||||
|
||||
reporterCtl.replay();
|
||||
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( project )
|
||||
.setLocalRepositoryPath( localRepo )
|
||||
.setShowErrors( true )
|
||||
.setErrorReporter( reporter )
|
||||
.setGoals( Arrays.asList( new String[] {
|
||||
"initialize"
|
||||
} ) );
|
||||
|
||||
maven.execute( request );
|
||||
|
||||
reporterCtl.verify();
|
||||
}
|
||||
|
||||
public void testReportAggregatedMojoFailureException()
|
||||
@ -613,27 +618,49 @@ public void testReportProjectCycle()
|
||||
}
|
||||
|
||||
public void testReportProjectDependenciesNotFound()
|
||||
throws URISyntaxException, IOException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
File projectDir = prepareProjectDir();
|
||||
|
||||
reporter.reportProjectDependenciesNotFound( null, null, (MultipleArtifactsNotFoundException) 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[] {
|
||||
"compile"
|
||||
} ) );
|
||||
|
||||
maven.execute( request );
|
||||
|
||||
reporterCtl.verify();
|
||||
}
|
||||
|
||||
public void testReportProjectDependenciesUnresolvable()
|
||||
throws URISyntaxException, IOException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
File projectDir = prepareProjectDir();
|
||||
|
||||
}
|
||||
reporter.reportProjectDependenciesUnresolvable( null, null, null );
|
||||
reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
reporterCtl.setVoidCallable();
|
||||
|
||||
public void testReportProjectDependencyArtifactNotFound()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
reporterCtl.replay();
|
||||
|
||||
}
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( projectDir )
|
||||
.setShowErrors( true )
|
||||
.setErrorReporter( reporter )
|
||||
.setGoals( Arrays.asList( new String[] {
|
||||
"compile"
|
||||
} ) );
|
||||
|
||||
public void testReportProjectDependencyArtifactUnresolvable()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
maven.execute( request );
|
||||
|
||||
reporterCtl.verify();
|
||||
}
|
||||
|
||||
public void testReportProjectMojoFailureException()
|
||||
|
Loading…
x
Reference in New Issue
Block a user