Search in sources :

Example 6 with PsProject

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

the class ModuleDependencyNode method setUp.

private void setUp(@NotNull PsModuleAndroidDependency moduleDependency) {
    myName = moduleDependency.toText(PLAIN_TEXT);
    PsAndroidModule dependentModule = moduleDependency.getParent();
    PsProject project = dependentModule.getParent();
    PsModule referred = project.findModuleByGradlePath(moduleDependency.getGradlePath());
    if (referred instanceof PsAndroidModule) {
        PsAndroidModule androidModule = (PsAndroidModule) referred;
        androidModule.forEachDependency(dependency -> {
            if (!dependency.isDeclared()) {
                return;
            }
            String moduleVariant = moduleDependency.getConfigurationName();
            if (!dependency.isIn(ARTIFACT_MAIN, moduleVariant)) {
                return;
            }
            AbstractPsModelNode<?> child = AbstractDependencyNode.createNode(this, dependency);
            if (child != null) {
                myChildren.add(child);
            }
        });
    }
}
Also used : PsProject(com.android.tools.idea.gradle.structure.model.PsProject) PsModule(com.android.tools.idea.gradle.structure.model.PsModule) PsAndroidModule(com.android.tools.idea.gradle.structure.model.android.PsAndroidModule)

Example 7 with PsProject

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

the class PsAndroidModuleTest method testVariants.

public void testVariants() throws Throwable {
    loadProject(PROJECT_WITH_APPAND_LIB);
    Project resolvedProject = myFixture.getProject();
    PsProject project = new PsProject(resolvedProject);
    PsAndroidModule appModule = (PsAndroidModule) project.findModuleByName("app");
    assertNotNull(appModule);
    Collection<PsVariant> variants = getVariants(appModule);
    assertThat(variants).hasSize(4);
    PsVariant paidDebug = appModule.findVariant("paidDebug");
    assertNotNull(paidDebug);
    List<String> flavors = paidDebug.getProductFlavors();
    assertThat(flavors).containsExactly("paid");
    PsVariant paidRelease = appModule.findVariant("paidRelease");
    assertNotNull(paidRelease);
    flavors = paidRelease.getProductFlavors();
    assertThat(flavors).containsExactly("paid");
    PsVariant basicDebug = appModule.findVariant("basicDebug");
    assertNotNull(basicDebug);
    flavors = basicDebug.getProductFlavors();
    assertThat(flavors).containsExactly("basic");
    PsVariant basicRelease = appModule.findVariant("basicRelease");
    assertNotNull(basicRelease);
    flavors = basicRelease.getProductFlavors();
    assertThat(flavors).containsExactly("basic");
}
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)

Example 8 with PsProject

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

the class PsAndroidModuleTest method testEditableDependencies.

public void testEditableDependencies() throws Throwable {
    loadProject(PROJECT_WITH_APPAND_LIB);
    Project resolvedProject = myFixture.getProject();
    Module appModule = ModuleManager.getInstance(resolvedProject).findModuleByName("app");
    assertNotNull(appModule);
    // Make sure 'app' has an artifact dependency with version not including a '+'
    GradleBuildModel buildModel = GradleBuildModel.get(appModule);
    assertNotNull(buildModel);
    for (ArtifactDependencyModel dependency : buildModel.dependencies().artifacts("compile")) {
        if ("com.android.support".equals(dependency.group().value()) && "appcompat-v7".equals(dependency.name().value())) {
            dependency.setVersion("23.1.1");
            break;
        }
    }
    runWriteCommandAction(resolvedProject, buildModel::applyChanges);
    //noinspection ConstantConditions
    importProject(resolvedProject.getName(), new File(resolvedProject.getBasePath()), null);
    PsProject project = new PsProject(resolvedProject);
    PsAndroidModule module = (PsAndroidModule) project.findModuleByName("app");
    assertNotNull(module);
    List<PsAndroidDependency> declaredDependencies = getDeclaredDependencies(module);
    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 resolvedSpec = appCompatV7.getResolvedSpec();
    assertEquals("com.android.support", resolvedSpec.group);
    assertEquals("appcompat-v7", resolvedSpec.name);
    // 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(module.findVariant(variant));
    }
}
Also used : PsProject(com.android.tools.idea.gradle.structure.model.PsProject) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) Project(com.intellij.openapi.project.Project) PsProject(com.android.tools.idea.gradle.structure.model.PsProject) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) Module(com.intellij.openapi.module.Module) File(java.io.File)

Aggregations

PsProject (com.android.tools.idea.gradle.structure.model.PsProject)8 Project (com.intellij.openapi.project.Project)5 PsArtifactDependencySpec (com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)2 PsModule (com.android.tools.idea.gradle.structure.model.PsModule)2 PsAndroidModule (com.android.tools.idea.gradle.structure.model.android.PsAndroidModule)2 NotNull (org.jetbrains.annotations.NotNull)2 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)1 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)1 PsAllModulesFakeModule (com.android.tools.idea.gradle.structure.configurables.android.dependencies.PsAllModulesFakeModule)1 Module (com.intellij.openapi.module.Module)1 File (java.io.File)1