use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class AdbOptionsModelTest method testEditElements.
public void testEditElements() throws Exception {
String text = "android {\n" + " adbOptions {\n" + " installOptions 'abcd', 'efgh'\n" + " timeOutInMs = 200\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());
assertEquals("timeOutInMs", Integer.valueOf(200), adbOptions.timeOutInMs());
adbOptions.replaceInstallOption("efgh", "xyz").setTimeOutInMs(300);
applyChangesAndReparse(buildModel);
android = buildModel.android();
assertNotNull(android);
adbOptions = android.adbOptions();
assertEquals("installOptions", ImmutableList.of("abcd", "xyz"), adbOptions.installOptions());
assertEquals("timeOutInMs", Integer.valueOf(300), adbOptions.timeOutInMs());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class AaptOptionsModelTest method testRemoveElements.
public void testRemoveElements() throws Exception {
String text = "android {\n" + " aaptOptions {\n" + " additionalParameters 'abcd', 'efgh'\n" + " cruncherEnabled true\n" + " cruncherProcesses 1\n" + " failOnMissingConfigEntry false\n" + " ignoreAssets 'efgh'\n" + " noCompress 'a'\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
AndroidModel android = buildModel.android();
assertNotNull(android);
AaptOptionsModel aaptOptions = android.aaptOptions();
assertTrue(aaptOptions.hasValidPsiElement());
assertEquals("additionalParameters", ImmutableList.of("abcd", "efgh"), aaptOptions.additionalParameters());
assertEquals("cruncherEnabled", Boolean.TRUE, aaptOptions.cruncherEnabled());
assertEquals("cruncherProcesses", Integer.valueOf(1), aaptOptions.cruncherProcesses());
assertEquals("failOnMissingConfigEntry", Boolean.FALSE, aaptOptions.failOnMissingConfigEntry());
assertEquals("ignoreAssets", "efgh", aaptOptions.ignoreAssets());
assertEquals("noCompress", ImmutableList.of("a"), aaptOptions.noCompress());
aaptOptions.removeAllAdditionalParameters().removeCruncherEnabled().removeCruncherProcesses().removeFailOnMissingConfigEntry().removeIgnoreAssets().removeAllNoCompress();
applyChangesAndReparse(buildModel);
android = buildModel.android();
assertNotNull(android);
aaptOptions = android.aaptOptions();
assertFalse(aaptOptions.hasValidPsiElement());
assertNull("additionalParameters", aaptOptions.additionalParameters());
assertNull("cruncherEnabled", aaptOptions.cruncherEnabled());
assertNull("cruncherProcesses", aaptOptions.cruncherProcesses());
assertNull("failOnMissingConfigEntry", aaptOptions.failOnMissingConfigEntry());
assertNull("ignoreAssets", aaptOptions.ignoreAssets());
assertNull("noCompress", aaptOptions.noCompress());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class AaptOptionsModelTest method testRemoveOneOfElementsInTheList.
public void testRemoveOneOfElementsInTheList() throws Exception {
String text = "android {\n" + " aaptOptions {\n" + " additionalParameters 'abcd', 'efgh'\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("noCompress", ImmutableList.of("a", "b"), aaptOptions.noCompress());
aaptOptions.removeAdditionalParameter("abcd");
aaptOptions.removeNoCompress("b");
applyChangesAndReparse(buildModel);
android = buildModel.android();
assertNotNull(android);
aaptOptions = android.aaptOptions();
assertEquals("additionalParameters", ImmutableList.of("efgh"), aaptOptions.additionalParameters());
assertEquals("noCompress", ImmutableList.of("a"), aaptOptions.noCompress());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class GradleDependencyManager method findMissingDependencies.
/**
* Returns the dependencies that are NOT included in the specified module.
* Note: the version of the dependency is disregarded.
*
* @param module the module to check dependencies in
* @param dependencies the dependencies of interest.
* @return a list of the dependencies NOT included in the module
*/
@NotNull
public List<GradleCoordinate> findMissingDependencies(@NotNull Module module, @NotNull Iterable<GradleCoordinate> dependencies) {
AndroidModuleModel gradleModel = AndroidModuleModel.get(module);
GradleBuildModel buildModel = GradleBuildModel.get(module);
if (gradleModel == null && buildModel == null) {
return Collections.emptyList();
}
RepositoryUrlManager manager = RepositoryUrlManager.get();
List<GradleCoordinate> missingLibraries = Lists.newArrayList();
for (GradleCoordinate coordinate : dependencies) {
GradleCoordinate resolvedCoordinate = manager.resolveDynamicCoordinate(coordinate, null);
if (resolvedCoordinate == null) {
// We don't have anything installed, but we can keep trying with the unresolved coordinate if we have enough info
if (coordinate.getArtifactId() == null || coordinate.getGroupId() == null) {
// TODO Should this be an error ?
continue;
}
} else {
coordinate = resolvedCoordinate;
}
boolean dependencyFound = false;
// First look in the model returned by Gradle.
if (gradleModel != null && GradleUtil.dependsOn(gradleModel, String.format("%s:%s", coordinate.getGroupId(), coordinate.getArtifactId()))) {
// GradleUtil.dependsOn method only checks the android library dependencies.
// TODO: Consider updating it to also check for java library dependencies.
dependencyFound = true;
} else if (buildModel != null) {
// Now, check in the model obtained from the gradle files.
for (ArtifactDependencyModel dependency : buildModel.dependencies().artifacts(COMPILE)) {
if (Objects.equal(coordinate.getGroupId(), dependency.group().value()) && Objects.equal(coordinate.getArtifactId(), dependency.name().value())) {
dependencyFound = true;
break;
}
}
}
if (!dependencyFound) {
missingLibraries.add(coordinate);
}
}
return missingLibraries;
}
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;
}
Aggregations