You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ti...@apache.org on 2013/10/01 01:50:05 UTC

[1/2] git commit: [CB-4872] - adding in custom semver check for project

Updated Branches:
  refs/heads/sdkCheck [created] feb5f2e72


[CB-4872] - adding in custom semver check for project


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

Branch: refs/heads/sdkCheck
Commit: feb5f2e7218a0db550c409e50564d9ec6bda262f
Parents: aa48d73
Author: Tim Kim <ti...@adobe.com>
Authored: Wed Sep 25 14:30:11 2013 -0700
Committer: Tim Kim <ti...@adobe.com>
Committed: Mon Sep 30 16:49:40 2013 -0700

----------------------------------------------------------------------
 spec/install.spec.js                        |  26 +--
 spec/plugins/EnginePluginAndroid/plugin.xml |   2 +-
 spec/plugins/EnginePluginiOS/plugin.xml     |  34 ++++
 spec/util/version-compare.spec.js           | 205 +++++++++++++++++++++++
 src/install.js                              |   4 +-
 src/util/version-compare.js                 | 136 +++++++++++++++
 6 files changed, 391 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/feb5f2e7/spec/install.spec.js
----------------------------------------------------------------------
diff --git a/spec/install.spec.js b/spec/install.spec.js
index 459a42c..925c4e8 100644
--- a/spec/install.spec.js
+++ b/spec/install.spec.js
@@ -8,7 +8,7 @@ var install = require('../src/install'),
     path    = require('path'),
     shell   = require('shelljs'),
     child_process = require('child_process'),
-    semver  = require('semver'),
+    version_compare  = require('../src/util/version-compare'),
     temp    = __dirname,
     dummyplugin = 'DummyPlugin',
     dummy_id = 'com.phonegap.plugins.dummyplugin',
@@ -91,7 +91,7 @@ describe('install', function() {
             expect(spy).toHaveBeenCalledWith('results', 'Plugin "'+dummy_id+'" already installed, \'sall good.');
         });
         it('should check version if plugin has engine tag', function(){
-            var spy = spyOn(semver, 'satisfies').andReturn(true);
+            var spy = spyOn(version_compare, 'satisfies').andReturn(true);
             exec.andCallFake(function(cmd, cb) {
                 cb(null, '2.5.0\n', '');
             });
@@ -103,8 +103,8 @@ describe('install', function() {
                 expect(spy).toHaveBeenCalledWith('2.5.0','>=2.3.0');
             });
         });
