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