Author: bentmann
Date: Fri Apr 16 13:18:48 2010
New Revision: 934861

URL: http://svn.apache.org/viewvc?rev=934861&view=rev
Log:
o Refactored code

Modified:
    
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
    
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java
    
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingException.java
    
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java
    
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java
    
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblem.java
    
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemUtils.java

Modified: 
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java?rev=934861&r1=934860&r2=934861&view=diff
==============================================================================
--- 
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java 
(original)
+++ 
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java 
Fri Apr 16 13:18:48 2010
@@ -40,6 +40,7 @@ import org.apache.maven.execution.Projec
 import org.apache.maven.lifecycle.LifecycleExecutor;
 import org.apache.maven.lifecycle.internal.ExecutionEventCatapult;
 import org.apache.maven.model.building.ModelProblem;
+import org.apache.maven.model.building.ModelProblemUtils;
 import org.apache.maven.model.building.ModelSource;
 import org.apache.maven.model.building.UrlModelSource;
 import org.apache.maven.project.DuplicateProjectException;
@@ -414,7 +415,8 @@ public class DefaultMaven
 
                 for ( ModelProblem problem : result.getProblems() )
                 {
-                    logger.warn( problem.getMessage() + " @ " + 
problem.getLocation() );
+                    logger.warn( problem.getMessage() + " @ "
+                        + ModelProblemUtils.formatLocation( problem, 
result.getProjectId() ) );
                 }
 
                 problems = true;

Modified: 
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java?rev=934861&r1=934860&r2=934861&view=diff
==============================================================================
--- 
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java
 (original)
+++ 
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java
 Fri Apr 16 13:18:48 2010
@@ -25,6 +25,7 @@ import java.util.List;
 
 import org.apache.maven.lifecycle.LifecycleExecutionException;
 import org.apache.maven.model.building.ModelProblem;
