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

Support constant command line arguments and arguments in JNI mode #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion head_src/consolehead/consolehead.c
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ int main(int argc, char* argv[])
cmdLine = "";
}

int result = prepare(cmdLine);
int result = prepare(cmdLine, FALSE);

if (result == ERROR_ALREADY_EXISTS)
{
2 changes: 1 addition & 1 deletion head_src/guihead/guihead.c
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ int APIENTRY WinMain(HINSTANCE hInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
int result = prepare(lpCmdLine);
int result = prepare(lpCmdLine, FALSE);

if (result == ERROR_ALREADY_EXISTS)
{
27 changes: 14 additions & 13 deletions head_src/head.c
Original file line number Diff line number Diff line change
@@ -1111,7 +1111,7 @@ void setEnvironmentVariables(const char *exePath, const int pathLen)
}
}

void setMainClassAndClassPath(const char *exePath, const int pathLen)
void setMainClassAndClassPath(const char *exePath, const int pathLen, BOOL jni)
{
char classPath[MAX_ARGS] = {0};
char expandedClassPath[MAX_ARGS] = {0};
@@ -1179,7 +1179,9 @@ void setMainClassAndClassPath(const char *exePath, const int pathLen)

*(launcher.args + strlen(launcher.args) - 1) = 0;
strcat(launcher.args, "\" ");
strcat(launcher.args, launcher.mainClass);
if (!jni) {
strcat(launcher.args, launcher.mainClass);
}
}
else if (wrapper)
{
@@ -1194,17 +1196,18 @@ void setMainClassAndClassPath(const char *exePath, const int pathLen)
appendPath(launcher.args, jar);
strcat(launcher.args, "\"");
}

}

void setCommandLineArgs(const char *lpCmdLine)
void setCommandLineArgs(const char *lpCmdLine, BOOL jni)
{
const char *target = jni? launcher.mainClass: launcher.args;
char tmp[MAX_ARGS] = {0};

// Constant command line arguments
if (loadString(CMD_LINE, tmp))
{
strcat(launcher.args, " ");
strcat(launcher.args, tmp);
strcat(target, " ");
strcat(target, tmp);
}

// Command line arguments
@@ -1226,13 +1229,13 @@ void setCommandLineArgs(const char *lpCmdLine)
}
if (*tmp)
{
strcat(launcher.args, " ");
strcat(launcher.args, tmp);
strcat(target, " ");
strcat(target, tmp);
}
}
}

int prepare(const char *lpCmdLine)
int prepare(const char *lpCmdLine, BOOL jni)
{
if (!initGlobals())
{
@@ -1272,7 +1275,6 @@ int prepare(const char *lpCmdLine)
}

setWorkingDirectory(exePath, pathLen);

if (!jreSearch(exePath, pathLen))
{
return FALSE;
@@ -1282,7 +1284,6 @@ int prepare(const char *lpCmdLine)
{
return FALSE;
}

setEnvironmentVariables(exePath, pathLen);
processPriority = loadInt(PRIORITY_CLASS);
appendLauncher(launcher.cmd);
@@ -1291,8 +1292,8 @@ int prepare(const char *lpCmdLine)
char jvmOptions[MAX_ARGS] = {0};
setJvmOptions(jvmOptions, exePath);
expandVars(launcher.args, jvmOptions, exePath, pathLen);
setMainClassAndClassPath(exePath, pathLen);
setCommandLineArgs(lpCmdLine);
setMainClassAndClassPath(exePath, pathLen, jni);
setCommandLineArgs(lpCmdLine, jni);

debug("Launcher:\t%s\n", launcher.cmd);
debug("Launcher args:\t%s\n", launcher.args);
6 changes: 3 additions & 3 deletions head_src/head.h
Original file line number Diff line number Diff line change
@@ -134,9 +134,9 @@ BOOL jreSearch(const char *exePath, const int pathLen);
BOOL appendToPathVar(const char* path);
BOOL appendJreBinToPathVar();
void setEnvironmentVariables(const char *exePath, const int pathLen);
void setMainClassAndClassPath(const char *exePath, const int pathLen);
void setCommandLineArgs(const char *lpCmdLine);
int prepare(const char *lpCmdLine);
void setMainClassAndClassPath(const char *exePath, const int pathLen, BOOL jni);
void setCommandLineArgs(const char *lpCmdLine, BOOL jni);
int prepare(const char *lpCmdLine, BOOL jni);
void closeProcessHandles();
BOOL execute(const BOOL wait, DWORD *dwExitCode);
const char* getJavaHome();
2 changes: 1 addition & 1 deletion head_src/jniconsolehead_BETA/jniconsolehead.c
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ int main(int argc, char* argv[])
cmdLine = "";
}

int result = prepare(cmdLine);
int result = prepare(cmdLine, TRUE);

if (result == ERROR_ALREADY_EXISTS)
{
2 changes: 1 addition & 1 deletion head_src/jniguihead_BETA/jniguihead.c
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ int APIENTRY WinMain(HINSTANCE hInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
int result = prepare(lpCmdLine);
int result = prepare(lpCmdLine, TRUE);

if (result == ERROR_ALREADY_EXISTS)
{
7 changes: 7 additions & 0 deletions head_src/jnihead.c
Original file line number Diff line number Diff line change
@@ -61,6 +61,13 @@ void saveJvmOptions(const char *jrePath, const char *mainClass, const char *pcOp
strcpy(g_rgcCurrJrePth, jrePath);
strcpy(g_rgcMnCls, mainClass);

/* Extract main class from arguments */
char *delim = strpbrk(g_rgcMnCls, g_pcSep);
if (delim != NULL) {
*delim = '\0';
strcpy(g_rgcMnClsArgs, delim + 1);
}

char rgcOptCpy[MAX_ARGS] = {0};
int iArgCnt = 0, iCurrArg = 0, iSkipArgCnt = 0;
char *pcCurrOpt;
2 changes: 0 additions & 2 deletions src/net/sf/launch4j/config/Config.java
Original file line number Diff line number Diff line change
@@ -160,8 +160,6 @@ private void checkJniInvariants() {
if (isJniApplication()) {
Validator.checkTrue(".".equals(chdir), "chdir",
"Only '.' is allowed in change directory.");
Validator.checkTrue(Validator.isEmpty(cmdLine), "cmdLine",
"Constant command line arguments not supported.");
Validator.checkFalse(stayAlive, "stayAlive",
"Stay alive option is not used in JNI, this is the default behavior.");
Validator.checkFalse(restartOnCrash, "restartOnCrash",