use of com.android.tools.idea.gradle.structure.model.PsDependency in project android by JetBrains.
the class DependencyNodes method addTransitive.
private static void addTransitive(@NotNull PsDependency dependency, @NotNull Multimap<PsDependency, PsDependency> allTransitive) {
if (allTransitive.containsKey(dependency)) {
return;
}
if (dependency instanceof PsLibraryAndroidDependency) {
PsLibraryAndroidDependency libraryDependency = (PsLibraryAndroidDependency) dependency;
ImmutableCollection<PsDependency> transitives = libraryDependency.getTransitiveDependencies();
allTransitive.putAll(dependency, transitives);
for (PsDependency transitive : transitives) {
addTransitive(transitive, allTransitive);
}
}
}
use of com.android.tools.idea.gradle.structure.model.PsDependency in project android by JetBrains.
the class ResolvedDependenciesTreeRootNode method createChildren.
@NotNull
private List<? extends AndroidArtifactNode> createChildren(@NotNull PsAndroidModule module, @NotNull Map<String, PsVariant> variantsByName) {
List<AndroidArtifactNode> childrenNodes = Lists.newArrayList();
// [Outer map] key: variant name, value: dependencies by artifact
// [Inner map] key: artifact name, value: dependencies
Map<String, Map<String, List<PsDependency>>> dependenciesByVariantAndArtifact = Maps.newHashMap();
module.forEachDependency(dependency -> {
if (!dependency.isDeclared()) {
return;
}
for (PsDependencyContainer container : dependency.getContainers()) {
Map<String, List<PsDependency>> dependenciesByArtifact = dependenciesByVariantAndArtifact.get(container.getVariant());
if (dependenciesByArtifact == null) {
dependenciesByArtifact = Maps.newHashMap();
dependenciesByVariantAndArtifact.put(container.getVariant(), dependenciesByArtifact);
}
List<PsDependency> artifactDependencies = dependenciesByArtifact.get(container.getArtifact());
if (artifactDependencies == null) {
artifactDependencies = Lists.newArrayList();
dependenciesByArtifact.put(container.getArtifact(), artifactDependencies);
}
artifactDependencies.add(dependency);
}
});
List<String> variantNames = Lists.newArrayList(dependenciesByVariantAndArtifact.keySet());
Collections.sort(variantNames);
for (String variantName : variantNames) {
PsVariant variant = variantsByName.get(variantName);
Map<String, List<PsDependency>> dependenciesByArtifact = dependenciesByVariantAndArtifact.get(variantName);
if (dependenciesByArtifact != null) {
List<String> artifactNames = Lists.newArrayList(dependenciesByArtifact.keySet());
//noinspection TestOnlyProblems
Collections.sort(artifactNames, ArtifactComparator.byName());
for (String artifactName : artifactNames) {
PsAndroidArtifact artifact = variant.findArtifact(artifactName);
assert artifact != null;
AndroidArtifactNode mainArtifactNode = null;
String mainArtifactName = ARTIFACT_MAIN;
if (!mainArtifactName.equals(artifactName)) {
// Add "main" artifact as a dependency of "unit test" or "android test" artifact.
PsAndroidArtifact mainArtifact = variant.findArtifact(mainArtifactName);
if (mainArtifact != null) {
List<PsDependency> artifactDependencies = dependenciesByArtifact.get(mainArtifactName);
if (artifactDependencies == null) {
artifactDependencies = Collections.emptyList();
}
mainArtifactNode = createArtifactNode(mainArtifact, artifactDependencies, null);
}
}
AndroidArtifactNode artifactNode = createArtifactNode(artifact, dependenciesByArtifact.get(artifactName), mainArtifactNode);
if (artifactNode != null) {
childrenNodes.add(artifactNode);
}
}
}
}
return childrenNodes;
}
use of com.android.tools.idea.gradle.structure.model.PsDependency in project android by JetBrains.
the class LibraryDependencyNode method setUp.
private void setUp(@NotNull PsLibraryAndroidDependency dependency) {
myName = getText(dependency);
ImmutableCollection<PsDependency> transitiveDependencies = dependency.getTransitiveDependencies();
transitiveDependencies.stream().filter(transitive -> transitive instanceof PsLibraryAndroidDependency).forEach(transitive -> {
PsLibraryAndroidDependency transitiveLibrary = (PsLibraryAndroidDependency) transitive;
LibraryDependencyNode child = new LibraryDependencyNode(this, transitiveLibrary);
myChildren.add(child);
});
Collections.sort(myChildren, DependencyNodeComparator.INSTANCE);
}
use of com.android.tools.idea.gradle.structure.model.PsDependency in project android by JetBrains.
the class PsLibraryAndroidDependency method getTransitiveDependencies.
@Override
@NotNull
public ImmutableCollection<PsDependency> getTransitiveDependencies() {
PsAndroidModule module = getParent();
ImmutableSet.Builder<PsDependency> transitive = ImmutableSet.builder();
for (String dependency : myTransitiveDependencies) {
PsAndroidDependency found = module.findLibraryDependency(dependency);
if (found != null) {
transitive.add(found);
}
}
for (PsArtifactDependencySpec dependency : myPomDependencies) {
PsLibraryAndroidDependency found = module.findLibraryDependency(dependency);
if (found != null) {
transitive.add(found);
}
}
return transitive.build();
}
use of com.android.tools.idea.gradle.structure.model.PsDependency in project android by JetBrains.
the class DependencyNodes method createNodesFor.
@NotNull
static List<AbstractPsModelNode<?>> createNodesFor(@NotNull AndroidArtifactNode parent, @NotNull Collection<PsDependency> dependencies) {
List<AbstractPsModelNode<?>> children = Lists.newArrayList();
List<PsDependency> declared = new SortedList<>(PsDependencyComparator.INSTANCE);
Multimap<PsDependency, PsDependency> allTransitive = HashMultimap.create();
List<PsDependency> mayBeTransitive = Lists.newArrayList();
for (PsDependency dependency : dependencies) {
Collection<DependencyModel> parsedModels = dependency.getParsedModels();
if (parsedModels.isEmpty()) {
mayBeTransitive.add(dependency);
} else {
for (DependencyModel parsedModel : parsedModels) {
// "main" artifact.
for (PsAndroidArtifact artifact : parent.getModels()) {
if (artifact.contains(parsedModel)) {
declared.add(dependency);
break;
}
}
}
addTransitive(dependency, allTransitive);
}
}
Collection<PsDependency> uniqueTransitives = allTransitive.values();
declared.addAll(mayBeTransitive.stream().filter(dependency -> !uniqueTransitives.contains(dependency)).collect(Collectors.toList()));
for (PsDependency dependency : declared) {
AbstractDependencyNode<?> child = AbstractDependencyNode.createNode(parent, dependency);
if (child != null) {
children.add(child);
}
}
return children;
}
Aggregations