diff options
author | 2017-12-07 05:49:46 -0800 | |
---|---|---|
committer | 2017-12-07 05:51:48 -0800 | |
commit | 7c8cd9c402b3ca4f7b50074d249ef8e1dc52086a (patch) | |
tree | ca87a69553e56bf9dbb0843a6c6a15165b01fbce /src/test/java | |
parent | cbac328f40cbf42569d93cf0027405a590504281 (diff) |
Expose two methods from JavaSkylarkApiProvider in JavaInfo
JavaSkylarkApiProvider will be deprecated soon and replaced by JavaInfo.
Methods exposed:
getCompilationInfoProvider()
getTransitiveExports()
Changed signature of JavaCommon methods to accept JavaInfoBuilder.
RELNOTES:none
PiperOrigin-RevId: 178229835
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java | 60 |
1 files changed, 59 insertions, 1 deletions
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 4ec72daf94..dcfe291e1a 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 @@ -1058,6 +1058,37 @@ public class JavaSkylarkApiTest extends BuildViewTestCase { @Test + public void testJavaInfoGetTransitiveExports() throws Exception { + scratch.file( + "foo/extension.bzl", + "result = provider()", + "def _impl(ctx):", + " return [result(property = ctx.attr.dep[JavaInfo].transitive_exports)]", + "my_rule = rule(_impl, attrs = { 'dep' : attr.label() })"); + + scratch.file( + "foo/BUILD", + "load(':extension.bzl', 'my_rule')", + "java_library(name = 'my_java_lib_c', srcs = ['java/C.java'])", + "java_library(name = 'my_java_lib_b', srcs = ['java/B.java'])", + "java_library(name = 'my_java_lib_a', srcs = ['java/A.java'], ", + " deps = [':my_java_lib_b', ':my_java_lib_c'], ", + " exports = [':my_java_lib_b']) ", + "my_rule(name = 'my_skylark_rule', dep = ':my_java_lib_a')"); + assertNoEvents(); + ConfiguredTarget myRuleTarget = getConfiguredTarget("//foo:my_skylark_rule"); + Info info = myRuleTarget.get( + new SkylarkKey(Label.parseAbsolute("//foo:extension.bzl"), "result")); + + @SuppressWarnings("unchecked") SkylarkNestedSet exports = + (SkylarkNestedSet) (info.getValue("property")); + + assertThat(exports.getSet(Label.class)) + .containsExactly(Label.parseAbsolute("//foo:my_java_lib_b")); + } + + + @Test public void testJavaInfoGetGenJarsProvider() throws Exception { scratch.file( "foo/extension.bzl", @@ -1070,7 +1101,7 @@ public class JavaSkylarkApiTest extends BuildViewTestCase { "foo/BUILD", "load(':extension.bzl', 'my_rule')", "java_library(name = 'my_java_lib_a', srcs = ['java/A.java'], ", - "javacopts = ['-processor com.google.process.Processor'])", + " javacopts = ['-processor com.google.process.Processor'])", "my_rule(name = 'my_skylark_rule', dep = ':my_java_lib_a')"); assertNoEvents(); ConfiguredTarget myRuleTarget = getConfiguredTarget("//foo:my_skylark_rule"); @@ -1087,6 +1118,33 @@ public class JavaSkylarkApiTest extends BuildViewTestCase { @Test + public void javaInfoGetCompilationInfoProvider() throws Exception { + scratch.file( + "foo/extension.bzl", + "result = provider()", + "def _impl(ctx):", + " return [result(property = ctx.attr.dep[JavaInfo].compilation_info)]", + "my_rule = rule(_impl, attrs = { 'dep' : attr.label() })"); + + scratch.file( + "foo/BUILD", + "load(':extension.bzl', 'my_rule')", + "java_library(name = 'my_java_lib_a', srcs = ['java/A.java'])", + "my_rule(name = 'my_skylark_rule', dep = ':my_java_lib_a')"); + assertNoEvents(); + ConfiguredTarget myRuleTarget = getConfiguredTarget("//foo:my_skylark_rule"); + Info info = myRuleTarget.get( + new SkylarkKey(Label.parseAbsolute("//foo:extension.bzl"), "result")); + + JavaCompilationInfoProvider javaCompilationInfoProvider = + (JavaCompilationInfoProvider) info.getValue("property"); + + assertThat(prettyJarNames(javaCompilationInfoProvider.getRuntimeClasspath())) + .containsExactly("foo/libmy_java_lib_a.jar"); + } + + + @Test public void strictDepsEnabled() throws Exception { scratch.file( "foo/custom_library.bzl", |