You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by mm...@apache.org on 2014/05/16 21:54:13 UTC

[1/3] git commit: support for shrinkwrap flag

Repository: cordova-lib
Updated Branches:
  refs/heads/master 9daafe8c8 -> b3a0b3a7c


support for shrinkwrap flag

Adds support for a shrinkwrap flag. Unless the flag is specified the saved
data will not contain the version information.


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

Branch: refs/heads/master
Commit: 4fb7e472f12a4cd353246261d1fc201253518695
Parents: ebe4ce9
Author: Gorkem Ercan <go...@gmail.com>
Authored: Thu May 15 15:43:44 2014 -0400
Committer: Michal Mocny <mm...@gmail.com>
Committed: Fri May 16 14:47:20 2014 -0400

----------------------------------------------------------------------
 cordova-lib/src/cordova/save.js | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/4fb7e472/cordova-lib/src/cordova/save.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/save.js b/cordova-lib/src/cordova/save.js
index b767caa..6c1bc0b 100644
--- a/cordova-lib/src/cordova/save.js
+++ b/cordova-lib/src/cordova/save.js
@@ -24,7 +24,8 @@ var cordova_util    = require('./util'),
     Q                = require('q'),
     events           = require('./events');
 
-module.exports = function save(target){
+module.exports = function save(target, opts){
+  opts = opts || {};
   var projectHome = cordova_util.cdProjectRoot();
   var configPath = cordova_util.projectConfig(projectHome);
   var configXml = new ConfigParser(configPath);
@@ -53,7 +54,10 @@ module.exports = function save(target){
     var name = readPluginName(currentPluginPath);
     var id = plugin;
     var version = readPluginVersion(currentPluginPath);
-    var params = [{name:"id", value:id},{name:"version", value: version}];
+    var params = [{name:"id", value:id}];
+    if(opts.shrinkwrap){
+        params.push({name:"version", value: version});
+    }
     configXml.addFeature(name,params);
     configXml.write();
     events.emit('results', 'Saved plugin info for "'+plugin+'" to config.xml');


[2/3] git commit: Initial implementation for restore and save plugin

Posted by mm...@apache.org.
Initial implementation for restore and save plugin

Adds a new save command to CLI which persists the currently added plugins to config.xml. There
is also an accompanying restore command which scans the config.xml and
restores the missing plugins that are listed.  Adds a new function to ConfigParser for adding
features. Updates plugin rm command to print a warning to also remove a
plugin that has been added to config.xml as a restore target.

Adds two new test for the new commands namely restore.spec and save.spec and
enhances the existing ConfigParser.spec for the new addFeature function.


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

Branch: refs/heads/master
Commit: ebe4ce9f2f9af20fa534656544fc2dea454e9c28
Parents: 9daafe8
Author: Gorkem Ercan <go...@gmail.com>
Authored: Tue May 13 21:05:48 2014 -0400
Committer: Michal Mocny <mm...@gmail.com>
Committed: Fri May 16 14:47:20 2014 -0400

----------------------------------------------------------------------
 cordova-lib/spec-cordova/ConfigParser.spec.js | 15 ++++
 cordova-lib/spec-cordova/restore.spec.js      | 69 +++++++++++++++++++
 cordova-lib/spec-cordova/save.spec.js         | 63 +++++++++++++++++
 cordova-lib/src/cordova/ConfigParser.js       | 16 +++++
 cordova-lib/src/cordova/cordova.js            |  2 +
 cordova-lib/src/cordova/plugin.js             | 11 +++
 cordova-lib/src/cordova/restore.js            | 76 +++++++++++++++++++++
 cordova-lib/src/cordova/save.js               | 79 ++++++++++++++++++++++
 8 files changed, 331 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/ebe4ce9f/cordova-lib/spec-cordova/ConfigParser.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/ConfigParser.spec.js b/cordova-lib/spec-cordova/ConfigParser.spec.js
index 2c745be..a1ba102 100644
--- a/cordova-lib/spec-cordova/ConfigParser.spec.js
+++ b/cordova-lib/spec-cordova/ConfigParser.spec.js
@@ -80,5 +80,20 @@ describe('config.xml parser', function () {
                 expect(cfg.getPreference('zimzooo!')).toEqual(undefined);
             });
         });
+        describe('feature',function(){
+            it('should allow adding a new feature', function(){
+                cfg.addFeature('myfeature');
+                var features = cfg.doc.findall('feature');
+                expect(features[0].attrib.name).toEqual('myfeature');
+            });
+            it('should allow adding features with params', function(){
+                cfg.addFeature('afeature', JSON.parse('[{"name":"paraname", "value":"paravalue"}]'));
+                var features = cfg.doc.findall('feature');
+                expect(features[0].attrib.name).toEqual('afeature');
+                var params = features[0].findall('param');
+                expect(params[0].attrib.name).toEqual('paraname');
+                expect(params[0].attrib.value).toEqual('paravalue');
+            });
+        });
     });
 });

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/ebe4ce9f/cordova-lib/spec-cordova/restore.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/restore.spec.js b/cordova-lib/spec-cordova/restore.spec.js
new file mode 100644
index 0000000..a47b795
--- /dev/null
+++ b/cordova-lib/spec-cordova/restore.spec.js
@@ -0,0 +1,69 @@
+/**
+    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.
+*/
+
+var project_dir = path.join(__dirname, 'fixtures', 'base');
+
+var cordova = require('../src/cordova/cordova'),
+    cordova_util = require('../src/cordova/util'),
+    ConfigParser = require('../src/cordova/ConfigParser');
+
+describe('restore command', function(){
+  var is_cordova, result, config_add_feature, cd_project;
+
+   function wrapper(f, post) {
+        runs(function() {
+            Q().then(f).then(function() { result = true; }, function(err) { result = err; });
+        });
+        waitsFor(function() { return result; }, 'promise never resolved', 500);
+        runs(post);
+    }
+
+  beforeEach(function(){
+    is_cordova = spyOn(cordova_util, 'isCordova').andReturn(project_dir);
+   
+  });
+
+  it('should not run outside of a Cordova-based project by calling util.isCordova', function() {
+     is_cordova.andReturn(false);
+     wrapper(cordova.raw.restore, function() {
+        expect(result).toEqual(new Error('Current working directory is not a Cordova-based project.'));
+     });
+  });
+
+  it('should not try to restore featrues from config.xml', function(){
+ 
+ 
+   cd_project_root = spyOn(cordova_util, 'cdProjectRoot').andReturn(project_dir);
+ 
+    var call_count =0;
+    ConfigParser.prototype.write = function(){
+      call_count++;
+    }
+
+     expect(call_count).toEqual(0);
+     
+     cordova.restore('plugins');
+
+     expect(call_count).toEqual(0);
+  });
+
+
+
+
+});

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/ebe4ce9f/cordova-lib/spec-cordova/save.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/save.spec.js b/cordova-lib/spec-cordova/save.spec.js
new file mode 100644
index 0000000..b068ebc
--- /dev/null
+++ b/cordova-lib/spec-cordova/save.spec.js
@@ -0,0 +1,63 @@
+/**
+    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.
+*/
+
+var project_dir = path.join(__dirname, 'fixtures', 'base');
+
+var cordova = require('../src/cordova/cordova'),
+    cordova_util = require('../src/cordova/util'),
+    ConfigParser = require('../src/cordova/ConfigParser');
+
+describe('save command', function(){
+  var is_cordova, result, config_add_feature, cd_project;
+
+   function wrapper(f, post) {
+        runs(function() {
+            Q().then(f).then(function() { result = true; }, function(err) { result = err; });
+        });
+        waitsFor(function() { return result; }, 'promise never resolved', 500);
+        runs(post);
+    }
+
+  beforeEach(function(){
+    is_cordova = spyOn(cordova_util, 'isCordova').andReturn(project_dir);
+   
+  });
+
+  it('should not run outside of a Cordova-based project by calling util.isCordova', function() {
+     is_cordova.andReturn(false);
+     wrapper(cordova.raw.save, function() {
+        expect(result).toEqual(new Error('Current working directory is not a Cordova-based project.'));
+     });
+  });
+
+  it('should not try to add features to config.xml', function(){
+   cd_project_root = spyOn(cordova_util, 'cdProjectRoot').andReturn(project_dir);
+    var call_count =0;
+    ConfigParser.prototype.write = function(){
+      call_count++;
+    }
+    expect(call_count).toEqual(0);
+    cordova.save('plugins');
+    expect(call_count).toEqual(0);
+  });
+
+
+
+
+});

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/ebe4ce9f/cordova-lib/src/cordova/ConfigParser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/ConfigParser.js b/cordova-lib/src/cordova/ConfigParser.js
index a6850d2..b8a89e0 100644
--- a/cordova-lib/src/cordova/ConfigParser.js
+++ b/cordova-lib/src/cordova/ConfigParser.js
@@ -155,6 +155,22 @@ ConfigParser.prototype = {
 
         return ret;
     },
