Search in sources :

Example 1 with GradleBuildModel

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

the class SplitsModelTest method testRemoveOneOfElementsInTheList.

public void testRemoveOneOfElementsInTheList() throws Exception {
    String text = "android {\n" + "  splits {\n" + "    abi {\n" + "      exclude 'abi-exclude-1', 'abi-exclude-2'\n" + "      include 'abi-include-1', 'abi-include-2'\n" + "    }\n" + "    density {\n" + "      compatibleScreens 'screen1', 'screen2'\n" + "      exclude 'density-exclude-1', 'density-exclude-2'\n" + "      include 'density-include-1', 'density-include-2'\n" + "    }\n" + "    language {\n" + "      include 'language-include-1', 'language-include-2'\n" + "    }\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    SplitsModel splits = android.splits();
    AbiModel abi = splits.abi();
    assertEquals("exclude", ImmutableList.of("abi-exclude-1", "abi-exclude-2"), abi.exclude());
    assertEquals("include", ImmutableList.of("abi-include-1", "abi-include-2"), abi.include());
    DensityModel density = splits.density();
    assertEquals("compatibleScreens", ImmutableList.of("screen1", "screen2"), density.compatibleScreens());
    assertEquals("exclude", ImmutableList.of("density-exclude-1", "density-exclude-2"), density.exclude());
    assertEquals("include", ImmutableList.of("density-include-1", "density-include-2"), density.include());
    LanguageModel language = splits.language();
    assertEquals("include", ImmutableList.of("language-include-1", "language-include-2"), language.include());
    abi.removeExclude("abi-exclude-1");
    abi.removeInclude("abi-include-2");
    density.removeCompatibleScreen("screen1");
    density.removeExclude("density-exclude-2");
    density.removeInclude("density-include-1");
    language.removeInclude("language-include-2");
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    splits = android.splits();
    abi = splits.abi();
    assertEquals("exclude", ImmutableList.of("abi-exclude-2"), abi.exclude());
    assertEquals("include", ImmutableList.of("abi-include-1"), abi.include());
    density = splits.density();
    assertEquals("compatibleScreens", ImmutableList.of("screen2"), density.compatibleScreens());
    assertEquals("exclude", ImmutableList.of("density-exclude-1"), density.exclude());
    assertEquals("include", ImmutableList.of("density-include-2"), density.include());
    language = splits.language();
    assertEquals("include", ImmutableList.of("language-include-1"), language.include());
}
Also used : DensityModel(com.android.tools.idea.gradle.dsl.model.android.splits.DensityModel) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) LanguageModel(com.android.tools.idea.gradle.dsl.model.android.splits.LanguageModel) AbiModel(com.android.tools.idea.gradle.dsl.model.android.splits.AbiModel)

Example 2 with GradleBuildModel

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

the class SplitsModelTest method testRemoveOnlyElementsInTheList.

