Adding error reporting for most project errors via aspects that collect the context information and format a nice message (the aspect just binds to the errors API in org.apache.maven.project.error.*).

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@598748 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2007-11-27 19:55:04 +00:00
parent 249af52bb5
commit a3b489d71e
12 changed files with 1751 additions and 394 deletions

View File

@ -32,6 +32,11 @@ under the License.
<artifactId>maven-core</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
@ -69,7 +74,7 @@ under the License.
<artifactId>wagon-file</artifactId>
</dependency>
<!-- Needed for backward compat aspect. -->
<!-- Needed for compat and cache-control aspects. -->
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjrt</artifactId>
@ -175,7 +180,7 @@ under the License.
-->
<id>tycho</id>
<properties>
<bundleVersion>2.1.0.v20071105-1933</bundleVersion>
<bundleVersion>2.1.0.v20071120-1632</bundleVersion>
</properties>
<build>
<resources>

View File

@ -0,0 +1,87 @@
package org.apache.maven.embedder.cache;
import org.aspectj.lang.Aspects;
import java.io.StringWriter;
import java.io.PrintWriter;
import org.apache.maven.cli.CLIReportingUtils;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.project.aspect.PBEDerivativeReporterAspect;
import org.apache.maven.project.error.DefaultProjectErrorReporter;
import org.apache.maven.project.error.ProjectErrorReporter;
import org.apache.maven.project.ProjectBuildingException;
public privileged aspect ErrorReportingAspect
{
private ProjectErrorReporter projectErrorReporter;
private pointcut embedderCalls():
execution( public MavenExecutionResult MavenEmbedder.*( .. ) );
before():
embedderCalls() && !cflow( embedderCalls() )
{
projectErrorReporter = new DefaultProjectErrorReporter();
PBEDerivativeReporterAspect pbeDerivativeReporterAspect = Aspects.aspectOf( PBEDerivativeReporterAspect.class );
pbeDerivativeReporterAspect.setProjectErrorReporter( projectErrorReporter );
}
private pointcut cliReportingUtilsCalls():
execution( * CLIReportingUtils.*( .. ) );
before():
cliReportingUtilsCalls()
&& !cflow( cliReportingUtilsCalls() )
&& !cflow( embedderCalls() )
{
projectErrorReporter = new DefaultProjectErrorReporter();
PBEDerivativeReporterAspect pbeDerivativeReporterAspect = Aspects.aspectOf( PBEDerivativeReporterAspect.class );
pbeDerivativeReporterAspect.setProjectErrorReporter( projectErrorReporter );
}
boolean around( ProjectBuildingException e, boolean showStackTraces, StringWriter writer ):
execution( private static boolean CLIReportingUtils.handleProjectBuildingException( ProjectBuildingException, boolean, StringWriter ) )
&& args( e, showStackTraces, writer )
{
// if ( projectErrorReporter == null )
// {
// return proceed( e, showStackTraces, writer );
// }
// else
// {
Throwable reportingError = projectErrorReporter.findReportedException( e );
boolean result = false;
if ( reportingError != null )
{
writer.write( projectErrorReporter.getFormattedMessage( reportingError ) );
if ( showStackTraces )
{
writer.write( CLIReportingUtils.NEWLINE );
writer.write( CLIReportingUtils.NEWLINE );
Throwable cause = projectErrorReporter.getRealCause( reportingError );
cause.printStackTrace( new PrintWriter( writer ) );
}
writer.write( CLIReportingUtils.NEWLINE );
writer.write( CLIReportingUtils.NEWLINE );
result = true;
}
else
{
result = proceed( e, showStackTraces, writer );
}
return result;
// }
}
}

View File

@ -6,7 +6,6 @@ import org.apache.maven.InvalidTaskException;
import org.apache.maven.NoGoalsSpecifiedException;
import org.apache.maven.ProjectBuildFailureException;
import org.apache.maven.ProjectCycleException;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
@ -18,20 +17,15 @@ import org.apache.maven.execution.ReactorManager;
import org.apache.maven.extension.ExtensionScanningException;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.MojoBindingUtils;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.loader.PluginLoaderException;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.project.DuplicateProjectException;
import org.apache.maven.project.InvalidProjectModelException;
import org.apache.maven.project.InvalidProjectVersionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.reactor.MavenExecutionException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@ -610,73 +604,76 @@ public final class CLIReportingUtils
Throwable cause = e.getCause();
// Start by looking at whether we can handle the PBE as a specific sub-class of ProjectBuildingException...
if ( e instanceof InvalidProjectModelException )
// if ( e instanceof InvalidProjectModelException )
// {
// InvalidProjectModelException error = (InvalidProjectModelException) e;
//
// writer.write( error.getMessage() );
// writer.write( NEWLINE );
// writer.write( NEWLINE );
// writer.write( "The following POM validation errors were detected:" );
// writer.write( NEWLINE );
//
// for ( Iterator it = error.getValidationResult().getMessages().iterator(); it.hasNext(); )
// {
// String message = (String) it.next();
// writer.write( NEWLINE );
// writer.write( " - " );
// writer.write( message );
// }
//
// writer.write( NEWLINE );
// writer.write( NEWLINE );
//
// result = true;
// }
if ( false )
{
InvalidProjectModelException error = (InvalidProjectModelException) e;
writer.write( error.getMessage() );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "The following POM validation errors were detected:" );
writer.write( NEWLINE );
for ( Iterator it = error.getValidationResult().getMessages().iterator(); it.hasNext(); )
{
String message = (String) it.next();
writer.write( NEWLINE );
writer.write( " - " );
writer.write( message );
}
writer.write( NEWLINE );
writer.write( NEWLINE );
result = true;
}
else if ( e instanceof InvalidDependencyVersionException )
{
writer.write( NEWLINE );
writer.write( "Your project declares a dependency with an invalid version." );
writer.write( NEWLINE );
writer.write( NEWLINE );
Dependency dep = ((InvalidDependencyVersionException)e).getDependency();
writer.write( "Dependency:" );
writer.write( NEWLINE );
writer.write( "Group-Id: " );
writer.write( dep.getGroupId() );
writer.write( NEWLINE );
writer.write( "Artifact-Id: " );
writer.write( dep.getArtifactId() );
writer.write( NEWLINE );
writer.write( "Version: " );
writer.write( dep.getVersion() );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Reason: " );
writer.write( cause.getMessage() );
writer.write( NEWLINE );
result = true;
}
// else if ( e instanceof InvalidDependencyVersionException )
// {
// writer.write( NEWLINE );
// writer.write( "Your project declares a dependency with an invalid version." );
// writer.write( NEWLINE );
// writer.write( NEWLINE );
//
// Dependency dep = ((InvalidDependencyVersionException)e).getDependency();
// writer.write( "Dependency:" );
// writer.write( NEWLINE );
// writer.write( "Group-Id: " );
// writer.write( dep.getGroupId() );
// writer.write( NEWLINE );
// writer.write( "Artifact-Id: " );
// writer.write( dep.getArtifactId() );
// writer.write( NEWLINE );
// writer.write( "Version: " );
// writer.write( dep.getVersion() );
// writer.write( NEWLINE );
// writer.write( NEWLINE );
//
// writer.write( "Reason: " );
// writer.write( cause.getMessage() );
// writer.write( NEWLINE );
//
// result = true;
// }
// InvalidDependencyVersionException extends from InvalidProjectVersionException, so it comes first.
else if ( e instanceof InvalidProjectVersionException )
{
writer.write( NEWLINE );
writer.write( "You have an invalid version in your POM:" );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Location: " );
writer.write( ((InvalidProjectVersionException)e).getLocationInPom() );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Reason: " );
writer.write( cause.getMessage() );
writer.write( NEWLINE );
result = true;
}
// else if ( e instanceof InvalidProjectVersionException )
// {
// writer.write( NEWLINE );
// writer.write( "You have an invalid version in your POM:" );
// writer.write( NEWLINE );
// writer.write( NEWLINE );
// writer.write( "Location: " );
// writer.write( ((InvalidProjectVersionException)e).getLocationInPom() );
// writer.write( NEWLINE );
// writer.write( NEWLINE );
// writer.write( "Reason: " );
// writer.write( cause.getMessage() );
// writer.write( NEWLINE );
//
// result = true;
// }
// now that we've sorted through all the sub-classes of ProjectBuildingException,
// let's look at causes of a basic PBE instance.
else if ( ( cause instanceof ArtifactNotFoundException )
@ -692,18 +689,19 @@ public final class CLIReportingUtils
result = true;
}
else if ( cause instanceof ProfileActivationException )
{
writer.write( NEWLINE );
writer.write( "Profile activation failed. One or more named profile activators may be missing." );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Reason: " );
writer.write( cause.getMessage() );
writer.write( NEWLINE );
result = true;
}
// handled by aspect binding to ProjectErrorReporter now.
// else if ( cause instanceof ProfileActivationException )
// {
// writer.write( NEWLINE );
// writer.write( "Profile activation failed. One or more named profile activators may be missing." );
// writer.write( NEWLINE );
// writer.write( NEWLINE );
// writer.write( "Reason: " );
// writer.write( cause.getMessage() );
// writer.write( NEWLINE );
//
// result = true;
// }
else if ( cause instanceof IOException )
{
writer.write( NEWLINE );
@ -745,22 +743,22 @@ public final class CLIReportingUtils
result = true;
}
else if ( cause instanceof InvalidRepositoryException )
{
writer.write( NEWLINE );
writer.write( "You have an invalid repository/pluginRepository declaration in your POM:" );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Repository-Id: " );
writer.write( ((InvalidRepositoryException)cause).getRepositoryId() );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Reason: " );
writer.write( cause.getMessage() );
writer.write( NEWLINE );
result = true;
}
// else if ( cause instanceof InvalidRepositoryException )
// {
// writer.write( NEWLINE );
// writer.write( "You have an invalid repository/pluginRepository declaration in your POM:" );
// writer.write( NEWLINE );
// writer.write( NEWLINE );
// writer.write( "Repository-Id: " );
// writer.write( ((InvalidRepositoryException)cause).getRepositoryId() );
// writer.write( NEWLINE );
// writer.write( NEWLINE );
// writer.write( "Reason: " );
// writer.write( cause.getMessage() );
// writer.write( NEWLINE );
//
// result = true;
// }
writer.write( NEWLINE );
writer.write( "Failing project's id: " );

