You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2013/03/05 23:37:12 UTC
[2/2] android commit: CB-2623: Added partial work on update script
Updated Branches:
refs/heads/master 7caac3265 -> 9a71cc5b4
CB-2623: Added partial work on update script
Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/9a71cc5b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/9a71cc5b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/9a71cc5b
Branch: refs/heads/master
Commit: 9a71cc5b4ef7b53ccd62087e36bb312ef3ca9b8e
Parents: c543b74
Author: Joe Bowser <bo...@apache.org>
Authored: Tue Mar 5 14:36:52 2013 -0800
Committer: Joe Bowser <bo...@apache.org>
Committed: Tue Mar 5 14:36:52 2013 -0800
----------------------------------------------------------------------
bin/update.bat | 32 ++++++++
bin/update.js | 203 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 235 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/9a71cc5b/bin/update.bat
----------------------------------------------------------------------
diff --git a/bin/update.bat b/bin/update.bat
new file mode 100644
index 0000000..a61fd26
--- /dev/null
+++ b/bin/update.bat
@@ -0,0 +1,32 @@
+:: 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
+IF NOT DEFINED JAVA_HOME GOTO MISSING
+FOR %%X in (java.exe javac.exe ant.bat android.bat) do (
+ SET FOUND=%%~$PATH:X
+ IF NOT DEFINED FOUND GOTO MISSING
+)
+cscript "%~dp0\update.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
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/9a71cc5b/bin/update.js
----------------------------------------------------------------------
diff --git a/bin/update.js b/bin/update.js
new file mode 100644
index 0000000..a1a367e
--- /dev/null
+++ b/bin/update.js
@@ -0,0 +1,203 @@
+/*
+ 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.
+*/
+
+/*
+ * create a cordova/android project
+ *
+ * USAGE
+ * ./update [path]
+ */
+
+var fso = WScript.CreateObject('Scripting.FileSystemObject');
+
+function read(filename) {
+ var fso=WScript.CreateObject("Scripting.FileSystemObject");
+ var f=fso.OpenTextFile(filename, 1);
+ var s=f.ReadAll();
+ f.Close();
+ return s;
+}
+
+function checkTargets(targets) {
+ if(!targets) {
+ WScript.Echo("You do not have any android targets setup. Please create at least one target with the `android` command");
+ WScript.Quit(69);
+ }
+}
+
+function setTarget() {
+ var targets = shell.Exec('android.bat list targets').StdOut.ReadAll().match(/id:\s\d+/g);
+ checkTargets(targets);
+ return targets[targets.length - 1].replace(/id: /, ""); // TODO: give users the option to set their target
+}
+
+function setApiLevel() {
+ var targets = shell.Exec('android.bat list targets').StdOut.ReadAll().match(/API level:\s\d+/g);
+ checkTargets(targets);
+ return targets[targets.length - 1].replace(/API level: /, "");
+}
+
+function write(filename, contents) {
+ var fso=WScript.CreateObject("Scripting.FileSystemObject");
+ var f=fso.OpenTextFile(filename, 2, true);
+ f.Write(contents);
+ f.Close();
+}
+
+function replaceInFile(filename, regexp, replacement) {
+ write(filename, read(filename).replace(regexp, replacement));
+}
+
+function exec(command) {
+ var oShell=shell.Exec(command);
+ while (oShell.Status == 0) {
+ if(!oShell.StdOut.AtEndOfStream) {
+ var line = oShell.StdOut.ReadLine();
+ // XXX: Change to verbose mode
+ // WScript.StdOut.WriteLine(line);
+ }
+ WScript.sleep(100);
+ }
+}
+
+function createAppInfoJar() {
+ if(!fso.FileExists(ROOT+"\\bin\\templates\\cordova\\appinfo.jar")) {
+ WScript.Echo("Creating appinfo.jar...");
+ var cur = shell.CurrentDirectory;
+ shell.CurrentDirectory = ROOT+"\\bin\\templates\\cordova\\ApplicationInfo";
+ exec("javac ApplicationInfo.java");
+ exec("jar -cfe ..\\appinfo.jar ApplicationInfo ApplicationInfo.class");
+ shell.CurrentDirectory = cur;
+ }
+}
+
+function cleanup() {
+ 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');
+ }
+}
+
+function downloadCommonsCodec() {
+ if (!fso.FileExists(ROOT + '\\framework\\libs\\commons-codec-1.7.jar')) {
+ // We need the .jar
+ var url = 'http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.7-bin.zip';
+ var libsPath = ROOT + '\\framework\\libs';
+ var savePath = libsPath + '\\commons-codec-1.7-bin.zip';
+ if (!fso.FileExists(savePath)) {
+ if(!fso.FolderExists(ROOT + '\\framework\\libs')) {
+ fso.CreateFolder(libsPath);
+ }
+ // We need the zip to get the jar
+ var xhr = WScript.CreateObject('MSXML2.XMLHTTP');
+ xhr.open('GET', url, false);
+ xhr.send();
+ if (xhr.status == 200) {
+ var stream = WScript.CreateObject('ADODB.Stream');
+ stream.Open();
+ stream.Type = 1;
+ stream.Write(xhr.ResponseBody);
+ stream.Position = 0;
+ stream.SaveToFile(savePath);
+ stream.Close();
+ } else {
+ WScript.Echo('Could not retrieve the commons-codec. Please download it yourself and put into the framework/libs directory. This process may fail now. Sorry.');
+ }
+ }
+ var app = WScript.CreateObject('Shell.Application');
+ var source = app.NameSpace(savePath).Items();
+ var target = app.NameSpace(ROOT + '\\framework\\libs');
+ target.CopyHere(source, 256);
+
+ // Move the jar into libs
+ fso.MoveFile(ROOT + '\\framework\\libs\\commons-codec-1.7\\commons-codec-1.7.jar', ROOT + '\\framework\\libs\\commons-codec-1.7.jar');
+
+ // Clean up
+ fso.DeleteFile(ROOT + '\\framework\\libs\\commons-codec-1.7-bin.zip');
+ fso.DeleteFolder(ROOT + '\\framework\\libs\\commons-codec-1.7', true);
+ }
+}
+
+var args = WScript.Arguments, PROJECT_PATH="example",
+ PACKAGE="org.apache.cordova.example", ACTIVITY="cordovaExample",
+ shell=WScript.CreateObject("WScript.Shell");
+
+// working dir
+var ROOT = WScript.ScriptFullName.split('\\bin\\create.js').join('');
+
+if (args.Count() == 3) {
+ PROJECT_PATH=args(0);
+ PACKAGE=args(1);
+ ACTIVITY=args(2);
+}
+
+if(fso.FolderExists(PROJECT_PATH)) {
+ WScript.Echo("Project already exists!");
+ WScript.Quit(1);
+}
+
+var PACKAGE_AS_PATH=PACKAGE.replace(/\./g, '\\');
+var ACTIVITY_PATH=PROJECT_PATH+'\\src\\'+PACKAGE_AS_PATH+'\\'+ACTIVITY+'.java';
+var MANIFEST_PATH=PROJECT_PATH+'\\AndroidManifest.xml';
+var TARGET=setTarget();
+var API_LEVEL=setApiLevel();
+var VERSION=read(ROOT+'\\VERSION').replace(/\r\n/,'').replace(/\n/,'');
+
+// build from source. distro should have these files
+if (!fso.FileExists(ROOT+'\\cordova-'+VERSION+'.jar') &&
+ !fso.FileExists(ROOT+'\\cordova-'+VERSION+'.js')) {
+ WScript.Echo("Building jar and js files...");
+ // update the cordova framework project to a target that exists on this machine
+ exec('android.bat update project --target '+TARGET+' --path '+ROOT+'\\framework');
+ // pull down commons codec if necessary
+ downloadCommonsCodec();
+ exec('ant.bat -f \"'+ ROOT +'\\framework\\build.xml\" jar');
+}
+
+// check if we have the source or the distro files
+WScript.Echo("Copying js, jar & config.xml files...");
+if(fso.FolderExists(ROOT + '\\framework')) {
+ exec('%comspec% /c copy "'+ROOT+'"\\framework\\assets\\www\\cordova-'+VERSION+'.js '+PROJECT_PATH+'\\assets\\www\\cordova-'+VERSION+'.js /Y');
+ exec('%comspec% /c copy "'+ROOT+'"\\framework\\cordova-'+VERSION+'.jar '+PROJECT_PATH+'\\libs\\cordova-'+VERSION+'.jar /Y');
+ fso.CreateFolder(PROJECT_PATH + '\\res\\xml');
+ exec('%comspec% /c copy "'+ROOT+'"\\framework\\res\\xml\\config.xml ' + PROJECT_PATH + '\\res\\xml\\config.xml /Y');
+} else {
+ // copy in cordova.js
+ exec('%comspec% /c copy "'+ROOT+'"\\cordova-'+VERSION+'.js '+PROJECT_PATH+'\\assets\\www\\cordova-'+VERSION+'.js /Y');
+ // copy in cordova.jar
+ exec('%comspec% /c copy "'+ROOT+'"\\cordova-'+VERSION+'.jar '+PROJECT_PATH+'\\libs\\cordova-'+VERSION+'.jar /Y');
+ // copy in xml
+ fso.CreateFolder(PROJECT_PATH + '\\res\\xml');
+ exec('%comspec% /c copy "'+ROOT+'"\\xml\\config.xml ' + PROJECT_PATH + '\\res\\xml\\config.xml /Y');
+}
+
+// update cordova scripts
+createAppInfoJar();
+WScript.Echo("Copying cordova command tools...");
+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\\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');
+
+cleanup();