+    /**
+     *This does not check for duplicate feature entries
+     */
+    addFeature: function (name, params){ 
+      var el = new et.Element('feature');
+        el.attrib.name = name;
+        if(params){
+          params.forEach(function(param){
+            var p = new et.Element('param');
+            p.attrib.name = param.name;
+            p.attrib.value = param.value;
+            el.append(p);
+          });
+        }
+        this.doc.getroot().append(el);
+    },    
     write:function() {
         fs.writeFileSync(this.path, this.doc.write({indent: 4}), 'utf-8');
     }

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/ebe4ce9f/cordova-lib/src/cordova/cordova.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/cordova.js b/cordova-lib/src/cordova/cordova.js
index abd6709..6fcb05e 100644
--- a/cordova-lib/src/cordova/cordova.js
+++ b/cordova-lib/src/cordova/cordova.js
@@ -64,5 +64,7 @@ addModuleProperty(module, 'platforms', './platform', true);
 addModuleProperty(module, 'compile', './compile', true);
 addModuleProperty(module, 'run', './run', true);
 addModuleProperty(module, 'info', './info', true);
+addModuleProperty(module, 'save', './save', true);
+addModuleProperty(module, 'restore', './restore', true);
 
 

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/ebe4ce9f/cordova-lib/src/cordova/plugin.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/plugin.js b/cordova-lib/src/cordova/plugin.js
index ec60954..06433e9 100644
--- a/cordova-lib/src/cordova/plugin.js
+++ b/cordova-lib/src/cordova/plugin.js
@@ -26,6 +26,8 @@ var cordova_util  = require('./util'),
     config        = require('./config'),
     Q             = require('q'),
     CordovaError  = require('../CordovaError'),