View File

@ -1,272 +0,0 @@
package org.apache.maven.cli;
import org.apache.maven.AggregatedBuildFailureException;
import org.apache.maven.BuildFailureException;
import org.apache.maven.InvalidTaskException;
import org.apache.maven.NoGoalsSpecifiedException;
import org.apache.maven.ProjectBuildFailureException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.lifecycle.LifecycleLoaderException;
import org.apache.maven.lifecycle.TaskValidationResult;
import org.apache.maven.lifecycle.model.MojoBinding;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.InvalidProjectModelException;
import org.apache.maven.project.InvalidProjectVersionException;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.validation.ModelValidationResult;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import junit.framework.TestCase;
public class CLIReportingUtilsTest
extends TestCase
{
// =====================================================================
// Still left to test for ProjectBuildingException:
// =====================================================================
//
// ProjectBuildingException(String, String, File, XmlPullParserException)
//
// ProjectBuildingException(String, String, IOException)
// ProjectBuildingException(String, String, File, IOException)
//
// ProjectBuildingException(String, String, ArtifactNotFoundException)
// ProjectBuildingException(String, String, File, ArtifactNotFoundException)
//
// ProjectBuildingException(String, String, ArtifactResolutionException)
// ProjectBuildingException(String, String, File, ArtifactResolutionException)
//
// ProjectBuildingException(String, String, File, ProfileActivationException)
//
// ProjectBuildingException(String, String, InvalidRepositoryException)
// ProjectBuildingException(String, String, File, InvalidRepositoryException)
public void test_handleProjectBuildingException_ShowReasonableMessageForInvalidProjectModel()
{
String validationMessage = "dependencies.dependency.version is required";
ModelValidationResult results = new ModelValidationResult();
results.addMessage( validationMessage );
String projectId = "test:project";
File projectPath = new File( "/path/to/somewhere" );
String message = "message";
InvalidProjectModelException e = new InvalidProjectModelException( projectId, message,
projectPath, results );
StringWriter writer = new StringWriter();
CLIReportingUtils.buildErrorMessage( e, false, writer );
toConsole( writer );
String[] contentLines = writer.toString().split( "\r?\n" );
assertPresent( projectId, contentLines );
assertPresent( projectPath.getPath(), contentLines );
assertPresent( message, contentLines );
assertPresent( validationMessage, contentLines );
}
public void test_handleProjectBuildingException_ShowLocationInfoForInvalidDependencyVersionException()
throws IOException
{
String version = "[1.0";
InvalidVersionSpecificationException cause = null;
try
{
VersionRange.createFromVersionSpec( version );
fail( "Version should be invalid." );
}
catch ( InvalidVersionSpecificationException versionException )
{
cause = versionException;
}
Dependency dep = new Dependency();
dep.setGroupId( "org.group" );
dep.setArtifactId( "dep-artifact" );
dep.setVersion( version );
File pomFile = File.createTempFile( "CLIReportingUtils.test.", "" );
pomFile.deleteOnExit();
String projectId = "org.group.id:some-artifact:1";
InvalidDependencyVersionException e = new InvalidDependencyVersionException( projectId,
dep, pomFile,
cause );
StringWriter writer = new StringWriter();
CLIReportingUtils.buildErrorMessage( e, false, writer );
toConsole( writer );
String[] contentLines = writer.toString().split( "\r?\n" );
assertPresent( projectId, contentLines );
assertPresent( "Group-Id: " + dep.getGroupId(), contentLines );
assertPresent( "Artifact-Id: " + dep.getArtifactId(), contentLines );
assertPresent( version, contentLines );
}
public void test_handleProjectBuildingException_ShowLocationInfoForInvalidProjectVersionException()
throws IOException
{
String version = "[1.0";
InvalidVersionSpecificationException cause = null;
try
{
VersionRange.createFromVersionSpec( version );
fail( "Version should be invalid." );
}
catch ( InvalidVersionSpecificationException versionException )
{
cause = versionException;
}
File pomFile = File.createTempFile( "CLIReportingUtils.test.", "" );
pomFile.deleteOnExit();
String projectId = "org.group.id:some-artifact:1";
String extLocation = "extension: org.group:extension-artifact";
InvalidProjectVersionException e = new InvalidProjectVersionException( projectId,
extLocation,
version, pomFile,
cause );
StringWriter writer = new StringWriter();
CLIReportingUtils.buildErrorMessage( e, false, writer );
toConsole( writer );
String[] contentLines = writer.toString().split( "\r?\n" );
assertPresent( projectId, contentLines );
assertPresent( extLocation, contentLines );
assertPresent( version, contentLines );
}
// =====================================================================
// Still left to test for BuildFailureException:
// =====================================================================
// ProjectCycleException(List, String, CycleDetectedException)
public void test_handleBuildFailureException_ShowAdviceMessageForNoGoalsSpecifiedException()
{
NoGoalsSpecifiedException e = new NoGoalsSpecifiedException( "No goals were specified." );
StringWriter writer = new StringWriter();
CLIReportingUtils.buildErrorMessage( e, false, writer );
toConsole( writer );
String[] contentLines = writer.toString().split( "\r?\n" );
assertPresent( "http://maven.apache.org/users/", contentLines );
assertPresent( "http://maven.apache.org/plugins/", contentLines );
}
public void test_handleBuildFailureException_ShowAdviceMessageForInvalidTaskException()
{
Plugin plugin = new Plugin();
plugin.setGroupId( "org.apache.maven.plugins" );
plugin.setArtifactId( "maven-something-plugin" );
plugin.setVersion( "[1.0" );
TaskValidationResult tvr = new TaskValidationResult(
"something-dumb",
"test message.",
new LifecycleLoaderException(
"No such lifecycle phase: something-dumb" ) );
InvalidTaskException e = tvr.generateInvalidTaskException();
StringWriter writer = new StringWriter();
CLIReportingUtils.buildErrorMessage( e, false, writer );
toConsole( writer );
String[] contentLines = writer.toString().split( "\r?\n" );
assertPresent( "test message", contentLines );
assertPresent( "something-dumb", contentLines );
assertPresent( "No such lifecycle phase: something-dumb", contentLines );
}
public void test_handleBuildFailureException_ShowLongMessageForMojoFailureException()
{
String longMessage = "This is a longer message.";
MojoFailureException e = new MojoFailureException( "test-id", "Short Message", longMessage );
MojoBinding binding = new MojoBinding();
binding.setGroupId( "plugin.group" );
binding.setArtifactId( "plugin-artifact" );
binding.setVersion( "10" );
BuildFailureException buildError = new ProjectBuildFailureException( "test:project:1",
binding, e );
StringWriter writer = new StringWriter();
CLIReportingUtils.buildErrorMessage( buildError, false, writer );
toConsole( writer );
String[] contentLines = writer.toString().split( "\r?\n" );
assertPresent( longMessage, contentLines );
}
public void test_handleBuildFailureException_ShowLongMessageForAggregatedMojoFailureException()
{
String longMessage = "This is a longer message.";
MojoFailureException e = new MojoFailureException( "test-id", "Short Message", longMessage );
MojoBinding binding = new MojoBinding();
binding.setGroupId( "plugin.group" );
binding.setArtifactId( "plugin-artifact" );
binding.setVersion( "10" );
BuildFailureException buildError = new AggregatedBuildFailureException(
"/path/to/project/dir",
binding, e );
StringWriter writer = new StringWriter();
CLIReportingUtils.buildErrorMessage( buildError, false, writer );
toConsole( writer );
String[] contentLines = writer.toString().split( "\r?\n" );
assertPresent( longMessage, contentLines );
}
private void assertPresent( String message,
String[] contentLines )
{
for ( int i = 0; i < contentLines.length; i++ )
{
if ( contentLines[i].indexOf( message ) > -1 )
{
return;
}
}
fail( "Message not found in output: \'" + message + "\'" );
}
private void toConsole( StringWriter writer )
{
System.out.println( new Throwable().getStackTrace()[1].getMethodName() + ":" );
System.out.println( "==========================" );
System.out.println( writer.toString() );
System.out.println( "==========================" );
System.out.println( "\n\n" );
}
}

