com.intellij.execution.BeforeRunTask Java Examples

The following examples show how to use com.intellij.execution.BeforeRunTask. 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: PantsIntegrationTestCase.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
protected void assertAndRunPantsMake(JUnitConfiguration runConfiguration) {

    RunManager runManager = RunManager.getInstance(myProject);
    assertTrue(runManager instanceof RunManagerImpl);
    RunManagerImpl runManagerImpl = (RunManagerImpl) runManager;

    RunnerAndConfigurationSettings runnerAndConfigurationSettings =
      runManagerImpl.createConfiguration(runConfiguration, JUnitConfigurationType.getInstance().getConfigurationFactories()[0]);
    runManagerImpl.addConfiguration(runnerAndConfigurationSettings, false);

    // Make sure PantsMake is the one and only task before JUnit run.
    List<BeforeRunTask<?>> beforeRunTaskList = runManagerImpl.getBeforeRunTasks(runConfiguration);
    assertEquals(1, beforeRunTaskList.size());
    BeforeRunTask task = beforeRunTaskList.iterator().next();
    assertEquals(PantsMakeBeforeRun.ID, task.getProviderId());

    /*
     * Manually invoke BeforeRunTask as {@link ExecutionManager#compileAndRun} launches another task asynchronously,
     * and there is no way to catch that.
     */
    BeforeRunTaskProvider provider = BeforeRunTaskProvider.getProvider(myProject, task.getProviderId());
    assertNotNull(String.format("Cannot find BeforeRunTaskProvider for id='%s'", task.getProviderId()), provider);
    assertTrue(provider.executeTask(null, runConfiguration, null, task));
  }
 
Example #2
Source File: BeforeRunStepsPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean checkBeforeRunTasksAbility(boolean checkOnlyAddAction) {
  if (isUnknown()) {
    return false;
  }
  Set<Key> activeProviderKeys = getActiveProviderKeys();
  final BeforeRunTaskProvider<BeforeRunTask>[] providers = Extensions.getExtensions(BeforeRunTaskProvider.EP_NAME, myRunConfiguration.getProject());
  for (final BeforeRunTaskProvider<BeforeRunTask> provider : providers) {
    if (provider.createTask(myRunConfiguration) != null) {
      if (!checkOnlyAddAction) {
        return true;
      }
      else if (!provider.isSingleton() || !activeProviderKeys.contains(provider.getId())) {
        return true;
      }
    }
  }
  return false;
}
 
Example #3
Source File: CompoundRunConfigurationSettingsEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean canBeAdded(@Nonnull RunConfiguration candidate, @Nonnull final CompoundRunConfiguration root) {
  if (candidate.getType() == root.getType() && candidate.getName().equals(root.getName())) return false;
  List<BeforeRunTask> tasks = myRunManager.getBeforeRunTasks(candidate);
  for (BeforeRunTask task : tasks) {
    if (task instanceof RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask) {
      RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask runTask
              = (RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask)task;
      RunnerAndConfigurationSettings settings = runTask.getSettings();
      if (settings != null) {
        if (!canBeAdded(settings.getConfiguration(), root)) return false;
      }
    }
  }
  if (candidate instanceof CompoundRunConfiguration) {
    Set<RunConfiguration> set = ((CompoundRunConfiguration)candidate).getSetToRun();
    for (RunConfiguration configuration : set) {
      if (!canBeAdded(configuration, root)) return false;
    }
  }
  return true;
}
 
Example #4
Source File: BlazeRunConfigurationSyncListener.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static boolean addBlazeBeforeRunTask(BlazeCommandRunConfiguration config) {
  BeforeRunTaskProvider<?> provider =
      BlazeBeforeRunTaskProvider.getProvider(config.getProject(), BlazeBeforeRunTaskProvider.ID);
  if (provider == null) {
    return false;
  }
  BeforeRunTask<?> task = provider.createTask(config);
  if (task == null) {
    return false;
  }
  task.setEnabled(true);

  List<BeforeRunTask<?>> beforeRunTasks = new ArrayList<>(config.getBeforeRunTasks());
  beforeRunTasks.add(task);
  config.setBeforeRunTasks(beforeRunTasks);

  return true;
}
 
