8172309: classpath wildcards code does not support --class-path
authorhenryjen
Fri, 27 Jan 2017 13:10:27 -0800
changeset 43330 6aa5f2938b75
parent 43329 4b34ab4c7ba1
child 43331 0bcbff9e43aa
8172309: classpath wildcards code does not support --class-path Reviewed-by: ksrini
jdk/src/java.base/share/native/libjli/java.c
jdk/src/java.base/share/native/libjli/wildcard.c
jdk/test/tools/launcher/ClassPathWildCard.sh
--- a/jdk/src/java.base/share/native/libjli/java.c	Fri Jan 27 16:27:52 2017 +0000
+++ b/jdk/src/java.base/share/native/libjli/java.c	Fri Jan 27 13:10:27 2017 -0800
@@ -1566,6 +1566,31 @@
     return (*env)->CallStaticObjectMethod(env, cls, mid);
 }
 
+static char* expandWildcardOnLongOpt(char* arg) {
+    char *p, *value;
+    size_t optLen, valueLen;
+    p = JLI_StrChr(arg, '=');
+
+    if (p == NULL || p[1] == '\0') {
+        JLI_ReportErrorMessage(ARG_ERROR1, arg);
+        exit(1);
+    }
+    p++;
+    value = (char *) JLI_WildcardExpandClasspath(p);
+    if (p == value) {
+        // no wildcard
+        return arg;
+    }
+
+    optLen = p - arg;
+    valueLen = JLI_StrLen(value);
+    p = JLI_MemAlloc(optLen + valueLen + 1);
+    memcpy(p, arg, optLen);
+    memcpy(p + optLen, value, valueLen);
+    p[optLen + valueLen + 1] = '\0';
+    return p;
+}
+
 /*
  * For tools, convert command line args thus:
  *   javac -cp foo:foo/"*" -J-ms32m ...
@@ -1616,14 +1641,17 @@
         if (arg[0] == '-') {
             if (arg[1] == 'J')
                 continue;
-            if (IsWildCardEnabled() && arg[1] == 'c'
-                && (JLI_StrCmp(arg, "-cp") == 0 ||
-                    JLI_StrCmp(arg, "-classpath") == 0)
-                && i < argc - 1) {
-                *nargv++ = arg;
-                *nargv++ = (char *) JLI_WildcardExpandClasspath(argv[i+1]);
-                i++;
-                continue;
+            if (IsWildCardEnabled()) {
+                if (IsClassPathOption(arg) && i < argc - 1) {
+                    *nargv++ = arg;
+                    *nargv++ = (char *) JLI_WildcardExpandClasspath(argv[i+1]);
+                    i++;
+                    continue;
+                }
+                if (JLI_StrCCmp(arg, "--class-path=") == 0) {
+                    *nargv++ = expandWildcardOnLongOpt(arg);
+                    continue;
+                }
             }
         }
         *nargv++ = arg;
--- a/jdk/src/java.base/share/native/libjli/wildcard.c	Fri Jan 27 16:27:52 2017 +0000
+++ b/jdk/src/java.base/share/native/libjli/wildcard.c	Fri Jan 27 13:10:27 2017 -0800
@@ -272,14 +272,16 @@
         (! exists(filename));
 }
 
-static void
+static int
 FileList_expandWildcards(JLI_List fl)
 {
     size_t i, j;
+    int expandedCnt = 0;
     for (i = 0; i < fl->size; i++) {
         if (isWildcard(fl->elements[i])) {
             JLI_List expanded = wildcardFileList(fl->elements[i]);
             if (expanded != NULL && expanded->size > 0) {
+                expandedCnt++;
                 JLI_MemFree(fl->elements[i]);
                 JLI_List_ensureCapacity(fl, fl->size + expanded->size);
                 for (j = fl->size - 1; j >= i+1; j--)
@@ -294,19 +296,20 @@
             JLI_List_free(expanded);
         }
     }
+    return expandedCnt;
 }
 
 const char *
 JLI_WildcardExpandClasspath(const char *classpath)
 {
-    char *expanded;
+    const char *expanded;
     JLI_List fl;
 
     if (JLI_StrChr(classpath, '*') == NULL)
         return classpath;
     fl = JLI_List_split(classpath, PATH_SEPARATOR);
-    FileList_expandWildcards(fl);
-    expanded = JLI_List_join(fl, PATH_SEPARATOR);
+    expanded = FileList_expandWildcards(fl) ?
+        JLI_List_join(fl, PATH_SEPARATOR) : classpath;
     JLI_List_free(fl);
     if (getenv(JLDEBUG_ENV_ENTRY) != 0)
         printf("Expanded wildcards:\n"
--- a/jdk/test/tools/launcher/ClassPathWildCard.sh	Fri Jan 27 16:27:52 2017 +0000
+++ b/jdk/test/tools/launcher/ClassPathWildCard.sh	Fri Jan 27 13:10:27 2017 -0800
@@ -125,7 +125,7 @@
   CheckFail TestA
 
   rm -f TestB${OUTEXT}
-  $JAVA${variant} -classpath JarDir/"*"$NOOP TestB || exit 1
+  $JAVA${variant} -cp JarDir/"*"$NOOP TestB || exit 1
   CheckFail TestB
 
 
@@ -134,11 +134,11 @@
   cp TestD/*.class JarDir
 
   rm -f TestC${OUTEXT}
-  $JAVA${variant} -classpath JarDir${PATHSEP}JarDir/"*"$NOOP TestC || exit 1
+  $JAVA${variant} --class-path JarDir${PATHSEP}JarDir/"*"$NOOP TestC || exit 1
   CheckFail TestC
 
   rm -f TestD${OUTEXT}
-  $JAVA${variant} -classpath JarDir${PATHSEP}JarDir/"*"$NOOP TestD || exit 1
+  $JAVA${variant} --class-path=JarDir${PATHSEP}JarDir/"*"$NOOP TestD || exit 1
   CheckFail TestD
 }