protected void doRun(
     @NotNull final ExecutionEnvironment environment, @NotNull final Runnable startRunnable) {
   Boolean allowSkipRun = environment.getUserData(EXECUTION_SKIP_RUN);
   if (allowSkipRun != null && allowSkipRun) {
     environment
         .getProject()
         .getMessageBus()
         .syncPublisher(EXECUTION_TOPIC)
         .processNotStarted(environment.getExecutor().getId(), environment);
   } else {
     // important! Do not use DumbService.smartInvokeLater here because it depends on modality
     // state
     // and execution of startRunnable could be skipped if modality state check fails
     //noinspection SSBasedInspection
     SwingUtilities.invokeLater(
         () -> {
           if (!myProject.isDisposed()) {
             if (!Registry.is("dumb.aware.run.configurations")) {
               DumbService.getInstance(myProject).runWhenSmart(startRunnable);
             } else {
               try {
                 DumbService.getInstance(myProject).setAlternativeResolveEnabled(true);
                 startRunnable.run();
               } catch (IndexNotReadyException ignored) {
                 ExecutionUtil.handleExecutionError(
                     environment,
                     new ExecutionException("cannot start while indexing is in progress."));
               } finally {
                 DumbService.getInstance(myProject).setAlternativeResolveEnabled(false);
               }
             }
           }
         });
   }
 }
 public static void handleExecutionError(
     @NotNull ExecutionEnvironment environment, @NotNull ExecutionException e) {
   handleExecutionError(
       environment.getProject(),
       environment.getExecutor().getToolWindowId(),
       environment.getRunProfile().getName(),
       e);
 }
 public RunProfileState getState(
     @NotNull final Executor executor, @NotNull final ExecutionEnvironment env)
     throws ExecutionException {
   return TestObject.fromString(
       myData.TEST_OBJECT,
       getProject(),
       this,
       env.getRunnerSettings(),
       env.getConfigurationSettings());
 }
 private static void performAction(@NotNull ExecutionEnvironmentBuilder builder) {
   ExecutionEnvironment environment = builder.build();
   try {
     environment.getRunner().execute(environment);
   } catch (ExecutionException e) {
     LOG.error(e);
   } finally {
     ((MyRunProfile) environment.getRunProfile()).clear();
   }
 }
 @NotNull
 @Override
 protected OSProcessHandler startProcess() throws ExecutionException {
   ExecutionEnvironment env = getEnvironment();
   GeneralCommandLine commandLine = new GeneralCommandLine();
   commandLine.setWorkDirectory(env.getProject().getBasePath());
   // TODO: This should probably be a bit more generic than relying on `cabal test`.
   final String cabalPath = HaskellBuildSettings.getInstance(myConfig.getProject()).getCabalPath();
   commandLine.setExePath(cabalPath);
   ParametersList parametersList = commandLine.getParametersList();
   parametersList.add("test");
   parametersList.addParametersString(myConfig.programArguments);
   return new OSProcessHandler(commandLine.createProcess());
 }
Exemplo n.º 6
0
 boolean isEnabled() {
   ProcessHandler processHandler = myDescriptor.getProcessHandler();
   boolean isTerminating = processHandler != null && processHandler.isProcessTerminating();
   boolean isStarting =
       ExecutorRegistry.getInstance()
           .isStarting(myEnvironment.getProject(), myExecutor.getId(), myRunner.getRunnerId());
   return !isStarting && !isTerminating;
 }
Exemplo n.º 7
0
  @Override
  public void update(final AnActionEvent event) {
    final Presentation presentation = event.getPresentation();
    String name = myEnvironment.getRunProfile().getName();
    ProcessHandler processHandler = myDescriptor.getProcessHandler();
    final boolean isRunning = processHandler != null && !processHandler.isProcessTerminated();

    presentation.setText(ExecutionBundle.message("rerun.configuration.action.name", name));
    presentation.setIcon(isRunning ? AllIcons.Actions.Restart : myExecutor.getIcon());
    presentation.setEnabled(isEnabled());
  }
  @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(
              () -> {
                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);
              });
    }
  }
