You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2010/04/15 17:31:09 UTC

svn commit: r934451 - in /maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building: DefaultModelBuilder.java ModelBuildingException.java

Author: bentmann
Date: Thu Apr 15 15:31:08 2010
New Revision: 934451

URL: http://svn.apache.org/viewvc?rev=934451&view=rev
Log:
o Allowed inspection of erroneous model

Modified:
    maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
    maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java

Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java?rev=934451&r1=934450&r2=934451&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java (original)
+++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java Thu Apr 15 15:31:08 2010
@@ -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;

Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java?rev=934451&r1=934450&r2=934451&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java (original)
+++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java Thu Apr 15 15:31:08 2010
@@ -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>();
@@ -59,6 +65,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
      * exception is thrown so this information is merely meant to assist the user.