use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class LinkExternalCppProjectDialog method doOKAction.
@Override
protected void doOKAction() {
String projectPath = toSystemIndependentName(myProjectPathTextField.getText().trim());
String relativePath = getPathRelativeToModuleDir(myModule, projectPath);
assert relativePath != null;
GradleBuildModel buildModel = GradleBuildModel.get(myModule);
assert buildModel != null;
AndroidModel android = buildModel.android();
assert android != null;
if (myBuildSystemCombo.getSelectedItem() == BuildSystem.CMAKE) {
android.externalNativeBuild().cmake().setPath(new File(relativePath));
} else {
android.externalNativeBuild().ndkBuild().setPath(new File(relativePath));
}
Project project = myModule.getProject();
new WriteCommandAction(project, "Link C++ Project with Gradle") {
@Override
protected void run(@NotNull Result result) throws Throwable {
buildModel.applyChanges();
}
}.execute();
GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
super.doOKAction();
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class DefaultRecipeExecutor method applyPlugin.
@Override
public void applyPlugin(@NotNull String plugin) {
plugin = plugin.trim();
myReferences.applyPlugin(plugin);
Project project = myContext.getProject();
File buildFile = getGradleBuildFilePath(myContext.getModuleRoot());
if (project.isInitialized()) {
GradleBuildModel buildModel = getBuildModel(buildFile, project);
if (!buildModel.appliedPlugins().contains(plugin)) {
buildModel.applyPlugin(plugin);
myIO.applyChanges(buildModel);
}
} else {
String destinationContents = buildFile.exists() ? nullToEmpty(readTextFile(buildFile)) : "";
String applyPluginStatement = "apply plugin: '" + plugin + "'";
String result = destinationContents.isEmpty() ? applyPluginStatement : destinationContents + LINE_SEPARATOR + applyPluginStatement;
try {
myIO.writeFile(this, result, buildFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
myNeedsGradleSync = true;
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class BuildTypeModelTest method testRemoveAndResetMapElements.
public void testRemoveAndResetMapElements() throws Exception {
String text = "android {\n" + " buildTypes {\n" + " xyz {\n" + " manifestPlaceholders activityLabel1:\"defaultName1\", activityLabel2:\"defaultName2\"\n" + " }\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
BuildTypeModel buildType = getXyzBuildType(buildModel);
assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel1", "defaultName1", "activityLabel2", "defaultName2"), buildType.manifestPlaceholders());
buildType.removeManifestPlaceholder("activityLabel1");
assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel2", "defaultName2"), buildType.manifestPlaceholders());
buildModel.resetState();
assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel1", "defaultName1", "activityLabel2", "defaultName2"), buildType.manifestPlaceholders());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class BuildTypeModelTest method testRemoveAndApplyMapElements.
public void testRemoveAndApplyMapElements() throws Exception {
String text = "android {\n" + " buildTypes {\n" + " xyz {\n" + " manifestPlaceholders activityLabel1:\"defaultName1\", activityLabel2:\"defaultName2\"\n" + " }\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
BuildTypeModel buildType = getXyzBuildType(buildModel);
assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel1", "defaultName1", "activityLabel2", "defaultName2"), buildType.manifestPlaceholders());
buildType.removeManifestPlaceholder("activityLabel1");
assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel2", "defaultName2"), buildType.manifestPlaceholders());
applyChanges(buildModel);
assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel2", "defaultName2"), buildType.manifestPlaceholders());
buildModel.reparse();
buildType = getXyzBuildType(buildModel);
assertEquals("manifestPlaceholders", ImmutableMap.of("activityLabel2", "defaultName2"), buildType.manifestPlaceholders());
}
use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.
the class BuildTypeModelTest method testEditAndApplyLiteralElements.
public void testEditAndApplyLiteralElements() throws Exception {
String text = "android {\n" + " buildTypes {\n" + " xyz {\n" + " applicationIdSuffix \"mySuffix\"\n" + " debuggable true\n" + " embedMicroApp false\n" + " jniDebuggable true\n" + " minifyEnabled false\n" + " multiDexEnabled true\n" + " pseudoLocalesEnabled false\n" + " renderscriptDebuggable true\n" + " renderscriptOptimLevel 1\n" + " shrinkResources false\n" + " testCoverageEnabled true\n" + " useJack false\n" + " versionNameSuffix \"abc\"\n" + " zipAlignEnabled true\n" + " }\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
BuildTypeModel buildType = getXyzBuildType(buildModel);
assertEquals("applicationIdSuffix", "mySuffix", buildType.applicationIdSuffix());
assertEquals("debuggable", Boolean.TRUE, buildType.debuggable());
assertEquals("embedMicroApp", Boolean.FALSE, buildType.embedMicroApp());
assertEquals("jniDebuggable", Boolean.TRUE, buildType.jniDebuggable());
assertEquals("minifyEnabled", Boolean.FALSE, buildType.minifyEnabled());
assertEquals("multiDexEnabled", Boolean.TRUE, buildType.multiDexEnabled());
assertEquals("pseudoLocalesEnabled", Boolean.FALSE, buildType.pseudoLocalesEnabled());
assertEquals("renderscriptDebuggable", Boolean.TRUE, buildType.renderscriptDebuggable());
assertEquals("renderscriptOptimLevel", Integer.valueOf(1), buildType.renderscriptOptimLevel());
assertEquals("shrinkResources", Boolean.FALSE, buildType.shrinkResources());
assertEquals("testCoverageEnabled", Boolean.TRUE, buildType.testCoverageEnabled());
assertEquals("useJack", Boolean.FALSE, buildType.useJack());
assertEquals("versionNameSuffix", "abc", buildType.versionNameSuffix());
assertEquals("zipAlignEnabled", Boolean.TRUE, buildType.zipAlignEnabled());
buildType.setApplicationIdSuffix("mySuffix-1").setDebuggable(false).setEmbedMicroApp(true).setJniDebuggable(false).setMinifyEnabled(true).setMultiDexEnabled(false).setPseudoLocalesEnabled(true).setRenderscriptDebuggable(false).setRenderscriptOptimLevel(2).setShrinkResources(true).setTestCoverageEnabled(false).setUseJack(true).setVersionNameSuffix("def").setZipAlignEnabled(false);
assertEquals("applicationIdSuffix", "mySuffix-1", buildType.applicationIdSuffix());
assertEquals("debuggable", Boolean.FALSE, buildType.debuggable());
assertEquals("embedMicroApp", Boolean.TRUE, buildType.embedMicroApp());
assertEquals("jniDebuggable", Boolean.FALSE, buildType.jniDebuggable());
assertEquals("minifyEnabled", Boolean.TRUE, buildType.minifyEnabled());
assertEquals("multiDexEnabled", Boolean.FALSE, buildType.multiDexEnabled());
assertEquals("pseudoLocalesEnabled", Boolean.TRUE, buildType.pseudoLocalesEnabled());
assertEquals("renderscriptDebuggable", Boolean.FALSE, buildType.renderscriptDebuggable());
assertEquals("renderscriptOptimLevel", Integer.valueOf(2), buildType.renderscriptOptimLevel());
assertEquals("shrinkResources", Boolean.TRUE, buildType.shrinkResources());
assertEquals("testCoverageEnabled", Boolean.FALSE, buildType.testCoverageEnabled());
assertEquals("useJack", Boolean.TRUE, buildType.useJack());
assertEquals("versionNameSuffix", "def", buildType.versionNameSuffix());
assertEquals("zipAlignEnabled", Boolean.FALSE, buildType.zipAlignEnabled());
applyChanges(buildModel);
assertEquals("applicationIdSuffix", "mySuffix-1", buildType.applicationIdSuffix());
assertEquals("debuggable", Boolean.FALSE, buildType.debuggable());
assertEquals("embedMicroApp", Boolean.TRUE, buildType.embedMicroApp());
assertEquals("jniDebuggable", Boolean.FALSE, buildType.jniDebuggable());
assertEquals("minifyEnabled", Boolean.TRUE, buildType.minifyEnabled());
assertEquals("multiDexEnabled", Boolean.FALSE, buildType.multiDexEnabled());
assertEquals("pseudoLocalesEnabled", Boolean.TRUE, buildType.pseudoLocalesEnabled());
assertEquals("renderscriptDebuggable", Boolean.FALSE, buildType.renderscriptDebuggable());
assertEquals("renderscriptOptimLevel", Integer.valueOf(2), buildType.renderscriptOptimLevel());
assertEquals("shrinkResources", Boolean.TRUE, buildType.shrinkResources());
assertEquals("testCoverageEnabled", Boolean.FALSE, buildType.testCoverageEnabled());
assertEquals("useJack", Boolean.TRUE, buildType.useJack());
assertEquals("versionNameSuffix", "def", buildType.versionNameSuffix());
assertEquals("zipAlignEnabled", Boolean.FALSE, buildType.zipAlignEnabled());
buildModel.reparse();
buildType = getXyzBuildType(buildModel);
assertEquals("applicationIdSuffix", "mySuffix-1", buildType.applicationIdSuffix());
assertEquals("debuggable", Boolean.FALSE, buildType.debuggable());
assertEquals("embedMicroApp", Boolean.TRUE, buildType.embedMicroApp());
assertEquals("jniDebuggable", Boolean.FALSE, buildType.jniDebuggable());
assertEquals("minifyEnabled", Boolean.TRUE, buildType.minifyEnabled());
assertEquals("multiDexEnabled", Boolean.FALSE, buildType.multiDexEnabled());
assertEquals("pseudoLocalesEnabled", Boolean.TRUE, buildType.pseudoLocalesEnabled());
assertEquals("renderscriptDebuggable", Boolean.FALSE, buildType.renderscriptDebuggable());
assertEquals("renderscriptOptimLevel", Integer.valueOf(2), buildType.renderscriptOptimLevel());
assertEquals("shrinkResources", Boolean.TRUE, buildType.shrinkResources());
assertEquals("testCoverageEnabled", Boolean.FALSE, buildType.testCoverageEnabled());
assertEquals("useJack", Boolean.TRUE, buildType.useJack());
assertEquals("versionNameSuffix", "def", buildType.versionNameSuffix());
assertEquals("zipAlignEnabled", Boolean.FALSE, buildType.zipAlignEnabled());
}
Aggregations