You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2017/12/30 19:03:31 UTC

maven git commit: [MNG-6305] Validation of CI friendly version incorrect o Cleaned up code. o Fixed RegEx greedy/non greedy usage. Added another test for that.

Repository: maven
Updated Branches:
  refs/heads/MNG-6305-validation-of-ci-friendly 14bd534ea -> 8fcd17bc6


[MNG-6305] Validation of CI friendly version incorrect
 o Cleaned up code.
 o Fixed RegEx greedy/non greedy usage. Added another test for that.


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/8fcd17bc
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/8fcd17bc
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/8fcd17bc

Branch: refs/heads/MNG-6305-validation-of-ci-friendly
Commit: 8fcd17bc6f9af19653f6c225a93b03082aff24e5
Parents: 14bd534
Author: Karl Heinz Marbaise <kh...@apache.org>
Authored: Sat Dec 30 20:02:36 2017 +0100
Committer: Karl Heinz Marbaise <kh...@apache.org>
Committed: Sat Dec 30 20:02:36 2017 +0100

----------------------------------------------------------------------
 .../model/validation/DefaultModelValidator.java | 58 +++-----------------
 .../validation/DefaultModelValidatorTest.java   | 39 ++++++++-----
 .../ok-ci-friendly-all-expressions.xml          | 31 +++++++++++
 3 files changed, 63 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/8fcd17bc/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
----------------------------------------------------------------------
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
index d355454..da4ba07 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
@@ -66,14 +66,7 @@ public class DefaultModelValidator
     implements ModelValidator
 {
 
-    private static final Pattern PATTERN_SHA1_PROPERTY =
-        Pattern.compile( AbstractStringBasedModelInterpolator.SHA1_PROPERTY_EXPRESSION, Pattern.LITERAL );
-
-    private static final Pattern PATTERN_CHANGELIST_PROPERTY =
-        Pattern.compile( AbstractStringBasedModelInterpolator.CHANGELIST_PROPERTY_EXPRESSION, Pattern.LITERAL );
-
-    private static final Pattern PATTERN_REVISION_PROPERTY =
-        Pattern.compile( AbstractStringBasedModelInterpolator.REVISION_PROPERTY_EXPRESSION, Pattern.LITERAL );
+    private static final Pattern CI_FRIENDLY_EXPRESSION = Pattern.compile( "\\$\\{(.+?)\\}" );
 
     private static final Pattern ID_REGEX = Pattern.compile( "[A-Za-z0-9_\\-.]+" );
 
@@ -865,7 +858,6 @@ public class DefaultModelValidator
     private boolean validateVersionNoExpression( String fieldName, ModelProblemCollector problems, Severity severity,
                                                  Version version, String string, InputLocationTracker tracker )
     {
-
         if ( !hasExpression( string ) )
         {
             return true;
@@ -878,56 +870,22 @@ public class DefaultModelValidator
         // revision
         // sha1
         //
-        
-        Pattern p = Pattern.compile( "\\$\\{(.+)\\}" );
-        
         List<String> ciVersions = Arrays.asList( AbstractStringBasedModelInterpolator.REVISION_PROPERTY,
-                       AbstractStringBasedModelInterpolator.CHANGELIST_PROPERTY, 
-                       AbstractStringBasedModelInterpolator.SHA1_PROPERTY );
-        Matcher m = p.matcher( string.trim() );
+                                                 AbstractStringBasedModelInterpolator.CHANGELIST_PROPERTY,
+                                                 AbstractStringBasedModelInterpolator.SHA1_PROPERTY );
+        Matcher m = CI_FRIENDLY_EXPRESSION.matcher( string.trim() );
         while ( m.find() )
         {
             if ( !ciVersions.contains( m.group( 1 ) ) )
             {
-                addViolation( problems, severity, version, fieldName, null, "contains an expression but should be a constant.",
-                              tracker );
-                
+                addViolation( problems, severity, version, fieldName, null,
+                              "contains an expression but should be a constant.", tracker );
+
                 return false;
             }
         }
-        
+
         return true;
-        
-//        string = string.trim();
-//        if ( string.contains( AbstractStringBasedModelInterpolator.CHANGELIST_PROPERTY_EXPRESSION )
-//            || string.contains( AbstractStringBasedModelInterpolator.REVISION_PROPERTY_EXPRESSION )
-//            || string.contains( AbstractStringBasedModelInterpolator.SHA1_PROPERTY_EXPRESSION ) )
-//        {
-//            //@formatter:off
-//            string =
-//                PATTERN_REVISION_PROPERTY
-//                    .matcher( string )
-//                    .replaceAll( AbstractStringBasedModelInterpolator.REVISION_PROPERTY );
-//            string =
-//                PATTERN_CHANGELIST_PROPERTY
-//                    .matcher( string )
-//                    .replaceAll( AbstractStringBasedModelInterpolator.CHANGELIST_PROPERTY );
-//            string =
-//                PATTERN_SHA1_PROPERTY
-//                    .matcher( string )
-//                    .replaceAll( AbstractStringBasedModelInterpolator.SHA1_PROPERTY );
-//            //@formatter:on
-//
-//            if ( !hasExpression( string ) )
-//            {
-//                return true;
-//            }
-//        }
-//
-//        addViolation( problems, severity, version, fieldName, null, "contains an expression but should be a constant.",
-//                      tracker );
-//
-//        return false;
     }
 
     private boolean hasExpression( String value )

http://git-wip-us.apache.org/repos/asf/maven/blob/8fcd17bc/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
----------------------------------------------------------------------
diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
index 687f99c..0bb3bd4 100644
--- a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
+++ b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
@@ -419,18 +419,19 @@ public class DefaultModelValidatorTest
         assertViolations( result, 0, 0, 1 );
 
         assertContains( result.getWarnings().get( 0 ),
-                "'dependencies.dependency.systemPath' for test:a:jar should use a variable instead of a hard-coded path" );
+                        "'dependencies.dependency.systemPath' for test:a:jar should use a variable instead of a hard-coded path" );
 
