You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2019/07/10 14:48:12 UTC

[maven] branch MNG-6705 created (now c38f3e4)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch MNG-6705
in repository https://gitbox.apache.org/repos/asf/maven.git.


      at c38f3e4  [MNG-6705] Speep up Artifact version check and Parent interpolation

This branch includes the following new commits:

     new c38f3e4  [MNG-6705] Speep up Artifact version check and Parent interpolation

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven] 01/01: [MNG-6705] Speep up Artifact version check and Parent interpolation

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch MNG-6705
in repository https://gitbox.apache.org/repos/asf/maven.git

commit c38f3e44a2646af301f38c7f8fe99f17fc06dd34
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Fri Jun 28 10:44:10 2019 +0200

    [MNG-6705] Speep up Artifact version check and Parent interpolation
    
    This closes #260
---
 .../org/apache/maven/artifact/ArtifactUtils.java   | 40 +++++++++++++++-------
 .../org/apache/maven/artifact/DefaultArtifact.java | 12 +------
 .../maven/model/building/DefaultModelBuilder.java  |  9 +++--
 3 files changed, 34 insertions(+), 27 deletions(-)

diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
index a0f18ad..bd76edd 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
@@ -54,17 +54,22 @@ public final class ArtifactUtils
 
     public static String toSnapshotVersion( String version )
     {
-        Validate.notBlank( version, "version can neither be null, empty nor blank" );
+        notBlank( version, "version can neither be null, empty nor blank" );
 
-        Matcher m = Artifact.VERSION_FILE_PATTERN.matcher( version );
-        if ( m.matches() )
+        int lastHyphen = version.lastIndexOf( '-' );
+        if ( lastHyphen > 0 )
         {
-            return m.group( 1 ) + "-" + Artifact.SNAPSHOT_VERSION;
-        }
-        else
-        {
-            return version;
+            int prevHyphen = version.lastIndexOf( '-', lastHyphen - 1 );
+            if ( prevHyphen > 0 )
+            {
+                Matcher m = Artifact.VERSION_FILE_PATTERN.matcher( version );
+                if ( m.matches() )
+                {
+                    return m.group( 1 ) + "-" + Artifact.SNAPSHOT_VERSION;
+                }
+            }
         }
+        return version;
     }
 
     public static String versionlessKey( Artifact artifact )
@@ -74,8 +79,8 @@ public final class ArtifactUtils
 
     public static String versionlessKey( String groupId, String artifactId )
     {
-        Validate.notBlank( groupId, "groupId can neither be null, empty nor blank" );
-        Validate.notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
+        notBlank( groupId, "groupId can neither be null, empty nor blank" );
+        notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
 
         return groupId + ":" + artifactId;
     }
@@ -87,13 +92,22 @@ public final class ArtifactUtils
 
     public static String key( String groupId, String artifactId, String version )
     {
-        Validate.notBlank( groupId, "groupId can neither be null, empty nor blank" );
-        Validate.notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
-        Validate.notBlank( version, "version can neither be null, empty nor blank" );
+        notBlank( groupId, "groupId can neither be null, empty nor blank" );
+        notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
+        notBlank( version, "version can neither be null, empty nor blank" );
 
         return groupId + ":" + artifactId + ":" + version;
     }
 
+    private static void notBlank( String str, String message )
+    {
+        int c = str != null && str.length() > 0 ? str.charAt( 0 ) : 0;
+        if ( ( c < '0' || c > '9' ) && ( c < 'a' || c > 'z' ) )
+        {
+            Validate.notBlank( str, message );
+        }
+    }
+
     public static Map<String, Artifact> artifactMapByVersionlessId( Collection<Artifact> artifacts )
     {
         Map<String, Artifact> artifactMap = new LinkedHashMap<>();
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
index 3fa1907..d63d6c9 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
@@ -25,7 +25,6 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.regex.Matcher;
 
 import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.artifact.metadata.ArtifactMetadata;
@@ -387,16 +386,7 @@ public class DefaultArtifact
 
     protected void setBaseVersionInternal( String baseVersion )
     {
-        Matcher m = VERSION_FILE_PATTERN.matcher( baseVersion );
-
-        if ( m.matches() )
-        {
-            this.baseVersion = m.group( 1 ) + "-" + SNAPSHOT_VERSION;
-        }
-        else
-        {
-            this.baseVersion = baseVersion;
-        }
+        this.baseVersion = ArtifactUtils.toSnapshotVersion( baseVersion );
     }
 
     public int compareTo( Artifact a )
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index d127f56..f981944 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -396,9 +396,12 @@ public class DefaultModelBuilder
         if ( resultModel.getParent() != null )
         {
             final ModelData parentData = lineage.get( 1 );
-            final Model interpolatedParent = interpolateModel( parentData.getModel(), request, problems );
-            // parentData.setModel( interpolatedParent );
-            parentData.setVersion( interpolatedParent.getVersion() );
+            if ( parentData.getVersion() == null || parentData.getVersion().contains( "${" ) )
+            {
+                final Model interpolatedParent = interpolateModel( parentData.getModel(), request, problems );
+                // parentData.setModel( interpolatedParent );
+                parentData.setVersion( interpolatedParent.getVersion() );
+            }
         }
 
         // url normalization