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

The following examples show how to use com.intellij.execution.process.ProcessHandler#isProcessTerminating() . 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: 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 2
Source File: StopProcessAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void update(@Nonnull Presentation presentation,
                          @Nonnull Presentation templatePresentation,
                          @Nullable ProcessHandler processHandler) {
  boolean enable = false;
  Icon icon = templatePresentation.getIcon();
  String description = templatePresentation.getDescription();
  if (processHandler != null && !processHandler.isProcessTerminated()) {
    enable = true;
    if (processHandler.isProcessTerminating() && processHandler instanceof KillableProcess) {
      KillableProcess killableProcess = (KillableProcess) processHandler;
      if (killableProcess.canKillProcess()) {
        // 'force quite' action presentation
        icon = AllIcons.Debugger.KillProcess;
        description = "Kill process";
      }
    }
  }
  presentation.setEnabled(enable);
  presentation.setIcon(icon);
  presentation.setDescription(description);
}
 
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: FakeRerunAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected boolean isEnabled(AnActionEvent event) {
  RunContentDescriptor descriptor = getDescriptor(event);
  ProcessHandler processHandler = descriptor == null ? null : descriptor.getProcessHandler();
  ExecutionEnvironment environment = getEnvironment(event);
  return environment != null &&
         !ExecutorRegistry.getInstance().isStarting(environment) &&
         !(processHandler != null && processHandler.isProcessTerminating());
}
 
Example 8
Source File: SkylarkDebugProcess.java    From intellij with Apache License 2.0 4 votes vote down vote up
/** Returns false if the blaze process is terminating or already terminated. */
boolean isProcessAlive() {
  ProcessHandler handler = getProcessHandler();
  return !handler.isProcessTerminated() && !handler.isProcessTerminating();
}
 
Example 9
Source File: ExecutionUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void restartIfActive(@Nonnull RunContentDescriptor descriptor) {
  ProcessHandler processHandler = descriptor.getProcessHandler();
  if (processHandler != null && processHandler.isStartNotified() && !processHandler.isProcessTerminating() && !processHandler.isProcessTerminated()) {
    restart(descriptor);
  }
}
 
Example 10
Source File: StopAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void update(final AnActionEvent e) {
  boolean enable = false;
  Icon icon = getTemplatePresentation().getIcon();
  String description = getTemplatePresentation().getDescription();
  Presentation presentation = e.getPresentation();
  if (isPlaceGlobal(e)) {
    List<RunContentDescriptor> stoppableDescriptors = getActiveStoppableDescriptors(e.getDataContext());
    List<Pair<TaskInfo, ProgressIndicator>> cancellableProcesses = getCancellableProcesses(e.getProject());
    int todoSize = stoppableDescriptors.size() + cancellableProcesses.size();
    if (todoSize > 1) {
      presentation.setText(getTemplatePresentation().getText() + "...");
    }
    else if (todoSize == 1) {
      if (stoppableDescriptors.size() == 1) {
        presentation
                .setText(ExecutionBundle.message("stop.configuration.action.name", StringUtil.escapeMnemonics(stoppableDescriptors.get(0).getDisplayName())));
      }
      else {
        TaskInfo taskInfo = cancellableProcesses.get(0).first;
        presentation.setText(taskInfo.getCancelText() + " " + taskInfo.getTitle());
      }
    }
    else {
      presentation.setText(getTemplatePresentation().getText());
    }
    enable = todoSize > 0;
    if (todoSize > 1) {
      icon = IconUtil.addText(icon, String.valueOf(todoSize));
    }
  }
  else {
    RunContentDescriptor contentDescriptor = e.getData(LangDataKeys.RUN_CONTENT_DESCRIPTOR);
    ProcessHandler processHandler = contentDescriptor == null ? null : contentDescriptor.getProcessHandler();
    if (processHandler != null && !processHandler.isProcessTerminated()) {
      if (!processHandler.isProcessTerminating()) {
        enable = true;
      }
      else if (processHandler instanceof KillableProcess && ((KillableProcess)processHandler).canKillProcess()) {
        enable = true;
        icon = AllIcons.Debugger.KillProcess;
        description = "Kill process";
      }
    }

    RunProfile runProfile = e.getData(LangDataKeys.RUN_PROFILE);
    if (runProfile == null && contentDescriptor == null) {
      presentation.setText(getTemplatePresentation().getText());
    }
    else {
      presentation.setText(ExecutionBundle.message("stop.configuration.action.name", StringUtil
              .escapeMnemonics(runProfile == null ? contentDescriptor.getDisplayName() : runProfile.getName())));
    }
  }

  presentation.setEnabled(enable);
  presentation.setIcon(icon);
  presentation.setDescription(description);
}
 
Example 11
Source File: StopAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean canBeStopped(@Nullable RunContentDescriptor descriptor) {
  @Nullable ProcessHandler processHandler = descriptor != null ? descriptor.getProcessHandler() : null;
  return processHandler != null &&
         !processHandler.isProcessTerminated() &&
         (!processHandler.isProcessTerminating() || processHandler instanceof KillableProcess && ((KillableProcess)processHandler).canKillProcess());
}