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;
}
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();
}
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;
}
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());
}
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());
}
Aggregations