+import org.apache.maven.model.building.ModelProblemUtils;
 import org.apache.maven.plugin.AbstractMojoExecutionException;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -149,17 +150,7 @@ public class DefaultExceptionHandler
         {
             String message = problem.getMessage();
 
-            String location = "";
-
-            if ( !problem.getModelId().equals( projectId ) )
-            {
-                location += problem.getModelId();
-
-                if ( StringUtils.isNotEmpty( problem.getSource() ) )
-                {
-                    location += " (" + problem.getSource() + ")";
-                }
-            }
+            String location = ModelProblemUtils.formatLocation( problem, 
projectId );
 
             if ( StringUtils.isNotEmpty( location ) )
             {

Modified: 
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingException.java
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingException.java?rev=934861&r1=934860&r2=934861&view=diff
==============================================================================
--- 
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingException.java
 (original)
+++ 
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingException.java
 Fri Apr 16 13:18:48 2010
@@ -25,6 +25,7 @@ import java.io.StringWriter;
 import java.util.List;
 
 import org.apache.maven.model.building.ModelProblem;
+import org.apache.maven.model.building.ModelProblemUtils;
 
 /**
  * @author Jason van Zyl
@@ -134,7 +135,7 @@ public class ProjectBuildingException
                 writer.print( "] " );
                 writer.print( problem.getMessage() );
                 writer.print( " @ " );
-                writer.println( problem.getLocation() );
+                writer.println( ModelProblemUtils.formatLocation( problem, 
result.getProjectId() ) );
             }
         }
         writer.close();

Modified: 
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java?rev=934861&r1=934860&r2=934861&view=diff
==============================================================================
--- 
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java
 (original)
+++ 
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java
 Fri Apr 16 13:18:48 2010
@@ -106,42 +106,6 @@ public class DefaultModelProblem
         return modelId;
     }
 
-    public String getLocation()
-    {
-        StringBuilder buffer = new StringBuilder( 256 );
-
-        buffer.append( getModelId() );
-
-        if ( getSource().length() > 0 )
-        {
-            if ( buffer.length() > 0 )
-            {
-                buffer.append( ", " );
-            }
-            buffer.append( getSource() );
-        }
-
-        if ( getLineNumber() > 0 )
-        {
-            if ( buffer.length() > 0 )
-            {
-                buffer.append( ", " );
-            }
-            buffer.append( "line " ).append( getLineNumber() );
-        }
-
-        if ( getColumnNumber() > 0 )
-        {
-            if ( buffer.length() > 0 )
-            {
-                buffer.append( ", " );
-            }
-            buffer.append( "column " ).append( getColumnNumber() );
-        }
-
-        return buffer.toString();
-    }
-
     public Exception getException()
     {
         return exception;
@@ -180,7 +144,7 @@ public class DefaultModelProblem
 
         buffer.append( "[" ).append( getSeverity() ).append( "] " );
         buffer.append( getMessage() );
-        buffer.append( " @ " ).append( getLocation() );
+        buffer.append( " @ " ).append( ModelProblemUtils.formatLocation( this, 
null ) );
 
         return buffer.toString();
     }

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=934861&r1=934860&r2=934861&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
 Fri Apr 16 13:18:48 2010
@@ -119,7 +119,7 @@ public class ModelBuildingException
             writer.print( "] " );
             writer.print( problem.getMessage() );
             writer.print( " @ " );
-            writer.println( problem.getLocation() );
+            writer.println( ModelProblemUtils.formatLocation( problem, modelId 
) );
         }
 
         return buffer.toString();

Modified: 
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblem.java
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblem.java?rev=934861&r1=934860&r2=934861&view=diff
==============================================================================
--- 
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblem.java
 (original)
+++ 
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblem.java
 Fri Apr 16 13:18:48 2010
@@ -79,15 +79,6 @@ public interface ModelProblem
     String getModelId();
 
     /**
-     * Gets the location of the problem. The location is a user-friendly 
combination of the values from
-     * {...@link #getModelId()}, {...@link #getSource()}, {...@link 
#getLineNumber()} and {...@link #getColumnNumber()}. The exact
-     * syntax of the returned value is undefined.
-     * 
-     * @return The location of the problem, never {...@code null}.
-     */
-    String getLocation();
-
-    /**
      * Gets the exception that caused this problem (if any).
      * 
      * @return The exception that caused this problem or {...@code null} if 
not applicable.

Modified: 
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemUtils.java
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemUtils.java?rev=934861&r1=934860&r2=934861&view=diff
==============================================================================
--- 
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemUtils.java
 (original)
+++ 
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemUtils.java
 Fri Apr 16 13:18:48 2010
@@ -24,11 +24,11 @@ import java.io.File;
 import org.apache.maven.model.Model;
 
 /**
- * Assists in the creation of model problems.
+ * Assists in the handling of model problems.
  * 
  * @author Benjamin Bentmann
  */
-class ModelProblemUtils
+public class ModelProblemUtils
 {
 
     /**
@@ -37,7 +37,7 @@ class ModelProblemUtils
      * @param model The model to create a source hint for, may be {...@code 
null}.
      * @return The user-friendly source hint, never {...@code null}.
      */
-    public static String toSourceHint( Model model )
+    static String toSourceHint( Model model )
     {
         if ( model == null )
         {
@@ -57,7 +57,7 @@ class ModelProblemUtils
         return buffer.toString();
     }
 
-    public static String toPath( Model model )
+    static String toPath( Model model )
     {
         String path = "";
 
@@ -74,7 +74,7 @@ class ModelProblemUtils
         return path;
     }
 
-    public static String toId( Model model )
+    static String toId( Model model )
     {
         if ( model == null )
         {
@@ -106,7 +106,7 @@ class ModelProblemUtils
      * @param version The version, may be {...@code null}.
      * @return The user-friendly artifact id, never {...@code null}.
      */
-    public static String toId( String groupId, String artifactId, String 
version )
+    static String toId( String groupId, String artifactId, String version )
     {
         StringBuilder buffer = new StringBuilder( 96 );
 
@@ -119,4 +119,53 @@ class ModelProblemUtils
         return buffer.toString();
     }
 
+    /**
+     * Creates a string with all location details for the specified model 
problem. If the project identifier is
+     * provided, the generated location will omit the model id and source 
information and only give line/column
+     * information for problems originating directly from this POM.
+     * 
+     * @param problem The problem whose location should be formatted, must not 
be {...@code null}.
+     * @param projectId The {...@code <groupId>:<artifactId>:<version>} of the 
corresponding project, may be {...@code null}
+     *            to force output of model id and source.
+     * @return The formatted problem location or an empty string if unknown, 
never {...@code null}.
+     */
+    public static String formatLocation( ModelProblem problem, String 
projectId )
+    {
+        StringBuilder buffer = new StringBuilder( 256 );
+
+        if ( !problem.getModelId().equals( projectId ) )
+        {
+            buffer.append( problem.getModelId() );
+
+            if ( problem.getSource().length() > 0 )
+            {
+                if ( buffer.length() > 0 )
+                {
+                    buffer.append( ", " );
+                }
+                buffer.append( problem.getSource() );
+            }
+        }
+
+        if ( problem.getLineNumber() > 0 )
+        {
+            if ( buffer.length() > 0 )
+            {
+                buffer.append( ", " );
+            }
+            buffer.append( "line " ).append( problem.getLineNumber() );
+        }
+
+        if ( problem.getColumnNumber() > 0 )
+        {
+            if ( buffer.length() > 0 )
+            {
+                buffer.append( ", " );
+            }
+            buffer.append( "column " ).append( problem.getColumnNumber() );
+        }
+
+        return buffer.toString();
+    }
+
 }


Reply via email to