Example #5
Source File: BlazeRunConfigurationSyncListener.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static boolean enableBlazeBeforeRunTask(BlazeCommandRunConfiguration config) {
  @SuppressWarnings("rawtypes")
  List<BeforeRunTask> tasks =
      RunManagerEx.getInstanceEx(config.getProject()).getBeforeRunTasks(config);
  if (tasks.stream().noneMatch(t -> t.getProviderId().equals(BlazeBeforeRunTaskProvider.ID))) {
    return addBlazeBeforeRunTask(config);
  }
  boolean changed = false;
  for (BeforeRunTask<?> task : tasks) {
    if (task.getProviderId().equals(BlazeBeforeRunTaskProvider.ID) && !task.isEnabled()) {
      changed = true;
      task.setEnabled(true);
    }
  }
  return changed;
}
 
Example #6
Source File: BeforeRunStepsPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void customizeCellRenderer(@Nonnull JList<? extends BeforeRunTask> list, BeforeRunTask value, int index, boolean selected, boolean hasFocus) {
  BeforeRunTaskProvider<BeforeRunTask> provider = BeforeRunTaskProvider.getProvider(myRunConfiguration.getProject(), value.getProviderId());
  if (provider != null) {
    setIcon(provider.getTaskIcon(value));
    append(provider.getDescription(value));
  }
}
 
Example #7
Source File: BeforeRunStepsPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void getAllRunBeforeRuns(BeforeRunTask task, Set<RunConfiguration> configurationSet) {
  if (task instanceof RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask) {
    RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask runTask = (RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask)task;
    RunConfiguration configuration = runTask.getSettings().getConfiguration();

    List<BeforeRunTask> tasks = RunManagerImpl.getInstanceImpl(configuration.getProject()).getBeforeRunTasks(configuration);
    for (BeforeRunTask beforeRunTask : tasks) {
      if (beforeRunTask instanceof RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask) {
        if (configurationSet.add(((RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask)beforeRunTask).getSettings().getConfiguration())) {
          getAllRunBeforeRuns(beforeRunTask, configurationSet);
        }
      }
    }
  }
}
 
Example #8
Source File: BeforeRunStepsPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Set<Key> getActiveProviderKeys() {
  Set<Key> result = new HashSet<>();
  for (BeforeRunTask task : myModel.getItems()) {
    result.add(task.getProviderId());
  }
  return result;
}
 
Example #9
Source File: OSSPantsIntegrationTest.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private List<BeforeRunTask<?>> getBeforeRunTask(RunConfiguration configuration) {
  RunManagerImpl runManager = (RunManagerImpl) RunManager.getInstance(myProject);
  RunnerAndConfigurationSettingsImpl configurationSettings = new RunnerAndConfigurationSettingsImpl(runManager, configuration, true);
  runManager.addConfiguration(configurationSettings, true);
  List<BeforeRunTask<?>> tasks = runManager.getBeforeRunTasks(configuration);
  runManager.removeConfiguration(configurationSettings);
  return tasks;
}
 
Example #10
Source File: PantsClasspathRunConfigurationExtension.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * The goal of this function is to find classpath for IntelliJ JUnit/Scala runner.
 * <p/>
 * This function will fail if the projects' Pants doesn't support `--export-classpath-manifest-jar-only`.
 * It also assumes that Pants has created a manifest jar that contains all the classpath links for the
 * particular test that's being run.
 */
@Override
public <T extends RunConfigurationBase> void updateJavaParameters(
  T configuration,
  @NotNull JavaParameters params,
  RunnerSettings runnerSettings
) throws ExecutionException {
  List<BeforeRunTask<?>> tasks = ((RunManagerImpl) RunManager.getInstance(configuration.getProject())).getBeforeRunTasks(configuration);
  boolean builtByPants = tasks.stream().anyMatch(s -> s.getProviderId().equals(PantsMakeBeforeRun.ID));
  // Not built by Pants means it was built by IntelliJ, in which case we don't need to change the classpath.
  if (!builtByPants) {
    return;
  }

  final Module module = findPantsModule(configuration);
  if (module == null) {
    return;
  }

  Set<String> pathsAllowed = calculatePathsAllowed(params);

  final PathsList classpath = params.getClassPath();
  List<String> classpathToKeep = classpath.getPathList().stream()
    .filter(cp -> pathsAllowed.stream().anyMatch(cp::contains)).collect(Collectors.toList());
  classpath.clear();
  classpath.addAll(classpathToKeep);

  VirtualFile manifestJar = PantsUtil.findProjectManifestJar(configuration.getProject())
    .orElseThrow(() -> new ExecutionException("manifest.jar is not found. It should be generated by `./pants export-classpath ...`"));
  classpath.add(manifestJar.getPath());

  PantsExternalMetricsListenerManager.getInstance().logTestRunner(configuration);
}
 
