Search in sources :

Example 76 with GradleBuildModel

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

the class AndroidModelTest method testRemoveAndApplySigningConfigBlock.

public void testRemoveAndApplySigningConfigBlock() throws Exception {
    String text = "android { \n" + "  signingConfigs { \n" + "    config1 { \n" + "    } \n" + "    config2 {" + "    } \n" + "  } \n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    List<SigningConfigModel> signingConfigs = android.signingConfigs();
    assertThat(signingConfigs).hasSize(2);
    assertEquals("signingConfigs", "config1", signingConfigs.get(0).name());
    assertEquals("signingConfigs", "config2", signingConfigs.get(1).name());
    android.removeSigningConfig("config2");
    signingConfigs = android.signingConfigs();
    assertThat(signingConfigs).hasSize(1);
    assertEquals("signingConfigs", "config1", signingConfigs.get(0).name());
    applyChanges(buildModel);
    signingConfigs = android.signingConfigs();
    assertThat(signingConfigs).hasSize(1);
    assertEquals("signingConfigs", "config1", signingConfigs.get(0).name());
    buildModel.reparse();
    android = buildModel.android();
    assertNotNull(android);
    signingConfigs = android.signingConfigs();
    assertThat(signingConfigs).hasSize(1);
    assertEquals("signingConfigs", "config1", signingConfigs.get(0).name());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 77 with GradleBuildModel

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

the class AndroidModelTest method testRemoveAndApplySourceSetBlock.

public void testRemoveAndApplySourceSetBlock() throws Exception {
    String text = "android { \n" + "  sourceSets { \n" + "    set1 { \n" + "    } \n" + "    set2 {" + "    } \n" + "  } \n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    List<SourceSetModel> sourceSets = android.sourceSets();
    assertThat(sourceSets).hasSize(2);
    assertEquals("sourceSets", "set1", sourceSets.get(0).name());
    assertEquals("sourceSets", "set2", sourceSets.get(1).name());
    android.removeSourceSet("set2");
    sourceSets = android.sourceSets();
    assertThat(sourceSets).hasSize(1);
    assertEquals("sourceSets", "set1", sourceSets.get(0).name());
    applyChanges(buildModel);
    sourceSets = android.sourceSets();
    assertThat(sourceSets).hasSize(1);
    assertEquals("sourceSets", "set1", sourceSets.get(0).name());
    buildModel.reparse();
    android = buildModel.android();
    assertNotNull(android);
    sourceSets = android.sourceSets();
    assertThat(sourceSets).hasSize(1);
    assertEquals("sourceSets", "set1", sourceSets.get(0).name());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 78 with GradleBuildModel

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

the class AndroidModelTest method testRemoveAndApplyBuildTypeBlock.

public void testRemoveAndApplyBuildTypeBlock() throws Exception {
    String text = "android { \n" + "  buildTypes { \n" + "    type1 { \n" + "    } \n" + "    type2 { \n" + "    } \n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    List<BuildTypeModel> buildTypes = android.buildTypes();
    assertThat(buildTypes).hasSize(2);
    assertEquals("buildTypes", "type1", buildTypes.get(0).name());
    assertEquals("buildTypes", "type2", buildTypes.get(1).name());
    android.removeBuildType("type1");
    buildTypes = android.buildTypes();
    assertThat(buildTypes).hasSize(1);
    assertEquals("buildTypes", "type2", buildTypes.get(0).name());
    applyChanges(buildModel);
    buildTypes = android.buildTypes();
    assertThat(buildTypes).hasSize(1);
    assertEquals("buildTypes", "type2", buildTypes.get(0).name());
    buildModel.reparse();
    android = buildModel.android();
    assertNotNull(android);
    buildTypes = android.buildTypes();
    assertThat(buildTypes).hasSize(1);
    assertEquals("buildTypes", "type2", buildTypes.get(0).name());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 79 with GradleBuildModel

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

the class AndroidModelTest method testAddAndResetProductFlavorBlock.

public void testAddAndResetProductFlavorBlock() throws Exception {
    String text = "android { \n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    assertThat(android.productFlavors()).isEmpty();
    android.addProductFlavor("flavor");
    List<ProductFlavorModel> productFlavors = android.productFlavors();
    assertThat(productFlavors).hasSize(1);
    assertEquals("productFlavors", "flavor", productFlavors.get(0).name());
    buildModel.resetState();
    assertThat(android.productFlavors()).isEmpty();
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 80 with GradleBuildModel

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

the class AndroidModelTest method testAddAndApplyBuildTypeBlock.

public void testAddAndApplyBuildTypeBlock() 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);
    BuildTypeModel buildType = buildTypes.get(0);
    buildType.setApplicationIdSuffix("mySuffix");
    buildTypes = android.buildTypes();
    assertThat(buildTypes).hasSize(1);
    buildType = buildTypes.get(0);
    assertEquals("buildTypes", "type", buildType.name());
    assertEquals("buildTypes", "mySuffix", buildType.applicationIdSuffix());
    applyChanges(buildModel);
    buildTypes = android.buildTypes();
    assertThat(buildTypes).hasSize(1);
    buildType = buildTypes.get(0);
    assertEquals("buildTypes", "type", buildType.name());
    assertEquals("buildTypes", "mySuffix", buildType.applicationIdSuffix());
    buildModel.reparse();
    android = buildModel.android();
    assertNotNull(android);
    buildTypes = android.buildTypes();
    assertThat(buildTypes).hasSize(1);
    buildType = buildTypes.get(0);
    assertEquals("buildTypes", "type", buildType.name());
    assertEquals("buildTypes", "mySuffix", buildType.applicationIdSuffix());
}
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