maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tryg...@apache.org
Subject cvs commit: maven-components/maven-core/src/main/java/org/apache/maven/project/validation DefaultModelValidator.java
Date Fri, 30 Jul 2004 15:20:11 GMT
trygvis     2004/07/30 08:20:11

  Modified:    maven-core/src/main/java/org/apache/maven/project/validation
                        DefaultModelValidator.java
  Log:
  o Adding validation of <modelVersion>.
  
  Revision  Changes    Path
  1.4       +31 -6     maven-components/maven-core/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java
  
  Index: DefaultModelValidator.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultModelValidator.java	27 Jun 2004 07:39:08 -0000	1.3
  +++ DefaultModelValidator.java	30 Jul 2004 15:20:11 -0000	1.4
  @@ -28,13 +28,16 @@
   public class DefaultModelValidator
       implements ModelValidator
   {
  -    ///////////////////////////////////////////////////////////////////////////
  -    // ModelValidator Implementation
  +    // ----------------------------------------------------------------------
  +    // ModelValidator
  +    // ----------------------------------------------------------------------
   
       public ModelValidationResult validate( Model model )
       {
           ModelValidationResult result = new ModelValidationResult();
   
  +        validateStringEquals( "modelVersion", result, "4.0.0", model.getModelVersion()
);
  +
           validateStringNotEmpty( "groupId", result, model.getGroupId() );
   
           validateStringNotEmpty( "artifactId", result, model.getArtifactId() );
  @@ -59,8 +62,24 @@
           return result;
       }
   
  -    ///////////////////////////////////////////////////////////////////////////
  +    // ----------------------------------------------------------------------
       // Field validator
  +    // ----------------------------------------------------------------------
  +
  +    private boolean validateStringEquals( String fieldName, ModelValidationResult result,
String expected, String actual )
  +    {
  +        if ( !validateNotNull( fieldName, result, actual ) )
  +            return false;
  +
  +        if ( actual.equals( expected) )
  +        {
  +            return true;
  +        }
  +
  +        result.addMessage( "'" + fieldName + "' was '" + actual + "', but must be '" +
expected + "'." );
  +
  +        return false;
  +    }
   
       /**
        * Asserts:
  @@ -73,12 +92,16 @@
       private boolean validateStringNotEmpty( String fieldName, ModelValidationResult result,
String string )
       {
           if ( !validateNotNull( fieldName, result, string ) )
  +        {
               return false;
  +        }
   
           if ( string.length() > 0 )
  +        {
               return true;
  +        }
   
  -        result.addMessage( "'" + fieldName + "' is empty." );
  +        result.addMessage( "'" + fieldName + "' cannot be empty." );
   
           return false;
       }
  @@ -93,9 +116,11 @@
       private boolean validateNotNull( String fieldName, ModelValidationResult result, Object
object )
       {
           if ( object != null )
  +        {
               return true;
  +        }
   
  -        result.addMessage( "'" + fieldName + "' is missing." );
  +        result.addMessage( "'" + fieldName + "' must be set." );
   
           return false;
       }
  
  
  

Mime
View raw message