View File

@ -0,0 +1,255 @@
package org.apache.maven.project.aspect;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.InvalidProjectVersionException;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
import org.apache.maven.model.Model;
import org.apache.maven.model.Repository;
import org.apache.maven.model.DeploymentRepository;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.MavenTools;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.DefaultMavenProjectBuilder;
import org.apache.maven.project.InvalidProjectModelException;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.error.DefaultProjectErrorReporter;
import org.apache.maven.project.error.ProjectErrorReporter;
import java.io.File;
import java.util.Set;
public privileged aspect PBEDerivativeReporterAspect
{
private ProjectErrorReporter reporter;
public void setProjectErrorReporter( ProjectErrorReporter reporter )
{
this.reporter = reporter;
}
private ProjectErrorReporter getReporter()
{
if ( reporter == null )
{
reporter = new DefaultProjectErrorReporter();
}
return reporter;
}
// UnknownRepositoryLayoutException
private pointcut mavenTools_buildDeploymentArtifactRepository( DeploymentRepository repo ):
call( ArtifactRepository MavenTools+.buildDeploymentArtifactRepository( DeploymentRepository ) )
&& args( repo );
private pointcut pbldr_processProjectLogic( MavenProject project, File pomFile ):
execution( private MavenProject DefaultMavenProjectBuilder.processProjectLogic( MavenProject, File, .. ) )
&& args( project, pomFile, .. );
// =========================================================================
// Call Stack:
// =========================================================================
// ...
// --> DefaultMavenProjectBuilder.buildFromRepository(..)
// DefaultMavenProjectBuilder.build(..)
// --> DefaultMavenProjectBuilder.buildFromSourceFileInternal(..) (private)
// --> DefaultMavenProjectBuilder.buildInternal(..) (private)
// --> DefaultMavenProjectBuilder.processProjectLogic(..) (private)
// --> DefaultMavenTools.buildDeploymentArtifactRepository(..)
// <-- UnknownRepositoryLayoutException
// <---------- ProjectBuildingException
// =========================================================================
after( MavenProject project, File pomFile, DeploymentRepository repo ) throwing( UnknownRepositoryLayoutException cause ):
mavenTools_buildDeploymentArtifactRepository( repo ) &&
cflow( pbldr_processProjectLogic( project, pomFile ) )
{
getReporter().reportErrorCreatingDeploymentArtifactRepository( project, pomFile, repo, cause );
}
private pointcut mavenTools_buildArtifactRepository( Repository repo ):
call( ArtifactRepository MavenTools+.buildArtifactRepository( Repository ) )
&& args( repo );
private boolean processingPluginRepositories = false;
// =========================================================================
// Call Stack:
// =========================================================================
// ...
// --> DefaultMavenProjectBuilder.buildFromRepository(..)
// DefaultMavenProjectBuilder.build(..)
// --> DefaultMavenProjectBuilder.buildFromSourceFileInternal(..) (private)
// --> DefaultMavenProjectBuilder.buildInternal(..) (private)
// --> DefaultMavenProjectBuilder.processProjectLogic(..) (private)
// --> DefaultMavenTools.buildArtifactRepositories(..)
// --> DefaultMavenTools.buildArtifactRepository(..)
// <------ UnknownRepositoryLayoutException
// <---------- ProjectBuildingException
// =========================================================================
after( MavenProject project, File pomFile, Repository repo ) throwing( UnknownRepositoryLayoutException cause ):
mavenTools_buildArtifactRepository( repo ) && cflow( pbldr_processProjectLogic( project, pomFile ) )
{
getReporter().reportErrorCreatingArtifactRepository( project, pomFile, repo, cause, processingPluginRepositories );
}
after():
call( * Model+.getPluginRepositories() )
{
processingPluginRepositories = true;
}
after():
call( * Model+.getRepositories() )
{
processingPluginRepositories = false;
}
after( MavenProject project, File pomFile ): pbldr_processProjectLogic( project, pomFile )
{
processingPluginRepositories = false;
}
// ModelInterpolationException
// =========================================================================
// Call Stack:
// =========================================================================
// ...
// --> DefaultMavenProjectBuilder.buildFromRepository(..)
// DefaultMavenProjectBuilder.build(..)
// --> DefaultMavenProjectBuilder.buildFromSourceFileInternal(..) (private)
// --> DefaultMavenProjectBuilder.buildInternal(..) (private)
// --> DefaultMavenProjectBuilder.processProjectLogic(..) (private)
// --> ModelInterpolator.interpolate(..)
// <-- ModelInterpolationException
// <---------- ProjectBuildingException
// =========================================================================
after( MavenProject project, File pomFile ) throwing( ModelInterpolationException cause ):
pbldr_processProjectLogic( project, pomFile )
{
getReporter().reportErrorInterpolatingModel( project, pomFile, cause );
}
// InvalidProjectVersionException
private pointcut pbldr_createNonDependencyArtifacts():
call( protected * DefaultMavenProjectBuilder.createPluginArtifacts( .. ) )
|| call( protected * DefaultMavenProjectBuilder.createReportArtifacts( .. ) )
|| call( protected * DefaultMavenProjectBuilder.createExtensionArtifacts( .. ) );
// =========================================================================
// Call Stack:
// =========================================================================
// ...
// --> DefaultMavenProjectBuilder.buildFromRepository(..)
// DefaultMavenProjectBuilder.build(..)
// --> DefaultMavenProjectBuilder.buildFromSourceFileInternal(..) (private)
// --> DefaultMavenProjectBuilder.buildInternal(..) (private)
// --> DefaultMavenProjectBuilder.processProjectLogic(..) (private)
// --> DefaultMavenProjectBuilder.createPluginArtifacts(..)
// --> DefaultMavenProjectBuilder.createReportArtifacts(..)
// --> DefaultMavenProjectBuilder.createExtensionArtifacts(..)
// <-- InvalidProjectVersionException
// <---------- ProjectBuildingException
// =========================================================================
after( MavenProject project, File pomFile ) throwing( ProjectBuildingException cause ):
cflow( pbldr_processProjectLogic( project, pomFile ) )
&& pbldr_createNonDependencyArtifacts()
{
if ( cause instanceof InvalidProjectVersionException )
{
getReporter().reportBadNonDependencyProjectArtifactVersion( project, pomFile, (InvalidProjectVersionException) cause );
}
}
// =========================================================================
// Call Stack:
// =========================================================================
// ...
// --> DefaultMavenProjectBuilder.buildFromRepository(..)
// DefaultMavenProjectBuilder.build(..)
// --> DefaultMavenProjectBuilder.buildFromSourceFileInternal(..) (private)
// --> DefaultMavenProjectBuilder.buildInternal(..) (private)
// --> DefaultMavenProjectBuilder.processProjectLogic(..) (private)
// --> (model validator result)
// <-- InvalidProjectModelException
// <------ ProjectBuildingException
// =========================================================================
after( MavenProject project, File pomFile ) throwing( InvalidProjectModelException cause ):
cflow( pbldr_processProjectLogic( project, pomFile ) )
&& execution( void DefaultMavenProjectBuilder.validateModel( .. ) )
{
getReporter().reportProjectValidationFailure( project, pomFile, cause );
}
// InvalidDependencyVersionException
private pointcut pbldr_buildInternal():
execution( * DefaultMavenProjectBuilder.buildInternal( .. ) );
private MavenProject projectBeingBuilt;
after( MavenProject project ):
cflow( pbldr_buildInternal() )
&& !cflowbelow( pbldr_buildInternal() )
&& call( DependencyManagement MavenProject.getDependencyManagement() )
&& target( project )
{
projectBeingBuilt = project;
}
after(): pbldr_buildInternal()
{
projectBeingBuilt = null;
}
// =========================================================================
// Call Stack:
// =========================================================================
// ...
// --> DefaultMavenProjectBuilder.buildFromRepository(..)
// DefaultMavenProjectBuilder.build(..)
// --> DefaultMavenProjectBuilder.buildFromSourceFileInternal(..) (private)
// --> DefaultMavenProjectBuilder.buildInternal(..) (private)
// --> DefaultMavenProjectBuilder.createManagedVersionMap(..) (private)
// <-- InvalidDependencyVersionException
// <------ ProjectBuildingException
// =========================================================================
after( File pomFile ) throwing( ProjectBuildingException cause ):
cflow( pbldr_buildInternal() )
&& execution( * DefaultMavenProjectBuilder.createManagedVersionMap( .., File ) )
&& args( .., pomFile )
{
if ( cause instanceof InvalidDependencyVersionException )
{
getReporter().reportBadManagedDependencyVersion( projectBeingBuilt, pomFile, (InvalidDependencyVersionException) cause );
}
}
protected pointcut mms_createArtifacts( MavenProject project ):
call( public static Set MavenMetadataSource.createArtifacts( .., MavenProject ) )
&& args( .., project );
// =========================================================================
// Call Stack:
// =========================================================================
// ...
// --> MavenProject.createArtifacts(..)
// --> MavenMetadataSource.createArtifacts(..)
// <-- InvalidDependencyVersionException
// <-- ProjectBuildingException
// =========================================================================
after( MavenProject project ) throwing( InvalidDependencyVersionException cause ):
cflow( execution( * MavenProject.createArtifacts( .. ) ) )
&& mms_createArtifacts( project )
{
getReporter().reportBadDependencyVersion( project, project.getFile(), cause );
}
}

