Search in sources :

Example 1 with ExtModel

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

the class ReferenceResolutionTest method testResolveProjectDir.

public void testResolveProjectDir() throws Exception {
    String settingsText = "include ':" + SUB_MODULE_NAME + "'";
    String mainModuleText = "";
    String subModuleText = "ext {\n" + "  pd = projectDir\n" + "  pd1 = project.projectDir\n" + "  pd2 = parent.projectDir\n" + "  pd3 = rootProject.projectDir\n" + "  pd4 = project(':" + SUB_MODULE_NAME + "').projectDir\n" + "  pd5 = project(':').projectDir\n" + "}";
    writeToSettingsFile(settingsText);
    writeToBuildFile(mainModuleText);
    writeToSubModuleBuildFile(subModuleText);
    String expectedRootDir = getBaseDirPath(myProject).getPath();
    String expectedSubModuleDir = mySubModuleBuildFile.getParent();
    ExtModel ext = getSubModuleGradleBuildModel().ext();
    assertEquals("projectDir", expectedSubModuleDir, ext.getLiteralProperty("pd", String.class));
    assertEquals("projectDir", expectedSubModuleDir, ext.getLiteralProperty("pd1", String.class));
    assertEquals("projectDir", expectedRootDir, ext.getLiteralProperty("pd2", String.class));
    assertEquals("projectDir", expectedRootDir, ext.getLiteralProperty("pd3", String.class));
    assertEquals("projectDir", expectedSubModuleDir, ext.getLiteralProperty("pd4", String.class));
    assertEquals("projectDir", expectedRootDir, ext.getLiteralProperty("pd5", String.class));
}
Also used : ExtModel(com.android.tools.idea.gradle.dsl.model.ext.ExtModel)

Example 2 with ExtModel

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

the class GradleBuildModel method ext.

@NotNull
public ExtModel ext() {
    ExtDslElement extDslElement = myGradleDslFile.getPropertyElement(EXT_BLOCK_NAME, ExtDslElement.class);
    if (extDslElement == null) {
        extDslElement = new ExtDslElement(myGradleDslFile);
        myGradleDslFile.setNewElement(EXT_BLOCK_NAME, extDslElement);
    }
    return new ExtModel(extDslElement);
}
Also used : ExtDslElement(com.android.tools.idea.gradle.dsl.parser.ext.ExtDslElement) ExtModel(com.android.tools.idea.gradle.dsl.model.ext.ExtModel) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ExtModel

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

the class ReferenceResolutionTest method testResolveRootDir.

public void testResolveRootDir() throws Exception {
    String settingsText = "include ':" + SUB_MODULE_NAME + "'";
    String mainModuleText = "";
    String subModuleText = "ext {\n" + "  rpd = rootDir\n" + "  rpd1 = project.rootDir\n" + "  rpd2 = parent.rootDir\n" + "  rpd3 = rootProject.rootDir\n" + "  rpd4 = project(':" + SUB_MODULE_NAME + "').rootDir\n" + "  rpd5 = project(':').rootDir\n" + "}";
    writeToSettingsFile(settingsText);
    writeToBuildFile(mainModuleText);
    writeToSubModuleBuildFile(subModuleText);
    String expectedRootDir = getBaseDirPath(myProject).getPath();
    ExtModel ext = getSubModuleGradleBuildModel().ext();
    assertEquals("rootDir", expectedRootDir, ext.getLiteralProperty("rpd", String.class));
    assertEquals("rootDir", expectedRootDir, ext.getLiteralProperty("rpd1", String.class));
    assertEquals("rootDir", expectedRootDir, ext.getLiteralProperty("rpd2", String.class));
    assertEquals("rootDir", expectedRootDir, ext.getLiteralProperty("rpd3", String.class));
    assertEquals("rootDir", expectedRootDir, ext.getLiteralProperty("rpd4", String.class));
    assertEquals("rootDir", expectedRootDir, ext.getLiteralProperty("rpd5", String.class));
}
Also used : ExtModel(com.android.tools.idea.gradle.dsl.model.ext.ExtModel)

Aggregations

ExtModel (com.android.tools.idea.gradle.dsl.model.ext.ExtModel)3 ExtDslElement (com.android.tools.idea.gradle.dsl.parser.ext.ExtDslElement)1 NotNull (org.jetbrains.annotations.NotNull)1