You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ge...@apache.org on 2021/05/10 20:16:04 UTC

[netbeans] branch delivery updated: [NETBEANS-5587] Fix regression in gavSplit

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

geertjan pushed a commit to branch delivery
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/delivery by this push:
     new 054a368  [NETBEANS-5587] Fix regression in gavSplit
     new 87dae1c  Merge pull request #2942 from lkishalmi/NETBEANS-5587
054a368 is described below

commit 054a368dac801bb6351541667275eed5d1d94798
Author: Laszlo Kishalmi <la...@gmail.com>
AuthorDate: Sat May 8 22:02:54 2021 -0700

    [NETBEANS-5587] Fix regression in gavSplit
---
 .../modules/gradle/GradleModuleFileCache21.java    | 10 ++--
 .../gradle/GradleModuleFileCache21Test.java        | 66 +++++++++++++++++++---
 2 files changed, 62 insertions(+), 14 deletions(-)

diff --git a/extide/gradle/src/org/netbeans/modules/gradle/GradleModuleFileCache21.java b/extide/gradle/src/org/netbeans/modules/gradle/GradleModuleFileCache21.java
index f0be755..b81a28a 100644
--- a/extide/gradle/src/org/netbeans/modules/gradle/GradleModuleFileCache21.java
+++ b/extide/gradle/src/org/netbeans/modules/gradle/GradleModuleFileCache21.java
@@ -247,17 +247,17 @@ public final class GradleModuleFileCache21 {
         // the general GAV format is - <group>:<artifact>:<version/snapshot>[:<classifier>][@extension]
         int firstColon = gav.indexOf(':'); // NOI18N
         int versionColon = gav.indexOf(':', firstColon + 1); // NOI18N
-        int versionEnd = gav.indexOf(':', versionColon + 1); // NO18N
+        int versionEnd = versionColon > firstColon ? gav.indexOf(':', versionColon + 1) : -1; // NO18N
 
+        if (firstColon == -1 || versionColon == -1 || firstColon == versionColon) {
+            throw new IllegalArgumentException("Invalid GAV format: '" + gav + "'"); //NOI18N
+        }
         int end = versionEnd == -1 ? gav.length() : versionEnd;
 
-        if (firstColon == -1 || firstColon == versionColon) {
-            throw new IllegalArgumentException("Invalid GAV format: " + gav); //NOI18N
-        }
         return new String[]{
             gav.substring(0, firstColon),
             gav.substring(firstColon + 1, versionColon),
-             gav.substring(versionColon + 1, end)
+            gav.substring(versionColon + 1, end)
         };
     }
 }
diff --git a/extide/gradle/test/unit/src/org/netbeans/modules/gradle/GradleModuleFileCache21Test.java b/extide/gradle/test/unit/src/org/netbeans/modules/gradle/GradleModuleFileCache21Test.java
index 1371d81..aa70337 100644
--- a/extide/gradle/test/unit/src/org/netbeans/modules/gradle/GradleModuleFileCache21Test.java
+++ b/extide/gradle/test/unit/src/org/netbeans/modules/gradle/GradleModuleFileCache21Test.java
@@ -35,9 +35,9 @@ public class GradleModuleFileCache21Test extends NbTestCase {
      */
     public void testGavSplitFixedVersion() throws Exception {
         String[] parts = GradleModuleFileCache21.gavSplit("io.micronaut:micronaut-core:2.3.4"); // NOI18N
-        assertEquals(parts[0], "io.micronaut"); // NOI18N
-        assertEquals(parts[1], "micronaut-core"); // NOI18N
-        assertEquals(parts[2], "2.3.4"); // NOI18N
+        assertEquals("io.micronaut", parts[0]);
+        assertEquals("micronaut-core", parts[1]);
+        assertEquals("2.3.4", parts[2]);
     }
 
     /**
@@ -46,15 +46,63 @@ public class GradleModuleFileCache21Test extends NbTestCase {
      */
     public void testGavSplitFixedSnapshotWithMavenTimestamp() throws Exception {
         String[] parts = GradleModuleFileCache21.gavSplit("io.micronaut:micronaut-core:2.3.4-SNAPSHOT:20210302.164619-21"); // NOI18N
-        assertEquals(parts[0], "io.micronaut"); // NOI18N
-        assertEquals(parts[1], "micronaut-core"); // NOI18N
-        assertEquals(parts[2], "2.3.4-SNAPSHOT"); // NOI18N
+        assertEquals("io.micronaut", parts[0]); 
+        assertEquals("micronaut-core", parts[1]);
+        assertEquals("2.3.4-SNAPSHOT", parts[2]);
     }
 
     public void testGavSplitFixedSnapshotWithoutUnqiueId() throws Exception {
         String[] parts = GradleModuleFileCache21.gavSplit("io.micronaut:micronaut-core:2.3.4-SNAPSHOT"); // NOI18N
-        assertEquals(parts[0], "io.micronaut"); // NOI18N
-        assertEquals(parts[1], "micronaut-core"); // NOI18N
-        assertEquals(parts[2], "2.3.4-SNAPSHOT"); // NOI18N
+        assertEquals("io.micronaut", parts[0]); 
+        assertEquals("micronaut-core", parts[1]);
+        assertEquals("2.3.4-SNAPSHOT", parts[2]);
+    }
+
+    public void testGavSplitIncomplete() throws Exception {
+        try {
+            GradleModuleFileCache21.gavSplit("junit:junit");
+            fail("IllegalArgumentException expected");
+        } catch (IllegalArgumentException iae) {
+            assertEquals("Invalid GAV format: 'junit:junit'", iae.getMessage());
+        }
+    }
+
+    public void testGavSplitIncomplete2() throws Exception {
+        try {
+            GradleModuleFileCache21.gavSplit("junit");
+            fail("IllegalArgumentException expected");
+        } catch (IllegalArgumentException iae) {
+            assertEquals("Invalid GAV format: 'junit'", iae.getMessage());
+        }
+    }
+
+    public void testGavSplitIncomplete3() throws Exception {
+        try {
+            GradleModuleFileCache21.gavSplit("");
+            fail("IllegalArgumentException expected");
+        } catch (IllegalArgumentException iae) {
+            assertEquals("Invalid GAV format: ''", iae.getMessage());
+        }
+    }
+
+    public void testGavSplitEmpty() throws Exception {
+        String[] parts = GradleModuleFileCache21.gavSplit("org.junit.jupiter:junit-jupiter-api:");
+        assertEquals("org.junit.jupiter", parts[0]); 
+        assertEquals("junit-jupiter-api", parts[1]);
+        assertEquals("", parts[2]);
+    }
+
+    public void testGavSplitEmpty2() throws Exception {
+        String[] parts = GradleModuleFileCache21.gavSplit("org.junit.jupiter::");
+        assertEquals("org.junit.jupiter", parts[0]); 
+        assertEquals("", parts[1]);
+        assertEquals("", parts[2]);
+    }
+
+    public void testGavSplitEmpty3() throws Exception {
+        String[] parts = GradleModuleFileCache21.gavSplit("::");
+        assertEquals("", parts[0]); 
+        assertEquals("", parts[1]);
+        assertEquals("", parts[2]);
     }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists