Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2015-04-20 17:21:41 +0000
committerArun Thondapu2015-04-22 09:38:23 +0000
commit03864f87260515557c0d1f17de8ec418e2caf73e (patch)
tree61dbf55fdff9705eb7bf7a648ee3e730ca40e912
parentead8061d709b1279743a6873f146c2c250d1df45 (diff)
downloadrt.equinox.framework-03864f87260515557c0d1f17de8ec418e2caf73e.tar.gz
rt.equinox.framework-03864f87260515557c0d1f17de8ec418e2caf73e.tar.xz
rt.equinox.framework-03864f87260515557c0d1f17de8ec418e2caf73e.zip
Bug 461728 - [Mac] Allow users to specify values in eclipse.ini outside
of the installation Change-Id: I28c846cdea159439b289a427b4c6be26952da5c2 Signed-off-by: Pascal Rapicault <pascal@rapicorp.com>
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/eclipse.c120
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/eclipseMain.c13
2 files changed, 100 insertions, 33 deletions
diff --git a/features/org.eclipse.equinox.executable.feature/library/eclipse.c b/features/org.eclipse.equinox.executable.feature/library/eclipse.c
index 1d62c7ede..1302518f6 100644
--- a/features/org.eclipse.equinox.executable.feature/library/eclipse.c
+++ b/features/org.eclipse.equinox.executable.feature/library/eclipse.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 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
@@ -10,6 +10,7 @@
* Kevin Cornell (Rational Software Corporation)
* Markus Schorn (Wind River Systems), bug 193340
* Martin Oberhuber (Wind River) - [149994] Add --launcher.appendVmargs
+ * Rapicorp, Inc - Bug 461728 - [Mac] Allow users to specify values in eclipse.ini outside of the installation
*******************************************************************************/
/* Eclipse Program Launcher
@@ -148,6 +149,7 @@
#else
#include <unistd.h>
#include <strings.h>
+#include <libgen.h>
#endif
#ifdef MACOSX
@@ -238,6 +240,7 @@ home directory.");
#define CP _T_ECLIPSE("-cp")
#define CLASSPATH _T_ECLIPSE("-classpath")
#define JAR _T_ECLIPSE("-jar")
+#define PROTECT _T_ECLIPSE("-protect")
#define OPENFILE _T_ECLIPSE("--launcher.openFile")
#define DEFAULTACTION _T_ECLIPSE("--launcher.defaultAction")
@@ -282,6 +285,7 @@ static _TCHAR* timeoutString = NULL; /* timeout value for opening a file */
static _TCHAR* defaultAction = NULL; /* default action for non '-' command line arguments */
static _TCHAR* iniFile = NULL; /* the launcher.ini file set if --launcher.ini was specified */
static _TCHAR* gtkVersionString = NULL; /* GTK+ version specified by --launcher.GTK_version */
+static _TCHAR* protectMode = NULL; /* The protection mode */
/* variables for ee options */
static _TCHAR* eeExecutable = NULL;
@@ -331,7 +335,9 @@ static Option options[] = {
{ TIMEOUT, &timeoutString, 0, 2 },
{ DEFAULTACTION,&defaultAction, 0, 2 },
{ WS, &wsArg, 0, 2 },
- { GTK_VERSION, &gtkVersionString, 0, 2 } };
+ { GTK_VERSION, &gtkVersionString, 0, 2 },
+ { PROTECT, &protectMode, 0, 2 } };
+
static int optionsSize = (sizeof(options) / sizeof(options[0]));
static Option eeOptions[] = {
@@ -353,7 +359,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 mergeUserVMArgs( _TCHAR **vmArgs[], _TCHAR** launchersIniVMArgs );
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);
@@ -367,6 +373,8 @@ static _TCHAR* findSplash(_TCHAR* splashArg);
static _TCHAR** getRelaunchCommand( _TCHAR **vmCommand );
static const _TCHAR* getVMArch();
static int _run(int argc, _TCHAR* argv[], _TCHAR* vmArgs[]);
+static _TCHAR** mergeConfigurationFilesVMArgs();
+static _TCHAR** extractVMArgs(_TCHAR** launcherIniValues);
#ifdef _WIN32
static void createConsole();
@@ -466,6 +474,19 @@ JNIEXPORT int run(int argc, _TCHAR* argv[], _TCHAR* vmArgs[])
return _run(argc, argv, vmArgs);
}
+static void handleVMArgs(_TCHAR** vmArgs[]) {
+ _TCHAR** configFilesVMArgs = mergeConfigurationFilesVMArgs();
+ if (vmArgs == NULL) {
+ *vmArgs = configFilesVMArgs;
+ } else {
+ /* reconcile VM Args from commandline with launcher.ini (append or override),
+ * this always allocates new memory */
+ mergeUserVMArgs(vmArgs, configFilesVMArgs);
+ }
+ /* platform specific processing of vmargs */
+ processVMArgs(vmArgs);
+}
+
static int _run(int argc, _TCHAR* argv[], _TCHAR* vmArgs[])
{
_TCHAR** vmCommand = NULL;
@@ -544,14 +565,8 @@ static int _run(int argc, _TCHAR* argv[], _TCHAR* vmArgs[])
exit( 1 );
}
- 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);
- }
-
+ handleVMArgs(&vmArgs);
+
launchMode = determineVM(&msg);
if (launchMode == -1) {
/* problem */
@@ -930,6 +945,41 @@ static _TCHAR** parseArgList( _TCHAR* data ) {
return execArg;
}
+#ifdef MACOSX
+static _TCHAR* getLauncherFileNameFromConfiguration(_TCHAR* program) {
+ _TCHAR* osPath;
+ _TCHAR* configFile;
+
+ osPath = getFolderForApplicationData();
+
+ char* basec = strdup(program);
+ char* bname = basename(basec);
+ configFile = malloc(_tcslen(osPath) + 1 + strlen(bname) + 5 * sizeof(_TCHAR));
+ sprintf(configFile, "%s/%s.ini", osPath, bname);
+ return configFile;
+}
+#endif
+
+static _TCHAR** getLauncherIniFileFromConfiguration() {
+#ifdef MACOSX
+ if (protectMode == NULL)
+ return NULL;
+ if (strcmp(protectMode, _T_ECLIPSE("base")) == 0) {
+ _TCHAR** configArgv = NULL;
+ int configArgc = 0;
+ int ret = 0;
+
+ ret = readConfigFile(getLauncherFileNameFromConfiguration(program), &configArgc, &configArgv);
+ if (ret == 0)
+ return configArgv;
+ return NULL;
+ }
+ return NULL;
+#else
+ return NULL;
+#endif
+}
+
/* Return the list of args from the launcher ini file (if it exists). Caller is responsible to free(). */
static _TCHAR** getConfigArgs() {
_TCHAR** configArgv = NULL;
@@ -944,27 +994,43 @@ static _TCHAR** getConfigArgs() {
return NULL;
}
-/** Append Commandline VM Args to VM Args that came from the launcher.ini
+/** Append Commandline VM Args to VM Args provided
* 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;
+static void mergeUserVMArgs(_TCHAR** vmArgs[], _TCHAR** launchersIniVMArgs) {
+ if (appendVmargs == 0) {
+ if (*vmArgs == NULL) {
+ *vmArgs = launchersIniVMArgs;
+ return;
+ } else {
+ //We copy the vmargs, otherwise the last call to free would fail
+ *vmArgs = concatArgs(*vmArgs, NULL);
+ return;
}
}
/* 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);
+ *vmArgs = concatArgs(launchersIniVMArgs, *vmArgs);
+}
+
+static _TCHAR** extractVMArgs(_TCHAR** launcherIniValues) {
+ if (launcherIniValues != NULL) {
+ int vmArg = indexOf(VMARGS, launcherIniValues);
+ if (vmArg >= 0)
+ return launcherIniValues + vmArg + 1;
+ }
+ return NULL;
+}
+
+//Reads the installation eclipse.ini file, reads a eclipse.ini from the configuration location,
+//and merge the VM arguments
+static _TCHAR** mergeConfigurationFilesVMArgs() {
+ _TCHAR** userLauncherIniVMArgs = extractVMArgs(getLauncherIniFileFromConfiguration());
+ _TCHAR** configVMArgs = extractVMArgs(getConfigArgs());
+
+ /* This always allocates new memory so we don't need to guess if it is safe
+ * to free later */
+ return concatArgs(configVMArgs, userLauncherIniVMArgs);
}
static void adjustVMArgs(_TCHAR *javaVM, _TCHAR *jniLib, _TCHAR **vmArgv[]) {
@@ -1018,7 +1084,7 @@ static void getVMCommand( int launchMode, int argc, _TCHAR* argv[], _TCHAR **vmA
/* If the user specified "-vmargs", add them instead of the default VM args. */
vmArg = (userVMarg != NULL) ? userVMarg : getArgVM( (launchMode == LAUNCH_JNI) ? jniLib : javaVM );
-
+
adjustVMArgs(javaVM, jniLib, &vmArg);
/* Calculate the number of VM arguments. */
diff --git a/features/org.eclipse.equinox.executable.feature/library/eclipseMain.c b/features/org.eclipse.equinox.executable.feature/library/eclipseMain.c
index ab900500c..195ecfa62 100644
--- a/features/org.eclipse.equinox.executable.feature/library/eclipseMain.c
+++ b/features/org.eclipse.equinox.executable.feature/library/eclipseMain.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2013 IBM Corporation and others.
+ * Copyright (c) 2006, 2015 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
@@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* Andrew Niefer
* Red Hat, Inc - Bug 379102 - Prevent running Eclipse as root (optionally)
+ * Rapicorp, Inc - Bug 461728 - [Mac] Allow users to specify values in eclipse.ini outside of the installation
*******************************************************************************/
#include "eclipseUnicode.h"
@@ -60,7 +61,7 @@ static int suppressErrors = 0; /* supress error dialogs */
static int protectRoot = 0; /* check if launcher was run as root */
static int createUserArgs(int configArgc, _TCHAR **configArgv, int *argc, _TCHAR ***argv);
-static void parseArgs( int* argc, _TCHAR* argv[] );
+static void parseArgs( int* argc, _TCHAR* argv[], int handleVMArgs );
static _TCHAR* getDefaultOfficialName(_TCHAR* program);
static _TCHAR* findProgram(_TCHAR* argv[]);
static _TCHAR* findLibrary(_TCHAR* library, _TCHAR* program);
@@ -149,12 +150,12 @@ int main( int argc, _TCHAR* argv[] )
ret = readIniFile(program, &configArgc, &configArgv);
if (ret == 0)
{
- parseArgs (&configArgc, configArgv);
+ parseArgs (&configArgc, configArgv, 0);
}
/* Parse command line arguments */
/* Overrides configuration file arguments */
- parseArgs( &argc, argv );
+ parseArgs( &argc, argv, 1);
/* Special case - user arguments specified in the config file
* are appended to the user arguments passed from the command line.
@@ -270,7 +271,7 @@ static _TCHAR* findProgram(_TCHAR* argv[]) {
/*
* Parse arguments of the command.
*/
-static void parseArgs( int* pArgc, _TCHAR* argv[] )
+static void parseArgs( int* pArgc, _TCHAR* argv[], int handleVMargs )
{
int index;
@@ -279,7 +280,7 @@ static void parseArgs( int* pArgc, _TCHAR* argv[] )
/* For each user defined argument */
for (index = 0; index < *pArgc; index++){
- if(_tcsicmp(argv[index], VMARGS) == 0) {
+ if(handleVMargs == 1 && _tcsicmp(argv[index], VMARGS) == 0) {
userVMarg = &argv[ index+1 ];
argv[ index ] = NULL;
*pArgc = index;

Back to the top