Search in sources :

Example 21 with AndroidModel

use of com.android.tools.idea.gradle.dsl.model.android.AndroidModel in project android by JetBrains.

the class ExtModelTest method testResolveExtProperty.

public void testResolveExtProperty() throws IOException {
    String text = "ext.COMPILE_SDK_VERSION = 21\n" + "android {\n" + "  compileSdkVersion COMPILE_SDK_VERSION\n" + "}";
    writeToBuildFile(text);
    ExtModel extModel = getGradleBuildModel().ext();
    assertEquals(21, extModel.getLiteralProperty("COMPILE_SDK_VERSION", Integer.class));
    AndroidModel androidModel = getGradleBuildModel().android();
    assertNotNull(androidModel);
    assertEquals("compileSdkVersion", "21", androidModel.compileSdkVersion());
}
Also used : AndroidModel(com.android.tools.idea.gradle.dsl.model.android.AndroidModel)

Example 22 with AndroidModel

use of com.android.tools.idea.gradle.dsl.model.android.AndroidModel in project android by JetBrains.

the class ExtModelTest method testResolveVariablesInStringLiteral.

public void testResolveVariablesInStringLiteral() throws IOException {
    String text = "ext.ANDROID = \"android\"\n" + "ext.SDK_VERSION = 23\n" + "android {\n" + "  compileSdkVersion = \"$ANDROID-${SDK_VERSION}\"\n" + "  defaultConfig {\n" + "    targetSdkVersion \"$compileSdkVersion\"\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    ExtModel extModel = buildModel.ext();
    assertEquals("android", extModel.getLiteralProperty("ANDROID", String.class));
    assertEquals(23, extModel.getLiteralProperty("SDK_VERSION", Integer.class));
    AndroidModel androidModel = buildModel.android();
    assertNotNull(androidModel);
    assertEquals("compileSdkVersion", "android-23", androidModel.compileSdkVersion());
    ProductFlavorModel defaultConfig = androidModel.defaultConfig();
    assertEquals("targetSdkVersion", "android-23", defaultConfig.targetSdkVersion());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) AndroidModel(com.android.tools.idea.gradle.dsl.model.android.AndroidModel) ProductFlavorModel(com.android.tools.idea.gradle.dsl.model.android.ProductFlavorModel)

Example 23 with AndroidModel

use of com.android.tools.idea.gradle.dsl.model.android.AndroidModel in project android by JetBrains.

the class ExtModelTest method testResolveMultiModuleExtProperty.

public void testResolveMultiModuleExtProperty() throws IOException {
    String settingsText = "include ':" + SUB_MODULE_NAME + "'";
    String mainModuleText = "ext.SDK_VERSION = 21";
    String subModuleText = "android {\n" + "  compileSdkVersion SDK_VERSION\n" + "}";
    writeToSettingsFile(settingsText);
    writeToBuildFile(mainModuleText);
    writeToSubModuleBuildFile(subModuleText);
    GradleBuildModel buildModel = getGradleBuildModel();
    ExtModel extModel = buildModel.ext();
    assertEquals(21, extModel.getLiteralProperty("SDK_VERSION", Integer.class));
    GradleBuildModel subModuleBuildModel = getSubModuleGradleBuildModel();
    ExtModel subModuleExtModel = subModuleBuildModel.ext();
    // SDK_VERSION is not defined in the sub module.
    assertNull(subModuleExtModel.getLiteralProperty("SDK_VERSION", Integer.class).value());
    AndroidModel androidModel = subModuleBuildModel.android();
    assertNotNull(androidModel);
    // SDK_VERSION resolved from the main module.
    assertEquals("compileSdkVersion", "21", androidModel.compileSdkVersion());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) AndroidModel(com.android.tools.idea.gradle.dsl.model.android.AndroidModel)

Example 24 with AndroidModel

use of com.android.tools.idea.gradle.dsl.model.android.AndroidModel in project android by JetBrains.

the class ExtModelTest method testResolveQualifiedExtProperty.

public void testResolveQualifiedExtProperty() throws IOException {
    String text = "ext.constants = [\n" + "  COMPILE_SDK_VERSION : 21\n" + "]\n" + "android {\n" + "  compileSdkVersion constants.COMPILE_SDK_VERSION\n" + "}";
    writeToBuildFile(text);
    ExtModel extModel = getGradleBuildModel().ext();
    assertEquals(21, extModel.getLiteralProperty("constants.COMPILE_SDK_VERSION", Integer.class));
    AndroidModel androidModel = getGradleBuildModel().android();
    assertNotNull(androidModel);
    assertEquals("compileSdkVersion", "21", androidModel.compileSdkVersion());
}
Also used : AndroidModel(com.android.tools.idea.gradle.dsl.model.android.AndroidModel)

Example 25 with AndroidModel

use of com.android.tools.idea.gradle.dsl.model.android.AndroidModel in project android by JetBrains.

the class ExtModelTest method testResolveVariableInListProperty.

public void testResolveVariableInListProperty() throws IOException {
    String text = "ext.TEST_STRING = \"test\"\n" + "android.defaultConfig {\n" + "    proguardFiles 'proguard-android.txt', \"$TEST_STRING\"\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    ExtModel extModel = buildModel.ext();
    assertEquals("test", extModel.getLiteralProperty("TEST_STRING", String.class));
    AndroidModel androidModel = buildModel.android();
    assertNotNull(androidModel);
    ProductFlavorModel defaultConfig = androidModel.defaultConfig();
    assertEquals("proguardFiles", ImmutableList.of("proguard-android.txt", "test"), defaultConfig.proguardFiles());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) AndroidModel(com.android.tools.idea.gradle.dsl.model.android.AndroidModel) ProductFlavorModel(com.android.tools.idea.gradle.dsl.model.android.ProductFlavorModel)

Aggregations

AndroidModel (com.android.tools.idea.gradle.dsl.model.android.AndroidModel)28 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)13 ProductFlavorModel (com.android.tools.idea.gradle.dsl.model.android.ProductFlavorModel)13 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 Project (com.intellij.openapi.project.Project)2 Nullable (org.jetbrains.annotations.Nullable)2 AbstractFlavorTypeModel (com.android.tools.idea.gradle.dsl.model.android.AbstractFlavorTypeModel)1 BuildTypeModel (com.android.tools.idea.gradle.dsl.model.android.BuildTypeModel)1 CompileOptionsModel (com.android.tools.idea.gradle.dsl.model.android.CompileOptionsModel)1 JavaModel (com.android.tools.idea.gradle.dsl.model.java.JavaModel)1 AndroidDslElement (com.android.tools.idea.gradle.dsl.parser.android.AndroidDslElement)1 GradleDslExpressionList (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionList)1 AndroidPluginInfo (com.android.tools.idea.gradle.plugin.AndroidPluginInfo)1 JavaFacet (com.android.tools.idea.gradle.project.facet.java.JavaFacet)1 Projects.getAndroidModel (com.android.tools.idea.gradle.util.Projects.getAndroidModel)1 Module (com.intellij.openapi.module.Module)1 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1