Task plugin: Track ChangeData in TaskTree

Track ChangeData as part of TaskTree so that the information of a change
can be used to construct change task properties in future.

Change-Id: I5a85c35b837ec85a30d31a01607b884e98c35839
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/TaskAttributeFactory.java b/src/main/java/com/googlesource/gerrit/plugins/task/TaskAttributeFactory.java
index 65cd203..0baea8b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/task/TaskAttributeFactory.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/task/TaskAttributeFactory.java
@@ -90,8 +90,8 @@
   protected PluginDefinedInfo createWithExceptions(ChangeData c) {
     TaskPluginAttribute a = new TaskPluginAttribute();
     try {
-      for (Node node : definitions.getRootNodes()) {
-        new AttributeFactory(c, node).create().ifPresent(t -> a.roots.add(t));
+      for (Node node : definitions.getRootNodes(c)) {
+        new AttributeFactory(node).create().ifPresent(t -> a.roots.add(t));
       }
     } catch (ConfigInvalidException | IOException e) {
       a.roots.add(invalid());
@@ -104,18 +104,16 @@
   }
 
   protected class AttributeFactory {
-    public ChangeData changeData;
     public Node node;
     public MatchCache matchCache;
     protected Task definition;
     protected TaskAttribute attribute;
 
-    protected AttributeFactory(ChangeData changeData, Node node) {
-      this(changeData, node, new MatchCache(predicateCache, changeData));
+    protected AttributeFactory(Node node) {
+      this(node, new MatchCache(predicateCache, node.getChangeData()));
     }
 
-    protected AttributeFactory(ChangeData changeData, Node node, MatchCache matchCache) {
-      this.changeData = changeData;
+    protected AttributeFactory(Node node, MatchCache matchCache) {
       this.node = node;
       this.matchCache = matchCache;
       this.definition = node.definition;
@@ -245,9 +243,7 @@
         if (subNode == null) {
           subTasks.add(invalid());
         } else {
-          new AttributeFactory(changeData, subNode, matchCache)
-              .create()
-              .ifPresent(t -> subTasks.add(t));
+          new AttributeFactory(subNode, matchCache).create().ifPresent(t -> subTasks.add(t));
         }
       }
       if (subTasks.isEmpty()) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/TaskTree.java b/src/main/java/com/googlesource/gerrit/plugins/task/TaskTree.java
index 46ad180..94cca58 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/task/TaskTree.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/task/TaskTree.java
@@ -65,6 +65,8 @@
   protected final Provider<ChangeQueryBuilder> changeQueryBuilderProvider;
   protected final Provider<ChangeQueryProcessor> changeQueryProcessorProvider;
 
+  protected ChangeData changeData;
+
   @Inject
   public TaskTree(
       AccountResolver accountResolver,
@@ -86,7 +88,8 @@
     taskFactory.masquerade(psa);
   }
 
-  public List<Node> getRootNodes() throws ConfigInvalidException, IOException {
+  public List<Node> getRootNodes(ChangeData changeData) throws ConfigInvalidException, IOException {
+    this.changeData = changeData;
     return root.getRootNodes();
   }
 
@@ -114,6 +117,10 @@
       }
       nodes.add(node);
     }
+
+    public ChangeData getChangeData() {
+      return TaskTree.this.changeData;
+    }
   }
 
   protected class Root extends NodeList {