Java 类org.apache.commons.exec.ShutdownHookProcessDestroyer 实例源码

项目:guetzliconverter    文件:ProcessExecutor.java   
@Override
public Long call() throws Exception {
    Executor executor = new DefaultExecutor();
    executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
    ExecuteWatchdog watchDog = new ExecuteWatchdog(watchdogTimeout);
    executor.setWatchdog(watchDog);
    executor.setStreamHandler(new PumpStreamHandler(new MyLogOutputStream(handler, true), new MyLogOutputStream(handler, false)));
    Long exitValue;
    try {
        exitValue = new Long(executor.execute(commandline));
    } catch (ExecuteException e) {
        exitValue = new Long(e.getExitValue());
    }
    if (watchDog.killedProcess()) {
        exitValue = WATCHDOG_EXIST_VALUE;
    }
    return exitValue;
}
项目:project-build-plugin    文件:TestStartEngine.java   
@Test
public void testKillEngineOnVmExit() throws Exception
{
  StartTestEngineMojo mojo = rule.getMojo();
  Executor startedProcess = null;
  try
  {
    startedProcess = mojo.startEngine();
    assertThat(startedProcess.getProcessDestroyer()).isInstanceOf(ShutdownHookProcessDestroyer.class);
    ShutdownHookProcessDestroyer jvmShutdownHoock = (ShutdownHookProcessDestroyer) startedProcess.getProcessDestroyer();
    assertThat(jvmShutdownHoock.size())
      .as("One started engine process must be killed on VM end.")
      .isEqualTo(1);
  }
  finally
  {
    kill(startedProcess);
  }
}
项目:Camel    文件:DefaultExecCommandExecutor.java   
protected DefaultExecutor prepareDefaultExecutor(ExecCommand execCommand) {
    DefaultExecutor executor = new ExecDefaultExecutor();
    executor.setExitValues(null);

    if (execCommand.getWorkingDir() != null) {
        executor.setWorkingDirectory(new File(execCommand.getWorkingDir()).getAbsoluteFile());
    }
    if (execCommand.getTimeout() != ExecEndpoint.NO_TIMEOUT) {
        executor.setWatchdog(new ExecuteWatchdog(execCommand.getTimeout()));
    }
    executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
    return executor;
}
项目:Camel    文件:ProvokeExceptionExecCommandExecutor.java   
@Override
protected DefaultExecutor prepareDefaultExecutor(ExecCommand execCommand) {
    DefaultExecutor executor = new DefaultExecutorMock();
    executor.setExitValues(null);
    executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());

    return executor;
}
项目:project-build-plugin    文件:EngineControl.java   
public Executor start() throws Exception
{
  CommandLine startCmd = toEngineCommand(Command.start);
  context.log.info("Start Axon.ivy Engine in folder: " + context.engineDirectory);

  Executor executor = createEngineExecutor();
  executor.setStreamHandler(createEngineLogStreamForwarder(logLine -> findStartEngineUrl(logLine)));
  executor.setWatchdog(new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT)); 
  executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
  executor.execute(startCmd, asynchExecutionHandler());
  waitForEngineStart(executor);
  return executor;
}
项目:frontend-maven-plugin    文件:ProcessExecutor.java   
private Executor createExecutor(File workingDirectory, long timeoutInSeconds) {
    DefaultExecutor executor = new DefaultExecutor();
    executor.setWorkingDirectory(workingDirectory);
    executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());   // Fixes #41

    if (timeoutInSeconds > 0) {
        executor.setWatchdog(new ExecuteWatchdog(timeoutInSeconds * 1000));
    }

    return executor;
}
项目:gatling-maven-plugin    文件:Fork.java   
void run() throws Exception {
  if (propagateSystemProperties) {
    for (Entry<Object, Object> systemProp : System.getProperties().entrySet()) {
      String name = systemProp.getKey().toString();
      String value = safeWindowsPath(systemProp.getValue().toString());
      if (isPropagatableProperty(name)) {
        if (name.contains(" ")) {
          log.warn("System property name '" + name + "' contains a whitespace and can't be propagated");

        } else if (MojoUtils.IS_WINDOWS && value.contains(" ")) {
          log.warn("System property value '" + value + "' contains a whitespace and can't be propagated on Windows");

        } else {
          this.jvmArgs.add("-D" + name + "=" + safe(StringUtils.escape(value)));
        }
      }
    }
  }

  this.jvmArgs.add("-jar");

  if (log.isDebugEnabled()) {
    log.debug(StringUtils.join(classpath.iterator(), ",\n"));
  }

  this.jvmArgs.add(MojoUtils.createBooterJar(classpath, MainWithArgsInFile.class.getName()).getCanonicalPath());

  List<String> command = buildCommand();

  Executor exec = new DefaultExecutor();
  exec.setStreamHandler(new PumpStreamHandler(System.out, System.err, System.in));
  exec.setProcessDestroyer(new ShutdownHookProcessDestroyer());

  CommandLine cl = new CommandLine(javaExecutable);
  for (String arg : command) {
    cl.addArgument(arg, false);
  }

  if (log.isDebugEnabled()) {
    log.debug(cl.toString());
  }

  int exitValue = exec.execute(cl);
  if (exitValue != 0) {
    throw new MojoFailureException("command line returned non-zero value:" + exitValue);
  }
}