maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r804894 - in /maven/components/trunk: maven-core/src/main/java/org/apache/maven/project/ maven-model-builder/src/main/java/org/apache/maven/model/building/
Date Mon, 17 Aug 2009 08:19:55 GMT
Author: bentmann
Date: Mon Aug 17 08:19:55 2009
New Revision: 804894

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

Added:
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java
  (with props)
Modified:
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblemCollector.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblem.java

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java?rev=804894&r1=804893&r2=804894&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
(original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
Mon Aug 17 08:19:55 2009
@@ -35,6 +35,7 @@
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Profile;
 import org.apache.maven.model.building.DefaultModelBuildingRequest;
+import org.apache.maven.model.building.DefaultModelProblem;
 import org.apache.maven.model.building.FileModelSource;
 import org.apache.maven.model.building.ModelBuilder;
 import org.apache.maven.model.building.ModelBuildingException;
@@ -382,10 +383,9 @@
 
                         if ( !moduleFile.isFile() )
                         {
-                            String source = toSourceHint( model );
                             ModelProblem problem =
-                                new ModelProblem( "Child module " + moduleFile + " of " +
source + " does not exist",
-                                                  ModelProblem.Severity.ERROR, source );
+                                new DefaultModelProblem( "Child module " + moduleFile + "
of " + pomFile
+                                    + " does not exist", ModelProblem.Severity.ERROR, model
);
                             result.getProblems().add( problem );
 
                             errors = true;
@@ -495,23 +495,4 @@
         return project;
     }
 
-    private String toSourceHint( Model model )
-    {
-        StringBuilder buffer = new StringBuilder( 192 );
-
-        buffer.append( model.getGroupId() );
-        buffer.append( ':' );
-        buffer.append( model.getArtifactId() );
-        buffer.append( ':' );
-        buffer.append( model.getVersion() );
-
-        File pomFile = model.getPomFile();
-        if ( pomFile != null )
-        {
-            buffer.append( " (" ).append( pomFile ).append( ")" );
-        }
-
-        return buffer.toString();
-    }
-
 }

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java?rev=804894&r1=804893&r2=804894&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
(original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
Mon Aug 17 08:19:55 2009
@@ -276,14 +276,14 @@
         }
         catch ( ModelParseException e )
         {
-            problems.add( new ModelProblem( "Non-parseable POM " + modelSource.getLocation()
+ ": " + e.getMessage(),
-                                            ModelProblem.Severity.FATAL, modelSource.getLocation(),
e ) );
+            problems.add( new DefaultModelProblem( "Non-parseable POM " + modelSource.getLocation()
+ ": "
+                + e.getMessage(), ModelProblem.Severity.FATAL, modelSource.getLocation(),
e ) );
             throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems()
);
         }
         catch ( IOException e )
         {
-            problems.add( new ModelProblem( "Non-readable POM " + modelSource.getLocation()
+ ": " + e.getMessage(),
-                                            ModelProblem.Severity.FATAL, modelSource.getLocation(),
e ) );
+            problems.add( new DefaultModelProblem( "Non-readable POM " + modelSource.getLocation()
+ ": "
+                + e.getMessage(), ModelProblem.Severity.FATAL, modelSource.getLocation(),
e ) );
             throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems()
);
         }
 

Added: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java?rev=804894&view=auto
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java
(added)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java
Mon Aug 17 08:19:55 2009
@@ -0,0 +1,130 @@
+package org.apache.maven.model.building;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.model.Model;
+
+/**
+ * Describes a problem that was encountered during model building. A problem can either be
an exception that was thrown
+ * or a simple string message. In addition, a problem carries a hint about its source, e.g.
the POM file that exhibits
+ * the problem.
+ * 
+ * @author Benjamin Bentmann
+ */
+public class DefaultModelProblem
+    implements ModelProblem
+{
+
+    private final String source;
+
+    private final String message;
+
+    private final Exception exception;
+
+    private final Severity severity;
+
+    /**
+     * Creates a new problem with the specified message.
+     * 
+     * @param message The message describing the problem, may be {@code null}.
+     * @param severity The severity level of the problem, may be {@code null} to default
to {@link Severity#ERROR}.
+     * @param source The source of the problem, may be {@code null}.
+     */
+    public DefaultModelProblem( String message, Severity severity, Model source )
+    {
+        this( message, severity, ModelProblemUtils.toSourceHint( source ), null );
+    }
+
+    /**
+     * Creates a new problem with the specified message.
+     * 
+     * @param message The message describing the problem, may be {@code null}.
+     * @param severity The severity level of the problem, may be {@code null} to default
to {@link Severity#ERROR}.
+     * @param source A hint about the source of the problem, may be {@code null}.
+     */
+    public DefaultModelProblem( String message, Severity severity, String source )
+    {
+        this( message, severity, source, null );
+    }
+
+    /**
+     * Creates a new problem with the specified message and exception.
+     * 
+     * @param message The message describing the problem, may be {@code null}.
+     * @param severity The severity level of the problem, may be {@code null} to default
to {@link Severity#ERROR}.
+     * @param source A hint about the source of the problem, may be {@code null}.
+     * @param exception The exception that caused this problem, may be {@code null}.
+     */
+    public DefaultModelProblem( String message, Severity severity, String source, Exception
exception )
+    {
+        this.message = message;
+        this.severity = ( severity != null ) ? severity : Severity.ERROR;
+        this.source = ( source != null ) ? source : "";
+        this.exception = exception;
+    }
+
+    public String getSource()
+    {
+        return source;
+    }
+
+    public Exception getException()
+    {
+        return exception;
+    }
+
+    public String getMessage()
+    {
+        String msg;
+
+        if ( message != null && message.length() > 0 )
+        {
+            msg = message;
+        }
+        else
+        {
+            msg = exception.getMessage();
+
+            if ( msg == null )
+            {
+                msg = "";
+            }
+        }
+
+        return msg;
+    }
+
+    public Severity getSeverity()
+    {
+        return severity;
+    }
+
+    @Override
+    public String toString()
+    {
+        StringBuilder buffer = new StringBuilder( 128 );
+
+        buffer.append( "[" ).append( getSeverity() ).append( "] " );
+        buffer.append( getSource() ).append( ": " ).append( getMessage() );
+
+        return buffer.toString();
+    }
+
+}

