CB-8694 Replaced dependencies plugin with command line parameter

github close #123
diff --git a/createmobilespec/createmobilespec.js b/createmobilespec/createmobilespec.js
index a43c438..0cb1d1a 100755
--- a/createmobilespec/createmobilespec.js
+++ b/createmobilespec/createmobilespec.js
@@ -57,11 +57,13 @@
 
 function pluginAdd(pluginName, searchPath, extraFlags) {
     var command = cli + ' plugin add ' + pluginName;
-    if (searchPath) {
+    if (!argv.global && !argv.globalplugins && SEARCH_PATHS.hasOwnProperty(pluginName)) {
+        command += ' --searchpath ' + SEARCH_PATHS[pluginName];
+    } else if (searchPath) {
         command += ' --searchpath ' + searchPath;
     }
     if (extraFlags) {
-        command + extraFlags;
+        command += extraFlags;
     }
     shelljs.exec(command);
 }
@@ -103,7 +105,7 @@
                                               "www": ["www"] },
                             "firefoxos":    { "bin": ["cordova-firefoxos"],
                                               "www": ["www"] } },
-    argv = optimist.usage("\nUsage: $0 PLATFORM... [--help] [--plugman] [--link] [--global] [--globalplugins] [--skipjs] [--skiplink] [directoryName]\n" +
+    argv = optimist.usage("\nUsage: $0 PLATFORM... [--help] [--plugman] [--link] [--global] [--globalplugins] [--plugins=\".\\myPluginDir\"] [--skipjs] [--skiplink] [directoryName]\n" +
                           "A project will be created with the mobile-spec app and all the core plugins.\n" +
                           "At least one platform must be specified. See the included README.md.\n" +
                           "\tPLATFORM: [--<amazon|android|blackberry10|ios|windows|windows8|wp8|firefoxos>]\n" +
@@ -126,6 +128,8 @@
                    .boolean("globalplugins").describe("globalplugins", "Use the plugins from the remote registry instead of the local git repo.\n" +
                                                       "\t\t\tRarely used, generally to test platform releases.\n" +
                                                       "\t\t\tCannot be used with --global because it is implied when --global is used.")
+                   .string("plugins").describe("plugins", "Used to explicitly specify the list of plugins to be installed.\n" +
+                                               "Example: --plugins=\"org.apache.cordova.device org.apache.cordova.file-transfer my.custom.plugin\"")
                    .boolean("skipjs").describe("skipjs", "Do not update the platform's cordova.js from the js git repo, use the one already present in the platform.\n" +
                                                "\t\t\tRarely used, generally to test RC releases.\n" +
                                                "\t\t\tCannot be used with --global because it is implied when --global is used.")
@@ -181,12 +185,44 @@
     'https://github.com/Telerik-Verified-Plugins/AppVersion',
     'https://github.com/Telerik-Verified-Plugins/PrivacyScreen'
 ];
+
 var PLUGREG_PLUGINS = [
     'https://github.com/brodysoft/Cordova-SQLitePlugin.git',
     // 'https://github.com/wildabeast/BarcodeScanner.git',
     // 'https://github.com/phonegap-build/PushPlugin.git',
 ];
 
+var DEFAULT_PLUGINS = [
+    'org.apache.cordova.battery-status',
+    'org.apache.cordova.camera',
+    'org.apache.cordova.console',
+    'org.apache.cordova.contacts',
+    'org.apache.cordova.device',
+    'org.apache.cordova.device-motion',
+    'org.apache.cordova.device-orientation',
+    'org.apache.cordova.dialogs',
+    'org.apache.cordova.file',
+    'org.apache.cordova.file-transfer',
+    'org.apache.cordova.geolocation',
+    'org.apache.cordova.globalization',
+    'org.apache.cordova.inappbrowser',
+    'org.apache.cordova.media',
+    'org.apache.cordova.media-capture',
+    'org.apache.cordova.network-information',
+    'org.apache.cordova.splashscreen',
+    'org.apache.cordova.statusbar',
+    'org.apache.cordova.vibration',
+    'org.apache.cordova.mobilespec.tests',
+];
+
+// plugin search paths that will override default
+var SEARCH_PATHS = {
+    'org.apache.cordova.mobilespec.tests': mobile_spec_git_dir,
+    'org.apache.cordova.test.whitelist': mobile_spec_git_dir,
+    'org.apache.cordova.test.echo': mobile_spec_git_dir,
+    'org.apache.cordova.test-framework': top_dir,
+};
+
 if (!fs.existsSync(mobile_spec_git_dir)) {
     console.log("Please run this script from "+path.dirname(path.dirname(__dirname)));
     shelljs.exit(1);
@@ -458,8 +494,22 @@
     popd();
 }
 
+function pluginIdToDirName(id) {
+    var lastDotIndex = id.lastIndexOf('.');
+
+    if ((lastDotIndex === -1) || (lastDotIndex === id.length - 1)) return null;
+    return 'cordova-plugin-' + id.substr(lastDotIndex + 1);
+}
+
 ////////////////////// install plugins for each platform
 function installPlugins() {
+    var plugins = DEFAULT_PLUGINS;
+    if (argv.plugins) {
+        plugins = argv.plugins.split(" ").filter(function (item) { 
+            return item !== ""; 
+        });
+    }
+
     if (argv.plugman) {
         console.log("Adding plugins using plugman...");
         if (!fs.existsSync(path.join(top_dir, "cordova-plugman"))) {
@@ -472,19 +522,19 @@
             var projName = getProjName(platform),
                 nodeCommand = /^win/.test(process.platform) ? ("\"" + process.argv[0] + "\" ") : "";
             pushd(projName);
-            // plugin path must be relative and not absolute (sigh)
-            shelljs.exec(nodeCommand + path.join(top_dir, "cordova-plugman", "main.js") +
-                         " install --platform " + platform +
-                         " --project . --plugin " + path.join("..", "cordova-mobile-spec", "dependencies-plugin") +
-                         " --searchpath " + top_dir + browserifyFlag);
+            plugins.forEach(function(plugin) {
+                // plugin path must be relative and not absolute (sigh)
+                shelljs.exec(nodeCommand + path.join(top_dir, "cordova-plugman", "main.js") +
+                             " install --platform " + platform +
+                             " --project . --plugin " + plugin +
+                             " --searchpath " + top_dir + browserifyFlag);
+            });
 
             // Install new-style test plugins
             console.log("Adding plugin tests using plugman...");
-            var plugin_path = join_paths(platform_layout[platform].www.concat(["plugins"]));
-            shelljs.ls(plugin_path).forEach(function(plugin) {
-                var id_elts = plugin.split(".");
-                var plugin_name = "cordova-plugin-" + id_elts[id_elts.length - 1];
-                var potential_tests_plugin_xml = path.join(top_dir, plugin_name, 'tests', 'plugin.xml');
+            plugins.forEach(function(plugin) {
+                var pluginDirName = pluginIdToDirName(plugin);
+                var potential_tests_plugin_xml = path.join(top_dir, pluginDirName, 'tests', 'plugin.xml');
                 if (fs.existsSync(potential_tests_plugin_xml)) {
                     shelljs.exec(nodeCommand + path.join(top_dir, "cordova-plugman", "main.js") +
                                 " install --platform " + platform +
@@ -512,6 +562,7 @@
         pluginAdd('org.apache.cordova.test.whitelist', mobile_spec_git_dir, linkPluginsFlag + browserifyFlag);
         pluginAdd('org.apache.cordova.test.echo', mobile_spec_git_dir, linkPluginsFlag + browserifyFlag);
         pluginAdd('org.apache.cordova.test-framework', top_dir, linkPluginsFlag + browserifyFlag);
+        pluginAdd('org.apache.cordova.device', top_dir, linkPluginsFlag + browserifyFlag);
 
         if (argv.android) {
             pluginAdd(path.join(top_dir, 'cordova-plugin-whitelist'), null, linkPluginsFlag + browserifyFlag);
@@ -523,11 +574,12 @@
         }
 
         if (argv.globalplugins) {
-            pluginAdd(path.join(mobile_spec_git_dir, "dependencies-plugin"), null, linkPluginsFlag + browserifyFlag);
+            pluginAdd(plugins.join(' '), null, linkPluginsFlag + browserifyFlag);
         } else {
-            pluginAdd(path.join(mobile_spec_git_dir, "dependencies-plugin"), searchpath, linkPluginsFlag + browserifyFlag);
+            plugins.forEach(function(plugin) {
+                pluginAdd(plugin, searchpath, linkPluginsFlag + browserifyFlag);
+            });
         }
-
         if (argv.thirdpartyplugins || argv.cprplugins) {
             var mapVars = ' --variable API_KEY_FOR_ANDROID="AIzaSyBICVSs9JqT7WdASuN5HSe7w-pCE0n_X88" --variable API_KEY_FOR_IOS="AIzaSyAikyYG24YYFvq5Vy41P5kppsfO2GgF9jM"';
             var fbVars = ' --variable APP_ID=value --variable APP_NAME=value';
@@ -551,7 +603,7 @@
         // Install new-style test plugins
         console.log("Adding plugin tests using CLI...");
         var pluginTestPaths = [];
-        shelljs.ls('plugins').forEach(function(plugin) {
+        plugins.forEach(function(plugin) {
           var potential_tests_plugin_xml = path.join('plugins', plugin, 'tests', 'plugin.xml');
           if (fs.existsSync(potential_tests_plugin_xml)) {
             pluginTestPaths.push(path.resolve(path.dirname(potential_tests_plugin_xml)));
diff --git a/dependencies-plugin/plugin.xml b/dependencies-plugin/plugin.xml
deleted file mode 100644
index 4f0b23e..0000000
--- a/dependencies-plugin/plugin.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
- 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.
--->
-
-<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
-    id="org.cordova.mobile-spec-dependencies"
-    version="1.0.0">
-  <engines>
-    <engine name="cordova" version=">=3.3.0" />
-  </engines>
-
-  <name>Mobile-Spec plugin to quickly pull in all cordova plugins</name>
-
-  <dependency id="org.apache.cordova.battery-status"/>
-  <dependency id="org.apache.cordova.camera"/>
-  <dependency id="org.apache.cordova.console"/>
-  <dependency id="org.apache.cordova.contacts"/>
-  <dependency id="org.apache.cordova.device"/>
-  <dependency id="org.apache.cordova.device-motion"/>
-  <dependency id="org.apache.cordova.device-orientation"/>
-  <dependency id="org.apache.cordova.dialogs"/>
-  <dependency id="org.apache.cordova.file"/>
-  <dependency id="org.apache.cordova.file-transfer"/>
-  <dependency id="org.apache.cordova.geolocation"/>
-  <dependency id="org.apache.cordova.globalization"/>
-  <dependency id="org.apache.cordova.inappbrowser"/>
-  <dependency id="org.apache.cordova.media"/>
-  <dependency id="org.apache.cordova.media-capture"/>
-  <dependency id="org.apache.cordova.network-information"/>
-  <dependency id="org.apache.cordova.splashscreen"/>
-  <dependency id="org.apache.cordova.statusbar"/>
-  <dependency id="org.apache.cordova.vibration"/>
-  <dependency id="org.apache.cordova.test-framework"/>
-  <dependency id="org.apache.cordova.test.whitelist" url="." subdir="cordova-plugin-whitelist" />
-  <dependency id="org.apache.cordova.test.echo" url="." subdir="cordova-plugin-echo" />
-  <dependency id="org.apache.cordova.mobilespec.tests" url="." subdir="cordova-plugin-mobilespec-tests" />
-</plugin>