Search in sources :

Example 1 with PsNewDependencyScopes

use of com.android.tools.idea.gradle.structure.model.android.dependency.PsNewDependencyScopes 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 2 with PsNewDependencyScopes

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

the class AddLibraryDependencyDialog method addNewDependencies.

@Override
public void addNewDependencies() {
    String library = myLibraryDependenciesForm.getSelectedLibrary();
    assert library != null;
    AbstractDependencyScopesPanel scopesPanel = getScopesPanel();
    List<String> scopesNames = scopesPanel.getSelectedScopeNames();
    PsModule module = getModule();
    if (module instanceof PsAndroidModule) {
        PsNewDependencyScopes newScopes = ((AndroidDependencyScopesPanel) scopesPanel).getNewScopes();
        assert newScopes != null;
        ((PsAndroidModule) module).addLibraryDependency(library, newScopes, scopesNames);
    } else if (module instanceof PsJavaModule) {
        ((PsJavaModule) module).addLibraryDependency(library, scopesNames);
    }
}
Also used : PsJavaModule(com.android.tools.idea.gradle.structure.model.java.PsJavaModule) PsModule(com.android.tools.idea.gradle.structure.model.PsModule) PsNewDependencyScopes(com.android.tools.idea.gradle.structure.model.android.dependency.PsNewDependencyScopes) PsAndroidModule(com.android.tools.idea.gradle.structure.model.android.PsAndroidModule) AndroidDependencyScopesPanel(com.android.tools.idea.gradle.structure.dependencies.android.AndroidDependencyScopesPanel)

Aggregations

PsModule (com.android.tools.idea.gradle.structure.model.PsModule)2 PsNewDependencyScopes (com.android.tools.idea.gradle.structure.model.android.dependency.PsNewDependencyScopes)2 PROJECT_TYPE_APP (com.android.builder.model.AndroidProject.PROJECT_TYPE_APP)1 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 AndroidDependencyScopesPanel (com.android.tools.idea.gradle.structure.dependencies.android.AndroidDependencyScopesPanel)1 PsArtifactDependencySpec (com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)1 PsParsedDependencies (com.android.tools.idea.gradle.structure.model.PsParsedDependencies)1 PsProject (com.android.tools.idea.gradle.structure.model.PsProject)1 PsAndroidModule (com.android.tools.idea.gradle.structure.model.android.PsAndroidModule)1 PsJavaModule (com.android.tools.idea.gradle.structure.model.java.PsJavaModule)1 AndroidSdkRepositories (com.android.tools.idea.gradle.structure.model.repositories.search.AndroidSdkRepositories)1 ArtifactRepository (com.android.tools.idea.gradle.structure.model.repositories.search.ArtifactRepository)1 Lists (com.google.common.collect.Lists)1 Module (com.intellij.openapi.module.Module)1 AndroidIcons (icons.AndroidIcons)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 javax.swing (javax.swing)1 NotNull (org.jetbrains.annotations.NotNull)1