Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2010-08-12 16:49:34 -0400
committerAndrew Niefer2010-08-12 16:49:34 -0400
commit67a27df7f4e3927c6360476f790ac72360d9457a (patch)
tree44e42391fe46adb1bc00b03349035639307bf590
parent3eda7983ef723579cf2d4b5b3d4574c7c9c8fba9 (diff)
downloadrt.equinox.framework-67a27df7f4e3927c6360476f790ac72360d9457a.tar.gz
rt.equinox.framework-67a27df7f4e3927c6360476f790ac72360d9457a.tar.xz
rt.equinox.framework-67a27df7f4e3927c6360476f790ac72360d9457a.zip
bug 149994 - --launcher.appendVmargs
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipse.c100
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipseUtil.c45
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipseUtil.h9
3 files changed, 133 insertions, 21 deletions
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipse.c b/bundles/org.eclipse.equinox.executable/library/eclipse.c
index bec693c48..3982f5c26 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipse.c
+++ b/bundles/org.eclipse.equinox.executable/library/eclipse.c
@@ -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 @@ home directory.");
#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 debug = 0; /* True: output debugging info */
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 @@ typedef struct
/* 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 @@ static Option options[] = {
{ 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 @@ static int nEEargs = 0;
/* 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,14 @@ JNIEXPORT int run(int argc, _TCHAR* argv[], _TCHAR* vmArgs[])
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),
+ * this always allocates new memory */
+ mergeUserVMArgs(&vmArgs);
+ /* platform specific processing of user's vmargs */
+ processVMArgs(&vmArgs);
+ }
+
launchMode = determineVM(&msg);
if (launchMode == -1) {
/* problem */
@@ -636,11 +650,12 @@ JNIEXPORT int run(int argc, _TCHAR* argv[], _TCHAR* vmArgs[])
free( programDir );
free( program );
free( officialName );
- if ( vmCommand != NULL ) free( vmCommand );
- if ( launchMode == LAUNCH_JNI ) free( cp );
- if ( cpValue != NULL) free( cpValue );
- if ( exitData != NULL ) free( exitData );
- if ( splashBitmap != NULL ) free( splashBitmap );
+ if(vmCommand != NULL) free(vmCommand);
+ if(launchMode == LAUNCH_JNI) free(cp);
+ if(cpValue != NULL) free(cpValue);
+ if(exitData != NULL) free(exitData);
+ if(splashBitmap != NULL) free(splashBitmap);
+ if(vmArgs != NULL) free(vmArgs);
if (javaResults == NULL)
return -1;
@@ -720,18 +735,18 @@ static void parseArgs(int* pArgc, _TCHAR* argv[]) {
/* 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) {
/* count how many args, this is the -argument itself + following the non'-' args */
- while(count + index < *pArgc && argv[count + index][0] != _T_ECLIPSE('-'))
+ while (count + index < *pArgc && argv[count + index][0] != _T_ECLIPSE('-'))
count++;
-
+
/* allocate memory for a _TCHAR* list and initialize it with NULLs*/
*((void**) option->value) = malloc(count * sizeof(_TCHAR *));
memset(*((void **) option->value), 0, count * sizeof(_TCHAR *));
-
+
if (option->remove != 0)
option->remove = count;
}
@@ -746,7 +761,7 @@ static void parseArgs(int* pArgc, _TCHAR* argv[]) {
(*((_TCHAR***) option->value))[i] = next;
else
*((_TCHAR**) option->value) = next;
- } else if (option->flag & OPTIONAL_VALUE){
+ } else if (option->flag & OPTIONAL_VALUE) {
/* value was optional, and the next arg starts with '-' */
optional = 1;
}
@@ -796,24 +811,70 @@ static _TCHAR** parseArgList( _TCHAR* data ) {
return execArg;
}
-static void adjustVMArgs( _TCHAR *javaVM, _TCHAR *jniLib, _TCHAR **vmArgv[] ) {
+/* 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
+ * Always returns new memory even if no new arguments were appended */
+static void mergeUserVMArgs(_TCHAR **vmArgs[]) {
+ _TCHAR** configVMArgs = NULL;
+ _TCHAR** configArgs = NULL;
+
+ if (appendVmargs != 0 && indexOf(VMARGS, initialArgv) > 0) {
+ /* Get vmargs from the launcher.ini, if any */
+ configArgs = getConfigArgs();
+ if (configArgs != NULL) {
+ int vmArg = indexOf(VMARGS, configArgs);
+ if (vmArg >= 0)
+ configVMArgs = configArgs + vmArg + 1;
+ }
+ }
+
+ /* This always allocates new memory so we don't need to guess if it is safe
+ * to free later */
+ *vmArgs = concatArgs(configVMArgs, *vmArgs);
+ if (configArgs != NULL)
+ free(configArgs);
+}
+
+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);
-
+
*vmArgv = malloc((i + 2) * sizeof(_TCHAR *));
memcpy(*vmArgv, oldArgs, i * sizeof(_TCHAR *));
(*vmArgv)[i] = newArg;
@@ -821,6 +882,7 @@ static void adjustVMArgs( _TCHAR *javaVM, _TCHAR *jniLib, _TCHAR **vmArgv[] ) {
}
}
}
+
/*
* Get the command and arguments to start the Java VM.
*
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseUtil.c b/bundles/org.eclipse.equinox.executable/library/eclipseUtil.c
index 9ed7b68b2..09eb9fd8b 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipseUtil.c
+++ b/bundles/org.eclipse.equinox.executable/library/eclipseUtil.c
@@ -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 @@ _TCHAR * concatPaths(_TCHAR** strs, _TCHAR separator) {
}
/*
+ * 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.
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseUtil.h b/bundles/org.eclipse.equinox.executable/library/eclipseUtil.h
index 970aba374..f9d500364 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipseUtil.h
+++ b/bundles/org.eclipse.equinox.executable/library/eclipseUtil.h
@@ -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 @@ extern _TCHAR * checkPathList( _TCHAR* pathList, _TCHAR* programDir, int reverse
/* 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);

Back to the top