Search in sources :

Example 6 with PsDependency

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;
}
Also used : AndroidArtifactNode(com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.AndroidArtifactNode) PsDependency(com.android.tools.idea.gradle.structure.model.PsDependency) SortedList(com.intellij.util.containers.SortedList) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsDependency (com.android.tools.idea.gradle.structure.model.PsDependency)6 NotNull (org.jetbrains.annotations.NotNull)5 SortedList (com.intellij.util.containers.SortedList)3 List (java.util.List)3 AndroidArtifactNode (com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.AndroidArtifactNode)2 PsArtifactDependencySpec (com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)2 PsLibraryAndroidDependency (com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency)2 GRADLE_PATH_SEPARATOR (com.android.SdkConstants.GRADLE_PATH_SEPARATOR)1 DependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.DependencyModel)1 PsUISettings (com.android.tools.idea.gradle.structure.configurables.ui.PsUISettings)1 AbstractPsModelNode (com.android.tools.idea.gradle.structure.configurables.ui.treeview.AbstractPsModelNode)1 AbstractPsNode (com.android.tools.idea.gradle.structure.configurables.ui.treeview.AbstractPsNode)1 PsModel (com.android.tools.idea.gradle.structure.model.PsModel)1 PsAndroidArtifact (com.android.tools.idea.gradle.structure.model.android.PsAndroidArtifact)1 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 StringUtil.isNotEmpty (com.intellij.openapi.util.text.StringUtil.isNotEmpty)1 SimpleNode (com.intellij.ui.treeStructure.SimpleNode)1 Collections (java.util.Collections)1