Make packages able to handle Postables as well

Packages can remember events associated with reading the package;
also make them aware of additional Postable events.

Change-Id: Id7933de7e364b142d0c95fd774585d3271204b2b
PiperOrigin-RevId: 158853675
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Package.java b/src/main/java/com/google/devtools/build/lib/packages/Package.java
index 55f39fd..91cc477 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Package.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Package.java
@@ -31,6 +31,7 @@
 import com.google.devtools.build.lib.collect.ImmutableSortedKeyMap;
 import com.google.devtools.build.lib.events.Event;
 import com.google.devtools.build.lib.events.EventHandler;
+import com.google.devtools.build.lib.events.ExtendedEventHandler.Postable;
 import com.google.devtools.build.lib.events.Location;
 import com.google.devtools.build.lib.packages.AttributeMap.AcceptsLabelAttribute;
 import com.google.devtools.build.lib.packages.License.DistributionType;
@@ -191,6 +192,7 @@
   private ImmutableSet<String> features;
 
   private ImmutableList<Event> events;
+  private ImmutableList<Postable> posts;
 
   /**
    * Package initialization, part 1 of 3: instantiates a new package with the
@@ -315,6 +317,7 @@
     this.defaultDistributionSet = builder.defaultDistributionSet;
     this.features = ImmutableSortedSet.copyOf(builder.features);
     this.events = ImmutableList.copyOf(builder.events);
+    this.posts = ImmutableList.copyOf(builder.posts);
   }
 
   /**
@@ -430,6 +433,10 @@
     return containsErrors;
   }
 
+  public List<Postable> getPosts() {
+    return posts;
+  }
+
   public List<Event> getEvents() {
     return events;
   }
@@ -743,6 +750,7 @@
     private List<String> defaultCopts = null;
     private List<String> features = new ArrayList<>();
     private List<Event> events = Lists.newArrayList();
+    private List<Postable> posts = Lists.newArrayList();
     private boolean containsErrors = false;
 
     private License defaultLicense = License.NO_LICENSE;
@@ -824,6 +832,10 @@
       return filename;
     }
 
+    public List<Postable> getPosts() {
+      return posts;
+    }
+
     public List<Event> getEvents() {
       return events;
     }
@@ -926,6 +938,18 @@
       return containsErrors;
     }
 
+    public Builder addPosts(Iterable<Postable> posts) {
+      for (Postable post : posts) {
+        addPost(post);
+      }
+      return this;
+    }
+
+    public Builder addPost(Postable post) {
+      this.posts.add(post);
+      return this;
+    }
+
     public Builder addEvents(Iterable<Event> events) {
       for (Event event : events) {
         addEvent(event);