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

The following examples show how to use com.intellij.execution.process.ProcessHandler#isProcessTerminated() . 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: LaunchState.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns the currently running app for the given RunConfig, if any.
 */
@Nullable
public static ProcessHandler getRunningAppProcess(RunConfig config) {
  final Project project = config.getProject();
  final List<RunContentDescriptor> runningProcesses =
    ExecutionManager.getInstance(project).getContentManager().getAllDescriptors();

  for (RunContentDescriptor descriptor : runningProcesses) {
    final ProcessHandler process = descriptor.getProcessHandler();
    if (process != null && !process.isProcessTerminated() && process.getUserData(FLUTTER_RUN_CONFIG_KEY) == config) {
      return process;
    }
  }

  return null;
}
 
Example 2
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 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: EOFAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  RunContentDescriptor descriptor = StopAction.getRecentlyStartedContentDescriptor(e.getDataContext());
  ProcessHandler activeProcessHandler = descriptor != null ? descriptor.getProcessHandler() : null;
  if (activeProcessHandler == null || activeProcessHandler.isProcessTerminated()) return;

  try {
    OutputStream input = activeProcessHandler.getProcessInput();
    if (input != null) {
      ConsoleView console = e.getData(LangDataKeys.CONSOLE_VIEW);
      if (console != null) {
        console.print("^D\n", ConsoleViewContentType.SYSTEM_OUTPUT);
      }
      input.close();
    }
  }
  catch (IOException ignored) {
  }
}
 
Example 5
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 6
Source File: LaunchState.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns the currently running app for the given RunConfig, if any.
 */
@Nullable
public static ProcessHandler getRunningAppProcess(RunConfig config) {
  final Project project = config.getProject();
  final List<RunContentDescriptor> runningProcesses =
    ExecutionManager.getInstance(project).getContentManager().getAllDescriptors();

  for (RunContentDescriptor descriptor : runningProcesses) {
    final ProcessHandler process = descriptor.getProcessHandler();
    if (process != null && !process.isProcessTerminated() && process.getUserData(FLUTTER_RUN_CONFIG_KEY) == config) {
      return process;
    }
  }

  return null;
}
 
Example 7
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 8
Source File: AbstractAutoTestManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void restartAutoTest(@Nonnull RunContentDescriptor descriptor,
                             int modificationStamp,
                             @Nonnull AutoTestWatcher documentWatcher) {
  ProcessHandler processHandler = descriptor.getProcessHandler();
  if (processHandler != null && !processHandler.isProcessTerminated()) {
    scheduleRestartOnTermination(descriptor, processHandler, modificationStamp, documentWatcher);
  }
  else {
    restart(descriptor);
  }
}
 
Example 9
Source File: ExecutionManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public List<RunContentDescriptor> getRunningDescriptors(@Nonnull Condition<RunnerAndConfigurationSettings> condition) {
  List<RunContentDescriptor> result = new SmartList<>();
  for (Trinity<RunContentDescriptor, RunnerAndConfigurationSettings, Executor> trinity : myRunningConfigurations) {
    if (condition.value(trinity.getSecond())) {
      ProcessHandler processHandler = trinity.getFirst().getProcessHandler();
      if (processHandler != null /*&& !processHandler.isProcessTerminating()*/ && !processHandler.isProcessTerminated()) {
        result.add(trinity.getFirst());
      }
    }
  }
  return result;
}
 
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());
}
 
Example 12
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 13
Source File: ProcessBackedConsoleExecuteActionHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
public final boolean isProcessTerminated() {
  final ProcessHandler handler = myProcessHandler;
  return handler == null || handler.isProcessTerminated();
}
 
Example 14
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();
    }
  };
}
 
Example 15
Source File: RunContentManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isTerminated(@Nonnull Content content) {
  RunContentDescriptor descriptor = getRunContentDescriptorByContent(content);
  ProcessHandler processHandler = descriptor == null ? null : descriptor.getProcessHandler();
  return processHandler == null || processHandler.isProcessTerminated();
}
 
Example 16
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 17
Source File: ExecutionManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isProcessRunning(@Nullable RunContentDescriptor descriptor) {
  ProcessHandler processHandler = descriptor == null ? null : descriptor.getProcessHandler();
  return processHandler != null && !processHandler.isProcessTerminated();
}