Search in sources :

Example 81 with GradleBuildModel

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

the class AndroidModelTest method testRemoveAndResetProductFlavorBlock.

public void testRemoveAndResetProductFlavorBlock() throws Exception {
    String text = "android { \n" + "  productFlavors { \n" + "    flavor1 { \n" + "    } \n" + "    flavor2 {" + "    } \n" + "  } \n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    List<ProductFlavorModel> productFlavors = android.productFlavors();
    assertThat(productFlavors).hasSize(2);
    assertEquals("productFlavors", "flavor1", productFlavors.get(0).name());
    assertEquals("productFlavors", "flavor2", productFlavors.get(1).name());
    android.removeProductFlavor("flavor2");
    productFlavors = android.productFlavors();
    assertThat(productFlavors).hasSize(1);
    assertEquals("productFlavors", "flavor1", productFlavors.get(0).name());
    buildModel.resetState();
    productFlavors = android.productFlavors();
    assertThat(productFlavors).hasSize(2);
    assertEquals("productFlavors", "flavor1", productFlavors.get(0).name());
    assertEquals("productFlavors", "flavor2", productFlavors.get(1).name());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 82 with GradleBuildModel

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

the class AndroidModelTest method testAddToAndApplyListElementsWithOneArgument.

public void testAddToAndApplyListElementsWithOneArgument() throws Exception {
    String text = "android { \n" + "  flavorDimensions \"abi\"\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    assertEquals("flavorDimensions", ImmutableList.of("abi"), android.flavorDimensions());
    android.addFlavorDimension("version");
    assertEquals("flavorDimensions", ImmutableList.of("abi", "version"), android.flavorDimensions());
    applyChanges(buildModel);
    assertEquals("flavorDimensions", ImmutableList.of("abi", "version"), android.flavorDimensions());
    buildModel.reparse();
    android = buildModel.android();
    assertNotNull(android);
    assertEquals("flavorDimensions", ImmutableList.of("abi", "version"), android.flavorDimensions());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 83 with GradleBuildModel

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

the class BuildTypeModelTest method testRemoveFromAndApplyListElementsWithSingleElement.

public void testRemoveFromAndApplyListElementsWithSingleElement() throws Exception {
    String text = "android {\n" + "  buildTypes {\n" + "    xyz {\n" + "      consumerProguardFiles 'proguard-android.txt'\n" + "      proguardFiles = ['proguard-rules.pro']\n" + "    }\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    BuildTypeModel buildType = getXyzBuildType(buildModel);
    assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt"), buildType.consumerProguardFiles());
    assertEquals("proguardFiles", ImmutableList.of("proguard-rules.pro"), buildType.proguardFiles());
    buildType.removeConsumerProguardFile("proguard-android.txt").removeProguardFile("proguard-rules.pro");
    assertThat(buildType.consumerProguardFiles()).named("consumerProguardFiles").isEmpty();
    assertThat(buildType.proguardFiles()).named("proguardFiles").isEmpty();
    applyChanges(buildModel);
    assertThat(buildType.consumerProguardFiles()).named("consumerProguardFiles").isEmpty();
    assertThat(buildType.proguardFiles()).named("proguardFiles").isEmpty();
    buildModel.reparse();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    assertFalse(android.hasValidPsiElement());
    assertThat(android.buildTypes()).isEmpty();
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 84 with GradleBuildModel

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

the class AndroidModelTest method testEditAndResetLiteralElements.

public void testEditAndResetLiteralElements() throws Exception {
    String text = "android { \n" + "  buildToolsVersion \"23.0.0\"\n" + "  compileSdkVersion \"23\"\n" + "  defaultPublishConfig \"debug\"\n" + "  generatePureSplits true\n" + "  publishNonDefault false\n" + "  resourcePrefix \"abcd\"\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    assertEquals("buildToolsVersion", "23.0.0", android.buildToolsVersion());
    assertEquals("compileSdkVersion", "23", android.compileSdkVersion());
    assertEquals("defaultPublishConfig", "debug", android.defaultPublishConfig());
    assertEquals("generatePureSplits", Boolean.TRUE, android.generatePureSplits());
    assertEquals("publishNonDefault", Boolean.FALSE, android.publishNonDefault());
    assertEquals("resourcePrefix", "abcd", android.resourcePrefix());
    android.setBuildToolsVersion("24.0.0").setCompileSdkVersion("24").setDefaultPublishConfig("release").setGeneratePureSplits(false).setPublishNonDefault(true).setResourcePrefix("efgh");
    assertEquals("buildToolsVersion", "24.0.0", android.buildToolsVersion());
    assertEquals("compileSdkVersion", "24", android.compileSdkVersion());
    assertEquals("defaultPublishConfig", "release", android.defaultPublishConfig());
    assertEquals("generatePureSplits", Boolean.FALSE, android.generatePureSplits());
    assertEquals("publishNonDefault", Boolean.TRUE, android.publishNonDefault());
    assertEquals("resourcePrefix", "efgh", android.resourcePrefix());
    buildModel.resetState();
    assertEquals("buildToolsVersion", "23.0.0", android.buildToolsVersion());
    assertEquals("compileSdkVersion", "23", android.compileSdkVersion());
    assertEquals("defaultPublishConfig", "debug", android.defaultPublishConfig());
    assertEquals("generatePureSplits", Boolean.TRUE, android.generatePureSplits());
    assertEquals("publishNonDefault", Boolean.FALSE, android.publishNonDefault());
    assertEquals("resourcePrefix", "abcd", android.resourcePrefix());
    // Test the fields that also accept an integer value along with the String valye.
    android.setBuildToolsVersion(22).setCompileSdkVersion(21);
    assertEquals("buildToolsVersion", "22", android.buildToolsVersion());
    assertEquals("compileSdkVersion", "21", android.compileSdkVersion());
    buildModel.resetState();
    assertEquals("buildToolsVersion", "23.0.0", android.buildToolsVersion());
    assertEquals("compileSdkVersion", "23", android.compileSdkVersion());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 85 with GradleBuildModel

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

the class AndroidModelTest method testAddAndApplyEmptySigningConfigBlock.

public void testAddAndApplyEmptySigningConfigBlock() throws Exception {
    String text = "android { \n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    android.addSigningConfig("config");
    List<SigningConfigModel> signingConfigs = android.signingConfigs();
    assertThat(signingConfigs).hasSize(1);
    assertEquals("signingConfigs", "config", signingConfigs.get(0).name());
    applyChanges(buildModel);
    // Empty blocks are not saved to the file.
    assertThat(android.signingConfigs()).isEmpty();
    buildModel.reparse();
    android = buildModel.android();
    assertNotNull(android);
    // Empty blocks are not saved to the file.
    assertThat(android.signingConfigs()).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