Create internal/migration-only Starlark API for JavaNativeLibraryProvider (and rename to ..Info)

PiperOrigin-RevId: 314949544
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/BUILD b/src/main/java/com/google/devtools/build/lib/rules/java/BUILD
index 4f9a49d..cb1c28c 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/BUILD
@@ -142,7 +142,7 @@
         "JavaInfo.java",
         "JavaInfoBuildHelper.java",
         "JavaLibraryHelper.java",
-        "JavaNativeLibraryProvider.java",
+        "JavaNativeLibraryInfo.java",
         "JavaOptions.java",
         "JavaPackageConfigurationProvider.java",
         "JavaPluginInfoProvider.java",
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
index 3fb222a..148079d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
@@ -379,7 +379,7 @@
   /**
    * Returns transitive Java native libraries.
    *
-   * @see JavaNativeLibraryProvider
+   * @see JavaNativeLibraryInfo
    */
   protected NestedSet<LibraryToLink> collectTransitiveJavaNativeLibraries() {
     NativeLibraryNestedSetBuilder builder = new NativeLibraryNestedSetBuilder();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java
index d427a8a..c6f6e2d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java
@@ -157,9 +157,7 @@
             JavaStarlarkApiProvider.NAME, JavaStarlarkApiProvider.fromRuleContext())
         .addNativeDeclaredProvider(javaInfo)
         .add(RunfilesProvider.class, RunfilesProvider.simple(runfiles))
-        .add(
-            JavaNativeLibraryProvider.class,
-            new JavaNativeLibraryProvider(transitiveJavaNativeLibraries))
+        .addNativeDeclaredProvider(new JavaNativeLibraryInfo(transitiveJavaNativeLibraries))
         .addNativeDeclaredProvider(new ProguardSpecProvider(proguardSpecs))
         .addOutputGroup(JavaSemantics.SOURCE_JARS_OUTPUT_GROUP, transitiveJavaSourceJars)
         .addOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL, proguardSpecs)
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java
index 5b99dcc..756fc0a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java
@@ -201,7 +201,7 @@
             RunfilesProvider.simple(
                 JavaCommon.getRunfiles(ruleContext, semantics, javaArtifacts, neverLink)))
         .setFilesToBuild(filesToBuild)
