use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class AndroidModelTest method testRemoveAndApplyProductFlavorBlock.
public void testRemoveAndApplyProductFlavorBlock() throws Exception {
String text = "android { \n" + " productFlavors { \n" + " flavor1 { \n" + " } \n" + " flavor2 {" + " } \n" + " } \n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
AndroidModel android = buildModel.android();
assertNotNull(android);
List<ProductFlavorModel> productFlavors = android.productFlavors();
assertThat(productFlavors).hasSize(2);
assertEquals("productFlavors", "flavor1", productFlavors.get(0).name());
assertEquals("productFlavors", "flavor2", productFlavors.get(1).name());
android.removeProductFlavor("flavor2");
productFlavors = android.productFlavors();
assertThat(productFlavors).hasSize(1);
assertEquals("productFlavors", "flavor1", productFlavors.get(0).name());
applyChanges(buildModel);
productFlavors = android.productFlavors();
assertThat(productFlavors).hasSize(1);
assertEquals("productFlavors", "flavor1", productFlavors.get(0).name());
buildModel.reparse();
android = buildModel.android();
assertNotNull(android);
productFlavors = android.productFlavors();
assertThat(productFlavors).hasSize(1);
assertEquals("productFlavors", "flavor1", productFlavors.get(0).name());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class AndroidModelTest method testAddAndApplyBlockStatements.
public void testAddAndApplyBlockStatements() throws Exception {
String text = "android.defaultConfig.applicationId \"com.example.myapplication\"\n" + "android.defaultConfig.proguardFiles \"proguard-android.txt\", \"proguard-rules.pro\"";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
AndroidModel android = buildModel.android();
assertNotNull(android);
ProductFlavorModel defaultConfig = android.defaultConfig();
assertEquals("applicationId", "com.example.myapplication", defaultConfig.applicationId());
assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.proguardFiles());
defaultConfig.setDimension("abcd");
assertEquals("applicationId", "com.example.myapplication", defaultConfig.applicationId());
assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.proguardFiles());
assertEquals("dimension", "abcd", defaultConfig.dimension());
applyChangesAndReparse(buildModel);
android = buildModel.android();
assertNotNull(android);
defaultConfig = android.defaultConfig();
assertEquals("applicationId", "com.example.myapplication", defaultConfig.applicationId());
assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "proguard-rules.pro"), defaultConfig.proguardFiles());
assertEquals("dimension", "abcd", defaultConfig.dimension());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class AndroidModelTest method testReplaceAndResetListElements.
public void testReplaceAndResetListElements() throws Exception {
String text = "android { \n" + " flavorDimensions \"abi\", \"version\"\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
AndroidModel android = buildModel.android();
assertNotNull(android);
assertEquals("flavorDimensions", ImmutableList.of("abi", "version"), android.flavorDimensions());
android.replaceFlavorDimension("abi", "xyz");
assertEquals("flavorDimensions", ImmutableList.of("xyz", "version"), android.flavorDimensions());
buildModel.resetState();
assertEquals("flavorDimensions", ImmutableList.of("abi", "version"), android.flavorDimensions());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class GradleSyncTest method aarSourceAttachments.
@Test
public void aarSourceAttachments() throws IOException {
guiTest.importSimpleApplication();
IdeFrameFixture ideFrame = guiTest.ideFrame();
Project project = ideFrame.getProject();
Module appModule = ideFrame.getModule("app");
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
runWriteCommandAction(project, () -> {
GradleBuildModel buildModel = GradleBuildModel.get(appModule);
String newDependency = "com.mapbox.mapboxsdk:mapbox-android-sdk:0.7.4@aar";
buildModel.dependencies().addArtifact(COMPILE, newDependency);
buildModel.applyChanges();
});
}
});
ideFrame.requestProjectSync().waitForGradleProjectSyncToFinish();
// Verify that the library has sources.
LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
String libraryName = "mapbox-android-sdk-0.7.4";
Library library = libraryTable.getLibraryByName(libraryName);
VirtualFile[] files = library.getFiles(SOURCES);
assertThat(files).asList().hasSize(1);
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class SigningConfigModelTest method testEditConsoleReadPasswordElements.
public void testEditConsoleReadPasswordElements() throws Exception {
String text = "android {\n" + " signingConfigs {\n" + " release {\n" + " storePassword System.console().readLine(\"\\nKeystore password: \")\n" + " keyPassword System.console().readLine(\"\\nKey password: \")" + " }\n" + " }" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
AndroidModel android = buildModel.android();
assertNotNull(android);
List<SigningConfigModel> signingConfigs = android.signingConfigs();
assertThat(signingConfigs).hasSize(1);
SigningConfigModel signingConfig = signingConfigs.get(0);
assertEquals("signingConfig", new SigningConfigPassword(CONSOLE_READ, "\nKeystore password: "), signingConfig.storePassword());
assertEquals("signingConfig", new SigningConfigPassword(CONSOLE_READ, "\nKey password: "), signingConfig.keyPassword());
signingConfig.setStorePassword(CONSOLE_READ, "Another Keystore Password: ");
signingConfig.setKeyPassword(CONSOLE_READ, "Another Key Password: ");
applyChangesAndReparse(buildModel);
android = buildModel.android();
assertNotNull(android);
signingConfigs = android.signingConfigs();
assertThat(signingConfigs).hasSize(1);
signingConfig = signingConfigs.get(0);
assertEquals("signingConfig", new SigningConfigPassword(CONSOLE_READ, "Another Keystore Password: "), signingConfig.storePassword());
assertEquals("signingConfig", new SigningConfigPassword(CONSOLE_READ, "Another Key Password: "), signingConfig.keyPassword());
}
Aggregations