use of com.android.tools.idea.gradle.dsl.model.android.AbstractFlavorTypeModel.ResValue in project android by JetBrains.
the class BuildTypeModelTest method testAddAndResetListElements.
public void testAddAndResetListElements() throws Exception {
String text = "android {\n" + " buildTypes {\n" + " xyz {\n" + " }\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
BuildTypeModel buildType = getXyzBuildType(buildModel);
assertNull("buildConfigFields", buildType.buildConfigFields());
assertNull("consumerProguardFiles", buildType.consumerProguardFiles());
assertNull("proguardFiles", buildType.proguardFiles());
assertNull("resValues", buildType.resValues());
buildType.addBuildConfigField(new BuildConfigField("abcd", "efgh", "ijkl")).addConsumerProguardFile("proguard-android.txt").addProguardFile("proguard-android.txt").addResValue(new ResValue("mnop", "qrst", "uvwx"));
assertEquals("buildConfigFields", ImmutableList.of(new BuildConfigField("abcd", "efgh", "ijkl")), buildType.buildConfigFields());
assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt"), buildType.consumerProguardFiles());
assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt"), buildType.proguardFiles());
assertEquals("resValues", ImmutableList.of(new ResValue("mnop", "qrst", "uvwx")), buildType.resValues());
buildModel.resetState();
assertNull("buildConfigFields", buildType.buildConfigFields());
assertNull("consumerProguardFiles", buildType.consumerProguardFiles());
assertNull("proguardFiles", buildType.proguardFiles());
assertNull("resValues", buildType.resValues());
}
use of com.android.tools.idea.gradle.dsl.model.android.AbstractFlavorTypeModel.ResValue in project android by JetBrains.
the class BuildTypeModelTest method testReplaceAndApplyListElements.
public void testReplaceAndApplyListElements() 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.replaceBuildConfigField(new BuildConfigField("abcd", "efgh", "ijkl"), new BuildConfigField("abcd", "mnop", "qrst")).replaceConsumerProguardFile("proguard-android.txt", "proguard-android-1.txt").replaceProguardFile("proguard-android.txt", "proguard-android-1.txt").replaceResValue(new ResValue("mnop", "qrst", "uvwx"), new ResValue("mnop", "efgh", "ijkl"));
assertEquals("buildConfigFields", ImmutableList.of(new BuildConfigField("abcd", "mnop", "qrst")), buildType.buildConfigFields());
assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android-1.txt", "proguard-rules.pro"), buildType.consumerProguardFiles());
assertEquals("proguardFiles", ImmutableList.of("proguard-android-1.txt", "proguard-rules.pro"), buildType.proguardFiles());
assertEquals("resValues", ImmutableList.of(new ResValue("mnop", "efgh", "ijkl")), buildType.resValues());
applyChanges(buildModel);
assertEquals("buildConfigFields", ImmutableList.of(new BuildConfigField("abcd", "mnop", "qrst")), buildType.buildConfigFields());
assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android-1.txt", "proguard-rules.pro"), buildType.consumerProguardFiles());
assertEquals("proguardFiles", ImmutableList.of("proguard-android-1.txt", "proguard-rules.pro"), buildType.proguardFiles());
assertEquals("resValues", ImmutableList.of(new ResValue("mnop", "efgh", "ijkl")), buildType.resValues());
buildModel.reparse();
buildType = getXyzBuildType(buildModel);
assertEquals("buildConfigFields", ImmutableList.of(new BuildConfigField("abcd", "mnop", "qrst")), buildType.buildConfigFields());
assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android-1.txt", "proguard-rules.pro"), buildType.consumerProguardFiles());
assertEquals("proguardFiles", ImmutableList.of("proguard-android-1.txt", "proguard-rules.pro"), buildType.proguardFiles());
assertEquals("resValues", ImmutableList.of(new ResValue("mnop", "efgh", "ijkl")), buildType.resValues());
}
use of com.android.tools.idea.gradle.dsl.model.android.AbstractFlavorTypeModel.ResValue in project android by JetBrains.
the class BuildTypeModelTest method testRemoveAndApplyElements.
public void testRemoveAndApplyElements() throws Exception {
String text = "android {\n" + " buildTypes {\n" + " xyz {\n" + " applicationIdSuffix \"mySuffix\"\n" + " buildConfigField \"abcd\", \"efgh\", \"ijkl\"\n" + " consumerProguardFiles 'proguard-android.txt', 'proguard-rules.pro'\n" + " debuggable true\n" + " embedMicroApp true\n" + " jniDebuggable true\n" + " manifestPlaceholders activityLabel1:\"defaultName1\", activityLabel2:\"defaultName2\"\n" + " minifyEnabled true\n" + " multiDexEnabled true\n" + " proguardFiles 'proguard-android.txt', 'proguard-rules.pro'\n" + " pseudoLocalesEnabled true\n" + " renderscriptDebuggable true\n" + " renderscriptOptimLevel 1\n" + " resValue \"mnop\", \"qrst\", \"uvwx\"\n" + " shrinkResources true\n" + " testCoverageEnabled true\n" + " useJack true\n" + " versionNameSuffix \"abc\"\n" + " zipAlignEnabled true\n" + " }\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
AndroidModel android = buildModel.android();
assertNotNull(android);
assertTrue(android.hasValidPsiElement());
BuildTypeModel buildType = getXyzBuildType(buildModel);
assertTrue(buildType.hasValidPsiElement());
assertEquals("applicationIdSuffix", "mySuffix", buildType.applicationIdSuffix());
assertEquals("buildConfigFields", ImmutableList.of(new BuildConfigField("abcd", "efgh", "ijkl")), buildType.buildConfigFields());
assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), buildType.consumerProguardFiles());
assertEquals("debuggable", Boolean.TRUE, buildType.debuggable());
assertEquals("embedMicroApp", Boolean.TRUE, buildType.embedMicroApp());
assertEquals("jniDebuggable", Boolean.TRUE, buildType.jniDebuggable());
assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel1", "defaultName1", "activityLabel2", "defaultName2"), buildType.manifestPlaceholders());
assertEquals("minifyEnabled", Boolean.TRUE, buildType.minifyEnabled());
assertEquals("multiDexEnabled", Boolean.TRUE, buildType.multiDexEnabled());
assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), buildType.proguardFiles());
assertEquals("pseudoLocalesEnabled", Boolean.TRUE, buildType.pseudoLocalesEnabled());
assertEquals("renderscriptDebuggable", Boolean.TRUE, buildType.renderscriptDebuggable());
assertEquals("renderscriptOptimLevel", Integer.valueOf(1), buildType.renderscriptOptimLevel());
assertEquals("resValues", ImmutableList.of(new ResValue("mnop", "qrst", "uvwx")), buildType.resValues());
assertEquals("shrinkResources", Boolean.TRUE, buildType.shrinkResources());
assertEquals("testCoverageEnabled", Boolean.TRUE, buildType.testCoverageEnabled());
assertEquals("useJack", Boolean.TRUE, buildType.useJack());
assertEquals("versionNameSuffix", "abc", buildType.versionNameSuffix());
assertEquals("zipAlignEnabled", Boolean.TRUE, buildType.zipAlignEnabled());
// Remove all the properties except the applicationIdSuffix.
buildType.removeAllBuildConfigFields().removeAllConsumerProguardFiles().removeDebuggable().removeEmbedMicroApp().removeJniDebuggable().removeAllManifestPlaceholders().removeMinifyEnabled().removeMultiDexEnabled().removeAllProguardFiles().removePseudoLocalesEnabled().removeRenderscriptDebuggable().removeRenderscriptOptimLevel().removeAllResValues().removeShrinkResources().removeTestCoverageEnabled().removeUseJack().removeVersionNameSuffix().removeZipAlignEnabled();
assertTrue(android.hasValidPsiElement());
assertTrue(buildType.hasValidPsiElement());
assertEquals("applicationIdSuffix", "mySuffix", buildType.applicationIdSuffix());
assertNull("buildConfigFields", buildType.buildConfigFields());
assertNull("consumerProguardFiles", buildType.consumerProguardFiles());
assertNull("debuggable", buildType.debuggable());
assertNull("embedMicroApp", buildType.embedMicroApp());
assertNull("jniDebuggable", buildType.jniDebuggable());
assertNull("manifestPlaceholders", buildType.manifestPlaceholders());
assertNull("minifyEnabled", buildType.minifyEnabled());
assertNull("multiDexEnabled", buildType.multiDexEnabled());
assertNull("proguardFiles", buildType.proguardFiles());
assertNull("pseudoLocalesEnabled", buildType.pseudoLocalesEnabled());
assertNull("renderscriptDebuggable", buildType.renderscriptDebuggable());
assertNull("renderscriptOptimLevel", buildType.renderscriptOptimLevel());
assertNull("resValues", buildType.resValues());
assertNull("shrinkResources", buildType.shrinkResources());
assertNull("testCoverageEnabled", buildType.testCoverageEnabled());
assertNull("useJack", buildType.useJack());
assertNull("versionNameSuffix", buildType.versionNameSuffix());
assertNull("zipAlignEnabled", buildType.zipAlignEnabled());
applyChanges(buildModel);
assertTrue(android.hasValidPsiElement());
assertTrue(buildType.hasValidPsiElement());
assertEquals("applicationIdSuffix", "mySuffix", buildType.applicationIdSuffix());
assertNull("buildConfigFields", buildType.buildConfigFields());
assertNull("consumerProguardFiles", buildType.consumerProguardFiles());
assertNull("debuggable", buildType.debuggable());
assertNull("embedMicroApp", buildType.embedMicroApp());
assertNull("jniDebuggable", buildType.jniDebuggable());
assertNull("manifestPlaceholders", buildType.manifestPlaceholders());
assertNull("minifyEnabled", buildType.minifyEnabled());
assertNull("multiDexEnabled", buildType.multiDexEnabled());
assertNull("proguardFiles", buildType.proguardFiles());
assertNull("pseudoLocalesEnabled", buildType.pseudoLocalesEnabled());
assertNull("renderscriptDebuggable", buildType.renderscriptDebuggable());
assertNull("renderscriptOptimLevel", buildType.renderscriptOptimLevel());
assertNull("resValues", buildType.resValues());
assertNull("shrinkResources", buildType.shrinkResources());
assertNull("testCoverageEnabled", buildType.testCoverageEnabled());
assertNull("useJack", buildType.useJack());
assertNull("versionNameSuffix", buildType.versionNameSuffix());
assertNull("zipAlignEnabled", buildType.zipAlignEnabled());
buildModel.reparse();
android = buildModel.android();
assertNotNull(android);
assertTrue(android.hasValidPsiElement());
buildType = getXyzBuildType(buildModel);
assertTrue(buildType.hasValidPsiElement());
assertEquals("applicationIdSuffix", "mySuffix", buildType.applicationIdSuffix());
assertNull("buildConfigFields", buildType.buildConfigFields());
assertNull("consumerProguardFiles", buildType.consumerProguardFiles());
assertNull("debuggable", buildType.debuggable());
assertNull("embedMicroApp", buildType.embedMicroApp());
assertNull("jniDebuggable", buildType.jniDebuggable());
assertNull("manifestPlaceholders", buildType.manifestPlaceholders());
assertNull("minifyEnabled", buildType.minifyEnabled());
assertNull("multiDexEnabled", buildType.multiDexEnabled());
assertNull("proguardFiles", buildType.proguardFiles());
assertNull("pseudoLocalesEnabled", buildType.pseudoLocalesEnabled());
assertNull("renderscriptDebuggable", buildType.renderscriptDebuggable());
assertNull("renderscriptOptimLevel", buildType.renderscriptOptimLevel());
assertNull("resValues", buildType.resValues());
assertNull("shrinkResources", buildType.shrinkResources());
assertNull("testCoverageEnabled", buildType.testCoverageEnabled());
assertNull("useJack", buildType.useJack());
assertNull("versionNameSuffix", buildType.versionNameSuffix());
assertNull("zipAlignEnabled", buildType.zipAlignEnabled());
// Now remove the applicationIdSuffix also and see the whole android block is removed as it would be an empty block.
buildType.removeApplicationIdSuffix();
assertTrue(android.hasValidPsiElement());
assertTrue(buildType.hasValidPsiElement());
assertNull("applicationIdSuffix", buildType.applicationIdSuffix());
applyChanges(buildModel);
assertFalse(android.hasValidPsiElement());
assertFalse(buildType.hasValidPsiElement());
buildModel.reparse();
android = buildModel.android();
assertNotNull(android);
assertFalse(android.hasValidPsiElement());
assertThat(android.buildTypes()).isEmpty();
}
use of com.android.tools.idea.gradle.dsl.model.android.AbstractFlavorTypeModel.ResValue 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.android.AbstractFlavorTypeModel.ResValue in project android by JetBrains.
the class ProductFlavorModelTest method testAddAndResetListElements.
public void testAddAndResetListElements() throws Exception {
String text = "android {\n" + " defaultConfig {\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
AndroidModel android = buildModel.android();
assertNotNull(android);
ProductFlavorModel defaultConfig = android.defaultConfig();
assertNull("consumerProguardFiles", defaultConfig.consumerProguardFiles());
assertNull("proguardFiles", defaultConfig.proguardFiles());
assertNull("resConfigs", defaultConfig.resConfigs());
assertNull("resValues", defaultConfig.resValues());
defaultConfig.addConsumerProguardFile("proguard-android.txt").addProguardFile("proguard-android.txt").addResConfig("abcd").addResValue(new ResValue("mnop", "qrst", "uvwx"));
assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt"), defaultConfig.consumerProguardFiles());
assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt"), defaultConfig.proguardFiles());
assertEquals("resConfigs", ImmutableList.of("abcd"), defaultConfig.resConfigs());
assertEquals("resValues", ImmutableList.of(new ResValue("mnop", "qrst", "uvwx")), defaultConfig.resValues());
buildModel.resetState();
assertNull("consumerProguardFiles", defaultConfig.consumerProguardFiles());
assertNull("proguardFiles", defaultConfig.proguardFiles());
assertNull("resConfigs", defaultConfig.resConfigs());
assertNull("resValues", defaultConfig.resValues());
}
Aggregations