Search in sources :

Example 71 with GradleBuildModel

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

the class AndroidModelTest method testAddAndApplyEmptyBuildTypeBlock.

public void testAddAndApplyEmptyBuildTypeBlock() throws Exception {
    String text = "android { \n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    android.addBuildType("type");
    List<BuildTypeModel> buildTypes = android.buildTypes();
    assertThat(buildTypes).hasSize(1);
    assertEquals("buildTypes", "type", buildTypes.get(0).name());
    applyChanges(buildModel);
    // Empty blocks are not saved to the file.
    assertThat(android.buildTypes()).isEmpty();
    buildModel.reparse();
    android = buildModel.android();
    assertNotNull(android);
    // Empty blocks are not saved to the file.
    assertThat(android.buildTypes()).isEmpty();
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 72 with GradleBuildModel

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

the class AndroidModelTest method testRemoveAndApplyBlockApplicationStatements.

public void testRemoveAndApplyBlockApplicationStatements() throws Exception {
    String text = "android.defaultConfig.applicationId \"com.example.myapplication\"\n" + "android.defaultConfig.proguardFiles \"proguard-android.txt\", \"proguard-rules.pro\"";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    ProductFlavorModel defaultConfig = android.defaultConfig();
    assertEquals("applicationId", "com.example.myapplication", defaultConfig.applicationId());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.proguardFiles());
    defaultConfig.removeApplicationId();
    defaultConfig.removeAllProguardFiles();
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    defaultConfig = android.defaultConfig();
    assertNull(defaultConfig.applicationId());
    assertNull(defaultConfig.proguardFiles());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 73 with GradleBuildModel

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

the class AndroidModelTest method testAddToAndResetListElementsWithMultipleArguments.

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

Example 74 with GradleBuildModel

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

the class AndroidModelTest method testEditAndApplyIntegerLiteralElements.

public void testEditAndApplyIntegerLiteralElements() throws Exception {
    String text = "android { \n" + "  buildToolsVersion \"23.0.0\"\n" + "  compileSdkVersion \"23\"\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    assertEquals("buildToolsVersion", "23.0.0", android.buildToolsVersion());
    assertEquals("compileSdkVersion", "23", android.compileSdkVersion());
    android.setBuildToolsVersion(22).setCompileSdkVersion(21);
    assertEquals("buildToolsVersion", "22", android.buildToolsVersion());
    assertEquals("compileSdkVersion", "21", android.compileSdkVersion());
    applyChanges(buildModel);
    assertEquals("buildToolsVersion", "22", android.buildToolsVersion());
    assertEquals("compileSdkVersion", "21", android.compileSdkVersion());
    buildModel.reparse();
    android = buildModel.android();
    assertNotNull(android);
    assertEquals("buildToolsVersion", "22", android.buildToolsVersion());
    assertEquals("compileSdkVersion", "21", android.compileSdkVersion());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 75 with GradleBuildModel

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

the class AndroidModelTest method testAddToAndApplyListElementsWithMultipleArguments.

public void testAddToAndApplyListElementsWithMultipleArguments() throws Exception {
    String text = "android { \n" + "  flavorDimensions \"abi\", \"version\"\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    assertEquals("flavorDimensions", ImmutableList.of("abi", "version"), android.flavorDimensions());
    android.addFlavorDimension("xyz");
    assertEquals("flavorDimensions", ImmutableList.of("abi", "version", "xyz"), android.flavorDimensions());
    applyChanges(buildModel);
    assertEquals("flavorDimensions", ImmutableList.of("abi", "version", "xyz"), android.flavorDimensions());
    buildModel.reparse();
    android = buildModel.android();
    assertNotNull(android);
    assertEquals("flavorDimensions", ImmutableList.of("abi", "version", "xyz"), android.flavorDimensions());
}
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