Search in sources :

Example 1 with AbstractDependencyNode

use of com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.AbstractDependencyNode in project android by JetBrains.

the class DependenciesTreeRootNode method createChildren.

@Override
@NotNull
protected List<? extends AbstractPsModelNode> createChildren() {
    T model = getFirstModel();
    DependencyCollector collector = myDependencyCollectorFunction.apply(model);
    List<AbstractDependencyNode> children = Lists.newArrayList();
    for (Map.Entry<LibraryDependencySpecs, List<PsLibraryAndroidDependency>> entry : collector.libraryDependenciesBySpec.entrySet()) {
        LibraryDependencyNode child = new LibraryDependencyNode(this, entry.getValue());
        children.add(child);
    }
    for (Map.Entry<String, List<PsModuleAndroidDependency>> entry : collector.moduleDependenciesByGradlePath.entrySet()) {
        ModuleDependencyNode child = new ModuleDependencyNode(this, entry.getValue());
        children.add(child);
    }
    Collections.sort(children, DependencyNodeComparator.INSTANCE);
    return children;
}
Also used : AbstractDependencyNode(com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.AbstractDependencyNode) LibraryDependencyNode(com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.LibraryDependencyNode) ModuleDependencyNode(com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.ModuleDependencyNode) List(java.util.List) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with AbstractDependencyNode

use of com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.AbstractDependencyNode in project android by JetBrains.

the class TargetModulesTreeStructure method getDeclaredDependencyNodeHierarchy.

@NotNull
private static List<AbstractDependencyNode<? extends PsAndroidDependency>> getDeclaredDependencyNodeHierarchy(AbstractDependencyNode<?> node) {
    List<AbstractDependencyNode<? extends PsAndroidDependency>> nodes = Lists.newArrayList();
    if (node.isDeclared()) {
        nodes.add(node);
    }
    SimpleNode current = node;
    while (true) {
        SimpleNode parent = current.getParent();
        if (parent instanceof AbstractDependencyNode && ((AbstractDependencyNode) parent).isDeclared()) {
            nodes.add((AbstractDependencyNode<? extends PsAndroidDependency>) parent);
        } else if (parent == null) {
            break;
        }
        current = parent;
    }
    return nodes;
}
Also used : AbstractDependencyNode(com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.AbstractDependencyNode) SimpleNode(com.intellij.ui.treeStructure.SimpleNode) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with AbstractDependencyNode

use of com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.AbstractDependencyNode in project android by JetBrains.

the class TargetModulesTreeStructure method displayTargetModules.

void displayTargetModules(@NotNull List<AbstractDependencyNode<? extends PsAndroidDependency>> dependencyNodes) {
    // Key: module name, Value: pair of module and version of the dependency used in the module.
    Map<String, Pair<PsAndroidModule, String>> modules = Maps.newHashMap();
    // Key: module name, Value: configuration names.
    Multimap<String, Configuration> configurationNamesByModule = HashMultimap.create();
    // From the list of AbstractDependencyNode:
    //  1. Extract modules (to show them as top-level nodes)
    //  2. Extract variants/artifact (i.e. PsDependencyContainer) per module (to show them as children nodes of the module nodes)
    dependencyNodes.forEach(node -> {
        List<AbstractDependencyNode<? extends PsAndroidDependency>> declaredDependencyNodes = getDeclaredDependencyNodeHierarchy(node);
        Map<String, String> versionByModule = Maps.newHashMap();
        for (PsAndroidDependency dependency : node.getModels()) {
            if (dependency instanceof PsLibraryAndroidDependency) {
                PsLibraryAndroidDependency libraryDependency = (PsLibraryAndroidDependency) dependency;
                PsArtifactDependencySpec spec = libraryDependency.getDeclaredSpec();
                if (spec == null) {
                    spec = libraryDependency.getResolvedSpec();
                }
                PsAndroidModule module = dependency.getParent();
                versionByModule.put(module.getName(), spec.version);
            }
        }
        AbstractDependencyNode<? extends PsAndroidDependency> topParentNode = declaredDependencyNodes.get(declaredDependencyNodes.size() - 1);
        for (PsAndroidDependency dependency : topParentNode.getModels()) {
            PsAndroidModule module = dependency.getParent();
            String moduleName = module.getName();
            Pair<PsAndroidModule, String> existing = modules.get(moduleName);
            if (existing == null) {
                modules.put(moduleName, Pair.create(module, versionByModule.get(moduleName)));
            }
        }
        declaredDependencyNodes.forEach(declaredDependencyNode -> {
            List<PsAndroidDependency> declaredDependencies = getDeclaredDependencies(declaredDependencyNode);
            declaredDependencies.forEach(declaredDependency -> {
                List<String> configurationNames = declaredDependency.getConfigurationNames();
                assert !configurationNames.isEmpty();
                PsAndroidModule module = declaredDependency.getParent();
                String moduleName = module.getName();
                for (PsDependencyContainer container : declaredDependency.getContainers()) {
                    PsAndroidArtifact artifact = container.findArtifact(module, false);
                    for (String configurationName : configurationNames) {
                        if (artifact != null && artifact.containsConfigurationName(configurationName)) {
                            boolean transitive = declaredDependencyNode != node;
                            Collection<Configuration> configurations = configurationNamesByModule.get(moduleName);
                            boolean found = false;
                            for (Configuration configuration : configurations) {
                                if (configuration.getName().equals(configurationName)) {
                                    configuration.addType(transitive);
                                    found = true;
                                    break;
                                }
                            }
                            if (!found) {
                                Icon icon = artifact.getIcon();
                                configurationNamesByModule.put(moduleName, new Configuration(configurationName, icon, transitive));
                            }
                        }
                    }
                }
            });
        });
    });
    // Now we create the tree nodes.
    List<TargetAndroidModuleNode> children = Lists.newArrayList();
    for (Pair<PsAndroidModule, String> moduleAndVersion : modules.values()) {
        PsAndroidModule module = moduleAndVersion.getFirst();
        TargetAndroidModuleNode moduleNode = new TargetAndroidModuleNode(myRootNode, module, moduleAndVersion.getSecond());
        List<Configuration> configurations = Lists.newArrayList(configurationNamesByModule.get(module.getName()));
        Collections.sort(configurations);
        List<TargetConfigurationNode> nodes = Lists.newArrayList();
        configurations.forEach(configuration -> nodes.add(new TargetConfigurationNode(configuration)));
        moduleNode.setChildren(nodes);
        children.add(moduleNode);
    }
    Collections.sort(children, new SimpleNodeComparator<>());
    myRootNode.setChildren(children);
}
Also used : Pair(com.intellij.openapi.util.Pair) AbstractDependencyNode(com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.AbstractDependencyNode) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)

Aggregations

AbstractDependencyNode (com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.AbstractDependencyNode)3 NotNull (org.jetbrains.annotations.NotNull)2 LibraryDependencyNode (com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.LibraryDependencyNode)1 ModuleDependencyNode (com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.ModuleDependencyNode)1 PsArtifactDependencySpec (com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)1 Pair (com.intellij.openapi.util.Pair)1 SimpleNode (com.intellij.ui.treeStructure.SimpleNode)1 List (java.util.List)1 Map (java.util.Map)1