+    ConfigParser  = require('./ConfigParser'),
+    fs            = require('fs'),
     PluginInfo    = require('../PluginInfo'),
     events        = require('./events');
 
@@ -173,6 +175,15 @@ module.exports = function plugin(command, targets, opts) {
                             var platformRoot = path.join(projectRoot, 'platforms', platform);
                             var platforms = require('./platforms');
                             var parser = new platforms[platform].parser(platformRoot);
+                            //check if plugin is restorable and warn
+                            var configPath = cordova_util.projectConfig(projectRoot);
+                            if(fs.existsSync(configPath)){//should not happen with real life but needed for tests
+                                var configXml = new ConfigParser(configPath);
+                                var features = configXml.doc.findall('./feature/param[@name="id"][@value="'+target+'"]/..');
+                                if(features && features.length){
+                                    events.emit('results','"'+target + '" plugin is restorable, call "cordova save plugins" to remove it from restorable plugins list');
+                                }
+                            }                            
                             events.emit('verbose', 'Calling plugman.uninstall on plugin "' + target + '" for platform "' + platform + '"');
                             return plugman.raw.uninstall.uninstallPlatform(platform, platformRoot, target, path.join(projectRoot, 'plugins'));
                         });

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/ebe4ce9f/cordova-lib/src/cordova/restore.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/restore.js b/cordova-lib/src/cordova/restore.js
new file mode 100644
index 0000000..6414e00
--- /dev/null
+++ b/cordova-lib/src/cordova/restore.js
@@ -0,0 +1,76 @@
+/**
+    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.
+*/
+
+var cordova_util    = require('./util'),
+    ConfigParser     = require('./ConfigParser'),
+    path             = require('path'),
+    xml              = require('../util/xml-helpers')
+    Q                = require('q'),
+    fs               = require('fs'),
+    plugin           = require('./plugin'),
+    events           = require('./events');
+
+module.exports = function restore(target){
+    var projectHome = cordova_util.cdProjectRoot();
+    var configPath = cordova_util.projectConfig(projectHome);
+    var configXml = new ConfigParser(configPath);    
+    return installPluginsFromConfigXML(configXml);
+}
+
+
+//returns a Promise
+function installPluginsFromConfigXML(cfg){
+        //Install plugins that are listed on config.xml
+        var pluginsFromConfig = new Array();
+        var projectRoot = cordova_util.cdProjectRoot();
+        var plugins_dir = path.join(projectRoot, 'plugins');
+
+        var features = cfg.doc.findall('feature');
+        features.forEach(function(feature){
+          var params = feature.findall('param');
+          var pluginId = "";
+          var pluginVersion = "";
+          for( var i =0; i < params.length; i++){
+            if(params[i].attrib.name === 'id'){
+              pluginId = params[i].attrib.value;
+            }
+            if(params[i].attrib.name === 'version'){
+              pluginVersion = params[i].attrib.value;
+            }
+          } 
+          var pluginPath =  path.join(plugins_dir,pluginId);
+          // contents of the plugins folder takes precedence hence
+          // we ignore if the correct version is installed or not.
+          if(pluginId !== "" && !fs.existsSync(pluginPath)){
+            if( pluginVersion !== ""){
+              pluginId = pluginId +"@"+pluginVersion;
+            }
+            events.emit('log', "Discovered "+ pluginId + " in config.xml. Installing to the project")
+            pluginsFromConfig.push(pluginId);
+          }
+
+        })
+        
+        //Use cli instead of plugman directly ensuring all the hooks 
+        // to get fired.  
+        if(pluginsFromConfig.length >0){
+            return plugin("add",pluginsFromConfig);
+        }
+        return Q.all("No config.xml plugins to install");
+}

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/ebe4ce9f/cordova-lib/src/cordova/save.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/save.js b/cordova-lib/src/cordova/save.js
new file mode 100644
index 0000000..b767caa
--- /dev/null
+++ b/cordova-lib/src/cordova/save.js
@@ -0,0 +1,79 @@
+/**
+    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.
+*/
+
+var cordova_util    = require('./util'),
+    ConfigParser     = require('./ConfigParser'),
+    path             = require('path'),
+    xml              = require('../util/xml-helpers')
+    Q                = require('q'),
+    events           = require('./events');
+
+module.exports = function save(target){
+  var projectHome = cordova_util.cdProjectRoot();
+  var configPath = cordova_util.projectConfig(projectHome);
+  var configXml = new ConfigParser(configPath);
+  var pluginsPath = path.join(projectHome, 'plugins');
+  var plugins = cordova_util.findPlugins(pluginsPath);
+  var features = configXml.doc.findall('./feature/param[@name="id"]/..');
+  //clear obsolete features with id params.
+  for(var i=0; i<features.length; i++){
+     //somehow elementtree remove fails on me  
+     var childs = configXml.doc.getroot().getchildren();
+     var idx = childs.indexOf(features[i]);
+     if(idx > -1){
+        childs.splice(idx,1);
+      }
+  }
+  // persist the removed features here if there are no plugins 
+  // to be added to config.xml otherwise we can delay the 
+  // persist to add feature    
+  if((!plugins || plugins.length<1) &&
+        (features && features.length)){
+      configXml.write();
+  }
+
+  return Q.all(plugins.map(function(plugin){
+    var currentPluginPath = path.join(pluginsPath,plugin);
+    var name = readPluginName(currentPluginPath);
+    var id = plugin;
+    var version = readPluginVersion(currentPluginPath);
+    var params = [{name:"id", value:id},{name:"version", value: version}];
+    configXml.addFeature(name,params);
+    configXml.write();
+    events.emit('results', 'Saved plugin info for "'+plugin+'" to config.xml');
+    return Q();
+  }));
+}
+
+function readPluginName(pluginPath){
+    var xml_path = path.join(pluginPath, 'plugin.xml');
+    var et = xml.parseElementtreeSync(xml_path);
+    var el = et.getroot().find('name');
+    if(el && el.text){
+       return el.text.trim();
+    }
+    return "";
+}
+
+function readPluginVersion(pluginPath){
+    var xml_path = path.join(pluginPath, 'plugin.xml');
+    var et = xml.parseElementtreeSync(xml_path);
+    var version = et.getroot().attrib.version;
+    return version;
+}


