Search in sources :

Example 6 with GradleBuildModel

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

the class BuildFileProcessor method processRecursively.

public void processRecursively(@NotNull Project project, @NotNull Processor<GradleBuildModel> processor) {
    ApplicationManager.getApplication().runReadAction(() -> {
        VirtualFile projectRootFolder = project.getBaseDir();
        if (projectRootFolder == null) {
            // Unlikely to happen: this is default project.
            return;
        }
        processFileRecursivelyWithoutIgnored(projectRootFolder, virtualFile -> {
            if (FN_BUILD_GRADLE.equals(virtualFile.getName())) {
                GradleBuildModel buildModel = parseBuildFile(virtualFile, project);
                return processor.process(buildModel);
            }
            return true;
        });
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 7 with GradleBuildModel

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

the class GradleUtil method setBuildToolsVersion.

public static void setBuildToolsVersion(@NotNull Project project, @NotNull String version) {
    List<GradleBuildModel> modelsToUpdate = Lists.newArrayList();
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        AndroidFacet facet = AndroidFacet.getInstance(module);
        if (facet != null) {
            GradleBuildModel buildModel = GradleBuildModel.get(module);
            if (buildModel != null) {
                AndroidModel android = buildModel.android();
                if (android != null && !version.equals(android.buildToolsVersion().value())) {
                    android.setBuildToolsVersion(version);
                    modelsToUpdate.add(buildModel);
                }
            }
        }
    }
    if (!modelsToUpdate.isEmpty()) {
        runWriteCommandAction(project, () -> {
            for (GradleBuildModel buildModel : modelsToUpdate) {
                buildModel.applyChanges();
            }
        });
    }
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) AndroidModel(com.android.tools.idea.gradle.dsl.model.android.AndroidModel) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 8 with GradleBuildModel

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

the class AdbOptionsModelTest method testRemoveOneOfElementsInTheList.

public void testRemoveOneOfElementsInTheList() throws Exception {
    String text = "android {\n" + "  adbOptions {\n" + "    installOptions 'abcd', 'efgh'\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    AdbOptionsModel adbOptions = android.adbOptions();
    assertEquals("installOptions", ImmutableList.of("abcd", "efgh"), adbOptions.installOptions());
    adbOptions.removeInstallOption("abcd");
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    adbOptions = android.adbOptions();
    assertEquals("installOptions", ImmutableList.of("efgh"), adbOptions.installOptions());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 9 with GradleBuildModel

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

the class AaptOptionsModelTest method testEditElements.

public void testEditElements() throws Exception {
    String text = "android {\n" + "  aaptOptions {\n" + "    additionalParameters 'abcd', 'efgh'\n" + "    cruncherEnabled false\n" + "    cruncherProcesses 2\n" + "    failOnMissingConfigEntry true\n" + "    ignoreAssets 'ijkl'\n" + "    noCompress 'a', 'b'\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    AaptOptionsModel aaptOptions = android.aaptOptions();
    assertEquals("additionalParameters", ImmutableList.of("abcd", "efgh"), aaptOptions.additionalParameters());
    assertEquals("cruncherEnabled", Boolean.FALSE, aaptOptions.cruncherEnabled());
    assertEquals("cruncherProcesses", Integer.valueOf(2), aaptOptions.cruncherProcesses());
    assertEquals("failOnMissingConfigEntry", Boolean.TRUE, aaptOptions.failOnMissingConfigEntry());
    assertEquals("ignoreAssets", "ijkl", aaptOptions.ignoreAssets());
    assertEquals("noCompress", ImmutableList.of("a", "b"), aaptOptions.noCompress());
    aaptOptions.replaceAdditionalParameter("efgh", "xyz").setCruncherEnabled(true).setCruncherProcesses(3).setFailOnMissingConfigEntry(false).setIgnoreAssets("mnop").replaceNoCompress("b", "c");
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    aaptOptions = android.aaptOptions();
    assertEquals("additionalParameters", ImmutableList.of("abcd", "xyz"), aaptOptions.additionalParameters());
    assertEquals("cruncherEnabled", Boolean.TRUE, aaptOptions.cruncherEnabled());
    assertEquals("cruncherProcesses", Integer.valueOf(3), aaptOptions.cruncherProcesses());
    assertEquals("failOnMissingConfigEntry", Boolean.FALSE, aaptOptions.failOnMissingConfigEntry());
    assertEquals("ignoreAssets", "mnop", aaptOptions.ignoreAssets());
    assertEquals("noCompress", ImmutableList.of("a", "c"), aaptOptions.noCompress());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 10 with GradleBuildModel

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

the class AdbOptionsModelTest method testRemoveOnlyElementInTheList.

public void testRemoveOnlyElementInTheList() throws Exception {
    String text = "android {\n" + "  adbOptions {\n" + "    installOptions 'abcd'\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    AdbOptionsModel adbOptions = android.adbOptions();
    assertTrue(adbOptions.hasValidPsiElement());
    assertEquals("installOptions", ImmutableList.of("abcd"), adbOptions.installOptions());
    adbOptions.removeInstallOption("abcd");
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    adbOptions = android.adbOptions();
    assertFalse(adbOptions.hasValidPsiElement());
    assertNull("installOptions", adbOptions.installOptions());
}
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