Search in sources :

Example 6 with JavaModel

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

the class GradleBuildModel method java.

@NotNull
public JavaModel java() {
    JavaDslElement javaDslElement = myGradleDslFile.getPropertyElement(JAVA_BLOCK_NAME, JavaDslElement.class);
    if (javaDslElement == null) {
        javaDslElement = new JavaDslElement(myGradleDslFile);
        myGradleDslFile.setNewElement(JAVA_BLOCK_NAME, javaDslElement);
    }
    return new JavaModel(javaDslElement);
}
Also used : JavaDslElement(com.android.tools.idea.gradle.dsl.parser.java.JavaDslElement) JavaModel(com.android.tools.idea.gradle.dsl.model.java.JavaModel) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with JavaModel

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

the class SubProjectsTest method testOverrideSubProjectsSection.

public void testOverrideSubProjectsSection() throws Exception {
    String settingsText = "include ':" + SUB_MODULE_NAME + "'";
    String mainModuleText = "subprojects { \n" + "  sourceCompatibility = 1.4\n" + "  targetCompatibility = 1.5\n" + "}\n" + "sourceCompatibility = 1.5 \n" + "targetCompatibility = 1.6";
    String subModuleText = "sourceCompatibility = 1.6\n" + "targetCompatibility = 1.7";
    writeToSettingsFile(settingsText);
    writeToBuildFile(mainModuleText);
    writeToSubModuleBuildFile(subModuleText);
    JavaModel java = getGradleBuildModel().java();
    assertEquals(LanguageLevel.JDK_1_5, java.sourceCompatibility());
    assertEquals(LanguageLevel.JDK_1_6, java.targetCompatibility());
    JavaModel subModuleJava = getSubModuleGradleBuildModel().java();
    // 1_4 is overridden with 1_6
    assertEquals(LanguageLevel.JDK_1_6, subModuleJava.sourceCompatibility());
    // 1_5 is overridden with 1_7
    assertEquals(LanguageLevel.JDK_1_7, subModuleJava.targetCompatibility());
}
Also used : JavaModel(com.android.tools.idea.gradle.dsl.model.java.JavaModel)

Example 8 with JavaModel

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

the class SubProjectsTest method testSubProjectsSection.

public void testSubProjectsSection() throws Exception {
    String settingsText = "include ':" + SUB_MODULE_NAME + "'";
    String mainModuleText = "subprojects { \n" + "  sourceCompatibility = 1.5\n" + "  targetCompatibility = 1.6\n" + "}";
    String subModuleText = "";
    writeToSettingsFile(settingsText);
    writeToBuildFile(mainModuleText);
    writeToSubModuleBuildFile(subModuleText);
    JavaModel java = getGradleBuildModel().java();
    assertNull(java.sourceCompatibility());
    assertNull(java.targetCompatibility());
    JavaModel subModuleJava = getSubModuleGradleBuildModel().java();
    assertEquals(LanguageLevel.JDK_1_5, subModuleJava.sourceCompatibility());
    assertEquals(LanguageLevel.JDK_1_6, subModuleJava.targetCompatibility());
}
Also used : JavaModel(com.android.tools.idea.gradle.dsl.model.java.JavaModel)

Example 9 with JavaModel

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

the class SubProjectsTest method testSubProjectsSectionWithLocalProperties.

public void testSubProjectsSectionWithLocalProperties() throws Exception {
    String settingsText = "include ':" + SUB_MODULE_NAME + "'";
    String mainModuleText = "sourceCompatibility = 1.4 \n" + "targetCompatibility = 1.5 \n" + "subprojects { \n" + "  sourceCompatibility = 1.5\n" + "  targetCompatibility = 1.6\n" + "}";
    String subModuleText = "";
    writeToSettingsFile(settingsText);
    writeToBuildFile(mainModuleText);
    writeToSubModuleBuildFile(subModuleText);
    JavaModel java = getGradleBuildModel().java();
    // subprojects section applies only for sub projects.
    assertEquals(LanguageLevel.JDK_1_4, java.sourceCompatibility());
    // subprojects section applies only for sub projects.
    assertEquals(LanguageLevel.JDK_1_5, java.targetCompatibility());
    JavaModel subModuleJava = getSubModuleGradleBuildModel().java();
    // Subproject got 1_5 from SubProjects section
    assertEquals(LanguageLevel.JDK_1_5, subModuleJava.sourceCompatibility());
    // Subproject got 1_6 from SubProjects section
    assertEquals(LanguageLevel.JDK_1_6, subModuleJava.targetCompatibility());
}
Also used : JavaModel(com.android.tools.idea.gradle.dsl.model.java.JavaModel)

Aggregations

JavaModel (com.android.tools.idea.gradle.dsl.model.java.JavaModel)9 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)1 AndroidModel (com.android.tools.idea.gradle.dsl.model.android.AndroidModel)1 CompileOptionsModel (com.android.tools.idea.gradle.dsl.model.android.CompileOptionsModel)1 JavaDslElement (com.android.tools.idea.gradle.dsl.parser.java.JavaDslElement)1 JavaFacet (com.android.tools.idea.gradle.project.facet.java.JavaFacet)1 Projects.getAndroidModel (com.android.tools.idea.gradle.util.Projects.getAndroidModel)1 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Project (com.intellij.openapi.project.Project)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1