cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject git commit: CB-6469 "plugin save" now records (path/url/registry) and ignores dependent plugins
Date Tue, 07 Oct 2014 18:09:52 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master d50441c26 -> 35a3059bb


CB-6469 "plugin save" now records (path/url/registry) and ignores dependent plugins

Implements save and restore for plugins that are coming from local file system or from a git
repo.
Also makes a change so that the dependency plugins are not saved during a save. Makes a change
on the fetch.js so that .fetch.json now accurately records the type for plugin installations
from registry
as type 'registry'

github: close #86


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/35a3059b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/35a3059b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/35a3059b

Branch: refs/heads/master
Commit: 35a3059bbbe5fcabdb74ff30b8c2845d135dada7
Parents: d50441c
Author: Gorkem Ercan <gorkem.ercan@gmail.com>
Authored: Sun Sep 14 20:56:54 2014 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Tue Oct 7 14:06:38 2014 -0400

----------------------------------------------------------------------
 cordova-lib/src/configparser/ConfigParser.js |  3 +-
 cordova-lib/src/cordova/restore.js           | 15 ++-----
 cordova-lib/src/cordova/save.js              | 55 ++++++++++++++++++++++-
 cordova-lib/src/plugman/fetch.js             | 34 +++++++++-----
 4 files changed, 83 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/35a3059b/cordova-lib/src/configparser/ConfigParser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/configparser/ConfigParser.js b/cordova-lib/src/configparser/ConfigParser.js
