Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbeaver/dbeaver#35080 Add support for specifying additional JVM arguments #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions features/org.eclipse.equinox.executable.feature/library/eclipse.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ static _TCHAR* defaultAction = NULL; /* default action for non '-' command li
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; /* Process protectMode specified via -protect, to trigger the reading of eclipse.ini in the configuration (Mac specific currently) */
static _TCHAR** additionalVmargsPath = NULL; /* List of locations of files with extra vmargs that have higher priority over other vmargs */

/* variables for ee options */
static _TCHAR* eeExecutable = NULL;
Expand All @@ -282,6 +283,7 @@ typedef struct
#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 */
#define EXPAND_PATH 32 /* value is a path, expands patterns like %name% with environment-variable strings */

static Option options[] = {
{ CONSOLE, &needConsole, VALUE_IS_FLAG, 0 },
Expand All @@ -307,7 +309,8 @@ static Option options[] = {
{ DEFAULTACTION,&defaultAction, 0, 2 },
{ WS, &wsArg, 0, 2 },
{ GTK_VERSION, &gtkVersionString, 0, 2 },
{ PROTECT, &protectMode, 0, 2 } };
{ PROTECT, &protectMode, 0, 2 },
{ ADDITIONAL_VMARGS, &additionalVmargsPath, ADJUST_PATH | EXPAND_PATH | VALUE_IS_LIST, -1 } };

static int optionsSize = (sizeof(options) / sizeof(options[0]));

Expand Down Expand Up @@ -864,6 +867,8 @@ static void parseArgs(int* pArgc, _TCHAR* argv[]) {
_TCHAR * next = argv[index + i + 1];
if (option->flag & ADJUST_PATH)
next = checkPath(next, getProgramDir(), 0);
if (option->flag & EXPAND_PATH)
next = expandPath(next);
if (next[0] != _T_ECLIPSE('-')) {
if (option->flag & VALUE_IS_LIST)
(*((_TCHAR***) option->value))[i] = next;
Expand Down Expand Up @@ -996,15 +1001,32 @@ static _TCHAR** extractVMArgs(_TCHAR** launcherIniValues) {
return NULL;
}

/** Attempts to read the first configuration file
* If the file is not found, it will try the next one in the list
* Returns the arguments read from the file or NULL if no file was found */
static _TCHAR** getAdditionalVMArgs() {
int argc = 0;
_TCHAR** argv = NULL;

for (_TCHAR** path = additionalVmargsPath; path; path++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (_TCHAR** path = additionalVmargsPath; path; path++) {
for (_TCHAR** path = additionalVMArgsPath; path; path++) {

if (readConfigFile(*path, &argc, &argv) == 0) {
break;
}
}

return argv;
}

//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());
_TCHAR** additionalVMArgs = getAdditionalVMArgs();

/* This always allocates new memory so we don't need to guess if it is safe
* to free later */
return concatArgs(configVMArgs, userLauncherIniVMArgs);
/* This always allocates new memory so we don't need to guess if it is safe
* to free later */
return concatArgs(concatArgs(configVMArgs, userLauncherIniVMArgs), additionalVMArgs);
}

static void adjustVMArgs(_TCHAR *javaVM, _TCHAR *jniLib, _TCHAR **vmArgv[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,44 @@ _TCHAR* checkPath( _TCHAR* path, _TCHAR* programDir, int reverseOrder )
return result != NULL ? result : path;
}

_TCHAR* expandPath(_TCHAR* inPath) {
_TCHAR buffer[MAX_PATH_LENGTH];
_TCHAR variable[MAX_PATH_LENGTH];

_TCHAR* dstCur = &buffer[0];
_TCHAR* srcCur = &inPath[0];

for(;;) {
_TCHAR* start = _tcschr(srcCur, _T_ECLIPSE('%'));
if (start == NULL) {
// No more variables
_tcscpy(dstCur, srcCur);
return _tcsdup(buffer);
}
_TCHAR* end = _tcschr(start + 1, _T_ECLIPSE('%'));
if (end == NULL) {
// Not a variable
*dstCur++ = *srcCur++;
continue;
}
_tcsncpy(variable, start + 1, end - start);
variable[end - start - 1] = _T_ECLIPSE('\0');
_TCHAR* value = _tgetenv(variable);
if (value != NULL) {
// Found a variable
_tcsncpy(dstCur, srcCur, start - srcCur);
dstCur += start - srcCur;
_tcscpy(dstCur, value);
dstCur += _tcslen(value);
} else {
// Variable is not found
_tcsncpy(dstCur, srcCur, end - srcCur + 1);
dstCur += end - srcCur + 1;
}
srcCur = end + 1;
}
}

_TCHAR * lastDirSeparator(_TCHAR* str) {
#ifndef _WIN32
return _tcsrchr(str, dirSeparator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#define OLD_ARGS_START _T_ECLIPSE("--launcher.oldUserArgsStart")
#define OLD_ARGS_END _T_ECLIPSE("--launcher.oldUserArgsEnd")
#define SKIP_OLD_ARGS _T_ECLIPSE("--launcher.skipOldUserArgs")
#define ADDITIONAL_VMARGS _T_ECLIPSE("--launcher.additionalVmargs")
ShadelessFox marked this conversation as resolved.
Show resolved Hide resolved

#define XXPERMGEN _T_ECLIPSE("-XX:MaxPermSize=")
#define ADDMODULES _T_ECLIPSE("--add-modules")
Expand Down Expand Up @@ -153,6 +154,9 @@ extern void * findSymbol( void * handle, _TCHAR * symbol );
/* check the given path and attempt to make it absolute if it is relative */
extern _TCHAR* checkPath( _TCHAR* path, _TCHAR* programDir, int reverseOrder );

/* expands environment-variable strings and replaces them with the values defined for the current user */
extern _TCHAR* expandPath(_TCHAR* path);

extern _TCHAR * lastDirSeparator(_TCHAR* str);

extern _TCHAR * firstDirSeparator(_TCHAR* str);
Expand Down
Loading