@Nullable
 private static RunnerAndConfigurationSettings chooseTempSettings(@NotNull Project project) {
   RunnerAndConfigurationSettings selectedConfiguration =
       RunManager.getInstance(project).getSelectedConfiguration();
   if (selectedConfiguration != null && selectedConfiguration.isTemporary()) {
     return selectedConfiguration;
   }
   Iterator<RunnerAndConfigurationSettings> iterator =
       RunManager.getInstance(project).getTempConfigurationsList().iterator();
   return iterator.hasNext() ? iterator.next() : null;
 }
 @Override
 public void actionPerformed(final AnActionEvent e) {
   final Project project = e.getData(CommonDataKeys.PROJECT);
   if (project != null) {
     RunnerAndConfigurationSettings settings = chooseTempSettings(project);
     if (settings != null) {
       final RunManager runManager = RunManager.getInstance(project);
       runManager.makeStable(settings);
     }
   }
 }
 @Override
 public void actionPerformed(final AnActionEvent e) {
   RunManager.getInstance(myProject).setSelectedConfiguration(myConfiguration);
   updatePresentation(
       ExecutionTargetManager.getActiveTarget(myProject),
       myConfiguration,
       myProject,
       e.getPresentation());
 }
  @Override
  @NotNull
  protected DefaultActionGroup createPopupActionGroup(final JComponent button) {
    final DefaultActionGroup allActionsGroup = new DefaultActionGroup();
    final Project project =
        CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(button));
    if (project != null) {
      final RunManagerEx runManager = RunManagerEx.getInstanceEx(project);

      allActionsGroup.add(
          ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_RUN_CONFIGURATIONS));
      allActionsGroup.add(new SaveTemporaryAction());
      allActionsGroup.addSeparator();

      RunnerAndConfigurationSettings selected =
          RunManager.getInstance(project).getSelectedConfiguration();
      if (selected != null) {
        ExecutionTarget activeTarget = ExecutionTargetManager.getActiveTarget(project);
        for (ExecutionTarget eachTarget :
            ExecutionTargetManager.getTargetsToChooseFor(project, selected)) {
          allActionsGroup.add(
              new SelectTargetAction(project, eachTarget, eachTarget.equals(activeTarget)));
        }
        allActionsGroup.addSeparator();
      }

      final ConfigurationType[] types = runManager.getConfigurationFactories();
      for (ConfigurationType type : types) {
        final DefaultActionGroup actionGroup = new DefaultActionGroup();
        Map<String, List<RunnerAndConfigurationSettings>> structure = runManager.getStructure(type);
        for (Map.Entry<String, List<RunnerAndConfigurationSettings>> entry : structure.entrySet()) {
          DefaultActionGroup group =
              entry.getKey() != null ? new DefaultActionGroup(entry.getKey(), true) : actionGroup;
          group.getTemplatePresentation().setIcon(AllIcons.Nodes.Folder);
          for (RunnerAndConfigurationSettings settings : entry.getValue()) {
            group.add(new SelectConfigAction(settings, project));
          }
          if (group != actionGroup) {
            actionGroup.add(group);
          }
        }

        allActionsGroup.add(actionGroup);
        allActionsGroup.addSeparator();
      }
    }
    return allActionsGroup;
  }
コード例 #5
0
  @Nullable
  public static Pair<ProgramRunner, ExecutionEnvironment> createRunner(
      @NotNull ExternalSystemTaskExecutionSettings taskSettings,
      @NotNull String executorId,
      @NotNull Project project,
      @NotNull ProjectSystemId externalSystemId) {
    Executor executor = ExecutorRegistry.getInstance().getExecutorById(executorId);
    if (executor == null) return null;

    String runnerId = getRunnerId(executorId);
    if (runnerId == null) return null;

    ProgramRunner runner = RunnerRegistry.getInstance().findRunnerById(runnerId);
    if (runner == null) return null;

    AbstractExternalSystemTaskConfigurationType configurationType =
        findConfigurationType(externalSystemId);
    if (configurationType == null) return null;

    String name = AbstractExternalSystemTaskConfigurationType.generateName(project, taskSettings);
    RunnerAndConfigurationSettings settings =
        RunManager.getInstance(project)
            .createRunConfiguration(name, configurationType.getFactory());
    ExternalSystemRunConfiguration runConfiguration =
        (ExternalSystemRunConfiguration) settings.getConfiguration();
    runConfiguration.getSettings().setExternalProjectPath(taskSettings.getExternalProjectPath());
    runConfiguration
        .getSettings()
        .setTaskNames(ContainerUtil.newArrayList(taskSettings.getTaskNames()));
    runConfiguration
        .getSettings()
        .setTaskDescriptions(ContainerUtil.newArrayList(taskSettings.getTaskDescriptions()));
    runConfiguration.getSettings().setVmOptions(taskSettings.getVmOptions());
    runConfiguration.getSettings().setScriptParameters(taskSettings.getScriptParameters());
    runConfiguration.getSettings().setExecutionName(taskSettings.getExecutionName());

    return Pair.create(runner, new ExecutionEnvironment(executor, runner, settings, project));
  }