You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by br...@apache.org on 2013/07/23 22:23:17 UTC
[6/6] git commit: [CB-4341] Adding a fix to make subdirectories work
within a local plugin dependency - Includes the integration of integration
specs which test installation of plugins with dependencies
[CB-4341] Adding a fix to make subdirectories work within a local plugin dependency
- Includes the integration of integration specs which test installation
of plugins with dependencies
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/21b6d79b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/21b6d79b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/21b6d79b
Branch: refs/heads/master
Commit: 21b6d79b32a3dbce29e85d1b67f547351a1bf11b
Parents: f2fa751
Author: Jeffrey Heifetz <jh...@blackberry.com>
Authored: Mon Jul 22 15:23:46 2013 -0400
Committer: Jeffrey Heifetz <jh...@blackberry.com>
Committed: Tue Jul 23 14:53:43 2013 -0400
----------------------------------------------------------------------
.gitignore | 2 +
spec/install.spec.js | 8 +-
spec/integration.spec.js | 85 +
spec/plugins/Contacts/plugin.xml | 143 ++
.../Contacts/src/android/ContactAccessor.java | 198 ++
.../src/android/ContactAccessorSdk5.java | 2183 ++++++++++++++++++
.../Contacts/src/android/ContactManager.java | 122 +
.../src/blackberry10/ContactActivity.js | 26 +
.../Contacts/src/blackberry10/ContactAddress.js | 30 +
.../Contacts/src/blackberry10/ContactError.js | 30 +
.../Contacts/src/blackberry10/ContactField.js | 27 +
.../src/blackberry10/ContactFindOptions.js | 50 +
.../Contacts/src/blackberry10/ContactName.js | 39 +
.../Contacts/src/blackberry10/ContactNews.js | 26 +
.../src/blackberry10/ContactOrganization.js | 22 +
.../Contacts/src/blackberry10/ContactPhoto.js | 23 +
.../Contacts/src/blackberry10/contactConsts.js | 225 ++
.../Contacts/src/blackberry10/contactUtils.js | 223 ++
spec/plugins/Contacts/src/blackberry10/index.js | 374 +++
.../Contacts/src/blackberry10/plugin.xml | 41 +
spec/plugins/Contacts/src/ios/CDVContact.h | 136 ++
spec/plugins/Contacts/src/ios/CDVContact.m | 1752 ++++++++++++++
spec/plugins/Contacts/src/ios/CDVContacts.h | 151 ++
spec/plugins/Contacts/src/ios/CDVContacts.m | 593 +++++
spec/plugins/Contacts/src/wp/Contacts.cs | 664 ++++++
spec/plugins/Contacts/www/Contact.js | 177 ++
spec/plugins/Contacts/www/ContactAddress.js | 46 +
spec/plugins/Contacts/www/ContactError.js | 42 +
spec/plugins/Contacts/www/ContactField.js | 37 +
spec/plugins/Contacts/www/ContactFindOptions.js | 34 +
spec/plugins/Contacts/www/ContactName.js | 41 +
.../plugins/Contacts/www/ContactOrganization.js | 44 +
spec/plugins/Contacts/www/contacts.js | 76 +
spec/plugins/Contacts/www/ios/Contact.js | 51 +
spec/plugins/Contacts/www/ios/contacts.js | 62 +
spec/plugins/dependencies/B/plugin.xml | 8 +-
spec/plugins/dependencies/E/plugin.xml | 57 -
spec/plugins/dependencies/E/src/android/E.java | 0
.../dependencies/E/src/ios/EPluginCommand.h | 0
.../dependencies/E/src/ios/EPluginCommand.m | 0
spec/plugins/dependencies/E/www/plugin-e.js | 0
spec/plugins/dependencies/subdir/E/plugin.xml | 57 +
.../dependencies/subdir/E/src/android/E.java | 0
.../subdir/E/src/ios/EPluginCommand.h | 0
.../subdir/E/src/ios/EPluginCommand.m | 0
.../dependencies/subdir/E/www/plugin-e.js | 0
.../blackberry10/native/device/chrome/.gitkeep | 0
.../native/device/plugins/jnext/auth.txt | 3 +
.../native/simulator/chrome/.gitkeep | 0
.../native/simulator/plugins/jnext/auth.txt | 3 +
src/install.js | 2 +
51 files changed, 7849 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/21b6d79b/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 9daa824..7dbb168 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
.DS_Store
node_modules
+.gitkeep
+.tmp
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/21b6d79b/spec/install.spec.js
----------------------------------------------------------------------
diff --git a/spec/install.spec.js b/spec/install.spec.js
index 33bfcc8..c48db9a 100644
--- a/spec/install.spec.js
+++ b/spec/install.spec.js
@@ -103,17 +103,19 @@ describe('install', function() {
expect(proc.calls.length).toEqual(3);
});
it('should fetch any dependent plugins if missing', function() {
- var s = spyOn(plugman, 'fetch').andCallFake(function(id, dir, opts, cb) {
+ var deps_dir = path.join(plugins_dir, 'dependencies'),
+ s = spyOn(plugman, 'fetch').andCallFake(function(id, dir, opts, cb) {
cb(false, path.join(dir, id));
});
exists.andReturn(false);
// Plugin A depends on C & D
- install('android', temp, 'A', path.join(plugins_dir, 'dependencies'), {});
+ install('android', temp, 'A', deps_dir, {});
+ expect(s).toHaveBeenCalledWith('C', deps_dir, { link: false, subdir: undefined, git_ref: undefined}, jasmine.any(Function));
expect(s.calls.length).toEqual(3);
});
});
});
-
+
describe('failure', function() {
it('should throw if platform is unrecognized', function() {
expect(function() {
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/21b6d79b/spec/integration.spec.js
----------------------------------------------------------------------
diff --git a/spec/integration.spec.js b/spec/integration.spec.js
new file mode 100644
index 0000000..54b578e
--- /dev/null
+++ b/spec/integration.spec.js
@@ -0,0 +1,85 @@
+var plugman = require('../plugman'),
+ path = require('path'),
+ fs = require('fs'),
+ shell = require('shelljs'),
+ temp = path.join(__dirname, "..", ".tmp"),
+ plugins_dir = path.join(temp, 'plugins');
+
+describe("integration", function () {
+ beforeEach(function () {
+ if ( !fs.existsSync(temp)) {
+ shell.mkdir("-p", temp);
+ }
+ });
+ describe("local non-root depdencies", function () {
+ var project_src = path.join(__dirname, "projects", "android_one", "*"),
+ plugin_src = path.join(__dirname, "plugins", "dependencies", "B"),
+ project_dir = path.join(temp, "android");
+
+ beforeEach(function () {
+ shell.cp("-rf", project_src, project_dir);
+ });
+
+ it("should install dependencies from github", function () {
+ var flag = false,
+ installData;
+
+ runs(function () {
+ plugman.install('android', project_dir, plugin_src, plugins_dir, {}, function (error) {
+ expect(error).not.toBeDefined();
+ flag = true;
+ });
+ });
+ waitsFor(function () { return flag; }, "plugman install to finish", 10000);
+ runs(function () {
+ installData = require(path.join(plugins_dir, "android.json"));
+ expect(installData.installed_plugins).toEqual({ 'B': { PACKAGE_NAME: 'com.alunny.childapp'}});
+ expect(installData.dependent_plugins).toEqual({
+ 'D' : { PACKAGE_NAME: 'com.alunny.childapp'},
+ 'E': { PACKAGE_NAME: 'com.alunny.childapp'}
+ });
+ });
+ //Cleanup
+ this.after(function () {
+ shell.rm("-rf", project_dir);
+ });
+ });
+ });
+
+ describe("blackberry10", function () {
+ var project_src = path.join(__dirname, "projects", "blackberry10", "*"),
+ plugin_src = path.join(__dirname, "plugins", "Contacts"),
+ project_dir = path.join(temp, "blackberry10");
+
+ beforeEach(function () {
+ shell.cp("-rf", project_src, project_dir);
+ });
+
+ it("should install dependencies from github", function () {
+ var flag = false,
+ installData;
+
+ runs(function () {
+ plugman.install('blackberry10', project_dir, plugin_src, plugins_dir, {}, function (error) {
+ expect(error).not.toBeDefined();
+ flag = true;
+ });
+ });
+ waitsFor(function () { return flag; }, "plugman install to finish", 10000);
+ runs(function () {
+ installData = require(path.join(plugins_dir, "blackberry10.json"));
+ expect(installData.installed_plugins).toEqual({ 'org.apache.cordova.core.contacts': { PACKAGE_NAME: 'cordovaExample'}});
+ expect(installData.dependent_plugins).toEqual({
+ 'com.blackberry.utils' : { PACKAGE_NAME: 'cordovaExample'},
+ 'org.apache.cordova.blackberry10.pimlib': { PACKAGE_NAME: 'cordovaExample'}
+ });
+ });
+ //Cleanup
+ this.after(function () {
+ shell.rm("-rf", project_dir);
+ shell.rm("-rf", temp);
+ });
+ });
+ });
+
+});
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/21b6d79b/spec/plugins/Contacts/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/Contacts/plugin.xml b/spec/plugins/Contacts/plugin.xml
new file mode 100644
index 0000000..7328f1a
--- /dev/null
+++ b/spec/plugins/Contacts/plugin.xml
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
+ id="org.apache.cordova.core.contacts"
+ version="0.1.0">
+ <name>Contacts</name>
+
+
+ <js-module src="www/contacts.js" name="contacts">
+ <clobbers target="navigator.contacts" />
+ </js-module>
+
+ <js-module src="www/Contact.js" name="Contact">
+ <clobbers target="Contact" />
+ </js-module>
+
+ <js-module src="www/ContactAddress.js" name="ContactAddress">
+ <clobbers target="ContactAddress" />
+ </js-module>
+
+ <js-module src="www/ContactError.js" name="ContactError">
+ <clobbers target="ContactError" />
+ </js-module>
+
+ <js-module src="www/ContactField.js" name="ContactField">
+ <clobbers target="ContactField" />
+ </js-module>
+
+ <js-module src="www/ContactFindOptions.js" name="ContactFindOptions">
+ <clobbers target="ContactFindOptions" />
+ </js-module>
+
+ <js-module src="www/ContactName.js" name="ContactName">
+ <clobbers target="ContactName" />
+ </js-module>
+
+ <js-module src="www/ContactOrganization.js" name="ContactOrganization">
+ <clobbers target="ContactOrganization" />
+ </js-module>
+
+
+
+
+ <!-- android -->
+ <platform name="android">
+ <config-file target="res/xml/config.xml" parent="/*">
+ <feature name="Contacts">
+ <param name="android-package" value="org.apache.cordova.core.ContactManager"/>
+ </feature>
+ </config-file>
+
+ <config-file target="AndroidManifest.xml" parent="/*">
+ <uses-permission android:name="android.permission.READ_CONTACTS" />
+ <uses-permission android:name="android.permission.WRITE_CONTACTS" />
+ <uses-permission android:name="android.permission.GET_ACCOUNTS" />
+ </config-file>
+
+ <source-file src="src/android/ContactAccessor.java" target-dir="src/org/apache/cordova/core" />
+ <source-file src="src/android/ContactAccessorSdk5.java" target-dir="src/org/apache/cordova/core" />
+ <source-file src="src/android/ContactManager.java" target-dir="src/org/apache/cordova/core" />
+ </platform>
+
+ <!-- ios -->
+ <platform name="ios">
+ <config-file target="config.xml" parent="/*">
+ <feature name="Contacts">
+ <param name="ios-package" value="CDVContacts"/>
+ </feature>
+ </config-file>
+
+ <js-module src="www/ios/contacts.js" name="contacts">
+ <merges target="navigator.contacts" />
+ </js-module>
+
+ <js-module src="www/ios/Contact.js" name="Contact">
+ <merges target="Contact" />
+ </js-module>
+
+ <header-file src="src/ios/CDVContacts.h" />
+ <source-file src="src/ios/CDVContacts.m" />
+ <header-file src="src/ios/CDVContact.h" />
+ <source-file src="src/ios/CDVContact.m" />
+ </platform>
+
+ <!-- blackberry10 -->
+ <platform name="blackberry10">
+ <config-file target="www/config.xml" parent="/widget">
+ <feature name="Contacts" value="Contacts"/>
+ </config-file>
+ <config-file target="www/config.xml" parent="/widget">
+ <rim:permissions>
+ </rim:permissions>
+ </config-file>
+ <config-file target="www/config.xml" parent="/widget/rim:permissions">
+ <rim:permit>access_pimdomain_contacts</rim:permit>
+ </config-file>
+ <source-file src="src/blackberry10/index.js" target-dir="Contacts"></source-file>
+ <source-file src="src/blackberry10/ContactActivity.js" target-dir="Contacts"></source-file>
+ <source-file src="src/blackberry10/ContactAddress.js" target-dir="Contacts"></source-file>
+ <source-file src="src/blackberry10/contactConsts.js" target-dir="Contacts"></source-file>
+ <source-file src="src/blackberry10/ContactError.js" target-dir="Contacts"></source-file>
+ <source-file src="src/blackberry10/ContactField.js" target-dir="Contacts"></source-file>
+ <source-file src="src/blackberry10/ContactFindOptions.js" target-dir="Contacts"></source-file>
+ <source-file src="src/blackberry10/ContactName.js" target-dir="Contacts"></source-file>
+ <source-file src="src/blackberry10/ContactNews.js" target-dir="Contacts"></source-file>
+ <source-file src="src/blackberry10/ContactOrganization.js" target-dir="Contacts"></source-file>
+ <source-file src="src/blackberry10/ContactPhoto.js" target-dir="Contacts"></source-file>
+ <source-file src="src/blackberry10/contactUtils.js" target-dir="Contacts"></source-file>
+ <dependency id="com.blackberry.utils" url="https://github.com/blackberry/cordova-blackberry-plugins.git" commit="plugins" subdir="plugin/com.blackberry.utils"/>
+ <dependency id="org.apache.cordova.blackberry10.pimlib" url="https://github.com/blackberry/cordova-blackberry-plugins.git" commit="plugins" subdir="/plugin/org.apache.cordova.blackberry10.pimlib/"/>
+ </platform>
+
+ <!-- wp7 -->
+ <platform name="wp7">
+ <config-file target="config.xml" parent="/*">
+ <feature name="Contacts">
+ <param name="wp-package" value="Contacts"/>
+ </feature>
+ </config-file>
+
+ <config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
+ <Capability Name="ID_CAP_CONTACTS" />
+ </config-file>
+
+ <source-file src="src/wp/Contacts.cs" />
+ </platform>
+
+ <!-- wp8 -->
+ <platform name="wp8">
+ <config-file target="config.xml" parent="/*">
+ <feature name="Contacts">
+ <param name="wp-package" value="Contacts"/>
+ </feature>
+ </config-file>
+
+ <config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
+ <Capability Name="ID_CAP_CONTACTS" />
+ </config-file>
+
+ <source-file src="src/wp/Contacts.cs" />
+ </platform>
+
+</plugin>
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/21b6d79b/spec/plugins/Contacts/src/android/ContactAccessor.java
----------------------------------------------------------------------
diff --git a/spec/plugins/Contacts/src/android/ContactAccessor.java b/spec/plugins/Contacts/src/android/ContactAccessor.java
new file mode 100644
index 0000000..24ef9c6
--- /dev/null
+++ b/spec/plugins/Contacts/src/android/ContactAccessor.java
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed 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.
+ */
+
+package org.apache.cordova.core;
+
+import java.util.HashMap;
+
+import android.util.Log;
+import android.webkit.WebView;
+
+import org.apache.cordova.CordovaInterface;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * This abstract class defines SDK-independent API for communication with
+ * Contacts Provider. The actual implementation used by the application depends
+ * on the level of API available on the device. If the API level is Cupcake or
+ * Donut, we want to use the {@link ContactAccessorSdk3_4} class. If it is
+ * Eclair or higher, we want to use {@link ContactAccessorSdk5}.
+ */
+public abstract class ContactAccessor {
+
+ protected final String LOG_TAG = "ContactsAccessor";
+ protected CordovaInterface mApp;
+ protected WebView mView;
+
+ /**
+ * Check to see if the data associated with the key is required to
+ * be populated in the Contact object.
+ * @param key
+ * @param map created by running buildPopulationSet.
+ * @return true if the key data is required
+ */
+ protected boolean isRequired(String key, HashMap<String,Boolean> map) {
+ Boolean retVal = map.get(key);
+ return (retVal == null) ? false : retVal.booleanValue();
+ }
+
+ /**
+ * Create a hash map of what data needs to be populated in the Contact object
+ * @param fields the list of fields to populate
+ * @return the hash map of required data
+ */
+ protected HashMap<String,Boolean> buildPopulationSet(JSONArray fields) {
+ HashMap<String,Boolean> map = new HashMap<String,Boolean>();
+
+ String key;
+ try {
+ if (fields.length() == 1 && fields.getString(0).equals("*")) {
+ map.put("displayName", true);
+ map.put("name", true);
+ map.put("nickname", true);
+ map.put("phoneNumbers", true);
+ map.put("emails", true);
+ map.put("addresses", true);
+ map.put("ims", true);
+ map.put("organizations", true);
+ map.put("birthday", true);
+ map.put("note", true);
+ map.put("urls", true);
+ map.put("photos", true);
+ map.put("categories", true);
+ }
+ else {
+ for (int i=0; i<fields.length(); i++) {
+ key = fields.getString(i);
+ if (key.startsWith("displayName")) {
+ map.put("displayName", true);
+ }
+ else if (key.startsWith("name")) {
+ map.put("displayName", true);
+ map.put("name", true);
+ }
+ else if (key.startsWith("nickname")) {
+ map.put("nickname", true);
+ }
+ else if (key.startsWith("phoneNumbers")) {
+ map.put("phoneNumbers", true);
+ }
+ else if (key.startsWith("emails")) {
+ map.put("emails", true);
+ }
+ else if (key.startsWith("addresses")) {
+ map.put("addresses", true);
+ }
+ else if (key.startsWith("ims")) {
+ map.put("ims", true);
+ }
+ else if (key.startsWith("organizations")) {
+ map.put("organizations", true);
+ }
+ else if (key.startsWith("birthday")) {
+ map.put("birthday", true);
+ }
+ else if (key.startsWith("note")) {
+ map.put("note", true);
+ }
+ else if (key.startsWith("urls")) {
+ map.put("urls", true);
+ }
+ else if (key.startsWith("photos")) {
+ map.put("photos", true);
+ }
+ else if (key.startsWith("categories")) {
+ map.put("categories", true);
+ }
+ }
+ }
+ }
+ catch (JSONException e) {
+ Log.e(LOG_TAG, e.getMessage(), e);
+ }
+ return map;
+ }
+
+ /**
+ * Convenience method to get a string from a JSON object. Saves a
+ * lot of try/catch writing.
+ * If the property is not found in the object null will be returned.
+ *
+ * @param obj contact object to search
+ * @param property to be looked up
+ * @return The value of the property
+ */
+ protected String getJsonString(JSONObject obj, String property) {
+ String value = null;
+ try {
+ if (obj != null) {
+ value = obj.getString(property);
+ if (value.equals("null")) {
+ Log.d(LOG_TAG, property + " is string called 'null'");
+ value = null;
+ }
+ }
+ }
+ catch (JSONException e) {
+ Log.d(LOG_TAG, "Could not get = " + e.getMessage());
+ }
+ return value;
+ }
+
+ /**
+ * Handles adding a JSON Contact object into the database.
+ * @return TODO
+ */
+ public abstract String save(JSONObject contact);
+
+ /**
+ * Handles searching through SDK-specific contacts API.
+ */
+ public abstract JSONArray search(JSONArray filter, JSONObject options);
+
+ /**
+ * Handles searching through SDK-specific contacts API.
+ * @throws JSONException
+ */
+ public abstract JSONObject getContactById(String id) throws JSONException;
+
+ /**
+ * Handles removing a contact from the database.
+ */
+ public abstract boolean remove(String id);
+
+ /**
+ * A class that represents the where clause to be used in the database query
+ */
+ class WhereOptions {
+ private String where;
+ private String[] whereArgs;
+ public void setWhere(String where) {
+ this.where = where;
+ }
+ public String getWhere() {
+ return where;
+ }
+ public void setWhereArgs(String[] whereArgs) {
+ this.whereArgs = whereArgs;
+ }
+ public String[] getWhereArgs() {
+ return whereArgs;
+ }
+ }
+}