View File

@ -0,0 +1,255 @@
package org.apache.maven.project.aspect;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.error.DefaultProjectErrorReporter;
import org.apache.maven.project.error.ProjectErrorReporter;
import org.apache.maven.profiles.activation.ProfileActivator;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.model.Model;
import org.apache.maven.model.Repository;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.profiles.build.DefaultProfileAdvisor;
import org.apache.maven.model.Profile;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.MavenProfilesBuilder;
import org.apache.maven.profiles.ProfilesRoot;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.MavenTools;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.codehaus.plexus.PlexusContainer;
import java.util.List;
import java.util.LinkedHashSet;
import java.io.File;
import java.io.IOException;
/**
* Error reporting advice to handle {@link ProjectBuildingException} instances
* coming from {@link DefaultProfileAdvisor}.
*/
public privileged aspect ProfileErrorReporterAspect
{
private ProjectErrorReporter reporter;
public void setProjectErrorReporter( ProjectErrorReporter reporter )
{
this.reporter = reporter;
}
private ProjectErrorReporter getReporter()
{
if ( reporter == null )
{
reporter = new DefaultProjectErrorReporter();
}
return reporter;
}
protected pointcut componentLookupException( ComponentLookupException cause ):
handler( ComponentLookupException )
&& args( cause );
private pointcut pMgr_isActiveExec( Profile profile, ProfileActivationContext context ):
execution( boolean DefaultProfileManager.isActive( Profile, ProfileActivationContext ) )
&& args( profile, context );
private pointcut pAdv_applyActivatedProfiles( Model model, File pomFile ):
execution( private List DefaultProfileAdvisor.applyActivatedProfiles( Model, File, .. ) )
&& args( model, pomFile, .. );
private pointcut applyActivatedProfiles_ComponentLookupException( Model model,
File pomFile,
Profile profile ):
call( List PlexusContainer+.lookupList( .. ) )
&& cflow( pAdv_applyActivatedProfiles( model, pomFile ) )
&& cflow( pMgr_isActiveExec( profile, ProfileActivationContext ) );
// =========================================================================
// Call Stack:
// =========================================================================
// DefaultProfileAdvisor.applyActivatedProfiles(..)
// DefaultProfileAdvisor.applyActivatedExternalProfiles(..)
// --> DefaultProfileAdvisor.applyActivatedProfiles(..) (private)
// --> DefaultProfileManager.getActiveProfiles(..)
// --> DefaultProfileManager.isActive(..) (private)
// --> PlexusContainer.lookupList(..)
// <-- ComponentLookupException
// <-- ProfileActivationException
// <------ ProjectBuildingException
// =========================================================================
after( Model model, File pomFile, Profile profile )
throwing( ComponentLookupException cause ):
applyActivatedProfiles_ComponentLookupException( model, pomFile, profile )
{
getReporter().reportActivatorLookupErrorWhileApplyingProfiles( model, pomFile, profile, cause );
}
protected pointcut profileActivatorCall( ProfileActivator activator ):
call( * ProfileActivator+.*( .. ) )
&& target( activator );
private pointcut applyActivatedProfiles_ActivatorThrown( ProfileActivator activator,
Model model,
File pomFile,
Profile profile,
ProfileActivationContext context ):
profileActivatorCall( activator )
&& cflow( pAdv_applyActivatedProfiles( model, pomFile ) )
&& cflow( pMgr_isActiveExec( profile, context ) );
// =========================================================================
// Call Stack:
// =========================================================================
// DefaultProfileAdvisor.applyActivatedProfiles(..)
// DefaultProfileAdvisor.applyActivatedExternalProfiles(..)
// --> DefaultProfileAdvisor.applyActivatedProfiles(..) (private)
// --> DefaultProfileManager.getActiveProfiles(..)
// --> DefaultProfileManager.isActive(..) (private)
// --> ProfileActivator.canDetermineActivation(..)
// --> ProfileActivator.isActive(..)
// <------ ProfileActivationException
// <------ ProjectBuildingException
// =========================================================================
after( ProfileActivator activator, Model model, File pomFile, Profile profile, ProfileActivationContext context )
throwing( ProfileActivationException cause ):
applyActivatedProfiles_ActivatorThrown( activator, model, pomFile, profile, context )
{
getReporter().reportActivatorErrorWhileApplyingProfiles( activator, model, pomFile, profile, context, cause );
}
private pointcut pAdv_loadExternalProjectProfiles( Model model, File pomFile ):
execution( private void DefaultProfileAdvisor.loadExternalProjectProfiles( *, Model, File ) )
&& args( *, model, pomFile );
private pointcut loadExternalProfiles_profileBuilding( Model model,
File pomFile,
File projectDir ):
call( ProfilesRoot MavenProfilesBuilder+.buildProfiles( File ) )
&& cflow( pAdv_loadExternalProjectProfiles( model, pomFile ) )
&& args( projectDir );
// =========================================================================
// Call Stack:
// =========================================================================
// DefaultProfileAdvisor.applyActivatedProfiles(..)
// DefaultProfileAdvisor.getArtifactRepositoriesFromActiveProfiles(..)
// --> DefaultProfileAdvisor.buildProfileManager(..) (private)
// --> DefaultProfileAdvisor.loadExternalProjectProfiles(..) (private)
// --> MavenProfilesBuilder.buildProfiles(..)
// <-- IOException
// <------ ProjectBuildingException
// =========================================================================
after( Model model, File pomFile, File projectDir )
throwing( IOException cause ):
loadExternalProfiles_profileBuilding( model, pomFile, projectDir )
{
getReporter().reportErrorLoadingExternalProfilesFromFile( model, pomFile, projectDir, cause );
}
// =========================================================================
// Call Stack:
// =========================================================================
// DefaultProfileAdvisor.applyActivatedProfiles(..)
// DefaultProfileAdvisor.getArtifactRepositoriesFromActiveProfiles(..)
// --> DefaultProfileAdvisor.buildProfileManager(..) (private)
// --> DefaultProfileAdvisor.loadExternalProjectProfiles(..) (private)
// --> MavenProfilesBuilder.buildProfiles(..)
// <-- XmlPullParserException
// <------ ProjectBuildingException
// =========================================================================
after( Model model, File pomFile, File projectDir )
throwing( XmlPullParserException cause ):
loadExternalProfiles_profileBuilding( model, pomFile, projectDir )
{
getReporter().reportErrorLoadingExternalProfilesFromFile( model, pomFile, projectDir, cause );
}
private pointcut pAdv_getArtifactRepositoriesFromActiveProfiles( String projectId, File pomFile ):
execution( LinkedHashSet DefaultProfileAdvisor.getArtifactRepositoriesFromActiveProfiles( *, File, String ) )
&& args( *, pomFile, projectId );
private pointcut getArtifactRepositoriesFromActiveProfiles_ComponentLookupException( String projectId,
File pomFile,
Profile profile ):
call( List PlexusContainer+.lookupList( .. ) )
&& cflow( pAdv_getArtifactRepositoriesFromActiveProfiles( projectId, pomFile ) )
&& cflow( pMgr_isActiveExec( profile, ProfileActivationContext ) );
// =========================================================================
// Call Stack:
// =========================================================================
// DefaultProfileAdvisor.applyActivatedProfiles(..)
// DefaultProfileAdvisor.applyActivatedExternalProfiles(..)
// --> DefaultProfileAdvisor.getArtifactRepositoriesFromActiveProfiles(..)
// --> DefaultProfileManager.getActiveProfiles(..)
// --> DefaultProfileManager.isActive(..) (private)
// --> PlexusContainer.lookupList(..)
// <-- ComponentLookupException
// <-- ProfileActivationException
// <------ ProjectBuildingException
// =========================================================================
after( String projectId, File pomFile, Profile profile )
throwing( ComponentLookupException cause ):
getArtifactRepositoriesFromActiveProfiles_ComponentLookupException( projectId, pomFile, profile )
{
getReporter().reportActivatorLookupErrorWhileGettingRepositoriesFromProfiles( projectId, pomFile, profile, cause );
}
private pointcut getArtifactRepositoriesFromActiveProfiles_ActivatorThrown( ProfileActivator activator,
String projectId,
File pomFile,
Profile profile,
ProfileActivationContext context ):
profileActivatorCall( activator )
&& cflow( pAdv_getArtifactRepositoriesFromActiveProfiles( projectId, pomFile ) )
&& cflow( pMgr_isActiveExec( profile, context ) );
// =========================================================================
// Call Stack:
// =========================================================================
// DefaultProfileAdvisor.applyActivatedProfiles(..)
// DefaultProfileAdvisor.applyActivatedExternalProfiles(..)
// --> DefaultProfileAdvisor.getArtifactRepositoriesFromActiveProfiles(..)
// --> DefaultProfileManager.getActiveProfiles(..)
// --> DefaultProfileManager.isActive(..) (private)
// --> ProfileActivator.canDetermineActivation(..)
// --> ProfileActivator.isActive(..)
// <------ ProfileActivationException
// <------ ProjectBuildingException
// =========================================================================
after( ProfileActivator activator, String projectId, File pomFile, Profile profile, ProfileActivationContext context )
throwing( ProfileActivationException cause ):
getArtifactRepositoriesFromActiveProfiles_ActivatorThrown( activator, projectId, pomFile, profile, context )
{
getReporter().reportActivatorErrorWhileGettingRepositoriesFromProfiles( activator, projectId, pomFile, profile, context, cause );
}
private pointcut getArtifactRepositoriesFromActiveProfiles_InvalidRepository( Repository repo,
String projectId,
File pomFile ):
call( ArtifactRepository MavenTools+.buildArtifactRepository( Repository ) )
&& args( repo )
&& cflow( pAdv_getArtifactRepositoriesFromActiveProfiles( projectId, pomFile ) );
// =========================================================================
// Call Stack:
// =========================================================================
// DefaultProfileAdvisor.applyActivatedProfiles(..)
// DefaultProfileAdvisor.applyActivatedExternalProfiles(..)
// --> DefaultProfileAdvisor.getArtifactRepositoriesFromActiveProfiles(..)
// --> MavenTools.buildArtifactRepository(..)
// <-- InvalidRepositoryException
// <-- ProjectBuildingException
// =========================================================================
after( Repository repo, String projectId, File pomFile )
throwing( InvalidRepositoryException cause ):
getArtifactRepositoriesFromActiveProfiles_InvalidRepository( repo, projectId, pomFile )
{
getReporter().reportInvalidRepositoryWhileGettingRepositoriesFromProfiles( repo, projectId, pomFile, cause );
}
}

