forked from github/cordova-android
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e01678da93 | ||
|
|
2b6a683198 | ||
|
|
1f58d8ee27 | ||
|
|
fb4527d91b | ||
|
|
a83bbcaf1d |
@@ -106,20 +106,6 @@ function createAppInfoJar() {
|
||||
}
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
// Cleanup
|
||||
// if(fso.FileExists(ROOT + '\\framework\\libs\\commons-codec-1.6.jar')) {
|
||||
// fso.DeleteFile(ROOT + '\\framework\\libs\\commons-codec-1.6.jar');
|
||||
// fso.DeleteFolder(ROOT + '\\framework\\libs', true);
|
||||
// }
|
||||
if(fso.FileExists(ROOT + '\\framework\\cordova-'+VERSION+'.jar')) {
|
||||
fso.DeleteFile(ROOT + '\\framework\\cordova-'+VERSION+'.jar');
|
||||
}
|
||||
if(fso.FileExists(ROOT + '\\framework\\assets\\www\\cordova-'+VERSION+'.js')) {
|
||||
fso.DeleteFile(ROOT + '\\framework\\assets\\www\\cordova-'+VERSION+'.js');
|
||||
}
|
||||
}
|
||||
|
||||
// working dir
|
||||
var ROOT = WScript.ScriptFullName.split('\\bin\\create.js').join('');
|
||||
if (args.Count() > 0) {
|
||||
@@ -212,6 +198,7 @@ exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\clean.bat" "' + PROJ
|
||||
exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\build.bat" "' + PROJECT_PATH + '\\cordova\\build.bat" /Y');
|
||||
exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\log.bat" "' + PROJECT_PATH + '\\cordova\\log.bat" /Y');
|
||||
exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\run.bat" "' + PROJECT_PATH + '\\cordova\\run.bat" /Y');
|
||||
exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\version.bat" "' + PROJECT_PATH + '\\cordova\\version.bat" /Y');
|
||||
|
||||
// interpolate the activity name and package
|
||||
Log("Updating AndroidManifest.xml and Main Activity...");
|
||||
@@ -220,6 +207,4 @@ replaceInFile(ACTIVITY_PATH, /__ID__/, PACKAGE);
|
||||
|
||||
replaceInFile(MANIFEST_PATH, /__ACTIVITY__/, ACTIVITY);
|
||||
replaceInFile(MANIFEST_PATH, /__PACKAGE__/, PACKAGE);
|
||||
replaceInFile(MANIFEST_PATH, /__APILEVEL__/, API_LEVEL);
|
||||
|
||||
cleanup();
|
||||
replaceInFile(MANIFEST_PATH, /__APILEVEL__/, API_LEVEL);
|
||||
562
bin/templates/cordova/lib/cordova.js
vendored
562
bin/templates/cordova/lib/cordova.js
vendored
@@ -18,6 +18,21 @@
|
||||
var ROOT = WScript.ScriptFullName.split('\\cordova\\lib\\cordova.js').join(''),
|
||||
shell = WScript.CreateObject("WScript.Shell"),
|
||||
fso = WScript.CreateObject('Scripting.FileSystemObject');
|
||||
//device_id for targeting specific device
|
||||
var device_id;
|
||||
//build types
|
||||
var NONE = 0,
|
||||
DEBUG = '--debug',
|
||||
RELEASE = '--release',
|
||||
NO_BUILD = '--nobuild';
|
||||
var build_type = NONE;
|
||||
|
||||
//deploy tpyes
|
||||
var NONE = 0,
|
||||
EMULATOR = 1,
|
||||
DEVICE = 2,
|
||||
TARGET = 3;
|
||||
var deploy_type = NONE;
|
||||
|
||||
|
||||
// log to stdout or stderr
|
||||
@@ -86,6 +101,25 @@ function exec_verbose(command) {
|
||||
}
|
||||
}
|
||||
|
||||
function version(path) {
|
||||
var cordovajs_path = path + "\\assets\\www\\cordova.js";
|
||||
if(fso.FileExists(cordovajs_path)) {
|
||||
var f = fso.OpenTextFile(cordovajs_path, 1,2);
|
||||
var cordovajs = f.ReadAll();
|
||||
f.Close();
|
||||
var version_regex = /^.*CORDOVA_JS_BUILD_LABEL.*$/m;
|
||||
var version_line = cordovajs.match(version_regex) + "";
|
||||
var version = version_line.match(/(\d+)\.(\d+)\.(\d+)(rc\d)?/) + "";
|
||||
// TODO : figure out why this isn't matching properly so we can remove this substring workaround.
|
||||
Log(version.substr(0, ((version.length/2) -1)));
|
||||
} else {
|
||||
Log("Error : Could not find cordova js.", true);
|
||||
Log("Expected Location : " + cordovajs_path, true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function get_devices() {
|
||||
var device_list = []
|
||||
var local_devices = shell.Exec("%comspec% /c adb devices").StdOut.ReadAll();
|
||||
@@ -117,38 +151,18 @@ function list_devices() {
|
||||
}
|
||||
|
||||
function get_emulator_images() {
|
||||
// discription contains all data recieved squashed onto one line
|
||||
var add_description = true;
|
||||
var avd_list = [];
|
||||
var local_emulators = shell.Exec("%comspec% /c android list avds").StdOut.ReadAll();
|
||||
if (local_emulators.match(/Name\:/)) {
|
||||
emulators = local_emulators.split('\n');
|
||||
//format (ID DESCRIPTION)
|
||||
var count = 0;
|
||||
var output = '';
|
||||
for (i in emulators) {
|
||||
// Find the line with the emulator name.
|
||||
if (emulators[i].match(/Name\:/)) {
|
||||
// strip description
|
||||
var emulator_name = emulators[i].replace(/\s*Name\:\s/, '') + ' ';
|
||||
if (add_description) {
|
||||
count = 1;
|
||||
output += emulator_name
|
||||
}
|
||||
else {
|
||||
avd_list.push(emulator_name);
|
||||
}
|
||||
}
|
||||
// add description if indicated (all data squeezed onto one line)
|
||||
if (count > 0) {
|
||||
var emulator_description = emulators[i].replace(/\s*/g, '');
|
||||
if (count > 4) {
|
||||
avd_list.push(output + emulator_description);
|
||||
count = 0;
|
||||
output = '';
|
||||
}
|
||||
else {
|
||||
count++;
|
||||
output += emulator_description + ' '
|
||||
}
|
||||
avd_list.push(emulator_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,8 +206,21 @@ function list_started_emulators() {
|
||||
}
|
||||
}
|
||||
else {
|
||||
Log('No started emulators found, if you would like to start an emulator call \'list-emulator-images\'');
|
||||
Log(' to get the name of an emulator and then start the emulator with \'start-emulator <Name>\'');
|
||||
Log('No started emulators found, if you would like to start an emulator call ');
|
||||
Log('\'list-emulator-images\'');
|
||||
Log(' to get the name of an emulator and then start the emulator with');
|
||||
Log('\'start-emulator <Name>\'');
|
||||
}
|
||||
}
|
||||
|
||||
function create_emulator() {
|
||||
//get targets
|
||||
var targets = shell.Exec('android.bat list targets').StdOut.ReadAll().match(/id:\s\d+/g);
|
||||
if(targets) {
|
||||
exec('%comspec% /c android create avd --name cordova_emulator --target ' + targets[targets.length - 1].replace(/id: /, ""));
|
||||
} else {
|
||||
Log("You do not have any android targets setup. Please create at least one target with the `android` command so that an emulator can be created.", true);
|
||||
WScript.Quit(69);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,14 +234,14 @@ function start_emulator(name) {
|
||||
for (i in emulators) {
|
||||
if (emulators[i].substr(0,name.length) == name) {
|
||||
Log("Starting emulator : " + name);
|
||||
shell.Run("%comspec% /c start cmd /c emulator -avd " + name);
|
||||
shell.Exec("%comspec% /c emulator -avd " + name + " &");
|
||||
//shell.Run("%comspec% /c start cmd /c emulator -cpu-delay 0 -no-boot-anim -cache %Temp%\cache -avd " + name);
|
||||
started = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (emulators.length > 0 && started_emulators < 1) {
|
||||
if (emulators.length > 0 && started_emulators.length == 0) {
|
||||
emulator_name = emulators[0].split(' ', 1)[0];
|
||||
start_emulator(emulator_name);
|
||||
return;
|
||||
@@ -230,15 +257,16 @@ function start_emulator(name) {
|
||||
Log("Error : unable to start emulator, ensure you have emulators availible by checking \'list-emulator-images\'", true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
else { // wait for emulator to boot before returning
|
||||
WScript.Stdout.Write('Booting up emulator..');
|
||||
else {
|
||||
// wait for emulator to get the ID
|
||||
Log('Waiting for emulator...');
|
||||
var boot_anim = null;
|
||||
var emulator_ID = null;
|
||||
var new_started = get_started_emulators();
|
||||
var new_started = null;
|
||||
var i = 0;
|
||||
// use boot animation property to tell when boot is complete.
|
||||
while ((boot_anim == null || !boot_anim.output.match(/stopped/)) && i < 100) {
|
||||
if (new_started.length > started_emulators.length && emulator_ID == null) {
|
||||
while(emulator_ID == null && i < 10) {
|
||||
new_started = get_started_emulators();
|
||||
if(new_started.length > started_emulators.length) {
|
||||
// find new emulator that was just started to get it's ID
|
||||
for(var i = 0; i < new_started.length; i++) {
|
||||
if (new_started[i] != started_emulators[i]) {
|
||||
@@ -248,18 +276,25 @@ function start_emulator(name) {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (boot_anim == null) {
|
||||
new_started = get_started_emulators();
|
||||
}
|
||||
else {
|
||||
boot_anim = exec_out('%comspec% /c adb -s ' + emulator_ID + ' shell getprop init.svc.bootanim');
|
||||
}
|
||||
}
|
||||
if (i == 10) {
|
||||
Log('\nEmulator start timed out.');
|
||||
WScript.Quit(2);
|
||||
}
|
||||
i = 0;
|
||||
WScript.Stdout.Write('Booting up emulator (this may take a while).');
|
||||
// use boot animation property to tell when boot is complete.
|
||||
while (!boot_anim.output.match(/stopped/) && i < 100) {
|
||||
boot_anim = exec_out('%comspec% /c adb -s ' + emulator_ID + ' shell getprop init.svc.bootanim');
|
||||
i++;
|
||||
WScript.Stdout.Write('.');
|
||||
WScript.Sleep(2000);
|
||||
}
|
||||
|
||||
if (i < 100) {
|
||||
Log('\nBoot Complete!');
|
||||
// Unlock the device
|
||||
shell.Exec("%comspec% /c adb -s " + emulator_ID + " shell input keyevent 82");
|
||||
} else {
|
||||
Log('\nEmulator boot timed out. Failed to load emulator');
|
||||
WScript.Quit(2);
|
||||
@@ -267,34 +302,11 @@ function start_emulator(name) {
|
||||
}
|
||||
}
|
||||
|
||||
function install_device(target) {
|
||||
var devices = get_devices();
|
||||
var use_target = false;
|
||||
if (devices.length < 1) {
|
||||
Log("Error : No devices found to install to, make sure there are devices", true);
|
||||
Log(" availible by checking \'<project_dir>\\cordova\\lib\\list-devices\'", true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
if (target) {
|
||||
var exists = false;
|
||||
for (i in devices) {
|
||||
if (devices[i].substr(0,target.length) == target)
|
||||
{
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!exists) {
|
||||
Log("Error : Unable to find target " + target, true);
|
||||
Log("Please ensure the target exists by checking \'<project>\\cordova\\lib\\list-devices'");
|
||||
WScript.Quit(2);
|
||||
}
|
||||
use_target = true;
|
||||
}
|
||||
function get_apk(path) {
|
||||
// check if file .apk has been created
|
||||
if (fso.FolderExists(ROOT + '\\bin')) {
|
||||
if (fso.FolderExists(path + '\\bin')) {
|
||||
var path_to_apk;
|
||||
var out_folder = fso.GetFolder(ROOT + '\\bin');
|
||||
var out_folder = fso.GetFolder(path + '\\bin');
|
||||
var out_files = new Enumerator(out_folder.Files);
|
||||
for (;!out_files.atEnd(); out_files.moveNext()) {
|
||||
var path = out_files.item() + '';
|
||||
@@ -304,38 +316,7 @@ function install_device(target) {
|
||||
}
|
||||
}
|
||||
if (path_to_apk) {
|
||||
var launch_name = exec_out("%comspec% /c java -jar "+ROOT+"\\cordova\\appinfo.jar "+ROOT+"\\AndroidManifest.xml");
|
||||
if (launch_name.error) {
|
||||
Log("Failed to get application name from appinfo.jar + AndroidManifest : ", true);
|
||||
Log("Output : " + launch_name.output, true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
// install on device (-d)
|
||||
Log("Installing app on device...");
|
||||
var cmd;
|
||||
if (use_target) {
|
||||
cmd = '%comspec% /c adb -s ' + target + ' install -r ' + path_to_apk;
|
||||
} else {
|
||||
cmd = '%comspec% /c adb -s ' + devices[0].split(' ', 1)[0] + ' install -r ' + path_to_apk;
|
||||
}
|
||||
var install = exec_out(cmd);
|
||||
if ( install.error && install.output.match(/Failure/)) {
|
||||
Log("Error : Could not install apk to device : ", true);
|
||||
Log(install.output, true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
else {
|
||||
Log(install.output);
|
||||
}
|
||||
// run on device
|
||||
Log("Launching application...");
|
||||
cmd;
|
||||
if (use_target) {
|
||||
cmd = '%comspec% /c adb -s ' + target + ' shell am start -W -a android.intent.action.MAIN -n ' + launch_name.output;
|
||||
} else {
|
||||
cmd = '%comspec% /c adb -s ' + devices[0].split(' ', 1)[0] + ' shell am start -W -a android.intent.action.MAIN -n ' + launch_name.output;
|
||||
}
|
||||
exec_verbose(cmd);
|
||||
return path_to_apk;
|
||||
}
|
||||
else {
|
||||
Log('Failed to find apk, make sure you project is built and there is an ', true);
|
||||
@@ -345,7 +326,18 @@ function install_device(target) {
|
||||
}
|
||||
}
|
||||
|
||||
function install_emulator(target) {
|
||||
function install_device(path) {
|
||||
var devices = get_devices();
|
||||
var use_target = false;
|
||||
if (devices.length < 1) {
|
||||
Log("Error : No devices found to install to, make sure there are devices", true);
|
||||
Log(" availible by checking \'<project_dir>\\cordova\\lib\\list-devices\'", true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
launch(path, devices[0].split(' ', 1)[0], true);
|
||||
}
|
||||
|
||||
function install_emulator(path) {
|
||||
var emulators = get_started_emulators();
|
||||
var use_target = false;
|
||||
if (emulators.length < 1) {
|
||||
@@ -353,46 +345,59 @@ function install_emulator(target) {
|
||||
Log(" availible by checking \'<project_dir>\\cordova\\lib\\list-started-emulators\'", true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
if (target) {
|
||||
launch(path, emulators[0].split(' ', 1)[0], false);
|
||||
}
|
||||
|
||||
function install_target(path) {
|
||||
if(device_id) {
|
||||
var device = false;
|
||||
var emulators = get_started_emulators();
|
||||
var devices = get_devices();
|
||||
var exists = false;
|
||||
for (i in emulators) {
|
||||
if (emulators[i].substr(0,target.length) == target)
|
||||
{
|
||||
if (emulators[i].substr(0,device_id.length) == device_id) {
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!exists) {
|
||||
Log("Error : Unable to find target " + target, true);
|
||||
Log("Please ensure the target exists by checking \'<project>\\cordova\\lib\\list-started-emulators'")
|
||||
}
|
||||
use_target = true;
|
||||
} else {
|
||||
target = emulators[0].split(' ', 1)[0];
|
||||
Log("Deploying to emulator : " + target);
|
||||
}
|
||||
// check if file .apk has been created
|
||||
if (fso.FolderExists(ROOT + '\\bin')) {
|
||||
var path_to_apk;
|
||||
var out_folder = fso.GetFolder(ROOT + '\\bin');
|
||||
var out_files = new Enumerator(out_folder.Files);
|
||||
for (;!out_files.atEnd(); out_files.moveNext()) {
|
||||
var path = out_files.item() + '';
|
||||
if (fso.GetExtensionName(path) == 'apk' && !path.match(/unaligned/)) {
|
||||
path_to_apk = out_files.item();
|
||||
for (i in devices) {
|
||||
if (devices[i].substr(0,device_id.length) == device_id) {
|
||||
exists = true;
|
||||
device = true
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!exists) {
|
||||
Log("Error : Unable to find target " + device_id, true);
|
||||
Log("Please ensure the target exists by checking \'<project>\\cordova\\lib\\list-started-emulators'");
|
||||
Log(" Or \'<project>\\cordova\\lib\\list-devices'");
|
||||
}
|
||||
launch(path, device_id, device);
|
||||
}
|
||||
else {
|
||||
Log("You cannot install to a target without providing a valid target ID.", true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
}
|
||||
|
||||
function launch(path, id, device) {
|
||||
if(id) {
|
||||
var path_to_apk = get_apk(path);
|
||||
if (path_to_apk) {
|
||||
var launch_name = exec_out("%comspec% /c java -jar "+ROOT+"\\cordova\\appinfo.jar "+ROOT+"\\AndroidManifest.xml");
|
||||
var launch_name = exec_out("%comspec% /c java -jar "+path+"\\cordova\\appinfo.jar "+path+"\\AndroidManifest.xml");
|
||||
if (launch_name.error) {
|
||||
Log("Failed to get application name from appinfo.jar + AndroidManifest : ", true);
|
||||
Log("Output : " + launch_name.output, true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
// install on emulator (-e)
|
||||
Log("Installing app on emulator...");
|
||||
var cmd = '%comspec% /c adb -s ' + target + ' install -r ' + path_to_apk;
|
||||
if (device) {
|
||||
// install on device (-d)
|
||||
Log("Installing app on device...");
|
||||
} else {
|
||||
// install on emulator (-e)
|
||||
Log("Installing app on emulator...");
|
||||
}
|
||||
var cmd = '%comspec% /c adb -s ' + id + ' install -r ' + path_to_apk;
|
||||
var install = exec_out(cmd);
|
||||
if ( install.error && install.output.match(/Failure/)) {
|
||||
Log("Error : Could not install apk to emulator : ", true);
|
||||
@@ -402,14 +407,9 @@ function install_emulator(target) {
|
||||
else {
|
||||
Log(install.output);
|
||||
}
|
||||
// run on emulator
|
||||
// launch the application
|
||||
Log("Launching application...");
|
||||
cmd;
|
||||
if (use_target) {
|
||||
cmd = '%comspec% /c adb -s ' + target + ' shell am start -W -a android.intent.action.MAIN -n ' + launch_name.output;
|
||||
} else {
|
||||
cmd = '%comspec% /c adb -s ' + emulators[0].split(' ', 1)[0] + ' shell am start -W -a android.intent.action.MAIN -n ' + launch_name.output
|
||||
}
|
||||
cmd = '%comspec% /c adb -s ' + id + ' shell am start -W -a android.intent.action.MAIN -n ' + launch_name.output;
|
||||
exec_verbose(cmd);
|
||||
}
|
||||
else {
|
||||
@@ -419,43 +419,14 @@ function install_emulator(target) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
Log('Failed to find apk, make sure you project is built and there is an ', true);
|
||||
Log(' apk in <project>\\bin\\. To build your project use \'<project>\\cordova\\build\'', true);
|
||||
Log("You cannot install to a target without providing a valid target ID.", true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
}
|
||||
|
||||
function clean() {
|
||||
function clean(path) {
|
||||
Log("Cleaning project...");
|
||||
exec("%comspec% /c ant.bat clean -f "+ROOT+"\\build.xml 2>&1");
|
||||
}
|
||||
|
||||
function build(build_type) {
|
||||
if (build_type) {
|
||||
switch (build_type) {
|
||||
case "--debug" :
|
||||
clean();
|
||||
Log("Building project...");
|
||||
exec_verbose("%comspec% /c ant.bat debug -f "+ROOT+"\\build.xml 2>&1");
|
||||
break;
|
||||
case "--release" :
|
||||
clean();
|
||||
Log("Building project...");
|
||||
exec_verbose("%comspec% /c ant.bat release -f "+ROOT+"\\build.xml 2>&1");
|
||||
break;
|
||||
case "--nobuild" :
|
||||
Log("Skipping build process.");
|
||||
break;
|
||||
default :
|
||||
Log("Build option not recognized: " + build_type, true);
|
||||
WScript.Quit(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Log("WARNING: [ --debug | --release | --nobuild ] not specified, defaulting to --debug.");
|
||||
exec_verbose("%comspec% /c ant.bat debug -f "+ROOT+"\\build.xml 2>&1");
|
||||
}
|
||||
exec("%comspec% /c ant.bat clean -f "+path+"\\build.xml 2>&1");
|
||||
}
|
||||
|
||||
function log() {
|
||||
@@ -463,131 +434,176 @@ function log() {
|
||||
shell.Run("%comspec% /c adb logcat | grep -v nativeGetEnabledTags");
|
||||
}
|
||||
|
||||
function run(target, build_type) {
|
||||
var use_target = false;
|
||||
if (!target) {
|
||||
Log("WARNING: [ --target=<ID> | --emulator | --device ] not specified, using defaults");
|
||||
}
|
||||
// build application
|
||||
build(build_type);
|
||||
// attempt to deploy to connected device
|
||||
var devices = get_devices();
|
||||
if (devices.length > 0 || target == "--device") {
|
||||
if (target) {
|
||||
if (target.substr(0,9) == "--target=") {
|
||||
install_device(target.split('--target=').join(''))
|
||||
} else if (target == "--device") {
|
||||
install_device();
|
||||
} else {
|
||||
Log("Did not regognize " + target + " as a run option.", true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Log("WARNING: [ --target=<ID> | --emulator | --device ] not specified, using defaults");
|
||||
install_device();
|
||||
}
|
||||
}
|
||||
else {
|
||||
var emulators = get_started_emulators();
|
||||
if (emulators.length > 0) {
|
||||
install_emulator();
|
||||
}
|
||||
else {
|
||||
var emulator_images = get_emulator_images();
|
||||
if (emulator_images.length < 1) {
|
||||
Log('No emulators found, if you would like to create an emulator follow the instructions', true);
|
||||
Log(' provided here : http://developer.android.com/tools/devices/index.html', true);
|
||||
Log(' Or run \'android create avd --name <name> --target <targetID>\' in on the command line.', true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
start_emulator(emulator_images[0].split(' ')[0]);
|
||||
emulators = get_started_emulators();
|
||||
if (emulators.length > 0) {
|
||||
install_emulator();
|
||||
}
|
||||
else {
|
||||
Log("Error : emulator failed to start.", true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
}
|
||||
function build(path) {
|
||||
switch (build_type) {
|
||||
case DEBUG :
|
||||
clean(path);
|
||||
Log("Building project...");
|
||||
exec_verbose("%comspec% /c ant.bat debug -f "+path+"\\build.xml 2>&1");
|
||||
break;
|
||||
case RELEASE :
|
||||
clean(path);
|
||||
Log("Building project...");
|
||||
exec_verbose("%comspec% /c ant.bat release -f "+path+"\\build.xml 2>&1");
|
||||
break;
|
||||
case NO_BUILD :
|
||||
Log("Skipping build process.");
|
||||
break;
|
||||
case NONE :
|
||||
clean(path);
|
||||
Log("WARNING: [ --debug | --release | --nobuild ] not specified, defaulting to --debug.");
|
||||
exec_verbose("%comspec% /c ant.bat debug -f "+path+"\\build.xml 2>&1");
|
||||
break;
|
||||
default :
|
||||
Log("Build option not recognized: " + build_type, true);
|
||||
WScript.Quit(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function run(path) {
|
||||
switch(deploy_type) {
|
||||
case EMULATOR :
|
||||
build(path);
|
||||
if(get_started_emulators().length == 0) {
|
||||
start_emulator();
|
||||
}
|
||||
//TODO : Start emulator if one isn't started, and create one if none exists.
|
||||
install_emulator(path);
|
||||
break;
|
||||
case DEVICE :
|
||||
build(path);
|
||||
install_device(path);
|
||||
break;
|
||||
case TARGET :
|
||||
build(path);
|
||||
install_target(path);
|
||||
break;
|
||||
case NONE :
|
||||
if (get_devices().length > 0) {
|
||||
Log("WARNING: [ --target=<ID> | --emulator | --device ] not specified, defaulting to --device");
|
||||
deploy_type = DEVICE;
|
||||
} else {
|
||||
Log("WARNING: [ --target=<ID> | --emulator | --device ] not specified, defaulting to --emulator");
|
||||
deploy_type = EMULATOR;
|
||||
}
|
||||
run(path);
|
||||
break;
|
||||
default :
|
||||
Log("Deploy option not recognized: " + deploy_type, true);
|
||||
WScript.Quit(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var args = WScript.Arguments;
|
||||
if (args.count() == 0) {
|
||||
Log("Error: no args provided.");
|
||||
WScript.Quit(2);
|
||||
}
|
||||
else {
|
||||
if (args(0) == "build") {
|
||||
if (args.Count() > 1) {
|
||||
build(args(1))
|
||||
} else {
|
||||
build();
|
||||
}
|
||||
} else if (args(0) == "clean") {
|
||||
clean();
|
||||
} else if (args(0) == "list-devices") {
|
||||
list_devices();
|
||||
} else if (args(0) == "list-emulator-images") {
|
||||
list_emulator_images();
|
||||
} else if (args(0) == "list-started-emulators") {
|
||||
list_started_emulators();
|
||||
} else if (args(0) == "start-emulator") {
|
||||
if (args.Count() > 1) {
|
||||
start_emulator(args(1))
|
||||
} else {
|
||||
start_emulator();
|
||||
}
|
||||
} else if (args(0) == "log") {
|
||||
log();
|
||||
} else if (args(0) == "install-emulator") {
|
||||
if (args.Count() == 2) {
|
||||
if (args(1).substr(0,9) == "--target=") {
|
||||
install_emulator(args(1).split('--target=').join(''));
|
||||
} else {
|
||||
Log('Error: \"' + args(1) + '\" is not recognized as an install option', true);
|
||||
WScript.Quit(2);
|
||||
// parse command
|
||||
switch(args(0)) {
|
||||
case "version" :
|
||||
version(ROOT);
|
||||
break;
|
||||
case "build" :
|
||||
if(args.Count() > 1) {
|
||||
if (args(1) == "--release") {
|
||||
build_type = RELEASE;
|
||||
}
|
||||
else if (args(1) == "--debug") {
|
||||
build_type = DEBUG;
|
||||
}
|
||||
else if (args(1) == "--nobuild") {
|
||||
build_type = NO_BUILD;
|
||||
}
|
||||
else {
|
||||
Log('Error: \"' + args(i) + '\" is not recognized as a build option', true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
install_emulator();
|
||||
}
|
||||
} else if (args(0) == "install-device") {
|
||||
if (args.Count() == 2) {
|
||||
if (args(1).substr(0,9) == "--target=") {
|
||||
install_device(args(1).split('--target=').join(''));
|
||||
build(ROOT);
|
||||
break;
|
||||
case "clean" :
|
||||
clean();
|
||||
break;
|
||||
case "list-devices" :
|
||||
list_devices();
|
||||
break;
|
||||
case "list-emulator-images" :
|
||||
list_emulator_images();
|
||||
break;
|
||||
case "list-started-emulators" :
|
||||
list_started_emulators();
|
||||
break;
|
||||
case "start-emulator" :
|
||||
if (args.Count() > 1) {
|
||||
start_emulator(args(1))
|
||||
} else {
|
||||
Log('Error: \"' + args(1) + '\" is not recognized as an install option', true);
|
||||
WScript.Quit(2);
|
||||
start_emulator();
|
||||
}
|
||||
} else {
|
||||
install_device();
|
||||
}
|
||||
} else if (args(0) == "run") {
|
||||
if (args.Count() == 3) {
|
||||
run(args(1), args(2));
|
||||
}
|
||||
else if (args.Count() == 2) {
|
||||
if (args(1).substr(0,9) == "--target=" ||
|
||||
args(1) == "--emulator" ||
|
||||
args(1) == "--device") {
|
||||
run(args(1));
|
||||
} else if (args(1) == "--debug" ||
|
||||
args(1) == "--release" ||
|
||||
args(1) == "--nobuild") {
|
||||
run(null, args(1))
|
||||
break;
|
||||
case "install-emulator" :
|
||||
if (args.Count() == 2) {
|
||||
if (args(1).substr(0,9) == "--target=") {
|
||||
device_id = args(1).split('--target=').join('');
|
||||
install_emulator(ROOT);
|
||||
} else {
|
||||
Log('Error: \"' + args(1) + '\" is not recognized as an install option', true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
} else {
|
||||
Log('Error: \"' + args(1) + '\" is not recognized as a run option', true);
|
||||
WScript.Quit(2);
|
||||
install_emulator(ROOT);
|
||||
}
|
||||
}
|
||||
else {
|
||||
run();
|
||||
}
|
||||
} else {
|
||||
Log('Error: \"' + args(0) + '\" is not recognized as a tooling command', true);
|
||||
WScript.Quit(2);
|
||||
break;
|
||||
case "install-device" :
|
||||
if (args.Count() == 2) {
|
||||
if (args(1).substr(0,9) == "--target=") {
|
||||
device_id = args(1).split('--target=').join('');
|
||||
install_target(ROOT);
|
||||
} else {
|
||||
Log('Error: \"' + args(1) + '\" is not recognized as an install option', true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
} else {
|
||||
install_device(ROOT);
|
||||
}
|
||||
break;
|
||||
case "run" :
|
||||
//parse args
|
||||
for(var i = 1; i < args.Count(); i++) {
|
||||
if (args(i) == "--release") {
|
||||
build_type = RELEASE;
|
||||
}
|
||||
else if (args(i) == "--debug") {
|
||||
build_type = DEBUG;
|
||||
}
|
||||
else if (args(i) == "--nobuild") {
|
||||
build_type = NO_BUILD;
|
||||
}
|
||||
else if (args(i) == "--emulator" || args(i) == "-e") {
|
||||
deploy_type = EMULATOR;
|
||||
}
|
||||
else if (args(i) == "--device" || args(i) == "-d") {
|
||||
deploy_type = DEVICE;
|
||||
}
|
||||
else if (args(i).substr(0,9) == "--target=") {
|
||||
device_id = args(i).split("--target=").join("");
|
||||
deploy_type = TARGET;
|
||||
}
|
||||
else {
|
||||
Log('Error: \"' + args(i) + '\" is not recognized as a run option', true);
|
||||
WScript.Quit(2);
|
||||
}
|
||||
}
|
||||
run(ROOT);
|
||||
break;
|
||||
default :
|
||||
Log("Cordova does not regognize the command " + args(0), true);
|
||||
WScript.Quit(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
18
bin/templates/cordova/version.bat
Normal file
18
bin/templates/cordova/version.bat
Normal file
@@ -0,0 +1,18 @@
|
||||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
@ECHO OFF
|
||||
%~dp0\cordova.bat version %*
|
||||
127
framework/assets/www/cordova.js
vendored
127
framework/assets/www/cordova.js
vendored
@@ -1,5 +1,5 @@
|
||||
// Platform: android
|
||||
// 2.7.0rc1-75-g76065a1
|
||||
// 2.9.0rc1-0-g002f33d
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
@@ -19,7 +19,7 @@
|
||||
under the License.
|
||||
*/
|
||||
;(function() {
|
||||
var CORDOVA_JS_BUILD_LABEL = '2.7.0rc1-75-g76065a1';
|
||||
var CORDOVA_JS_BUILD_LABEL = '2.9.0rc1-0-g002f33d';
|
||||
// file: lib/scripts/require.js
|
||||
|
||||
var require,
|
||||
@@ -2396,11 +2396,7 @@ function initRead(reader, file) {
|
||||
reader._error = null;
|
||||
reader._readyState = FileReader.LOADING;
|
||||
|
||||
if (typeof file == 'string') {
|
||||
// Deprecated in Cordova 2.4.
|
||||
console.warn('Using a string argument with FileReader.readAs functions is deprecated.');
|
||||
reader._fileName = file;
|
||||
} else if (typeof file.fullPath == 'string') {
|
||||
if (typeof file.fullPath == 'string') {
|
||||
reader._fileName = file.fullPath;
|
||||
} else {
|
||||
reader._fileName = '';
|
||||
@@ -3063,9 +3059,31 @@ FileWriter.prototype.abort = function() {
|
||||
/**
|
||||
* Writes data to the file
|
||||
*
|
||||
* @param text to be written
|
||||
* @param data text or blob to be written
|
||||
*/
|
||||
FileWriter.prototype.write = function(text) {
|
||||
FileWriter.prototype.write = function(data) {
|
||||
|
||||
var isBinary = false;
|
||||
|
||||
// If we don't have Blob or ArrayBuffer support, don't bother.
|
||||
if (typeof window.Blob !== 'undefined' && typeof window.ArrayBuffer !== 'undefined') {
|
||||
|
||||
// Check to see if the incoming data is a blob
|
||||
if (data instanceof Blob) {
|
||||
var that=this;
|
||||
var fileReader = new FileReader();
|
||||
fileReader.onload = function() {
|
||||
// Call this method again, with the arraybuffer as argument
|
||||
FileWriter.prototype.write.call(that, this.result);
|
||||
};
|
||||
fileReader.readAsArrayBuffer(data);
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark data type for safer transport over the binary bridge
|
||||
isBinary = (data instanceof ArrayBuffer);
|
||||
}
|
||||
|
||||
// Throw an exception if we are already writing a file
|
||||
if (this.readyState === FileWriter.WRITING) {
|
||||
throw new FileError(FileError.INVALID_STATE_ERR);
|
||||
@@ -3131,7 +3149,7 @@ FileWriter.prototype.write = function(text) {
|
||||
if (typeof me.onwriteend === "function") {
|
||||
me.onwriteend(new ProgressEvent("writeend", {"target":me}));
|
||||
}
|
||||
}, "File", "write", [this.fileName, text, this.position]);
|
||||
}, "File", "write", [this.fileName, data, this.position, isBinary]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -3317,6 +3335,9 @@ InAppBrowser.prototype = {
|
||||
close: function (eventname) {
|
||||
exec(null, null, "InAppBrowser", "close", []);
|
||||
},
|
||||
show: function (eventname) {
|
||||
exec(null, null, "InAppBrowser", "show", []);
|
||||
},
|
||||
addEventListener: function (eventname,f) {
|
||||
if (eventname in this.channels) {
|
||||
this.channels[eventname].subscribe(f);
|
||||
@@ -6780,11 +6801,21 @@ require('cordova/channel').onNativeReady.fire();
|
||||
}
|
||||
}
|
||||
|
||||
function scriptErrorCallback(err) {
|
||||
// Open Question: If a script path specified in cordova_plugins.js does not exist, do we fail for all?
|
||||
// this is currently just continuing.
|
||||
scriptCounter--;
|
||||
if (scriptCounter === 0) {
|
||||
onScriptLoadingComplete && onScriptLoadingComplete();
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to inject a <script> tag.
|
||||
function injectScript(path) {
|
||||
scriptCounter++;
|
||||
var script = document.createElement("script");
|
||||
script.onload = scriptLoadedCallback;
|
||||
script.onerror = scriptErrorCallback;
|
||||
script.src = path;
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
@@ -6796,10 +6827,10 @@ require('cordova/channel').onNativeReady.fire();
|
||||
context.cordova.require('cordova/channel').onPluginsReady.fire();
|
||||
}
|
||||
|
||||
// Handler for the cordova_plugins.json content.
|
||||
// Handler for the cordova_plugins.js content.
|
||||
// See plugman's plugin_loader.js for the details of this object.
|
||||
// This function is only called if the really is a plugins array that isn't empty.
|
||||
// Otherwise the XHR response handler will just call finishPluginLoading().
|
||||
// Otherwise the onerror response handler will just call finishPluginLoading().
|
||||
function handlePluginsObject(modules, path) {
|
||||
// First create the callback for when all plugins are loaded.
|
||||
var mapper = context.cordova.require('cordova/modulemapper');
|
||||
@@ -6807,26 +6838,31 @@ require('cordova/channel').onNativeReady.fire();
|
||||
// Loop through all the plugins and then through their clobbers and merges.
|
||||
for (var i = 0; i < modules.length; i++) {
|
||||
var module = modules[i];
|
||||
if (!module) continue;
|
||||
if (module) {
|
||||
try {
|
||||
if (module.clobbers && module.clobbers.length) {
|
||||
for (var j = 0; j < module.clobbers.length; j++) {
|
||||
mapper.clobbers(module.id, module.clobbers[j]);
|
||||
}
|
||||
}
|
||||
|
||||
if (module.clobbers && module.clobbers.length) {
|
||||
for (var j = 0; j < module.clobbers.length; j++) {
|
||||
mapper.clobbers(module.id, module.clobbers[j]);
|
||||
if (module.merges && module.merges.length) {
|
||||
for (var k = 0; k < module.merges.length; k++) {
|
||||
mapper.merges(module.id, module.merges[k]);
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, if runs is truthy we want to simply require() the module.
|
||||
// This can be skipped if it had any merges or clobbers, though,
|
||||
// since the mapper will already have required the module.
|
||||
if (module.runs && !(module.clobbers && module.clobbers.length) && !(module.merges && module.merges.length)) {
|
||||
context.cordova.require(module.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (module.merges && module.merges.length) {
|
||||
for (var k = 0; k < module.merges.length; k++) {
|
||||
mapper.merges(module.id, module.merges[k]);
|
||||
catch(err) {
|
||||
// error with module, most likely clobbers, should we continue?
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, if runs is truthy we want to simply require() the module.
|
||||
// This can be skipped if it had any merges or clobbers, though,
|
||||
// since the mapper will already have required the module.
|
||||
if (module.runs && !(module.clobbers && module.clobbers.length) && !(module.merges && module.merges.length)) {
|
||||
context.cordova.require(module.id);
|
||||
}
|
||||
}
|
||||
|
||||
finishPluginLoading();
|
||||
@@ -6849,6 +6885,33 @@ require('cordova/channel').onNativeReady.fire();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var plugins_json = path + 'cordova_plugins.json';
|
||||
var plugins_js = path + 'cordova_plugins.js';
|
||||
|
||||
// One some phones (Windows) this xhr.open throws an Access Denied exception
|
||||
// So lets keep trying, but with a script tag injection technique instead of XHR
|
||||
var injectPluginScript = function injectPluginScript() {
|
||||
try {
|
||||
var script = document.createElement("script");
|
||||
script.onload = function(){
|
||||
var list = cordova.require("cordova/plugin_list");
|
||||
handlePluginsObject(list,path);
|
||||
};
|
||||
script.onerror = function() {
|
||||
// Error loading cordova_plugins.js, file not found or something
|
||||
// this is an acceptable error, pre-3.0.0, so we just move on.
|
||||
finishPluginLoading();
|
||||
};
|
||||
script.src = plugins_js;
|
||||
document.head.appendChild(script);
|
||||
|
||||
} catch(err){
|
||||
finishPluginLoading();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Try to XHR the cordova_plugins.json file asynchronously.
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onload = function() {
|
||||
@@ -6867,14 +6930,16 @@ require('cordova/channel').onNativeReady.fire();
|
||||
}
|
||||
};
|
||||
xhr.onerror = function() {
|
||||
finishPluginLoading();
|
||||
// In this case, the json file was not present, but XHR was allowed,
|
||||
// so we should still try the script injection technique with the js file
|
||||
// in case that is there.
|
||||
injectPluginScript();
|
||||
};
|
||||
var plugins_json = path + 'cordova_plugins.json';
|
||||
try { // we commented we were going to try, so let us actually try and catch
|
||||
xhr.open('GET', plugins_json, true); // Async
|
||||
xhr.send();
|
||||
} catch(err){
|
||||
finishPluginLoading();
|
||||
injectPluginScript();
|
||||
}
|
||||
}(window));
|
||||
|
||||
|
||||
@@ -188,6 +188,17 @@ public class CordovaWebViewClient extends WebViewClient {
|
||||
LOG.e(TAG, "Error sending sms " + url + ":" + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
//Android Market
|
||||
else if(url.startsWith("market:")) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(url));
|
||||
this.cordova.getActivity().startActivity(intent);
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
LOG.e(TAG, "Error loading Google Play Store: " + url, e);
|
||||
}
|
||||
}
|
||||
|
||||
// All else
|
||||
else {
|
||||
|
||||
@@ -38,7 +38,7 @@ import android.telephony.TelephonyManager;
|
||||
public class Device extends CordovaPlugin {
|
||||
public static final String TAG = "Device";
|
||||
|
||||
public static String cordovaVersion = "dev"; // Cordova version
|
||||
public static String cordovaVersion = "2.9.0rc1"; // Cordova version
|
||||
public static String platform = "Android"; // Device OS
|
||||
public static String uuid; // Device UUID
|
||||
|
||||
|
||||
Reference in New Issue
Block a user