This commit is contained in:
Joe Bowser 2012-06-18 16:01:19 -07:00
commit 67d46432ed
12 changed files with 216 additions and 0 deletions

View File

@ -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

View File

@ -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);
}
}

View File

@ -0,0 +1 @@
Main-Class: ApplicationInfo

View File

@ -0,0 +1,7 @@
#!/bin/bash
set -e
CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd )
bash $CORDOVA_PATH/cordova BOOM

Binary file not shown.

View File

@ -0,0 +1,7 @@
#!/bin/bash
set -e
CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd )
bash $CORDOVA_PATH/cordova clean

View File

@ -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)

View File

@ -0,0 +1,7 @@
#!/bin/bash
set -e
CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd )
bash $CORDOVA_PATH/cordova debug

View File

@ -0,0 +1,7 @@
#!/bin/bash
set -e
CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd )
bash $CORDOVA_PATH/cordova emulate

View File

@ -0,0 +1,7 @@
#!/bin/bash
set -e
PROJECT_PATH=$( cd "$( dirname "$0" )/.." && pwd )
bash $PROJECT_PATH/cordova/cordova log

View File

@ -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});