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