mirror of https://github.com/apache/maven.git
o Extended error reporting to provide the id of the POM that failed
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@801449 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7de1280968
commit
84dc78cbe4
|
@ -113,7 +113,7 @@ public class DefaultProjectBuilder
|
||||||
}
|
}
|
||||||
catch ( ModelBuildingException e )
|
catch ( ModelBuildingException e )
|
||||||
{
|
{
|
||||||
throw new ProjectBuildingException( "[unknown]", "Encountered POM errors", pomFile, e );
|
throw new ProjectBuildingException( e.getModelId(), "Encountered POM errors", pomFile, e );
|
||||||
}
|
}
|
||||||
|
|
||||||
Model model = result.getEffectiveModel();
|
Model model = result.getEffectiveModel();
|
||||||
|
@ -327,7 +327,8 @@ public class DefaultProjectBuilder
|
||||||
}
|
}
|
||||||
catch ( ModelBuildingException e )
|
catch ( ModelBuildingException e )
|
||||||
{
|
{
|
||||||
results.add( new DefaultProjectBuildingResult( interimResult.pomFile, e.getProblems() ) );
|
results.add( new DefaultProjectBuildingResult( e.getModelId(), interimResult.pomFile,
|
||||||
|
e.getProblems() ) );
|
||||||
|
|
||||||
errors = true;
|
errors = true;
|
||||||
}
|
}
|
||||||
|
@ -431,7 +432,7 @@ public class DefaultProjectBuilder
|
||||||
}
|
}
|
||||||
catch ( ModelBuildingException e )
|
catch ( ModelBuildingException e )
|
||||||
{
|
{
|
||||||
results.add( new DefaultProjectBuildingResult( pomFile, e.getProblems() ) );
|
results.add( new DefaultProjectBuildingResult( e.getModelId(), pomFile, e.getProblems() ) );
|
||||||
|
|
||||||
errors = true;
|
errors = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,8 @@ class DefaultProjectBuildingResult
|
||||||
implements ProjectBuildingResult
|
implements ProjectBuildingResult
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private String projectId;
|
||||||
|
|
||||||
private File pomFile;
|
private File pomFile;
|
||||||
|
|
||||||
private MavenProject project;
|
private MavenProject project;
|
||||||
|
@ -48,6 +50,7 @@ class DefaultProjectBuildingResult
|
||||||
*/
|
*/
|
||||||
public DefaultProjectBuildingResult( MavenProject project, List<ModelProblem> problems )
|
public DefaultProjectBuildingResult( MavenProject project, List<ModelProblem> problems )
|
||||||
{
|
{
|
||||||
|
this.projectId = ( project != null ) ? project.getId() : "";
|
||||||
this.pomFile = ( project != null ) ? project.getFile() : null;
|
this.pomFile = ( project != null ) ? project.getFile() : null;
|
||||||
this.project = project;
|
this.project = project;
|
||||||
this.problems = problems;
|
this.problems = problems;
|
||||||
|
@ -56,15 +59,22 @@ class DefaultProjectBuildingResult
|
||||||
/**
|
/**
|
||||||
* Creates a new result with the specified contents.
|
* Creates a new result with the specified contents.
|
||||||
*
|
*
|
||||||
|
* @param projectId The
|
||||||
* @param pomFile The POM file from which the project was built, may be {@code null}.
|
* @param pomFile The POM file from which the project was built, may be {@code null}.
|
||||||
* @param problems The problems that were encouterned, may be {@code null}.
|
* @param problems The problems that were encouterned, may be {@code null}.
|
||||||
*/
|
*/
|
||||||
public DefaultProjectBuildingResult( File pomFile, List<ModelProblem> problems )
|
public DefaultProjectBuildingResult( String projectId, File pomFile, List<ModelProblem> problems )
|
||||||
{
|
{
|
||||||
|
this.projectId = ( projectId != null ) ? projectId : "";
|
||||||
this.pomFile = pomFile;
|
this.pomFile = pomFile;
|
||||||
this.problems = problems;
|
this.problems = problems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getProjectId()
|
||||||
|
{
|
||||||
|
return projectId;
|
||||||
|
}
|
||||||
|
|
||||||
public File getPomFile()
|
public File getPomFile()
|
||||||
{
|
{
|
||||||
return pomFile;
|
return pomFile;
|
||||||
|
|
|
@ -32,6 +32,15 @@ import org.apache.maven.model.building.ModelProblem;
|
||||||
public interface ProjectBuildingResult
|
public interface ProjectBuildingResult
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the identifier of the project that could not be built. The general format of the identifier is {@code
|
||||||
|
* <groupId>:<artifactId>:<version>} but some of these coordinates may still be unknown at the point the exception
|
||||||
|
* is thrown so this information is merely meant to assist the user.
|
||||||
|
*
|
||||||
|
* @return The identifier of the project or an empty string if not known, never {@code null}.
|
||||||
|
*/
|
||||||
|
String getProjectId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the POM file from which the project was built.
|
* Gets the POM file from which the project was built.
|
||||||
*
|
*
|
||||||
|
|
|
@ -121,6 +121,8 @@ public class DefaultModelBuilder
|
||||||
|
|
||||||
Model inputModel = readModel( request.getModelSource(), request.getPomFile(), request, problems );
|
Model inputModel = readModel( request.getModelSource(), request.getPomFile(), request, problems );
|
||||||
|
|
||||||
|
problems.setRootModel( inputModel );
|
||||||
|
|
||||||
ModelData resultData = new ModelData( inputModel );
|
ModelData resultData = new ModelData( inputModel );
|
||||||
|
|
||||||
List<ModelData> lineage = new ArrayList<ModelData>();
|
List<ModelData> lineage = new ArrayList<ModelData>();
|
||||||
|
@ -170,6 +172,7 @@ public class DefaultModelBuilder
|
||||||
Model resultModel = resultData.getModel();
|
Model resultModel = resultData.getModel();
|
||||||
|
|
||||||
problems.setSourceHint( resultModel );
|
problems.setSourceHint( resultModel );
|
||||||
|
problems.setRootModel( resultModel );
|
||||||
|
|
||||||
resultModel = interpolateModel( resultModel, request, problems );
|
resultModel = interpolateModel( resultModel, request, problems );
|
||||||
resultData.setModel( resultModel );
|
resultData.setModel( resultModel );
|
||||||
|
@ -208,6 +211,7 @@ public class DefaultModelBuilder
|
||||||
|
|
||||||
DefaultModelProblemCollector problems = new DefaultModelProblemCollector( result.getProblems() );
|
DefaultModelProblemCollector problems = new DefaultModelProblemCollector( result.getProblems() );
|
||||||
problems.setSourceHint( resultModel );
|
problems.setSourceHint( resultModel );
|
||||||
|
problems.setRootModel( resultModel );
|
||||||
|
|
||||||
modelPathTranslator.alignToBaseDirectory( resultModel, resultModel.getProjectDirectory(), request );
|
modelPathTranslator.alignToBaseDirectory( resultModel, resultModel.getProjectDirectory(), request );
|
||||||
|
|
||||||
|
@ -237,7 +241,7 @@ public class DefaultModelBuilder
|
||||||
|
|
||||||
if ( hasErrors( problems.getProblems() ) )
|
if ( hasErrors( problems.getProblems() ) )
|
||||||
{
|
{
|
||||||
throw new ModelBuildingException( problems.getProblems() );
|
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -274,13 +278,13 @@ public class DefaultModelBuilder
|
||||||
{
|
{
|
||||||
problems.add( new ModelProblem( "Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage(),
|
problems.add( new ModelProblem( "Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage(),
|
||||||
ModelProblem.Severity.FATAL, modelSource.getLocation(), e ) );
|
ModelProblem.Severity.FATAL, modelSource.getLocation(), e ) );
|
||||||
throw new ModelBuildingException( problems.getProblems() );
|
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
|
||||||
}
|
}
|
||||||
catch ( IOException e )
|
catch ( IOException e )
|
||||||
{
|
{
|
||||||
problems.add( new ModelProblem( "Non-readable POM " + modelSource.getLocation() + ": " + e.getMessage(),
|
problems.add( new ModelProblem( "Non-readable POM " + modelSource.getLocation() + ": " + e.getMessage(),
|
||||||
ModelProblem.Severity.FATAL, modelSource.getLocation(), e ) );
|
ModelProblem.Severity.FATAL, modelSource.getLocation(), e ) );
|
||||||
throw new ModelBuildingException( problems.getProblems() );
|
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
|
||||||
}
|
}
|
||||||
|
|
||||||
model.setPomFile( pomFile );
|
model.setPomFile( pomFile );
|
||||||
|
@ -517,11 +521,9 @@ public class DefaultModelBuilder
|
||||||
}
|
}
|
||||||
catch ( UnresolvableModelException e )
|
catch ( UnresolvableModelException e )
|
||||||
{
|
{
|
||||||
problems.add( new ModelProblem( "Non-resolvable parent POM "
|
problems.addFatalError( "Non-resolvable parent POM "
|
||||||
+ ModelProblemUtils.toId( groupId, artifactId, version ) + ": " + e.getMessage(),
|
+ ModelProblemUtils.toId( groupId, artifactId, version ) + ": " + e.getMessage(), e );
|
||||||
ModelProblem.Severity.FATAL, ModelProblemUtils.toSourceHint( childModel ),
|
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
|
||||||
e ) );
|
|
||||||
throw new ModelBuildingException( problems.getProblems() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Model parentModel = readModel( modelSource, null, request, problems );
|
Model parentModel = readModel( modelSource, null, request, problems );
|
||||||
|
|
|
@ -43,6 +43,8 @@ class DefaultModelProblemCollector
|
||||||
|
|
||||||
private Model sourceModel;
|
private Model sourceModel;
|
||||||
|
|
||||||
|
private Model rootModel;
|
||||||
|
|
||||||
public DefaultModelProblemCollector( List<ModelProblem> problems )
|
public DefaultModelProblemCollector( List<ModelProblem> problems )
|
||||||
{
|
{
|
||||||
this.problems = ( problems != null ) ? problems : new ArrayList<ModelProblem>();
|
this.problems = ( problems != null ) ? problems : new ArrayList<ModelProblem>();
|
||||||
|
@ -74,11 +76,36 @@ class DefaultModelProblemCollector
|
||||||
return sourceHint;
|
return sourceHint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRootModel( Model rootModel )
|
||||||
|
{
|
||||||
|
this.rootModel = rootModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Model getRootModel()
|
||||||
|
{
|
||||||
|
return rootModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRootModelId()
|
||||||
|
{
|
||||||
|
return ModelProblemUtils.toId( rootModel );
|
||||||
|
}
|
||||||
|
|
||||||
public void add( ModelProblem problem )
|
public void add( ModelProblem problem )
|
||||||
{
|
{
|
||||||
problems.add( problem );
|
problems.add( problem );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addFatalError( String message )
|
||||||
|
{
|
||||||
|
problems.add( new ModelProblem( message, ModelProblem.Severity.FATAL, getSourceHint() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFatalError( String message, Exception cause )
|
||||||
|
{
|
||||||
|
problems.add( new ModelProblem( message, ModelProblem.Severity.FATAL, getSourceHint(), cause ) );
|
||||||
|
}
|
||||||
|
|
||||||
public void addError( String message )
|
public void addError( String message )
|
||||||
{
|
{
|
||||||
problems.add( new ModelProblem( message, ModelProblem.Severity.ERROR, getSourceHint() ) );
|
problems.add( new ModelProblem( message, ModelProblem.Severity.ERROR, getSourceHint() ) );
|
||||||
|
|
|
@ -35,16 +35,21 @@ public class ModelBuildingException
|
||||||
extends Exception
|
extends Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private final String modelId;
|
||||||
|
|
||||||
private final List<ModelProblem> problems;
|
private final List<ModelProblem> problems;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new exception with the specified problems.
|
* Creates a new exception with the specified problems.
|
||||||
*
|
*
|
||||||
|
* @param modelId The identifier of the model that could not be built, may be {@code null}.
|
||||||
* @param problems The problems that causes this exception, may be {@code null}.
|
* @param problems The problems that causes this exception, may be {@code null}.
|
||||||
*/
|
*/
|
||||||
public ModelBuildingException( List<ModelProblem> problems )
|
public ModelBuildingException( String modelId, List<ModelProblem> problems )
|
||||||
{
|
{
|
||||||
super( toMessage( problems ) );
|
super( toMessage( modelId, problems ) );
|
||||||
|
|
||||||
|
this.modelId = ( modelId != null ) ? modelId : "";
|
||||||
|
|
||||||
this.problems = new ArrayList<ModelProblem>();
|
this.problems = new ArrayList<ModelProblem>();
|
||||||
if ( problems != null )
|
if ( problems != null )
|
||||||
|
@ -53,6 +58,18 @@ public class ModelBuildingException
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the identifier of the POM whose effective model could not be built. The general format of the identifier is
|
||||||
|
* {@code <groupId>:<artifactId>:<version>} but some of these coordinates may still be unknown at the point the
|
||||||
|
* exception is thrown so this information is merely meant to assist the user.
|
||||||
|
*
|
||||||
|
* @return The identifier of the POM or an empty string if not known, never {@code null}.
|
||||||
|
*/
|
||||||
|
public String getModelId()
|
||||||
|
{
|
||||||
|
return modelId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the problems that caused this exception.
|
* Gets the problems that caused this exception.
|
||||||
*
|
*
|
||||||
|
@ -60,10 +77,10 @@ public class ModelBuildingException
|
||||||
*/
|
*/
|
||||||
public List<ModelProblem> getProblems()
|
public List<ModelProblem> getProblems()
|
||||||
{
|
{
|
||||||
return this.problems;
|
return problems;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String toMessage( List<ModelProblem> problems )
|
private static String toMessage( String modelId, List<ModelProblem> problems )
|
||||||
{
|
{
|
||||||
StringWriter buffer = new StringWriter( 1024 );
|
StringWriter buffer = new StringWriter( 1024 );
|
||||||
|
|
||||||
|
@ -71,7 +88,13 @@ public class ModelBuildingException
|
||||||
|
|
||||||
writer.print( problems.size() );
|
writer.print( problems.size() );
|
||||||
writer.print( ( problems.size() == 1 ) ? " problem was " : " problems were " );
|
writer.print( ( problems.size() == 1 ) ? " problem was " : " problems were " );
|
||||||
writer.println( "encountered during construction of the effective model:" );
|
writer.print( "encountered while building the effective model" );
|
||||||
|
if ( modelId != null && modelId.length() > 0 )
|
||||||
|
{
|
||||||
|
writer.print( " for " );
|
||||||
|
writer.print( modelId );
|
||||||
|
}
|
||||||
|
writer.println();
|
||||||
|
|
||||||
for ( ModelProblem problem : problems )
|
for ( ModelProblem problem : problems )
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,11 +34,16 @@ class ModelProblemUtils
|
||||||
/**
|
/**
|
||||||
* Creates a user-friendly source hint for the specified model.
|
* Creates a user-friendly source hint for the specified model.
|
||||||
*
|
*
|
||||||
* @param model The model to create a source hint for, must not be {@code null}.
|
* @param model The model to create a source hint for, may be {@code null}.
|
||||||
* @return The user-friendly source hint, never {@code null}.
|
* @return The user-friendly source hint, never {@code null}.
|
||||||
*/
|
*/
|
||||||
public static String toSourceHint( Model model )
|
public static String toSourceHint( Model model )
|
||||||
{
|
{
|
||||||
|
if ( model == null )
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder buffer = new StringBuilder( 192 );
|
StringBuilder buffer = new StringBuilder( 192 );
|
||||||
|
|
||||||
buffer.append( toId( model ) );
|
buffer.append( toId( model ) );
|
||||||
|
@ -52,8 +57,13 @@ class ModelProblemUtils
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String toId( Model model )
|
public static String toId( Model model )
|
||||||
{
|
{
|
||||||
|
if ( model == null )
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
String groupId = model.getGroupId();
|
String groupId = model.getGroupId();
|
||||||
if ( groupId == null && model.getParent() != null )
|
if ( groupId == null && model.getParent() != null )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue