Skip to content

Commit

Permalink
Remove databinding classInfos and setterStores duplicates from provider
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsampathkumar-grabtaxi committed Feb 15, 2021
1 parent 506b1fd commit 09cb632
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
import net.starlark.java.eval.EvalException;
import net.starlark.java.eval.Sequence;

import java.util.Comparator;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
* A provider that exposes this enables <a
* href="https://developer.android.com/topic/libraries/data-binding/index.html">data binding</a>
Expand Down Expand Up @@ -53,8 +57,8 @@ public DataBindingV2Provider(
NestedSet<Artifact> transitiveBRFiles,
ImmutableList<LabelJavaPackagePair> labelAndJavaPackages,
NestedSet<LabelJavaPackagePair> transitiveLabelAndJavaPackages) {
this.classInfos = classInfos;
this.setterStores = setterStores;
this.classInfos = removeDuplicates(classInfos);
this.setterStores = removeDuplicates(setterStores);
this.transitiveBRFiles = transitiveBRFiles;
this.labelAndJavaPackages = labelAndJavaPackages;
this.transitiveLabelAndJavaPackages = transitiveLabelAndJavaPackages;
Expand Down Expand Up @@ -164,6 +168,17 @@ public static DataBindingV2Provider createProvider(
transitiveLabelAndJavaPackages.build());
}

/**
* Remove all duplicates from given artifact list. Needed until https://github.com/bazelbuild/bazel/issues/12780 is
* fixed
*/
private ImmutableList<Artifact> removeDuplicates(ImmutableList<Artifact> source) {
return source.stream()
.collect(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Artifact::getExecPath))))
.stream()
.collect(ImmutableList.toImmutableList());
}

/** The provider can construct the DataBindingV2Provider provider. */
public static class Provider extends BuiltinProvider<DataBindingV2Provider>
implements DataBindingV2ProviderApi.Provider<Artifact> {
Expand Down

0 comments on commit 09cb632

Please sign in to comment.