Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Inherit the SDK path from the android plugin #70

Merged
merged 5 commits into from
Feb 20, 2015
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,27 @@ public class AndroidCommandPlugin implements Plugin<Project> {
if (!project.plugins.hasPlugin('android')) {
throw new StopExecutionException("The 'android' plugin is required.")
}
def extension = project.android.extensions.create("command", AndroidCommandPluginExtension, project)

def androidExtension = project.android
String androidHome = getAndroidHome(androidExtension)

def extension = androidExtension.extensions.create("command", AndroidCommandPluginExtension, project, androidHome)
extension.task 'installDevice', 'installs the APK on the specified device', Install, ['assemble']
extension.task 'run', 'installs and runs a APK on the specified device', Run, ['installDevice']
extension.task 'monkey', 'calls the monkey command on the specified device', Monkey, ['installDevice']
extension.task 'clearPrefs', 'clears the shared preferences on the specified device', ClearPreferences
extension.task 'uninstallDevice', 'uninstalls the APK from the specific device', Uninstall
}

private static String getAndroidHome(androidExtension) {
def androidHome
if (androidExtension.hasProperty('sdkHandler')) {
androidHome = "${androidExtension.sdkHandler.sdkFolder}"
} else if(androidExtension.hasProperty('sdkDirectory')) {
androidHome = "${androidExtension.sdkDirectory}"
} else {
throw new IllegalStateException('The android plugin is not exposing the SDK folder in an expected way.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
androidHome
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.gradle.api.Project

public class AndroidCommandPluginExtension {

def androidHome
String androidHome
def adb
def aapt
def deviceId
Expand All @@ -13,14 +13,9 @@ public class AndroidCommandPluginExtension {

private final Project project

AndroidCommandPluginExtension(Project project) {
AndroidCommandPluginExtension(Project project, String androidHome) {
this.project = project
androidHome = readSdkDirFromLocalProperties() ?: System.env.ANDROID_HOME
if (androidHome == null) {
throw new IllegalStateException("Couldn't read the SDK directory. If you're running the tests, " +
"make sure you set the ANDROID_HOME env. variable and it points to your Android SDK home. Otherwise, " +
"make sure there's a local.properties in the root of your project with the property sdk.dir pointing to the Android SDK")
}
this.androidHome = androidHome
}

def task(String name, Class<? extends AdbTask> type, Closure configuration) {
Expand Down Expand Up @@ -103,15 +98,4 @@ public class AndroidCommandPluginExtension {
}
deviceIds[0]
}

private def readSdkDirFromLocalProperties() {
try {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
properties.getProperty('sdk.dir').trim()
}
catch (Exception e) {
project.getLogger().debug("could not read local.properties", e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.novoda.gradle.command
import org.gradle.testfixtures.ProjectBuilder

class AndroidCommandPluginExtensionTest extends GroovyTestCase {
static private final String SDK_PATH = '/some/path'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


void testDefaultAdbPath() {
def extension = createExtension()
Expand All @@ -11,7 +12,7 @@ class AndroidCommandPluginExtensionTest extends GroovyTestCase {

void testDefaultAndroidHomePath() {
def extension = createExtension()
assert extension.androidHome != null
assert extension.androidHome == SDK_PATH
}

void testDefaultEvents() {
Expand All @@ -27,7 +28,7 @@ class AndroidCommandPluginExtensionTest extends GroovyTestCase {
private static AndroidCommandPluginExtension createExtension() {
def projectDir = new File('..')
def project = ProjectBuilder.builder().withProjectDir(projectDir).build()
def extension = new AndroidCommandPluginExtension(project)
def extension = new AndroidCommandPluginExtension(project, SDK_PATH)
extension
}
}
Expand Down