Example #11
Source File: PantsMakeBeforeRun.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
public static void replaceDefaultMakeWithPantsMake(@NotNull RunConfiguration runConfiguration) {
  if (!PantsUtil.isScalaRelatedTestRunConfiguration(runConfiguration) &&
      !(runConfiguration instanceof CommonProgramRunConfigurationParameters)) {
    return;
  }

  RunManager runManager = RunManager.getInstance(runConfiguration.getProject());
  RunManagerImpl runManagerImpl = (RunManagerImpl) runManager;
  BeforeRunTask pantsMakeTask = new ExternalSystemBeforeRunTask(ID, PantsConstants.SYSTEM_ID);
  pantsMakeTask.setEnabled(true);
  runManagerImpl.setBeforeRunTasks(runConfiguration, Collections.singletonList(pantsMakeTask));
}
 
Example #12
Source File: BeforeRunStepsPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private Pair<BeforeRunTask, BeforeRunTaskProvider<BeforeRunTask>> getSelection() {
  final int index = myList.getSelectedIndex();
  if (index == -1) return null;
  BeforeRunTask task = myModel.getElementAt(index);
  Key providerId = task.getProviderId();
  BeforeRunTaskProvider<BeforeRunTask> provider = BeforeRunTaskProvider.getProvider(myRunConfiguration.getProject(), providerId);
  return provider != null ? Pair.create(task, provider) : null;
}
 
Example #13
Source File: BeforeRunStepsPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public List<BeforeRunTask> getTasks(boolean applyCurrentState) {
  if (applyCurrentState) {
    originalTasks.clear();
    originalTasks.addAll(myModel.getItems());
  }
  return Collections.unmodifiableList(originalTasks);
}
 
Example #14
Source File: ConfigurationSettingsEditorWrapper.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void addBeforeLaunchStep(BeforeRunTask<?> task) {
  myBeforeRunStepsPanel.addTask(task);
}
 
Example #15
Source File: AbstractArtifactsBeforeRunTask.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public BeforeRunTask clone() {
  final AbstractArtifactsBeforeRunTask task = (AbstractArtifactsBeforeRunTask)super.clone();
  task.myArtifactPointers = new ArrayList<ArtifactPointer>(myArtifactPointers);
  return task;
}
 
Example #16
Source File: BeforeRunStepsPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void addTask(BeforeRunTask task) {
  myModel.add(task);
}
 
Example #17
Source File: BeforeRunStepsPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
void doAddAction(AnActionButton button) {
  if (isUnknown()) {
    return;
  }

  final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
  final List<BeforeRunTaskProvider<BeforeRunTask>> providers = BeforeRunTaskProvider.EP_NAME.getExtensionList(myRunConfiguration.getProject());
  Set<Key> activeProviderKeys = getActiveProviderKeys();

  DefaultActionGroup actionGroup = new DefaultActionGroup(null, false);
  for (final BeforeRunTaskProvider<BeforeRunTask> provider : providers) {
    if (provider.createTask(myRunConfiguration) == null) continue;
    if (activeProviderKeys.contains(provider.getId()) && provider.isSingleton()) continue;
    AnAction providerAction = new AnAction(provider.getName(), null, provider.getIcon()) {
      @RequiredUIAccess
      @Override
      public void actionPerformed(@Nonnull AnActionEvent e) {
        BeforeRunTask task = provider.createTask(myRunConfiguration);
        if (task == null) {
          return;
        }

        provider.configureTask(myRunConfiguration, task).doWhenProcessed(() -> {
          if (!provider.canExecuteTask(myRunConfiguration, task)) return;
          task.setEnabled(true);

          Set<RunConfiguration> configurationSet = new HashSet<>();
          getAllRunBeforeRuns(task, configurationSet);
          if (configurationSet.contains(myRunConfiguration)) {
            JOptionPane.showMessageDialog(BeforeRunStepsPanel.this,
                                          ExecutionBundle.message("before.launch.panel.cyclic_dependency_warning", myRunConfiguration.getName(), provider.getDescription(task)),
                                          ExecutionBundle.message("warning.common.title"), JOptionPane.WARNING_MESSAGE);
            return;
          }
          addTask(task);
          myListener.fireStepsBeforeRunChanged();
        });
      }
    };
    actionGroup.add(providerAction);
  }
  final ListPopup popup = popupFactory
          .createActionGroupPopup(ExecutionBundle.message("add.new.run.configuration.acrtion.name"), actionGroup, SimpleDataContext.getProjectContext(myRunConfiguration.getProject()), false, false,
                                  false, null, -1, Condition.TRUE);
  popup.show(button.getPreferredPopupPoint());
}
 
