use of com.android.tools.idea.gradle.dsl.model.android.AndroidModel in project android by JetBrains.
the class GradleValueTest method testListOfGradleValuesInAssignmentStatements.
public void testListOfGradleValuesInAssignmentStatements() throws Exception {
String text = "android {\n" + " defaultConfig {\n" + " consumerProguardFiles = ['con-proguard-android.txt', 'con-proguard-rules.pro']\n" + " proguardFiles = ['proguard-android.txt', 'proguard-rules.pro']\n" + " }\n" + "}";
writeToBuildFile(text);
AndroidModel android = getGradleBuildModel().android();
assertNotNull(android);
ProductFlavorModel defaultConfig = android.defaultConfig();
List<GradleNotNullValue<String>> consumerProguardFiles = defaultConfig.consumerProguardFiles();
assertNotNull(consumerProguardFiles);
assertThat(consumerProguardFiles).hasSize(2);
verifyGradleValue(consumerProguardFiles.get(0), "android.defaultConfig.consumerProguardFiles.consumerProguardFiles", "'con-proguard-android.txt'");
verifyGradleValue(consumerProguardFiles.get(1), "android.defaultConfig.consumerProguardFiles.consumerProguardFiles", "'con-proguard-rules.pro'");
List<GradleNotNullValue<String>> proguardFiles = defaultConfig.proguardFiles();
assertNotNull(proguardFiles);
assertThat(proguardFiles).hasSize(2);
verifyGradleValue(proguardFiles.get(0), "android.defaultConfig.proguardFiles.proguardFiles", "'proguard-android.txt'");
verifyGradleValue(proguardFiles.get(1), "android.defaultConfig.proguardFiles.proguardFiles", "'proguard-rules.pro'");
}
use of com.android.tools.idea.gradle.dsl.model.android.AndroidModel 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);
}
use of com.android.tools.idea.gradle.dsl.model.android.AndroidModel in project android by JetBrains.
the class FixBuildToolsVersionHyperlink method setBuildToolsVersion.
static void setBuildToolsVersion(@NotNull Project project, @NotNull VirtualFile buildFile, @NotNull String version, boolean requestSync) {
// TODO check that the build file has the 'android' plugin applied.
GradleBuildModel buildModel = parseBuildFile(buildFile, project);
AndroidModel android = buildModel.android();
if (android == null) {
return;
}
if (version.equals(android.buildToolsVersion())) {
return;
}
android.setBuildToolsVersion(version);
runWriteCommandAction(project, buildModel::applyChanges);
if (requestSync) {
GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
}
}
use of com.android.tools.idea.gradle.dsl.model.android.AndroidModel in project android by JetBrains.
the class ExtModelTest method testResolveMultiLevelExtProperty.
public void testResolveMultiLevelExtProperty() throws IOException {
String text = "ext.SDK_VERSION = 21\n" + "ext.COMPILE_SDK_VERSION = SDK_VERSION\n" + "android {\n" + " compileSdkVersion COMPILE_SDK_VERSION\n" + " defaultConfig {\n" + " targetSdkVersion compileSdkVersion\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
ExtModel extModel = buildModel.ext();
assertEquals(21, extModel.getLiteralProperty("SDK_VERSION", Integer.class));
assertEquals(21, extModel.getLiteralProperty("COMPILE_SDK_VERSION", Integer.class));
AndroidModel androidModel = buildModel.android();
assertNotNull(androidModel);
assertEquals("compileSdkVersion", "21", androidModel.compileSdkVersion());
ProductFlavorModel defaultConfig = androidModel.defaultConfig();
assertEquals("targetSdkVersion", "21", defaultConfig.targetSdkVersion());
}
use of com.android.tools.idea.gradle.dsl.model.android.AndroidModel in project android by JetBrains.
the class ExtModelTest method testResolveQualifiedVariableInStringLiteral.
public void testResolveQualifiedVariableInStringLiteral() throws IOException {
String text = "android {\n" + " compileSdkVersion 23\n" + " defaultConfig {\n" + " targetSdkVersion \"$android.compileSdkVersion\"\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
AndroidModel androidModel = buildModel.android();
assertNotNull(androidModel);
assertEquals("compileSdkVersion", "23", androidModel.compileSdkVersion());
ProductFlavorModel defaultConfig = androidModel.defaultConfig();
assertEquals("targetSdkVersion", "23", defaultConfig.targetSdkVersion());
}
Aggregations