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 2019/04/23 18:48:00 UTC

[maven] branch MNG-6643 created (now 52a4a10)

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

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


      at 52a4a10  [MNG-6643] - Version comparison CLI does not work anymore

This branch includes the following new commits:

     new 52a4a10  [MNG-6643] - Version comparison CLI does not work anymore

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-6643] - Version comparison CLI does not work anymore

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

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

commit 52a4a10d79522e07e9ffeed88d0822f7ebf045bf
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Tue Apr 23 20:47:45 2019 +0200

    [MNG-6643] - Version comparison CLI does not work anymore
---
 .../artifact/versioning/ComparableVersion.java     | 19 ++++++++----
 .../maven/artifact/versioning/StripTest.java       | 34 ++++++++++++++++++++++
 2 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java
index c0ad57d..f83c0a1 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java
@@ -29,8 +29,6 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Properties;
 
-import org.apache.commons.lang3.StringUtils;
-
 /**
  * <p>
  * Generic implementation of version comparison.
@@ -609,12 +607,23 @@ public class ComparableVersion
 
     private static String stripLeadingZeroes( String buf )
     {
-        String strippedBuf = StringUtils.stripStart( buf, "0" );
-        if ( strippedBuf.isEmpty() )
+        if (buf == null) {
+            buf  = "";
+        }
+        for (int i = 0; i < buf.length(); ++i) {
+            char c = buf.charAt(i);
+            if (c != '0') {
+                return buf.substring(i);
+            }
+        }
+        if ( buf.isEmpty() )
         {
             return "0";
         }
-        return strippedBuf;
+        else
+        {
+            return buf;
+        }
     }
 
     @Override
diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/StripTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/StripTest.java
new file mode 100644
index 0000000..1b0350d
--- /dev/null
+++ b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/StripTest.java
@@ -0,0 +1,34 @@
+package org.apache.maven.artifact.versioning;
+
+import org.junit.Test;
+
+public class StripTest {
+
+    private static String stripLeadingZeroes( String buf )
+    {
+        if (buf == null) {
+            buf  = "";
+        }
+        for (int i = 0; i < buf.length(); ++i) {
+            char c = buf.charAt(i);
+            if (c != '0') {
+                return buf.substring(i);
+            }
+        }
+        if ( buf.isEmpty() )
+        {
+            return "0";
+        }
+        else
+        {
+            return buf;
+        }
+    }
+
+    @Test
+    public void name() {
+        String s = "0000";
+        String result = stripLeadingZeroes("");
+        System.out.println("Result: '" + result + "'");
+    }
+}