/*
 * Copyright 2000-2015 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jetbrains.plugins.gradle.tooling.builder;

import org.gradle.api.Project;
import org.gradle.api.Task;

import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

public class TasksFactory {
  private Map<Project, Set<Task>> allTasks;

  private void collectTasks(Project root) {
    allTasks = root.getAllTasks(true);
  }

  public Set<Task> getTasks(Project project) {
    if (allTasks == null) {
      collectTasks(project.getRootProject());
    }

    Set<Task> tasks = new LinkedHashSet<Task>(allTasks.get(project));
    for (Project subProject : project.getSubprojects()) {
      tasks.addAll(allTasks.get(subProject));
    }
    return tasks;
  }
}
@@ -730,65 +730,9 @@
 til.
-LinkedHashSet;%0Aimport java.util.Map;%0Aimport java.util.Set
+*
 ;%0A%0Ap
@@ -768,16 +768,22 @@
 private 
+final 
 Map%3CProj
@@ -806,16 +806,129 @@
 allTasks
+ = new HashMap%3CProject, Set%3CTask%3E%3E();%0A  private final Set%3CProject%3E processedRootProjects = new HashSet%3CProject%3E()
 ;%0A%0A  pri
@@ -978,19 +978,24 @@
 allTasks
- = 
+.putAll(
 root.get
@@ -1008,16 +1008,17 @@
 ks(true)
+)
 ;%0A  %7D%0A%0A 
@@ -1071,28 +1071,102 @@
     
-if (allTasks == null
+Project rootProject = project.getRootProject();%0A    if (processedRootProjects.add(rootProject)
 ) %7B%0A
@@ -1184,29 +1184,18 @@
 ctTasks(
-p
 ro
-ject.getRo
 otProjec
@@ -1195,18 +1195,16 @@
 tProject
-()
 );%0A    %7D

fix shared tasks cached data for multiple root projects