Using JavaProvider.getProvidersFromListOfTargets in JavaCommon
.collectCompileTimeDependencyArtifacts instead of retrieving the JavaCompilationArgsProviders twice and checking for duplicates.
@@ -29,7 +29,6 @@ import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.Runfiles;
import com.google.devtools.build.lib.analysis.RunfilesProvider;
-import com.google.devtools.build.lib.analysis.SkylarkProviders;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.analysis.Util;
@@ -291,31 +290,13 @@ public class JavaCommon {
*/
public NestedSet<Artifact> collectCompileTimeDependencyArtifacts(@Nullable Artifact outDeps) {
NestedSetBuilder<Artifact> builder = NestedSetBuilder.stableOrder();
- Set<JavaCompilationArgsProvider> addedProviders = new LinkedHashSet<>();
if (outDeps != null) {
builder.add(outDeps);
}
- for (JavaCompilationArgsProvider provider : AnalysisUtils.getProviders(
- getExports(ruleContext), JavaCompilationArgsProvider.class)) {
+ for (JavaCompilationArgsProvider provider : JavaProvider.getProvidersFromListOfTargets(
+ JavaCompilationArgsProvider.class, getExports(ruleContext))) {
builder.addTransitive(provider.getCompileTimeJavaDependencyArtifacts());
- addedProviders.add(provider);
- }
-
- // We also check for artifacts in the JavaProvider of the dependencies (might exist when
- // information is passed from a custom Skylark Java rule).
- for (SkylarkProviders skylarkProviders : AnalysisUtils.getProviders(
- getExports(ruleContext), SkylarkProviders.class)) {
- JavaProvider javaProvider =
- (JavaProvider) skylarkProviders.getDeclaredProvider(JavaProvider.JAVA_PROVIDER.getKey());
- if (javaProvider != null) {
- JavaCompilationArgsProvider compilationArgsProvider =
- javaProvider.getProvider(JavaCompilationArgsProvider.class);
- if (!addedProviders.contains(compilationArgsProvider)) {
- builder.addTransitive((javaProvider.getProvider(JavaCompilationArgsProvider.class))
- .getCompileTimeJavaDependencyArtifacts());
- }
- }
}
return builder.build();
