Skip to content

Commit

Permalink
Prepare tests for flipping --incompatible_disallow_legacy_java_provider.
Browse files Browse the repository at this point in the history
Progress on #7598.

RELNOTES: None.
PiperOrigin-RevId: 265874920
  • Loading branch information
iirina authored and copybara-github committed Aug 28, 2019
1 parent 50951dd commit b774f65
Showing 1 changed file with 0 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -994,60 +994,6 @@ public void testJavaCommonCompileAdditionalInputsAndOutputs() throws Exception {
assertThat(artifactFilesNames(javaAction.getOutputs())).contains("custom_additional_output");
}

@Test
public void testExposesJavaSkylarkApiProvider() throws Exception {
scratch.file(
"java/test/BUILD",
"load(':extension.bzl', 'my_rule')",
"java_library(",
" name = 'dep',",
" srcs = [ 'Dep.java'],",
")",
"my_rule(",
" name = 'my',",
" dep = ':dep',",
")");
scratch.file(
"java/test/extension.bzl",
"result = provider()",
"def impl(ctx):",
" depj = ctx.attr.dep.java",
" return [result(",
" source_jars = depj.source_jars,",
" transitive_deps = depj.transitive_deps,",
" transitive_runtime_deps = depj.transitive_runtime_deps,",
" transitive_source_jars = depj.transitive_source_jars,",
" outputs = depj.outputs.jars,",
" )]",
"my_rule = rule(impl, attrs = { 'dep' : attr.label() })");

ConfiguredTarget configuredTarget = getConfiguredTarget("//java/test:my");
StructImpl info =
(StructImpl)
configuredTarget.get(
new SkylarkKey(
Label.parseAbsolute("//java/test:extension.bzl", ImmutableMap.of()), "result"));

SkylarkNestedSet sourceJars = ((SkylarkNestedSet) info.getValue("source_jars"));
SkylarkNestedSet transitiveDeps = ((SkylarkNestedSet) info.getValue("transitive_deps"));
SkylarkNestedSet transitiveRuntimeDeps =
((SkylarkNestedSet) info.getValue("transitive_runtime_deps"));
SkylarkNestedSet transitiveSourceJars =
((SkylarkNestedSet) info.getValue("transitive_source_jars"));
SkylarkList<OutputJar> outputJars = ((SkylarkList<OutputJar>) info.getValue("outputs"));

assertThat(artifactFilesNames(sourceJars.toCollection(Artifact.class)))
.containsExactly("libdep-src.jar");
assertThat(artifactFilesNames(transitiveDeps.toCollection(Artifact.class)))
.containsExactly("libdep-hjar.jar");
assertThat(artifactFilesNames(transitiveRuntimeDeps.toCollection(Artifact.class)))
.containsExactly("libdep.jar");
assertThat(artifactFilesNames(transitiveSourceJars.toCollection(Artifact.class)))
.containsExactly("libdep-src.jar");
assertThat(outputJars).hasSize(1);
assertThat(outputJars.get(0).getClassJar().getFilename()).isEqualTo("libdep.jar");
}

private static Collection<String> artifactFilesNames(Iterable<Artifact> artifacts) {
List<String> result = new ArrayList<>();
for (Artifact artifact : artifacts) {
Expand Down

0 comments on commit b774f65

Please sign in to comment.