src/java.base/windows/native/libjli/java_md.c

Print this page




 973 PostJVMInit(JNIEnv *env, jclass mainClass, JavaVM *vm)
 974 {
 975     // stubbed out for windows and *nixes.
 976 }
 977 
 978 void
 979 RegisterThread()
 980 {
 981     // stubbed out for windows and *nixes.
 982 }
 983 
 984 /*
 985  * on windows, we return a false to indicate this option is not applicable
 986  */
 987 jboolean
 988 ProcessPlatformOption(const char *arg)
 989 {
 990     return JNI_FALSE;
 991 }
 992 




















 993 /*
 994  * At this point we have the arguments to the application, and we need to
 995  * check with original stdargs in order to compare which of these truly
 996  * needs expansion. cmdtoargs will specify this if it finds a bare
 997  * (unquoted) argument containing a glob character(s) ie. * or ?
 998  */
 999 jobjectArray
1000 CreateApplicationArgs(JNIEnv *env, char **strv, int argc)
1001 {
1002     int i, j, idx;
1003     size_t tlen;
1004     jobjectArray outArray, inArray;
1005     char *ostart, *astart, **nargv;
1006     jboolean needs_expansion = JNI_FALSE;
1007     jmethodID mid;
1008     int stdargc;
1009     StdArg *stdargs;

1010     jclass cls = GetLauncherHelperClass(env);
1011     NULL_CHECK0(cls);
1012 
1013     if (argc == 0) {
1014         return NewPlatformStringArray(env, strv, argc);
1015     }
1016     // the holy grail we need to compare with.
1017     stdargs = JLI_GetStdArgs();
1018     stdargc = JLI_GetStdArgc();
1019 


1020     // sanity check, this should never happen
1021     if (argc > stdargc) {
1022         JLI_TraceLauncher("Warning: app args is larger than the original, %d %d\n", argc, stdargc);
1023         JLI_TraceLauncher("passing arguments as-is.\n");
1024         return NewPlatformStringArray(env, strv, argc);
1025     }
1026 
1027     // sanity check, match the args we have, to the holy grail
1028     idx = stdargc - argc;
1029     ostart = stdargs[idx].arg;
1030     astart = strv[0];
1031     // sanity check, ensure that the first argument of the arrays are the same
1032     if (JLI_StrCmp(ostart, astart) != 0) {
1033         // some thing is amiss the args don't match
1034         JLI_TraceLauncher("Warning: app args parsing error\n");
1035         JLI_TraceLauncher("passing arguments as-is\n");
1036         return NewPlatformStringArray(env, strv, argc);
1037     }
1038 
1039     // make a copy of the args which will be expanded in java if required.
1040     nargv = (char **)JLI_MemAlloc(argc * sizeof(char*));
1041     for (i = 0, j = idx; i < argc; i++, j++) {
1042         jboolean arg_expand = (JLI_StrCmp(stdargs[j].arg, strv[i]) == 0)
1043                                 ? stdargs[j].has_wildcard
1044                                 : JNI_FALSE;
1045         if (needs_expansion == JNI_FALSE)
1046             needs_expansion = arg_expand;
1047 
1048         // indicator char + String + NULL terminator, the java method will strip
1049         // out the first character, the indicator character, so no matter what
1050         // we add the indicator
1051         tlen = 1 + JLI_StrLen(strv[i]) + 1;
1052         nargv[i] = (char *) JLI_MemAlloc(tlen);
1053         if (JLI_Snprintf(nargv[i], tlen, "%c%s", arg_expand ? 'T' : 'F',
1054                          strv[i]) < 0) {
1055             return NULL;
1056         }
1057         JLI_TraceLauncher("%s\n", nargv[i]);
1058     }
1059 
1060     if (!needs_expansion) {
1061         // clean up any allocated memory and return back the old arguments
1062         for (i = 0 ; i < argc ; i++) {
1063             JLI_MemFree(nargv[i]);
1064         }
1065         JLI_MemFree(nargv);
1066         return NewPlatformStringArray(env, strv, argc);
1067     }
1068     NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls,
1069                                                 "expandArgs",
1070                                                 "([Ljava/lang/String;)[Ljava/lang/String;"));
1071 
1072     // expand the arguments that require expansion, the java method will strip
1073     // out the indicator character.
1074     NULL_CHECK0(inArray = NewPlatformStringArray(env, nargv, argc));
1075     outArray = (*env)->CallStaticObjectMethod(env, cls, mid, inArray);
1076     for (i = 0; i < argc; i++) {
1077         JLI_MemFree(nargv[i]);
1078     }
1079     JLI_MemFree(nargv);

