aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationInfoProvider.java32
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaInfo.java262
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaRuleOutputJarsProvider.java67
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/BUILD3
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaCompilationInfoProviderApi.java57
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaInfoApi.java317
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaRuleOutputJarsProviderApi.java51
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/OutputJarApi.java66
8 files changed, 532 insertions, 323 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationInfoProvider.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationInfoProvider.java
index 12bbb8460b..6928ed7598 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationInfoProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationInfoProvider.java
@@ -20,21 +20,15 @@ import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+import com.google.devtools.build.lib.skylarkbuildapi.java.JavaCompilationInfoProviderApi;
/**
* A class that provides compilation information in Java rules, for perusal of aspects and tools.
*/
-@SkylarkModule(
- name = "java_compilation_info",
- category = SkylarkModuleCategory.NONE,
- doc = "Provides access to compilation information for Java rules."
-)
@Immutable
@AutoCodec
-public class JavaCompilationInfoProvider implements TransitiveInfoProvider {
+public class JavaCompilationInfoProvider
+ implements TransitiveInfoProvider, JavaCompilationInfoProviderApi<Artifact> {
private final ImmutableList<String> javacOpts;
private final NestedSet<Artifact> runtimeClasspath;
private final NestedSet<Artifact> compilationClasspath;
@@ -75,34 +69,22 @@ public class JavaCompilationInfoProvider implements TransitiveInfoProvider {
}
}
- @SkylarkCallable(name = "javac_options", structField = true, doc = "Options to java compiler.")
+ @Override
public ImmutableList<String> getJavacOpts() {
return javacOpts;
}
- @SkylarkCallable(
- name = "runtime_classpath",
- structField = true,
- doc = "Run-time classpath for this Java target."
- )
+ @Override
public NestedSet<Artifact> getRuntimeClasspath() {
return runtimeClasspath;
}
- @SkylarkCallable(
- name = "compilation_classpath",
- structField = true,
- doc = "Compilation classpath for this Java target."
- )
+ @Override
public NestedSet<Artifact> getCompilationClasspath() {
return compilationClasspath;
}
- @SkylarkCallable(
- name = "boot_classpath",
- structField = true,
- doc = "Boot classpath for this Java target."
- )
+ @Override
public ImmutableList<Artifact> getBootClasspath() {
return bootClasspath;
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfo.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfo.java
index 04ad9d27c7..9c60a78023 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfo.java
@@ -18,7 +18,6 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.Runfiles;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
@@ -34,13 +33,8 @@ import com.google.devtools.build.lib.packages.NativeInfo;
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.FileApi;
-import com.google.devtools.build.lib.skylarkbuildapi.ProviderApi;
-import com.google.devtools.build.lib.skylarkbuildapi.SkylarkActionFactoryApi;
-import com.google.devtools.build.lib.skylarkinterface.Param;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkConstructor;
+import com.google.devtools.build.lib.skylarkbuildapi.java.JavaInfoApi;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.syntax.EvalException;
@@ -54,13 +48,9 @@ import java.util.function.Function;
import javax.annotation.Nullable;
/** A Skylark declared provider that encapsulates all providers that are needed by Java rules. */
-@SkylarkModule(
- name = "JavaInfo",
- doc = "Encapsulates all information provided by Java rules.",
- category = SkylarkModuleCategory.PROVIDER)
@Immutable
@AutoCodec
-public final class JavaInfo extends NativeInfo {
+public final class JavaInfo extends NativeInfo implements JavaInfoApi<Artifact> {
public static final String SKYLARK_NAME = "JavaInfo";
@@ -269,36 +259,17 @@ public final class JavaInfo extends NativeInfo {
return neverlink;
}
- @SkylarkCallable(
- name = "transitive_runtime_jars",
- doc = "Depset of runtime jars required by this target",
- structField = true
- )
+ @Override
public SkylarkNestedSet getTransitiveRuntimeJars() {
return SkylarkNestedSet.of(Artifact.class, getTransitiveRuntimeDeps());
}
- @SkylarkCallable(
- name = "transitive_compile_time_jars",
- doc = "Depset of compile time jars recusrively required by this target. See `compile_jars` "
- + "for more details.",
- structField = true
- )
+ @Override
public SkylarkNestedSet getTransitiveCompileTimeJars() {
return SkylarkNestedSet.of(Artifact.class, getTransitiveDeps());
}
- @SkylarkCallable(
- name = "compile_jars",
- doc = "Returns the compile time jars required by this target directly. They can be: <ul>"
- + "<li> interface jars (ijars), if an ijar tool was used, either by calling "
- + "java_common.create_provider(use_ijar=True, ...) or by passing --use_ijars on the "
- + "command line for native Java rules and `java_common.compile`</li>"
- + "<li> normal full jars, if no ijar action was requested</li>"
- + "<li> both ijars and normal full jars, if this provider was created by merging two or "
- + "more providers created with different ijar requests </li> </ul>",
- structField = true
- )
+ @Override
public SkylarkNestedSet getCompileTimeJars() {
NestedSet<Artifact> compileTimeJars =
getProviderAsNestedSet(
@@ -307,16 +278,7 @@ public final class JavaInfo extends NativeInfo {
return SkylarkNestedSet.of(Artifact.class, compileTimeJars);
}
- @SkylarkCallable(
- name = "full_compile_jars",
- doc = "Returns the full compile time jars required by this target directly. They can be <ul>"
- + "<li> the corresponding normal full jars of the ijars returned by `compile_jars`</li>"
- + "<li> the normal full jars returned by `compile_jars`</li></ul>"
- + "Note: `compile_jars` can return a mix of ijars and normal full jars. In that case, "
- + "`full_compile_jars` returns the corresponding full jars of the ijars and the remaining"
- + "normal full jars in `compile_jars`.",
- structField = true
- )
+ @Override
public SkylarkNestedSet getFullCompileTimeJars() {
NestedSet<Artifact> fullCompileTimeJars =
getProviderAsNestedSet(
@@ -324,13 +286,7 @@ public final class JavaInfo extends NativeInfo {
return SkylarkNestedSet.of(Artifact.class, fullCompileTimeJars);
}
- @SkylarkCallable(
- name = "source_jars",
- doc = "Returns a list of jar files containing all the uncompiled source files (including "
- + "those generated by annotations) from the target itself, i.e. NOT including the sources of "
- + "the transitive dependencies",
- structField = true
- )
+ @Override
public SkylarkList<Artifact> getSourceJars() {
//TODO(#4221) change return type to NestedSet<Artifact>
JavaSourceJarsProvider provider = providers.getProvider(JavaSourceJarsProvider.class);
@@ -339,41 +295,23 @@ public final class JavaInfo extends NativeInfo {
return SkylarkList.createImmutable(sourceJars);
}
- @SkylarkCallable(
- name = "outputs",
- doc = "Returns information about outputs of this Java target.",
- structField = true,
- allowReturnNones = true
- )
+ @Override
public JavaRuleOutputJarsProvider getOutputJars() {
return getProvider(JavaRuleOutputJarsProvider.class);
}
- @SkylarkCallable(
- name = "annotation_processing",
- structField = true,
- allowReturnNones = true,
- doc = "Returns information about annotation processing for this Java target."
- )
+ @Override
public JavaGenJarsProvider getGenJarsProvider() {
return getProvider(JavaGenJarsProvider.class);
}
- @SkylarkCallable(
- name = "compilation_info",
- structField = true,
- allowReturnNones = true,
- doc = "Returns compilation information for this Java target."
- )
+ @Override
public JavaCompilationInfoProvider getCompilationInfoProvider() {
return getProvider(JavaCompilationInfoProvider.class);
}
- @SkylarkCallable(
- name = "runtime_output_jars",
- doc = "Returns the runtime output jars provided by this Java target.",
- structField = true)
+ @Override
public SkylarkList<Artifact> getRuntimeOutputJars() {
return SkylarkList.createImmutable(getDirectRuntimeJars());
}
@@ -382,44 +320,27 @@ public final class JavaInfo extends NativeInfo {
return directRuntimeJars;
}
- @SkylarkCallable(
- name = "transitive_deps",
- doc = "Returns the transitive set of Jars required to build the target.",
- structField = true
- )
+ @Override
public NestedSet<Artifact> getTransitiveDeps() {
return getProviderAsNestedSet(
JavaCompilationArgsProvider.class,
JavaCompilationArgsProvider::getTransitiveCompileTimeJars);
}
- @SkylarkCallable(
- name = "transitive_runtime_deps",
- doc = "Returns the transitive set of Jars required on the target's runtime classpath.",
- structField = true
- )
+ @Override
public NestedSet<Artifact> getTransitiveRuntimeDeps() {
return getProviderAsNestedSet(
JavaCompilationArgsProvider.class, JavaCompilationArgsProvider::getRuntimeJars);
}
- @SkylarkCallable(
- name = "transitive_source_jars",
- doc = "Returns the Jars containing Java source files for the target "
- + "and all of its transitive dependencies.",
- structField = true
- )
+ @Override
public NestedSet<Artifact> getTransitiveSourceJars() {
return getProviderAsNestedSet(
JavaSourceJarsProvider.class,
JavaSourceJarsProvider::getTransitiveSourceJars);
}
- @SkylarkCallable(
- name = "transitive_exports",
- structField = true,
- doc = "Returns transitive set of labels that are being exported from this rule."
- )
+ @Override
public NestedSet<Label> getTransitiveExports() {
return getProviderAsNestedSet(
JavaExportsProvider.class,
@@ -477,160 +398,13 @@ public final class JavaInfo extends NativeInfo {
/** Provider class for {@link JavaInfo} objects. */
@SkylarkModule(name = "Provider", documented = false, doc = "")
- public static class JavaInfoProvider extends BuiltinProvider<JavaInfo> implements ProviderApi {
+ public static class JavaInfoProvider extends BuiltinProvider<JavaInfo>
+ implements JavaInfoProviderApi {
private JavaInfoProvider() {
super(SKYLARK_NAME, JavaInfo.class);
}
- @SkylarkCallable(name = "JavaInfo",
- doc = "The <code>JavaInfo</code> constructor.",
- parameters = {
- @Param(
- name = "output_jar",
- type = FileApi.class,
- named = true,
- doc = "The jar that was created as a result of a compilation "
- + "(e.g. javac, scalac, etc)."
- ),
- @Param(
- name = "compile_jar",
- type = FileApi.class,
- named = true,
- noneable = true,
- defaultValue = "None",
- doc = "A jar that is added as the compile-time dependency in lieu of "
- + "<code>output_jar</code>. Typically this is the ijar produced by "
- + "<code><a class=\"anchor\" href=\"java_common.html#run_ijar\">"
- + "run_ijar</a></code>. "
- + "If you cannot use ijar, consider instead using the output of "
- + "<code><a class=\"anchor\" href=\"java_common.html#stamp_jar\">"
- + "stamp_ijar</a></code>. If you do not wish to use either, "
- + "you can simply pass <code>output_jar</code>."
- ),
- @Param(
- name = "source_jar",
- type = FileApi.class,
- named = true,
- noneable = true,
- defaultValue = "None",
- doc = "The source jar that was used to create the output jar. "
- + "Use <code><a class=\"anchor\" href=\"java_common.html#pack_sources\">"
- + "pack_sources</a></code> to produce this source jar."
- ),
- @Param(
- name = "neverlink",
- type = Boolean.class,
- named = true,
- defaultValue = "False",
- doc = "If true only use this library for compilation and not at runtime."
- ),
- @Param(
- name = "deps",
- type = SkylarkList.class,
- generic1 = JavaInfo.class,
- named = true,
- defaultValue = "[]",
- doc = "Compile time dependencies that were used to create the output jar."
- ),
- @Param(
- name = "runtime_deps",
- type = SkylarkList.class,
- generic1 = JavaInfo.class,
- named = true,
- defaultValue = "[]",
- doc = "Runtime dependencies that are needed for this library."
- ),
- @Param(
- name = "exports",
- type = SkylarkList.class,
- generic1 = JavaInfo.class,
- named = true,
- defaultValue = "[]",
- doc = "Libraries to make available for users of this library. See also "
- + "<a class=\"anchor\" href=\"https://docs.bazel.build/versions/"
- + "master/be/java.html#java_library.exports\">java_library.exports</a>."
- ),
- @Param(
- name = "actions",
- type = SkylarkActionFactoryApi.class,
- named = true,
- defaultValue = "None",
- noneable = true,
- doc = "Deprecated. No longer needed when <code>compile_jar</code> and/or "
- + "<code>source_jar</code> are used. "
- + "<p>Used to create the ijar and pack source files to jar actions.</p>"
- ),
- @Param(
- name = "sources",
- type = SkylarkList.class,
- generic1 = FileApi.class,
- named = true,
- defaultValue = "None",
- noneable = true,
- doc = "Deprecated. Use <code>source_jar</code> instead. "
- + "<p>The sources that were used to create the output jar.</p>"
- ),
- @Param(
- name = "source_jars",
- type = SkylarkList.class,
- generic1 = FileApi.class,
- named = true,
- defaultValue = "None",
- noneable = true,
- doc = "Deprecated. Use <code>source_jar</code> instead. "
- + "<p>The source jars that were used to create the output jar.</p>"
- ),
- @Param(
- name = "use_ijar",
- type = Boolean.class,
- named = true,
- defaultValue = "None",
- noneable = true,
- doc = "Deprecated. Use <code>compile_jar</code> instead. "
- + "<p>If an ijar of the output jar should be created and stored in the "
- + "provider. </p>"
- ),
- @Param(
- name = "java_toolchain",
- type = ConfiguredTarget.class,
- named = true,
- defaultValue = "None",
- noneable = true,
- doc = "Deprecated. No longer needed when <code>compile_jar</code> and/or "
- + "<code>source_jar</code> are used. "
- + "<p>The toolchain to be used for retrieving the ijar tool and packing source "
- + "files to Jar.</p>"
- ),
- @Param(
- name = "host_javabase",
- type = ConfiguredTarget.class,
- named = true,
- defaultValue = "None",
- noneable = true,
- doc = "Deprecated. No longer needed when <code>compile_jar</code> and/or "
- + "<code>source_jar</code> are used. "
- + "<p>The host_javabase to be used for packing source files to Jar.</p>"
- ),
- @Param(
- name = "jdeps",
- type = FileApi.class,
- named = true,
- defaultValue = "None",
- noneable = true,
- doc = "jdeps information for the rule output (if available). This should be a "
- + "binary proto encoded using the deps.proto protobuf included with Bazel. "
- + "If available this file is typically produced by a compiler. IDEs and other "
- + "tools can use this information for more efficient processing."
- ),
- },
- selfCall = true,
- useLocation = true,
- useEnvironment = true
- )
- @SkylarkConstructor(
- objectType = JavaInfo.class,
- receiverNameForDoc = "JavaInfo"
- )
+ @Override
@SuppressWarnings({"unchecked"})
public JavaInfo javaInfo(
FileApi outputJarApi,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuleOutputJarsProvider.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuleOutputJarsProvider.java
index 9f9fa089aa..5595651c83 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuleOutputJarsProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuleOutputJarsProvider.java
@@ -22,37 +22,28 @@ import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+import com.google.devtools.build.lib.skylarkbuildapi.java.JavaRuleOutputJarsProviderApi;
+import com.google.devtools.build.lib.skylarkbuildapi.java.OutputJarApi;
import com.google.devtools.build.lib.syntax.SkylarkList;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
/** Provides information about jar files produced by a Java rule. */
@Immutable
-@SkylarkModule(
- name = "java_output_jars",
- category = SkylarkModuleCategory.NONE,
- doc = "Information about outputs of a Java rule."
-)
@AutoCodec
-public final class JavaRuleOutputJarsProvider implements TransitiveInfoProvider {
+public final class JavaRuleOutputJarsProvider
+ implements TransitiveInfoProvider, JavaRuleOutputJarsProviderApi<OutputJar> {
public static final JavaRuleOutputJarsProvider EMPTY =
new JavaRuleOutputJarsProvider(
ImmutableList.<OutputJar>of(), /* jdeps= */ null, /* nativeHeaders= */ null);
/** A collection of artifacts associated with a jar output. */
- @SkylarkModule(
- name = "java_output",
- category = SkylarkModuleCategory.NONE,
- doc = "Java classes jar, together with their associated source and interface archives."
- )
@Immutable
@AutoCodec
- public static class OutputJar {
+ public static class OutputJar implements OutputJarApi<Artifact> {
@Nullable private final Artifact classJar;
@Nullable private final Artifact iJar;
@Nullable private final ImmutableList<Artifact> srcJars;
@@ -67,47 +58,25 @@ public final class JavaRuleOutputJarsProvider implements TransitiveInfoProvider
}
@Nullable
- @SkylarkCallable(
- name = "class_jar",
- doc = "A classes jar file.",
- allowReturnNones = true,
- structField = true
- )
+ @Override
public Artifact getClassJar() {
return classJar;
}
@Nullable
- @SkylarkCallable(
- name = "ijar",
- doc = "A interface jar file.",
- allowReturnNones = true,
- structField = true
- )
+ @Override
public Artifact getIJar() {
return iJar;
}
@Nullable
- @SkylarkCallable(
- name = "source_jar",
- doc = "A sources archive file. Deprecated. Kept for migration reasons. "
- + "Please use source_jars instead.",
- allowReturnNones = true,
- structField = true
- )
- @Deprecated
+ @Override
public Artifact getSrcJar() {
return Iterables.getOnlyElement(srcJars, null);
}
@Nullable
- @SkylarkCallable(
- name = "source_jars",
- doc = "A list of sources archive files.",
- allowReturnNones = true,
- structField = true
- )
+ @Override
public SkylarkList<Artifact> getSrcJarsSkylark() {
return SkylarkList.createImmutable(srcJars);
}
@@ -143,7 +112,7 @@ public final class JavaRuleOutputJarsProvider implements TransitiveInfoProvider
return new JavaRuleOutputJarsProvider(outputJars, jdeps, nativeHeaders);
}
- @SkylarkCallable(name = "jars", doc = "A list of jars the rule outputs.", structField = true)
+ @Override
public ImmutableList<OutputJar> getOutputJars() {
return outputJars;
}
@@ -166,23 +135,13 @@ public final class JavaRuleOutputJarsProvider implements TransitiveInfoProvider
}
@Nullable
- @SkylarkCallable(
- name = "jdeps",
- doc = "The jdeps file for rule outputs.",
- structField = true,
- allowReturnNones = true
- )
+ @Override
public Artifact getJdeps() {
return jdeps;
}
@Nullable
- @SkylarkCallable(
- name = "native_headers",
- doc = "An archive of native header files.",
- structField = true,
- allowReturnNones = true
- )
+ @Override
public Artifact getNativeHeaders() {
return nativeHeaders;
}
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/BUILD b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/BUILD
index 5eb5bad004..7c5169569a 100644
--- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/BUILD
@@ -19,7 +19,10 @@ java_library(
name = "java",
srcs = glob(["*.java"]),
deps = [
+ "//src/main/java/com/google/devtools/build/lib:events",
"//src/main/java/com/google/devtools/build/lib:skylarkinterface",
+ "//src/main/java/com/google/devtools/build/lib:syntax",
+ "//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/com/google/devtools/build/lib/skylarkbuildapi",
"//third_party:guava",
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaCompilationInfoProviderApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaCompilationInfoProviderApi.java
new file mode 100644
index 0000000000..f0b296ec63
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaCompilationInfoProviderApi.java
@@ -0,0 +1,57 @@
+// Copyright 2018 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.common.collect.ImmutableList;
+import com.google.devtools.build.lib.collect.nestedset.NestedSet;
+import com.google.devtools.build.lib.skylarkbuildapi.FileApi;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+
+/**
+ * Info object for compilation information for java rules.
+ */
+@SkylarkModule(
+ name = "java_compilation_info",
+ category = SkylarkModuleCategory.NONE,
+ doc = "Provides access to compilation information for Java rules."
+)
+public interface JavaCompilationInfoProviderApi<FileT extends FileApi> {
+
+ @SkylarkCallable(name = "javac_options", structField = true, doc = "Options to java compiler.")
+ public ImmutableList<String> getJavacOpts();
+
+ @SkylarkCallable(
+ name = "runtime_classpath",
+ structField = true,
+ doc = "Run-time classpath for this Java target."
+ )
+ public NestedSet<FileT> getRuntimeClasspath();
+
+ @SkylarkCallable(
+ name = "compilation_classpath",
+ structField = true,
+ doc = "Compilation classpath for this Java target."
+ )
+ public NestedSet<FileT> getCompilationClasspath();
+
+ @SkylarkCallable(
+ name = "boot_classpath",
+ structField = true,
+ doc = "Boot classpath for this Java target."
+ )
+ public ImmutableList<FileT> getBootClasspath();
+}
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaInfoApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaInfoApi.java
new file mode 100644
index 0000000000..5b5ccc489c
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaInfoApi.java
@@ -0,0 +1,317 @@
+// Copyright 2018 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.cmdline.Label;
+import com.google.devtools.build.lib.collect.nestedset.NestedSet;
+import com.google.devtools.build.lib.events.Location;
+import com.google.devtools.build.lib.skylarkbuildapi.FileApi;
+import com.google.devtools.build.lib.skylarkbuildapi.ProviderApi;
+import com.google.devtools.build.lib.skylarkbuildapi.SkylarkActionFactoryApi;
+import com.google.devtools.build.lib.skylarkbuildapi.StructApi;
+import com.google.devtools.build.lib.skylarkinterface.Param;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkConstructor;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+import com.google.devtools.build.lib.syntax.Environment;
+import com.google.devtools.build.lib.syntax.EvalException;
+import com.google.devtools.build.lib.syntax.SkylarkList;
+import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
+
+/**
+ * Info object encapsulating all information by java rules.
+ */
+@SkylarkModule(
+ name = "JavaInfo",
+ doc = "Encapsulates all information provided by Java rules.",
+ category = SkylarkModuleCategory.PROVIDER)
+public interface JavaInfoApi <FileT extends FileApi> extends StructApi {
+
+ @SkylarkCallable(
+ name = "transitive_runtime_jars",
+ doc = "Depset of runtime jars required by this target",
+ structField = true
+ )
+ public SkylarkNestedSet getTransitiveRuntimeJars();
+
+ @SkylarkCallable(
+ name = "transitive_compile_time_jars",
+ doc = "Depset of compile time jars recusrively required by this target. See `compile_jars` "
+ + "for more details.",
+ structField = true
+ )
+ public SkylarkNestedSet getTransitiveCompileTimeJars();
+
+ @SkylarkCallable(
+ name = "compile_jars",
+ doc = "Returns the compile time jars required by this target directly. They can be: <ul>"
+ + "<li> interface jars (ijars), if an ijar tool was used, either by calling "
+ + "java_common.create_provider(use_ijar=True, ...) or by passing --use_ijars on the "
+ + "command line for native Java rules and `java_common.compile`</li>"
+ + "<li> normal full jars, if no ijar action was requested</li>"
+ + "<li> both ijars and normal full jars, if this provider was created by merging two or "
+ + "more providers created with different ijar requests </li> </ul>",
+ structField = true
+ )
+ public SkylarkNestedSet getCompileTimeJars();
+
+ @SkylarkCallable(
+ name = "full_compile_jars",
+ doc = "Returns the full compile time jars required by this target directly. They can be <ul>"
+ + "<li> the corresponding normal full jars of the ijars returned by `compile_jars`</li>"
+ + "<li> the normal full jars returned by `compile_jars`</li></ul>"
+ + "Note: `compile_jars` can return a mix of ijars and normal full jars. In that case, "
+ + "`full_compile_jars` returns the corresponding full jars of the ijars and the remaining"
+ + "normal full jars in `compile_jars`.",
+ structField = true
+ )
+ public SkylarkNestedSet getFullCompileTimeJars();
+
+ @SkylarkCallable(
+ name = "source_jars",
+ doc = "Returns a list of jar files containing all the uncompiled source files (including "
+ + "those generated by annotations) from the target itself, i.e. NOT including the sources of "
+ + "the transitive dependencies",
+ structField = true
+ )
+ public SkylarkList<FileT> getSourceJars();
+
+ @SkylarkCallable(
+ name = "outputs",
+ doc = "Returns information about outputs of this Java target.",
+ structField = true,
+ allowReturnNones = true
+ )
+ public JavaRuleOutputJarsProviderApi<?> getOutputJars();
+
+ @SkylarkCallable(
+ name = "annotation_processing",
+ structField = true,
+ allowReturnNones = true,
+ doc = "Returns information about annotation processing for this Java target."
+ )
+ public JavaAnnotationProcessingApi<?> getGenJarsProvider();
+
+ @SkylarkCallable(
+ name = "compilation_info",
+ structField = true,
+ allowReturnNones = true,
+ doc = "Returns compilation information for this Java target."
+ )
+ public JavaCompilationInfoProviderApi<?> getCompilationInfoProvider();
+
+ @SkylarkCallable(
+ name = "runtime_output_jars",
+ doc = "Returns the runtime output jars provided by this Java target.",
+ structField = true)
+ public SkylarkList<FileT> getRuntimeOutputJars();
+
+ @SkylarkCallable(
+ name = "transitive_deps",
+ doc = "Returns the transitive set of Jars required to build the target.",
+ structField = true
+ )
+ public NestedSet<FileT> getTransitiveDeps();
+
+ @SkylarkCallable(
+ name = "transitive_runtime_deps",
+ doc = "Returns the transitive set of Jars required on the target's runtime classpath.",
+ structField = true
+ )
+ public NestedSet<FileT> getTransitiveRuntimeDeps();
+
+ @SkylarkCallable(
+ name = "transitive_source_jars",
+ doc = "Returns the Jars containing Java source files for the target "
+ + "and all of its transitive dependencies.",
+ structField = true
+ )
+ public NestedSet<FileT> getTransitiveSourceJars();
+
+ @SkylarkCallable(
+ name = "transitive_exports",
+ structField = true,
+ doc = "Returns transitive set of labels that are being exported from this rule."
+ )
+ public NestedSet<Label> getTransitiveExports();
+
+ /** Provider class for {@link JavaInfoApi} objects. */
+ @SkylarkModule(name = "Provider", documented = false, doc = "")
+ public interface JavaInfoProviderApi extends ProviderApi {
+
+ @SkylarkCallable(
+ name = "JavaInfo",
+ doc = "The <code>JavaInfo</code> constructor.",
+ parameters = {
+ @Param(
+ name = "output_jar",
+ type = FileApi.class,
+ named = true,
+ doc =
+ "The jar that was created as a result of a compilation "
+ + "(e.g. javac, scalac, etc)."),
+ @Param(
+ name = "compile_jar",
+ type = FileApi.class,
+ named = true,
+ noneable = true,
+ defaultValue = "None",
+ doc =
+ "A jar that is added as the compile-time dependency in lieu of "
+ + "<code>output_jar</code>. Typically this is the ijar produced by "
+ + "<code><a class=\"anchor\" href=\"java_common.html#run_ijar\">"
+ + "run_ijar</a></code>. "
+ + "If you cannot use ijar, consider instead using the output of "
+ + "<code><a class=\"anchor\" href=\"java_common.html#stamp_jar\">"
+ + "stamp_ijar</a></code>. If you do not wish to use either, "
+ + "you can simply pass <code>output_jar</code>."),
+ @Param(
+ name = "source_jar",
+ type = FileApi.class,
+ named = true,
+ noneable = true,
+ defaultValue = "None",
+ doc =
+ "The source jar that was used to create the output jar. "
+ + "Use <code><a class=\"anchor\" href=\"java_common.html#pack_sources\">"
+ + "pack_sources</a></code> to produce this source jar."),
+ @Param(
+ name = "neverlink",
+ type = Boolean.class,
+ named = true,
+ defaultValue = "False",
+ doc = "If true only use this library for compilation and not at runtime."),
+ @Param(
+ name = "deps",
+ type = SkylarkList.class,
+ generic1 = JavaInfoApi.class,
+ named = true,
+ defaultValue = "[]",
+ doc = "Compile time dependencies that were used to create the output jar."),
+ @Param(
+ name = "runtime_deps",
+ type = SkylarkList.class,
+ generic1 = JavaInfoApi.class,
+ named = true,
+ defaultValue = "[]",
+ doc = "Runtime dependencies that are needed for this library."),
+ @Param(
+ name = "exports",
+ type = SkylarkList.class,
+ generic1 = JavaInfoApi.class,
+ named = true,
+ defaultValue = "[]",
+ doc =
+ "Libraries to make available for users of this library. See also "
+ + "<a class=\"anchor\" href=\"https://docs.bazel.build/versions/"
+ + "master/be/java.html#java_library.exports\">java_library.exports</a>."),
+ @Param(
+ name = "actions",
+ type = SkylarkActionFactoryApi.class,
+ named = true,
+ defaultValue = "None",
+ noneable = true,
+ doc =
+ "Deprecated. No longer needed when <code>compile_jar</code> and/or "
+ + "<code>source_jar</code> are used. "
+ + "<p>Used to create the ijar and pack source files to jar actions.</p>"),
+ @Param(
+ name = "sources",
+ type = SkylarkList.class,
+ generic1 = FileApi.class,
+ named = true,
+ defaultValue = "None",
+ noneable = true,
+ doc =
+ "Deprecated. Use <code>source_jar</code> instead. "
+ + "<p>The sources that were used to create the output jar.</p>"),
+ @Param(
+ name = "source_jars",
+ type = SkylarkList.class,
+ generic1 = FileApi.class,
+ named = true,
+ defaultValue = "None",
+ noneable = true,
+ doc =
+ "Deprecated. Use <code>source_jar</code> instead. "
+ + "<p>The source jars that were used to create the output jar.</p>"),
+ @Param(
+ name = "use_ijar",
+ type = Boolean.class,
+ named = true,
+ defaultValue = "None",
+ noneable = true,
+ doc =
+ "Deprecated. Use <code>compile_jar</code> instead. "
+ + "<p>If an ijar of the output jar should be created and stored in the "
+ + "provider. </p>"),
+ @Param(
+ name = "java_toolchain",
+ type = Object.class,
+ named = true,
+ defaultValue = "None",
+ noneable = true,
+ doc =
+ "Deprecated. No longer needed when <code>compile_jar</code> and/or "
+ + "<code>source_jar</code> are used. "
+ + "<p>The toolchain to be used for retrieving the ijar tool and packing source "
+ + "files to Jar. This should be a Target.</p>"),
+ @Param(
+ name = "host_javabase",
+ type = Object.class,
+ named = true,
+ defaultValue = "None",
+ noneable = true,
+ doc =
+ "Deprecated. No longer needed when <code>compile_jar</code> and/or "
+ + "<code>source_jar</code> are used. "
+ + "<p>The host_javabase to be used for packing source files to Jar. "
+ + "This should be a Target.</p>"),
+ @Param(
+ name = "jdeps",
+ type = FileApi.class,
+ named = true,
+ defaultValue = "None",
+ noneable = true,
+ doc = "jdeps information for the rule output (if available). This should be a "
+ + "binary proto encoded using the deps.proto protobuf included with Bazel. "
+ + "If available this file is typically produced by a compiler. IDEs and other "
+ + "tools can use this information for more efficient processing."),
+ },
+ selfCall = true,
+ useLocation = true,
+ useEnvironment = true)
+ @SkylarkConstructor(objectType = JavaInfoApi.class, receiverNameForDoc = "JavaInfo")
+ public JavaInfoApi<?> javaInfo(
+ FileApi outputJarApi,
+ Object compileJarApi,
+ Object sourceJarApi,
+ Boolean neverlink,
+ SkylarkList<?> deps,
+ SkylarkList<?> runtimeDeps,
+ SkylarkList<?> exports,
+ Object actionsApi,
+ Object sourcesApi,
+ Object sourceJarsApi,
+ Object useIjarApi,
+ Object javaToolchainApi,
+ Object hostJavabaseApi,
+ Object jdepsApi,
+ Location loc,
+ Environment env)
+ throws EvalException;
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaRuleOutputJarsProviderApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaRuleOutputJarsProviderApi.java
new file mode 100644
index 0000000000..027bf55ab7
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaRuleOutputJarsProviderApi.java
@@ -0,0 +1,51 @@
+// Copyright 2018 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.common.collect.ImmutableList;
+import com.google.devtools.build.lib.skylarkbuildapi.FileApi;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+
+/**
+ * Info object about outputs of a Java rule.
+ */
+@SkylarkModule(
+ name = "java_output_jars",
+ category = SkylarkModuleCategory.NONE,
+ doc = "Information about outputs of a Java rule."
+)
+public interface JavaRuleOutputJarsProviderApi<OutputJarT extends OutputJarApi<?>> {
+
+ @SkylarkCallable(name = "jars", doc = "A list of jars the rule outputs.", structField = true)
+ public ImmutableList<OutputJarT> getOutputJars();
+
+ @SkylarkCallable(
+ name = "jdeps",
+ doc = "The jdeps file for rule outputs.",
+ structField = true,
+ allowReturnNones = true
+ )
+ public FileApi getJdeps();
+
+ @SkylarkCallable(
+ name = "native_headers",
+ doc = "An archive of native header files.",
+ structField = true,
+ allowReturnNones = true
+ )
+ public FileApi getNativeHeaders();
+}
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/OutputJarApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/OutputJarApi.java
new file mode 100644
index 0000000000..a31d2fdc70
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/OutputJarApi.java
@@ -0,0 +1,66 @@
+// Copyright 2018 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.skylarkbuildapi.FileApi;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+import com.google.devtools.build.lib.syntax.SkylarkList;
+
+/**
+ * A tuple of a java classes jar and its associated source and interface archives.
+ */
+@SkylarkModule(
+ name = "java_output",
+ category = SkylarkModuleCategory.NONE,
+ doc = "Java classes jar, together with their associated source and interface archives."
+)
+public interface OutputJarApi<FileT extends FileApi> {
+
+ @SkylarkCallable(
+ name = "class_jar",
+ doc = "A classes jar file.",
+ allowReturnNones = true,
+ structField = true
+ )
+ public FileT getClassJar();
+
+ @SkylarkCallable(
+ name = "ijar",
+ doc = "A interface jar file.",
+ allowReturnNones = true,
+ structField = true
+ )
+ public FileT getIJar();
+
+ @SkylarkCallable(
+ name = "source_jar",
+ doc = "A sources archive file. Deprecated. Kept for migration reasons. "
+ + "Please use source_jars instead.",
+ allowReturnNones = true,
+ structField = true
+ )
+ @Deprecated
+ public FileT getSrcJar();
+
+ @SkylarkCallable(
+ name = "source_jars",
+ doc = "A list of sources archive files.",
+ allowReturnNones = true,
+ structField = true
+ )
+ public SkylarkList<FileT> getSrcJarsSkylark();
+}