Propchange: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblemCollector.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblemCollector.java?rev=804894&r1=804893&r2=804894&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblemCollector.java
(original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblemCollector.java
Mon Aug 17 08:19:55 2009
@@ -98,32 +98,32 @@
 
     public void addFatalError( String message )
     {
-        problems.add( new ModelProblem( message, ModelProblem.Severity.FATAL, getSourceHint()
) );
+        problems.add( new DefaultModelProblem( message, ModelProblem.Severity.FATAL, getSourceHint()
) );
     }
 
     public void addFatalError( String message, Exception cause )
     {
-        problems.add( new ModelProblem( message, ModelProblem.Severity.FATAL, getSourceHint(),
cause ) );
+        problems.add( new DefaultModelProblem( message, ModelProblem.Severity.FATAL, getSourceHint(),
cause ) );
     }
 
     public void addError( String message )
     {
-        problems.add( new ModelProblem( message, ModelProblem.Severity.ERROR, getSourceHint()
) );
+        problems.add( new DefaultModelProblem( message, ModelProblem.Severity.ERROR, getSourceHint()
) );
     }
 
     public void addError( String message, Exception cause )
     {
-        problems.add( new ModelProblem( message, ModelProblem.Severity.ERROR, getSourceHint(),
cause ) );
+        problems.add( new DefaultModelProblem( message, ModelProblem.Severity.ERROR, getSourceHint(),
cause ) );
     }
 
     public void addWarning( String message )
     {
-        problems.add( new ModelProblem( message, ModelProblem.Severity.WARNING, getSourceHint()
) );
+        problems.add( new DefaultModelProblem( message, ModelProblem.Severity.WARNING, getSourceHint()
) );
     }
 
     public void addWarning( String message, Exception cause )
     {
-        problems.add( new ModelProblem( message, ModelProblem.Severity.WARNING, getSourceHint(),
cause ) );
+        problems.add( new DefaultModelProblem( message, ModelProblem.Severity.WARNING, getSourceHint(),
cause ) );
     }
 
 }

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblem.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblem.java?rev=804894&r1=804893&r2=804894&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblem.java
(original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblem.java
Mon Aug 17 08:19:55 2009
@@ -26,7 +26,7 @@
  * 
  * @author Benjamin Bentmann
  */
-public class ModelProblem
+public interface ModelProblem
 {
 
     /**
@@ -41,42 +41,6 @@
 
     }
 
-    private final String source;
-
-    private final String message;
-
-    private final Exception exception;
-
-    private final Severity severity;
-
-    /**
-     * Creates a new problem with the specified message.
-     * 
-     * @param message The message describing the problem, may be {@code null}.
-     * @param severity The severity level of the problem, may be {@code null} to default
to {@link Severity#ERROR}.
-     * @param source A hint about the source of the problem, may be {@code null}.
-     */
-    public ModelProblem( String message, Severity severity, String source )
-    {
-        this( message, severity, source, null );
-    }
-
-    /**
-     * Creates a new problem with the specified message and exception.
-     * 
-     * @param message The message describing the problem, may be {@code null}.
-     * @param severity The severity level of the problem, may be {@code null} to default
to {@link Severity#ERROR}.
-     * @param source A hint about the source of the problem, may be {@code null}.
-     * @param exception The exception that caused this problem, may be {@code null}.
-     */
-    public ModelProblem( String message, Severity severity, String source, Exception exception
)
-    {
-        this.message = message;
-        this.severity = ( severity != null ) ? severity : Severity.ERROR;
-        this.source = ( source != null ) ? source : "";
-        this.exception = exception;
-    }
-
     /**
      * Gets the hint about the source of the problem. While the syntax of this hint is unspecified
and depends on the
      * creator of the problem, the general expectation is that the hint provides sufficient
information to the user to
@@ -84,66 +48,27 @@
      * 
      * @return The hint about the source of the problem, never {@code null}.
      */
-    public String getSource()
-    {
-        return source;
-    }
+    public String getSource();
 
     /**
      * Gets the exception that caused this problem (if any).
      * 
      * @return The exception that caused this problem or {@code null} if not applicable.
      */
-    public Exception getException()
-    {
-        return exception;
-    }
+    public Exception getException();
 
     /**
      * Gets the message that describes this problem.
      * 
      * @return The message describing this problem, never {@code null}.
      */
-    public String getMessage()
-    {
-        String msg;
-
-        if ( message != null && message.length() > 0 )
-        {
-            msg = message;
-        }
-        else
-        {
-            msg = exception.getMessage();
-
-            if ( msg == null )
-            {
-                msg = "";
-            }
-        }
-
-        return msg;
-    }
+    public String getMessage();
 
     /**
      * Gets the severity level of this problem.
      * 
      * @return The severity level of this problem, never {@code null}.
      */
-    public Severity getSeverity()
-    {
-        return severity;
-    }
-
-    @Override
-    public String toString()
-    {
-        StringBuilder buffer = new StringBuilder( 128 );
-
-        buffer.append( "[" ).append( getSeverity() ).append( "] " );
-        buffer.append( getSource() ).append( ": " ).append( getMessage() );
-
-        return buffer.toString();
-    }
+    public Severity getSeverity();
 
 }



Mime
View raw message