Search in sources :

Example 56 with GradleBuildModel

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

the class GradleDependencyManager method updateLibrariesToVersion.

/**
   * Updates any coordinates to the versions specified in the dependencies list.
   * For example, if you pass it [com.android.support.constraint:constraint-layout:1.0.0-alpha2],
   * it will find any constraint layout occurrences of 1.0.0-alpha1 and replace them with 1.0.0-alpha2.
   */
public boolean updateLibrariesToVersion(@NotNull Module module, @NotNull List<GradleCoordinate> dependencies, @Nullable Runnable callback) {
    GradleBuildModel buildModel = GradleBuildModel.get(module);
    if (buildModel == null) {
        return false;
    }
    updateDependenciesInTransaction(buildModel, module, dependencies, callback);
    return true;
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 57 with GradleBuildModel

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

the class LinkExternalCppProjectDialog method doOKAction.

@Override
protected void doOKAction() {
    String projectPath = toSystemIndependentName(myProjectPathTextField.getText().trim());
    String relativePath = getPathRelativeToModuleDir(myModule, projectPath);
    assert relativePath != null;
    GradleBuildModel buildModel = GradleBuildModel.get(myModule);
    assert buildModel != null;
    AndroidModel android = buildModel.android();
    assert android != null;
    if (myBuildSystemCombo.getSelectedItem() == BuildSystem.CMAKE) {
        android.externalNativeBuild().cmake().setPath(new File(relativePath));
    } else {
        android.externalNativeBuild().ndkBuild().setPath(new File(relativePath));
    }
    Project project = myModule.getProject();
    new WriteCommandAction(project, "Link C++ Project with Gradle") {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            buildModel.applyChanges();
        }
    }.execute();
    GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
    super.doOKAction();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) AndroidModel(com.android.tools.idea.gradle.dsl.model.android.AndroidModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) Result(com.intellij.openapi.application.Result)

Example 58 with GradleBuildModel

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

the class DefaultRecipeExecutor method applyPlugin.

@Override
public void applyPlugin(@NotNull String plugin) {
    plugin = plugin.trim();
    myReferences.applyPlugin(plugin);
    Project project = myContext.getProject();
    File buildFile = getGradleBuildFilePath(myContext.getModuleRoot());
    if (project.isInitialized()) {
        GradleBuildModel buildModel = getBuildModel(buildFile, project);
        if (!buildModel.appliedPlugins().contains(plugin)) {
            buildModel.applyPlugin(plugin);
            myIO.applyChanges(buildModel);
        }
    } else {
        String destinationContents = buildFile.exists() ? nullToEmpty(readTextFile(buildFile)) : "";
        String applyPluginStatement = "apply plugin: '" + plugin + "'";
        String result = destinationContents.isEmpty() ? applyPluginStatement : destinationContents + LINE_SEPARATOR + applyPluginStatement;
        try {
            myIO.writeFile(this, result, buildFile);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    myNeedsGradleSync = true;
}
Also used : Project(com.intellij.openapi.project.Project) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) GradleBuildModel.parseBuildFile(com.android.tools.idea.gradle.dsl.model.GradleBuildModel.parseBuildFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) File(java.io.File)

Example 59 with GradleBuildModel

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

the class BuildTypeModelTest method testRemoveAndResetMapElements.

public void testRemoveAndResetMapElements() throws Exception {
    String text = "android {\n" + "  buildTypes {\n" + "    xyz {\n" + "      manifestPlaceholders activityLabel1:\"defaultName1\", activityLabel2:\"defaultName2\"\n" + "    }\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    BuildTypeModel buildType = getXyzBuildType(buildModel);
    assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel1", "defaultName1", "activityLabel2", "defaultName2"), buildType.manifestPlaceholders());
    buildType.removeManifestPlaceholder("activityLabel1");
    assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel2", "defaultName2"), buildType.manifestPlaceholders());
    buildModel.resetState();
    assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel1", "defaultName1", "activityLabel2", "defaultName2"), buildType.manifestPlaceholders());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 60 with GradleBuildModel

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

the class BuildTypeModelTest method testRemoveAndApplyMapElements.

public void testRemoveAndApplyMapElements() throws Exception {
    String text = "android {\n" + "  buildTypes {\n" + "    xyz {\n" + "      manifestPlaceholders activityLabel1:\"defaultName1\", activityLabel2:\"defaultName2\"\n" + "    }\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    BuildTypeModel buildType = getXyzBuildType(buildModel);
    assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel1", "defaultName1", "activityLabel2", "defaultName2"), buildType.manifestPlaceholders());
    buildType.removeManifestPlaceholder("activityLabel1");
    assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel2", "defaultName2"), buildType.manifestPlaceholders());
    applyChanges(buildModel);
    assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel2", "defaultName2"), buildType.manifestPlaceholders());
    buildModel.reparse();
    buildType = getXyzBuildType(buildModel);
    assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel2", "defaultName2"), 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