View File

@ -19,7 +19,7 @@ import java.util.Map;
public privileged aspect ProjectCacheAspect
{
private Map DefaultMavenProjectBuilder.projectCache = new HashMap();
private Map<Object, MavenProject> DefaultMavenProjectBuilder.projectCache = new HashMap<Object, MavenProject>();
public void DefaultMavenProjectBuilder.clearProjectCache()
{
@ -159,7 +159,7 @@ public privileged aspect ProjectCacheAspect
return groupId + ":" + artifactId + ":" + version;
}
private Map DefaultModelLineageBuilder.modelAndFileCache = new HashMap();
private Map<Object, ModelAndFile> DefaultModelLineageBuilder.modelAndFileCache = new HashMap<Object, ModelAndFile>();
public void DefaultModelLineageBuilder.clearModelAndFileCache()
{

View File

@ -864,6 +864,27 @@ public class DefaultMavenProjectBuilder
project.setParentArtifact( parentArtifact );
}
validateModel( model, pomFile );
project.setRemoteArtifactRepositories(
mavenTools.buildArtifactRepositories( model.getRepositories() ) );
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
// TODO: these aren't taking active project artifacts into consideration in the reactor
project.setPluginArtifacts( createPluginArtifacts( projectId, project.getBuildPlugins(), pomFile ) );
project.setReportArtifacts( createReportArtifacts( projectId, project.getReportPlugins(), pomFile ) );
project.setExtensionArtifacts( createExtensionArtifacts( projectId, project.getBuildExtensions(), pomFile ) );
return project;
}
private void validateModel( Model model,
File pomFile )
throws InvalidProjectModelException
{
// Must validate before artifact construction to make sure dependencies are good
ModelValidationResult validationResult = validator.validate( model );
@ -874,18 +895,6 @@ public class DefaultMavenProjectBuilder
throw new InvalidProjectModelException( projectId, "Failed to validate POM", pomFile,
validationResult );
}
project.setRemoteArtifactRepositories(
mavenTools.buildArtifactRepositories( model.getRepositories() ) );
// TODO: these aren't taking active project artifacts into consideration in the reactor
project.setPluginArtifacts( createPluginArtifacts( projectId, project.getBuildPlugins(), pomFile ) );
project.setReportArtifacts( createReportArtifacts( projectId, project.getReportPlugins(), pomFile ) );
project.setExtensionArtifacts( createExtensionArtifacts( projectId, project.getBuildExtensions(), pomFile ) );
return project;
}
/**
@ -1083,9 +1092,7 @@ public class DefaultMavenProjectBuilder
}
catch ( InvalidVersionSpecificationException e )
{
throw new ProjectBuildingException( projectId, "Unable to parse version '" + version +
"' for plugin '" + ArtifactUtils.versionlessKey( p.getGroupId(), p.getArtifactId() ) + "': " +
e.getMessage(), pomLocation, e );
throw new InvalidProjectVersionException( projectId, "Plugin: " + p.getKey(), version, pomLocation, e );
}
if ( artifact != null )
@ -1144,9 +1151,7 @@ public class DefaultMavenProjectBuilder
}
catch ( InvalidVersionSpecificationException e )
{
throw new ProjectBuildingException( projectId, "Unable to parse version '" + version +
"' for report '" + ArtifactUtils.versionlessKey( p.getGroupId(), p.getArtifactId() ) + "': " +
e.getMessage(), pomLocation, e );
throw new InvalidProjectVersionException( projectId, "Report plugin: " + p.getKey(), version, pomLocation, e );
}
if ( artifact != null )
@ -1208,7 +1213,7 @@ public class DefaultMavenProjectBuilder
catch ( InvalidVersionSpecificationException e )
{
String key = ArtifactUtils.versionlessKey( ext.getGroupId(), ext.getArtifactId() );
throw new InvalidProjectVersionException( projectId, "extension '" + key,
throw new InvalidProjectVersionException( projectId, "Extension: " + key,
version, pomFile, e );
}

View File

@ -45,7 +45,7 @@ public class InvalidDependencyVersionException
private static String formatLocationInPom( Dependency dependency )
{
return "dependency: " + ArtifactUtils.versionlessKey( dependency.getGroupId(), dependency.getArtifactId() );
return "Dependency: " + ArtifactUtils.versionlessKey( dependency.getGroupId(), dependency.getArtifactId() );
}
public Dependency getDependency()

View File

@ -0,0 +1,560 @@
package org.apache.maven.project.error;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DeploymentRepository;
import org.apache.maven.model.Model;
import org.apache.maven.model.Profile;
import org.apache.maven.model.Repository;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.profiles.activation.ProfileActivator;
import org.apache.maven.project.InvalidProjectModelException;
import org.apache.maven.project.InvalidProjectVersionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class DefaultProjectErrorReporter
implements ProjectErrorReporter
{
private Map<Throwable, String> formattedMessages = new HashMap<Throwable, String>();
private Map<Throwable, Throwable> realCauses = new HashMap<Throwable, Throwable>();
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#clearErrors()
*/
public void clearErrors()
{
formattedMessages.clear();
realCauses.clear();
}
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#hasInformationFor(java.lang.Throwable)
*/
public Throwable findReportedException( Throwable error )
{
if ( formattedMessages.containsKey( error ) )
{
return error;
}
else if ( error.getCause() != null )
{
return findReportedException( error.getCause() );
}
return null;
}
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#getFormattedMessage(java.lang.Throwable)
*/
public String getFormattedMessage( Throwable error )
{
return formattedMessages.get( error );
}
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#getRealCause(java.lang.Throwable)
*/
public Throwable getRealCause( Throwable error )
{
return realCauses.get( error );
}
private void registerProjectBuildError( Throwable error,
String formattedMessage,
Throwable realCause )
{
formattedMessages.put( error, formattedMessage );
realCauses.put( error, realCause );
}
private void registerProjectBuildError( Throwable error,
String formattedMessage )
{
formattedMessages.put( error, formattedMessage );
}
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#reportActivatorErrorWhileApplyingProfiles(org.apache.maven.profiles.activation.ProfileActivator, org.apache.maven.model.Model, java.io.File, org.apache.maven.model.Profile, org.apache.maven.profiles.activation.ProfileActivationContext, org.apache.maven.profiles.activation.ProfileActivationException)
*/
public void reportActivatorErrorWhileApplyingProfiles( ProfileActivator activator,
Model model,
File pomFile,
Profile profile,
ProfileActivationContext context,
ProfileActivationException cause )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "Profile activator: " );
writer.write( activator.getClass().getName() );
writer.write( " experienced an error while processing profile:" );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( profile.getId() );
writer.write( " (source: " );
writer.write( profile.getSource() );
writer.write( ")" );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Error message: " );
writer.write( NEWLINE );
writer.write( cause.getMessage() );
addStandardInfo( model.getId(), pomFile, writer );
addTips( ProjectErrorTips.getTipsForActivatorErrorWhileApplyingProfiles( activator,
model,
pomFile,
profile,
context,
cause ), writer );
registerProjectBuildError( cause, writer.toString(), cause.getCause() );
}
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#reportActivatorErrorWhileGettingRepositoriesFromProfiles(org.apache.maven.profiles.activation.ProfileActivator, java.lang.String, java.io.File, org.apache.maven.model.Profile, org.apache.maven.profiles.activation.ProfileActivationContext, org.apache.maven.profiles.activation.ProfileActivationException)
*/
public void reportActivatorErrorWhileGettingRepositoriesFromProfiles( ProfileActivator activator,
String projectId,
File pomFile,
Profile profile,
ProfileActivationContext context,
ProfileActivationException cause )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "Profile activator: " );
writer.write( activator.getClass().getName() );
writer.write( " experienced an error while processing profile:" );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( profile.getId() );
writer.write( " (source: " );
writer.write( profile.getSource() );
writer.write( ")" );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Error message: " );
writer.write( NEWLINE );
writer.write( cause.getMessage() );
addStandardInfo( projectId, pomFile, writer );
addTips( ProjectErrorTips.getTipsForActivatorErrorWhileGettingRepositoriesFromProfiles( activator,
projectId,
pomFile,
profile,
context,
cause ),
writer );
registerProjectBuildError( cause, writer.toString(), cause.getCause() );
}
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#reportActivatorLookupErrorWhileApplyingProfiles(org.apache.maven.model.Model, java.io.File, org.apache.maven.model.Profile, org.codehaus.plexus.component.repository.exception.ComponentLookupException)
*/
public void reportActivatorLookupErrorWhileApplyingProfiles( Model model,
File pomFile,
Profile profile,
ComponentLookupException cause )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "Error retrieving profile-activator component while processing profile:" );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( profile.getId() );
writer.write( " (source: " );
writer.write( profile.getSource() );
writer.write( ")" );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Error message: " );
writer.write( NEWLINE );
writer.write( cause.getMessage() );
addStandardInfo( model.getId(), pomFile, writer );
addTips( ProjectErrorTips.getTipsForActivatorLookupErrorWhileApplyingProfiles( model,
pomFile,
profile,
cause ),
writer );
registerProjectBuildError( cause, writer.toString(), cause.getCause() );
}
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#reportActivatorLookupErrorWhileGettingRepositoriesFromProfiles(java.lang.String, java.io.File, org.apache.maven.model.Profile, org.codehaus.plexus.component.repository.exception.ComponentLookupException)
*/
public void reportActivatorLookupErrorWhileGettingRepositoriesFromProfiles( String projectId,
File pomFile,
Profile profile,
ComponentLookupException cause )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "Error retrieving profile-activator component while processing profile:" );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( profile.getId() );
writer.write( " (source: " );
writer.write( profile.getSource() );
writer.write( ")" );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Error message: " );
writer.write( NEWLINE );
writer.write( cause.getMessage() );
addStandardInfo( projectId, pomFile, writer );
addTips( ProjectErrorTips.getTipsForActivatorLookupErrorWhileGettingRepositoriesFromProfiles( projectId,
pomFile,
profile,
cause ),
writer );
registerProjectBuildError( cause, writer.toString(), cause.getCause() );
}
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#reportErrorLoadingExternalProfilesFromFile(org.apache.maven.model.Model, java.io.File, java.io.File, java.io.IOException)
*/
public void reportErrorLoadingExternalProfilesFromFile( Model model,
File pomFile,
File projectDir,
IOException cause )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "Failed to load external profiles from project directory: " );
writer.write( NEWLINE );
writer.write( String.valueOf( projectDir ) );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Error message: " );
writer.write( NEWLINE );
writer.write( cause.getMessage() );
addStandardInfo( model.getId(), pomFile, writer );
addTips( ProjectErrorTips.getTipsForErrorLoadingExternalProfilesFromFile( model,
pomFile,
projectDir,
cause ), writer );
registerProjectBuildError( cause, writer.toString(), cause.getCause() );
}
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#reportErrorLoadingExternalProfilesFromFile(org.apache.maven.model.Model, java.io.File, java.io.File, org.codehaus.plexus.util.xml.pull.XmlPullParserException)
*/
public void reportErrorLoadingExternalProfilesFromFile( Model model,
File pomFile,
File projectDir,
XmlPullParserException cause )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "Failed to load external profiles from project directory: " );
writer.write( NEWLINE );
writer.write( String.valueOf( projectDir ) );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Error message: " );
writer.write( NEWLINE );
writer.write( cause.getMessage() );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Line: " );
writer.write( cause.getLineNumber() );
writer.write( NEWLINE );
writer.write( "Column: " );
writer.write( cause.getColumnNumber() );
addStandardInfo( model.getId(), pomFile, writer );
addTips( ProjectErrorTips.getTipsForErrorLoadingExternalProfilesFromFile( model,
pomFile,
projectDir,
cause ), writer );
registerProjectBuildError( cause, writer.toString(), cause.getCause() );
}
/**
* @see org.apache.maven.project.error.ProjectErrorReporter#reportInvalidRepositoryWhileGettingRepositoriesFromProfiles(org.apache.maven.model.Repository, java.lang.String, java.io.File, org.apache.maven.artifact.InvalidRepositoryException)
*/
public void reportInvalidRepositoryWhileGettingRepositoriesFromProfiles( Repository repo,
String projectId,
File pomFile,
InvalidRepositoryException cause )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "Invalid repository declaration: " );
writer.write( repo.getId() );
writer.write( NEWLINE );
writer.write( "(URL: " );
writer.write( repo.getUrl() );
writer.write( ")" );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Error message: " );
writer.write( NEWLINE );
writer.write( cause.getMessage() );
addStandardInfo( projectId, pomFile, writer );
addTips( ProjectErrorTips.getTipsForInvalidRepositorySpec( repo, projectId, pomFile, cause ),
writer );
registerProjectBuildError( cause, writer.toString(), cause.getCause() );
}
private void addStandardInfo( String projectId,
File pomFile,
StringWriter writer )
{
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "While applying profile to: " );
writer.write( projectId );
writer.write( NEWLINE );
writer.write( "From file: " );
writer.write( String.valueOf( pomFile ) );
}
private void addTips( List<String> tips,
StringWriter writer )
{
if ( ( tips != null ) && !tips.isEmpty() )
{
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Some tips:" );
for ( String tip : tips )
{
writer.write( NEWLINE );
writer.write( "\t- " );
writer.write( tip );
}
}
}
public void reportErrorCreatingArtifactRepository( MavenProject project,
File pomFile,
Repository repo,
UnknownRepositoryLayoutException cause,
boolean isPluginRepo )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "You have an invalid repository/pluginRepository declaration in your POM:" );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Repository-Id: " );
writer.write( ((InvalidRepositoryException)cause).getRepositoryId() );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Reason: " );
writer.write( cause.getMessage() );
writer.write( NEWLINE );
addStandardInfo( project.getId(), pomFile, writer );
addTips( ProjectErrorTips.getTipsForInvalidRepositorySpec( repo, project.getId(), pomFile, cause ),
writer );
registerProjectBuildError( cause, writer.toString() );
}
public void reportErrorCreatingDeploymentArtifactRepository( MavenProject project,
File pomFile,
DeploymentRepository repo,
UnknownRepositoryLayoutException cause )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "You have an invalid repository/snapshotRepository declaration in the <distributionManagement/> section of your POM:" );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Repository-Id: " );
writer.write( ((InvalidRepositoryException)cause).getRepositoryId() );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Reason: " );
writer.write( cause.getMessage() );
writer.write( NEWLINE );
addStandardInfo( project.getId(), pomFile, writer );
addTips( ProjectErrorTips.getTipsForInvalidRepositorySpec( repo, project.getId(), pomFile, cause ),
writer );
registerProjectBuildError( cause, writer.toString() );
}
public void reportBadNonDependencyProjectArtifactVersion( MavenProject project,
File pomFile,
InvalidProjectVersionException cause )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "You have an invalid version in your POM:" );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Location: " );
writer.write( cause.getLocationInPom() );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Reason: " );
writer.write( cause.getMessage() );
writer.write( NEWLINE );
addStandardInfo( project.getId(), pomFile, writer );
addTips( ProjectErrorTips.getTipsForBadNonDependencyArtifactSpec( project, pomFile, cause ),
writer );
registerProjectBuildError( cause, writer.toString() );
}
public void reportErrorInterpolatingModel( MavenProject project,
File pomFile,
ModelInterpolationException cause )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "You have an invalid expression in your POM (interpolation failed):" );
writer.write( NEWLINE );
writer.write( cause.getMessage() );
addStandardInfo( project.getId(), pomFile, writer );
addTips( ProjectErrorTips.getTipsForProjectInterpolationError( project, pomFile, cause ),
writer );
registerProjectBuildError( cause, writer.toString() );
}
public void reportProjectValidationFailure( MavenProject project,
File pomFile,
InvalidProjectModelException error )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "The following POM validation errors were detected:" );
writer.write( NEWLINE );
for ( Iterator it = error.getValidationResult().getMessages().iterator(); it.hasNext(); )
{
String message = (String) it.next();
writer.write( NEWLINE );
writer.write( " - " );
writer.write( message );
}
writer.write( NEWLINE );
writer.write( NEWLINE );
addStandardInfo( project.getId(), pomFile, writer );
addTips( ProjectErrorTips.getTipsForProjectValidationFailure( project, pomFile, error.getValidationResult() ),
writer );
registerProjectBuildError( error, writer.toString() );
}
public void reportBadManagedDependencyVersion( MavenProject project,
File pomFile,
InvalidDependencyVersionException cause )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "Your project declares a dependency with an invalid version inside its <dependencyManagement/> section." );
writer.write( NEWLINE );
writer.write( NEWLINE );
Dependency dep = cause.getDependency();
writer.write( "Dependency:" );
writer.write( NEWLINE );
writer.write( "Group-Id: " );
writer.write( dep.getGroupId() );
writer.write( NEWLINE );
writer.write( "Artifact-Id: " );
writer.write( dep.getArtifactId() );
writer.write( NEWLINE );
writer.write( "Version: " );
writer.write( dep.getVersion() );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Reason: " );
writer.write( cause.getMessage() );
writer.write( NEWLINE );
addStandardInfo( project.getId(), pomFile, writer );
addTips( ProjectErrorTips.getTipsForBadDependencySpec( project, pomFile, dep ),
writer );
registerProjectBuildError( cause, writer.toString() );
}
public void reportBadDependencyVersion( MavenProject project,
File pomFile,
InvalidDependencyVersionException cause )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "Your project declares a dependency with an invalid version." );
writer.write( NEWLINE );
writer.write( NEWLINE );
Dependency dep = cause.getDependency();
writer.write( "Dependency:" );
writer.write( NEWLINE );
writer.write( "Group-Id: " );
writer.write( dep.getGroupId() );
writer.write( NEWLINE );
writer.write( "Artifact-Id: " );
writer.write( dep.getArtifactId() );
writer.write( NEWLINE );
writer.write( "Version: " );
writer.write( dep.getVersion() );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Reason: " );
writer.write( cause.getMessage() );
writer.write( NEWLINE );
addStandardInfo( project.getId(), pomFile, writer );
addTips( ProjectErrorTips.getTipsForBadDependencySpec( project, pomFile, dep ),
writer );
registerProjectBuildError( cause, writer.toString() );
}
}

