You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pm...@apache.org on 2012/03/15 14:47:19 UTC
git commit: CB-314 - create errgen platform
Updated Branches:
refs/heads/master 3beb47078 -> 574da1a65
CB-314 - create errgen platform
https://issues.apache.org/jira/browse/CB-314
This is a work-in-progress, only a couple of tests and overrides
have been implemented. Decent start.
Some drive-by enhancements:
- Added a .wr file - see: https://github.com/pmuellr/wr
- Moved the require()'s in the Jakefile to the top
- Added a new Jakefile subtask to ensure we're in the right
directory before running. Things broke if you weren't in
the base directory
- Added a new 'dalek' task for Dalek lovers everywhere
- Now that there's a separate 'dalek' task, it's function
can be removed from the 'build' task
- Made the build use the correct Apache license source header
stuff ala http://www.apache.org/legal/src-headers.html#headers
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/574da1a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/574da1a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/574da1a6
Branch: refs/heads/master
Commit: 574da1a6512636b412078ae02d29308dd184ffc2
Parents: 3beb470
Author: Patrick Mueller <pm...@apache.org>
Authored: Thu Mar 15 09:41:27 2012 -0400
Committer: Patrick Mueller <pm...@apache.org>
Committed: Thu Mar 15 09:41:27 2012 -0400
----------------------------------------------------------------------
.wr | 34 ++++++++++++
Jakefile | 31 ++++++++---
LICENSE-for-js-file.txt | 16 ++++++
build/packager.js | 6 ++-
lib/bootstrap/errgen.js | 20 +++++++
lib/exec/errgen.js | 107 ++++++++++++++++++++++++++++++++++++++
lib/platform/errgen.js | 28 ++++++++++
lib/plugin/errgen/device.js | 42 +++++++++++++++
test/errgen/errgen-tests.js | 86 ++++++++++++++++++++++++++++++
test/errgen/index.html | 75 ++++++++++++++++++++++++++
10 files changed, 434 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/574da1a6/.wr
----------------------------------------------------------------------
diff --git a/.wr b/.wr
new file mode 100644
index 0000000..02bb789
--- /dev/null
+++ b/.wr
@@ -0,0 +1,34 @@
+# ------------------------------------------------------------------------------
+# 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.
+# ------------------------------------------------------------------------------
+
+# ------------------------------------------------------------------------------
+# a .wr file to rebuild cordova when a source file changes
+# see: https://github.com/pmuellr/wr
+# npm install wr
+# ------------------------------------------------------------------------------
+
+--stdoutcolor blue
+--stderrcolor red
+
+jake
+
+build
+Jakefile
+lib
+test
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/574da1a6/Jakefile
----------------------------------------------------------------------
diff --git a/Jakefile b/Jakefile
index 49266aa..af05af6 100644
--- a/Jakefile
+++ b/Jakefile
@@ -1,12 +1,14 @@
+var util = require('util')
+var fs = require('fs')
+var childProcess = require('child_process')
+var path = require("path")
desc("runs build");
task('default', ['build', 'test'], function () {});
desc("clean");
-task('clean', [], function () {
- var childProcess = require('child_process');
- var path = require("path");
+task('clean', ['set-cwd'], function () {
var DEPLOY = path.join(__dirname,"pkg");
var cmd = 'rm -rf ' + DEPLOY + ' && ' +
@@ -18,21 +20,32 @@ task('clean', [], function () {
desc("compiles the source files for all extensions");
task('build', ['clean'], function () {
- var util = require('util'),
- fs = require('fs'),
- packager = require("./build/packager");
+ var packager = require("./build/packager");
packager.write("blackberry");
packager.write("playbook");
packager.write("ios");
packager.write("wp7");
packager.write("android");
+ packager.write("errgen");
- util.puts(fs.readFileSync("build/dalek", "utf-8"));
});
+desc("prints a dalek");
+task('dalek', ['set-cwd'], function () {
+ util.puts(fs.readFileSync("build/dalek", "utf-8"));
+})
+
desc("runs the unit tests in node");
-task('test', [], require('./test/runner').node);
+task('test', ['set-cwd'], require('./test/runner').node);
desc("starts a webserver to point at to run the unit tests");
-task('btest', [], require('./test/runner').browser);
+task('btest', ['set-cwd'], require('./test/runner').browser);
+
+desc("make sure we're in the right directory");
+task('set-cwd', [], function() {
+ if (__dirname != process.cwd()) {
+ process.chdir(__dirname)
+ }
+});
+
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/574da1a6/LICENSE-for-js-file.txt
----------------------------------------------------------------------
diff --git a/LICENSE-for-js-file.txt b/LICENSE-for-js-file.txt
new file mode 100644
index 0000000..20f533b
--- /dev/null
+++ b/LICENSE-for-js-file.txt
@@ -0,0 +1,16 @@
+ 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.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/574da1a6/build/packager.js
----------------------------------------------------------------------
diff --git a/build/packager.js b/build/packager.js
index b3933a7..39a9704 100644
--- a/build/packager.js
+++ b/build/packager.js
@@ -95,11 +95,13 @@ module.exports = {
},
bundle: function (platform) {
+ console.log("building platform: " + platform);
+
var output = "";
//include LICENSE
- output += include("LICENSE", function (file) {
- return "/*\n" + file + "\n*/\n";
+ output += include("LICENSE-for-js-file.txt", function (file) {
+ return "/*\n" + file + "*/\n";
});
// wrap the entire thing in one more closure
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/574da1a6/lib/bootstrap/errgen.js
----------------------------------------------------------------------
diff --git a/lib/bootstrap/errgen.js b/lib/bootstrap/errgen.js
new file mode 100644
index 0000000..cc479e8
--- /dev/null
+++ b/lib/bootstrap/errgen.js
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+require('cordova/channel').onNativeReady.fire()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/574da1a6/lib/exec/errgen.js
----------------------------------------------------------------------
diff --git a/lib/exec/errgen.js b/lib/exec/errgen.js
new file mode 100644
index 0000000..dc47fcb
--- /dev/null
+++ b/lib/exec/errgen.js
@@ -0,0 +1,107 @@
+/*
+ * 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.
+ */
+
+/**
+ * Execute a cordova command. It is up to the native side whether this action
+ * is synchronous or asynchronous. The native side can return:
+ * Synchronous: PluginResult object as a JSON string
+ * Asynchrounous: Empty string ""
+ * If async, the native side will cordova.callbackSuccess or cordova.callbackError,
+ * depending upon the result of the action.
+ *
+ * @param {Function} success The success callback
+ * @param {Function} fail The fail callback
+ * @param {String} service The name of the service to use
+ * @param {String} action Action to be run in cordova
+ * @param {String[]} [args] Zero or more arguments to pass to the method
+ */
+
+//------------------------------------------------------------------------------
+module.exports = function exec(success, fail, service, action, args) {
+ var signature = service + "::" + action
+
+ //--------------------------------------------------------------------------
+ function callFail() {
+ var args = "<unable to JSONify>"
+
+ try {
+ args = JSON.stringify(args)
+ }
+ catch (e) {}
+
+ var call = signature + "(" + args + ")"
+
+ if (!fail) {
+ console.log("failure callback not set for " + call)
+ return
+ }
+
+ if (typeof(fail) != 'function') {
+ console.log("failure callback not a function for " + call)
+ return
+ }
+
+ try {
+ fail("expected errgen failure for " + call)
+ }
+ catch (e) {
+ console.log("exception running failure callback for " + call)
+ console.log(" exception: " + e)
+ return
+ }
+ }
+
+ //--------------------------------------------------------------------------
+ if (Overrides[signature]) {
+ Overrides[signature].call(null, success, fail, args)
+ return
+ }
+
+ setTimeout(callFail, 10)
+}
+
+//------------------------------------------------------------------------------
+var Overrides = {}
+
+//------------------------------------------------------------------------------
+function addOverride(func) {
+ var name = func.name.replace('__', '::')
+ Overrides[name] = func
+}
+
+//------------------------------------------------------------------------------
+addOverride(function Accelerometer__setTimeout(success, fail, args) {
+ setTimeout(function() {
+ fail("Accelerometer::setTimeout")
+ }, 10)
+})
+
+//------------------------------------------------------------------------------
+addOverride(function Accelerometer__getTimeout(success, fail, args) {
+ setTimeout(function() {
+ fail("Accelerometer::getTimeout")
+ }, 10)
+})
+
+//------------------------------------------------------------------------------
+addOverride(function Network_Status__getConnectionInfo(success, fail) {
+ setTimeout(function() {
+ success("none")
+ }, 10)
+})
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/574da1a6/lib/platform/errgen.js
----------------------------------------------------------------------
diff --git a/lib/platform/errgen.js b/lib/platform/errgen.js
new file mode 100644
index 0000000..8677cab
--- /dev/null
+++ b/lib/platform/errgen.js
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+// required call to kick off the device ready callback
+require('cordova/plugin/errgen/device')
+
+//------------------------------------------------------------------------------
+module.exports = {
+ id: "errgen",
+ initialize: function() {},
+ objects: {}
+}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/574da1a6/lib/plugin/errgen/device.js
----------------------------------------------------------------------
diff --git a/lib/plugin/errgen/device.js b/lib/plugin/errgen/device.js
new file mode 100644
index 0000000..4e05777
--- /dev/null
+++ b/lib/plugin/errgen/device.js
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+/**
+ * this represents the mobile device, and provides properties for inspecting the model, version, UUID of the
+ * phone, etc.
+ * @constructor
+ */
+
+//------------------------------------------------------------------------------
+function Device() {
+ window.DeviceInfo = {}
+
+ this.platform = "errgen"
+ this.version = "any"
+ this.name = "errgen"
+ this.phonegap = {}
+ this.gap = this.phonegap
+ this.uuid = "1234-5678-9012-3456"
+ this.available = true
+
+ require('cordova/channel').onCordovaInfoReady.fire()
+}
+
+//------------------------------------------------------------------------------
+module.exports = window.DeviceInfo = new Device()
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/574da1a6/test/errgen/errgen-tests.js
----------------------------------------------------------------------
diff --git a/test/errgen/errgen-tests.js b/test/errgen/errgen-tests.js
new file mode 100644
index 0000000..bc8ad27
--- /dev/null
+++ b/test/errgen/errgen-tests.js
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+
+document.addEventListener("deviceready", onDeviceReady, false)
+
+//------------------------------------------------------------------------------
+function onDeviceReady() {
+ // TODO: finish the tests
+ testAccelerometer();
+ testCamera();
+ // testCapture();
+ testCompass();
+ // testConnection();
+ // testContacts();
+ // testDevice();
+ // testEvents();
+ // testFile();
+ // testGeolocation();
+ // testMedia();
+ // testNotification();
+ // testStorage();
+}
+
+//------------------------------------------------------------------------------
+function getSuccessCB(api) {
+ return function() {
+ reportFailure(api + ": success callback was called")
+ }
+}
+
+//------------------------------------------------------------------------------
+function getErrorCB(api) {
+ return function() {
+ reportSuccess(api + ": error callback was called")
+ }
+}
+
+//------------------------------------------------------------------------------
+function testAPI(receiver, func, args) {
+ if (!args) args = []
+ var origArgs = args
+
+ var receiverObject = eval(receiver)
+ var funcObject = receiverObject[func]
+
+ var api = receiver + "." + func
+
+ args.unshift(getErrorCB(api))
+ args.unshift(getSuccessCB(api))
+
+ return funcObject.apply(receiverObject, origArgs)
+}
+
+//------------------------------------------------------------------------------
+function testAccelerometer() {
+ testAPI("navigator.accelerometer", "getCurrentAcceleration")
+}
+
+//------------------------------------------------------------------------------
+function testCamera() {
+ testAPI("navigator.camera", "getPicture", [{
+ quality: 100,
+ destinationType: Camera.DestinationType.FILE_URI
+ }])
+}
+
+//------------------------------------------------------------------------------
+function testCompass() {
+ testAPI("navigator.compass", "getCurrentHeading")
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/574da1a6/test/errgen/index.html
----------------------------------------------------------------------
diff --git a/test/errgen/index.html b/test/errgen/index.html
new file mode 100644
index 0000000..cee46ba
--- /dev/null
+++ b/test/errgen/index.html
@@ -0,0 +1,75 @@
+<!doctype html>
+
+<!--
+ * 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.
+-->
+
+<html>
+
+<!-- ======================================================================= -->
+<head>
+<title>cordova errgen tester</title>
+<script src='../../pkg/cordova.errgen.js'></script>
+<script src='./errgen-tests.js'></script>
+</head>
+
+<!-- ======================================================================= -->
+<body>
+<h1>cordova errgen tester</h1>
+<div id="results">
+</div>
+</body>
+
+<!-- ======================================================================= -->
+<script>
+var resultsDiv = null
+
+function reportSuccess(message) {
+ reportMessage(message, 'success')
+}
+
+function reportFailure(message) {
+ reportMessage(message, 'failure')
+}
+
+function reportMessage(message, className) {
+ var div = document.createElement('div')
+ div.className = className
+ div.innerText = message
+
+ if (!resultsDiv) {
+ resultsDiv = document.getElementById('results')
+ }
+
+ resultsDiv.appendChild(div)
+}
+</script>
+
+<!-- ======================================================================= -->
+<style>
+.success {
+ color: green;
+}
+.failure {
+ color: red;
+}
+
+</style>
+
+<!-- ======================================================================= -->
+</html>
\ No newline at end of file