Search in sources :

Example 1 with PsDependency

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);
        }
    }
}
Also used : PsLibraryAndroidDependency(com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency) PsDependency(com.android.tools.idea.gradle.structure.model.PsDependency)

Example 2 with PsDependency

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;
}
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) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PsDependency

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);
}
Also used : StringUtil.isNotEmpty(com.intellij.openapi.util.text.StringUtil.isNotEmpty) GRADLE_PATH_SEPARATOR(com.android.SdkConstants.GRADLE_PATH_SEPARATOR) PsDependency(com.android.tools.idea.gradle.structure.model.PsDependency) ImmutableCollection(com.google.common.collect.ImmutableCollection) AbstractPsNode(com.android.tools.idea.gradle.structure.configurables.ui.treeview.AbstractPsNode) PsLibraryAndroidDependency(com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency) Nullable(org.jetbrains.annotations.Nullable) PsUISettings(com.android.tools.idea.gradle.structure.configurables.ui.PsUISettings) List(java.util.List) Lists(com.google.common.collect.Lists) PsModel(com.android.tools.idea.gradle.structure.model.PsModel) SimpleNode(com.intellij.ui.treeStructure.SimpleNode) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) PsLibraryAndroidDependency(com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency) PsDependency(com.android.tools.idea.gradle.structure.model.PsDependency)

Example 4 with PsDependency

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();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) PsDependency(com.android.tools.idea.gradle.structure.model.PsDependency) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with PsDependency

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;
}
Also used : DependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.DependencyModel) PsAndroidArtifact(com.android.tools.idea.gradle.structure.model.android.PsAndroidArtifact) SortedList(com.intellij.util.containers.SortedList) AbstractPsModelNode(com.android.tools.idea.gradle.structure.configurables.ui.treeview.AbstractPsModelNode) PsDependency(com.android.tools.idea.gradle.structure.model.PsDependency) 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