maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r965141 - in /maven/maven-3/trunk/maven-model-builder/src: main/java/org/apache/maven/model/validation/ test/java/org/apache/maven/model/validation/ test/resources/poms/validation/
Date Sat, 17 Jul 2010 21:53:47 GMT
Author: bentmann
Date: Sat Jul 17 21:53:47 2010
New Revision: 965141

URL: http://svn.apache.org/viewvc?rev=965141&view=rev
Log:
[MNG-4732] Version string validation

Added:
    maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-version.xml
  (with props)
Modified:
    maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
    maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java

Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java?rev=965141&r1=965140&r2=965141&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
(original)
+++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
Sat Jul 17 21:53:47 2010
@@ -61,6 +61,8 @@ public class DefaultModelValidator
 
     private static final String ID_REGEX = "[A-Za-z0-9_\\-.]+";
 
+    private static final String ILLEGAL_VERSION_CHARS = "\\/:\"<>|?*";
+
     public void validateRawModel( Model model, ModelBuildingRequest request, ModelProblemCollector
problems )
     {
         Parent parent = model.getParent();
@@ -252,6 +254,9 @@ public class DefaultModelValidator
 
             Severity errOn31 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1
);
 
+            validateBannedCharacters( "version", problems, errOn31, model.getVersion(), null,
model,
+                                      ILLEGAL_VERSION_CHARS );
+
             Build build = model.getBuild();
             if ( build != null )
             {
@@ -689,6 +694,27 @@ public class DefaultModelValidator
         return false;
     }
 
+    private boolean validateBannedCharacters( String fieldName, ModelProblemCollector problems,
Severity severity,
+                                              String string, String sourceHint, InputLocationTracker
tracker,
+                                              String banned )
+    {
+        if ( string != null )
+        {
+            for ( int i = string.length() - 1; i >= 0; i-- )
+            {
+                if ( banned.indexOf( string.charAt( i ) ) >= 0 )
+                {
+                    addViolation( problems, severity, fieldName, sourceHint,
+                                  "must not contain any of these characters " + banned +
" but found "
+                                      + string.charAt( i ), tracker );
+                    return false;
+                }
+            }
+        }
+
+        return true;
+    }
+
     private boolean validateVersion( String fieldName, ModelProblemCollector problems, Severity
severity,
                                      String string, String sourceHint, InputLocationTracker
tracker )
     {

Modified: maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java?rev=965141&r1=965140&r2=965141&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
(original)
+++ maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
Sat Jul 17 21:53:47 2010
@@ -508,4 +508,14 @@ public class DefaultModelValidatorTest
         assertTrue( result.getErrors().get( 0 ).contains( "test:b" ) );
     }
 
+    public void testBadVersion()
+        throws Exception
+    {
+        SimpleProblemCollector result = validate( "bad-version.xml" );
+
+        assertViolations( result, 0, 0, 1 );
+
+        assertContains( result.getWarnings().get( 0 ), "'version' must not contain any of
these characters" );
+    }
+
 }

Added: maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-version.xml
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-version.xml?rev=965141&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-version.xml
(added)
+++ maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-version.xml
Sat Jul 17 21:53:47 2010
@@ -0,0 +1,25 @@
+<!--
+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.
+-->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>foo</groupId>
+  <artifactId>bar</artifactId>
+  <version>this\is/bad</version>
+</project>

Propchange: maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-version.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-version.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message