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());
}
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());
}
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();
}
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());
}
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();
}
Aggregations