Add JavaRuntimeInfo.files

to make the contents of the runtime (java_runtime.srcs) available to
starlark.

PiperOrigin-RevId: 232775594
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeInfo.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeInfo.java
index a2c8068..2ffbb29 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeInfo.java
@@ -34,6 +34,7 @@
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
 import com.google.devtools.build.lib.skylarkbuildapi.java.JavaRuntimeInfoApi;
+import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
 import com.google.devtools.build.lib.vfs.PathFragment;
 import javax.annotation.Nullable;
 
@@ -174,6 +175,11 @@
     return javaBinaryRunfilesPath;
   }
 
+  @Override
+  public SkylarkNestedSet skylarkJavaBaseInputs() {
+    return SkylarkNestedSet.of(Artifact.class, javaBaseInputs());
+  }
+
   // Not all of JavaRuntimeInfo is exposed to Skylark, which makes implementing deep equality
   // impossible: if Java-only parts are considered, the behavior is surprising in Skylark, if they
   // are not, the behavior is surprising in Java. Thus, object identity it is.
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaRuntimeInfoApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaRuntimeInfoApi.java
index e9aa1c6..c926833 100644
--- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaRuntimeInfoApi.java
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaRuntimeInfoApi.java
@@ -17,6 +17,7 @@
 import com.google.devtools.build.lib.skylarkbuildapi.platform.ToolchainInfoApi;
 import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
 import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
 /** Information about the Java runtime being used. */
@@ -26,16 +27,15 @@
   @SkylarkCallable(
       name = "java_home",
       doc = "Returns the execpath of the root of the Java installation.",
-      structField = true
-  )
-  public PathFragment javaHome();
+      structField = true)
+  PathFragment javaHome();
 
   /** The execpath of the Java binary. */
   @SkylarkCallable(
       name = "java_executable_exec_path",
       doc = "Returns the execpath of the Java executable.",
       structField = true)
-  public PathFragment javaBinaryExecPath();
+  PathFragment javaBinaryExecPath();
 
   /** The runfiles path of the JDK. */
   @SkylarkCallable(
@@ -46,7 +46,7 @@
               + "by Bazel. In particular, when one needs the JDK during an action, "
               + "java_home should be used instead.",
       structField = true)
-  public PathFragment javaHomeRunfilesPath();
+  PathFragment javaHomeRunfilesPath();
 
   /** The runfiles path of the Java binary. */
   @SkylarkCallable(
@@ -57,5 +57,12 @@
               + "by Bazel. In particular, when one needs to invoke the JVM during an action, "
               + "java_executable_exec_path should be used instead.",
       structField = true)
-  public PathFragment javaBinaryRunfilesPath();
+  PathFragment javaBinaryRunfilesPath();
+
+  /** The files in the Java runtime. */
+  @SkylarkCallable(
+      name = "files",
+      doc = "Returns the files in the Java runtime.",
+      structField = true)
+  SkylarkNestedSet skylarkJavaBaseInputs();
 }
diff --git a/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java b/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java
index 50c7c22..aaaf3ad 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java
@@ -2405,4 +2405,30 @@
 
     assertThat(toolchainResolutionEnabled()).isTrue();
   }
+
+  @Test
+  public void testJavaRuntimeProviderFiles() throws Exception {
+    scratch.file("a/a.txt", "hello");
+    scratch.file(
+        "a/BUILD",
+        "load(':rule.bzl', 'jrule')",
+        "java_runtime(name='jvm', srcs=['a.txt'], java_home='foo/bar')",
+        "java_runtime_alias(name='alias')",
+        "jrule(name='r')");
+
+    scratch.file(
+        "a/rule.bzl",
+        "def _impl(ctx):",
+        "  provider = ctx.attr._java_runtime[java_common.JavaRuntimeInfo]",
+        "  return struct(",
+        "    files = provider.files,",
+        "  )",
+        "jrule = rule(_impl, attrs = { '_java_runtime': attr.label(default=Label('//a:alias'))})");
+
+    useConfiguration("--javabase=//a:jvm");
+    ConfiguredTarget ct = getConfiguredTarget("//a:r");
+    @SuppressWarnings("unchecked")
+    SkylarkNestedSet files = (SkylarkNestedSet) ct.get("files");
+    assertThat(prettyArtifactNames(files.toCollection(Artifact.class))).containsExactly("a/a.txt");
+  }
 }