[3/3] git commit: CB-6709 Remove merges/ folder for default apps

Posted by mm...@apache.org.
CB-6709 Remove merges/ folder for default apps


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

Branch: refs/heads/master
Commit: b3a0b3a7c77e6ef5312b1797e23f1656a8e79989
Parents: 4fb7e47
Author: Michal Mocny <mm...@gmail.com>
Authored: Fri May 16 15:53:03 2014 -0400
Committer: Michal Mocny <mm...@gmail.com>
Committed: Fri May 16 15:53:03 2014 -0400

----------------------------------------------------------------------
 cordova-lib/src/cordova/create.js | 3 ---
 1 file changed, 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/b3a0b3a7/cordova-lib/src/cordova/create.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/create.js b/cordova-lib/src/cordova/create.js
index 1e996a2..f721901 100644
--- a/cordova-lib/src/cordova/create.js
+++ b/cordova-lib/src/cordova/create.js
@@ -197,9 +197,6 @@ function create(dir, id, name, cfg) {
 
         // Create basic project structure.
         shell.mkdir(path.join(dir, 'platforms'));
-        if ( !custom_merges) {
-            shell.mkdir(path.join(dir, 'merges'));
-        }
         shell.mkdir(path.join(dir, 'plugins'));
         shell.mkdir(path.join(dir, 'hooks'));