Java Code Examples for com.intellij.execution.runners.ExecutionEnvironment.assignNewExecutionId()

The following are Jave code examples for showing how to use assignNewExecutionId() of the com.intellij.execution.runners.ExecutionEnvironment class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: intellij-ce-playground   File: ExecutionManagerImpl.java   View Source Code Vote up 4 votes
@Override
public void compileAndRun(@NotNull final Runnable startRunnable,
                          @NotNull final ExecutionEnvironment environment,
                          @Nullable final RunProfileState state,
                          @Nullable final Runnable onCancelRunnable) {
  long id = environment.getExecutionId();
  if (id == 0) {
    id = environment.assignNewExecutionId();
  }

  RunProfile profile = environment.getRunProfile();
  if (!(profile instanceof RunConfiguration)) {
    startRunnable.run();
    return;
  }

  final RunConfiguration runConfiguration = (RunConfiguration)profile;
  final List<BeforeRunTask> beforeRunTasks = RunManagerEx.getInstanceEx(myProject).getBeforeRunTasks(runConfiguration);
  if (beforeRunTasks.isEmpty()) {
    startRunnable.run();
  }
  else {
    DataContext context = environment.getDataContext();
    final DataContext projectContext = context != null ? context : SimpleDataContext.getProjectContext(myProject);
    final long finalId = id;
    final Long executionSessionId = new Long(id);
    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
      /**
       * @noinspection SSBasedInspection
       */
      @Override
      public void run() {
        for (BeforeRunTask task : beforeRunTasks) {
          if (myProject.isDisposed()) {
            return;
          }
          @SuppressWarnings("unchecked")
          BeforeRunTaskProvider<BeforeRunTask> provider = BeforeRunTaskProvider.getProvider(myProject, task.getProviderId());
          if (provider == null) {
            LOG.warn("Cannot find BeforeRunTaskProvider for id='" + task.getProviderId() + "'");
            continue;
          }
          ExecutionEnvironment taskEnvironment = new ExecutionEnvironmentBuilder(environment).contentToReuse(null).build();
          taskEnvironment.setExecutionId(finalId);
          EXECUTION_SESSION_ID_KEY.set(taskEnvironment, executionSessionId);
          if (!provider.executeTask(projectContext, runConfiguration, taskEnvironment, task)) {
            if (onCancelRunnable != null) {
              SwingUtilities.invokeLater(onCancelRunnable);
            }
            return;
          }
        }

        doRun(environment, startRunnable);
      }
    });
  }
}
 
Example 2
Project: intellij-ce-playground   File: ProgramRunnerUtil.java   View Source Code Vote up 4 votes
public static void executeConfiguration(@NotNull ExecutionEnvironment environment, boolean showSettings, boolean assignNewId) {
  if (ExecutorRegistry.getInstance().isStarting(environment)) {
    return;
  }

  RunnerAndConfigurationSettings runnerAndConfigurationSettings = environment.getRunnerAndConfigurationSettings();
  if (runnerAndConfigurationSettings != null) {
    if (!ExecutionTargetManager.canRun(environment)) {
      ExecutionUtil.handleExecutionError(environment, new ExecutionException(
        StringUtil.escapeXml("Cannot run '" + environment.getRunProfile().getName() + "' on '" + environment.getExecutionTarget().getDisplayName() + "'")));
      return;
    }

    if (!RunManagerImpl.canRunConfiguration(environment) || (showSettings && runnerAndConfigurationSettings.isEditBeforeRun())) {
      if (!RunDialog.editConfiguration(environment, "Edit configuration")) {
        return;
      }

      while (!RunManagerImpl.canRunConfiguration(environment)) {
        if (Messages.YES == Messages
          .showYesNoDialog(environment.getProject(), "Configuration is still incorrect. Do you want to edit it again?", "Change Configuration Settings",
                           "Edit", "Continue Anyway", Messages.getErrorIcon())) {
          if (!RunDialog.editConfiguration(environment, "Edit configuration")) {
            return;
          }
        }
        else {
          break;
        }
      }
    }

    ConfigurationType configurationType = runnerAndConfigurationSettings.getType();
    if (configurationType != null) {
      UsageTrigger.trigger("execute." + ConvertUsagesUtil.ensureProperKey(configurationType.getId()) + "." + environment.getExecutor().getId());
    }
  }

  try {
    if (assignNewId) {
      environment.assignNewExecutionId();
    }
    environment.getRunner().execute(environment);
  }
  catch (ExecutionException e) {
    String name = runnerAndConfigurationSettings != null ? runnerAndConfigurationSettings.getName() : null;
    if (name == null) {
      name = environment.getRunProfile().getName();
    }
    if (name == null && environment.getContentToReuse() != null) {
      name = environment.getContentToReuse().getDisplayName();
    }
    if (name == null) {
      name = "<Unknown>";
    }
    ExecutionUtil.handleExecutionError(environment.getProject(), environment.getExecutor().getToolWindowId(), name, e);
  }
}