You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2021/06/08 13:36:27 UTC

[karaf] branch karaf-4.2.x updated: Fix version parsing

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

jbonofre pushed a commit to branch karaf-4.2.x
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/karaf-4.2.x by this push:
     new 6ea281a  Fix version parsing
6ea281a is described below

commit 6ea281a144737d4b568746828a648b3e7b8b66be
Author: Marten Gajda <ma...@dmfs.org>
AuthorDate: Tue Jun 8 15:27:20 2021 +0200

    Fix version parsing
    
    Make the first group of the regexp non-greedy to ensure it won't swallow
    the build meta data part. In particular, with a greedy first group it
    swallows everything up to the last dash that's followed by a
    digit, something that's quite common in SNAPSHOT builds.
    As a result a name like `foobar-1.0.0-PR-4-SNAPSHOT.jar` was parsed into
    version `4.0.0-SNAPSHOT`.
    
    (cherry picked from commit 40061af9e81b58a4394529b465b068200e1597a3)
---
 .../java/org/apache/karaf/util/DeployerUtils.java  |  2 +-
 .../org/apache/karaf/util/DeployerUtilsTest.java   | 47 ++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/util/src/main/java/org/apache/karaf/util/DeployerUtils.java b/util/src/main/java/org/apache/karaf/util/DeployerUtils.java
index 26171d3..3410f05 100644
--- a/util/src/main/java/org/apache/karaf/util/DeployerUtils.java
+++ b/util/src/main/java/org/apache/karaf/util/DeployerUtils.java
@@ -29,7 +29,7 @@ public final class DeployerUtils {
 
     private static final String DEFAULT_VERSION = "0.0.0";
 
-    private static final Pattern ARTIFACT_MATCHER = Pattern.compile("(.+)(?:-(\\d+)(?:\\.(\\d+)(?:\\.(\\d+))?)?(?:[^a-zA-Z0-9](.*))?)(?:\\.([^\\.]+))", Pattern.DOTALL);
+    private static final Pattern ARTIFACT_MATCHER = Pattern.compile("(.+?)(?:-(\\d+)(?:\\.(\\d+)(?:\\.(\\d+))?)?(?:[^a-zA-Z0-9](.*))?)(?:\\.([^\\.]+))", Pattern.DOTALL);
     private static final Pattern FUZZY_MODIFIDER = Pattern.compile("(?:\\d+[.-])*(.*)", Pattern.DOTALL);
 
     /**
diff --git a/util/src/test/java/org/apache/karaf/util/DeployerUtilsTest.java b/util/src/test/java/org/apache/karaf/util/DeployerUtilsTest.java
new file mode 100644
index 0000000..0e0e5c7
--- /dev/null
+++ b/util/src/test/java/org/apache/karaf/util/DeployerUtilsTest.java
@@ -0,0 +1,47 @@
+package org.apache.karaf.util;
+
+import junit.framework.TestCase;
+
+import org.junit.Test;
+
+import static org.apache.karaf.util.DeployerUtils.extractNameVersionType;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+
+public class DeployerUtilsTest extends TestCase
+{
+    @Test
+    public void test()
+    {
+        assertThat(
+            extractNameVersionType("foobarbaz-1.jar"),
+            equalTo(new String[]{"foobarbaz", "1", "jar"})
+        );
+
+        assertThat(
+            extractNameVersionType("foobarbaz-1.0.jar"),
+            equalTo(new String[]{"foobarbaz", "1.0", "jar"})
+        );
+
+        assertThat(
+            extractNameVersionType("foobarbaz-1.0.0.jar"),
+            equalTo(new String[]{"foobarbaz", "1.0.0", "jar"})
+        );
+
+        assertThat(
+            extractNameVersionType("foobarbaz-1-PR-4-SNAPSHOT.jar"),
+            equalTo(new String[]{"foobarbaz", "1.0.0.PR-4-SNAPSHOT", "jar"})
+        );
+
+        assertThat(
+            extractNameVersionType("foobarbaz-1.0-PR-4-SNAPSHOT.jar"),
+            equalTo(new String[]{"foobarbaz", "1.0.0.PR-4-SNAPSHOT", "jar"})
+        );
+
+        assertThat(
+            extractNameVersionType("foobarbaz-1.0.0-PR-4-SNAPSHOT.jar"),
+            equalTo(new String[]{"foobarbaz", "1.0.0.PR-4-SNAPSHOT", "jar"})
+        );
+    }
+}
\ No newline at end of file