diff --git a/bin/create b/bin/create index a6b5c8c6..d6885493 100755 --- a/bin/create +++ b/bin/create @@ -113,3 +113,13 @@ sed -i '' -e "s/__ID__/${PACKAGE}/g" $ACTIVITY_PATH cp $BUILD_PATH/bin/templates/project/AndroidManifest.xml $MANIFEST_PATH sed -i '' -e "s/__ACTIVITY__/${ACTIVITY}/g" $MANIFEST_PATH sed -i '' -e "s/__PACKAGE__/${PACKAGE}/g" $MANIFEST_PATH + +# creating cordova folder and copying emulate/debug/log/launch scripts +mkdir $PROJECT_PATH/cordova +cp $BUILD_PATH/bin/templates/cordova/appinfo.jar $PROJECT_PATH/cordova/appinfo.jar +cp $BUILD_PATH/bin/templates/cordova/cordova $PROJECT_PATH/cordova/cordova +cp $BUILD_PATH/bin/templates/cordova/debug $PROJECT_PATH/cordova/debug +cp $BUILD_PATH/bin/templates/cordova/clean $PROJECT_PATH/cordova/clean +cp $BUILD_PATH/bin/templates/cordova/log $PROJECT_PATH/cordova/log +cp $BUILD_PATH/bin/templates/cordova/emulate $PROJECT_PATH/cordova/emulate +cp $BUILD_PATH/bin/templates/cordova/BOOM $PROJECT_PATH/cordova/BOOM diff --git a/bin/templates/cordova/ApplicationInfo/ApplicationInfo.class b/bin/templates/cordova/ApplicationInfo/ApplicationInfo.class new file mode 100644 index 00000000..6b854f7d Binary files /dev/null and b/bin/templates/cordova/ApplicationInfo/ApplicationInfo.class differ diff --git a/bin/templates/cordova/ApplicationInfo/ApplicationInfo.java b/bin/templates/cordova/ApplicationInfo/ApplicationInfo.java new file mode 100644 index 00000000..9a663217 --- /dev/null +++ b/bin/templates/cordova/ApplicationInfo/ApplicationInfo.java @@ -0,0 +1,44 @@ +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import org.xml.sax.SAXException; +import java.io.IOException; + +public class ApplicationInfo { + private static void parseAndroidManifest(String path) { + // System.out.println(path); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + Document dom; + try { + DocumentBuilder db = dbf.newDocumentBuilder(); + dom = db.parse(path); + + // getting package information + Element manifest = dom.getDocumentElement(); + String pakkage = manifest.getAttribute("package"); + + // getting activity name + String activity = ((Element)dom.getElementsByTagName("activity").item(0)).getAttribute("android:name"); + System.out.println(String.format("%s/%s.%s", pakkage, pakkage, activity)); + } catch(ParserConfigurationException pce) { + pce.printStackTrace(); + } catch(SAXException se) { + se.printStackTrace(); + } catch(IOException ioe) { + ioe.printStackTrace(); + } + + } + + public static void main(String[] args) { + String path; + if(args.length > 0) { + path = args[0]; + } else { + path = System.getProperty("user.dir") + "/../AndroidManifest.xml"; + } + parseAndroidManifest(path); + } +} diff --git a/bin/templates/cordova/ApplicationInfo/manifest.txt b/bin/templates/cordova/ApplicationInfo/manifest.txt new file mode 100644 index 00000000..7d77999c --- /dev/null +++ b/bin/templates/cordova/ApplicationInfo/manifest.txt @@ -0,0 +1 @@ +Main-Class: ApplicationInfo diff --git a/bin/templates/cordova/BOOM b/bin/templates/cordova/BOOM new file mode 100644 index 00000000..37c623c4 --- /dev/null +++ b/bin/templates/cordova/BOOM @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd ) + +bash $CORDOVA_PATH/cordova BOOM diff --git a/bin/templates/cordova/appinfo.jar b/bin/templates/cordova/appinfo.jar new file mode 100644 index 00000000..4116f48c Binary files /dev/null and b/bin/templates/cordova/appinfo.jar differ diff --git a/bin/templates/cordova/clean b/bin/templates/cordova/clean new file mode 100644 index 00000000..daa84421 --- /dev/null +++ b/bin/templates/cordova/clean @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd ) + +bash $CORDOVA_PATH/cordova clean diff --git a/bin/templates/cordova/cordova b/bin/templates/cordova/cordova new file mode 100644 index 00000000..0f3e452c --- /dev/null +++ b/bin/templates/cordova/cordova @@ -0,0 +1,91 @@ +#!/bin/bash + +set -e + +PROJECT_PATH=$( cd "$( dirname "$0" )/.." && pwd ) + +function check_devices { + local devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}'` + if [ -z "$devices" ] ; then + echo "1" + else + echo "0" + fi +} + +function emulate { + declare -a avd_list=($(android list avd | grep "Name:" | cut -f 2 -d ":" | xargs)) + # we need to start adb-server + adb start-server 1>/dev/null + + # 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 + + local avd_id="1000" #FIXME: hopefully user does not have 1000 AVDs + # User has no AVDs + if [ ${#avd_list[@]} == 0 ] + then + echo "You don't have any Android Virtual Devices. Please create at least one AVD." + echo "android" + fi + # User has only one AVD + if [ ${#avd_list[@]} == 1 ] + then + emulator -cpu-delay 0 -no-boot-anim -cache /tmp/cache -avd ${avd_list[0]} 1> /dev/null 2>&1 & + # User has more than 1 AVD + elif [ ${#avd_list[@]} -gt 1 ] + then + while [ -z ${avd_list[$avd_id]} ] + do + echo "Choose from one of the following Android Virtual Devices [0 to $((${#avd_list[@]}-1))]:" + for(( i = 0 ; i < ${#avd_list[@]} ; i++ )) + do + echo "$i) ${avd_list[$i]}" + done + echo -n "> " + read avd_id + done + emulator -cpu-delay 0 -no-boot-anim -cache /tmp/cache -avd ${avd_list[$avd_id]} 1> /dev/null 2>&1 & + fi + +} + +function clean { + ant clean +} +# has to be used independently and not in conjuction with other commands +function log { + adb logcat +} + +function debug_install { + ant debug install +} + +function debug { + ant debug +} + +function launch { + local launch_str=$(java -jar $PROJECT_PATH/cordova/appinfo.jar $PROJECT_PATH/AndroidManifest.xml) + adb shell am start -n $launch_str +} + +function BOOM { + clean + if [ $(check_devices) == 0 ] ; then + debug_install && launch + return + else + debug + echo "##################################################################" + echo "# Plug in your device or launch an emulator with cordova/emulate #" + echo "##################################################################" + fi +} + +# TODO parse arguments +(cd $PROJECT_PATH && $1) diff --git a/bin/templates/cordova/debug b/bin/templates/cordova/debug new file mode 100644 index 00000000..5d63a39f --- /dev/null +++ b/bin/templates/cordova/debug @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd ) + +bash $CORDOVA_PATH/cordova debug diff --git a/bin/templates/cordova/emulate b/bin/templates/cordova/emulate new file mode 100644 index 00000000..6c4fab2b --- /dev/null +++ b/bin/templates/cordova/emulate @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd ) + +bash $CORDOVA_PATH/cordova emulate diff --git a/bin/templates/cordova/log b/bin/templates/cordova/log new file mode 100644 index 00000000..ab3622e5 --- /dev/null +++ b/bin/templates/cordova/log @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +PROJECT_PATH=$( cd "$( dirname "$0" )/.." && pwd ) + +bash $PROJECT_PATH/cordova/cordova log diff --git a/bin/tests/test_create_unix.js b/bin/tests/test_create_unix.js index 75e0697e..a9061767 100644 --- a/bin/tests/test_create_unix.js +++ b/bin/tests/test_create_unix.js @@ -80,6 +80,41 @@ create_project.on('exit', function(code) { path.exists(util.format('%s/assets/www/cordova-%s.js', project_path, version), function(exists) { assert(exists, 'cordova.js did not get added'); }); + + // make sure cordova master script was added + path.exists(util.format('%s/cordova/cordova', project_path), function(exists) { + assert(exists, 'cordova script did not get added'); + }); + + // make sure debug script was added + path.exists(util.format('%s/cordova/debug', project_path), function(exists) { + assert(exists, 'debug script did not get added'); + }); + + // make sure BOOM script was added + path.exists(util.format('%s/cordova/BOOM', project_path), function(exists) { + assert(exists, 'BOOM script did not get added'); + }); + + // make sure log script was added + path.exists(util.format('%s/cordova/log', project_path), function(exists) { + assert(exists, 'log script did not get added'); + }); + + // make sure clean script was added + path.exists(util.format('%s/cordova/clean', project_path), function(exists) { + assert(exists, 'clean script did not get added'); + }); + + // make sure emulate script was added + path.exists(util.format('%s/cordova/emulate', project_path), function(exists) { + assert(exists, 'emulate script did not get added'); + }); + + // make sure appinfo.jar script was added + path.exists(util.format('%s/cordova/appinfo.jar', project_path), function(exists) { + assert(exists, 'appinfo.jar script did not get added'); + }); // check that project compiles && creates a cordovaExample-debug.apk var compile_project = spawn('ant', ['debug'], {cwd: project_path});