maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r1054743 - 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 Mon, 03 Jan 2011 20:45:41 GMT
Author: bentmann
Date: Mon Jan  3 20:45:41 2011
New Revision: 1054743

URL: http://svn.apache.org/viewvc?rev=1054743&view=rev
Log:
[MNG-4957] Emit validation warning when project version uses irregular SNAPSHOT version string

Added:
    maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-snapshot-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=1054743&r1=1054742&r2=1054743&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
Mon Jan  3 20:45:41 2011
@@ -273,6 +273,7 @@ public class DefaultModelValidator
 
             validateBannedCharacters( "version", problems, errOn31, model.getVersion(), null,
model,
                                       ILLEGAL_VERSION_CHARS );
+            validateProperSnapshotVersion( "version", problems, errOn31, model.getVersion(),
null, model );
 
             Build build = model.getBuild();
             if ( build != null )
@@ -789,6 +790,24 @@ public class DefaultModelValidator
         return true;
     }
 
+    private boolean validateProperSnapshotVersion( String fieldName, ModelProblemCollector
problems, Severity severity,
+                                                   String string, String sourceHint, InputLocationTracker
tracker )
+    {
+        if ( string == null || string.length() <= 0 )
+        {
+            return true;
+        }
+
+        if ( string.endsWith( "SNAPSHOT" ) && !string.endsWith( "-SNAPSHOT" ) )
+        {
+            addViolation( problems, severity, fieldName, sourceHint, "uses an unsupported
snapshot version format"
+                + ", should be '*-SNAPSHOT' instead.", tracker );
+            return false;
+        }
+
+        return true;
+    }
+
     private boolean validatePluginVersion( String fieldName, ModelProblemCollector problems,
String string,
                                            String sourceHint, InputLocationTracker tracker,
                                            ModelBuildingRequest request )

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=1054743&r1=1054742&r2=1054743&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
Mon Jan  3 20:45:41 2011
@@ -526,6 +526,16 @@ public class DefaultModelValidatorTest
         assertContains( result.getWarnings().get( 0 ), "'version' must not contain any of
these characters" );
     }
 
+    public void testBadSnapshotVersion()
+        throws Exception
+    {
+        SimpleProblemCollector result = validate( "bad-snapshot-version.xml" );
+
+        assertViolations( result, 0, 0, 1 );
+
+        assertContains( result.getWarnings().get( 0 ), "'version' uses an unsupported snapshot
version format" );
+    }
+
     public void testBadRepositoryId()
         throws Exception
     {

Added: maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-snapshot-version.xml
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-snapshot-version.xml?rev=1054743&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-snapshot-version.xml
(added)
+++ maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-snapshot-version.xml
Mon Jan  3 20:45:41 2011
@@ -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>1.2.3.SNAPSHOT</version>
+</project>

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

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



Mime
View raw message