index 600ffdc..f116f81 100644
--- a/cordova-lib/src/configparser/ConfigParser.js
+++ b/cordova-lib/src/configparser/ConfigParser.js
@@ -34,7 +34,8 @@ var et = require('elementtree'),
 var FEATURE_SPECIAL_PARAMS = [
     'id',
     'url',
-    'version'
+    'version',
+    'installPath'
 ];
 
 /** Wraps a config.xml file */

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/35a3059b/cordova-lib/src/cordova/restore.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/restore.js b/cordova-lib/src/cordova/restore.js
index 6e4d262..39d2ee9 100644
--- a/cordova-lib/src/cordova/restore.js
+++ b/cordova-lib/src/cordova/restore.js
@@ -70,29 +70,22 @@ function installPluginsFromConfigXML(cfg) {
     }
 
     return features.reduce(function(soFar, featureId) {
-
         var pluginPath =  path.join(plugins_dir, featureId);
         if (fs.existsSync(pluginPath)) {
             // Plugin already exists
             return soFar;
         }
-
         return soFar.then(function() {
             events.emit('log', 'Discovered ' + featureId + ' in config.xml. Installing to
the project');
-
             var feature = cfg.getFeature(featureId);
 
             // Install from given URL if defined or using a plugin id
-            var installFrom = feature.url;
-            if (!installFrom) {
-                installFrom = feature.id;
-                if (!!feature.version) {
-                    installFrom += ('@' + feature.version);
-                }
+            var installFrom = feature.url || feature.installPath || feature.id;
+            if( feature.version && !feature.url && !feature.installPath ){
+                installFrom += ('@' + feature.version);
             }
-
             // Add feature preferences as CLI variables if have any
-            var options = 'undefined' !== typeof feature.variables ? {cli_variables: feature.variables}
: null;
+            var options = {cli_variables: feature.variables };
 
             return plugin('add', installFrom, options);
         });

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/35a3059b/cordova-lib/src/cordova/save.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/save.js b/cordova-lib/src/cordova/save.js
index 568a301..9d34543 100644
--- a/cordova-lib/src/cordova/save.js
+++ b/cordova-lib/src/cordova/save.js
@@ -29,7 +29,9 @@ var path             = require('path'),
     xml              = require('../util/xml-helpers'),
     events           = require('../events'),
     superspawn       = require('./superspawn'),
-    CordovaError     = require('../CordovaError');
+    CordovaError     = require('../CordovaError'),
+    plugman_metadata = require('../plugman/util/metadata'),
+    config_changes   = require('../plugman/util/config-changes');
 
 module.exports = save;
 function save(target, opts){
@@ -102,9 +104,37 @@ function savePlugins(opts){
         var currentPluginPath = path.join(pluginsPath,plugin);
         var name = readPluginName(currentPluginPath);
         var id = plugin;
-        var version = readPluginVersion(currentPluginPath);
+        // filter out the dependency plugins. Top-level plugins list is not always accurate.

+        if(isDependencyPlugin(id)){
+            events.emit('log', 'Skipping ' + plugin+ ', not a top-level plugin');
+            return Q();
+        }
+        //save id
         var params = [{name:'id', value:id}];
+        var fetchData = plugman_metadata.get_fetch_metadata(currentPluginPath);
+        if(fetchData.source){
+            var fetchSource = fetchData.source;
+            if(fetchSource.type === 'git'){
+                //restore the git url
+                var restoredUrl = fetchSource.url;
+                if(fetchSource.ref || fetchSource.subdir){
+                    restoredUrl += '#';
+                    if(fetchSource.ref){
+                        restoredUrl += fetchSource.ref;
+                    }
+                    if(fetchSource.subdir){
+                        restoredUrl += ':'+fetchSource.subdir;
+                    }
+                }
+                params.push({name:'url', value:restoredUrl});
+            }else
+            if(fetchSource.type === 'local'){
+                params.push({name:'installPath', value:fetchSource.path});
+            }
+        }
+        //save version if shrinkwrapped
         if(opts.shrinkwrap){
+            var version = readPluginVersion(currentPluginPath);
             params.push({ name: 'version', value: version });
         }
         configXml.addFeature(name,params);
@@ -114,6 +144,27 @@ function savePlugins(opts){
     }));
 }
 
+function isDependencyPlugin(pluginId){
+    var projectHome = cordova_util.cdProjectRoot();
+    var pluginsPath = path.join(projectHome, 'plugins');
+    var platforms = cordova_util.listPlatforms(projectHome);
+    //If platforms do not exists it is best (but not necessarily accurate) to 
+    //assume that this is a top level plugin. Because installed_plugins (top-level)
+    //info is kept with the platform. Removing platform(s) causes the top-level info 
+    //to be lost.
+    if(platforms.length === 0 ){
+        return false;
+    }
+    for(var i= 0; i< platforms.length; i++){
+        var platform_config = config_changes.get_platform_json(pluginsPath, platforms[i]);
+        if(platform_config.dependent_plugins[pluginId])
+        {
+            return true;
+        }
+    }
+    return false;
+}
+
 function readPluginName(pluginPath){
     var xml_path = path.join(pluginPath, 'plugin.xml');
     var et = xml.parseElementtreeSync(xml_path);

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/35a3059b/cordova-lib/src/plugman/fetch.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/fetch.js b/cordova-lib/src/plugman/fetch.js
index e5ac59d..046356a 100644
--- a/cordova-lib/src/plugman/fetch.js
+++ b/cordova-lib/src/plugman/fetch.js
@@ -42,6 +42,7 @@ var localPlugins = null;
 // Returns a promise.
 module.exports = fetchPlugin;
 function fetchPlugin(plugin_src, plugins_dir, options) {
+     var data = {};//data to be saved to .fetch.json
     // Ensure the containing directory exists.
     shell.mkdir('-p', plugins_dir);
 
@@ -77,7 +78,7 @@ function fetchPlugin(plugin_src, plugins_dir, options) {
         if (options.link) {
             return Q.reject(new CordovaError('--link is not supported for git URLs'));
         } else {
-            var data = {
+            data = {
                 source: {
                     type: 'git',
                     url:  plugin_src,
@@ -98,19 +99,31 @@ function fetchPlugin(plugin_src, plugins_dir, options) {
         }
     } else {
         // If it's not a network URL, it's either a local path or a plugin ID.
-
+       
         var p,  // The Q promise to be returned.
             linkable = true,
             plugin_dir = path.join(plugin_src, options.subdir);
 
         if (fs.existsSync(plugin_dir)) {
             p = Q(plugin_dir);
+            data = {
+                  source: {
+                    type: 'local',
+                    path: plugin_dir
+                    }
+                };
         } else {
             // If there is no such local path, it's a plugin id or id@versionspec.
             // First look for it in the local search path (if provided).
             var pinfo = findLocalPlugin(plugin_src, options.searchpath);
             if (pinfo) {
                 p = Q(pinfo.dir);
+                data = {
+                  source: {
+                    type: 'local',
+                    path: pinfo.dir
+                    }
+                };
                 events.emit('verbose', 'Found ' + plugin_src + ' at ' + pinfo.dir);
             } else if ( options.noregistry ) {
                 p = Q.reject(new CordovaError(
@@ -122,6 +135,12 @@ function fetchPlugin(plugin_src, plugins_dir, options) {
                 linkable = false;
                 events.emit('log', 'Fetching plugin "' + plugin_src + '" via plugin registry');
                 p = registry.fetch([plugin_src], options.client);
+                data = {
+                  source: {
+                    type: 'registry',
+                    id: plugin_src
+                    }
+                };
             }
         }
 
@@ -129,6 +148,9 @@ function fetchPlugin(plugin_src, plugins_dir, options) {
         .then(function(dir) {
             options.plugin_src_dir = dir;
             return copyPlugin(dir, plugins_dir, options.link && linkable);
+        }).then(function(dest){
+             metadata.save_fetch_metadata(dest, data);
+             return dest;
         })
         .then(function(dir) {
             checkID(options.expected_id, dir);
@@ -235,13 +257,5 @@ function copyPlugin(plugin_dir, plugins_dir, link) {
         events.emit('verbose', 'Copying plugin "' + plugin_dir + '" => "' + dest + '"');
         shell.cp('-R', path.join(plugin_dir, '*') , dest);
     }
-
-    var data = {
-        source: {
-            type: 'local',
-            path: plugin_dir
-        }
-    };
-    metadata.save_fetch_metadata(dest, data);
     return dest;
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message