Exemplo n.º 9
0
 public void restart() {
   final Project project =
       PlatformDataKeys.PROJECT.getData(
           DataManager.getInstance().getDataContext(myDescriptor.getComponent()));
   if (ExecutorRegistry.getInstance()
       .isStarting(project, myExecutor.getId(), myRunner.getRunnerId())) {
     return;
   }
   try {
     final ExecutionEnvironment old = myEnvironment;
     myRunner.execute(
         myExecutor,
         new ExecutionEnvironment(
             old.getRunProfile(),
             old.getExecutionTarget(),
             project,
             old.getRunnerSettings(),
             old.getConfigurationSettings(),
             myDescriptor,
             old.getRunnerAndConfigurationSettings()));
   } catch (RunCanceledByUserException ignore) {
   } catch (ExecutionException e1) {
     Messages.showErrorDialog(
         project, e1.getMessage(), ExecutionBundle.message("restart.error.message.title"));
   }
 }
Exemplo n.º 10
0
 @Override
 public void actionPerformed(final AnActionEvent e) {
   Project project = myEnvironment.getProject();
   if (project == null) return;
   if (myProcessHandler != null) {
     ExecutionManager.getInstance(project)
         .restartRunProfile(
             project,
             myExecutor,
             myEnvironment.getExecutionTarget(),
             myEnvironment.getRunnerAndConfigurationSettings(),
             myProcessHandler);
   } else {
     ExecutionManager.getInstance(project)
         .restartRunProfile(
             project,
             myExecutor,
             myEnvironment.getExecutionTarget(),
             myEnvironment.getRunnerAndConfigurationSettings(),
             myDescriptor);
   }
 }
  @Override
  public boolean canExecuteTask(
      RunConfiguration configuration, ExternalSystemBeforeRunTask beforeRunTask) {
    final ExternalSystemTaskExecutionSettings executionSettings =
        beforeRunTask.getTaskExecutionSettings();

    final List<ExternalTaskPojo> tasks = ContainerUtilRt.newArrayList();
    for (String taskName : executionSettings.getTaskNames()) {
      tasks.add(new ExternalTaskPojo(taskName, executionSettings.getExternalProjectPath(), null));
    }
    if (tasks.isEmpty()) return true;

    final Pair<ProgramRunner, ExecutionEnvironment> pair =
        ExternalSystemUtil.createRunner(
            executionSettings, DefaultRunExecutor.EXECUTOR_ID, myProject, mySystemId);

    if (pair == null) return false;

    final ProgramRunner runner = pair.first;
    final ExecutionEnvironment environment = pair.second;

    return runner.canRun(DefaultRunExecutor.EXECUTOR_ID, environment.getRunProfile());
  }
  @Nullable
  @Override
  public RunProfileState getState(
      @NotNull Executor executor, @NotNull final ExecutionEnvironment executionEnvironment)
      throws ExecutionException {
    val module = getConfigurationModule().getModule();
    if (module == null) {
      throw new ExecutionException("Module is null");
    }

    DotNetModuleExtension<?> extension =
        ModuleUtilCore.getExtension(module, DotNetModuleExtension.class);

    if (extension == null) {
      throw new ExecutionException("Module don't have .NET extension");
    }

    Sdk sdk = extension.getSdk();
    if (sdk == null) {
      throw new ExecutionException("SDK for module is not defined");
    }

    DebugConnectionInfo debugConnectionInfo = null;
    if (executor instanceof DefaultDebugExecutor) {
      debugConnectionInfo = new DebugConnectionInfo("127.0.0.1", -1, true);
    }

    DotNetConfiguration runProfile = (DotNetConfiguration) executionEnvironment.getRunProfile();
    GeneralCommandLine runCommandLine =
        extension.createDefaultCommandLine(sdk, debugConnectionInfo);
    String programParameters = runProfile.getProgramParameters();
    if (!StringUtil.isEmpty(programParameters)) {
      runCommandLine.addParameters(StringUtil.split(programParameters, " "));
    }
    runCommandLine.setPassParentEnvironment(runProfile.isPassParentEnvs());
    runCommandLine.getEnvironment().putAll(runProfile.getEnvs());
    runCommandLine.setWorkDirectory(
        DotNetMacroUtil.expand(module, runProfile.getWorkingDirectory(), false));

    DotNetRunProfileState state = new DotNetRunProfileState(executionEnvironment, runCommandLine);
    if (debugConnectionInfo != null) {
      state.putUserData(DotNetRunKeys.DEBUG_CONNECTION_INFO_KEY, debugConnectionInfo);
    }

    return state;
  }
