use of com.android.tools.idea.gradle.dsl.model.java.JavaModel in project android by JetBrains.
the class AllProjectsTest method testAllProjectsSection.
public void testAllProjectsSection() throws Exception {
String settingsText = "include ':" + SUB_MODULE_NAME + "'";
String mainModuleText = "allprojects { \n" + " sourceCompatibility = 1.5\n" + " targetCompatibility = 1.6\n" + "}";
String subModuleText = "";
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 subModuleJavaModel = getSubModuleGradleBuildModel().java();
assertEquals(LanguageLevel.JDK_1_5, subModuleJavaModel.sourceCompatibility());
assertEquals(LanguageLevel.JDK_1_6, subModuleJavaModel.targetCompatibility());
}
use of com.android.tools.idea.gradle.dsl.model.java.JavaModel in project android by JetBrains.
the class AllProjectsTest method testOverrideAllProjectsSectionInSubproject.
public void testOverrideAllProjectsSectionInSubproject() throws Exception {
String settingsText = "include ':" + SUB_MODULE_NAME + "'";
String mainModuleText = "allprojects { \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();
// 1_4 is overridden with 1_5
assertEquals(LanguageLevel.JDK_1_5, java.sourceCompatibility());
// 1_5 is overridden with 1_6
assertEquals(LanguageLevel.JDK_1_6, java.targetCompatibility());
JavaModel subModuleJavaModel = getSubModuleGradleBuildModel().java();
// 1_4 is overridden with 1_6
assertEquals(LanguageLevel.JDK_1_6, subModuleJavaModel.sourceCompatibility());
// 1_5 is overridden with 1_7
assertEquals(LanguageLevel.JDK_1_7, subModuleJavaModel.targetCompatibility());
}
use of com.android.tools.idea.gradle.dsl.model.java.JavaModel in project android by JetBrains.
the class AllProjectsTest method testOverrideWithAllProjectsSection.
public void testOverrideWithAllProjectsSection() throws Exception {
String settingsText = "include ':" + SUB_MODULE_NAME + "'";
String mainModuleText = "sourceCompatibility = 1.4 \n" + "targetCompatibility = 1.5 \n" + "allprojects { \n" + " sourceCompatibility = 1.5\n" + " targetCompatibility = 1.6\n" + "}";
String subModuleText = "";
writeToSettingsFile(settingsText);
writeToBuildFile(mainModuleText);
writeToSubModuleBuildFile(subModuleText);
JavaModel java = getGradleBuildModel().java();
// 1_4 is overridden with 1_5
assertEquals(LanguageLevel.JDK_1_5, java.sourceCompatibility());
// 1_5 is overridden with 1_6
assertEquals(LanguageLevel.JDK_1_6, java.targetCompatibility());
JavaModel subModuleJavaModel = getSubModuleGradleBuildModel().java();
// Subproject got 1_5 from allprojects section
assertEquals(LanguageLevel.JDK_1_5, subModuleJavaModel.sourceCompatibility());
// Subproject got 1_5 from allprojects section
assertEquals(LanguageLevel.JDK_1_6, subModuleJavaModel.targetCompatibility());
}
use of com.android.tools.idea.gradle.dsl.model.java.JavaModel in project android by JetBrains.
the class AllProjectsTest method testOverrideAllProjectsSection.
public void testOverrideAllProjectsSection() throws Exception {
String settingsText = "include ':" + SUB_MODULE_NAME + "'";
String mainModuleText = "allprojects { \n" + " sourceCompatibility = 1.4\n" + " targetCompatibility = 1.5\n" + "}\n" + "sourceCompatibility = 1.5 \n" + "targetCompatibility = 1.6";
String subModuleText = "";
writeToSettingsFile(settingsText);
writeToBuildFile(mainModuleText);
writeToSubModuleBuildFile(subModuleText);
JavaModel java = getGradleBuildModel().java();
// 1_4 is overridden with 1_5
assertEquals(LanguageLevel.JDK_1_5, java.sourceCompatibility());
// 1_5 is overridden with 1_6
assertEquals(LanguageLevel.JDK_1_6, java.targetCompatibility());
JavaModel subModuleJavaModel = getSubModuleGradleBuildModel().java();
// Subproject got 1_4 from allprojects section
assertEquals(LanguageLevel.JDK_1_4, subModuleJavaModel.sourceCompatibility());
// Subproject got 1_5 from allprojects section
assertEquals(LanguageLevel.JDK_1_5, subModuleJavaModel.targetCompatibility());
}
use of com.android.tools.idea.gradle.dsl.model.java.JavaModel in project android by JetBrains.
the class AndroidGradleJavaProjectModelModifier method changeLanguageLevel.
@Nullable
@Override
public Promise<Void> changeLanguageLevel(@NotNull Module module, @NotNull LanguageLevel level) {
Project project = module.getProject();
if (!isBuildWithGradle(module)) {
return null;
}
GradleBuildModel buildModel = GradleBuildModel.get(module);
if (buildModel == null) {
return null;
}
if (getAndroidModel(module) != null) {
AndroidModel android = buildModel.android();
if (android == null) {
return null;
}
CompileOptionsModel compileOptions = android.compileOptions();
compileOptions.setSourceCompatibility(level);
compileOptions.setTargetCompatibility(level);
} else {
JavaFacet javaFacet = JavaFacet.getInstance(module);
if (javaFacet == null || javaFacet.getJavaModuleModel() == null) {
return null;
}
JavaModel javaModel = buildModel.java();
javaModel.setSourceCompatibility(level);
javaModel.setTargetCompatibility(level);
}
new WriteCommandAction(project, "Change Gradle Language Level") {
@Override
protected void run(@NotNull Result result) throws Throwable {
buildModel.applyChanges();
registerUndoAction(project);
}
}.execute();
return requestProjectSync(project);
}
Aggregations