Search in sources :

Example 6 with ResValue

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();
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ResValue(com.android.tools.idea.gradle.dsl.model.android.AbstractFlavorTypeModel.ResValue) BuildConfigField(com.android.tools.idea.gradle.dsl.model.android.BuildTypeModel.BuildConfigField)

Example 7 with ResValue

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());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ResValue(com.android.tools.idea.gradle.dsl.model.android.AbstractFlavorTypeModel.ResValue) BuildConfigField(com.android.tools.idea.gradle.dsl.model.android.BuildTypeModel.BuildConfigField)

Example 8 with ResValue

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

the class ProductFlavorModelTest method testAddAndApplyListElements.

public void testAddAndApplyListElements() 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").addProguardFile("proguard-rules.pro").addResConfig("abcd").addResValue(new ResValue("mnop", "qrst", "uvwx"));
    assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt"), defaultConfig.consumerProguardFiles());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.proguardFiles());
    assertEquals("resConfigs", ImmutableList.of("abcd"), defaultConfig.resConfigs());
    assertEquals("resValues", ImmutableList.of(new ResValue("mnop", "qrst", "uvwx")), defaultConfig.resValues());
    applyChanges(buildModel);
    assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt"), defaultConfig.consumerProguardFiles());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.proguardFiles());
    assertEquals("resConfigs", ImmutableList.of("abcd"), defaultConfig.resConfigs());
    assertEquals("resValues", ImmutableList.of(new ResValue("mnop", "qrst", "uvwx")), defaultConfig.resValues());
    buildModel.reparse();
    android = buildModel.android();
    assertNotNull(android);
    defaultConfig = android.defaultConfig();
    assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt"), defaultConfig.consumerProguardFiles());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.proguardFiles());
    assertEquals("resConfigs", ImmutableList.of("abcd"), defaultConfig.resConfigs());
    assertEquals("resValues", ImmutableList.of(new ResValue("mnop", "qrst", "uvwx")), defaultConfig.resValues());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ResValue(com.android.tools.idea.gradle.dsl.model.android.AbstractFlavorTypeModel.ResValue)

Example 9 with ResValue

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

the class BuildTypeModelTest method testRemoveAndResetElements.

public void testRemoveAndResetElements() 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();
    BuildTypeModel buildType = getXyzBuildType(buildModel);
    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());
    buildType.removeApplicationIdSuffix().removeAllBuildConfigFields().removeAllConsumerProguardFiles().removeDebuggable().removeEmbedMicroApp().removeJniDebuggable().removeAllManifestPlaceholders().removeMinifyEnabled().removeMultiDexEnabled().removeAllProguardFiles().removePseudoLocalesEnabled().removeRenderscriptDebuggable().removeRenderscriptOptimLevel().removeAllResValues().removeShrinkResources().removeTestCoverageEnabled().removeUseJack().removeVersionNameSuffix().removeZipAlignEnabled();
    assertNull("applicationIdSuffix", 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.resetState();
    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());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ResValue(com.android.tools.idea.gradle.dsl.model.android.AbstractFlavorTypeModel.ResValue) BuildConfigField(com.android.tools.idea.gradle.dsl.model.android.BuildTypeModel.BuildConfigField)

Example 10 with ResValue

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

the class BuildTypeModelTest method testRemoveFromAndResetListElements.

public void testRemoveFromAndResetListElements() throws Exception {
    String text = "android {\n" + "  buildTypes {\n" + "    xyz {\n" + "      buildConfigField \"abcd\", \"efgh\", \"ijkl\"\n" + "      buildConfigField \"cdef\", \"ghij\", \"klmn\"\n" + "      consumerProguardFiles 'proguard-android.txt', 'proguard-rules.pro'\n" + "      proguardFiles 'proguard-android.txt', 'proguard-rules.pro'\n" + "      resValue \"mnop\", \"qrst\", \"uvwx\"\n" + "      resValue \"opqr\", \"stuv\", \"wxyz\"\n" + "    }\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    BuildTypeModel buildType = getXyzBuildType(buildModel);
    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"), buildType.consumerProguardFiles());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), buildType.proguardFiles());
    assertEquals("resValues", ImmutableList.of(new ResValue("mnop", "qrst", "uvwx"), new ResValue("opqr", "stuv", "wxyz")), buildType.resValues());
    buildType.removeBuildConfigField(new BuildConfigField("abcd", "efgh", "ijkl")).removeConsumerProguardFile("proguard-rules.pro").removeProguardFile("proguard-rules.pro").removeResValue(new ResValue("opqr", "stuv", "wxyz"));
    assertEquals("buildConfigFields", ImmutableList.of(new BuildConfigField("cdef", "ghij", "klmn")), 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();
    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"), buildType.consumerProguardFiles());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), buildType.proguardFiles());
    assertEquals("resValues", ImmutableList.of(new ResValue("mnop", "qrst", "uvwx"), new ResValue("opqr", "stuv", "wxyz")), buildType.resValues());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ResValue(com.android.tools.idea.gradle.dsl.model.android.AbstractFlavorTypeModel.ResValue) BuildConfigField(com.android.tools.idea.gradle.dsl.model.android.BuildTypeModel.BuildConfigField)

Aggregations

GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)20 ResValue (com.android.tools.idea.gradle.dsl.model.android.AbstractFlavorTypeModel.ResValue)20 BuildConfigField (com.android.tools.idea.gradle.dsl.model.android.BuildTypeModel.BuildConfigField)10