Search in sources :

Example 91 with GradleBuildModel

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

the class SplitsModelTest method testEditElements.

public void testEditElements() throws Exception {
    writeToBuildFile(SPLITS_TEXT);
    verifySplitsValues();
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    SplitsModel splits = android.splits();
    AbiModel abi = splits.abi();
    abi.setEnable(false);
    abi.replaceExclude("abi-exclude-2", "abi-exclude-3");
    abi.replaceInclude("abi-include-2", "abi-include-3");
    abi.setUniversalApk(true);
    DensityModel density = splits.density();
    density.setAuto(true);
    density.replaceCompatibleScreen("screen2", "screen3");
    density.setEnable(false);
    density.replaceExclude("density-exclude-2", "density-exclude-3");
    density.replaceInclude("density-include-2", "density-include-3");
    LanguageModel language = splits.language();
    language.setEnable(true);
    language.replaceInclude("language-include-2", "language-include-3");
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    splits = android.splits();
    abi = splits.abi();
    assertEquals("enable", Boolean.FALSE, abi.enable());
    assertEquals("exclude", ImmutableList.of("abi-exclude-1", "abi-exclude-3"), abi.exclude());
    assertEquals("include", ImmutableList.of("abi-include-1", "abi-include-3"), abi.include());
    assertEquals("universalApk", Boolean.TRUE, abi.universalApk());
    density = splits.density();
    assertEquals("auto", Boolean.TRUE, density.auto());
    assertEquals("compatibleScreens", ImmutableList.of("screen1", "screen3"), density.compatibleScreens());
    assertEquals("enable", Boolean.FALSE, density.enable());
    assertEquals("exclude", ImmutableList.of("density-exclude-1", "density-exclude-3"), density.exclude());
    assertEquals("include", ImmutableList.of("density-include-1", "density-include-3"), density.include());
    language = splits.language();
    assertEquals("enable", Boolean.TRUE, language.enable());
    assertEquals("include", ImmutableList.of("language-include-1", "language-include-3"), 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 92 with GradleBuildModel

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

the class SplitsModelTest method testRemoveResetStatement.

public void testRemoveResetStatement() throws Exception {
    String text = "android {\n" + "  splits {\n" + "    abi {\n" + "      include 'abi-include-1', 'abi-include-2'\n" + "      reset()\n" + "    }\n" + "    density {\n" + "      include 'density-include-1', 'density-include-2'\n" + "      reset()\n" + "    }\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    SplitsModel splits = android.splits();
    assertNull("abi-include", splits.abi().include());
    assertNull("density-include", splits.density().include());
    splits.abi().removeReset();
    splits.density().removeReset();
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    splits = android.splits();
    assertEquals("abi-include", ImmutableList.of("abi-include-1", "abi-include-2"), splits.abi().include());
    assertEquals("density-include", ImmutableList.of("density-include-1", "density-include-2"), splits.density().include());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 93 with GradleBuildModel

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

the class ProductFlavorModelTest method testAddNativeElements.

public void testAddNativeElements() throws Exception {
    String text = "android {\n" + "  defaultConfig {\n" + "  }\n" + "}";
    writeToBuildFile(text);
    verifyNullNativeElements();
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    ProductFlavorModel defaultConfig = android.defaultConfig();
    ExternalNativeBuildOptionsModel externalNativeBuild = defaultConfig.externalNativeBuild();
    CMakeOptionsModel cmake = externalNativeBuild.cmake();
    cmake.addAbiFilter("abiFilterX").addArgument("argumentX").addCFlag("cFlagX").addCppFlag("cppFlagX").addTarget("targetX");
    NdkBuildOptionsModel ndkBuild = externalNativeBuild.ndkBuild();
    ndkBuild.addAbiFilter("abiFilterY").addArgument("argumentY").addCFlag("cFlagY").addCppFlag("cppFlagY").addTarget("targetY");
    NdkOptionsModel ndk = defaultConfig.ndk();
    ndk.addAbiFilter("abiFilterZ");
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    defaultConfig = android.defaultConfig();
    externalNativeBuild = defaultConfig.externalNativeBuild();
    cmake = externalNativeBuild.cmake();
    assertEquals("cmake-abiFilters", ImmutableList.of("abiFilterX"), cmake.abiFilters());
    assertEquals("cmake-arguments", ImmutableList.of("argumentX"), cmake.arguments());
    assertEquals("cmake-cFlags", ImmutableList.of("cFlagX"), cmake.cFlags());
    assertEquals("cmake-cppFlags", ImmutableList.of("cppFlagX"), cmake.cppFlags());
    assertEquals("cmake-targets", ImmutableList.of("targetX"), cmake.targets());
    ndkBuild = externalNativeBuild.ndkBuild();
    assertEquals("ndkBuild-abiFilters", ImmutableList.of("abiFilterY"), ndkBuild.abiFilters());
    assertEquals("ndkBuild-arguments", ImmutableList.of("argumentY"), ndkBuild.arguments());
    assertEquals("ndkBuild-cFlags", ImmutableList.of("cFlagY"), ndkBuild.cFlags());
    assertEquals("ndkBuild-cppFlags", ImmutableList.of("cppFlagY"), ndkBuild.cppFlags());
    assertEquals("ndkBuild-targets", ImmutableList.of("targetY"), ndkBuild.targets());
    ndk = defaultConfig.ndk();
    assertEquals("ndk-abiFilters", ImmutableList.of("abiFilterZ"), ndk.abiFilters());
}
Also used : ExternalNativeBuildOptionsModel(com.android.tools.idea.gradle.dsl.model.android.productFlavors.ExternalNativeBuildOptionsModel) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) NdkBuildOptionsModel(com.android.tools.idea.gradle.dsl.model.android.productFlavors.externalNativeBuild.NdkBuildOptionsModel) CMakeOptionsModel(com.android.tools.idea.gradle.dsl.model.android.productFlavors.externalNativeBuild.CMakeOptionsModel) NdkOptionsModel(com.android.tools.idea.gradle.dsl.model.android.productFlavors.NdkOptionsModel)

Example 94 with GradleBuildModel

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

the class ProductFlavorModelTest method testAddToAndApplyListElements.

public void testAddToAndApplyListElements() throws Exception {
    String text = "android {\n" + "  defaultConfig {\n" + "    consumerProguardFiles 'proguard-android.txt', 'proguard-rules.pro'\n" + "    proguardFiles 'proguard-android.txt', 'proguard-rules.pro'\n" + "    resConfigs \"abcd\", \"efgh\"\n" + "    resValue \"abcd\", \"efgh\", \"ijkl\"\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    ProductFlavorModel defaultConfig = android.defaultConfig();
    assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.consumerProguardFiles());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.proguardFiles());
    assertEquals("resConfigs", ImmutableList.of("abcd", "efgh"), defaultConfig.resConfigs());
    assertEquals("resValues", ImmutableList.of(new ResValue("abcd", "efgh", "ijkl")), defaultConfig.resValues());
    defaultConfig.addConsumerProguardFile("proguard-android-1.txt").addProguardFile("proguard-android-1.txt").addResConfig("xyz").addResValue(new ResValue("mnop", "qrst", "uvwx"));
    assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro", "proguard-android-1.txt"), defaultConfig.consumerProguardFiles());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro", "proguard-android-1.txt"), defaultConfig.proguardFiles());
    assertEquals("resConfigs", ImmutableList.of("abcd", "efgh", "xyz"), defaultConfig.resConfigs());
    assertEquals("resValues", ImmutableList.of(new ResValue("abcd", "efgh", "ijkl"), new ResValue("mnop", "qrst", "uvwx")), defaultConfig.resValues());
    applyChanges(buildModel);
    assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro", "proguard-android-1.txt"), defaultConfig.consumerProguardFiles());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro", "proguard-android-1.txt"), defaultConfig.proguardFiles());
    assertEquals("resConfigs", ImmutableList.of("abcd", "efgh", "xyz"), defaultConfig.resConfigs());
    assertEquals("resValues", ImmutableList.of(new ResValue("abcd", "efgh", "ijkl"), new ResValue("mnop", "qrst", "uvwx")), defaultConfig.resValues());
    buildModel.reparse();
    android = buildModel.android();
    assertNotNull(android);
    defaultConfig = android.defaultConfig();
    assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro", "proguard-android-1.txt"), defaultConfig.consumerProguardFiles());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro", "proguard-android-1.txt"), defaultConfig.proguardFiles());
    assertEquals("resConfigs", ImmutableList.of("abcd", "efgh", "xyz"), defaultConfig.resConfigs());
    assertEquals("resValues", ImmutableList.of(new ResValue("abcd", "efgh", "ijkl"), new ResValue("mnop", "qrst", "uvwx")), defaultConfig.resValues());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ResValue(com.android.tools.idea.gradle.dsl.model.android.AbstractFlavorTypeModel.ResValue)

Example 95 with GradleBuildModel

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

the class ArtifactDependencyTest method testAddDependency.

public void testAddDependency() throws IOException {
    String text = "dependencies {\n" + "    runtime group: 'org.gradle.test.classifiers', name: 'service', version: '1.0', classifier: 'jdk14', ext: 'jar'\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    DependenciesModel dependenciesModel = buildModel.dependencies();
    ArtifactDependencySpec newDependency = new ArtifactDependencySpec("appcompat-v7", "com.android.support", "22.1.1");
    dependenciesModel.addArtifact(COMPILE, newDependency);
    assertTrue(buildModel.isModified());
    applyChangesAndReparse(buildModel);
    List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
    assertThat(dependencies).hasSize(2);
    ExpectedArtifactDependency expected = new ExpectedArtifactDependency(RUNTIME, "service", "org.gradle.test.classifiers", "1.0");
    expected.classifier = "jdk14";
    expected.extension = "jar";
    expected.assertMatches(dependencies.get(0));
    expected = new ExpectedArtifactDependency(COMPILE, "appcompat-v7", "com.android.support", "22.1.1");
    expected.assertMatches(dependencies.get(1));
}
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