@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);
              });
    }
  }
Beispiel #2
0
 @Override
 public void readExternal(Element element) {
   super.readExternal(element);
   Attribute configurationNameAttr = element.getAttribute("run_configuration_name");
   Attribute configurationTypeAttr = element.getAttribute("run_configuration_type");
   myConfigurationName = configurationNameAttr != null ? configurationNameAttr.getValue() : null;
   myConfigurationType = configurationTypeAttr != null ? configurationTypeAttr.getValue() : null;
 }
Beispiel #3
0
 @Override
 public void writeExternal(Element element) {
   super.writeExternal(element);
   if (myConfigurationName != null && myConfigurationType != null) {
     element.setAttribute("run_configuration_name", myConfigurationName);
     element.setAttribute("run_configuration_type", myConfigurationType);
   } else if (mySettings != null) {
     element.setAttribute("run_configuration_name", mySettings.getName());
     element.setAttribute("run_configuration_type", mySettings.getType().getId());
   }
 }