Search in sources :

Example 1 with EquinoxLaunchingException

use of org.eclipse.sisu.equinox.launching.EquinoxLaunchingException in project tycho by eclipse.

the class DefaultEquinoxLauncher method execute.

@Override
public int execute(LaunchConfiguration configuration, int forkedProcessTimeoutInSeconds) throws EquinoxLaunchingException {
    String executable = configuration.getJvmExecutable();
    if (executable == null || "".equals(executable)) {
        // use the same JVM as the one used to run Maven (the "java.home" one)
        executable = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
        if (File.separatorChar == '\\') {
            executable = executable + ".exe";
        }
    }
    CommandLine cli = new CommandLine(executable);
    final boolean handleQuotes = false;
    cli.addArguments(configuration.getVMArguments(), handleQuotes);
    cli.addArguments(new String[] { "-jar", getCanonicalPath(configuration.getLauncherJar()) }, handleQuotes);
    cli.addArguments(configuration.getProgramArguments(), handleQuotes);
    log.info("Command line:\n\t" + cli.toString());
    DefaultExecutor executor = new DefaultExecutor();
    ExecuteWatchdog watchdog = null;
    if (forkedProcessTimeoutInSeconds > 0) {
        watchdog = new ExecuteWatchdog(forkedProcessTimeoutInSeconds * 1000L);
        executor.setWatchdog(watchdog);
    }
    // best effort to avoid orphaned child process
    executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
    executor.setWorkingDirectory(configuration.getWorkingDirectory());
    try {
        return executor.execute(cli, getMergedEnvironment(configuration));
    } catch (ExecuteException e) {
        if (watchdog != null && watchdog.killedProcess()) {
            log.error("Timeout " + forkedProcessTimeoutInSeconds + " s exceeded. Process was killed.");
        }
        return e.getExitValue();
    } catch (IOException e) {
        throw new EquinoxLaunchingException(e);
    }
}
Also used : CommandLine(org.apache.commons.exec.CommandLine) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) ExecuteWatchdog(org.apache.commons.exec.ExecuteWatchdog) ExecuteException(org.apache.commons.exec.ExecuteException) IOException(java.io.IOException) EquinoxLaunchingException(org.eclipse.sisu.equinox.launching.EquinoxLaunchingException) ShutdownHookProcessDestroyer(org.apache.commons.exec.ShutdownHookProcessDestroyer)

Aggregations

IOException (java.io.IOException)1 CommandLine (org.apache.commons.exec.CommandLine)1 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)1 ExecuteException (org.apache.commons.exec.ExecuteException)1 ExecuteWatchdog (org.apache.commons.exec.ExecuteWatchdog)1 ShutdownHookProcessDestroyer (org.apache.commons.exec.ShutdownHookProcessDestroyer)1 EquinoxLaunchingException (org.eclipse.sisu.equinox.launching.EquinoxLaunchingException)1