o Allowed inspection of erroneous model

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@934451 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-04-15 15:31:08 +00:00
parent 41eb59fdd1
commit 4bddf292f5
2 changed files with 28 additions and 7 deletions

View File

@ -218,7 +218,8 @@ public class DefaultModelBuilder
message += currentData.getId();
problems.add( ModelProblem.Severity.FATAL, message, null );
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
throw new ModelBuildingException( problems.getRootModel(), problems.getRootModelId(),
problems.getProblems() );
}
}
@ -315,7 +316,7 @@ public class DefaultModelBuilder
if ( problems.hasErrors() )
{
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
throw new ModelBuildingException( resultModel, problems.getRootModelId(), problems.getProblems() );
}
return result;
@ -386,7 +387,8 @@ public class DefaultModelBuilder
catch ( ModelParseException e )
{
problems.add( Severity.FATAL, "Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage(), e );
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
throw new ModelBuildingException( problems.getRootModel(), problems.getRootModelId(),
problems.getProblems() );
}
catch ( IOException e )
{
@ -404,7 +406,8 @@ public class DefaultModelBuilder
}
}
problems.add( Severity.FATAL, "Non-readable POM " + modelSource.getLocation() + ": " + msg, e );
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
throw new ModelBuildingException( problems.getRootModel(), problems.getRootModelId(),
problems.getProblems() );
}
model.setPomFile( pomFile );
@ -414,7 +417,8 @@ public class DefaultModelBuilder
if ( problems.hasFatalErrors() )
{
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
throw new ModelBuildingException( problems.getRootModel(), problems.getRootModelId(),
problems.getProblems() );
}
return model;
@ -694,7 +698,8 @@ public class DefaultModelBuilder
problems.add( Severity.FATAL, "Non-resolvable parent POM "
+ ModelProblemUtils.toId( groupId, artifactId, version ) + " for "
+ ModelProblemUtils.toId( childModel ) + ": " + e.getMessage(), e );
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
throw new ModelBuildingException( problems.getRootModel(), problems.getRootModelId(),
problems.getProblems() );
}
ModelBuildingRequest lenientRequest = request;

View File

@ -24,6 +24,8 @@ import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.model.Model;
/**
* Signals one ore more errors during model building. The model builder tries to collect as many problems as possible
* before eventually failing to provide callers with rich error information. Use {@link #getProblems()} to query the
@ -35,6 +37,8 @@ public class ModelBuildingException
extends Exception
{
private final Model model;
private final String modelId;
private final List<ModelProblem> problems;
@ -42,13 +46,15 @@ public class ModelBuildingException
/**
* Creates a new exception with the specified problems.
*
* @param model The model that could not be built, may be {@code null}.
* @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}.
*/
public ModelBuildingException( String modelId, List<ModelProblem> problems )
public ModelBuildingException( Model model, String modelId, List<ModelProblem> problems )
{
super( toMessage( modelId, problems ) );
this.model = model;
this.modelId = ( modelId != null ) ? modelId : "";
this.problems = new ArrayList<ModelProblem>();
@ -58,6 +64,16 @@ public class ModelBuildingException
}
}
/**
* Gets the model that could not be built properly.
*
* @return The erroneous model or {@code null} if not available.
*/
public Model getModel()
{
return model;
}
/**
* 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