Example #18
Source File: ConfigurationSettingsEditorWrapper.java    From consulo with Apache License 2.0 4 votes vote down vote up
public List<BeforeRunTask> getStepsBeforeLaunch() {
  return Collections.unmodifiableList(myBeforeRunStepsPanel.getTasks(true));
}
 
Example #19
Source File: UnknownBeforeRunTaskProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public BeforeRunTask clone() {
  return super.clone();
}
 
Example #20
Source File: MuleConfigurationFactory.java    From mule-intellij-plugins with Apache License 2.0 4 votes vote down vote up
@Override
public void configureBeforeRunTaskDefaults(Key<? extends BeforeRunTask> providerID, BeforeRunTask task)
{
    super.configureBeforeRunTaskDefaults(providerID, task);
}
 
Example #21
Source File: BashConfigurationType.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
@Override
public void onNewConfigurationCreated(@NotNull RunConfiguration configuration) {
    //the last param has to be false because we do not want a fallback to the template (we're creating it right now) (avoiding a SOE)
    RunManagerEx.getInstanceEx(configuration.getProject()).setBeforeRunTasks(configuration, Collections.<BeforeRunTask>emptyList(), false);
}
 
Example #22
Source File: BlazeIntellijPluginConfigurationType.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public void configureBeforeRunTaskDefaults(
    Key<? extends BeforeRunTask> providerID, BeforeRunTask task) {
  task.setEnabled(providerID.equals(BuildPluginBeforeRunTaskProvider.ID));
}
 
Example #23
Source File: BlazeCommandRunConfigurationType.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public void configureBeforeRunTaskDefaults(
    Key<? extends BeforeRunTask> providerID, BeforeRunTask task) {
  task.setEnabled(providerID.equals(BlazeBeforeRunTaskProvider.ID));
}
 
Example #24
Source File: BlazeNativeAndroidDebugger.java    From intellij with Apache License 2.0 4 votes vote down vote up
/** Overridden to stop providing Grade tasks from superclasses */
@Override
public List<BeforeRunTask<?>> getBeforeRunTasks() {
  return Collections.emptyList();
}
 
Example #25
Source File: BlazeNativeAndroidDebugger.java    From intellij with Apache License 2.0 4 votes vote down vote up
/** Overridden to stop providing Grade tasks from superclasses */
@Override
public List<BeforeRunTask<?>> getBeforeRunTasks() {
  return Collections.emptyList();
}
 
Example #26
Source File: WeaveConfigurationFactory.java    From mule-intellij-plugins with Apache License 2.0 4 votes vote down vote up
@Override
public void configureBeforeRunTaskDefaults(Key<? extends BeforeRunTask> providerID, BeforeRunTask task)
{
    super.configureBeforeRunTaskDefaults(providerID, task);
}
 
Example #27
Source File: ConfigurationFactory.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * In this method you can configure defaults for the task, which are preferable to be used for your particular configuration type
 *
 * @param providerID
 * @param task
 */
public void configureBeforeRunTaskDefaults(Key<? extends BeforeRunTask> providerID, BeforeRunTask task) {
}