Search in sources :

Example 51 with GradleBuildModel

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

the class AdbOptionsModelTest method testRemoveOnlyElementInTheList.

public void testRemoveOnlyElementInTheList() throws Exception {
    String text = "android {\n" + "  adbOptions {\n" + "    installOptions 'abcd'\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    AdbOptionsModel adbOptions = android.adbOptions();
    assertTrue(adbOptions.hasValidPsiElement());
    assertEquals("installOptions", ImmutableList.of("abcd"), adbOptions.installOptions());
    adbOptions.removeInstallOption("abcd");
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    adbOptions = android.adbOptions();
    assertFalse(adbOptions.hasValidPsiElement());
    assertNull("installOptions", adbOptions.installOptions());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 52 with GradleBuildModel

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

the class AdbOptionsModelTest method testEditElements.

public void testEditElements() throws Exception {
    String text = "android {\n" + "  adbOptions {\n" + "    installOptions 'abcd', 'efgh'\n" + "    timeOutInMs = 200\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    AdbOptionsModel adbOptions = android.adbOptions();
    assertEquals("installOptions", ImmutableList.of("abcd", "efgh"), adbOptions.installOptions());
    assertEquals("timeOutInMs", Integer.valueOf(200), adbOptions.timeOutInMs());
    adbOptions.replaceInstallOption("efgh", "xyz").setTimeOutInMs(300);
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    adbOptions = android.adbOptions();
    assertEquals("installOptions", ImmutableList.of("abcd", "xyz"), adbOptions.installOptions());
    assertEquals("timeOutInMs", Integer.valueOf(300), adbOptions.timeOutInMs());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 53 with GradleBuildModel

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

the class AaptOptionsModelTest method testRemoveElements.

public void testRemoveElements() throws Exception {
    String text = "android {\n" + "  aaptOptions {\n" + "    additionalParameters 'abcd', 'efgh'\n" + "    cruncherEnabled true\n" + "    cruncherProcesses 1\n" + "    failOnMissingConfigEntry false\n" + "    ignoreAssets 'efgh'\n" + "    noCompress 'a'\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    AaptOptionsModel aaptOptions = android.aaptOptions();
    assertTrue(aaptOptions.hasValidPsiElement());
    assertEquals("additionalParameters", ImmutableList.of("abcd", "efgh"), aaptOptions.additionalParameters());
    assertEquals("cruncherEnabled", Boolean.TRUE, aaptOptions.cruncherEnabled());
    assertEquals("cruncherProcesses", Integer.valueOf(1), aaptOptions.cruncherProcesses());
    assertEquals("failOnMissingConfigEntry", Boolean.FALSE, aaptOptions.failOnMissingConfigEntry());
    assertEquals("ignoreAssets", "efgh", aaptOptions.ignoreAssets());
    assertEquals("noCompress", ImmutableList.of("a"), aaptOptions.noCompress());
    aaptOptions.removeAllAdditionalParameters().removeCruncherEnabled().removeCruncherProcesses().removeFailOnMissingConfigEntry().removeIgnoreAssets().removeAllNoCompress();
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    aaptOptions = android.aaptOptions();
    assertFalse(aaptOptions.hasValidPsiElement());
    assertNull("additionalParameters", aaptOptions.additionalParameters());
    assertNull("cruncherEnabled", aaptOptions.cruncherEnabled());
    assertNull("cruncherProcesses", aaptOptions.cruncherProcesses());
    assertNull("failOnMissingConfigEntry", aaptOptions.failOnMissingConfigEntry());
    assertNull("ignoreAssets", aaptOptions.ignoreAssets());
    assertNull("noCompress", aaptOptions.noCompress());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 54 with GradleBuildModel

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

the class AaptOptionsModelTest method testRemoveOneOfElementsInTheList.

public void testRemoveOneOfElementsInTheList() throws Exception {
    String text = "android {\n" + "  aaptOptions {\n" + "    additionalParameters 'abcd', 'efgh'\n" + "    noCompress 'a', 'b'\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    AaptOptionsModel aaptOptions = android.aaptOptions();
    assertEquals("additionalParameters", ImmutableList.of("abcd", "efgh"), aaptOptions.additionalParameters());
    assertEquals("noCompress", ImmutableList.of("a", "b"), aaptOptions.noCompress());
    aaptOptions.removeAdditionalParameter("abcd");
    aaptOptions.removeNoCompress("b");
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    aaptOptions = android.aaptOptions();
    assertEquals("additionalParameters", ImmutableList.of("efgh"), aaptOptions.additionalParameters());
    assertEquals("noCompress", ImmutableList.of("a"), aaptOptions.noCompress());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 55 with GradleBuildModel

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

the class GradleDependencyManager method findMissingDependencies.

/**
   * Returns the dependencies that are NOT included in the specified module.
   * Note: the version of the dependency is disregarded.
   *
   * @param module the module to check dependencies in
   * @param dependencies the dependencies of interest.
   * @return a list of the dependencies NOT included in the module
   */
@NotNull
public List<GradleCoordinate> findMissingDependencies(@NotNull Module module, @NotNull Iterable<GradleCoordinate> dependencies) {
    AndroidModuleModel gradleModel = AndroidModuleModel.get(module);
    GradleBuildModel buildModel = GradleBuildModel.get(module);
    if (gradleModel == null && buildModel == null) {
        return Collections.emptyList();
    }
    RepositoryUrlManager manager = RepositoryUrlManager.get();
    List<GradleCoordinate> missingLibraries = Lists.newArrayList();
    for (GradleCoordinate coordinate : dependencies) {
        GradleCoordinate resolvedCoordinate = manager.resolveDynamicCoordinate(coordinate, null);
        if (resolvedCoordinate == null) {
            // We don't have anything installed, but we can keep trying with the unresolved coordinate if we have enough info
            if (coordinate.getArtifactId() == null || coordinate.getGroupId() == null) {
                // TODO Should this be an error ?
                continue;
            }
        } else {
            coordinate = resolvedCoordinate;
        }
        boolean dependencyFound = false;
        // First look in the model returned by Gradle.
        if (gradleModel != null && GradleUtil.dependsOn(gradleModel, String.format("%s:%s", coordinate.getGroupId(), coordinate.getArtifactId()))) {
            // GradleUtil.dependsOn method only checks the android library dependencies.
            // TODO: Consider updating it to also check for java library dependencies.
            dependencyFound = true;
        } else if (buildModel != null) {
            // Now, check in the model obtained from the gradle files.
            for (ArtifactDependencyModel dependency : buildModel.dependencies().artifacts(COMPILE)) {
                if (Objects.equal(coordinate.getGroupId(), dependency.group().value()) && Objects.equal(coordinate.getArtifactId(), dependency.name().value())) {
                    dependencyFound = true;
                    break;
                }
            }
        }
        if (!dependencyFound) {
            missingLibraries.add(coordinate);
        }
    }
    return missingLibraries;
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) RepositoryUrlManager(com.android.tools.idea.templates.RepositoryUrlManager) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)285 ResValue (com.android.tools.idea.gradle.dsl.model.android.AbstractFlavorTypeModel.ResValue)20 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)17 SigningConfigPassword (com.android.tools.idea.gradle.dsl.model.android.SigningConfigModel.SigningConfigPassword)15 AndroidModel (com.android.tools.idea.gradle.dsl.model.android.AndroidModel)13 DependenciesModel (com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel)13 File (java.io.File)13 Project (com.intellij.openapi.project.Project)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 BuildConfigField (com.android.tools.idea.gradle.dsl.model.android.BuildTypeModel.BuildConfigField)10 Module (com.intellij.openapi.module.Module)9 ProductFlavorModel (com.android.tools.idea.gradle.dsl.model.android.ProductFlavorModel)8 SourceDirectoryModel (com.android.tools.idea.gradle.dsl.model.android.sourceSets.SourceDirectoryModel)8 Result (com.intellij.openapi.application.Result)8 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)8 GradleNotNullValue (com.android.tools.idea.gradle.dsl.model.values.GradleNotNullValue)7 ExternalNativeBuildOptionsModel (com.android.tools.idea.gradle.dsl.model.android.productFlavors.ExternalNativeBuildOptionsModel)6 NotNull (org.jetbrains.annotations.NotNull)6 NdkOptionsModel (com.android.tools.idea.gradle.dsl.model.android.productFlavors.NdkOptionsModel)5 CMakeOptionsModel (com.android.tools.idea.gradle.dsl.model.android.productFlavors.externalNativeBuild.CMakeOptionsModel)5