Skip to content

Commit

Permalink
Add -norestart option to launcher.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhendriks committed Jun 23, 2024
1 parent 808b90f commit ff78847
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ public interface IApplication {
public static final Integer EXIT_OK = Integer.valueOf(0);

/**
* Exit object requesting platform restart
* Exit object requesting platform restart.
*
* <p>
* Note: The handling of this special exit code may be disabled by launcher
* argument '-norestart'.
* </p>
*/
public static final Integer EXIT_RESTART = Integer.valueOf(23);

Expand All @@ -44,6 +49,11 @@ public interface IApplication {
* the executable is relaunched the command line will be retrieved from the
* {@link IApplicationContext#EXIT_DATA_PROPERTY eclipse.exitdata} system
* property.
*
* <p>
* Note: The handling of this special exit code may be disabled by launcher
* argument '-norestart'.
* </p>
*/
public static final Integer EXIT_RELAUNCH = Integer.valueOf(24);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -204,6 +206,66 @@ void test_appTerminatesWithCodeZeroOnExit() throws IOException, InterruptedExcep
assertEquals(0, launcherProcess.exitValue());
}

@Test
void test_appTerminatesWithoutNoRestartWithEXIT_OK() throws IOException, InterruptedException {
test_norestart(EXIT_OK, false);
}

@Test
void test_appTerminatesWithNoRestartAndEXIT_OK() throws IOException, InterruptedException {
test_norestart(EXIT_OK, true);
}

@Test
void test_appTerminatesWithNoRestartAndEXIT_RESTART() throws IOException, InterruptedException {
test_norestart(EXIT_RESTART, true);
}

@Test
void test_appTerminatesWithNoRestartAndEXIT_RELAUNCH() throws IOException, InterruptedException {
test_norestart(EXIT_RELAUNCH, true);
}

@Test
void test_appTerminatesWithoutNoRestartWithExitCode100() throws IOException, InterruptedException {
test_norestart(100, false);
}

@Test
void test_appTerminatesWithNoRestartAndExitCode100() throws IOException, InterruptedException {
test_norestart(100, true);
}

private void test_norestart(int exitCode, boolean addNoRestartArg) throws IOException, InterruptedException {
writeEclipseIni(DEFAULT_ECLIPSE_INI_CONTENT);

List<String> launcherArgs = addNoRestartArg ? List.of("-norestart", "--launcher.suppressErrors")
: List.of("--launcher.suppressErrors");
Process launcherProcess = startEclipseLauncher(launcherArgs);

Socket socket = server.accept();

List<String> appArgs = new ArrayList<>();
analyzeLaunchedTestApp(socket, appArgs, null, exitCode);

// Make sure -norestart arg is picked
assertEquals(addNoRestartArg, appArgs.contains("--launcher.noRestart"));
// Make sure launcher exited with expected exit value
launcherProcess.waitFor(5, TimeUnit.SECONDS);
assertEquals(exitCode, launcherProcess.exitValue());
try {
server.accept();
if (addNoRestartArg) {
fail("New eclipse started even with -norestart arg and exit code " + exitCode);
} else {
fail("New eclipse started even with exit code " + exitCode);
}
} catch (SocketTimeoutException e) {
// No new instance launched
return;
}
}

@Test
void test_eclipseIniChangesShouldBePickedOnRestart() throws IOException {
writeEclipseIni(DEFAULT_ECLIPSE_INI_CONTENT);
Expand Down
58 changes: 32 additions & 26 deletions features/org.eclipse.equinox.executable.feature/library/eclipse.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
* -nosplash do not display the splash screen. The java application will
* not receive the -showsplash command.
* -showsplash <bitmap> show the given bitmap in the splash screen.
* -norestart disables the restart behavior of exit codes 23 and 24.
* -name <name> application name displayed in error message dialogs and
* splash screen window. Default value is computed from the
* name of the executable - with the first letter capitalized
Expand Down Expand Up @@ -235,6 +236,7 @@ home directory.");
static int needConsole = 0; /* True: user wants a console */
static int debug = 0; /* True: output debugging info */
static int noSplash = 0; /* True: do not show splash win */
static int noRestart = 0; /* True: disables the restart behavior of the launcher */
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 */
Expand Down Expand Up @@ -286,6 +288,7 @@ static Option options[] = {
{ CONSOLELOG, &needConsole, VALUE_IS_FLAG, 0 },
{ DEBUG_ARG, &debug, VALUE_IS_FLAG, 0 },
{ NOSPLASH, &noSplash, VALUE_IS_FLAG, 1 },
{ NORESTART, &noRestart, VALUE_IS_FLAG, 1 },
{ SUPRESSERRORS, &suppressErrors, VALUE_IS_FLAG, 1},
{ SECOND_THREAD, &secondThread, VALUE_IS_FLAG, 1 },
{ APPEND_VMARGS, &appendVmargs, VALUE_IS_FLAG, 1 },
Expand Down Expand Up @@ -650,32 +653,35 @@ static int _run(int argc, _TCHAR* argv[], _TCHAR* vmArgs[])
case 0: /* normal exit */
break;
case RESTART_LAST_EC:
/* copy for relaunch, +1 to ensure NULL terminated */
relaunchCommand = malloc((initialArgc + 1) * sizeof(_TCHAR*));
memcpy(relaunchCommand, initialArgv, (initialArgc + 1) * sizeof(_TCHAR*));
relaunchCommand[initialArgc] = 0;
relaunchCommand[0] = program;
break;

if (!noRestart) {
/* copy for relaunch, +1 to ensure NULL terminated */
relaunchCommand = malloc((initialArgc + 1) * sizeof(_TCHAR*));
memcpy(relaunchCommand, initialArgv, (initialArgc + 1) * sizeof(_TCHAR*));
relaunchCommand[initialArgc] = 0;
relaunchCommand[0] = program;
break;
} // fall-through to default non-zero exit code handling.
case RESTART_NEW_EC:
if(launchMode == LAUNCH_EXE) {
if (exitData != NULL) free(exitData);
if (getSharedData( sharedID, &exitData ) != 0)
exitData = NULL;
}
if (exitData != 0) {
if (vmCommand != NULL) free( vmCommand );
vmCommand = parseArgList( exitData );
relaunchCommand = getRelaunchCommand(vmCommand);
} else {
if (debug) {
if (!suppressErrors)
displayMessage( officialName, shareMsg );
else
_ftprintf(stderr, _T_ECLIPSE("%s:\n%s\n"), officialName, shareMsg);
if (!noRestart) {
if(launchMode == LAUNCH_EXE) {
if (exitData != NULL) free(exitData);
if (getSharedData( sharedID, &exitData ) != 0)
exitData = NULL;
}
}
break;
if (exitData != 0) {
if (vmCommand != NULL) free( vmCommand );
vmCommand = parseArgList( exitData );
relaunchCommand = getRelaunchCommand(vmCommand);
} else {
if (debug) {
if (!suppressErrors)
displayMessage( officialName, shareMsg );
else
_ftprintf(stderr, _T_ECLIPSE("%s:\n%s\n"), officialName, shareMsg);
}
}
break;
} // fall-through to default non-zero exit code handling.
default: {
_TCHAR *title = _tcsdup(officialName);
errorMsg = NULL;
Expand Down Expand Up @@ -1104,12 +1110,12 @@ static void getVMCommand( int launchMode, int argc, _TCHAR* argv[], _TCHAR **vmA

/* Program arguments */
/* OS <os> + WS <ws> + ARCH <arch> + SHOWSPLASH <cmd> + LAUNCHER <program> + NAME <officialName>
* + LIBRARY <eclipseLibrary> + STARTUP <jarFile> + PROTECT <protectMode> + APPEND/OVERRIDE
* + LIBRARY <eclipseLibrary> + STARTUP <jarFile> + PROTECT <protectMode> + APPEND/OVERRIDE + NORESTART
* + EXITDATA <sharedId> + argv[] + VM <jniLib/javaVM> + VMARGS + vmArg[] + eeVMarg[] + reqVMarg[]
* + NULL)
*/
totalProgArgs = 2 + 2 + 2 + 2 + 2 + 2
+ 2 + 2 + 2 + 1
+ 2 + 2 + 2 + 1 + 1
+ 2 + argc + 2 + 1 + nVMarg + nEEargs + nReqVMarg
+ 1;
*progArgv = malloc( totalProgArgs * sizeof( _TCHAR* ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define OS _T_ECLIPSE("-os")
#define OSARCH _T_ECLIPSE("-arch")
#define NOSPLASH _T_ECLIPSE("-nosplash")
#define NORESTART _T_ECLIPSE("-norestart")
#define LAUNCHER _T_ECLIPSE("-launcher")
#define SHOWSPLASH _T_ECLIPSE("-showsplash")
#define EXITDATA _T_ECLIPSE("-exitdata")
Expand All @@ -47,6 +48,7 @@
#define INI _T_ECLIPSE("--launcher.ini")
#define APPEND_VMARGS _T_ECLIPSE("--launcher.appendVmargs")
#define OVERRIDE_VMARGS _T_ECLIPSE("--launcher.overrideVmargs")
#define LAUNCHER_NORESTART _T_ECLIPSE("--launcher.noRestart")
#define SECOND_THREAD _T_ECLIPSE("--launcher.secondThread")
#define PERM_GEN _T_ECLIPSE("--launcher.XXMaxPermSize")
#define OLD_ARGS_START _T_ECLIPSE("--launcher.oldUserArgsStart")
Expand Down

0 comments on commit ff78847

Please sign in to comment.