diff --git a/bin/create.js b/bin/create.js index fcce4786..35d4fd79 100644 --- a/bin/create.js +++ b/bin/create.js @@ -142,32 +142,32 @@ downloadCommonsCodec(); exec('ant.bat -f '+ ROOT +'\\framework\\build.xml jar'); // copy in the project template -exec('cmd /c xcopy '+ ROOT + '\\bin\\templates\\project\\res '+PROJECT_PATH+'\\res\\ /E /Y'); -exec('cmd /c xcopy '+ ROOT + '\\bin\\templates\\project\\assets '+PROJECT_PATH+'\\assets\\ /E /Y'); -exec('cmd /c copy '+ROOT+'\\bin\\templates\\project\\AndroidManifest.xml ' + PROJECT_PATH + '\\AndroidManifest.xml /Y'); -exec('cmd /c copy '+ROOT+'\\bin\\templates\\project\\Activity.java '+ ACTIVITY_PATH +' /Y'); +exec('%comspec% /c xcopy '+ ROOT + '\\bin\\templates\\project\\res '+PROJECT_PATH+'\\res\\ /E /Y'); +exec('%comspec% /c xcopy '+ ROOT + '\\bin\\templates\\project\\assets '+PROJECT_PATH+'\\assets\\ /E /Y'); +exec('%comspec% /c copy '+ROOT+'\\bin\\templates\\project\\AndroidManifest.xml ' + PROJECT_PATH + '\\AndroidManifest.xml /Y'); +exec('%comspec% /c copy '+ROOT+'\\bin\\templates\\project\\Activity.java '+ ACTIVITY_PATH +' /Y'); // copy in cordova.js -exec('cmd /c copy '+ROOT+'\\framework\\assets\\www\\cordova-'+VERSION+'.js '+PROJECT_PATH+'\\assets\\www\\cordova-'+VERSION+'.js /Y'); +exec('%comspec% /c copy '+ROOT+'\\framework\\assets\\www\\cordova-'+VERSION+'.js '+PROJECT_PATH+'\\assets\\www\\cordova-'+VERSION+'.js /Y'); // copy in cordova.jar -exec('cmd /c copy '+ROOT+'\\framework\\cordova-'+VERSION+'.jar '+PROJECT_PATH+'\\libs\\cordova-'+VERSION+'.jar /Y'); +exec('%comspec% /c copy '+ROOT+'\\framework\\cordova-'+VERSION+'.jar '+PROJECT_PATH+'\\libs\\cordova-'+VERSION+'.jar /Y'); // copy in xml fso.CreateFolder(PROJECT_PATH + '\\res\\xml'); -exec('cmd /c copy '+ROOT+'\\framework\\res\\xml\\cordova.xml ' + PROJECT_PATH + '\\res\\xml\\cordova.xml /Y'); -exec('cmd /c copy '+ROOT+'\\framework\\res\\xml\\plugins.xml ' + PROJECT_PATH + '\\res\\xml\\plugins.xml /Y'); +exec('%comspec% /c copy '+ROOT+'\\framework\\res\\xml\\cordova.xml ' + PROJECT_PATH + '\\res\\xml\\cordova.xml /Y'); +exec('%comspec% /c copy '+ROOT+'\\framework\\res\\xml\\plugins.xml ' + PROJECT_PATH + '\\res\\xml\\plugins.xml /Y'); // copy cordova scripts fso.CreateFolder(PROJECT_PATH + '\\cordova'); -exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\appinfo.jar ' + PROJECT_PATH + '\\cordova\\appinfo.jar /Y'); -exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\cordova.js ' + PROJECT_PATH + '\\cordova\\cordova.js /Y'); -exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\cordova.bat ' + PROJECT_PATH + '\\cordova\\cordova.bat /Y'); -exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\clean.bat ' + PROJECT_PATH + '\\cordova\\clean.bat /Y'); -exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\debug.bat ' + PROJECT_PATH + '\\cordova\\debug.bat /Y'); -exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\log.bat ' + PROJECT_PATH + '\\cordova\\log.bat /Y'); -exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\emulate.bat ' + PROJECT_PATH + '\\cordova\\emulate.bat /Y'); -exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\BOOM.bat ' + PROJECT_PATH + '\\cordova\\BOOM.bat /Y'); +exec('%comspec% /c copy '+ROOT+'\\bin\\templates\\cordova\\appinfo.jar ' + PROJECT_PATH + '\\cordova\\appinfo.jar /Y'); +exec('%comspec% /c copy '+ROOT+'\\bin\\templates\\cordova\\cordova.js ' + PROJECT_PATH + '\\cordova\\cordova.js /Y'); +exec('%comspec% /c copy '+ROOT+'\\bin\\templates\\cordova\\cordova.bat ' + PROJECT_PATH + '\\cordova\\cordova.bat /Y'); +exec('%comspec% /c copy '+ROOT+'\\bin\\templates\\cordova\\clean.bat ' + PROJECT_PATH + '\\cordova\\clean.bat /Y'); +exec('%comspec% /c copy '+ROOT+'\\bin\\templates\\cordova\\debug.bat ' + PROJECT_PATH + '\\cordova\\debug.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\\emulate.bat ' + PROJECT_PATH + '\\cordova\\emulate.bat /Y'); +exec('%comspec% /c copy '+ROOT+'\\bin\\templates\\cordova\\BOOM.bat ' + PROJECT_PATH + '\\cordova\\BOOM.bat /Y'); // interpolate the activity name and package replaceInFile(ACTIVITY_PATH, /__ACTIVITY__/, ACTIVITY); diff --git a/bin/templates/cordova/ApplicationInfo/ApplicationInfo.class b/bin/templates/cordova/ApplicationInfo/ApplicationInfo.class index 6b854f7d..5ad90f5c 100644 Binary files a/bin/templates/cordova/ApplicationInfo/ApplicationInfo.class 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 index 9a663217..21a0787e 100644 --- a/bin/templates/cordova/ApplicationInfo/ApplicationInfo.java +++ b/bin/templates/cordova/ApplicationInfo/ApplicationInfo.java @@ -21,7 +21,7 @@ public class ApplicationInfo { // 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)); + System.out.println(String.format("%s/.%s", pakkage, activity.replace(".", ""))); } catch(ParserConfigurationException pce) { pce.printStackTrace(); } catch(SAXException se) { diff --git a/bin/templates/cordova/ApplicationInfo/manifest.txt b/bin/templates/cordova/ApplicationInfo/manifest.txt deleted file mode 100644 index 7d77999c..00000000 --- a/bin/templates/cordova/ApplicationInfo/manifest.txt +++ /dev/null @@ -1 +0,0 @@ -Main-Class: ApplicationInfo diff --git a/bin/templates/cordova/BOOM.bat b/bin/templates/cordova/BOOM.bat index e69de29b..87b10426 100644 --- a/bin/templates/cordova/BOOM.bat +++ b/bin/templates/cordova/BOOM.bat @@ -0,0 +1 @@ +%~dp0\cordova.bat BOOM diff --git a/bin/templates/cordova/appinfo.jar b/bin/templates/cordova/appinfo.jar index 4116f48c..37e00dfc 100644 Binary files a/bin/templates/cordova/appinfo.jar and b/bin/templates/cordova/appinfo.jar differ diff --git a/bin/templates/cordova/clean.bat b/bin/templates/cordova/clean.bat index e69de29b..8194b33a 100644 --- a/bin/templates/cordova/clean.bat +++ b/bin/templates/cordova/clean.bat @@ -0,0 +1 @@ +%~dp0\cordova.bat clean diff --git a/bin/templates/cordova/cordova.bat b/bin/templates/cordova/cordova.bat index e69de29b..61641316 100644 --- a/bin/templates/cordova/cordova.bat +++ b/bin/templates/cordova/cordova.bat @@ -0,0 +1,15 @@ +@ECHO OFF +IF NOT DEFINED JAVA_HOME GOTO MISSING +FOR %%X in (java.exe ant.bat android.bat) do ( + SET FOUND=%%~$PATH:X + IF NOT DEFINED FOUND GOTO MISSING +) +cscript %~dp0\cordova.js %* +GOTO END +:MISSING +ECHO Missing one of the following: +ECHO JDK: http://java.oracle.com +ECHO Android SDK: http://developer.android.com +ECHO Apache ant: http://ant.apache.org +EXIT /B 1 +:END diff --git a/bin/templates/cordova/cordova.js b/bin/templates/cordova/cordova.js index 64357072..6353b55d 100644 --- a/bin/templates/cordova/cordova.js +++ b/bin/templates/cordova/cordova.js @@ -1,35 +1,42 @@ -var ROOT = WScript.ScriptFullName.split('\\bin\\templates\\cordova\\cordova.js').join(''), +var ROOT = WScript.ScriptFullName.split('\\cordova\\cordova.js').join(''), shell=WScript.CreateObject("WScript.Shell"); function exec(command) { var oExec=shell.Exec(command); - var output = ''; - while (!oExec.StdOut.AtEndOfStream) { - output += oExec.StdOut.ReadLine(); + var output = new String(); + while(oExec.Status == 0) { + if(!oExec.StdOut.AtEndOfStream) { + var line = oExec.StdOut.ReadLine(); + // XXX: Change to verbose mode + //WScript.StdOut.WriteLine(line); + output += line; + } + WScript.sleep(100); } + return output; } -function devices_running() { - var local_devices = exec("adb devices"); - if(local_devices.match(/device |emulator /)) { +function emulator_running() { + var local_devices = shell.Exec("%comspec% /c adb devices").StdOut.ReadAll(); + if(local_devices.match(/emulator/)) { return true; } return false; } function emulate() { // don't run emulator if a device is plugged in or if emulator is already running - if(devices_running()) { + if(emulator_running()) { WScript.Echo("Device or Emulator already running!"); return; } - var oExec = shell.Exec("android.bat list avd"); + var oExec = shell.Exec("%comspec% /c android.bat list avd"); var avd_list = []; var avd_id = -10; while(!oExec.StdOut.AtEndOfStream) { var output = oExec.StdOut.ReadLine(); if(output.match(/Name: (.)*/)) { - avd_list.push(output.replace(/\sName:\s/, "")); + avd_list.push(output.replace(/ *Name:\s/, "")); } } // user has no AVDs @@ -41,7 +48,7 @@ function emulate() { // user has only one AVD so we launch that one if(avd_list.length == 1) { - exec("emulator.bat -cpu-delay 0 -no-boot-anim -cache /tmp/cache -avd "+avd_list[0]+" > NUL"); + shell.Run("emulator -cpu-delay 0 -no-boot-anim -cache %Temp%\cache -avd "+avd_list[0]); } // user has more than one avd so we ask them to choose @@ -55,34 +62,35 @@ function emulate() { avd_id = new Number(WScript.StdIn.ReadLine()); } - WScript.Echo("emulator.bat -cpu-delay 0 -no-boot-anim -cache /tmp/cache -avd "+avd_list[avd_id]+" > NUL"); + shell.Run("emulator -cpu-delay 0 -no-boot-anim -cache %Temp%\\cache -avd "+avd_list[avd_id], 0, false); } } function clean() { - WScript.Echo(exec("ant.bat clean")); + exec("%comspec% /c ant.bat clean -f "+ROOT+"\\build.xml 2>&1"); } function debug() { - WScript.Echo(exec("ant.bat debug")); + exec("%comspec% /c ant.bat debug -f "+ROOT+"\\build.xml 2>&1"); } function debug_install() { - WScript.Echo(exec("ant.bat debug install")); + exec("%comspec% /c ant.bat debug install -f "+ROOT+"\\build.xml 2>&1"); } function log() { - WScript.Echo(exec("adb.bat logcat")); + WScript.Echo(exec("%comspec% /c adb.bat logcat")); } function launch() { - var launch_str=exec("java -jar "+ROOT+"\\cordova\\appinfo.jar "+ROOT+"\\AndroidManifest.xml") - exec("adb.bat shell am start -n "+launch_str); + var launch_str=exec("%comspec% /c java -jar "+ROOT+"\\cordova\\appinfo.jar "+ROOT+"\\AndroidManifest.xml"); + //WScript.Echo(launch_str); + exec("%comspec% /c adb shell am start -n "+launch_str+" 2>&1"); } function BOOM() { - clean(); - if(devices_running()) { + clean(); + if(emulator_running()) { debug_install(); launch(); } else { @@ -92,5 +100,9 @@ function BOOM() { WScript.Echo("##################################################################"); } } - -emulate(); +var args = WScript.Arguments; +if(args.count() != 1) { + WScript.StdErr.Write("An error has occured!\n"); + WScript.Quit(1); +} +eval(args(0)+"()"); diff --git a/bin/templates/cordova/debug.bat b/bin/templates/cordova/debug.bat index e69de29b..ff5edc2c 100644 --- a/bin/templates/cordova/debug.bat +++ b/bin/templates/cordova/debug.bat @@ -0,0 +1 @@ +%~dp0\cordova.bat debug diff --git a/bin/templates/cordova/emulate.bat b/bin/templates/cordova/emulate.bat index e69de29b..87ef969f 100644 --- a/bin/templates/cordova/emulate.bat +++ b/bin/templates/cordova/emulate.bat @@ -0,0 +1 @@ +%~dp0\cordova.bat emulate