Search in sources :

Example 1 with ArtifactDependencyModel

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

the class GradleOperations method removeDependencies.

@Override
public void removeDependencies(@NotNull Module module, @NotNull DeveloperServiceMetadata metadata) {
    final GradleBuildModel buildModel = GradleBuildModel.get(module);
    if (buildModel != null) {
        boolean dependenciesChanged = false;
        DependenciesModel dependenciesModel = buildModel.dependencies();
        if (dependenciesModel != null) {
            for (ArtifactDependencyModel dependency : dependenciesModel.artifacts()) {
                ArtifactDependencySpec spec = ArtifactDependencySpec.create(dependency);
                for (String dependencyValue : metadata.getDependencies()) {
                    if (spec.equals(ArtifactDependencySpec.create(dependencyValue))) {
                        dependenciesModel.remove(dependency);
                        dependenciesChanged = true;
                        break;
                    }
                }
            }
        }
        final Project project = module.getProject();
        if (dependenciesChanged) {
            new WriteCommandAction.Simple(project, "Uninstall " + metadata.getName()) {

                @Override
                public void run() {
                    buildModel.applyChanges();
                }
            }.execute();
        }
        GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) DependenciesModel(com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel) ArtifactDependencySpec(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencySpec)

Example 2 with ArtifactDependencyModel

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

the class GradleOperations method containsAllDependencies.

@Override
public boolean containsAllDependencies(@NotNull Module module, @NotNull DeveloperServiceMetadata metadata) {
    // Consider ourselves installed if this service's dependencies are already found in the current
    // module.
    // TODO: Flesh this simplistic approach out more. We would like to have a way to say a service
    // isn't installed even if its dependency happens to be added to the project. For example,
    // multiple services might share a dependency but have additional settings that indicate some
    // are installed and others aren't.
    List<String> moduleDependencyNames = Lists.newArrayList();
    GradleBuildModel buildModel = GradleBuildModel.get(module);
    if (buildModel != null) {
        DependenciesModel dependenciesModel = buildModel.dependencies();
        if (dependenciesModel != null) {
            for (ArtifactDependencyModel dependency : dependenciesModel.artifacts()) {
                String name = dependency.name().value();
                moduleDependencyNames.add(name);
            }
        }
    }
    boolean allDependenciesFound = true;
    for (String serviceDependency : metadata.getDependencies()) {
        boolean thisDependencyFound = false;
        for (String moduleDependencyName : moduleDependencyNames) {
            if (serviceDependency.contains(moduleDependencyName)) {
                thisDependencyFound = true;
                break;
            }
        }
        if (!thisDependencyFound) {
            allDependenciesFound = false;
            break;
        }
    }
    return allDependenciesFound;
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) DependenciesModel(com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel)

Example 3 with ArtifactDependencyModel

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

the class PsJavaDependencyCollection method addDependencies.

private void addDependencies() {
    PsParsedDependencies parsedDependencies = myParent.getParsedDependencies();
    JavaModuleModel gradleModel = myParent.getGradleModel();
    for (JarLibraryDependency libraryDependency : gradleModel.getJarLibraryDependencies()) {
        GradleModuleVersion moduleVersion = libraryDependency.getModuleVersion();
        if (moduleVersion != null) {
            PsArtifactDependencySpec spec = PsArtifactDependencySpec.create(moduleVersion);
            ArtifactDependencyModel parsed = parsedDependencies.findLibraryDependency(moduleVersion);
            PsLibraryJavaDependency dependency = new PsLibraryJavaDependency(myParent, spec, libraryDependency, parsed);
            myLibraryDependenciesBySpec.put(spec.toString(), dependency);
        }
    }
}
Also used : JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) JarLibraryDependency(com.android.tools.idea.gradle.model.java.JarLibraryDependency) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) PsParsedDependencies(com.android.tools.idea.gradle.structure.model.PsParsedDependencies) GradleModuleVersion(org.gradle.tooling.model.GradleModuleVersion)

Example 4 with ArtifactDependencyModel

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

the class PsAndroidModule method addLibraryDependency.