1080     return outArray;
1081 }


 973 PostJVMInit(JNIEnv *env, jclass mainClass, JavaVM *vm)
 974 {
 975     // stubbed out for windows and *nixes.
 976 }
 977 
 978 void
 979 RegisterThread()
 980 {
 981     // stubbed out for windows and *nixes.
 982 }
 983 
 984 /*
 985  * on windows, we return a false to indicate this option is not applicable
 986  */
 987 jboolean
 988 ProcessPlatformOption(const char *arg)
 989 {
 990     return JNI_FALSE;
 991 }
 992 
 993 int
 994 filterArgs(StdArg *stdargs, const int nargc, StdArg **pargv) {
 995     StdArg* argv = NULL;
 996     int nargs = 0;
 997     int i;
 998 
 999     /* Copy the non-vm args */
1000     for (i = 0; i < nargc ; i++) {
1001         const char *arg = stdargs[i].arg;
1002         if (arg[0] != '-' || arg[1] != 'J') {
1003             argv = (StdArg*) JLI_MemRealloc(argv, (nargs+1) * sizeof(StdArg));
1004             argv[nargs].arg = JLI_StringDup(arg);
1005             argv[nargs].has_wildcard = stdargs[i].has_wildcard;
1006             nargs++;
1007         }
1008     }
1009     *pargv = argv;
1010     return nargs;
1011 }
1012 
1013 /*
1014  * At this point we have the arguments to the application, and we need to
1015  * check with original stdargs in order to compare which of these truly
1016  * needs expansion. cmdtoargs will specify this if it finds a bare
1017  * (unquoted) argument containing a glob character(s) ie. * or ?
1018  */
1019 jobjectArray
1020 CreateApplicationArgs(JNIEnv *env, char **strv, int argc)
1021 {
1022     int i, j, idx;
1023     size_t tlen;
1024     jobjectArray outArray, inArray;
1025     char *ostart, *astart, **nargv;
1026     jboolean needs_expansion = JNI_FALSE;
1027     jmethodID mid;
1028     int filteredargc, stdargc;
1029     StdArg *stdargs;
1030     StdArg *filteredargs;
1031     jclass cls = GetLauncherHelperClass(env);
1032     NULL_CHECK0(cls);
1033 
1034     if (argc == 0) {
1035         return NewPlatformStringArray(env, strv, argc);
1036     }
1037     // the holy grail we need to compare with.
1038     stdargs = JLI_GetStdArgs();
1039     stdargc = JLI_GetStdArgc();
1040 
1041     filteredargc = filterArgs(stdargs, stdargc, &filteredargs);
1042 
1043     // sanity check, this should never happen
1044     if (argc > stdargc) {
1045         JLI_TraceLauncher("Warning: app args is larger than the original, %d %d\n", argc, stdargc);
1046         JLI_TraceLauncher("passing arguments as-is.\n");
1047         return NewPlatformStringArray(env, strv, argc);
1048     }
1049 
1050     // sanity check, match the args we have, to the holy grail
1051     idx = filteredargc - argc;
1052     ostart = filteredargs[idx].arg;
1053     astart = strv[0];
1054     // sanity check, ensure that the first argument of the arrays are the same
1055     if (JLI_StrCmp(ostart, astart) != 0) {
1056         // some thing is amiss the args don't match
1057         JLI_TraceLauncher("Warning: app args parsing error\n");
1058         JLI_TraceLauncher("passing arguments as-is\n");
1059         return NewPlatformStringArray(env, strv, argc);
1060     }
1061 
1062     // make a copy of the args which will be expanded in java if required.
1063     nargv = (char **)JLI_MemAlloc(argc * sizeof(char*));
1064     for (i = 0, j = idx; i < argc; i++, j++) {
1065         jboolean arg_expand = (JLI_StrCmp(filteredargs[j].arg, strv[i]) == 0)
1066                                 ? filteredargs[j].has_wildcard
1067                                 : JNI_FALSE;
1068         if (needs_expansion == JNI_FALSE)
1069             needs_expansion = arg_expand;
1070 
1071         // indicator char + String + NULL terminator, the java method will strip
1072         // out the first character, the indicator character, so no matter what
1073         // we add the indicator
1074         tlen = 1 + JLI_StrLen(strv[i]) + 1;
1075         nargv[i] = (char *) JLI_MemAlloc(tlen);
1076         if (JLI_Snprintf(nargv[i], tlen, "%c%s", arg_expand ? 'T' : 'F',
1077                          strv[i]) < 0) {
1078             return NULL;
1079         }
1080         JLI_TraceLauncher("%s\n", nargv[i]);
1081     }
1082 
1083     if (!needs_expansion) {
1084         // clean up any allocated memory and return back the old arguments
1085         for (i = 0 ; i < argc ; i++) {
1086             JLI_MemFree(nargv[i]);
1087         }
1088         JLI_MemFree(nargv);
1089         return NewPlatformStringArray(env, strv, argc);
1090     }
1091     NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls,
1092                                                 "expandArgs",
1093                                                 "([Ljava/lang/String;)[Ljava/lang/String;"));
1094 
1095     // expand the arguments that require expansion, the java method will strip
1096     // out the indicator character.
1097     NULL_CHECK0(inArray = NewPlatformStringArray(env, nargv, argc));
1098     outArray = (*env)->CallStaticObjectMethod(env, cls, mid, inArray);
1099     for (i = 0; i < argc; i++) {
1100         JLI_MemFree(nargv[i]);
1101     }
1102     JLI_MemFree(nargv);
1103     JLI_MemFree(filteredargs);
1104     return outArray;
1105 }