View File

@ -0,0 +1,307 @@
package org.apache.maven.project.error;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
import org.apache.maven.model.DeploymentRepository;
import org.apache.maven.model.Model;
import org.apache.maven.model.Profile;
import org.apache.maven.model.Repository;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.profiles.activation.ProfileActivator;
import org.apache.maven.project.InvalidProjectModelException;
import org.apache.maven.project.InvalidProjectVersionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.IOException;
public interface ProjectErrorReporter
{
String NEWLINE = "\n";
void clearErrors();
String getFormattedMessage( Throwable error );
Throwable getRealCause( Throwable error );
Throwable findReportedException( Throwable error );
/**
* <b>Call Stack:</b>
* <br/>
* <pre>
* DefaultProfileAdvisor.applyActivatedProfiles(..)
* DefaultProfileAdvisor.applyActivatedExternalProfiles(..)
* --&gt; DefaultProfileAdvisor.applyActivatedProfiles(..) (private)
* --&gt; DefaultProfileManager.getActiveProfiles(..)
* --&gt; DefaultProfileManager.isActive(..) (private)
* --&gt; ProfileActivator.canDetermineActivation(..)
* --&gt; ProfileActivator.isActive(..)
* &lt;------ ProfileActivationException
* &lt;------ ProjectBuildingException
* </pre>
*/
void reportActivatorErrorWhileApplyingProfiles( ProfileActivator activator,
Model model,
File pomFile,
Profile profile,
ProfileActivationContext context,
ProfileActivationException cause );
/**
* <b>Call Stack:</b>
* <br/>
* <pre>
* DefaultProfileAdvisor.applyActivatedProfiles(..)
* DefaultProfileAdvisor.applyActivatedExternalProfiles(..)
* --&gt; DefaultProfileAdvisor.getArtifactRepositoriesFromActiveProfiles(..)
* --&gt; DefaultProfileManager.getActiveProfiles(..)
* --&gt; DefaultProfileManager.isActive(..) (private)
* --&gt; ProfileActivator.canDetermineActivation(..)
* --&gt; ProfileActivator.isActive(..)
* &lt;------ ProfileActivationException
* &lt;------ ProjectBuildingException
* </pre>
*/
void reportActivatorErrorWhileGettingRepositoriesFromProfiles( ProfileActivator activator,
String projectId,
File pomFile,
Profile profile,
ProfileActivationContext context,
ProfileActivationException cause );
/**
* <b>Call Stack:</b>
* <br/>
* <pre>
* DefaultProfileAdvisor.applyActivatedProfiles(..)
* DefaultProfileAdvisor.applyActivatedExternalProfiles(..)
* --&gt; DefaultProfileAdvisor.applyActivatedProfiles(..) (private)
* --&gt; DefaultProfileManager.getActiveProfiles(..)
* --&gt; DefaultProfileManager.isActive(..) (private)
* --&gt; PlexusContainer.lookupList(..)
* &lt;-- ComponentLookupException
* &lt;-- ProfileActivationException
* &lt;------ ProjectBuildingException
* </pre>
*/
void reportActivatorLookupErrorWhileApplyingProfiles( Model model,
File pomFile,
Profile profile,
ComponentLookupException cause );
/**
* <b>Call Stack:</b>
* <br/>
* <pre>
* DefaultProfileAdvisor.applyActivatedProfiles(..)
* DefaultProfileAdvisor.applyActivatedExternalProfiles(..)
* --&gt; DefaultProfileAdvisor.getArtifactRepositoriesFromActiveProfiles(..)
* --&gt; DefaultProfileManager.getActiveProfiles(..)
* --&gt; DefaultProfileManager.isActive(..) (private)
* --&gt; PlexusContainer.lookupList(..)
* &lt;-- ComponentLookupException
* &lt;-- ProfileActivationException
* &lt;------ ProjectBuildingException
* </pre>
*/
void reportActivatorLookupErrorWhileGettingRepositoriesFromProfiles( String projectId,
File pomFile,
Profile profile,
ComponentLookupException cause );
/**
* <b>Call Stack:</b>
* <br/>
* <pre>
* DefaultProfileAdvisor.applyActivatedProfiles(..)
* DefaultProfileAdvisor.getArtifactRepositoriesFromActiveProfiles(..)
* --&gt; DefaultProfileAdvisor.buildProfileManager(..) (private)
* --&gt; DefaultProfileAdvisor.loadExternalProjectProfiles(..) (private)
* --&gt; MavenProfilesBuilder.buildProfiles(..)
* &lt;-- IOException
* &lt;------ ProjectBuildingException
* </pre>
*/
void reportErrorLoadingExternalProfilesFromFile( Model model,
File pomFile,
File projectDir,
IOException cause );
/**
* <b>Call Stack:</b>
* <br/>
* <pre>
* DefaultProfileAdvisor.applyActivatedProfiles(..)
* DefaultProfileAdvisor.getArtifactRepositoriesFromActiveProfiles(..)
* --&gt; DefaultProfileAdvisor.buildProfileManager(..) (private)
* --&gt; DefaultProfileAdvisor.loadExternalProjectProfiles(..) (private)
* --&gt; MavenProfilesBuilder.buildProfiles(..)
* &lt;-- XmlPullParserException
* &lt;------ ProjectBuildingException
* </pre>
*/
void reportErrorLoadingExternalProfilesFromFile( Model model,
File pomFile,
File projectDir,
XmlPullParserException cause );
/**
* <b>Call Stack:</b>
* <br/>
* <pre>
* DefaultProfileAdvisor.applyActivatedProfiles(..)
* DefaultProfileAdvisor.applyActivatedExternalProfiles(..)
* --&gt; DefaultProfileAdvisor.getArtifactRepositoriesFromActiveProfiles(..)
* --&gt; MavenTools.buildArtifactRepository(..)
* &lt;-- InvalidRepositoryException
* &lt;-- ProjectBuildingException
* </pre>
*/
void reportInvalidRepositoryWhileGettingRepositoriesFromProfiles( Repository repo,
String projectId,
File pomFile,
InvalidRepositoryException cause );
/**
* <b>Call Stack:</b>
* <br/>
* <pre>
* ...
* --&gt; DefaultMavenProjectBuilder.buildFromRepository(..)
* DefaultMavenProjectBuilder.build(..)
* --&gt; DefaultMavenProjectBuilder.buildFromSourceFileInternal(..) (private)
* --&gt; DefaultMavenProjectBuilder.buildInternal(..) (private)
* --&gt; DefaultMavenProjectBuilder.processProjectLogic(..) (private)
* --&gt; DefaultMavenTools.buildDeploymentArtifactRepository(..)
* &lt;-- UnknownRepositoryLayoutException
* &lt;-------- ProjectBuildingException
* </pre>
*/
void reportErrorCreatingDeploymentArtifactRepository( MavenProject project,
File pomFile,
DeploymentRepository repo,
UnknownRepositoryLayoutException cause );
/**
* <b>Call Stack:</b>
* <br/>
* <pre>
* ...
* --&gt; DefaultMavenProjectBuilder.buildFromRepository(..)
* DefaultMavenProjectBuilder.build(..)
* --&gt; DefaultMavenProjectBuilder.buildFromSourceFileInternal(..) (private)
* --&gt; DefaultMavenProjectBuilder.buildInternal(..) (private)
* --&gt; DefaultMavenProjectBuilder.processProjectLogic(..) (private)
* --&gt; DefaultMavenTools.buildArtifactRepositories(..)
* --&gt; DefaultMavenTools.buildArtifactRepository(..)
* &lt;------ UnknownRepositoryLayoutException
* &lt;---------- ProjectBuildingException
* </pre>
*/
void reportErrorCreatingArtifactRepository( MavenProject project,
File pomFile,
Repository repo,
UnknownRepositoryLayoutException cause,
boolean isPluginRepo );
/**
* <b>Call Stack:</b>
* <br/>
* <pre>
* ...
* --&gt; DefaultMavenProjectBuilder.buildFromRepository(..)
* DefaultMavenProjectBuilder.build(..)
* --&gt; DefaultMavenProjectBuilder.buildFromSourceFileInternal(..) (private)
* --&gt; DefaultMavenProjectBuilder.buildInternal(..) (private)
* --&gt; DefaultMavenProjectBuilder.processProjectLogic(..) (private)
* --&gt; ModelInterpolator.interpolate(..)
* &lt;-- ModelInterpolationException
* &lt;---------- ProjectBuildingException
* </pre>
*/
void reportErrorInterpolatingModel( MavenProject project,
File pomFile,
ModelInterpolationException cause );
/**
* <b>Call Stack:</b>
* <br/>
* <pre>
* ...
* --&gt; DefaultMavenProjectBuilder.buildFromRepository(..)
* DefaultMavenProjectBuilder.build(..)
* --&gt; DefaultMavenProjectBuilder.buildFromSourceFileInternal(..) (private)
* --&gt; DefaultMavenProjectBuilder.buildInternal(..) (private)
* --&gt; DefaultMavenProjectBuilder.processProjectLogic(..) (private)
* --&gt; DefaultMavenProjectBuilder.createPluginArtifacts(..)
* --&gt; DefaultMavenProjectBuilder.createReportArtifacts(..)
* --&gt; DefaultMavenProjectBuilder.createExtensionArtifacts(..)
* &lt;-- InvalidProjectVersionException
* &lt;---------- ProjectBuildingException
* </pre>
*/
void reportBadNonDependencyProjectArtifactVersion( MavenProject project,
File pomFile,
InvalidProjectVersionException cause );
/**
* <b>Call Stack:</b>
* <br/>
* <pre>
* ...
* --&gt; DefaultMavenProjectBuilder.buildFromRepository(..)
* DefaultMavenProjectBuilder.build(..)
* --&gt; DefaultMavenProjectBuilder.buildFromSourceFileInternal(..) (private)
* --&gt; DefaultMavenProjectBuilder.buildInternal(..) (private)
* --&gt; DefaultMavenProjectBuilder.processProjectLogic(..) (private)
* --&gt; (model validator result)
* &lt;-- InvalidProjectModelException
* &lt;---------- ProjectBuildingException
* </pre>
*/
void reportProjectValidationFailure( MavenProject project,
File pomFile,
InvalidProjectModelException error );
/**
* <b>Call Stack:</b>
* <br/>
* <pre>
* ...
* --&gt; DefaultMavenProjectBuilder.buildFromRepository(..)
* DefaultMavenProjectBuilder.build(..)
* --&gt; DefaultMavenProjectBuilder.buildFromSourceFileInternal(..) (private)
* --&gt; DefaultMavenProjectBuilder.buildInternal(..) (private)
* --&gt; DefaultMavenProjectBuilder.createManagedVersionMap(..) (private)
* &lt;-- InvalidDependencyVersionException
* &lt;---------- ProjectBuildingException
* </pre>
*/
void reportBadManagedDependencyVersion( MavenProject projectBeingBuilt,
File pomFile,
InvalidDependencyVersionException cause );
/**
* <b>Call Stack:</b>
* <br/>
* <pre>
* ...
* --&gt; MavenProject.createArtifacts(..)
* --&gt; MavenMetadataSource.createArtifacts(..)
* &lt;-- InvalidDependencyVersionException
* &lt;-- ProjectBuildingException
* </pre>
*/
void reportBadDependencyVersion( MavenProject project,
File pomFile,
InvalidDependencyVersionException cause );
}

