Java Code Examples for com.intellij.execution.process.ProcessHandler#destroyProcess()

The following examples show how to use com.intellij.execution.process.ProcessHandler#destroyProcess() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FreeRunConfiguration.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private ExecutionResult buildExecutionResult() throws ExecutionException {
    GeneralCommandLine commandLine = createDefaultCommandLine();
    ProcessHandler processHandler = createProcessHandler(commandLine);
    ProcessTerminatedListener.attach(processHandler);
    ConsoleView console = new TerminalExecutionConsole(getProject(), processHandler);

    console.print(
        "Welcome to React Native Console, now please click one button on top toolbar to start.\n",
        ConsoleViewContentType.SYSTEM_OUTPUT);
    console.attachToProcess(processHandler);

    console.print(
        "Give a Star or Suggestion:\n",
        ConsoleViewContentType.NORMAL_OUTPUT);


    processHandler.destroyProcess();
    return new DefaultExecutionResult(console, processHandler);
}
 
Example 2
Source File: ServerConnectionManager.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
public void stopDebugConnection(@NotNull DataContext dataContext) {
    ProcessHandler processHandler = getHandler(dataContext);
    if(processHandler instanceof KillableProcess && processHandler.isProcessTerminating()) {
        ((KillableProcess) processHandler).killProcess();
        return;
    }

    ServerConfiguration serverConfiguration = selectionHandler.getCurrentConfiguration();
    if(serverConfiguration != null) {
        serverConfiguration.setServerStatus(ServerConfiguration.ServerStatus.disconnecting);
    }
    if(processHandler != null) {
        if(processHandler.detachIsDefault()) {
            processHandler.detachProcess();
        } else {
            processHandler.destroyProcess();
        }
    }
    if(serverConfiguration != null) {
        serverConfiguration.setServerStatus(ServerConfiguration.ServerStatus.disconnected);
    }
}
 
Example 3
Source File: RunContentManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean closeQuery(boolean modal) {
  final RunContentDescriptor descriptor = getRunContentDescriptorByContent(myContent);
  if (descriptor == null) {
    return true;
  }

  final ProcessHandler processHandler = descriptor.getProcessHandler();
  if (processHandler == null || processHandler.isProcessTerminated() || processHandler.isProcessTerminating()) {
    return true;
  }
  GeneralSettings.ProcessCloseConfirmation rc = TerminateRemoteProcessDialog.show(myProject, descriptor.getDisplayName(), processHandler);
  if (rc == null) { // cancel
    return false;
  }
  boolean destroyProcess = rc == GeneralSettings.ProcessCloseConfirmation.TERMINATE;
  if (destroyProcess) {
    processHandler.destroyProcess();
  }
  else {
    processHandler.detachProcess();
  }
  waitForProcess(descriptor, modal);
  return true;
}
 
Example 4
Source File: ExecutionManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void stopProcess(@Nullable ProcessHandler processHandler) {
  if (processHandler == null) {
    return;
  }

  processHandler.putUserData(ProcessHandler.TERMINATION_REQUESTED, Boolean.TRUE);

  if (processHandler instanceof KillableProcess && processHandler.isProcessTerminating()) {
    // process termination was requested, but it's still alive
    // in this case 'force quit' will be performed
    ((KillableProcess)processHandler).killProcess();
    return;
  }

  if (!processHandler.isProcessTerminated()) {
    if (processHandler.detachIsDefault()) {
      processHandler.detachProcess();
    }
    else {
      processHandler.destroyProcess();
    }
  }
}
 
Example 5
Source File: XDebugSessionImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void stop() {
  ProcessHandler processHandler = myDebugProcess == null ? null : myDebugProcess.getProcessHandler();
  if (processHandler == null || processHandler.isProcessTerminated() || processHandler.isProcessTerminating()) return;

  if (processHandler.detachIsDefault()) {
    processHandler.detachProcess();
  }
  else {
    processHandler.destroyProcess();
  }
}
 
Example 6
Source File: StopProcessAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void stopProcess(@Nonnull ProcessHandler processHandler) {
  if (processHandler instanceof KillableProcess && processHandler.isProcessTerminating()) {
    // process termination was requested, but it's still alive
    // in this case 'force quit' will be performed
    ((KillableProcess)processHandler).killProcess();
    return;
  }

  if (processHandler.detachIsDefault()) {
    processHandler.detachProcess();
  }
  else {
    processHandler.destroyProcess();
  }
}
 