-        SimpleProblemCollector result_31 = validateRaw( "hard-coded-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
+        SimpleProblemCollector result_31 =
+            validateRaw( "hard-coded-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
 
         assertViolations( result_31, 0, 0, 3 );
 
         assertContains( result_31.getWarnings().get( 0 ),
-                "'dependencies.dependency.scope' for test:a:jar declares usage of deprecated 'system' scope" );
+                        "'dependencies.dependency.scope' for test:a:jar declares usage of deprecated 'system' scope" );
         assertContains( result_31.getWarnings().get( 1 ),
-                "'dependencies.dependency.systemPath' for test:a:jar should use a variable instead of a hard-coded path" );
+                        "'dependencies.dependency.systemPath' for test:a:jar should use a variable instead of a hard-coded path" );
         assertContains( result_31.getWarnings().get( 2 ),
-                "'dependencies.dependency.scope' for test:b:jar declares usage of deprecated 'system' scope" );
+                        "'dependencies.dependency.scope' for test:b:jar declares usage of deprecated 'system' scope" );
 
     }
 
@@ -625,22 +626,23 @@ public class DefaultModelValidatorTest
         assertViolations( result, 0, 0, 2 );
 
         assertContains( result.getWarnings().get( 0 ),
-                "'dependencies.dependency.systemPath' for test:a:jar should not point at files within the project directory" );
+                        "'dependencies.dependency.systemPath' for test:a:jar should not point at files within the project directory" );
         assertContains( result.getWarnings().get( 1 ),
-                "'dependencies.dependency.systemPath' for test:b:jar should not point at files within the project directory" );
+                        "'dependencies.dependency.systemPath' for test:b:jar should not point at files within the project directory" );
 
-        SimpleProblemCollector result_31 = validateRaw( "basedir-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
+        SimpleProblemCollector result_31 =
+            validateRaw( "basedir-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
 
         assertViolations( result_31, 0, 0, 4 );
 
         assertContains( result_31.getWarnings().get( 0 ),
-                "'dependencies.dependency.scope' for test:a:jar declares usage of deprecated 'system' scope" );
+                        "'dependencies.dependency.scope' for test:a:jar declares usage of deprecated 'system' scope" );
         assertContains( result_31.getWarnings().get( 1 ),
-                "'dependencies.dependency.systemPath' for test:a:jar should not point at files within the project directory" );
+                        "'dependencies.dependency.systemPath' for test:a:jar should not point at files within the project directory" );
         assertContains( result_31.getWarnings().get( 2 ),
-                "'dependencies.dependency.scope' for test:b:jar declares usage of deprecated 'system' scope" );
+                        "'dependencies.dependency.scope' for test:b:jar declares usage of deprecated 'system' scope" );
         assertContains( result_31.getWarnings().get( 3 ),
-                "'dependencies.dependency.systemPath' for test:b:jar should not point at files within the project directory" );
+                        "'dependencies.dependency.systemPath' for test:b:jar should not point at files within the project directory" );
     }
 
     public void testInvalidVersionInPluginManagement()
@@ -703,16 +705,16 @@ public class DefaultModelValidatorTest
     }
 
     public void testDeprecatedDependencyMetaversionsLatestAndRelease()
-            throws Exception
+        throws Exception
     {
         SimpleProblemCollector result = validateRaw( "deprecated-dependency-metaversions-latest-and-release.xml" );
 
         assertViolations( result, 0, 0, 2 );
 
         assertContains( result.getWarnings().get( 0 ),
-               "'dependencies.dependency.version' for test:a:jar is either LATEST or RELEASE (both of them are being deprecated)" );
+                        "'dependencies.dependency.version' for test:a:jar is either LATEST or RELEASE (both of them are being deprecated)" );
         assertContains( result.getWarnings().get( 1 ),
-                "'dependencies.dependency.version' for test:b:jar is either LATEST or RELEASE (both of them are being deprecated)" );
+                        "'dependencies.dependency.version' for test:b:jar is either LATEST or RELEASE (both of them are being deprecated)" );
     }
 
     public void testSelfReferencingDependencyInRawModel()
@@ -748,6 +750,13 @@ public class DefaultModelValidatorTest
         assertViolations( result, 0, 0, 0 );
     }
 
+    public void testCiFriendlyAllExpressions()
+        throws Exception
+    {
+        SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-all-expressions.xml" );
+        assertViolations( result, 0, 0, 0 );
+    }
+
     public void testCiFriendlyBad()
         throws Exception
     {

http://git-wip-us.apache.org/repos/asf/maven/blob/8fcd17bc/maven-model-builder/src/test/resources/poms/validation/raw-model/ok-ci-friendly-all-expressions.xml
----------------------------------------------------------------------
diff --git a/maven-model-builder/src/test/resources/poms/validation/raw-model/ok-ci-friendly-all-expressions.xml b/maven-model-builder/src/test/resources/poms/validation/raw-model/ok-ci-friendly-all-expressions.xml
new file mode 100644
index 0000000..860b482
--- /dev/null
+++ b/maven-model-builder/src/test/resources/poms/validation/raw-model/ok-ci-friendly-all-expressions.xml
@@ -0,0 +1,31 @@
+<!--
+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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>com.example.group</groupId>
+	<artifactId>valid-version-sha1</artifactId>
+	<version>${revision}${changelist}${sha1}</version>
+
+	<description>
+        This will test if the validation for the ci friendly versions
+        is working correct.
+	</description>
+</project>
\ No newline at end of file