public void addLibraryDependency(@NotNull String library, @NotNull PsNewDependencyScopes newScopes, @NotNull List<String> scopesNames) {
    // Update/reset the "parsed" model.
    addLibraryDependencyToParsedModel(scopesNames, library);
    // Reset dependencies.
    myDependencyCollection = null;
    PsAndroidDependencyCollection dependencyCollection = getOrCreateDependencyCollection();
    List<PsAndroidArtifact> targetArtifacts = Lists.newArrayList();
    forEachVariant(variant -> variant.forEachArtifact(artifact -> {
        if (newScopes.contains(artifact)) {
            targetArtifacts.add(artifact);
        }
    }));
    assert !targetArtifacts.isEmpty();
    PsArtifactDependencySpec spec = PsArtifactDependencySpec.create(library);
    assert spec != null;
    PsParsedDependencies parsedDependencies = getParsedDependencies();
    for (PsAndroidArtifact artifact : targetArtifacts) {
        List<ArtifactDependencyModel> matchingParsedDependencies = parsedDependencies.findLibraryDependencies(spec, artifact::contains);
        for (ArtifactDependencyModel parsedDependency : matchingParsedDependencies) {
            dependencyCollection.addLibraryDependency(spec, artifact, parsedDependency);
        }
    }
    fireLibraryDependencyAddedEvent(spec);
    setModified(true);
}
Also used : ArtifactRepository(com.android.tools.idea.gradle.structure.model.repositories.search.ArtifactRepository) PsModule(com.android.tools.idea.gradle.structure.model.PsModule) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) PROJECT_TYPE_APP(com.android.builder.model.AndroidProject.PROJECT_TYPE_APP) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Lists(com.google.common.collect.Lists) AndroidIcons(icons.AndroidIcons) PsParsedDependencies(com.android.tools.idea.gradle.structure.model.PsParsedDependencies) AndroidSdkRepositories(com.android.tools.idea.gradle.structure.model.repositories.search.AndroidSdkRepositories) PsProject(com.android.tools.idea.gradle.structure.model.PsProject) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) PsNewDependencyScopes(com.android.tools.idea.gradle.structure.model.android.dependency.PsNewDependencyScopes) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) PsParsedDependencies(com.android.tools.idea.gradle.structure.model.PsParsedDependencies)

Example 5 with ArtifactDependencyModel

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

the class GradleDependencyManager method updateDependencies.

private static void updateDependencies(@NotNull GradleBuildModel buildModel, @NotNull Module module, @NotNull List<GradleCoordinate> coordinates) {
    ModuleRootModificationUtil.updateModel(module, model -> {
        DependenciesModel dependenciesModel = buildModel.dependencies();
        for (GradleCoordinate gc : coordinates) {
            List<ArtifactDependencyModel> artifacts = Lists.newArrayList(dependenciesModel.artifacts());
            for (ArtifactDependencyModel m : artifacts) {
                if (gc.getGroupId() != null && gc.getGroupId().equals(m.group().value()) && gc.getArtifactId() != null && gc.getArtifactId().equals(m.name().value()) && !gc.getRevision().equals(m.version().value())) {
                    dependenciesModel.remove(m);
                    dependenciesModel.addArtifact(m.configurationName(), gc.toString());
                }
            }
        }
        buildModel.applyChanges();
    });
}
Also used : GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) DependenciesModel(com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel)

Aggregations

ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)28 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)17 DependenciesModel (com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel)12 NotNull (org.jetbrains.annotations.NotNull)7 Project (com.intellij.openapi.project.Project)6 GradleVersion (com.android.ide.common.repository.GradleVersion)5 PsArtifactDependencySpec (com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)5 File (java.io.File)5 ArtifactDependencySpec (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencySpec)4 PsParsedDependencies (com.android.tools.idea.gradle.structure.model.PsParsedDependencies)4 RepositoryUrlManager (com.android.tools.idea.templates.RepositoryUrlManager)4 Module (com.intellij.openapi.module.Module)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)3 ExpectedArtifactDependency (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyTest.ExpectedArtifactDependency)3 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 Nullable (org.jetbrains.annotations.Nullable)3 DependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.DependencyModel)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 PsProject (com.android.tools.idea.gradle.structure.model.PsProject)2