Search in sources :

Example 1 with DependencyModel

use of com.android.tools.idea.gradle.dsl.model.dependencies.DependencyModel in project android by JetBrains.

the class PsLibraryDependency method setVersion.

default default void setVersion(@NotNull String version) {
    boolean modified = false;
    ArtifactDependencyModel reference = null;
    for (DependencyModel parsedDependency : getParsedModels()) {
        if (parsedDependency instanceof ArtifactDependencyModel) {
            ArtifactDependencyModel dependency = (ArtifactDependencyModel) parsedDependency;
            dependency.setVersion(version);
            if (reference == null) {
                reference = dependency;
            }
            modified = true;
        }
    }
    if (modified) {
        GradleVersion parsedVersion = GradleVersion.parse(version);
        PsArtifactDependencySpec resolvedSpec = getResolvedSpec();
        String resolvedVersion = nullToEmpty(resolvedSpec.version);
        if (parsedVersion.compareTo(resolvedVersion) != 0) {
            // Update the "resolved" spec with the new version
            resolvedSpec = new PsArtifactDependencySpec(resolvedSpec.name, resolvedSpec.group, version);
            setResolvedSpec(resolvedSpec);
        }
        setDeclaredSpec(createSpec(reference));
        setModified(true);
        getParent().fireDependencyModifiedEvent((PsDependency) this);
    }
}
Also used : DependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.DependencyModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) GradleVersion(com.android.ide.common.repository.GradleVersion)

Example 2 with DependencyModel

use of com.android.tools.idea.gradle.dsl.model.dependencies.DependencyModel in project android by JetBrains.

the class PsParsedDependencies method reset.

void reset(@Nullable GradleBuildModel parsedModel) {
    myParsedArtifactDependencies.clear();
    myParsedModuleDependencies.clear();
    if (parsedModel != null) {
        ApplicationManager.getApplication().runReadAction(() -> {
            for (DependencyModel parsedDependency : parsedModel.dependencies().all()) {
                if (parsedDependency instanceof ArtifactDependencyModel) {
                    ArtifactDependencyModel artifact = (ArtifactDependencyModel) parsedDependency;
                    myParsedArtifactDependencies.put(createIdFrom(artifact), artifact);
                } else if (parsedDependency instanceof ModuleDependencyModel) {
                    ModuleDependencyModel module = (ModuleDependencyModel) parsedDependency;
                    myParsedModuleDependencies.put(module.path().value(), module);
                }
            }
        });
    }
}
Also used : ModuleDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ModuleDependencyModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) DependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.DependencyModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) ModuleDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ModuleDependencyModel)

Example 3 with DependencyModel

use of com.android.tools.idea.gradle.dsl.model.dependencies.DependencyModel 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

DependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.DependencyModel)3 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)2 GradleVersion (com.android.ide.common.repository.GradleVersion)1 ModuleDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ModuleDependencyModel)1 AbstractPsModelNode (com.android.tools.idea.gradle.structure.configurables.ui.treeview.AbstractPsModelNode)1 PsDependency (com.android.tools.idea.gradle.structure.model.PsDependency)1 PsAndroidArtifact (com.android.tools.idea.gradle.structure.model.android.PsAndroidArtifact)1 SortedList (com.intellij.util.containers.SortedList)1 NotNull (org.jetbrains.annotations.NotNull)1