-        it('should check version and munge it a little if it has "rc" in it so it plays nice with semver (introduce a dash in it)', function() {
-            var spy = spyOn(semver, 'satisfies').andReturn(true);
+        it('should check version and munge it a little if it has "rc" in it so it plays nice with version_compare (introduce a dash in it)', function() {
+            var spy = spyOn(version_compare, 'satisfies').andReturn(true);
             exec.andCallFake(function(cmd, cb) {
                 cb(null, '3.0.0rc1\n');
             });
@@ -117,7 +117,7 @@ describe('install', function() {
             });
         });
         it('should check specific platform version over cordova version if specified', function() {
-            var spy = spyOn(semver, 'satisfies').andReturn(true);
+            var spy = spyOn(version_compare, 'satisfies').andReturn(true);
             exec.andCallFake(function(cmd, cb) {
                 cb(null, '3.1.0\n', '');
             });
@@ -130,20 +130,20 @@ describe('install', function() {
             });
         });
         it('should check platform sdk version if specified', function() {
-            var spy = spyOn(semver, 'satisfies').andReturn(true);
+            var spy = spyOn(version_compare, 'satisfies').andReturn(true);
             exec.andCallFake(function(cmd, cb) {
-                cb(null, '4.3\n', '');
+                cb(null, '18\n', '');
             });
             runs(function() {
                 installPromise(install('android', temp, 'enginepluginAndroid', plugins_dir, {}));
             });
             waitsFor(function() { return done; }, 'install promise never resolved', 500);
             runs(function() {
-                expect(spy).toHaveBeenCalledWith('4.3','>=4.3');
+                expect(spy).toHaveBeenCalledWith('18','>=18');
             });
         });
         it('should check plugmans version', function() {
-            var spy = spyOn(semver, 'satisfies').andReturn(true);
+            var spy = spyOn(version_compare, 'satisfies').andReturn(true);
             runs(function() {
                 installPromise(install('android', temp, 'engineplugin', plugins_dir, {}));
             });
@@ -153,7 +153,7 @@ describe('install', function() {
             });
         });
         it('should check custom engine version', function() {
-            var spy = spyOn(semver, 'satisfies').andReturn(true);
+            var spy = spyOn(version_compare, 'satisfies').andReturn(true);
             runs(function() {
                 installPromise(install('android', temp, 'engineplugin', plugins_dir, {}));
             });
@@ -163,7 +163,7 @@ describe('install', function() {
             });
         });
         it('should check custom engine version that supports multiple platforms', function() {
-            var spy = spyOn(semver, 'satisfies').andReturn(true);
+            var spy = spyOn(version_compare, 'satisfies').andReturn(true);
             runs(function() {
                 installPromise(install('android', temp, 'engineplugin', plugins_dir, {}));
             });
@@ -173,7 +173,7 @@ describe('install', function() {
             });
         });
         it('should not check custom engine version that is not supported for platform', function() {
-            var spy = spyOn(semver, 'satisfies').andReturn(true);
+            var spy = spyOn(version_compare, 'satisfies').andReturn(true);
             runs(function() {
                 installPromise(install('blackberry10', temp, 'engineplugin', plugins_dir, {}));
             });
@@ -302,7 +302,7 @@ describe('install', function() {
             });
         });
         it('should throw if plugin version is less than the minimum requirement', function(){
-            var spy = spyOn(semver, 'satisfies').andReturn(false);
+            var spy = spyOn(version_compare, 'satisfies').andReturn(false);
             exec.andCallFake(function(cmd, cb) {
                 cb(null, '0.0.1\n', '');
             });

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/feb5f2e7/spec/plugins/EnginePluginAndroid/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/EnginePluginAndroid/plugin.xml b/spec/plugins/EnginePluginAndroid/plugin.xml
index dbbb4aa..fe2bce2 100644
--- a/spec/plugins/EnginePluginAndroid/plugin.xml
+++ b/spec/plugins/EnginePluginAndroid/plugin.xml
@@ -26,7 +26,7 @@
     <engines>
         <engine name="cordova" version=">=3.0.0"/>
         <engine name="cordova-android" version=">=3.1.0"/>
-        <engine name="android-sdk" version=">=18.0.0"/>
+        <engine name="android-sdk" version=">=18"/>
     </engines>
     
 </plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/feb5f2e7/spec/plugins/EnginePluginiOS/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/EnginePluginiOS/plugin.xml b/spec/plugins/EnginePluginiOS/plugin.xml
new file mode 100644
index 0000000..d7a9a8e
--- /dev/null
+++ b/spec/plugins/EnginePluginiOS/plugin.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed 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://www.phonegap.com/ns/plugins/1.0"
+    xmlns="http://www.phonegap.com/ns/plugins/1.0"
+    id="com.cordova.engine"
+    version="1.0.0">
+
+    <name>Engine Choo Choo</name>
+
+    <engines>
+        <engine name="cordova" version=">=3.0.0"/>
+        <engine name="cordova-android" version=">=3.1.0"/>
+        <engine name="apple-ios" version="6.1"/>
+        <engine name="apple-osx" version=">10.0"/>
+        <engine name="apple-xcode" version=">=4.6.3"/>
+    </engines>
+    
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/feb5f2e7/spec/util/version-compare.spec.js
----------------------------------------------------------------------
diff --git a/spec/util/version-compare.spec.js b/spec/util/version-compare.spec.js
new file mode 100644
index 0000000..e356404
--- /dev/null
+++ b/spec/util/version-compare.spec.js
@@ -0,0 +1,205 @@
+/*
+ *
+ *
+ * Licensed 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 version_compare = require('../../src/util/version-compare');
+// if major satisfies, all satisfied
+// if major equals, continue to next
+// if major not satisfies, fail
+
+// if minor satisfies, all satisfied,
+// if minor equal, continue
+// if minor not satisfied, fail
+
+// if patch satisfied, all satisfied
+// if patch not satisfied, fail
+
+describe('version-compare', function(){
+    describe('=', function() {
+        it('should satisfy', function(){
+            expect(version_compare.satisfies('0','0')).toBe(true);
+            expect(version_compare.satisfies('0.0','0.0')).toBe(true);
+            expect(version_compare.satisfies('0.0.0','0.0.0')).toBe(true);
+            expect(version_compare.satisfies('0','1')).toBe(false);
+            expect(version_compare.satisfies('0.0','0.1')).toBe(false);
+            expect(version_compare.satisfies('0.0.0','0.0.1')).toBe(false);
+        });
+        
+    });
+    describe('<', function() {
+        it('should satisfy', function(){
+            expect(version_compare.satisfies('0','<1')).toBe(true);
+            expect(version_compare.satisfies('0','<0')).toBe(false);
+            expect(version_compare.satisfies('1','<0')).toBe(false);
+            
+            expect(version_compare.satisfies('0.0','<1.0')).toBe(true);
+            expect(version_compare.satisfies('0.1','<1.0')).toBe(true);
+            expect(version_compare.satisfies('0.1','<0.1')).toBe(false);
+            expect(version_compare.satisfies('0.0','<0.1')).toBe(true);
+            expect(version_compare.satisfies('0.0','<0.0')).toBe(false);
+            expect(version_compare.satisfies('1.0','<1.0')).toBe(false);
+            expect(version_compare.satisfies('1.1','<1.0')).toBe(false);
+            expect(version_compare.satisfies('1.1','<0.1')).toBe(false);
+            expect(version_compare.satisfies('1.0','<0.1')).toBe(false);
+            expect(version_compare.satisfies('1.0','<0.0')).toBe(false);
+                       
+            expect(version_compare.satisfies('0.0.0','<1.0.0')).toBe(true);  
+            expect(version_compare.satisfies('0.1.0','<1.0.0')).toBe(true); 
+            expect(version_compare.satisfies('0.0.1','<1.0.0')).toBe(true); 
+            expect(version_compare.satisfies('0.1.1','<1.0.0')).toBe(true); 
+            expect(version_compare.satisfies('0.0.0','<0.1.0')).toBe(true);
+            expect(version_compare.satisfies('0.0.1','<0.1.0')).toBe(true);
+            expect(version_compare.satisfies('0.1.0','<0.2.0')).toBe(true); 
+            expect(version_compare.satisfies('0.0.0','<0.0.1')).toBe(true);            
+            expect(version_compare.satisfies('0.0.0','<0.0.0')).toBe(false); 
+            expect(version_compare.satisfies('1.0.0','<1.0.1')).toBe(true);  
+            expect(version_compare.satisfies('1.1.0','<1.0.1')).toBe(false); 
+            expect(version_compare.satisfies('1.0.1','<1.1.0')).toBe(true); 
+            expect(version_compare.satisfies('1.1.1','<1.0.0')).toBe(false); 
+            expect(version_compare.satisfies('1.0.0','<0.1.0')).toBe(false);
+            expect(version_compare.satisfies('1.0.1','<0.1.0')).toBe(false);
+            expect(version_compare.satisfies('1.1.0','<0.2.0')).toBe(false); 
+            expect(version_compare.satisfies('1.0.0','<0.0.1')).toBe(false);            
+            expect(version_compare.satisfies('1.0.0','<0.0.0')).toBe(false); 
+        });
+    });
+    describe('<=', function() {
+        it('should satisfy', function(){
+            expect(version_compare.satisfies('0','<=1')).toBe(true);
+            expect(version_compare.satisfies('0','<=0')).toBe(true);
+            expect(version_compare.satisfies('1','<=0')).toBe(false);
+            
+            expect(version_compare.satisfies('0.0','<=1.0')).toBe(true);
+            expect(version_compare.satisfies('0.1','<=1.0')).toBe(true);
+            expect(version_compare.satisfies('0.1','<=0.1')).toBe(true);
+            expect(version_compare.satisfies('0.0','<=0.1')).toBe(true);
+            expect(version_compare.satisfies('0.0','<=0.0')).toBe(true);
+            expect(version_compare.satisfies('1.0','<=1.0')).toBe(true);
+            expect(version_compare.satisfies('1.1','<=1.0')).toBe(false);
+            expect(version_compare.satisfies('1.1','<=0.1')).toBe(false);
+            expect(version_compare.satisfies('1.0','<=0.1')).toBe(false);
+            expect(version_compare.satisfies('1.0','<=0.0')).toBe(false);
+                       
+            expect(version_compare.satisfies('0.0.0','<=1.0.0')).toBe(true);  
+            expect(version_compare.satisfies('0.1.0','<=1.0.0')).toBe(true); 
+            expect(version_compare.satisfies('0.0.1','<=1.0.0')).toBe(true); 
+            expect(version_compare.satisfies('0.1.1','<=1.0.0')).toBe(true); 
+            expect(version_compare.satisfies('0.0.0','<=0.1.0')).toBe(true);
+            expect(version_compare.satisfies('0.0.1','<=0.1.0')).toBe(true);
+            expect(version_compare.satisfies('0.1.0','<=0.2.0')).toBe(true); 
+            expect(version_compare.satisfies('0.0.0','<=0.0.1')).toBe(true);            
+            expect(version_compare.satisfies('0.0.0','<=0.0.0')).toBe(true); 
+            expect(version_compare.satisfies('1.0.0','<=1.0.1')).toBe(true);  
+            expect(version_compare.satisfies('1.1.0','<=1.0.1')).toBe(false); 
+            expect(version_compare.satisfies('1.0.1','<=1.1.0')).toBe(true); 
+            expect(version_compare.satisfies('1.1.1','<=1.0.0')).toBe(false); 
+            expect(version_compare.satisfies('1.0.0','<=0.1.0')).toBe(false);
+            expect(version_compare.satisfies('1.0.1','<=0.1.0')).toBe(false);
+            expect(version_compare.satisfies('1.1.0','<=0.2.0')).toBe(false); 
+            expect(version_compare.satisfies('1.0.0','<=0.0.1')).toBe(false);            
+            expect(version_compare.satisfies('1.0.0','<=0.0.0')).toBe(false);             
+        });
+    });
+
+    describe('>', function() {
+        it('should satisfy', function(){
+            expect(version_compare.satisfies('0','>1')).toBe(false);
+            expect(version_compare.satisfies('0','>0')).toBe(false);
+            expect(version_compare.satisfies('1','>0')).toBe(true);
+            
+            expect(version_compare.satisfies('0.0','>1.0')).toBe(false);
+            expect(version_compare.satisfies('0.1','>1.0')).toBe(false);
+            expect(version_compare.satisfies('0.1','>0.1')).toBe(false);
+            expect(version_compare.satisfies('0.0','>0.1')).toBe(false);
+            expect(version_compare.satisfies('0.0','>0.0')).toBe(false);
+            expect(version_compare.satisfies('1.0','>1.0')).toBe(false);
+            expect(version_compare.satisfies('1.1','>1.0')).toBe(true);
+            expect(version_compare.satisfies('1.1','>0.1')).toBe(true);
+            expect(version_compare.satisfies('1.0','>0.1')).toBe(true);
+            expect(version_compare.satisfies('1.0','>0.0')).toBe(true);
+                       
+            expect(version_compare.satisfies('0.0.0','>1.0.0')).toBe(false);  
+            expect(version_compare.satisfies('0.1.0','>1.0.0')).toBe(false); 
+            expect(version_compare.satisfies('0.0.1','>1.0.0')).toBe(false); 
+            expect(version_compare.satisfies('0.1.1','>1.0.0')).toBe(false); 
+            expect(version_compare.satisfies('0.0.0','>0.1.0')).toBe(false);
+            expect(version_compare.satisfies('0.0.1','>0.1.0')).toBe(false);
+            expect(version_compare.satisfies('0.1.0','>0.2.0')).toBe(false); 
+            expect(version_compare.satisfies('0.0.0','>0.0.1')).toBe(false);            
+            expect(version_compare.satisfies('0.0.0','>0.0.0')).toBe(false); 
+            expect(version_compare.satisfies('1.0.0','>1.0.1')).toBe(false);  
+            expect(version_compare.satisfies('1.1.0','>1.0.1')).toBe(true); 
+            expect(version_compare.satisfies('1.0.1','>1.1.0')).toBe(false); 
+            expect(version_compare.satisfies('1.1.1','>1.0.0')).toBe(true); 
+            expect(version_compare.satisfies('1.0.0','>0.1.0')).toBe(true);
+            expect(version_compare.satisfies('1.0.1','>0.1.0')).toBe(true);
+            expect(version_compare.satisfies('1.1.0','>0.2.0')).toBe(true); 
+            expect(version_compare.satisfies('1.0.0','>0.0.1')).toBe(true);            
+            expect(version_compare.satisfies('1.0.0','>0.0.0')).toBe(true);             
+        });
+    });
+    describe('>=', function() {
+        it('should satisfy', function(){
+            expect(version_compare.satisfies('0','>=1')).toBe(false);
+            expect(version_compare.satisfies('0','>=0')).toBe(true);
+            expect(version_compare.satisfies('1','>=0')).toBe(true);
+            
+            expect(version_compare.satisfies('0.0','>=1.0')).toBe(false);
+            expect(version_compare.satisfies('0.1','>=1.0')).toBe(false);
+            expect(version_compare.satisfies('0.1','>=0.1')).toBe(true);
+            expect(version_compare.satisfies('0.0','>=0.1')).toBe(false);
+            expect(version_compare.satisfies('0.0','>=0.0')).toBe(true);
+            expect(version_compare.satisfies('1.0','>=1.0')).toBe(true);
+            expect(version_compare.satisfies('1.1','>=1.0')).toBe(true);
+            expect(version_compare.satisfies('1.1','>=0.1')).toBe(true);
+            expect(version_compare.satisfies('1.0','>=0.1')).toBe(true);
+            expect(version_compare.satisfies('1.0','>=0.0')).toBe(true);
+                       
+            expect(version_compare.satisfies('0.0.0','>=1.0.0')).toBe(false);  
+            expect(version_compare.satisfies('0.1.0','>=1.0.0')).toBe(false); 
+            expect(version_compare.satisfies('0.0.1','>=1.0.0')).toBe(false); 
+            expect(version_compare.satisfies('0.1.1','>=1.0.0')).toBe(false); 
+            expect(version_compare.satisfies('0.0.0','>=0.1.0')).toBe(false);
+            expect(version_compare.satisfies('0.0.1','>=0.1.0')).toBe(false);
+            expect(version_compare.satisfies('0.1.0','>=0.2.0')).toBe(false); 
+            expect(version_compare.satisfies('0.0.0','>=0.0.1')).toBe(false);            
+            expect(version_compare.satisfies('0.0.0','>=0.0.0')).toBe(true); 
+            expect(version_compare.satisfies('1.0.0','>=1.0.1')).toBe(false);  
+            expect(version_compare.satisfies('1.1.0','>=1.0.1')).toBe(true); 
+            expect(version_compare.satisfies('1.0.1','>=1.1.0')).toBe(false); 
+            expect(version_compare.satisfies('1.1.1','>=1.0.0')).toBe(true); 
+            expect(version_compare.satisfies('1.0.0','>=0.1.0')).toBe(true);
+            expect(version_compare.satisfies('1.0.1','>=0.1.0')).toBe(true);
+            expect(version_compare.satisfies('1.1.0','>=0.2.0')).toBe(true); 
+            expect(version_compare.satisfies('1.0.0','>=0.0.1')).toBe(true);            
+            expect(version_compare.satisfies('1.0.0','>=0.0.0')).toBe(true);             
+        });
+    });
+    
+    describe('incorrect formats', function(){
+        it('should throw an error with no version string', function(){
+            expect(function(){version_compare.satisfies('','')}).toThrow(new Error('No version string detected. Unable to compare to versions. Please check the output from your version script and the engine tag in your plugin.xml.'));
+            expect(function(){version_compare.satisfies('1','')}).toThrow(new Error('No version string detected. Unable to compare to versions. Please check the output from your version script and the engine tag in your plugin.xml.'));
+            expect(function(){version_compare.satisfies('','1')}).toThrow(new Error('No version string detected. Unable to compare to versions. Please check the output from your version script and the engine tag in your plugin.xml.'));
+        });
+        it('should throw an error with differing version format', function(){
+            expect(function(){version_compare.satisfies('1','1.0')}).toThrow(new Error('Different version string format detected. Unable to compare to versions. Please check the output from your version script and the engine tag in your plugin.xml.'));
+            expect(function(){version_compare.satisfies('1','1.0.0')}).toThrow(new Error('Different version string format detected. Unable to compare to versions. Please check the output from your version script and the engine tag in your plugin.xml.'));
+        });   
+        
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/feb5f2e7/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index ac70f82..b3a7498 100644
--- a/src/install.js
+++ b/src/install.js
@@ -5,7 +5,7 @@ var path = require('path'),
     action_stack = require('./util/action-stack'),
     shell = require('shelljs'),
     child_process = require('child_process'),
-    semver = require('semver'),
+    version_compare = require('./util/version-compare'),
     config_changes = require('./util/config-changes'),
     xml_helpers = require('./util/xml-helpers'),
     Q = require('q'),
@@ -63,7 +63,7 @@ function possiblyFetch(actions, platform, project_dir, id, plugins_dir, options)
 function checkEngines(engines) {
     for(var i = 0; i < engines.length; i++) {
         var engine = engines[i];
-        if(semver.satisfies(engine.currentVersion, engine.minVersion) || engine.currentVersion == null){
+        if(version_compare.satisfies(engine.currentVersion, engine.minVersion) || engine.currentVersion == null){
             // engine ok!
         }else{
             return Q.reject(new Error('Plugin doesn\'t support this project\'s '+engine.name+' version. '+engine.name+': ' + engine.currentVersion + ', failed version requirement: ' + engine.minVersion));

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/feb5f2e7/src/util/version-compare.js
----------------------------------------------------------------------
diff --git a/src/util/version-compare.js b/src/util/version-compare.js
new file mode 100644
index 0000000..625a97c
--- /dev/null
+++ b/src/util/version-compare.js
@@ -0,0 +1,136 @@
+function getVersionObject(versionString){
+    var majorReg = /\d+/,
+    minorReg = /\d+\.\d+/,
+    patchReg = /\d+\.\d+\.\d+/;
+    
+    var major = null,
+    minor = null,
+    patch = null;
+    
+    if(majorReg.test(versionString)){
+        major = parseInt(versionString.match(majorReg)[0]);
+    }else{
+        throw new Error('No version string detected. Unable to compare to versions. Please check the output from your version script and the engine tag in your plugin.xml.');
+    }
+    
+    if(minorReg.test(versionString)){
+        minor = parseInt(versionString.match(minorReg)[0].split('.')[1]);
+    }
+    
+    if(patchReg.test(versionString)){
+        patch = parseInt(versionString.match(patchReg)[0].split('.')[2]);
+    }
+    return {
+        major: major,
+        minor: minor,
+        patch: patch
+    }
+}
+
+function getComparator(versionString){
+    var compareReg = /^(<|>)=?/;
+    var comparator;
+    
+    if(compareReg.test(versionString)){
+        comparator = versionString.match(compareReg)[0];
+    }else{
+        comparator = '=';
+    }
+    return comparator; 
+}
+
+function compare(numOne, numTwo, comparator){
+    switch (comparator){
+        case '<':
+            return (numOne < numTwo);
+        break;
+        
+        case '<=':
+            return (numOne <= numTwo);
+        break;
+        
+        case '>':
+            return (numOne > numTwo);
+        break;
+        
+        case '>=':
+            return (numOne >= numTwo);
+        break;
+        
+        default:
+            return (numOne == numTwo);
+    }
+}
+
+function checkVersionFormat(versionOut, versionRange){
+    var majorOk = false, 
+    minorOk = false, 
+    patchOk = false;
+    
+    if(versionOut.major!=null && versionRange.major!=null){
+        majorOk = true;
+    }
+    
+    if(versionOut.minor!=null && versionRange.minor!=null){
+        minorOk = true;
+    }else if((versionOut.minor!=null && versionRange.minor==null) || (versionOut.minor==null && versionRange.minor!=null)){
+        throw new Error('Different version string format detected. Unable to compare to versions. Please check the output from your version script and the engine tag in your plugin.xml.');
+    }
+    
+    if(versionOut.patch!=null && versionRange.patch!=null){
+        patchOk = true;
+    }else if((versionOut.patch!=null && versionRange.patch==null) || (versionOut.patch==null && versionRange.patch!=null)){
+        throw new Error('Different version string format detected. Unable to compare to versions. Please check the output from your version script and the engine tag in your plugin.xml.');
+    }
+    
+    if(majorOk && minorOk && patchOk){
+        return 'toPatch';
+    }else if(majorOk && minorOk && !patchOk){
+        return 'toMinor';
+    }else if(majorOk && !minorOk && !patchOk){
+        return 'toMajor';
+    }
+}
+
+function satisfy(versionOut, versionRange, comparator){
+    var format = checkVersionFormat(versionOut, versionRange);
+    
+    switch(format){
+        case 'toMajor':
+            return compare(versionOut.major, versionRange.major, comparator);
+        break;
+        
+        case 'toMinor':
+            if(compare(versionOut.major, versionRange.major, '=')){
+                return compare(versionOut.minor, versionRange.minor, comparator);
+            }else{
+                return compare(versionOut.major, versionRange.major, comparator);
+            }
+            
+        break;
+        
+        case 'toPatch':
+            if(compare(versionOut.major, versionRange.major, '=')){
+                if(compare(versionOut.minor, versionRange.minor, '=')){
+                    return compare(versionOut.patch, versionRange.patch, comparator);
+                }else{
+                    return compare(versionOut.minor, versionRange.minor, comparator);
+                }
+            }else{
+                return compare(versionOut.major, versionRange.major, comparator);
+            }
+        break;
+    }
+}
+
+module.exports = {
+    satisfies: function(versionOut, versionRange){
+        var theVersionOut = getVersionObject(versionOut);
+        var theVersionRange = getVersionObject(versionRange);
+        var comparator = getComparator(versionRange);
+
+        return satisfy(theVersionOut, theVersionRange, comparator);
+    }
+}
+
+


[2/2] git commit: [CB-4872] - updated paths to version files

Posted by ti...@apache.org.
[CB-4872] - updated paths to version files


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

Branch: refs/heads/sdkCheck
Commit: aa48d735c372be13045be1f77b5125ced321a679
Parents: f240acc
Author: Tim Kim <ti...@adobe.com>
Authored: Mon Sep 23 17:32:25 2013 -0700
Committer: Tim Kim <ti...@adobe.com>
Committed: Mon Sep 30 16:49:40 2013 -0700

----------------------------------------------------------------------
 spec/plugins/EnginePluginAndroid/plugin.xml | 2 +-
 src/util/default-engines.js                 | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/aa48d735/spec/plugins/EnginePluginAndroid/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/EnginePluginAndroid/plugin.xml b/spec/plugins/EnginePluginAndroid/plugin.xml
index 7ada4ae..dbbb4aa 100644
--- a/spec/plugins/EnginePluginAndroid/plugin.xml
+++ b/spec/plugins/EnginePluginAndroid/plugin.xml
@@ -26,7 +26,7 @@
     <engines>
         <engine name="cordova" version=">=3.0.0"/>
         <engine name="cordova-android" version=">=3.1.0"/>
-        <engine name="android-sdk" version=">=4.3"/>
+        <engine name="android-sdk" version=">=18.0.0"/>
     </engines>
     
 </plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/aa48d735/src/util/default-engines.js
----------------------------------------------------------------------
diff --git a/src/util/default-engines.js b/src/util/default-engines.js
index 4fd4a65..21f5feb 100644
--- a/src/util/default-engines.js
+++ b/src/util/default-engines.js
@@ -22,13 +22,15 @@ module.exports = function(project_dir){
         
         // TODO: these scripts have not been made!
         'apple-xcode' : 
-            { 'platform':'ios', 'scriptSrc':  path.join(project_dir,'cordova','apple-xcode-version') },
+            { 'platform':'ios', 'scriptSrc':  path.join(project_dir,'cordova','apple_xcode_version') },
         'apple-ios' : 
-            { 'platform':'ios', 'scriptSrc': path.join(project_dir,'cordova','apple-ios-version') },
+            { 'platform':'ios', 'scriptSrc': path.join(project_dir,'cordova','apple_ios_version') },
+        'apple-osx' : 
+            { 'platform':'ios', 'scriptSrc': path.join(project_dir,'cordova','apple_osx_version') },
         'blackberry-webworks' : 
             { 'platform':'blackberry10', 'scriptSrc': path.join(project_dir,'blackberry-webworks-version') },
         'android-sdk' : 
             // will have to parse string output from android list targets
-            { 'platform':'android', 'scriptSrc': path.join(project_dir,'cordova','android-sdk-version') }
+            { 'platform':'android', 'scriptSrc': path.join(project_dir,'cordova','android_sdk_version') }
     }
 };