Exemplo n.º 1
0
  private void findTasks(
      Project project,
      Map<String, LaunchableGradleTaskSelector> taskSelectors,
      Collection<String> visibleTasks) {
    for (Project child : project.getChildProjects().values()) {
      findTasks(child, taskSelectors, visibleTasks);
    }

    for (Task task : taskLister.listProjectTasks(project)) {
      // in the map, store a minimally populated LaunchableGradleTaskSelector that contains just the
      // description and the path
      // replace the LaunchableGradleTaskSelector stored in the map iff we come across a task with
      // the same name whose path has a smaller ordering
      // this way, for each task selector, its description will be the one from the selected task
      // with the 'smallest' path
      if (!taskSelectors.containsKey(task.getName())) {
        LaunchableGradleTaskSelector taskSelector =
            new LaunchableGradleTaskSelector()
                .setDescription(task.getDescription())
                .setPath(task.getPath());
        taskSelectors.put(task.getName(), taskSelector);
      } else {
        LaunchableGradleTaskSelector taskSelector = taskSelectors.get(task.getName());
        if (hasPathWithLowerOrdering(task, taskSelector)) {
          taskSelector.setDescription(task.getDescription()).setPath(task.getPath());
        }
      }

      // visible tasks are specified as those that have a non-empty group
      if (PublicTaskSpecification.INSTANCE.isSatisfiedBy(task)) {
        visibleTasks.add(task.getName());
      }
    }
  }
  private static List<LaunchableGradleTask> tasks(
      DefaultGradleProject owner, TaskContainerInternal tasks) {
    tasks.discoverTasks();
    SortedSet<String> taskNames = tasks.getNames();
    List<LaunchableGradleTask> out = new ArrayList<LaunchableGradleTask>(taskNames.size());
    for (String taskName : taskNames) {
      Task t = tasks.findByName(taskName);
      if (t != null) {
        out.add(
            new LaunchableGradleProjectTask()
                .setProject(owner)
                .setPath(t.getPath())
                .setName(t.getName())
                .setDisplayName(t.toString())
                .setDescription(t.getDescription())
                .setPublic(PublicTaskSpecification.INSTANCE.isSatisfiedBy(t)));
      }
    }

    return out;
  }