Search in sources :

Example 11 with ResValue

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

the class ProductFlavorModelTest method testRemoveFromAndApplyListElements.

public void testRemoveFromAndApplyListElements() throws Exception {
    String text = "android {\n" + "  defaultConfig {\n" + "    consumerProguardFiles 'proguard-android.txt', 'proguard-rules.pro'\n" + "    proguardFiles = ['proguard-android.txt', 'proguard-rules.pro']\n" + "    resConfigs \"abcd\", \"efgh\"\n" + "    resValue \"abcd\", \"efgh\", \"ijkl\"\n" + "    resValue \"mnop\", \"qrst\", \"uvwx\"\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    ProductFlavorModel defaultConfig = android.defaultConfig();
    assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.consumerProguardFiles());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.proguardFiles());
    assertEquals("resConfigs", ImmutableList.of("abcd", "efgh"), defaultConfig.resConfigs());
    assertEquals("resValues", ImmutableList.of(new ResValue("abcd", "efgh", "ijkl"), new ResValue("mnop", "qrst", "uvwx")), defaultConfig.resValues());
    defaultConfig.removeConsumerProguardFile("proguard-rules.pro").removeProguardFile("proguard-rules.pro").removeResConfig("efgh").removeResValue(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("abcd", "efgh", "ijkl")), defaultConfig.resValues());
    applyChanges(buildModel);
    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("abcd", "efgh", "ijkl")), 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"), defaultConfig.proguardFiles());
    assertEquals("resConfigs", ImmutableList.of("abcd"), defaultConfig.resConfigs());
    assertEquals("resValues", ImmutableList.of(new ResValue("abcd", "efgh", "ijkl")), 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 12 with ResValue

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

the class ProductFlavorModelTest method testRemoveFromAndResetListElements.

public void testRemoveFromAndResetListElements() throws Exception {
    String text = "android {\n" + "  defaultConfig {\n" + "    consumerProguardFiles 'proguard-android.txt', 'proguard-rules.pro'\n" + "    proguardFiles 'proguard-android.txt', 'proguard-rules.pro'\n" + "    resConfigs \"abcd\", \"efgh\"\n" + "    resValue \"abcd\", \"efgh\", \"ijkl\"\n" + "    resValue \"mnop\", \"qrst\", \"uvwx\"\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    ProductFlavorModel defaultConfig = android.defaultConfig();
    assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.consumerProguardFiles());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.proguardFiles());
    assertEquals("resConfigs", ImmutableList.of("abcd", "efgh"), defaultConfig.resConfigs());
    assertEquals("resValues", ImmutableList.of(new ResValue("abcd", "efgh", "ijkl"), new ResValue("mnop", "qrst", "uvwx")), defaultConfig.resValues());
    defaultConfig.removeConsumerProguardFile("proguard-rules.pro").removeProguardFile("proguard-rules.pro").removeResConfig("efgh").removeResValue(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("abcd", "efgh", "ijkl")), defaultConfig.resValues());
    buildModel.resetState();
    assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.consumerProguardFiles());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.proguardFiles());
    assertEquals("resConfigs", ImmutableList.of("abcd", "efgh"), defaultConfig.resConfigs());
    assertEquals("resValues", ImmutableList.of(new ResValue("abcd", "efgh", "ijkl"), 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 13 with ResValue

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

the class BuildTypeModelTest method testRemoveFromAndApplyListElements.

public void testRemoveFromAndApplyListElements() 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());
    applyChanges(buildModel);
    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.reparse();
    buildType = getXyzBuildType(buildModel);
    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());
}
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 14 with ResValue

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

the class BuildTypeModelTest method testAddAndApplyListElements.

public void testAddAndApplyListElements() 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());
    applyChanges(buildModel);
    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.reparse();
    buildType = getXyzBuildType(buildModel);
    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());
}
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 15 with ResValue

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

the class BuildTypeModelTest method testAddToAndApplyListElements.

public void testAddToAndApplyListElements() 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());
    applyChanges(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", "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.reparse();
    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", "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());
}
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