-        .addProvider(new JavaNativeLibraryProvider(transitiveJavaNativeLibraries))
+        .addNativeDeclaredProvider(new JavaNativeLibraryInfo(transitiveJavaNativeLibraries))
         .addProvider(JavaSourceInfoProvider.fromJavaTargetAttributes(attributes, semantics))
         .addNativeDeclaredProvider(new ProguardSpecProvider(proguardSpecs))
         .addNativeDeclaredProvider(javaInfo)
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaNativeLibraryInfo.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaNativeLibraryInfo.java
new file mode 100644
index 0000000..7ed44aa
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaNativeLibraryInfo.java
@@ -0,0 +1,91 @@
+// Copyright 2014 The Bazel Authors. All rights reserved.
+//
+// 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 com.google.devtools.build.lib.rules.java;
+
+import com.google.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.collect.nestedset.Depset;
+import com.google.devtools.build.lib.collect.nestedset.NestedSet;
+import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
+import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.packages.BuiltinProvider;
+import com.google.devtools.build.lib.packages.NativeInfo;
+import com.google.devtools.build.lib.rules.cpp.LibraryToLink;
+import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
+import com.google.devtools.build.lib.skylarkbuildapi.java.JavaNativeLibraryInfoApi;
+import com.google.devtools.build.lib.syntax.EvalException;
+
+/**
+ * A target that provides native libraries in the transitive closure of its deps that are needed for
+ * executing Java code.
+ */
+@Immutable
+@AutoCodec
+public final class JavaNativeLibraryInfo
+    extends NativeInfo implements JavaNativeLibraryInfoApi<Artifact, LibraryToLink> {
+
+  public static final Provider PROVIDER = new Provider();
+
+  private final NestedSet<LibraryToLink> transitiveJavaNativeLibraries;
+
+  public JavaNativeLibraryInfo(NestedSet<LibraryToLink> transitiveJavaNativeLibraries) {
+    super(PROVIDER);
+    this.transitiveJavaNativeLibraries = transitiveJavaNativeLibraries;
+  }
+
+  /**
+   * Collects native libraries in the transitive closure of its deps that are needed for executing
+   * Java code.
+   */
+  NestedSet<LibraryToLink> getTransitiveJavaNativeLibraries() {
+    return transitiveJavaNativeLibraries;
+  }
+
+  @Override
+  public Depset /*<LibraryToLink>*/ getTransitiveJavaNativeLibrariesForStarlark() {
+    return Depset.of(LibraryToLink.TYPE, transitiveJavaNativeLibraries);
+  }
+
+  public static JavaNativeLibraryInfo merge(Iterable<JavaNativeLibraryInfo> deps) {
+    NestedSetBuilder<LibraryToLink> transitiveSourceJars = NestedSetBuilder.stableOrder();
+
+    for (JavaNativeLibraryInfo wrapper : deps) {
+      transitiveSourceJars.addTransitive(wrapper.getTransitiveJavaNativeLibraries());
+    }
+    return new JavaNativeLibraryInfo(transitiveSourceJars.build());
+  }
+
+  /** Provider class for {@link JavaNativeLibraryInfo} objects. */
+  public static class Provider extends BuiltinProvider<JavaNativeLibraryInfo>
+      implements JavaNativeLibraryInfoApi.Provider<Artifact, LibraryToLink> {
+
+    private Provider() {
+      super(NAME, JavaNativeLibraryInfo.class);
+    }
+
+    public String getName() {
+      return NAME;
+    }
+
+    @Override
+    public JavaNativeLibraryInfo create(Depset transitiveLibraries)
+        throws EvalException {
+      return new JavaNativeLibraryInfo(
+          NestedSetBuilder.<LibraryToLink>stableOrder()
+              .addTransitive(
+                  Depset.cast(transitiveLibraries, LibraryToLink.class, "transitive_libraries"))
+              .build());
+    }
+  }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaNativeLibraryProvider.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaNativeLibraryProvider.java
deleted file mode 100644
index c22b68e..0000000
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaNativeLibraryProvider.java
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2014 The Bazel Authors. All rights reserved.
-//
-// 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 com.google.devtools.build.lib.rules.java;
-
-import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
-import com.google.devtools.build.lib.collect.nestedset.NestedSet;
-import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-import com.google.devtools.build.lib.rules.cpp.LibraryToLink;
-import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
-
-/**
- * A target that provides native libraries in the transitive closure of its deps that are needed for
- * executing Java code.
- */
-@Immutable
-@AutoCodec
-public final class JavaNativeLibraryProvider implements TransitiveInfoProvider {
-
-  private final NestedSet<LibraryToLink> transitiveJavaNativeLibraries;
-
-  public JavaNativeLibraryProvider(NestedSet<LibraryToLink> transitiveJavaNativeLibraries) {
-    this.transitiveJavaNativeLibraries = transitiveJavaNativeLibraries;
-  }
-
-  /**
-   * Collects native libraries in the transitive closure of its deps that are needed for executing
-   * Java code.
-   */
-  public NestedSet<LibraryToLink> getTransitiveJavaNativeLibraries() {
-    return transitiveJavaNativeLibraries;
-  }
-
-  public static JavaNativeLibraryProvider merge(Iterable<JavaNativeLibraryProvider> deps) {
-    NestedSetBuilder<LibraryToLink> transitiveSourceJars = NestedSetBuilder.stableOrder();
-
-    for (JavaNativeLibraryProvider wrapper : deps) {
-      transitiveSourceJars.addTransitive(wrapper.getTransitiveJavaNativeLibraries());
-    }
-    return new JavaNativeLibraryProvider(transitiveSourceJars.build());
-  }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/NativeLibraryNestedSetBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/java/NativeLibraryNestedSetBuilder.java
index 2ee5cd8..f994e13 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/NativeLibraryNestedSetBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/NativeLibraryNestedSetBuilder.java
@@ -52,7 +52,7 @@
 
   /** Include native Java libraries of a specified target into the nested set. */
   public NativeLibraryNestedSetBuilder addJavaTarget(TransitiveInfoCollection dep) {
-    JavaNativeLibraryProvider javaProvider = dep.getProvider(JavaNativeLibraryProvider.class);
+    JavaNativeLibraryInfo javaProvider = dep.get(JavaNativeLibraryInfo.PROVIDER);
     if (javaProvider != null) {
       builder.addTransitive(javaProvider.getTransitiveJavaNativeLibraries());
       return this;
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaNativeLibraryInfoApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaNativeLibraryInfoApi.java
new file mode 100644
index 0000000..0d919ed
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaNativeLibraryInfoApi.java
@@ -0,0 +1,83 @@
+// Copyright 2020 The Bazel Authors. All rights reserved.
+//
+// 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 com.google.devtools.build.lib.skylarkbuildapi.java;
+
+import com.google.devtools.build.lib.collect.nestedset.Depset;
+import com.google.devtools.build.lib.skylarkbuildapi.FileApi;
+import com.google.devtools.build.lib.skylarkbuildapi.core.ProviderApi;
+import com.google.devtools.build.lib.skylarkbuildapi.core.StructApi;
+import com.google.devtools.build.lib.skylarkbuildapi.cpp.LibraryToLinkApi;
+import com.google.devtools.build.lib.syntax.EvalException;
+import com.google.devtools.build.lib.syntax.StarlarkSemantics.FlagIdentifier;
+import net.starlark.java.annot.Param;
+import net.starlark.java.annot.StarlarkBuiltin;
+import net.starlark.java.annot.StarlarkConstructor;
+import net.starlark.java.annot.StarlarkDocumentationCategory;
+import net.starlark.java.annot.StarlarkMethod;
+
+/** A target that provides C++ {@link LibraryToLinkApi}s to be linked into Java targets. */
+@StarlarkBuiltin(
+    name = "JavaNativeLibraryInfo",
+    doc =
+        "Do not use this module. It is intended for migration purposes only. If you depend on it, "
+            + "you will be broken when it is removed."
+            + "Information about the C++ libraries to be linked into Java targets.",
+    documented = true,
+    category = StarlarkDocumentationCategory.PROVIDER)
+public interface JavaNativeLibraryInfoApi<
+        FileT extends FileApi, LibraryToLinkT extends LibraryToLinkApi<FileT>>
+    extends StructApi {
+  /** Name of this info object. */
+  String NAME = "JavaNativeLibraryInfo";
+
+  /** Returns the cc linking info */
+  @StarlarkMethod(
+      name = "transitive_libraries",
+      structField = true,
+      doc = "Returns the set of transitive LibraryToLink objects.",
+      documented = true,
+      enableOnlyWithFlag = FlagIdentifier.EXPERIMENTAL_ENABLE_ANDROID_MIGRATION_APIS)
+  Depset /*<LibraryToLinkT>*/ getTransitiveJavaNativeLibrariesForStarlark();
+
+  /** The provider implementing this can construct the JavaNativeLibraryInfo provider. */
+  @StarlarkBuiltin(
+      name = "Provider",
+      doc =
+          "Do not use this module. It is intended for migration purposes only. If you depend on "
+              + "it, you will be broken when it is removed.",
+      documented = false)
+  interface Provider<FileT extends FileApi, LibraryToLinkT extends LibraryToLinkApi<FileT>>
+      extends ProviderApi {
+
+    @StarlarkMethod(
+        name = NAME,
+        doc = "The <code>JavaNativeLibraryInfo</code> constructor.",
+        documented = true,
+        enableOnlyWithFlag = FlagIdentifier.EXPERIMENTAL_ENABLE_ANDROID_MIGRATION_APIS,
+        parameters = {
+          @Param(
+              name = "transitive_libraries",
+              doc = "The transitive set of LibraryToLink providers.",
+              positional = true,
+              named = false,
+              type = Depset.class,
+              generic1 = LibraryToLinkApi.class),
+        },
+        selfCall = true)
+    @StarlarkConstructor(objectType = JavaNativeLibraryInfoApi.class, receiverNameForDoc = NAME)
+    JavaNativeLibraryInfoApi<FileT, LibraryToLinkT> create(Depset transitiveLibraries)
+        throws EvalException;
+  }
+}