Search in sources :

Example 1 with PsArtifactDependencySpec

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

the class PsAndroidModuleTest method testEditableDependenciesWithPlusInVersion.

public void testEditableDependenciesWithPlusInVersion() throws Throwable {
    loadProject(PROJECT_WITH_APPAND_LIB);
    Project resolvedProject = myFixture.getProject();
    PsProject project = new PsProject(resolvedProject);
    PsAndroidModule appModule = (PsAndroidModule) project.findModuleByName("app");
    assertNotNull(appModule);
    List<PsAndroidDependency> declaredDependencies = getDeclaredDependencies(appModule);
    assertThat(declaredDependencies).hasSize(1);
    // Verify that appcompat is considered a "editable" dependency, and it was matched properly
    PsLibraryAndroidDependency appCompatV7 = (PsLibraryAndroidDependency) declaredDependencies.get(0);
    assertTrue(appCompatV7.isDeclared());
    PsArtifactDependencySpec declaredSpec = appCompatV7.getDeclaredSpec();
    assertNotNull(declaredSpec);
    assertEquals("com.android.support:appcompat-v7:+", declaredSpec.toString());
    PsArtifactDependencySpec resolvedSpec = appCompatV7.getResolvedSpec();
    assertEquals("com.android.support", resolvedSpec.group);
    assertEquals("appcompat-v7", resolvedSpec.name);
    assertThat(resolvedSpec.version).isNotEqualTo("+");
    // Verify that the variants where appcompat is are properly registered.
    Collection<String> variants = appCompatV7.getVariants();
    assertThat(variants).containsExactly("paidDebug", "paidRelease", "basicDebug", "basicRelease");
    for (String variant : variants) {
        assertNotNull(appModule.findVariant(variant));
    }
}
Also used : Project(com.intellij.openapi.project.Project) PsProject(com.android.tools.idea.gradle.structure.model.PsProject) PsProject(com.android.tools.idea.gradle.structure.model.PsProject) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)

Example 2 with PsArtifactDependencySpec

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

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

the class MavenPoms method createSpec.

@Nullable
private static PsArtifactDependencySpec createSpec(@NotNull Element dependencyElement) {
    String artifactId = null;
    String groupId = null;
    String version = null;
    String scope = null;
    boolean optional = false;
    for (Element childElement : dependencyElement.getChildren()) {
        String name = childElement.getName();
        if ("artifactId".equals(name)) {
            artifactId = textOf(childElement);
        } else if ("groupId".equals(name)) {
            groupId = textOf(childElement);
        } else if ("version".equals(name)) {
            version = textOf(childElement);
        } else if ("optional".equals(name)) {
            optional = Boolean.valueOf(textOf(childElement));
        } else if ("scope".equals(name)) {
            scope = textOf(childElement);
        }
    }
    if (isNotEmpty(artifactId) && !optional && ("compile".equals(scope) || isEmpty(scope))) {
        return new PsArtifactDependencySpec(artifactId, groupId, version);
    }
    return null;
}
Also used : Element(org.jdom.Element) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with PsArtifactDependencySpec

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

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

the class MultipleLibraryDependenciesDetails method display.

@Override
public void display(@NotNull PsDependency dependency) {
    myDependency = (PsLibraryDependency) dependency;
    PsArtifactDependencySpec resolvedSpec = myDependency.getResolvedSpec();
    myArtifactNameLabel.setText(resolvedSpec.name);
    myGroupIdLabel.setText(resolvedSpec.group);
}
Also used : PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)

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