Exemplo n.º 13
0
  @Override
  public boolean executeTask(
      final DataContext dataContext,
      RunConfiguration configuration,
      final ExecutionEnvironment env,
      RunConfigurableBeforeRunTask task) {
    RunnerAndConfigurationSettings settings = task.getSettings();
    if (settings == null) {
      return false;
    }
    final Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    final String executorId = executor.getId();
    ExecutionEnvironmentBuilder builder =
        ExecutionEnvironmentBuilder.createOrNull(executor, settings);
    if (builder == null) {
      return false;
    }
    final ExecutionEnvironment environment = builder.build();
    environment.setExecutionId(env.getExecutionId());
    if (!ExecutionTargetManager.canRun(settings, env.getExecutionTarget())) {
      return false;
    }

    if (!environment.getRunner().canRun(executorId, environment.getRunProfile())) {
      return false;
    } else {
      final Semaphore targetDone = new Semaphore();
      final Ref<Boolean> result = new Ref<Boolean>(false);
      final Disposable disposable = Disposer.newDisposable();

      myProject
          .getMessageBus()
          .connect(disposable)
          .subscribe(
              ExecutionManager.EXECUTION_TOPIC,
              new ExecutionAdapter() {
                @Override
                public void processStartScheduled(
                    final String executorIdLocal, final ExecutionEnvironment environmentLocal) {
                  if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
                    targetDone.down();
                  }
                }

                @Override
                public void processNotStarted(
                    final String executorIdLocal,
                    @NotNull final ExecutionEnvironment environmentLocal) {
                  if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
                    targetDone.up();
                  }
                }

                @Override
                public void processStarted(
                    final String executorIdLocal,
                    @NotNull final ExecutionEnvironment environmentLocal,
                    @NotNull final ProcessHandler handler) {
                  if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
                    handler.addProcessListener(
                        new ProcessAdapter() {
                          @Override
                          public void processTerminated(ProcessEvent event) {
                            result.set(event.getExitCode() == 0);
                            targetDone.up();
                          }
                        });
                  }
                }
              });

      try {
        ApplicationManager.getApplication()
            .invokeAndWait(
                new Runnable() {
                  @Override
                  public void run() {
                    try {
                      environment.getRunner().execute(environment);
                    } catch (ExecutionException e) {
                      targetDone.up();
                      LOG.error(e);
                    }
                  }
                },
                ModalityState.NON_MODAL);
      } catch (Exception e) {
        LOG.error(e);
        Disposer.dispose(disposable);
        return false;
      }

      targetDone.waitFor();
      Disposer.dispose(disposable);

      return result.get();
    }
  }
  void execute(@NotNull AnActionEvent e, @NotNull ExecutionEnvironment environment) {
    MyRunProfile profile = getRunProfile(environment);
    if (profile == null) {
      return;
    }

    final ExecutionEnvironmentBuilder environmentBuilder =
        new ExecutionEnvironmentBuilder(environment).runProfile(profile);

    final InputEvent event = e.getInputEvent();
    if (!(event instanceof MouseEvent) || !event.isShiftDown()) {
      performAction(environmentBuilder);
      return;
    }

    final LinkedHashMap<Executor, ProgramRunner> availableRunners = new LinkedHashMap<>();
    for (Executor ex :
        new Executor[] {
          DefaultRunExecutor.getRunExecutorInstance(),
          DefaultDebugExecutor.getDebugExecutorInstance()
        }) {
      final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(ex.getId(), profile);
      if (runner != null) {
        availableRunners.put(ex, runner);
      }
    }

    if (availableRunners.isEmpty()) {
      LOG.error(environment.getExecutor().getActionName() + " is not available now");
    } else if (availableRunners.size() == 1) {
      //noinspection ConstantConditions
      performAction(environmentBuilder.runner(availableRunners.get(environment.getExecutor())));
    } else {
      final JBList list = new JBList(availableRunners.keySet());
      list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      list.setSelectedValue(environment.getExecutor(), true);
      list.setCellRenderer(
          new DefaultListCellRenderer() {
            @NotNull
            @Override
            public Component getListCellRendererComponent(
                @NotNull JList list,
                Object value,
                int index,
                boolean isSelected,
                boolean cellHasFocus) {
              final Component component =
                  super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
              if (value instanceof Executor) {
                setText(UIUtil.removeMnemonic(((Executor) value).getStartActionText()));
                setIcon(((Executor) value).getIcon());
              }
              return component;
            }
          });
      //noinspection ConstantConditions
      JBPopupFactory.getInstance()
          .createListPopupBuilder(list)
          .setTitle("Restart Failed Tests")
          .setMovable(false)
          .setResizable(false)
          .setRequestFocus(true)
          .setItemChoosenCallback(
              () -> {
                final Object value = list.getSelectedValue();
                if (value instanceof Executor) {
                  //noinspection ConstantConditions
                  performAction(
                      environmentBuilder
                          .runner(availableRunners.get(value))
                          .executor((Executor) value));
                }
              })
          .createPopup()
          .showUnderneathOf(event.getComponent());
    }
  }
  @Override
  public boolean executeTask(
      DataContext context,
      RunConfiguration configuration,
      ExecutionEnvironment env,
      ExternalSystemBeforeRunTask beforeRunTask) {

    final ExternalSystemTaskExecutionSettings executionSettings =
        beforeRunTask.getTaskExecutionSettings();

    final List<ExternalTaskPojo> tasks = ContainerUtilRt.newArrayList();
    for (String taskName : executionSettings.getTaskNames()) {
      tasks.add(new ExternalTaskPojo(taskName, executionSettings.getExternalProjectPath(), null));
    }
    if (tasks.isEmpty()) return true;

    final Pair<ProgramRunner, ExecutionEnvironment> pair =
        ExternalSystemUtil.createRunner(
            executionSettings, DefaultRunExecutor.EXECUTOR_ID, myProject, mySystemId);

    if (pair == null) return false;

    final ProgramRunner runner = pair.first;
    final ExecutionEnvironment environment = pair.second;
    environment.setExecutionId(env.getExecutionId());

    final Semaphore targetDone = new Semaphore();
    final Ref<Boolean> result = new Ref<Boolean>(false);
    final Disposable disposable = Disposer.newDisposable();

    final Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    final String executorId = executor.getId();

    myProject
        .getMessageBus()
        .connect(disposable)
        .subscribe(
            ExecutionManager.EXECUTION_TOPIC,
            new ExecutionAdapter() {
              public void processStartScheduled(
                  final String executorIdLocal, final ExecutionEnvironment environmentLocal) {
                if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
                  targetDone.down();
                }
              }

              public void processNotStarted(
                  final String executorIdLocal,
                  @NotNull final ExecutionEnvironment environmentLocal) {
                if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
                  targetDone.up();
                }
              }

              public void processStarted(
                  final String executorIdLocal,
                  @NotNull final ExecutionEnvironment environmentLocal,
                  @NotNull final ProcessHandler handler) {
                if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
                  handler.addProcessListener(
                      new ProcessAdapter() {
                        public void processTerminated(ProcessEvent event) {
                          result.set(event.getExitCode() == 0);
                          targetDone.up();
                          environmentLocal.getContentToReuse();
                        }
                      });
                }
              }
            });

    try {
      ApplicationManager.getApplication()
          .invokeAndWait(
              new Runnable() {
                @Override
                public void run() {
                  try {
                    runner.execute(environment);
                  } catch (ExecutionException e) {
                    targetDone.up();
                    LOG.error(e);
                  }
                }
              },
              ModalityState.NON_MODAL);
    } catch (Exception e) {
      LOG.error(e);
      Disposer.dispose(disposable);
      return false;
    }

    targetDone.waitFor();
    Disposer.dispose(disposable);

    return result.get();
  }
 public static void restart(@NotNull ExecutionEnvironment environment) {
   if (!ExecutorRegistry.getInstance().isStarting(environment)) {
     ExecutionManager.getInstance(environment.getProject()).restartRunProfile(environment);
   }
 }
  @Override
  public void restartRunProfile(@NotNull final ExecutionEnvironment environment) {
    RunnerAndConfigurationSettings configuration = environment.getRunnerAndConfigurationSettings();

    List<RunContentDescriptor> runningIncompatible;
    if (configuration == null) {
      runningIncompatible = Collections.emptyList();
    } else {
      runningIncompatible = getIncompatibleRunningDescriptors(configuration);
    }

    RunContentDescriptor contentToReuse = environment.getContentToReuse();
    final List<RunContentDescriptor> runningOfTheSameType = new SmartList<>();
    if (configuration != null && configuration.isSingleton()) {
      runningOfTheSameType.addAll(getRunningDescriptorsOfTheSameConfigType(configuration));
    } else if (isProcessRunning(contentToReuse)) {
      runningOfTheSameType.add(contentToReuse);
    }

    List<RunContentDescriptor> runningToStop =
        ContainerUtil.concat(runningOfTheSameType, runningIncompatible);
    if (!runningToStop.isEmpty()) {
      if (configuration != null) {
        if (!runningOfTheSameType.isEmpty()
            && (runningOfTheSameType.size() > 1
                || contentToReuse == null
                || runningOfTheSameType.get(0) != contentToReuse)
            && !userApprovesStopForSameTypeConfigurations(
                environment.getProject(), configuration.getName(), runningOfTheSameType.size())) {
          return;
        }
        if (!runningIncompatible.isEmpty()
            && !userApprovesStopForIncompatibleConfigurations(
                myProject, configuration.getName(), runningIncompatible)) {
          return;
        }
      }

      for (RunContentDescriptor descriptor : runningToStop) {
        stop(descriptor);
      }
    }

    if (myAwaitingRunProfiles.get(environment.getRunProfile()) == environment) {
      // defense from rerunning exactly the same ExecutionEnvironment
      return;
    }
    myAwaitingRunProfiles.put(environment.getRunProfile(), environment);

    awaitTermination(
        new Runnable() {
          @Override
          public void run() {
            if (myAwaitingRunProfiles.get(environment.getRunProfile()) != environment) {
              // a new rerun has been requested before starting this one, ignore this rerun
              return;
            }
            if ((DumbService.getInstance(myProject).isDumb()
                    && !Registry.is("dumb.aware.run.configurations"))
                || ExecutorRegistry.getInstance().isStarting(environment)) {
              awaitTermination(this, 100);
              return;
            }

            for (RunContentDescriptor descriptor : runningOfTheSameType) {
              ProcessHandler processHandler = descriptor.getProcessHandler();
              if (processHandler != null && !processHandler.isProcessTerminated()) {
                awaitTermination(this, 100);
                return;
              }
            }
            myAwaitingRunProfiles.remove(environment.getRunProfile());
            start(environment);
          }
        },
        50);
  }
  @Override
  public void startRunProfile(
      @NotNull final RunProfileStarter starter,
      @NotNull final RunProfileState state,
      @NotNull final ExecutionEnvironment environment) {
    final Project project = environment.getProject();
    RunContentDescriptor reuseContent = getContentManager().getReuseContent(environment);
    if (reuseContent != null) {
      reuseContent.setExecutionId(environment.getExecutionId());
      environment.setContentToReuse(reuseContent);
    }

    final Executor executor = environment.getExecutor();
    project
        .getMessageBus()
        .syncPublisher(EXECUTION_TOPIC)
        .processStartScheduled(executor.getId(), environment);

    Runnable startRunnable;
    startRunnable =
        () -> {
          if (project.isDisposed()) {
            return;
          }

          RunProfile profile = environment.getRunProfile();
          boolean started = false;
          try {
            project
                .getMessageBus()
                .syncPublisher(EXECUTION_TOPIC)
                .processStarting(executor.getId(), environment);

            final RunContentDescriptor descriptor = starter.execute(state, environment);
            if (descriptor != null) {
              final Trinity<RunContentDescriptor, RunnerAndConfigurationSettings, Executor>
                  trinity =
                      Trinity.create(
                          descriptor, environment.getRunnerAndConfigurationSettings(), executor);
              myRunningConfigurations.add(trinity);
              Disposer.register(descriptor, () -> myRunningConfigurations.remove(trinity));
              getContentManager()
                  .showRunContent(executor, descriptor, environment.getContentToReuse());
              final ProcessHandler processHandler = descriptor.getProcessHandler();
              if (processHandler != null) {
                if (!processHandler.isStartNotified()) {
                  processHandler.startNotify();
                }
                project
                    .getMessageBus()
                    .syncPublisher(EXECUTION_TOPIC)
                    .processStarted(executor.getId(), environment, processHandler);
                started = true;

                ProcessExecutionListener listener =
                    new ProcessExecutionListener(
                        project, executor.getId(), environment, processHandler, descriptor);
                processHandler.addProcessListener(listener);

                // Since we cannot guarantee that the listener is added before process handled is
                // start notified,
                // we have to make sure the process termination events are delivered to the clients.
                // Here we check the current process state and manually deliver events, while
                // the ProcessExecutionListener guarantees each such event is only delivered once
                // either by this code, or by the ProcessHandler.

                boolean terminating = processHandler.isProcessTerminating();
                boolean terminated = processHandler.isProcessTerminated();
                if (terminating || terminated) {
                  listener.processWillTerminate(
                      new ProcessEvent(processHandler), false /*doesn't matter*/);

                  if (terminated) {
                    //noinspection ConstantConditions
                    int exitCode = processHandler.getExitCode();
                    listener.processTerminated(new ProcessEvent(processHandler, exitCode));
                  }
                }
              }
              environment.setContentToReuse(descriptor);
            }
          } catch (ProcessCanceledException e) {
            LOG.info(e);
          } catch (ExecutionException e) {
            ExecutionUtil.handleExecutionError(project, executor.getToolWindowId(), profile, e);
            LOG.info(e);
          } finally {
            if (!started) {
              project
                  .getMessageBus()
                  .syncPublisher(EXECUTION_TOPIC)
                  .processNotStarted(executor.getId(), environment);
            }
          }
        };

    if (ApplicationManager.getApplication().isUnitTestMode() && !myForceCompilationInTests) {
      startRunnable.run();
    } else {
      compileAndRun(
          () -> TransactionGuard.submitTransaction(project, startRunnable),
          environment,
          state,
          () -> {
            if (!project.isDisposed()) {
              project
                  .getMessageBus()
                  .syncPublisher(EXECUTION_TOPIC)
                  .processNotStarted(executor.getId(), environment);
            }
          });
    }
  }
Exemplo n.º 19
0
 @Override
 public RunnerSettings getRunnerSettings() {
   return myEnvironment.getRunnerSettings();
 }
 private static void start(@NotNull ExecutionEnvironment environment) {
   RunnerAndConfigurationSettings settings = environment.getRunnerAndConfigurationSettings();
   ProgramRunnerUtil.executeConfiguration(
       environment, settings != null && settings.isEditBeforeRun(), true);
 }
Exemplo n.º 21
0
 @Override
 public ConfigurationPerRunnerSettings getConfigurationSettings() {
   return myEnvironment.getConfigurationSettings();
 }
  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);
    }
  }