Example 7
Source File: ExecutionHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Runnable createTimelimitedExecutionProcess(final ProcessHandler processHandler, final int timeout, @Nonnull final String presentableCmdline) {
  return new Runnable() {
    private final Semaphore mySemaphore = new Semaphore();

    private final Runnable myProcessThread = new Runnable() {
      @Override
      public void run() {
        try {
          final boolean finished = processHandler.waitFor(1000 * timeout);
          if (!finished) {
            final String msg = "Timeout (" + timeout + " sec) on executing: " + presentableCmdline;
            LOG.error(msg);
            processHandler.destroyProcess();
          }
        }
        finally {
          mySemaphore.up();
        }
      }
    };

    @Override
    public void run() {
      mySemaphore.down();
      ApplicationManager.getApplication().executeOnPooledThread(myProcessThread);

      mySemaphore.waitFor();
    }
  };
}
 
Example 8
Source File: UnityTestStatePostHandler.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public JsonResponse handle(@Nonnull UnityTestStatePostRequest request)
{
	UUID uuid = UUID.fromString(request.uuid);
	Unity3dTestSession session = Unity3dTestSessionManager.getInstance().findSession(uuid);
	if(session == null)
	{
		return JsonResponse.asError("no session");
	}

	GeneralTestEventsProcessor processor = session.getProcessor();
	ProcessHandler processHandler = session.getProcessHandler();

	String name = request.name;
	switch(request.type)
	{
		case TestStarted:
			processor.onTestStarted(new TestStartedEvent(name, null));
			break;
		case TestIgnored:
			processor.onTestIgnored(new TestIgnoredEvent(name, StringUtil.notNullize(request.message), request.stackTrace));
			break;
		case TestFailed:
			processor.onTestFailure(new TestFailedEvent(name, StringUtil.notNullize(request.message), request.stackTrace, false, null, null));
			break;
		case TestOutput:
			boolean stdOut = "Log".equals(request.messageType) || "Warning".equals(request.messageType);
			StringBuilder builder = new StringBuilder(request.message);
			if(!stdOut)
			{
				builder.append("\n");
				String[] strings = StringUtil.splitByLines(request.stackTrace);
				for(String line : strings)
				{
					builder.append("  at ").append(line).append("\n");
				}
			}
			processor.onTestOutput(new TestOutputEvent(name, builder.toString(), stdOut));
			break;
		case TestFinished:
			long time = (long) (request.time * 1000L);
			processor.onTestFinished(new TestFinishedEvent(name, time));
			break;
		case SuiteStarted:
			processor.onSuiteStarted(new TestSuiteStartedEvent(name, null));
			break;
		case SuiteFinished:
			processor.onSuiteFinished(new TestSuiteFinishedEvent(name));
			break;
		case RunFinished:
			processor.onFinishTesting();
			processHandler.destroyProcess();
			break;
	}

	return JsonResponse.asSuccess(null);
}
 
Example 9
Source File: ExecutionHelper.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static Runnable createCancelableExecutionProcess(final ProcessHandler processHandler, final Function<Object, Boolean> cancelableFun) {
  return new Runnable() {
    private ProgressIndicator myProgressIndicator;
    private final Semaphore mySemaphore = new Semaphore();

    private final Runnable myWaitThread = new Runnable() {
      @Override
      public void run() {
        try {
          processHandler.waitFor();
        }
        finally {
          mySemaphore.up();
        }
      }
    };

    private final Runnable myCancelListener = new Runnable() {
      @Override
      public void run() {
        for (; ; ) {
          if ((myProgressIndicator != null && (myProgressIndicator.isCanceled() || !myProgressIndicator.isRunning())) ||
              (cancelableFun != null && cancelableFun.fun(null).booleanValue()) ||
              processHandler.isProcessTerminated()) {

            if (!processHandler.isProcessTerminated()) {
              try {
                processHandler.destroyProcess();
              }
              finally {
                mySemaphore.up();
              }
            }
            break;
          }
          try {
            synchronized (this) {
              wait(1000);
            }
          }
          catch (InterruptedException e) {
            //Do nothing
          }
        }
      }
    };

    @Override
    public void run() {
      myProgressIndicator = ProgressManager.getInstance().getProgressIndicator();
      if (myProgressIndicator != null && StringUtil.isEmpty(myProgressIndicator.getText())) {
        myProgressIndicator.setText("Please wait...");
      }

      LOG.assertTrue(myProgressIndicator != null || cancelableFun != null, "Cancelable process must have an opportunity to be canceled!");
      mySemaphore.down();
      ApplicationManager.getApplication().executeOnPooledThread(myWaitThread);
      ApplicationManager.getApplication().executeOnPooledThread(myCancelListener);

      mySemaphore.waitFor();
    }
  };
}