function installPlugins()

in createmobilespec/createmobilespec.js [469:569]


function installPlugins() {
    var plugins = DEFAULT_PLUGINS;

    // special override for osx platform (macOS)
    if (argv.osx) {
        if (platforms.length > 1) {
            console.warn('Warning: Testing more than one platform at once may cause issues with unsupported plugins for osx platform (macOS).');
        } else {
            console.warn('Warning: Using reduced plugin list for osx platform (macOS).');
            plugins = DEFAULT_PLUGINS_OSX;
        }
    }

    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"))) {
            couldNotFind('plugman');
            console.log("  cd cordova-plugman");
            console.log("  npm link cordova-lib && npm install");
            return;
        }
        platforms.forEach(function (platform) {
            var projName = getProjName(platform),
                nodeCommand = /^win/.test(process.platform) ? ("\"" + process.argv[0] + "\" ") : "";
            pushd(projName);
            plugins.forEach(function(plugin) {
                // plugin path must be relative and not absolute (sigh)
                executeShellCommand(nodeCommand + path.join(top_dir, "cordova-plugman", "main.js") +
                             " install --platform " + platform +
                             " --project . --plugin " + plugin +
                             " --searchpath " + top_dir);
            });

            // Install new-style test plugins
            console.log("Adding plugin tests using plugman...");
            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)) {
                    executeShellCommand(nodeCommand + path.join(top_dir, "cordova-plugman", "main.js") +
                                " install --platform " + platform +
                                " --project . --plugin " + path.dirname(potential_tests_plugin_xml));
                }
            });
            popd();
        });
    } else {

        // don't use local git repos for plugins when using --global.
        var searchPath = argv.globalplugins ? '' : top_dir;

        console.log("### Adding plugins using CLI...");
        console.log("Searchpath:", searchPath);
        pushd(cli_project_dir);

        // we do need local plugin-test-framework
        console.log("Installing local test framework plugins...");
        var linkPluginsFlag = (argv.link || argv.linkplugins) ? ' --link' : '';
        var forcePluginsFlag = (argv.forceplugins)? ' --force' : '';
        var allPluginFlags = linkPluginsFlag + variableFlag + forcePluginsFlag;

        // Install mobilespec tests only if we install default list of plugins
        // If custom list of plugins is being installed, mobilespec tests can be listed there, if needed
        if (!argv.plugins) {
            //pluginAdd('org.apache.cordova.mobilespec.tests', mobile_spec_git_dir, allPluginFlags);
        }
        //pluginAdd('org.apache.cordova.test.whitelist', mobile_spec_git_dir, allPluginFlags);
        pluginAdd('org.apache.cordova.test.echo', mobile_spec_git_dir, allPluginFlags);

        pluginAdd('cordova-plugin-test-framework', searchPath, allPluginFlags);
        pluginAdd('cordova-plugin-device', searchPath, allPluginFlags);

        if (argv.android) {
            pluginAdd('cordova-plugin-whitelist', searchPath, allPluginFlags);
        }

        plugins.forEach(function(p) {
            var sp = SEARCH_PATHS.hasOwnProperty(p) ? SEARCH_PATHS[p] : searchPath;
            pluginAdd(p, sp, allPluginFlags);
        });

        // Install new-style test plugins
        console.log("Adding plugin tests using CLI...");
        var pluginTestPaths = [];
        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)));
          }
        });
        pluginAdd(pluginTestPaths.join(' '), null, allPluginFlags);

        popd();
    }
}