public void testJavaImport() throws Exception { scratch.file( "com/google/example/BUILD", "java_import(", " name = 'imp',", " jars = ['a.jar', 'b.jar'],", " srcjar = 'impsrc.jar',", ")", "java_library(", " name = 'lib',", " srcs = ['Lib.java'],", " deps = [':imp'],", ")"); Map<String, RuleIdeInfo> ruleIdeInfos = buildRuleIdeInfo("//com/google/example:lib"); final RuleIdeInfo libInfo = getRuleInfoAndVerifyLabel("//com/google/example:lib", ruleIdeInfos); RuleIdeInfo impInfo = getRuleInfoAndVerifyLabel("//com/google/example:imp", ruleIdeInfos); assertThat(impInfo.getKind()).isEqualTo(Kind.JAVA_IMPORT); assertThat(libInfo.getDependenciesList()).containsExactly("//com/google/example:imp"); JavaRuleIdeInfo javaRuleIdeInfo = impInfo.getJavaRuleIdeInfo(); assertThat(javaRuleIdeInfo).isNotNull(); assertThat(transform(javaRuleIdeInfo.getJarsList(), LIBRARY_ARTIFACT_TO_STRING)) .containsExactly( jarString("com/google/example", "a.jar", null, "impsrc.jar"), jarString("com/google/example", "b.jar", null, "impsrc.jar")) .inOrder(); assertThat(getIdeResolveFiles()) .containsExactly( "com/google/example/liblib.jar", "com/google/example/liblib-ijar.jar", "com/google/example/liblib-src.jar"); }
private static JavaRuleIdeInfo makeJavaRuleIdeInfo( ConfiguredTarget base, RuleContext ruleContext, JavaRuleOutputJarsProvider outputJarsProvider, NestedSetBuilder<Artifact> ideResolveArtifacts, @Nullable Artifact packageManifest) { JavaRuleIdeInfo.Builder builder = JavaRuleIdeInfo.newBuilder(); collectJarsFromOutputJarsProvider(builder, ideResolveArtifacts, outputJarsProvider); Artifact jdeps = outputJarsProvider.getJdeps(); if (jdeps != null) { builder.setJdeps(makeArtifactLocation(jdeps)); } JavaGenJarsProvider genJarsProvider = base.getProvider(JavaGenJarsProvider.class); if (genJarsProvider != null) { collectGenJars(builder, ideResolveArtifacts, genJarsProvider); } Collection<Artifact> sourceFiles = getSources(ruleContext); for (Artifact sourceFile : sourceFiles) { builder.addSources(makeArtifactLocation(sourceFile)); } if (packageManifest != null) { builder.setPackageManifest(makeArtifactLocation(packageManifest)); } return builder.build(); }