### Eclipse Workspace Patch 1.0 #P org.eclipse.equinox.executable Index: .cproject =================================================================== RCS file: /cvsroot/rt/org.eclipse.equinox/framework/bundles/org.eclipse.equinox.executable/.cproject,v retrieving revision 1.12 diff -u -r1.12 .cproject --- .cproject 8 Feb 2010 20:58:30 -0000 1.12 +++ .cproject 11 Aug 2010 13:27:39 -0000 @@ -1,4 +1,7 @@ - + + + + @@ -134,4 +137,4 @@ - \ No newline at end of file + Index: library/eclipse.c =================================================================== RCS file: /cvsroot/rt/org.eclipse.equinox/framework/bundles/org.eclipse.equinox.executable/library/eclipse.c,v retrieving revision 1.73 diff -u -r1.73 eclipse.c --- library/eclipse.c 17 Jun 2010 15:16:01 -0000 1.73 +++ library/eclipse.c 11 Aug 2010 13:27:39 -0000 @@ -9,6 +9,7 @@ * IBM Corporation - initial API and implementation * Kevin Cornell (Rational Software Corporation) * Markus Schorn (Wind River Systems), bug 193340 + * Martin Oberhuber (Wind River) - [149994] Add --launcher.appendVmargs *******************************************************************************/ /* Eclipse Program Launcher @@ -233,6 +234,8 @@ #define LIBRARY _T_ECLIPSE("--launcher.library") #define SUPRESSERRORS _T_ECLIPSE("--launcher.suppressErrors") #define INI _T_ECLIPSE("--launcher.ini") +#define APPEND_VMARGS _T_ECLIPSE("--launcher.appendVmargs") +#define OVERRIDE_VMARGS _T_ECLIPSE("--launcher.overrideVmargs") #define SECOND_THREAD _T_ECLIPSE("--launcher.secondThread") #define PERM_GEN _T_ECLIPSE("--launcher.XXMaxPermSize") @@ -254,6 +257,7 @@ static int noSplash = 0; /* True: do not show splash win */ static int suppressErrors = 0; /* True: do not display errors dialogs */ int secondThread = 0; /* True: start the VM on a second thread */ +static int appendVmargs = 0; /* True: append cmdline vmargs to launcher.ini vmargs */ static _TCHAR* showSplashArg = NULL; /* showsplash data (main launcher window) */ static _TCHAR* splashBitmap = NULL; /* the actual splash bitmap */ @@ -289,6 +293,7 @@ /* don't assign it and only remove (remove - 1) arguments */ #define ADJUST_PATH 4 /* value is a path, do processing on relative paths to try and make them absolute */ #define VALUE_IS_LIST 8 /* value is a pointer to a tokenized _TCHAR* string for EE files, or a _TCHAR** list for the command line */ +#define INVERT_FLAG 16 /* invert the meaning of a flag, i.e. reset it */ static Option options[] = { { CONSOLE, &needConsole, VALUE_IS_FLAG, 0 }, @@ -297,6 +302,8 @@ { NOSPLASH, &noSplash, VALUE_IS_FLAG, 1 }, { SUPRESSERRORS, &suppressErrors, VALUE_IS_FLAG, 1}, { SECOND_THREAD, &secondThread, VALUE_IS_FLAG, 1 }, + { APPEND_VMARGS, &appendVmargs, VALUE_IS_FLAG, 1 }, + { OVERRIDE_VMARGS, &appendVmargs, VALUE_IS_FLAG | INVERT_FLAG, 1 }, { LIBRARY, NULL, 0, 2 }, /* library was parsed by exe, just remove it */ { INI, NULL, 0, 2 }, /* same with ini */ { OS, &osArg, 0, 2 }, @@ -331,6 +338,7 @@ /* Local methods */ static void parseArgs( int* argc, _TCHAR* argv[] ); static void processDefaultAction(int argc, _TCHAR* argv[]); +static void mergeUserVMArgs( _TCHAR **vmArgs[] ); static void getVMCommand( int launchMode, int argc, _TCHAR* argv[], _TCHAR **vmArgv[], _TCHAR **progArgv[] ); static int determineVM(_TCHAR** msg); static int vmEEProps(_TCHAR* eeFile, _TCHAR** msg); @@ -422,8 +430,12 @@ exit( 1 ); } - /* platform specific processing of user's vmargs */ - processVMArgs(&vmArgs); + if (vmArgs != NULL) { + /* reconcile VM Args from commandline with launcher.ini (append or override) */ + mergeUserVMArgs(&vmArgs); + /* platform specific processing of user's vmargs */ + processVMArgs(&vmArgs); + } launchMode = determineVM(&msg); if (launchMode == -1) { /* problem */ @@ -720,7 +732,7 @@ /* If the option requires a value and there is one, extract the value. */ if (option->value != NULL) { if (option->flag & VALUE_IS_FLAG) - *((int *) option->value) = 1; + *((int *) option->value) = (option->flag & INVERT_FLAG) ? 0 : 1; else { int count = 1; if (option->flag & VALUE_IS_LIST) { @@ -796,20 +808,62 @@ return execArg; } +/* Return the list of args from the launcher ini file (if it exists). Caller is responsible to free(). */ +static _TCHAR** getConfigArgs() { + _TCHAR* iniFile = NULL; + _TCHAR** configArgv = NULL; + int configArgc = 0; + int ret = 0; + int iniArg; + + /* Parse configuration file arguments */ + iniArg = indexOf(INI, initialArgv); + if (iniArg > 0) { + iniFile = initialArgv[iniArg + 1]; + ret = readConfigFile(iniFile, &configArgc, &configArgv); + } else { + ret = readIniFile(program, &configArgc, &configArgv); + } + if (ret == 0) { + return configArgv; + } + return NULL; +} + +/** Append Commandline VM Args to VM Args that came from the launcher.ini */ +static void mergeUserVMArgs( _TCHAR **vmArgs[] ) { + if (appendVmargs != 0 && indexOf(VMARGS, initialArgv) > 0) { + /* Get vmargs from the launcher.ini, if any */ + _TCHAR** configArgs = getConfigArgs(); + if (configArgs != NULL) { + int vmArg = indexOf(VMARGS, configArgs); + if (vmArg >= 0) { + _TCHAR** configVMArgs = configArgs + vmArg + 1; + if (configVMArgs != NULL) { + *vmArgv = concatArgs(configVMArgs, *vmArgv); + } + } + free(configArgs); + } + /* else, no merge is necessary (there was only commandline vmargs) */ + } +} + static void adjustVMArgs( _TCHAR *javaVM, _TCHAR *jniLib, _TCHAR **vmArgv[] ) { /* Sun VMs need some extra perm gen space */ - if (permGen != NULL && isSunVM(javaVM, jniLib)) { + /* Detecting Sun VM is expensive - only do so if necessary */ + if (permGen != NULL) { int specified = 0, i = -1; /* first check to see if it is already specified */ - while ( (*vmArgv)[++i] != NULL) { + while ((*vmArgv)[++i] != NULL) { /* we are also counting the number of args here */ if (!specified && _tcsncmp((*vmArgv)[i], XXPERMGEN, _tcslen(XXPERMGEN)) == 0) { specified = 1; } } - if (!specified) { + if (!specified && isSunVM(javaVM, jniLib)) { _TCHAR ** oldArgs = *vmArgv; _TCHAR *newArg = malloc((_tcslen(XXPERMGEN) + _tcslen(permGen) + 1) * sizeof(_TCHAR)); _stprintf(newArg, _T_ECLIPSE("%s%s"), XXPERMGEN, permGen); Index: library/eclipseUtil.c =================================================================== RCS file: /cvsroot/rt/org.eclipse.equinox/framework/bundles/org.eclipse.equinox.executable/library/eclipseUtil.c,v retrieving revision 1.13 diff -u -r1.13 eclipseUtil.c --- library/eclipseUtil.c 8 Feb 2010 20:58:29 -0000 1.13 +++ library/eclipseUtil.c 11 Aug 2010 13:27:40 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Kevin Cornell (Rational Software Corporation) + * Martin Oberhuber (Wind River) - [149994] Add --launcher.appendVmargs *******************************************************************************/ /* Eclipse Launcher Utility Methods */ @@ -159,6 +160,48 @@ } /* + * Concatenates two NULL-terminated arrays of Strings, + * returning a new NULL-terminated array. + * The returned array must be freed with the regular free(). + */ +_TCHAR** concatArgs(_TCHAR** l1, _TCHAR** l2) { + _TCHAR** newArray = NULL; + int size1 = 0; + int size2 = 0; + + if (l1 != NULL) + while (l1[size1] != NULL) size1++; + if (l2 != NULL) + while (l2[size2] != NULL) size2++; + + newArray = (_TCHAR **) malloc((size1 + size2 + 1) * sizeof(_TCHAR *)); + if (size1 > 0) { + memcpy(newArray, l1, size1 * sizeof(_TCHAR *)); + } + if (size2 > 0) { + memcpy(newArray + size1, l2, size2 * sizeof(_TCHAR *)); + } + newArray[size1 + size2] = NULL; + return newArray; +} + +/* + * returns the relative position of arg in the NULL-terminated list of args, + * or -1 if args does not contain arg. + */ +int indexOf(_TCHAR *arg, _TCHAR **args) { + int i = -1; + if (arg != NULL && args != NULL) { + while (args[++i] != NULL) { + if (_tcsicmp(arg, args[i]) == 0) { + return i; + } + } + } + return -1; +} + +/* * buffer contains a pathSeparator separated list of paths, check * that it contains all the paths given. Each path is expected to be * terminated with a pathSeparator character. Index: library/eclipseUtil.h =================================================================== RCS file: /cvsroot/rt/org.eclipse.equinox/framework/bundles/org.eclipse.equinox.executable/library/eclipseUtil.h,v retrieving revision 1.8 diff -u -r1.8 eclipseUtil.h --- library/eclipseUtil.h 8 Feb 2010 20:58:28 -0000 1.8 +++ library/eclipseUtil.h 11 Aug 2010 13:27:40 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Kevin Cornell (Rational Software Corporation) + * Martin Oberhuber (Wind River) - [149994] Add --launcher.appendVmargs *******************************************************************************/ #ifndef ECLIPSE_UTIL_H @@ -37,6 +38,12 @@ /* take a NULL terminated array of strings and concatenate them together into one string */ extern _TCHAR * concatStrings(_TCHAR** strs); +/* Concatenates two NULL-terminated arrays of strings into a new array of strings */ +extern _TCHAR** concatArgs(_TCHAR** l1, _TCHAR** l2); + +/* Returns the relative position of arg in the NULL-terminated list of args, or -1 */ +extern int indexOf(_TCHAR *arg, _TCHAR **args); + /* take a NULL terminated array of strings and concatenate them together using the give pathSeparator */ extern _TCHAR* concatPaths(_TCHAR** paths, _TCHAR pathSeparator);