use of com.android.tools.idea.gradle.structure.model.PsDependency in project android by JetBrains.
the class ResolvedDependenciesTreeRootNode method createGroupedChildren.
@NotNull
private List<? extends AbstractPsModelNode> createGroupedChildren(@NotNull PsAndroidModule module, @NotNull Map<String, PsVariant> variantsByName) {
Map<String, List<PsDependencyContainer>> containersWithMainArtifactByVariant = Maps.newHashMap();
Map<List<PsDependencyContainer>, List<PsDependency>> groupedDependencies = groupDependencies(module);
for (List<PsDependencyContainer> containers : groupedDependencies.keySet()) {
for (PsDependencyContainer container : containers) {
if (container.getArtifact().endsWith(ARTIFACT_MAIN)) {
containersWithMainArtifactByVariant.put(container.getVariant(), containers);
break;
}
}
}
List<AndroidArtifactNode> children = Lists.newArrayList();
for (List<PsDependencyContainer> containers : groupedDependencies.keySet()) {
List<PsAndroidArtifact> groupArtifacts = extractArtifacts(containers, variantsByName);
AndroidArtifactNode mainArtifactNode = null;
if (!containersWithMainArtifactByVariant.values().contains(containers)) {
// This is a node for "Unit Test" or "Android Test"
if (containers.size() == 1) {
// This is not a group. Create the "main" artifact node for the same variant
PsDependencyContainer container = containers.get(0);
String variantName = container.getVariant();
PsVariant variant = variantsByName.get(variantName);
assert variant != null;
PsAndroidArtifact mainArtifact = variant.findArtifact(ARTIFACT_MAIN);
if (mainArtifact != null) {
List<PsDependencyContainer> mainArtifactContainers = containersWithMainArtifactByVariant.get(variantName);
if (mainArtifactContainers != null) {
List<PsDependency> mainArtifactDependencies = groupedDependencies.get(mainArtifactContainers);
mainArtifactNode = createArtifactNode(mainArtifact, mainArtifactDependencies, null);
}
}
} else {
// Create the node that contains all the containers with "main" artifacts
for (PsDependencyContainer container : containers) {
List<PsDependencyContainer> mainArtifactContainers = containersWithMainArtifactByVariant.get(container.getVariant());
if (mainArtifactContainers != null) {
List<PsAndroidArtifact> mainArtifacts = extractArtifacts(mainArtifactContainers, variantsByName);
mainArtifactNode = createArtifactNode(mainArtifacts, groupedDependencies.get(mainArtifactContainers), null);
break;
}
}
}
}
Collections.sort(groupArtifacts, ArtifactComparator.INSTANCE);
AndroidArtifactNode artifactNode = createArtifactNode(groupArtifacts, groupedDependencies.get(containers), mainArtifactNode);
if (artifactNode != null) {
children.add(artifactNode);
}
}
Collections.sort(children, (a1, a2) -> a1.getName().compareTo(a2.getName()));
return children;
}
Aggregations