use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class SplitsModelTest method testRemoveOneOfElementsInTheList.
public void testRemoveOneOfElementsInTheList() throws Exception {
String text = "android {\n" + " splits {\n" + " abi {\n" + " exclude 'abi-exclude-1', 'abi-exclude-2'\n" + " include 'abi-include-1', 'abi-include-2'\n" + " }\n" + " density {\n" + " compatibleScreens 'screen1', 'screen2'\n" + " exclude 'density-exclude-1', 'density-exclude-2'\n" + " include 'density-include-1', 'density-include-2'\n" + " }\n" + " language {\n" + " include 'language-include-1', 'language-include-2'\n" + " }\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
AndroidModel android = buildModel.android();
assertNotNull(android);
SplitsModel splits = android.splits();
AbiModel abi = splits.abi();
assertEquals("exclude", ImmutableList.of("abi-exclude-1", "abi-exclude-2"), abi.exclude());
assertEquals("include", ImmutableList.of("abi-include-1", "abi-include-2"), abi.include());
DensityModel density = splits.density();
assertEquals("compatibleScreens", ImmutableList.of("screen1", "screen2"), density.compatibleScreens());
assertEquals("exclude", ImmutableList.of("density-exclude-1", "density-exclude-2"), density.exclude());
assertEquals("include", ImmutableList.of("density-include-1", "density-include-2"), density.include());
LanguageModel language = splits.language();
assertEquals("include", ImmutableList.of("language-include-1", "language-include-2"), language.include());
abi.removeExclude("abi-exclude-1");
abi.removeInclude("abi-include-2");
density.removeCompatibleScreen("screen1");
density.removeExclude("density-exclude-2");
density.removeInclude("density-include-1");
language.removeInclude("language-include-2");
applyChangesAndReparse(buildModel);
android = buildModel.android();
assertNotNull(android);
splits = android.splits();
abi = splits.abi();
assertEquals("exclude", ImmutableList.of("abi-exclude-2"), abi.exclude());
assertEquals("include", ImmutableList.of("abi-include-1"), abi.include());
density = splits.density();
assertEquals("compatibleScreens", ImmutableList.of("screen2"), density.compatibleScreens());
assertEquals("exclude", ImmutableList.of("density-exclude-1"), density.exclude());
assertEquals("include", ImmutableList.of("density-include-2"), density.include());
language = splits.language();
assertEquals("include", ImmutableList.of("language-include-1"), language.include());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class SplitsModelTest method testRemoveOnlyElementsInTheList.
public void testRemoveOnlyElementsInTheList() throws Exception {
String text = "android {\n" + " splits {\n" + " abi {\n" + " exclude 'abi-exclude'\n" + " include 'abi-include'\n" + " }\n" + " density {\n" + " compatibleScreens 'screen'\n" + " exclude 'density-exclude'\n" + " include 'density-include'\n" + " }\n" + " language {\n" + " include 'language-include'\n" + " }\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
AndroidModel android = buildModel.android();
assertNotNull(android);
SplitsModel splits = android.splits();
assertTrue(splits.hasValidPsiElement());
AbiModel abi = splits.abi();
assertTrue(splits.hasValidPsiElement());
assertEquals("exclude", ImmutableList.of("abi-exclude"), abi.exclude());
assertEquals("include", ImmutableList.of("abi-include"), abi.include());
DensityModel density = splits.density();
assertTrue(density.hasValidPsiElement());
assertEquals("compatibleScreens", ImmutableList.of("screen"), density.compatibleScreens());
assertEquals("exclude", ImmutableList.of("density-exclude"), density.exclude());
assertEquals("include", ImmutableList.of("density-include"), density.include());
LanguageModel language = splits.language();
assertTrue(language.hasValidPsiElement());
assertEquals("include", ImmutableList.of("language-include"), language.include());
abi.removeExclude("abi-exclude");
abi.removeInclude("abi-include");
density.removeCompatibleScreen("screen");
density.removeExclude("density-exclude");
density.removeInclude("density-include");
language.removeInclude("language-include");
applyChangesAndReparse(buildModel);
android = buildModel.android();
assertNotNull(android);
splits = android.splits();
abi = splits.abi();
assertNull("exclude", abi.exclude());
assertNull("include", abi.include());
assertFalse(abi.hasValidPsiElement());
density = splits.density();
assertNull("compatibleScreens", density.compatibleScreens());
assertNull("exclude", density.exclude());
assertNull("include", density.include());
language = splits.language();
assertNull("include", language.include());
assertFalse(language.hasValidPsiElement());
assertFalse(splits.hasValidPsiElement());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class SourceSetModelTest method testSetRootEditAndReset.
public void testSetRootEditAndReset() throws Exception {
String text = "android {\n" + " sourceSets {\n" + " set1 {\n" + " root = \"source1\"\n" + " }\n" + " set2.root \"source2\"\n" + " }\n" + " sourceSets.set3.setRoot \"source3\"\n" + "}\n" + "android.sourceSets.set4.setRoot(\"source4\")";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
verifySourceSetRoot(buildModel, "source");
AndroidModel android = buildModel.android();
assertNotNull(android);
List<SourceSetModel> sourceSets = android.sourceSets();
sourceSets.get(0).setRoot("newRoot1");
sourceSets.get(1).setRoot("newRoot2");
sourceSets.get(2).setRoot("newRoot3");
sourceSets.get(3).setRoot("newRoot4");
verifySourceSetRoot(buildModel, "newRoot");
buildModel.resetState();
verifySourceSetRoot(buildModel, "source");
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class SourceSetModelTest method testSetRootRemoveAndReset.
public void testSetRootRemoveAndReset() throws Exception {
String text = "android {\n" + " sourceSets {\n" + " set1 {\n" + " root = \"source1\"\n" + " }\n" + " set2.root \"source2\"\n" + " }\n" + " sourceSets.set3.setRoot \"source3\"\n" + "}\n" + "android.sourceSets.set4.setRoot(\"source4\")";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
verifySourceSetRoot(buildModel, "source");
AndroidModel android = buildModel.android();
assertNotNull(android);
for (SourceSetModel sourceSet : android.sourceSets()) {
sourceSet.removeRoot();
}
for (SourceSetModel sourceSet : android.sourceSets()) {
assertNull("root", sourceSet.root());
}
buildModel.resetState();
verifySourceSetRoot(buildModel, "source");
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class SourceSetModelTest method testSetRootRemoveAndApply.
public void testSetRootRemoveAndApply() throws Exception {
String text = "android {\n" + " sourceSets {\n" + " set1 {\n" + " root = \"source1\"\n" + " }\n" + " set2.root \"source2\"\n" + " }\n" + " sourceSets.set3.setRoot \"source3\"\n" + "}\n" + "android.sourceSets.set4.setRoot(\"source4\")";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
verifySourceSetRoot(buildModel, "source");
AndroidModel android = buildModel.android();
assertNotNull(android);
assertTrue(android.hasValidPsiElement());
for (SourceSetModel sourceSet : android.sourceSets()) {
sourceSet.removeRoot();
}
for (SourceSetModel sourceSet : android.sourceSets()) {
assertNull("root", sourceSet.root());
}
applyChangesAndReparse(buildModel);
android = buildModel.android();
assertNotNull(android);
// the whole android block is deleted from the file.
assertFalse(android.hasValidPsiElement());
assertThat(android.sourceSets()).isEmpty();
}
Aggregations