public void testRemoveOnlyElementsInTheList() throws Exception {
    String text = "android {\n" + "  splits {\n" + "    abi {\n" + "      exclude 'abi-exclude'\n" + "      include 'abi-include'\n" + "    }\n" + "    density {\n" + "      compatibleScreens 'screen'\n" + "      exclude 'density-exclude'\n" + "      include 'density-include'\n" + "    }\n" + "    language {\n" + "      include 'language-include'\n" + "    }\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    SplitsModel splits = android.splits();
    assertTrue(splits.hasValidPsiElement());
    AbiModel abi = splits.abi();
    assertTrue(splits.hasValidPsiElement());
    assertEquals("exclude", ImmutableList.of("abi-exclude"), abi.exclude());
    assertEquals("include", ImmutableList.of("abi-include"), abi.include());
    DensityModel density = splits.density();
    assertTrue(density.hasValidPsiElement());
    assertEquals("compatibleScreens", ImmutableList.of("screen"), density.compatibleScreens());
    assertEquals("exclude", ImmutableList.of("density-exclude"), density.exclude());
    assertEquals("include", ImmutableList.of("density-include"), density.include());
    LanguageModel language = splits.language();
    assertTrue(language.hasValidPsiElement());
    assertEquals("include", ImmutableList.of("language-include"), language.include());
    abi.removeExclude("abi-exclude");
    abi.removeInclude("abi-include");
    density.removeCompatibleScreen("screen");
    density.removeExclude("density-exclude");
    density.removeInclude("density-include");
    language.removeInclude("language-include");
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    splits = android.splits();
    abi = splits.abi();
    assertNull("exclude", abi.exclude());
    assertNull("include", abi.include());
    assertFalse(abi.hasValidPsiElement());
    density = splits.density();
    assertNull("compatibleScreens", density.compatibleScreens());
    assertNull("exclude", density.exclude());
    assertNull("include", density.include());
    language = splits.language();
    assertNull("include", language.include());
    assertFalse(language.hasValidPsiElement());
    assertFalse(splits.hasValidPsiElement());
}
Also used : DensityModel(com.android.tools.idea.gradle.dsl.model.android.splits.DensityModel) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) LanguageModel(com.android.tools.idea.gradle.dsl.model.android.splits.LanguageModel) AbiModel(com.android.tools.idea.gradle.dsl.model.android.splits.AbiModel)

Example 3 with GradleBuildModel

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

the class SourceSetModelTest method testSetRootEditAndReset.

public void testSetRootEditAndReset() throws Exception {
    String text = "android {\n" + "  sourceSets {\n" + "    set1 {\n" + "      root = \"source1\"\n" + "    }\n" + "    set2.root \"source2\"\n" + "  }\n" + "  sourceSets.set3.setRoot \"source3\"\n" + "}\n" + "android.sourceSets.set4.setRoot(\"source4\")";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    verifySourceSetRoot(buildModel, "source");
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    List<SourceSetModel> sourceSets = android.sourceSets();
    sourceSets.get(0).setRoot("newRoot1");
    sourceSets.get(1).setRoot("newRoot2");
    sourceSets.get(2).setRoot("newRoot3");
    sourceSets.get(3).setRoot("newRoot4");
    verifySourceSetRoot(buildModel, "newRoot");
    buildModel.resetState();
    verifySourceSetRoot(buildModel, "source");
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 4 with GradleBuildModel

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

the class SourceSetModelTest method testSetRootRemoveAndReset.

public void testSetRootRemoveAndReset() throws Exception {
    String text = "android {\n" + "  sourceSets {\n" + "    set1 {\n" + "      root = \"source1\"\n" + "    }\n" + "    set2.root \"source2\"\n" + "  }\n" + "  sourceSets.set3.setRoot \"source3\"\n" + "}\n" + "android.sourceSets.set4.setRoot(\"source4\")";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    verifySourceSetRoot(buildModel, "source");
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    for (SourceSetModel sourceSet : android.sourceSets()) {
        sourceSet.removeRoot();
    }
    for (SourceSetModel sourceSet : android.sourceSets()) {
        assertNull("root", sourceSet.root());
    }
    buildModel.resetState();
    verifySourceSetRoot(buildModel, "source");
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 5 with GradleBuildModel

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

the class SourceSetModelTest method testSetRootRemoveAndApply.

public void testSetRootRemoveAndApply() throws Exception {
    String text = "android {\n" + "  sourceSets {\n" + "    set1 {\n" + "      root = \"source1\"\n" + "    }\n" + "    set2.root \"source2\"\n" + "  }\n" + "  sourceSets.set3.setRoot \"source3\"\n" + "}\n" + "android.sourceSets.set4.setRoot(\"source4\")";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    verifySourceSetRoot(buildModel, "source");
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    assertTrue(android.hasValidPsiElement());
    for (SourceSetModel sourceSet : android.sourceSets()) {
        sourceSet.removeRoot();
    }
    for (SourceSetModel sourceSet : android.sourceSets()) {
        assertNull("root", sourceSet.root());
    }
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    // the whole android block is deleted from the file.
    assertFalse(android.hasValidPsiElement());
    assertThat(android.sourceSets()).isEmpty();
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

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