@AutoCodec for LicenseProvider.

PiperOrigin-RevId: 185728682
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD
index 51d8726..fb7070a 100644
--- a/src/main/java/com/google/devtools/build/lib/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/BUILD
@@ -515,6 +515,7 @@
         "//src/main/java/com/google/devtools/build/lib/collect",
         "//src/main/java/com/google/devtools/build/lib/collect/compacthashset",
         "//src/main/java/com/google/devtools/build/lib/collect/nestedset",
+        "//src/main/java/com/google/devtools/build/lib/collect/nestedset:serialization",
         "//src/main/java/com/google/devtools/build/lib/concurrent",
         "//src/main/java/com/google/devtools/build/lib/graph",
         "//src/main/java/com/google/devtools/build/lib/profiler",
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/LicensesProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/LicensesProvider.java
index d52a050..e6cb1bf 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/LicensesProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/LicensesProvider.java
@@ -19,12 +19,15 @@
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.packages.License;
+import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
+import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
+import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.Strategy;
 import java.util.Objects;
 
-/**
- * A {@link ConfiguredTarget} that has licensed targets in its transitive closure.
- */
+/** A {@link ConfiguredTarget} that has licensed targets in its transitive closure. */
+@AutoCodec(strategy = Strategy.POLYMORPHIC)
 public interface LicensesProvider extends TransitiveInfoProvider {
+  ObjectCodec<LicensesProvider> CODEC = new LicensesProvider_AutoCodec();
 
   /**
    * The set of label - license associations in the transitive closure.
@@ -44,10 +47,11 @@
    */
   boolean hasOutputLicenses();
 
-  /**
-   * License association for a particular target.
-   */
-  public static final class TargetLicense {
+  /** License association for a particular target. */
+  @AutoCodec
+  final class TargetLicense {
+    public static final ObjectCodec<TargetLicense> CODEC =
+        new LicensesProvider_TargetLicense_AutoCodec();
 
     private final Label label;
     private final License license;
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/LicensesProviderImpl.java b/src/main/java/com/google/devtools/build/lib/analysis/LicensesProviderImpl.java
index fd4f467..7229aec 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/LicensesProviderImpl.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/LicensesProviderImpl.java
@@ -24,12 +24,16 @@
 import com.google.devtools.build.lib.packages.AttributeMap;
 import com.google.devtools.build.lib.packages.License;
 import com.google.devtools.build.lib.packages.Rule;
+import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
+import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 
-/**
- * A {@link ConfiguredTarget} that has licensed targets in its transitive closure.
- */
+/** A {@link ConfiguredTarget} that has licensed targets in its transitive closure. */
 @Immutable
+@AutoCodec
 public final class LicensesProviderImpl implements LicensesProvider {
+  public static final ObjectCodec<LicensesProviderImpl> CODEC =
+      new LicensesProviderImpl_AutoCodec();
+
   public static final LicensesProvider EMPTY =
       new LicensesProviderImpl(NestedSetBuilder.<TargetLicense>emptySet(Order.LINK_ORDER), null);
 
diff --git a/src/main/java/com/google/devtools/build/lib/packages/License.java b/src/main/java/com/google/devtools/build/lib/packages/License.java
index 6467a7e..de63c5e 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/License.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/License.java
@@ -27,21 +27,24 @@
 import com.google.devtools.build.lib.events.Event;
 import com.google.devtools.build.lib.events.EventHandler;
 import com.google.devtools.build.lib.events.Location;
-
+import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
+import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
+import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.List;
 import java.util.Set;
 
-/**
- * Support for license and distribution checking.
- */
-@Immutable @ThreadSafe
+/** Support for license and distribution checking. */
+@Immutable
+@ThreadSafe
+@AutoCodec
 public final class License {
+  public static final ObjectCodec<License> CODEC = new License_AutoCodec();
 
-  private final Set<LicenseType> licenseTypes;
-  private final Set<Label> exceptions;
+  private final ImmutableSet<LicenseType> licenseTypes;
+  private final ImmutableSet<Label> exceptions;
 
   /**
    * The error that's thrown if a build file contains an invalid license string.
@@ -84,11 +87,11 @@
   }
 
   /**
-   * An instance of LicenseType.None with no exceptions, used for packages
-   * outside of third_party which have no license clause in their BUILD files.
+   * An instance of LicenseType.None with no exceptions, used for packages outside of third_party
+   * which have no license clause in their BUILD files.
    */
   public static final License NO_LICENSE =
-      new License(ImmutableSet.of(LicenseType.NONE), Collections.<Label>emptySet());
+      new License(ImmutableSet.of(LicenseType.NONE), ImmutableSet.of());
 
   /**
    * A default instance of Distributions which is used for packages which
@@ -171,15 +174,17 @@
     return ImmutableTable.copyOf(result);
   }
 
-  private License(Set<LicenseType> licenseTypes, Set<Label> exceptions) {
+  @AutoCodec.Instantiator
+  @VisibleForSerialization
+  License(ImmutableSet<LicenseType> licenseTypes, ImmutableSet<Label> exceptions) {
     // Defensive copy is done in .of()
     this.licenseTypes = licenseTypes;
     this.exceptions = exceptions;
   }
 
   public static License of(Collection<LicenseType> licenses, Collection<Label> exceptions) {
-    Set<LicenseType> licenseSet = ImmutableSet.copyOf(licenses);
-    Set<Label> exceptionSet = ImmutableSet.copyOf(exceptions);
+    ImmutableSet<LicenseType> licenseSet = ImmutableSet.copyOf(licenses);
+    ImmutableSet<Label> exceptionSet = ImmutableSet.copyOf(exceptions);
 
     if (exceptionSet.isEmpty() && licenseSet.equals(ImmutableSet.of(LicenseType.NONE))) {
       return License.NO_LICENSE;