Search in sources :

Example 11 with PsArtifactDependencySpec

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

the class SingleLibraryDependencyDetails method display.

@Override
public void display(@NotNull PsDependency dependency, @Nullable String configurationNames) {
    myDependency = (PsLibraryDependency) dependency;
    PsArtifactDependencySpec spec = myDependency.getDeclaredSpec();
    if (spec == null) {
        spec = myDependency.getResolvedSpec();
    }
    myGroupIdLabel.setText(spec.group);
    myArtifactNameLabel.setText(spec.name);
    myResolvedVersionLabel.setText(myDependency.getResolvedSpec().version);
    myRequestedVersionLabel.setText(spec.version);
    String scopeToDisplay = isNotEmpty(configurationNames) ? configurationNames : dependency.getJoinedConfigurationNames();
    myScopeLabel.setText(scopeToDisplay);
}
Also used : PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)

Example 12 with PsArtifactDependencySpec

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

Example 13 with PsArtifactDependencySpec

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

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

the class LibraryDependencyNode method getText.

@NotNull
private String getText(@NotNull PsLibraryAndroidDependency dependency) {
    PsArtifactDependencySpec resolvedSpec = dependency.getResolvedSpec();
    if (dependency.hasPromotedVersion() && !(getParent() instanceof LibraryDependencyNode)) {
        // Show only "promoted" version for declared nodes.
        PsArtifactDependencySpec declaredSpec = dependency.getDeclaredSpec();
        assert declaredSpec != null;
        String version = declaredSpec.version + "→" + resolvedSpec.version;
        return getTextForSpec(declaredSpec.name, version, declaredSpec.group);
    }
    return resolvedSpec.getDisplayText();
}
Also used : PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with PsArtifactDependencySpec

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

the class AbstractDeclaredDependenciesTableModelTest method testShowArtifactDependencySpec.

public void testShowArtifactDependencySpec() {
    PsArtifactDependencySpec spec = new PsArtifactDependencySpec("appcompat-v7", "com.android.support", "23.1.0");
    when(myLibraryDependency.getResolvedSpec()).thenReturn(spec);
    when(myLibraryDependency.getDeclaredSpec()).thenReturn(spec);
    when(myLibraryDependency.toText(PLAIN_TEXT)).thenReturn("com.android.support:appcompat-v7:23.1.0");
    ColumnInfo[] columnInfos = myTableModel.getColumnInfos();
    PsUISettings.getInstance().DECLARED_DEPENDENCIES_SHOW_GROUP_ID = true;
    //noinspection unchecked
    ColumnInfo<PsAndroidDependency, String> specColumnInfo = columnInfos[0];
    DependencyCellRenderer renderer = (DependencyCellRenderer) specColumnInfo.getRenderer(myLibraryDependency);
    assertNotNull(renderer);
    String text = renderer.getText();
    assertEquals("com.android.support:appcompat-v7:23.1.0", text);
    PsUISettings.getInstance().DECLARED_DEPENDENCIES_SHOW_GROUP_ID = false;
    text = renderer.getText();
    assertEquals("appcompat-v7:23.1.0", text);
}
Also used : DependencyCellRenderer(com.android.tools.idea.gradle.structure.configurables.ui.dependencies.AbstractDeclaredDependenciesTableModel.DependencyCellRenderer) PsAndroidDependency(com.android.tools.idea.gradle.structure.model.android.PsAndroidDependency) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) ColumnInfo(com.intellij.util.ui.ColumnInfo)

Aggregations

PsArtifactDependencySpec (com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)16 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)5 NotNull (org.jetbrains.annotations.NotNull)5 PsParsedDependencies (com.android.tools.idea.gradle.structure.model.PsParsedDependencies)4 Nullable (org.jetbrains.annotations.Nullable)4 PsProject (com.android.tools.idea.gradle.structure.model.PsProject)3 File (java.io.File)3 PsModule (com.android.tools.idea.gradle.structure.model.PsModule)2 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 Element (org.jdom.Element)2 PROJECT_TYPE_APP (com.android.builder.model.AndroidProject.PROJECT_TYPE_APP)1 GradleVersion (com.android.ide.common.repository.GradleVersion)1 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)1 JarLibraryDependency (com.android.tools.idea.gradle.model.java.JarLibraryDependency)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 JavaModuleModel (com.android.tools.idea.gradle.project.model.JavaModuleModel)1 AbstractDependencyNode (com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.AbstractDependencyNode)1 DependencyCellRenderer (com.android.tools.idea.gradle.structure.configurables.ui.dependencies.AbstractDeclaredDependenciesTableModel.DependencyCellRenderer)1 PsDependency (com.android.tools.idea.gradle.structure.model.PsDependency)1