Search in sources :

Example 21 with GradleBuildModel

use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel 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());
}
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 22 with GradleBuildModel

use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel 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());
}
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 23 with GradleBuildModel

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

the class BuildTypeModelTest method testAddAndResetLiteralElements.

public void testAddAndResetLiteralElements() throws Exception {
    String text = "android {\n" + "  buildTypes {\n" + "    xyz {\n" + "    }\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    BuildTypeModel buildType = getXyzBuildType(buildModel);
    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());
    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();
    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());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 24 with GradleBuildModel

use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel 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 25 with GradleBuildModel

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

the class BuildTypeModelTest method testSetAndResetMapElements.

public void testSetAndResetMapElements() throws Exception {
    String text = "android {\n" + "  buildTypes {\n" + "    xyz {\n" + "      manifestPlaceholders key1:\"value1\", key2:\"value2\"\n" + "    }\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    BuildTypeModel buildType = getXyzBuildType(buildModel);
    assertEquals("manifestPlaceholders", ImmutableMap.of("key1", "value1", "key2", "value2"), buildType.manifestPlaceholders());
    buildType.setManifestPlaceholder("key1", 12345);
    buildType.setManifestPlaceholder("key3", true);
    assertEquals("manifestPlaceholders", ImmutableMap.of("key1", 12345, "key2", "value2", "key3", true), buildType.manifestPlaceholders());
    buildModel.resetState();
    assertEquals("manifestPlaceholders", ImmutableMap.of("key1", "value1", "key2", "value2"), buildType.manifestPlaceholders());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Aggregations

GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)285 ResValue (com.android.tools.idea.gradle.dsl.model.android.AbstractFlavorTypeModel.ResValue)20 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)17 SigningConfigPassword (com.android.tools.idea.gradle.dsl.model.android.SigningConfigModel.SigningConfigPassword)15 AndroidModel (com.android.tools.idea.gradle.dsl.model.android.AndroidModel)13 DependenciesModel (com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel)13 File (java.io.File)13 Project (com.intellij.openapi.project.Project)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 BuildConfigField (com.android.tools.idea.gradle.dsl.model.android.BuildTypeModel.BuildConfigField)10 Module (com.intellij.openapi.module.Module)9 ProductFlavorModel (com.android.tools.idea.gradle.dsl.model.android.ProductFlavorModel)8 SourceDirectoryModel (com.android.tools.idea.gradle.dsl.model.android.sourceSets.SourceDirectoryModel)8 Result (com.intellij.openapi.application.Result)8 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)8 GradleNotNullValue (com.android.tools.idea.gradle.dsl.model.values.GradleNotNullValue)7 ExternalNativeBuildOptionsModel (com.android.tools.idea.gradle.dsl.model.android.productFlavors.ExternalNativeBuildOptionsModel)6 NotNull (org.jetbrains.annotations.NotNull)6 NdkOptionsModel (com.android.tools.idea.gradle.dsl.model.android.productFlavors.NdkOptionsModel)5 CMakeOptionsModel (com.android.tools.idea.gradle.dsl.model.android.productFlavors.externalNativeBuild.CMakeOptionsModel)5