use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class BuildTypeModelTest method testEditAndResetLiteralElements.
public void testEditAndResetLiteralElements() throws Exception {
String text = "android {\n" + " buildTypes {\n" + " xyz {\n" + " applicationIdSuffix \"mySuffix\"\n" + " debuggable true\n" + " embedMicroApp false\n" + " jniDebuggable true\n" + " minifyEnabled false\n" + " multiDexEnabled true\n" + " pseudoLocalesEnabled false\n" + " renderscriptDebuggable true\n" + " renderscriptOptimLevel 1\n" + " shrinkResources false\n" + " testCoverageEnabled true\n" + " useJack false\n" + " versionNameSuffix \"abc\"\n" + " zipAlignEnabled true\n" + " }\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
BuildTypeModel buildType = getXyzBuildType(buildModel);
assertEquals("applicationIdSuffix", "mySuffix", buildType.applicationIdSuffix());
assertEquals("debuggable", Boolean.TRUE, buildType.debuggable());
assertEquals("embedMicroApp", Boolean.FALSE, buildType.embedMicroApp());
assertEquals("jniDebuggable", Boolean.TRUE, buildType.jniDebuggable());
assertEquals("minifyEnabled", Boolean.FALSE, buildType.minifyEnabled());
assertEquals("multiDexEnabled", Boolean.TRUE, buildType.multiDexEnabled());
assertEquals("pseudoLocalesEnabled", Boolean.FALSE, buildType.pseudoLocalesEnabled());
assertEquals("renderscriptDebuggable", Boolean.TRUE, buildType.renderscriptDebuggable());
assertEquals("renderscriptOptimLevel", Integer.valueOf(1), buildType.renderscriptOptimLevel());
assertEquals("shrinkResources", Boolean.FALSE, buildType.shrinkResources());
assertEquals("testCoverageEnabled", Boolean.TRUE, buildType.testCoverageEnabled());
assertEquals("useJack", Boolean.FALSE, buildType.useJack());
assertEquals("versionNameSuffix", "abc", buildType.versionNameSuffix());
assertEquals("zipAlignEnabled", Boolean.TRUE, buildType.zipAlignEnabled());
buildType.setApplicationIdSuffix("mySuffix-1").setDebuggable(false).setEmbedMicroApp(true).setJniDebuggable(false).setMinifyEnabled(true).setMultiDexEnabled(false).setPseudoLocalesEnabled(true).setRenderscriptDebuggable(false).setRenderscriptOptimLevel(2).setShrinkResources(true).setTestCoverageEnabled(false).setUseJack(true).setVersionNameSuffix("def").setZipAlignEnabled(false);
assertEquals("applicationIdSuffix", "mySuffix-1", buildType.applicationIdSuffix());
assertEquals("debuggable", Boolean.FALSE, buildType.debuggable());
assertEquals("embedMicroApp", Boolean.TRUE, buildType.embedMicroApp());
assertEquals("jniDebuggable", Boolean.FALSE, buildType.jniDebuggable());
assertEquals("minifyEnabled", Boolean.TRUE, buildType.minifyEnabled());
assertEquals("multiDexEnabled", Boolean.FALSE, buildType.multiDexEnabled());
assertEquals("pseudoLocalesEnabled", Boolean.TRUE, buildType.pseudoLocalesEnabled());
assertEquals("renderscriptDebuggable", Boolean.FALSE, buildType.renderscriptDebuggable());
assertEquals("renderscriptOptimLevel", Integer.valueOf(2), buildType.renderscriptOptimLevel());
assertEquals("shrinkResources", Boolean.TRUE, buildType.shrinkResources());
assertEquals("testCoverageEnabled", Boolean.FALSE, buildType.testCoverageEnabled());
assertEquals("useJack", Boolean.TRUE, buildType.useJack());
assertEquals("versionNameSuffix", "def", buildType.versionNameSuffix());
assertEquals("zipAlignEnabled", Boolean.FALSE, buildType.zipAlignEnabled());
buildModel.resetState();
assertEquals("applicationIdSuffix", "mySuffix", buildType.applicationIdSuffix());
assertEquals("debuggable", Boolean.TRUE, buildType.debuggable());
assertEquals("embedMicroApp", Boolean.FALSE, buildType.embedMicroApp());
assertEquals("jniDebuggable", Boolean.TRUE, buildType.jniDebuggable());
assertEquals("minifyEnabled", Boolean.FALSE, buildType.minifyEnabled());
assertEquals("multiDexEnabled", Boolean.TRUE, buildType.multiDexEnabled());
assertEquals("pseudoLocalesEnabled", Boolean.FALSE, buildType.pseudoLocalesEnabled());
assertEquals("renderscriptDebuggable", Boolean.TRUE, buildType.renderscriptDebuggable());
assertEquals("renderscriptOptimLevel", Integer.valueOf(1), buildType.renderscriptOptimLevel());
assertEquals("shrinkResources", Boolean.FALSE, buildType.shrinkResources());
assertEquals("testCoverageEnabled", Boolean.TRUE, buildType.testCoverageEnabled());
assertEquals("useJack", Boolean.FALSE, buildType.useJack());
assertEquals("versionNameSuffix", "abc", buildType.versionNameSuffix());
assertEquals("zipAlignEnabled", Boolean.TRUE, buildType.zipAlignEnabled());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class BuildTypeModelTest method testAddToAndResetListElements.
public void testAddToAndResetListElements() throws Exception {
String text = "android {\n" + " buildTypes {\n" + " xyz {\n" + " buildConfigField \"abcd\", \"efgh\", \"ijkl\"\n" + " consumerProguardFiles 'proguard-android.txt', 'proguard-rules.pro'\n" + " proguardFiles 'proguard-android.txt', 'proguard-rules.pro'\n" + " resValue \"mnop\", \"qrst\", \"uvwx\"\n" + " }\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
BuildTypeModel buildType = getXyzBuildType(buildModel);
assertEquals("buildConfigFields", ImmutableList.of(new BuildConfigField("abcd", "efgh", "ijkl")), buildType.buildConfigFields());
assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), buildType.consumerProguardFiles());
assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), buildType.proguardFiles());
assertEquals("resValues", ImmutableList.of(new ResValue("mnop", "qrst", "uvwx")), buildType.resValues());
buildType.addBuildConfigField(new BuildConfigField("cdef", "ghij", "klmn")).addConsumerProguardFile("proguard-android-1.txt").addProguardFile("proguard-android-1.txt").addResValue(new ResValue("opqr", "stuv", "wxyz"));
assertEquals("buildConfigFields", ImmutableList.of(new BuildConfigField("abcd", "efgh", "ijkl"), new BuildConfigField("cdef", "ghij", "klmn")), buildType.buildConfigFields());
assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro", "proguard-android-1.txt"), buildType.consumerProguardFiles());
assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro", "proguard-android-1.txt"), buildType.proguardFiles());
assertEquals("resValues", ImmutableList.of(new ResValue("mnop", "qrst", "uvwx"), new ResValue("opqr", "stuv", "wxyz")), buildType.resValues());
buildModel.resetState();
assertEquals("buildConfigFields", ImmutableList.of(new BuildConfigField("abcd", "efgh", "ijkl")), buildType.buildConfigFields());
assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), buildType.consumerProguardFiles());
assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), buildType.proguardFiles());
assertEquals("resValues", ImmutableList.of(new ResValue("mnop", "qrst", "uvwx")), buildType.resValues());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class BuildTypeModelTest method testAddAndResetMapElements.
public void testAddAndResetMapElements() throws Exception {
String text = "android {\n" + " buildTypes {\n" + " xyz {\n" + " }\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
BuildTypeModel buildType = getXyzBuildType(buildModel);
assertNull("manifestPlaceholders", buildType.manifestPlaceholders());
buildType.setManifestPlaceholder("activityLabel1", "newName1");
buildType.setManifestPlaceholder("activityLabel2", "newName2");
assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel1", "newName1", "activityLabel2", "newName2"), buildType.manifestPlaceholders());
buildModel.resetState();
assertNull("manifestPlaceholders", buildType.manifestPlaceholders());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class AndroidModelTest method testRemoveAndApplyElements.
public void testRemoveAndApplyElements() throws Exception {
String text = "android { \n" + " buildToolsVersion \"23.0.0\"\n" + " compileSdkVersion \"23\"\n" + " defaultPublishConfig \"debug\"\n" + " flavorDimensions \"abi\", \"version\"\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("flavorDimensions", ImmutableList.of("abi", "version"), android.flavorDimensions());
assertEquals("generatePureSplits", Boolean.TRUE, android.generatePureSplits());
assertEquals("publishNonDefault", Boolean.FALSE, android.publishNonDefault());
assertEquals("resourcePrefix", "abcd", android.resourcePrefix());
android.removeBuildToolsVersion();
android.removeCompileSdkVersion();
android.removeDefaultPublishConfig();
android.removeAllFlavorDimensions();
android.removeGeneratePureSplits();
android.removePublishNonDefault();
android.removeResourcePrefix();
assertNull("buildToolsVersion", android.buildToolsVersion());
assertNull("compileSdkVersion", android.compileSdkVersion());
assertNull("defaultPublishConfig", android.defaultPublishConfig());
assertNull("flavorDimensions", android.flavorDimensions());
assertNull("generatePureSplits", android.generatePureSplits());
assertNull("publishNonDefault", android.publishNonDefault());
assertNull("resourcePrefix", android.resourcePrefix());
applyChanges(buildModel);
assertNull("buildToolsVersion", android.buildToolsVersion());
assertNull("compileSdkVersion", android.compileSdkVersion());
assertNull("defaultPublishConfig", android.defaultPublishConfig());
assertNull("flavorDimensions", android.flavorDimensions());
assertNull("generatePureSplits", android.generatePureSplits());
assertNull("publishNonDefault", android.publishNonDefault());
assertNull("resourcePrefix", android.resourcePrefix());
buildModel.reparse();
android = buildModel.android();
assertNotNull(android);
assertFalse(android.hasValidPsiElement());
}
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();
}
Aggregations