@Nullable
  private Location buildLocation() {
    if (mySelectedTaskProvider == null) {
      return null;
    }
    ExternalTaskExecutionInfo task = mySelectedTaskProvider.produce();
    if (task == null) {
      return null;
    }

    String projectPath = task.getSettings().getExternalProjectPath();
    String name =
        myExternalSystemId.getReadableName()
            + projectPath
            + StringUtil.join(task.getSettings().getTaskNames(), " ");
    // We create a dummy text file instead of re-using external system file in order to avoid
    // clashing with other configuration producers.
    // For example gradle files are enhanced groovy scripts but we don't want to run them via
    // regular IJ groovy script runners.
    // Gradle tooling api should be used for running gradle tasks instead. IJ execution sub-system
    // operates on Location objects
    // which encapsulate PsiElement and groovy runners are automatically applied if that PsiElement
    // IS-A GroovyFile.
    PsiFile file =
        PsiFileFactory.getInstance(myProject)
            .createFileFromText(name, PlainTextFileType.INSTANCE, "nichts");

    return new ExternalSystemTaskLocation(myProject, file, task);
  }
 public void actionPerformed(@NotNull AnActionEvent e) {
   final ExternalTaskExecutionInfo taskExecutionInfo =
       ExternalSystemActionUtil.buildTaskInfo(myTaskData);
   ExternalSystemUtil.runTask(
       taskExecutionInfo.getSettings(),
       taskExecutionInfo.getExecutorId(),
       getProject(e),
       myTaskData.getOwner());
 }
Exemplo n.º 3
0
  /**
   * Is expected to be called when given task info is about to be executed.
   *
   * <p>Basically, this method updates recent tasks list at the corresponding external system tool
   * window and persists new recent tasks state.
   *
   * @param taskInfo task which is about to be executed
   * @param project target project
   */
  public static void updateRecentTasks(
      @NotNull ExternalTaskExecutionInfo taskInfo, @NotNull Project project) {
    ProjectSystemId externalSystemId = taskInfo.getSettings().getExternalSystemId();
    ExternalSystemRecentTasksList recentTasksList =
        getToolWindowElement(
            ExternalSystemRecentTasksList.class,
            project,
            ExternalSystemDataKeys.RECENT_TASKS_LIST,
            externalSystemId);
    if (recentTasksList == null) {
      return;
    }
    recentTasksList.setFirst(taskInfo);

    ExternalSystemManager<?, ?, ?, ?, ?> manager =
        ExternalSystemApiUtil.getManager(externalSystemId);
    assert manager != null;
    AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project);
    settings.setRecentTasks(recentTasksList.getModel().getTasks());
  }