Project.prototype.initPlugins = function()

in src/server/project.js [74:161]


Project.prototype.initPlugins = function () {
    this._resetPluginsData();

    // Find the default plugins
    var simulatedDefaultPlugins = {};
    var debugHostHandlers = this._simulatorProxy.config.debugHostHandlers;

    Project.DEFAULT_PLUGINS.forEach(function (pluginId) {
        var pluginPath = pluginUtil.findPluginPath(this.projectRoot, pluginId);

        if (pluginPath) {
            simulatedDefaultPlugins[pluginId] = pluginPath;
            this.pluginsTelemetry.simulatedBuiltIn.push(pluginId);
        }
    }.bind(this));

    // Find the project plugins that can be simulated.
    var projectPluginsRoot = path.resolve(this.platformRoot, 'plugins');
    var rawProjectPluginList = utils.getDirectoriesInPath(projectPluginsRoot);

    /* if the geolocation plugin is already added to the project,
       we need to remove it since it is in the list of default plugins as well and will appear twice otherwise */
    var geolocationIndex = rawProjectPluginList.indexOf('cordova-plugin-geolocation');
    if (geolocationIndex >= 0) {
        rawProjectPluginList.splice(geolocationIndex, 1);
    }

    var simulatedProjectPlugins = {};

    rawProjectPluginList.forEach(function (pluginId) {
        var pluginFilePath = pluginUtil.findPluginPath(this.projectRoot, pluginId);

        if (pluginFilePath && pluginUtil.shouldUsePluginWithDebugHost(pluginFilePath, true, debugHostHandlers)) {
            simulatedProjectPlugins[pluginId] = pluginFilePath;

            if (pluginFilePath.indexOf(dirs.plugins) === 0) {
                this.pluginsTelemetry.simulatedBuiltIn.push(pluginId);
            } else {
                this.pluginsTelemetry.simulatedNonBuiltIn.push(pluginId);
            }
        } else {
            this.pluginsTelemetry.notSimulated.push(pluginId);
        }
    }.bind(this));

    // Find built-in debug-host plugins (plugins that should be part of the simulation due to the presence of a
    // debug-host, even if they weren't added to the project).
    var simulatedDebugHostPlugins = {};

    if (debugHostHandlers) {
        var rawBuiltInPluginList = utils.getDirectoriesInPath(dirs.plugins);

        rawBuiltInPluginList.forEach(function (pluginId) {
            if (simulatedDefaultPlugins[pluginId] || simulatedProjectPlugins[pluginId]) {
                return;
            }

            var pluginPath = path.join(dirs.plugins, pluginId);

            if (pluginPath && pluginUtil.shouldUsePluginWithDebugHost(pluginPath, null, debugHostHandlers)) {
                simulatedDebugHostPlugins[pluginId] = pluginPath;
                this.pluginsTelemetry.simulatedBuiltIn.push(pluginId);
            }
        }.bind(this));
    }

    // Register the plugins. The default plugins are first, then the debug-host plugins (to have the correct order in
    // sim-host).
    var that = this;
    function registerPlugins(pluginDictionary) {
        Object.keys(pluginDictionary).forEach(function (pluginId) {
            that.plugins[pluginId] = pluginDictionary[pluginId];
        });
    }

    registerPlugins(simulatedDefaultPlugins);
    registerPlugins(simulatedDebugHostPlugins);
    registerPlugins(simulatedProjectPlugins);

    this._simulatorProxy.telemetry.sendTelemetry('plugin-list', {
        simulatedBuiltIn: this.pluginsTelemetry.simulatedBuiltIn
    }, {
        simulatedNonBuiltIn: this.pluginsTelemetry.simulatedNonBuiltIn,
        notSimulated: this.pluginsTelemetry.notSimulated
    });
    this._addPlatformDefaultHandlers();
    this._populateRouter();
};