Search in sources :

Example 6 with AndroidModel

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

the class GradleValueTest method testGradleValuesOfLiteralElementsInAssignmentStatements.

public void testGradleValuesOfLiteralElementsInAssignmentStatements() throws Exception {
    String text = "android { \n" + "  buildToolsVersion = \"23.0.0\"\n" + "  compileSdkVersion = \"android-23\"\n" + "  defaultPublishConfig = \"debug\"\n" + "  generatePureSplits = true\n" + "}";
    writeToBuildFile(text);
    AndroidModel android = getGradleBuildModel().android();
    assertNotNull(android);
    verifyGradleValue(android.buildToolsVersion(), "android.buildToolsVersion", "\"23.0.0\"");
    verifyGradleValue(android.compileSdkVersion(), "android.compileSdkVersion", "\"android-23\"");
    verifyGradleValue(android.defaultPublishConfig(), "android.defaultPublishConfig", "\"debug\"");
    verifyGradleValue(android.generatePureSplits(), "android.generatePureSplits", "true");
}
Also used : AndroidModel(com.android.tools.idea.gradle.dsl.model.android.AndroidModel)

Example 7 with AndroidModel

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

the class GradleValueTest method testMapOfGradleValuesInApplicationStatements.

public void testMapOfGradleValuesInApplicationStatements() throws Exception {
    String text = "android {\n" + "  defaultConfig {\n" + "    manifestPlaceholders activityLabel1:\"defaultName1\", activityLabel2:\"defaultName2\"\n" + "    testInstrumentationRunnerArguments size:\"medium\", foo:\"bar\"\n" + "  }\n" + "}";
    writeToBuildFile(text);
    AndroidModel android = getGradleBuildModel().android();
    assertNotNull(android);
    ProductFlavorModel defaultConfig = android.defaultConfig();
    Map<String, GradleNotNullValue<Object>> manifestPlaceholders = defaultConfig.manifestPlaceholders();
    assertNotNull(manifestPlaceholders);
    GradleNotNullValue<Object> activityLabel1 = manifestPlaceholders.get("activityLabel1");
    assertNotNull(activityLabel1);
    verifyGradleValue(activityLabel1, "android.defaultConfig.manifestPlaceholders.activityLabel1", "\"defaultName1\"");
    GradleNotNullValue<Object> activityLabel2 = manifestPlaceholders.get("activityLabel2");
    assertNotNull(activityLabel2);
    verifyGradleValue(activityLabel2, "android.defaultConfig.manifestPlaceholders.activityLabel2", "\"defaultName2\"");
    Map<String, GradleNotNullValue<String>> testInstrumentationRunnerArguments = defaultConfig.testInstrumentationRunnerArguments();
    assertNotNull(testInstrumentationRunnerArguments);
    GradleNotNullValue<String> size = testInstrumentationRunnerArguments.get("size");
    assertNotNull(size);
    verifyGradleValue(size, "android.defaultConfig.testInstrumentationRunnerArguments.size", "\"medium\"");
    GradleNotNullValue<String> foo = testInstrumentationRunnerArguments.get("foo");
    assertNotNull(foo);
    verifyGradleValue(foo, "android.defaultConfig.testInstrumentationRunnerArguments.foo", "\"bar\"");
}
Also used : AndroidModel(com.android.tools.idea.gradle.dsl.model.android.AndroidModel) ProductFlavorModel(com.android.tools.idea.gradle.dsl.model.android.ProductFlavorModel)

Example 8 with AndroidModel

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

the class ExtModelTest method testResolveVariableInMapProperty.

// TODO: Support this use case to get this test pass.
/*public void testMapReferenceInMapProperty() throws IOException {
    String text = "ext.TEST_MAP = [test1:\"value1\", test2:\"value2\"]\n" +
                  "android.defaultConfig {\n" +
                  "    testInstrumentationRunnerArguments TEST_MAP\n" +
                  "}";

    writeToBuildFile(text);

    GradleBuildModel buildModel = getGradleBuildModel();
    assertNotNull(buildModel);

    ExtModel extModel = buildModel.ext();
    assertNotNull(extModel);

    GradleDslExpressionMap expressionMap = extModel.getProperty("TEST_MAP", GradleDslExpressionMap.class);
    assertNotNull(expressionMap);
    assertEquals(ImmutableMap.of("test1", "value1", "test2", "value2"), expressionMap.getValues(String.class));

    AndroidModel androidModel = buildModel.android();
    assertNotNull(androidModel);
    ProductFlavorModel defaultConfig = androidModel.defaultConfig();
    assertNotNull(defaultConfig);
    assertEquals("testInstrumentationRunnerArguments", ImmutableMap.of("test1", "value1", "test2", "value2"),
                 defaultConfig.testInstrumentationRunnerArguments());
  }*/
public void testResolveVariableInMapProperty() throws IOException {
    String text = "ext.TEST_STRING = \"test\"\n" + "android.defaultConfig {\n" + "    testInstrumentationRunnerArguments size:\"medium\", foo:\"$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("testInstrumentationRunnerArguments", ImmutableMap.of("size", "medium", "foo", "test"), defaultConfig.testInstrumentationRunnerArguments());
}
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 9 with AndroidModel

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

the class ExtModelTest method testListReferenceInListProperty.

public void testListReferenceInListProperty() throws IOException {
    String text = "ext.TEST_STRINGS = [\"test1\", \"test2\"]\n" + "android.defaultConfig {\n" + "    proguardFiles TEST_STRINGS\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    ExtModel extModel = buildModel.ext();
    GradleDslExpressionList testStringsList = extModel.getPropertyElement("TEST_STRINGS", GradleDslExpressionList.class);
    assertNotNull(testStringsList);
    assertEquals(ImmutableList.of("test1", "test2"), testStringsList.getValues(String.class));
    AndroidModel androidModel = buildModel.android();
    assertNotNull(androidModel);
    ProductFlavorModel defaultConfig = androidModel.defaultConfig();
    assertEquals("proguardFiles", ImmutableList.of("test1", "test2"), defaultConfig.proguardFiles());
}
Also used : GradleDslExpressionList(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionList) 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 10 with AndroidModel

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

the class ExtModelTest method testStringReferenceInListProperty.

public void testStringReferenceInListProperty() 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