use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class SplitsModelTest method testEditElements.
public void testEditElements() throws Exception {
writeToBuildFile(SPLITS_TEXT);
verifySplitsValues();
GradleBuildModel buildModel = getGradleBuildModel();
AndroidModel android = buildModel.android();
assertNotNull(android);
SplitsModel splits = android.splits();
AbiModel abi = splits.abi();
abi.setEnable(false);
abi.replaceExclude("abi-exclude-2", "abi-exclude-3");
abi.replaceInclude("abi-include-2", "abi-include-3");
abi.setUniversalApk(true);
DensityModel density = splits.density();
density.setAuto(true);
density.replaceCompatibleScreen("screen2", "screen3");
density.setEnable(false);
density.replaceExclude("density-exclude-2", "density-exclude-3");
density.replaceInclude("density-include-2", "density-include-3");
LanguageModel language = splits.language();
language.setEnable(true);
language.replaceInclude("language-include-2", "language-include-3");
applyChangesAndReparse(buildModel);
android = buildModel.android();
assertNotNull(android);
splits = android.splits();
abi = splits.abi();
assertEquals("enable", Boolean.FALSE, abi.enable());
assertEquals("exclude", ImmutableList.of("abi-exclude-1", "abi-exclude-3"), abi.exclude());
assertEquals("include", ImmutableList.of("abi-include-1", "abi-include-3"), abi.include());
assertEquals("universalApk", Boolean.TRUE, abi.universalApk());
density = splits.density();
assertEquals("auto", Boolean.TRUE, density.auto());
assertEquals("compatibleScreens", ImmutableList.of("screen1", "screen3"), density.compatibleScreens());
assertEquals("enable", Boolean.FALSE, density.enable());
assertEquals("exclude", ImmutableList.of("density-exclude-1", "density-exclude-3"), density.exclude());
assertEquals("include", ImmutableList.of("density-include-1", "density-include-3"), density.include());
language = splits.language();
assertEquals("enable", Boolean.TRUE, language.enable());
assertEquals("include", ImmutableList.of("language-include-1", "language-include-3"), language.include());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class SplitsModelTest method testRemoveResetStatement.
public void testRemoveResetStatement() throws Exception {
String text = "android {\n" + " splits {\n" + " abi {\n" + " include 'abi-include-1', 'abi-include-2'\n" + " reset()\n" + " }\n" + " density {\n" + " include 'density-include-1', 'density-include-2'\n" + " reset()\n" + " }\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
AndroidModel android = buildModel.android();
assertNotNull(android);
SplitsModel splits = android.splits();
assertNull("abi-include", splits.abi().include());
assertNull("density-include", splits.density().include());
splits.abi().removeReset();
splits.density().removeReset();
applyChangesAndReparse(buildModel);
android = buildModel.android();
assertNotNull(android);
splits = android.splits();
assertEquals("abi-include", ImmutableList.of("abi-include-1", "abi-include-2"), splits.abi().include());
assertEquals("density-include", ImmutableList.of("density-include-1", "density-include-2"), splits.density().include());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class ProductFlavorModelTest method testAddNativeElements.
public void testAddNativeElements() throws Exception {
String text = "android {\n" + " defaultConfig {\n" + " }\n" + "}";
writeToBuildFile(text);
verifyNullNativeElements();
GradleBuildModel buildModel = getGradleBuildModel();
AndroidModel android = buildModel.android();
assertNotNull(android);
ProductFlavorModel defaultConfig = android.defaultConfig();
ExternalNativeBuildOptionsModel externalNativeBuild = defaultConfig.externalNativeBuild();
CMakeOptionsModel cmake = externalNativeBuild.cmake();
cmake.addAbiFilter("abiFilterX").addArgument("argumentX").addCFlag("cFlagX").addCppFlag("cppFlagX").addTarget("targetX");
NdkBuildOptionsModel ndkBuild = externalNativeBuild.ndkBuild();
ndkBuild.addAbiFilter("abiFilterY").addArgument("argumentY").addCFlag("cFlagY").addCppFlag("cppFlagY").addTarget("targetY");
NdkOptionsModel ndk = defaultConfig.ndk();
ndk.addAbiFilter("abiFilterZ");
applyChangesAndReparse(buildModel);
android = buildModel.android();
assertNotNull(android);
defaultConfig = android.defaultConfig();
externalNativeBuild = defaultConfig.externalNativeBuild();
cmake = externalNativeBuild.cmake();
assertEquals("cmake-abiFilters", ImmutableList.of("abiFilterX"), cmake.abiFilters());
assertEquals("cmake-arguments", ImmutableList.of("argumentX"), cmake.arguments());
assertEquals("cmake-cFlags", ImmutableList.of("cFlagX"), cmake.cFlags());
assertEquals("cmake-cppFlags", ImmutableList.of("cppFlagX"), cmake.cppFlags());
assertEquals("cmake-targets", ImmutableList.of("targetX"), cmake.targets());
ndkBuild = externalNativeBuild.ndkBuild();
assertEquals("ndkBuild-abiFilters", ImmutableList.of("abiFilterY"), ndkBuild.abiFilters());
assertEquals("ndkBuild-arguments", ImmutableList.of("argumentY"), ndkBuild.arguments());
assertEquals("ndkBuild-cFlags", ImmutableList.of("cFlagY"), ndkBuild.cFlags());
assertEquals("ndkBuild-cppFlags", ImmutableList.of("cppFlagY"), ndkBuild.cppFlags());
assertEquals("ndkBuild-targets", ImmutableList.of("targetY"), ndkBuild.targets());
ndk = defaultConfig.ndk();
assertEquals("ndk-abiFilters", ImmutableList.of("abiFilterZ"), ndk.abiFilters());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class ProductFlavorModelTest method testAddToAndApplyListElements.
public void testAddToAndApplyListElements() throws Exception {
String text = "android {\n" + " defaultConfig {\n" + " consumerProguardFiles 'proguard-android.txt', 'proguard-rules.pro'\n" + " proguardFiles 'proguard-android.txt', 'proguard-rules.pro'\n" + " resConfigs \"abcd\", \"efgh\"\n" + " resValue \"abcd\", \"efgh\", \"ijkl\"\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
AndroidModel android = buildModel.android();
assertNotNull(android);
ProductFlavorModel defaultConfig = android.defaultConfig();
assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.consumerProguardFiles());
assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.proguardFiles());
assertEquals("resConfigs", ImmutableList.of("abcd", "efgh"), defaultConfig.resConfigs());
assertEquals("resValues", ImmutableList.of(new ResValue("abcd", "efgh", "ijkl")), defaultConfig.resValues());
defaultConfig.addConsumerProguardFile("proguard-android-1.txt").addProguardFile("proguard-android-1.txt").addResConfig("xyz").addResValue(new ResValue("mnop", "qrst", "uvwx"));
assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro", "proguard-android-1.txt"), defaultConfig.consumerProguardFiles());
assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro", "proguard-android-1.txt"), defaultConfig.proguardFiles());
assertEquals("resConfigs", ImmutableList.of("abcd", "efgh", "xyz"), defaultConfig.resConfigs());
assertEquals("resValues", ImmutableList.of(new ResValue("abcd", "efgh", "ijkl"), new ResValue("mnop", "qrst", "uvwx")), defaultConfig.resValues());
applyChanges(buildModel);
assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro", "proguard-android-1.txt"), defaultConfig.consumerProguardFiles());
assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro", "proguard-android-1.txt"), defaultConfig.proguardFiles());
assertEquals("resConfigs", ImmutableList.of("abcd", "efgh", "xyz"), defaultConfig.resConfigs());
assertEquals("resValues", ImmutableList.of(new ResValue("abcd", "efgh", "ijkl"), new ResValue("mnop", "qrst", "uvwx")), defaultConfig.resValues());
buildModel.reparse();
android = buildModel.android();
assertNotNull(android);
defaultConfig = android.defaultConfig();
assertEquals("consumerProguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro", "proguard-android-1.txt"), defaultConfig.consumerProguardFiles());
assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro", "proguard-android-1.txt"), defaultConfig.proguardFiles());
assertEquals("resConfigs", ImmutableList.of("abcd", "efgh", "xyz"), defaultConfig.resConfigs());
assertEquals("resValues", ImmutableList.of(new ResValue("abcd", "efgh", "ijkl"), new ResValue("mnop", "qrst", "uvwx")), defaultConfig.resValues());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class ArtifactDependencyTest method testAddDependency.
public void testAddDependency() throws IOException {
String text = "dependencies {\n" + " runtime group: 'org.gradle.test.classifiers', name: 'service', version: '1.0', classifier: 'jdk14', ext: 'jar'\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
DependenciesModel dependenciesModel = buildModel.dependencies();
ArtifactDependencySpec newDependency = new ArtifactDependencySpec("appcompat-v7", "com.android.support", "22.1.1");
dependenciesModel.addArtifact(COMPILE, newDependency);
assertTrue(buildModel.isModified());
applyChangesAndReparse(buildModel);
List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
assertThat(dependencies).hasSize(2);
ExpectedArtifactDependency expected = new ExpectedArtifactDependency(RUNTIME, "service", "org.gradle.test.classifiers", "1.0");
expected.classifier = "jdk14";
expected.extension = "jar";
expected.assertMatches(dependencies.get(0));
expected = new ExpectedArtifactDependency(COMPILE, "appcompat-v7", "com.android.support", "22.1.1");
expected.assertMatches(dependencies.get(1));
}
Aggregations