From 4bddf292f518398ef3ce4cd8f0bd6bf94058029a Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Thu, 15 Apr 2010 15:31:08 +0000 Subject: [PATCH] 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 --- .../model/building/DefaultModelBuilder.java | 17 +++++++++++------ .../model/building/ModelBuildingException.java | 18 +++++++++++++++++- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index 7d5b0fbd56..a9abf5f8a1 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -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; diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java index 651d091f74..9a198e1393 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java @@ -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 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 problems ) + public ModelBuildingException( Model model, String modelId, List problems ) { super( toMessage( modelId, problems ) ); + this.model = model; this.modelId = ( modelId != null ) ? modelId : ""; this.problems = new ArrayList(); @@ -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 ::} but some of these coordinates may still be unknown at the point the