Search in sources :

Example 1 with PsLibraryAndroidDependency

use of com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency 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 PsLibraryAndroidDependency

use of com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency in project android by JetBrains.

the class LibraryDependencyNode method matches.

@Override
public boolean matches(@NotNull PsModel model) {
    if (model instanceof PsLibraryAndroidDependency) {
        PsLibraryAndroidDependency other = (PsLibraryAndroidDependency) model;
        List<PsLibraryAndroidDependency> models = getModels();
        for (PsLibraryAndroidDependency dependency : models) {
            if (dependency.getResolvedSpec().equals(other.getResolvedSpec())) {
                return true;
            }
        }
    }
    return false;
}
Also used : PsLibraryAndroidDependency(com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency)

Example 3 with PsLibraryAndroidDependency

use of com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency 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 PsLibraryAndroidDependency

use of com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency in project android by JetBrains.

the class AddLibraryDependencyDialog method doValidate.

@Override
@Nullable
protected ValidationInfo doValidate() {
    List<Exception> searchErrors = myLibraryDependenciesForm.getSearchErrors();
    if (!searchErrors.isEmpty()) {
        StringBuilder buffer = new StringBuilder();
        searchErrors.forEach(e -> buffer.append(getErrorMessage(e)).append("\n"));
        return new ValidationInfo(buffer.toString(), myLibraryDependenciesForm.getPreferredFocusedComponent());
    }
    String selectedLibrary = myLibraryDependenciesForm.getSelectedLibrary();
    if (isEmpty(selectedLibrary)) {
        return new ValidationInfo("Please specify the library to add as dependency", myLibraryDependenciesForm.getPreferredFocusedComponent());
    }
    PsArtifactDependencySpec spec = PsArtifactDependencySpec.create(selectedLibrary);
    PsModule module = getModule();
    if (spec != null && module instanceof PsAndroidModule) {
        PsAndroidModule androidModule = (PsAndroidModule) module;
        Ref<Boolean> found = new Ref<>(false);
        androidModule.forEachDeclaredDependency(dependency -> {
            if (dependency instanceof PsLibraryAndroidDependency) {
                PsLibraryAndroidDependency libraryDependency = (PsLibraryAndroidDependency) dependency;
                PsArtifactDependencySpec resolvedSpec = libraryDependency.getResolvedSpec();
                if (Objects.equals(spec.group, resolvedSpec.group) && Objects.equals(spec.name, resolvedSpec.name)) {
                    found.set(true);
                }
            }
        });
        if (found.get()) {
            String msg = String.format("Library '%1$s' is already a dependency", spec.name);
            return new ValidationInfo(msg, myLibraryDependenciesForm.getPreferredFocusedComponent());
        }
    }
    return getScopesPanel().validateInput();
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) Ref(com.intellij.openapi.util.Ref) PsModule(com.android.tools.idea.gradle.structure.model.PsModule) PsAndroidModule(com.android.tools.idea.gradle.structure.model.android.PsAndroidModule) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) PsLibraryAndroidDependency(com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency) UnknownHostException(java.net.UnknownHostException) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with PsLibraryAndroidDependency

use of com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency in project android by JetBrains.

the class DependenciesTreeBuilder method find.

@Nullable
public LibraryDependencyNode find(@NotNull PsArtifactDependencySpec spec) {
    DefaultMutableTreeNode rootNode = getRootNode();
    if (rootNode == null) {
        return null;
    }
    int childCount = rootNode.getChildCount();
    for (int i = 0; i < childCount; i++) {
        TreeNode child = rootNode.getChildAt(i);
        if (!(child instanceof DefaultMutableTreeNode)) {
            continue;
        }
        Object userObject = ((DefaultMutableTreeNode) child).getUserObject();
        if (!(userObject instanceof LibraryDependencyNode)) {
            continue;
        }
        LibraryDependencyNode node = (LibraryDependencyNode) userObject;
        for (PsLibraryAndroidDependency dependency : node.getModels()) {
            if (spec.equals(dependency.getDeclaredSpec())) {
                return node;
            }
        }
    }
    return null;
}
Also used : LibraryDependencyNode(com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.LibraryDependencyNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) PsLibraryAndroidDependency(com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsLibraryAndroidDependency (com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency)5 Nullable (org.jetbrains.annotations.Nullable)3 PsArtifactDependencySpec (com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)2 PsDependency (com.android.tools.idea.gradle.structure.model.PsDependency)2 GRADLE_PATH_SEPARATOR (com.android.SdkConstants.GRADLE_PATH_SEPARATOR)1 LibraryDependencyNode (com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.LibraryDependencyNode)1 PsUISettings (com.android.tools.idea.gradle.structure.configurables.ui.PsUISettings)1 AbstractPsNode (com.android.tools.idea.gradle.structure.configurables.ui.treeview.AbstractPsNode)1 PsModel (com.android.tools.idea.gradle.structure.model.PsModel)1 PsModule (com.android.tools.idea.gradle.structure.model.PsModule)1 PsAndroidModule (com.android.tools.idea.gradle.structure.model.android.PsAndroidModule)1 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 Lists (com.google.common.collect.Lists)1 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)1 Ref (com.intellij.openapi.util.Ref)1 StringUtil.isNotEmpty (com.intellij.openapi.util.text.StringUtil.isNotEmpty)1 SimpleNode (com.intellij.ui.treeStructure.SimpleNode)1 UnknownHostException (java.net.UnknownHostException)1 Collections (java.util.Collections)1 List (java.util.List)1