diff options
author | cparsons <cparsons@google.com> | 2018-05-07 07:26:25 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-05-07 07:28:20 -0700 |
commit | b0b2d2a3a09d6696e893b213c47aab8eebbb5823 (patch) | |
tree | afd956ebe8f1ad84e665505f25da792ad42cd1cf | |
parent | 94967f2def3496ceeb430d2e4930d6fee295eb18 (diff) |
Start migration of java build API classes to skylarkbuildapi
RELNOTES: None.
PiperOrigin-RevId: 195659799
4 files changed, 134 insertions, 51 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD index 1d51484c00..1b3142eff9 100644 --- a/src/main/java/com/google/devtools/build/lib/BUILD +++ b/src/main/java/com/google/devtools/build/lib/BUILD @@ -57,6 +57,7 @@ filegroup( "//src/main/java/com/google/devtools/build/lib/skyframe/packages:srcs", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:srcs", "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi:srcs", + "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java:srcs", "//src/main/java/com/google/devtools/build/lib/skylarkdebug/proto:srcs", "//src/main/java/com/google/devtools/build/lib/skylarkinterface/processor:srcs", "//src/main/java/com/google/devtools/build/lib/ssd:srcs", @@ -918,6 +919,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/rules/cpp", "//src/main/java/com/google/devtools/build/lib/shell", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", + "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java", "//src/main/java/com/google/devtools/build/lib/vfs", "//src/main/java/com/google/devtools/common/options", "//src/main/protobuf:extra_actions_base_java_proto", @@ -1010,6 +1012,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/rules/cpp", "//src/main/java/com/google/devtools/build/lib/shell", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", + "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java", "//src/main/java/com/google/devtools/build/lib/vfs", "//src/main/java/com/google/devtools/common/options", "//src/main/protobuf:extra_actions_base_java_proto", diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaGenJarsProvider.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaGenJarsProvider.java index b009257108..d58281c5d5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaGenJarsProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaGenJarsProvider.java @@ -20,20 +20,14 @@ 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.JavaAnnotationProcessingApi; import javax.annotation.Nullable; /** The collection of gen jars from the transitive closure. */ @Immutable -@SkylarkModule( - name = "java_annotation_processing", - category = SkylarkModuleCategory.NONE, - doc = "Information about jars that are a result of annotation processing for a Java rule." -) @AutoCodec -public final class JavaGenJarsProvider implements TransitiveInfoProvider { +public final class JavaGenJarsProvider + implements TransitiveInfoProvider, JavaAnnotationProcessingApi<Artifact> { private final boolean usesAnnotationProcessing; @Nullable @@ -64,74 +58,39 @@ public final class JavaGenJarsProvider implements TransitiveInfoProvider { this.transitiveGenSourceJars = transitiveGenSourceJars; } - @SkylarkCallable( - name = "enabled", - structField = true, - doc = "Returns true if the Java rule uses annotation processing." - ) + @Override public boolean usesAnnotationProcessing() { return usesAnnotationProcessing; } - @SkylarkCallable( - name = "class_jar", - structField = true, - allowReturnNones = true, - doc = "Returns a jar File that is a result of annotation processing for this rule." - ) + @Override @Nullable public Artifact getGenClassJar() { return genClassJar; } - @SkylarkCallable( - name = "source_jar", - structField = true, - allowReturnNones = true, - doc = "Returns a source archive resulting from annotation processing of this rule." - ) + @Override @Nullable public Artifact getGenSourceJar() { return genSourceJar; } - @SkylarkCallable( - name = "transitive_class_jars", - structField = true, - doc = - "Returns a transitive set of class file jars resulting from annotation " - + "processing of this rule and its dependencies." - ) + @Override public NestedSet<Artifact> getTransitiveGenClassJars() { return transitiveGenClassJars; } - @SkylarkCallable( - name = "transitive_source_jars", - structField = true, - doc = - "Returns a transitive set of source archives resulting from annotation processing " - + "of this rule and its dependencies." - ) + @Override public NestedSet<Artifact> getTransitiveGenSourceJars() { return transitiveGenSourceJars; } - @SkylarkCallable( - name = "processor_classpath", - structField = true, - doc = "Returns a classpath of annotation processors applied to this rule." - ) + @Override public NestedSet<Artifact> getProcessorClasspath() { return processorClasspath; } - @SkylarkCallable( - name = "processor_classnames", - structField = true, - doc = - "Returns class names of annotation processors applied to this rule." - ) + @Override public ImmutableList<String> getProcessorClassNames() { return processorClassNames; } 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 new file mode 100644 index 0000000000..5eb5bad004 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/BUILD @@ -0,0 +1,28 @@ +# Description: +# This package contains interfaces representing the skylark "build API" +# (but not the implementation of that API). Ultimately, this package +# may be broken out of the Bazel package hierarchy to be standalone. +# Thus, this package should not depend on Bazel-specific packages (only +# those which contain pure-Skylark concepts, such as the interpreter or +# annotation interfaces). + +package(default_visibility = ["//src/main/java/com/google/devtools/build/lib:__pkg__"]) + +licenses(["notice"]) # Apache 2.0 + +filegroup( + name = "srcs", + srcs = glob(["**"]), +) + +java_library( + name = "java", + srcs = glob(["*.java"]), + deps = [ + "//src/main/java/com/google/devtools/build/lib:skylarkinterface", + "//src/main/java/com/google/devtools/build/lib/collect/nestedset", + "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi", + "//third_party:guava", + "//third_party:jsr305", + ], +) diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaAnnotationProcessingApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaAnnotationProcessingApi.java new file mode 100644 index 0000000000..f4a0ca7080 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaAnnotationProcessingApi.java @@ -0,0 +1,93 @@ +// 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; +import javax.annotation.Nullable; + +/** + * Interface for an info object containing information about jars that are a result of + * annotation processing for a Java rule. + */ +@SkylarkModule( + name = "java_annotation_processing", + category = SkylarkModuleCategory.NONE, + doc = "Information about jars that are a result of annotation processing for a Java rule." +) +public interface JavaAnnotationProcessingApi<FileTypeT extends FileApi> { + + @SkylarkCallable( + name = "enabled", + structField = true, + doc = "Returns true if the Java rule uses annotation processing." + ) + public boolean usesAnnotationProcessing(); + + @SkylarkCallable( + name = "class_jar", + structField = true, + allowReturnNones = true, + doc = "Returns a jar File that is a result of annotation processing for this rule." + ) + @Nullable + public FileTypeT getGenClassJar(); + + @SkylarkCallable( + name = "source_jar", + structField = true, + allowReturnNones = true, + doc = "Returns a source archive resulting from annotation processing of this rule." + ) + @Nullable + public FileTypeT getGenSourceJar(); + + @SkylarkCallable( + name = "transitive_class_jars", + structField = true, + doc = + "Returns a transitive set of class file jars resulting from annotation " + + "processing of this rule and its dependencies." + ) + public NestedSet<FileTypeT> getTransitiveGenClassJars(); + + @SkylarkCallable( + name = "transitive_source_jars", + structField = true, + doc = + "Returns a transitive set of source archives resulting from annotation processing " + + "of this rule and its dependencies." + ) + public NestedSet<FileTypeT> getTransitiveGenSourceJars(); + + @SkylarkCallable( + name = "processor_classpath", + structField = true, + doc = "Returns a classpath of annotation processors applied to this rule." + ) + public NestedSet<FileTypeT> getProcessorClasspath(); + + @SkylarkCallable( + name = "processor_classnames", + structField = true, + doc = + "Returns class names of annotation processors applied to this rule." + ) + public ImmutableList<String> getProcessorClassNames(); +} |