Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3C3D5D596 for ; Tue, 20 Nov 2012 23:09:50 +0000 (UTC) Received: (qmail 59365 invoked by uid 500); 20 Nov 2012 23:09:50 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 59301 invoked by uid 500); 20 Nov 2012 23:09:50 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 59292 invoked by uid 500); 20 Nov 2012 23:09:50 -0000 Delivered-To: apmail-incubator-callback-commits@incubator.apache.org Received: (qmail 59254 invoked by uid 99); 20 Nov 2012 23:09:50 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Nov 2012 23:09:50 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id AD8523184D6; Tue, 20 Nov 2012 23:09:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: anis@apache.org To: callback-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [1/2] android commit: adding install function Message-Id: <20121120230949.AD8523184D6@tyr.zones.apache.org> Date: Tue, 20 Nov 2012 23:09:49 +0000 (UTC) Updated Branches: refs/heads/master 7657faa9c -> 3f3a0b914 adding install function Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/3f3a0b91 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/3f3a0b91 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/3f3a0b91 Branch: refs/heads/master Commit: 3f3a0b9140be5b07264fb33bf0a4a76348178679 Parents: e1347e4 Author: Anis Kadri Authored: Tue Nov 20 14:49:49 2012 -0800 Committer: Anis Kadri Committed: Tue Nov 20 14:49:49 2012 -0800 ---------------------------------------------------------------------- bin/templates/cordova/cordova | 76 +++++++++++++++++++++++++++--------- 1 files changed, 57 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/3f3a0b91/bin/templates/cordova/cordova ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/cordova b/bin/templates/cordova/cordova index 561663b..759f590 100755 --- a/bin/templates/cordova/cordova +++ b/bin/templates/cordova/cordova @@ -17,11 +17,11 @@ #!/bin/bash -set -e PROJECT_PATH=$( cd "$( dirname "$0" )/.." && pwd ) function check_devices { +# FIXME local devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep device` if [ -z "$devices" ] ; then echo "1" @@ -37,7 +37,6 @@ function emulate { # Do not launch an emulator if there is already one running or if a device is attached if [ $(check_devices) == 0 ] ; then - # echo "Device attached or emulator already running" return fi @@ -62,8 +61,9 @@ function emulate { do echo "$i) ${avd_list[$i]}" done - echo -n "> " - read avd_id + read -t 5 -p "> " avd_id + # default value if input timeout + if [ $avd_id -eq 1000 ] ; then avd_id=0 ; fi done emulator -cpu-delay 0 -no-boot-anim -cache /tmp/cache -avd ${avd_list[$avd_id]} 1> /dev/null 2>&1 & fi @@ -79,17 +79,41 @@ function log { } function run { - if [ $(check_devices) == 0 ] ; then - clean && emulate && install && launch - else - build - echo "##################################################################" - echo "# Plug in your device or launch an emulator with cordova/run #" - echo "##################################################################" - fi + clean && emulate && wait_for_device && install && launch } function install { + + declare -a devices=($(adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep device | cut -f 1)) + local device_id="1000" #FIXME: hopefully user does not have 1000 AVDs + + if [ ${#devices[@]} == 0 ] + then + # should not reach here. Emulator should launch or device should be attached + echo "Emulator not running or device not attached. Could not install debug package" + exit 70 + fi + + if [ ${#devices[@]} == 1 ] + then + export ANDROID_SERIAL=${devices[0]} + # User has more than 1 AVD + elif [ ${#devices[@]} -gt 1 ] + then + while [ -z ${devices[$device_id]} ] + do + echo "Choose from one of the following devices/emulators [0 to $((${#devices[@]}-1))]:" + for(( i = 0 ; i < ${#devices[@]} ; i++ )) + do + echo "$i) ${devices[$i]}" + done + read -t 5 -p "> " device_id + # default value if input timeout + if [ $device_id -eq 1000 ] ; then device_id=0 ; fi + done + export ANDROID_SERIAL=${devices[$device_id]} + fi + ant debug install } @@ -98,14 +122,28 @@ function build { } function wait_for_device { - local i=0 - echo "Waiting for emulator..." - while [ check_devices -eq 0 || timeout -lt 300 ] - do - sleep 1 - i=$[i+1] - end + local i="0" + echo -n "Waiting for device..." + while [ $i -lt 300 ] + do + if [ $(check_devices) -eq 0 ] + then + break + else + sleep 1 + i=$[i+1] + echo -n "." + fi + done + # Device timeout: emulator has not started in time or device not attached + if [ $i -eq 300 ] + then + echo "device timeout!" + exit 69 + else + echo "connected!" + fi } function launch {