Search in sources :

Example 86 with GradleBuildModel

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

the class AndroidModelTest method testRemoveAndApplyProductFlavorBlock.

public void testRemoveAndApplyProductFlavorBlock() throws Exception {
    String text = "android { \n" + "  productFlavors { \n" + "    flavor1 { \n" + "    } \n" + "    flavor2 {" + "    } \n" + "  } \n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    List<ProductFlavorModel> productFlavors = android.productFlavors();
    assertThat(productFlavors).hasSize(2);
    assertEquals("productFlavors", "flavor1", productFlavors.get(0).name());
    assertEquals("productFlavors", "flavor2", productFlavors.get(1).name());
    android.removeProductFlavor("flavor2");
    productFlavors = android.productFlavors();
    assertThat(productFlavors).hasSize(1);
    assertEquals("productFlavors", "flavor1", productFlavors.get(0).name());
    applyChanges(buildModel);
    productFlavors = android.productFlavors();
    assertThat(productFlavors).hasSize(1);
    assertEquals("productFlavors", "flavor1", productFlavors.get(0).name());
    buildModel.reparse();
    android = buildModel.android();
    assertNotNull(android);
    productFlavors = android.productFlavors();
    assertThat(productFlavors).hasSize(1);
    assertEquals("productFlavors", "flavor1", productFlavors.get(0).name());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 87 with GradleBuildModel

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

the class AndroidModelTest method testAddAndApplyBlockStatements.

public void testAddAndApplyBlockStatements() throws Exception {
    String text = "android.defaultConfig.applicationId \"com.example.myapplication\"\n" + "android.defaultConfig.proguardFiles \"proguard-android.txt\", \"proguard-rules.pro\"";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    ProductFlavorModel defaultConfig = android.defaultConfig();
    assertEquals("applicationId", "com.example.myapplication", defaultConfig.applicationId());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.proguardFiles());
    defaultConfig.setDimension("abcd");
    assertEquals("applicationId", "com.example.myapplication", defaultConfig.applicationId());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.proguardFiles());
    assertEquals("dimension", "abcd", defaultConfig.dimension());
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    defaultConfig = android.defaultConfig();
    assertEquals("applicationId", "com.example.myapplication", defaultConfig.applicationId());
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.proguardFiles());
    assertEquals("dimension", "abcd", defaultConfig.dimension());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 88 with GradleBuildModel

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

the class AndroidModelTest method testReplaceAndResetListElements.

public void testReplaceAndResetListElements() throws Exception {
    String text = "android { \n" + "  flavorDimensions \"abi\", \"version\"\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    assertEquals("flavorDimensions", ImmutableList.of("abi", "version"), android.flavorDimensions());
    android.replaceFlavorDimension("abi", "xyz");
    assertEquals("flavorDimensions", ImmutableList.of("xyz", "version"), android.flavorDimensions());
    buildModel.resetState();
    assertEquals("flavorDimensions", ImmutableList.of("abi", "version"), android.flavorDimensions());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 89 with GradleBuildModel

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

the class GradleSyncTest method aarSourceAttachments.

@Test
public void aarSourceAttachments() throws IOException {
    guiTest.importSimpleApplication();
    IdeFrameFixture ideFrame = guiTest.ideFrame();
    Project project = ideFrame.getProject();
    Module appModule = ideFrame.getModule("app");
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            runWriteCommandAction(project, () -> {
                GradleBuildModel buildModel = GradleBuildModel.get(appModule);
                String newDependency = "com.mapbox.mapboxsdk:mapbox-android-sdk:0.7.4@aar";
                buildModel.dependencies().addArtifact(COMPILE, newDependency);
                buildModel.applyChanges();
            });
        }
    });
    ideFrame.requestProjectSync().waitForGradleProjectSyncToFinish();
    // Verify that the library has sources.
    LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
    String libraryName = "mapbox-android-sdk-0.7.4";
    Library library = libraryTable.getLibraryByName(libraryName);
    VirtualFile[] files = library.getFiles(SOURCES);
    assertThat(files).asList().hasSize(1);
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) Test(org.junit.Test)

Example 90 with GradleBuildModel

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

the class SigningConfigModelTest method testEditConsoleReadPasswordElements.

public void testEditConsoleReadPasswordElements() throws Exception {
    String text = "android {\n" + "  signingConfigs {\n" + "    release {\n" + "      storePassword System.console().readLine(\"\\nKeystore password: \")\n" + "      keyPassword System.console().readLine(\"\\nKey password: \")" + "    }\n" + "  }" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    List<SigningConfigModel> signingConfigs = android.signingConfigs();
    assertThat(signingConfigs).hasSize(1);
    SigningConfigModel signingConfig = signingConfigs.get(0);
    assertEquals("signingConfig", new SigningConfigPassword(CONSOLE_READ, "\nKeystore password: "), signingConfig.storePassword());
    assertEquals("signingConfig", new SigningConfigPassword(CONSOLE_READ, "\nKey password: "), signingConfig.keyPassword());
    signingConfig.setStorePassword(CONSOLE_READ, "Another Keystore Password: ");
    signingConfig.setKeyPassword(CONSOLE_READ, "Another Key Password: ");
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    signingConfigs = android.signingConfigs();
    assertThat(signingConfigs).hasSize(1);
    signingConfig = signingConfigs.get(0);
    assertEquals("signingConfig", new SigningConfigPassword(CONSOLE_READ, "Another Keystore Password: "), signingConfig.storePassword());
    assertEquals("signingConfig", new SigningConfigPassword(CONSOLE_READ, "Another Key Password: "), signingConfig.keyPassword());
}
Also used : SigningConfigPassword(com.android.tools.idea.gradle.dsl.model.android.SigningConfigModel.SigningConfigPassword) 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