View File

@ -0,0 +1,157 @@
package org.apache.maven.project.error;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Profile;
import org.apache.maven.model.RepositoryBase;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.profiles.activation.ProfileActivator;
import org.apache.maven.project.InvalidProjectVersionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.apache.maven.project.validation.ModelValidationResult;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public final class ProjectErrorTips
{
private ProjectErrorTips()
{
}
public static List<String> getTipsForActivatorErrorWhileApplyingProfiles( ProfileActivator activator,
Model model,
File pomFile,
Profile profile,
ProfileActivationContext context,
ProfileActivationException cause )
{
return listOf( "If this is a standard profile activator, see "
+ "http://maven.apache.org/pom.html#Activation for help configuring profile activation.",
"XSD location for pom.xml: http://maven.apache.org/xsd/maven-4.0.0.xsd",
"XSD location for settings.xml: http://maven.apache.org/xsd/settings-1.0.0.xsd",
"XSD location for profiles.xml: http://maven.apache.org/xsd/profiles-1.0.0.xsd" );
}
public static List<String> getTipsForActivatorErrorWhileGettingRepositoriesFromProfiles( ProfileActivator activator,
String projectId,
File pomFile,
Profile profile,
ProfileActivationContext context,
ProfileActivationException cause )
{
return listOf( "If this is a standard profile activator, see "
+ "http://maven.apache.org/pom.html#Activation for help configuring profile activation.",
"XSD location for pom.xml: http://maven.apache.org/xsd/maven-4.0.0.xsd",
"XSD location for settings.xml: http://maven.apache.org/xsd/settings-1.0.0.xsd",
"XSD location for profiles.xml: http://maven.apache.org/xsd/profiles-1.0.0.xsd" );
}
public static List<String> getTipsForActivatorLookupErrorWhileApplyingProfiles( Model model,
File pomFile,
Profile profile,
ComponentLookupException cause )
{
return listOf( "If this is a custom profile activator, please ensure the activator's "
+ "artifact is present in the POM's build/extensions list.",
"See http://maven.apache.org/pom.html#Extensions for more on build extensions.",
"XSD location for pom.xml: http://maven.apache.org/xsd/maven-4.0.0.xsd",
"XSD location for settings.xml: http://maven.apache.org/xsd/settings-1.0.0.xsd",
"XSD location for profiles.xml: http://maven.apache.org/xsd/profiles-1.0.0.xsd" );
}
public static List<String> getTipsForActivatorLookupErrorWhileGettingRepositoriesFromProfiles( String projectId,
File pomFile,
Profile profile,
ComponentLookupException cause )
{
return listOf( "If this is a custom profile activator, please ensure the activator's "
+ "artifact is present in the POM's build/extensions list.",
"See http://maven.apache.org/pom.html#Extensions for more on build extensions.",
"XSD location for pom.xml: http://maven.apache.org/xsd/maven-4.0.0.xsd",
"XSD location for settings.xml: http://maven.apache.org/xsd/settings-1.0.0.xsd",
"XSD location for profiles.xml: http://maven.apache.org/xsd/profiles-1.0.0.xsd" );
}
public static List<String> getTipsForErrorLoadingExternalProfilesFromFile( Model model,
File pomFile,
File projectDir,
IOException cause )
{
String profilesXmlPath = new File( projectDir, "profiles.xml" ).getAbsolutePath();
return listOf( "Please ensure the " + profilesXmlPath + " file exists and is readable." );
}
public static List<String> getTipsForErrorLoadingExternalProfilesFromFile( Model model,
File pomFile,
File projectDir,
XmlPullParserException cause )
{
return listOf( "XSD location: http://maven.apache.org/xsd/profiles-1.0.0.xsd" );
}
public static List<String> getTipsForInvalidRepositorySpec( RepositoryBase repo,
String projectId,
File pomFile,
InvalidRepositoryException cause )
{
return listOf( "See http://maven.apache.org/pom.html#Repositories for more on custom artifact repositories.",
"See http://maven.apache.org/pom.html#PluginRepositories for more on custom plugin repositories.",
"XSD location for pom.xml: http://maven.apache.org/xsd/maven-4.0.0.xsd",
"XSD location for settings.xml: http://maven.apache.org/xsd/settings-1.0.0.xsd",
"XSD location for profiles.xml: http://maven.apache.org/xsd/profiles-1.0.0.xsd" );
}
private static List<String> listOf( String... tips )
{
List<String> list = new ArrayList<String>();
for ( String tip : tips )
{
list.add( tip );
}
return list;
}
public static List<String> getTipsForProjectValidationFailure( MavenProject project,
File pomFile,
ModelValidationResult validationResult )
{
// TODO Auto-generated method stub
return null;
}
public static List<String> getTipsForBadDependencySpec( MavenProject project,
File pomFile,
Dependency dep )
{
// TODO Auto-generated method stub
return null;
}
public static List<String> getTipsForBadNonDependencyArtifactSpec( MavenProject project,
File pomFile,
InvalidProjectVersionException cause )
{
// TODO Auto-generated method stub
return null;
}
public static List<String> getTipsForProjectInterpolationError( MavenProject project,
File pomFile,
ModelInterpolationException cause )
{
// TODO Auto-generated method stub
return null;
}
}