cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [4/4] git commit: CB-3284 moving asset installation to platforms
Date Mon, 29 Apr 2013 06:42:50 GMT
CB-3284 moving asset installation to platforms


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

Branch: refs/heads/master
Commit: 8c2e7ba18e6b5c0e2dfab72f813d3b58344a7572
Parents: 9ff46bc
Author: Anis Kadri <anis@apache.org>
Authored: Sun Apr 28 23:35:57 2013 -0700
Committer: Anis Kadri <anis@apache.org>
Committed: Sun Apr 28 23:41:22 2013 -0700

----------------------------------------------------------------------
 spec/platforms/android.spec.js       |    6 +-
 spec/platforms/blackberry.spec.js    |    6 +-
 spec/platforms/ios.spec.js           |   53 +++++++++++++++++++++++-
 spec/plugins/FaultyPlugin/plugin.xml |    3 +
 spec/prepare.spec.js                 |   10 ++--
 src/platforms/android.js             |   11 +++--
 src/platforms/blackberry.js          |   11 +++--
 src/platforms/common.js              |   17 ++++++++-
 src/platforms/ios.js                 |   11 +++--
 src/prepare.js                       |   61 +++++++++++++---------------
 10 files changed, 129 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/8c2e7ba1/spec/platforms/android.spec.js
----------------------------------------------------------------------
diff --git a/spec/platforms/android.spec.js b/spec/platforms/android.spec.js
index d3c279f..198a4bd 100644
--- a/spec/platforms/android.spec.js
+++ b/spec/platforms/android.spec.js
@@ -197,7 +197,7 @@ describe('android project handler', function() {
                 install('android', temp, 'DummyPlugin', plugins_dir, {}, function() {
                     var s = spyOn(shell, 'rm');
                     android.uninstall(as, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
-                    expect(s).toHaveBeenCalledWith('-rf', path.join(temp, 'assets', 'www',
'plugins', dummy_id));
+                    expect(s).toHaveBeenCalledWith('-Rf', path.join(temp, 'assets', 'www',
'plugins', dummy_id));
                     done();
                 });
             });
@@ -206,8 +206,8 @@ describe('android project handler', function() {
                 install('android', temp, 'DummyPlugin', plugins_dir, {}, function() {
                     var s = spyOn(shell, 'rm');
                     android.uninstall(as, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
-                    expect(s).toHaveBeenCalledWith('-rf', path.join(temp, 'assets', 'www',
'dummyplugin.js'));
-                    expect(s).toHaveBeenCalledWith('-rf', path.join(temp, 'assets', 'www',
'dummyplugin'));
+                    expect(s).toHaveBeenCalledWith('-Rf', path.join(temp, 'assets', 'www',
'dummyplugin.js'));
+                    expect(s).toHaveBeenCalledWith('-Rf', path.join(temp, 'assets', 'www',
'dummyplugin'));
                     done();
                 });
             });

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/8c2e7ba1/spec/platforms/blackberry.spec.js
----------------------------------------------------------------------
diff --git a/spec/platforms/blackberry.spec.js b/spec/platforms/blackberry.spec.js
index 3976096..a4d7e63 100644
--- a/spec/platforms/blackberry.spec.js
+++ b/spec/platforms/blackberry.spec.js
@@ -150,7 +150,7 @@ describe('blackberry project handler', function() {
                 install('blackberry', temp, 'DummyPlugin', plugins_dir, {}, function() {
                     var s = spyOn(shell, 'rm');
                     blackberry.uninstall(as, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
-                    expect(s).toHaveBeenCalledWith('-rf', path.join(temp, 'www', 'plugins',
dummy_id));
+                    expect(s).toHaveBeenCalledWith('-Rf', path.join(temp, 'www', 'plugins',
dummy_id));
                     done();
                 });
             });
@@ -159,8 +159,8 @@ describe('blackberry project handler', function() {
                 install('blackberry', temp, 'DummyPlugin', plugins_dir, {}, function() {
                     var s = spyOn(shell, 'rm');
                     blackberry.uninstall(as, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
-                    expect(s).toHaveBeenCalledWith('-rf', path.join(temp, 'www', 'dummyplugin.js'));
-                    expect(s).toHaveBeenCalledWith('-rf', path.join(temp, 'www', 'dummyplugin'));
+                    expect(s).toHaveBeenCalledWith('-Rf', path.join(temp, 'www', 'dummyplugin.js'));
+                    expect(s).toHaveBeenCalledWith('-Rf', path.join(temp, 'www', 'dummyplugin'));
                     done();
                 });
             });

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/8c2e7ba1/spec/platforms/ios.spec.js
----------------------------------------------------------------------
diff --git a/spec/platforms/ios.spec.js b/spec/platforms/ios.spec.js
index 6097da4..dc3bee5 100644
--- a/spec/platforms/ios.spec.js
+++ b/spec/platforms/ios.spec.js
@@ -25,7 +25,7 @@ var xml_path = path.join(dummyplugin, 'plugin.xml'),
 var platformTag = plugin_et.find('./platform[@name="ios"]');
 var dummy_id = plugin_et._root.attrib['id'];
 var valid_source = platformTag.findall('./source-file'),
-    assets = plugin_et.findall('./asset'),
+    valid_assets = plugin_et.findall('./asset'),
     valid_headers = platformTag.findall('./header-file'),
     valid_resources = platformTag.findall('./resource-file'),
     valid_frameworks = platformTag.findall('./framework'),
@@ -46,6 +46,7 @@ plugin_et = new et.ElementTree(et.XML(xml_test));
 platformTag = plugin_et.find('./platform[@name="ios"]');
 
 var faulty_id = plugin_et._root.attrib['id'];
+var invalid_assets = plugin_et.findall('./asset');
 var invalid_source = platformTag.findall('./source-file');
 var invalid_headers = platformTag.findall('./header-file');
 var invalid_resources = platformTag.findall('./resource-file');
@@ -118,6 +119,7 @@ describe('ios project handler', function() {
             it('should throw if source-file target already exists', function() {
                 var source = copyArray(valid_source);
                 var target = path.join(temp, 'SampleApp', 'Plugins', 'DummyPluginCommand.m');
+                shell.mkdir('-p', path.dirname(target));
                 fs.writeFileSync(target, 'some bs', 'utf-8');
                 expect(function() {
                     ios.install(source, dummy_id, temp, dummyplugin, {});
@@ -224,6 +226,7 @@ describe('ios project handler', function() {
             it('should throw if header-file target already exists', function() {
                 var headers = copyArray(valid_headers);
                 var target = path.join(temp, 'SampleApp', 'Plugins', 'DummyPluginCommand.h');
+                shell.mkdir('-p', path.dirname(target));
                 fs.writeFileSync(target, 'some bs', 'utf-8');
                 expect(function() {
                     ios.install(headers, dummy_id, temp, dummyplugin, {});
@@ -288,6 +291,7 @@ describe('ios project handler', function() {
             it('should throw if resource-file target already exists', function() {
                 var resources = copyArray(valid_resources);
                 var target = path.join(temp, 'SampleApp', 'Resources', 'DummyPlugin.bundle');
+                shell.mkdir('-p', path.dirname(target));
                 fs.writeFileSync(target, 'some bs', 'utf-8');
                 expect(function() {
                     ios.install(resources, dummy_id, temp, dummyplugin, {});
@@ -316,6 +320,45 @@ describe('ios project handler', function() {
                 expect(spy).toHaveBeenCalledWith('-R', path.join(dummyplugin, 'src', 'ios',
'DummyPlugin.bundle'), path.join(temp, 'SampleApp', 'Resources'));
             });
         });
+        
+        describe('of <asset> elements', function() {
+            beforeEach(function() {
+                shell.cp('-rf', ios_config_xml_project, temp);
+            });
+            it('should throw if asset src cannot be found', function() {
+                var assets = copyArray(invalid_assets);
+                expect(function() {
+                    ios.install(assets, faulty_id, temp, faultyplugin, {});
+                }).toThrow('"' + path.resolve(faultyplugin, 'www/main.js') + '" not found!');
+            });
+            it('should throw if asset target already exists', function() {
+                var assets = copyArray(valid_assets);
+                var target = path.join(temp, 'www', 'dummyplugin.js');
+                fs.writeFileSync(target, 'some bs', 'utf-8');
+                expect(function() {
+                    ios.install(assets, dummy_id, temp, dummyplugin, {});
+                }).toThrow('"'+ target + '" already exists!');
+            });
+            it('should cp the file and directory to the right target location', function()
{
+                var assets = copyArray(valid_assets);
+                var spy_cp = spyOn(shell, 'cp').andCallThrough();
+                var spy_mkdir = spyOn(shell, 'mkdir').andCallThrough();
+                ios.install(assets, dummy_id, temp, dummyplugin, {});
+                expect(spy_mkdir).toHaveBeenCalledWith('-p', path.join(temp, 'www'));
+                expect(spy_cp).toHaveBeenCalledWith(path.join(dummyplugin, 'www', 'dummyplugin.js'),
path.join(temp, 'www', 'dummyplugin.js'));
+                expect(spy_cp).toHaveBeenCalledWith('-R', path.join(dummyplugin, 'www', 'dummyplugin/*'),
path.join(temp, 'www', 'dummyplugin'));
+                
+                // make sure the file and directory are properly copies
+                expect(fs.existsSync(path.join(temp, 'www', 'dummyplugin.js'))).toBe(true);
+                expect(fs.statSync(path.join(temp, 'www', 'dummyplugin.js')).isFile()).toBe(true);
+                
+                expect(fs.existsSync(path.join(temp, 'www', 'dummyplugin'))).toBe(true);
+                expect(fs.statSync(path.join(temp, 'www', 'dummyplugin')).isDirectory()).toBe(true);
+                
+                expect(fs.existsSync(path.join(temp, 'www', 'dummyplugin', 'image.jpg'))).toBe(true);
+                expect(fs.statSync(path.join(temp, 'www', 'dummyplugin', 'image.jpg')).isFile()).toBe(true);
+            });
+        });
 
         describe('of <framework> elements', function() {
             beforeEach(function() {
@@ -382,8 +425,12 @@ describe('ios project handler', function() {
         });
 
         describe('of <asset> elements', function() {
-            it('should call rm on specified asset');
-            it('should call rm on the www/plugins/<plugin_id> folder');
+            it('should call rm on specified asset', function() {
+                
+            });
+            it('should call rm on the www/plugins/<plugin_id> folder', function() {
+                
+            });
         });
 
         describe('of <header-file> elements', function() {

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/8c2e7ba1/spec/plugins/FaultyPlugin/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/FaultyPlugin/plugin.xml b/spec/plugins/FaultyPlugin/plugin.xml
index 728a03b..4c49a06 100644
--- a/spec/plugins/FaultyPlugin/plugin.xml
+++ b/spec/plugins/FaultyPlugin/plugin.xml
@@ -27,6 +27,9 @@
 
 	<access origin="build.phonegap.com" />
 	<access origin="s3.amazonaws.com" />
+    <!-- file doesn't exist -->
+    <asset src="www/main.js" target="faultyplugin/main.js" />
+    <asset src="www/index.js" target="faultyplugin/index.js" />
 	
     <!-- android -->
     <platform name="android">

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/8c2e7ba1/spec/prepare.spec.js
----------------------------------------------------------------------
diff --git a/spec/prepare.spec.js b/spec/prepare.spec.js
index e54f102..bd7b118 100644
--- a/spec/prepare.spec.js
+++ b/spec/prepare.spec.js
@@ -27,11 +27,11 @@ describe('prepare', function() {
         prepare(temp, 'android', plugins_dir);
         expect(fs.existsSync(path.join(www, 'cordova_plugins.json'))).toBe(true);
     });
-    it('should copy over assets defined in <asset> elements', function() {
-        prepare(temp, 'android', plugins_dir);
-        expect(fs.existsSync(path.join(www, 'childbrowser_file.html'))).toBe(true);
-        expect(fs.statSync(path.join(www, 'childbrowser')).isDirectory()).toBe(true);
-    });
+//    it('should copy over assets defined in <asset> elements', function() {
+//        prepare(temp, 'android', plugins_dir);
+//        expect(fs.existsSync(path.join(www, 'childbrowser_file.html'))).toBe(true);
+//        expect(fs.statSync(path.join(www, 'childbrowser')).isDirectory()).toBe(true);
+//    });
     it('should create a plugins directory in an application\'s www directory', function()
{
         prepare(temp, 'android', plugins_dir);
         expect(fs.existsSync(path.join(www, 'plugins'))).toBe(true);

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/8c2e7ba1/src/platforms/android.js
----------------------------------------------------------------------
diff --git a/src/platforms/android.js b/src/platforms/android.js
index 3d0e75d..1234746 100644
--- a/src/platforms/android.js
+++ b/src/platforms/android.js
@@ -87,10 +87,13 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir,
variables
                     }
                     break;
                 case 'asset':
-                    if (action == 'uninstall') {
-                        var target = mod.attrib.target;
-                        shell.rm('-rf', path.resolve(module.exports.www_dir(project_dir),
target));
-                        shell.rm('-rf', path.resolve(module.exports.www_dir(project_dir),
'plugins', plugin_id));
+                    var src = mod.attrib['src'];
+                    var target = mod.attrib['target'];
+                    if (action == 'install') {
+                        common.copyFile(plugin_dir, src, module.exports.www_dir(project_dir),
target);
+                    } else {
+                        common.removeFile(module.exports.www_dir(project_dir), target);
+                        common.removeFileF(path.resolve(module.exports.www_dir(project_dir),
'plugins', plugin_id));
                     }
                     break;
                 default:

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/8c2e7ba1/src/platforms/blackberry.js
----------------------------------------------------------------------
diff --git a/src/platforms/blackberry.js b/src/platforms/blackberry.js
index d740559..6d20036 100644
--- a/src/platforms/blackberry.js
+++ b/src/platforms/blackberry.js
@@ -75,10 +75,13 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir,
variables
                     }
                     break;
                 case 'asset':
-                    if (action == 'uninstall') {
-                        var target = mod.attrib.target;
-                        shell.rm('-rf', path.resolve(module.exports.www_dir(project_dir),
target));
-                        shell.rm('-rf', path.resolve(module.exports.www_dir(project_dir),
'plugins', plugin_id));
+                    var src = mod.attrib['src'];
+                    var target = mod.attrib['target'];
+                    if (action == 'install') {
+                        common.copyFile(plugin_dir, src, module.exports.www_dir(project_dir),
target);
+                    } else {
+                        common.removeFile(module.exports.www_dir(project_dir), target);
+                        common.removeFileF(path.resolve(module.exports.www_dir(project_dir),
'plugins', plugin_id));
                     }
                     break;
                 default:

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/8c2e7ba1/src/platforms/common.js
----------------------------------------------------------------------
diff --git a/src/platforms/common.js b/src/platforms/common.js
index 8c1897c..7d294b9 100644
--- a/src/platforms/common.js
+++ b/src/platforms/common.js
@@ -22,7 +22,22 @@ module.exports = {
         src = module.exports.resolveSrcPath(plugin_dir, src);
         dest = module.exports.resolveTargetPath(project_dir, dest);
         shell.mkdir('-p', path.dirname(dest));
-        shell.cp(src, dest);
+
+        // XXX sheljs decides to create a directory when -R|-r is used which sucks. http://goo.gl/nbsjq
+        if(fs.statSync(src).isDirectory()) {
+            shell.cp('-R', src+'/*', dest);
+        } else {
+            shell.cp(src, dest);
+        }
+    },
+    // checks if file exists and then deletes. Error if doesn't exist
+    removeFile:function(project_dir, src) {
+        var file = module.exports.resolveSrcPath(project_dir, src);
+        shell.rm('-Rf', file);
+    },
+    // deletes file/directory without checking
+    removeFileF:function(file) {
+        shell.rm('-Rf', file);
     },
     // Sometimes we want to remove some java, and prune any unnecessary empty directories
     deleteJava:function(project_dir, destFile) {

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/8c2e7ba1/src/platforms/ios.js
----------------------------------------------------------------------
diff --git a/src/platforms/ios.js b/src/platforms/ios.js
index 0185863..101062a 100644
--- a/src/platforms/ios.js
+++ b/src/platforms/ios.js
@@ -192,10 +192,13 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir,
variables
                     }
                     break;
                 case 'asset':
-                    if (action == 'uninstall') {
-                        var target = mod.attrib.target;
-                        shell.rm('-rf', path.resolve(module.exports.www_dir(), target));
-                        shell.rm('-rf', path.resolve(module.exports.www_dir(), 'plugins',
plugin_id));
+                    var src = mod.attrib['src'];
+                    var target = mod.attrib['target'];
+                    if (action == 'install') {
+                        common.copyFile(plugin_dir, src, module.exports.www_dir(project_dir),
target);
+                    } else {
+                        common.removeFile(module.exports.www_dir(project_dir), target);
+                        common.removeFile(path.resolve(module.exports.www_dir(project_dir),
'plugins', plugin_id));
                     }
                     break;
                 case 'header-file':

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/8c2e7ba1/src/prepare.js
----------------------------------------------------------------------
diff --git a/src/prepare.js b/src/prepare.js
index 1d24726..43332d2 100644
--- a/src/prepare.js
+++ b/src/prepare.js
@@ -54,35 +54,36 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir)
{
             var plugin_id = xml.getroot().attrib.id;
     
             // Copy all the <asset>s into the platform's www/
-            var assets = xml.findall('./asset');
-            assets && assets.forEach(function(asset) {
-                var target = asset.attrib.target;
-               
-                var lastSlash = target.lastIndexOf('/');
-                var dirname  = lastSlash < 0 ? ''     : target.substring(0, lastSlash);
-                var basename = lastSlash < 0 ? target : target.substring(lastSlash + 1);
-    
-                var targetDir = path.join(wwwDir, dirname);
-                 
-                shell.mkdir('-p', targetDir);
-    
-                var srcFile = path.join(pluginDir, asset.attrib.src);
-                var targetFile = path.join(targetDir, basename);
-    
-                var cpOptions = '-f';
-                
-                if(fs.statSync(srcFile).isDirectory()){
-                    shell.mkdir('-p',targetFile);
-                    srcFile = srcFile+'/*';
-                    cpOptions = '-Rf';
-                }
-    
-                shell.cp(cpOptions, [srcFile], targetFile);
-                
-            });
+           // var assets = xml.findall('./asset');
+           // assets && assets.forEach(function(asset) {
+           //     var target = asset.attrib.target;
+           //    
+           //     var lastSlash = target.lastIndexOf('/');
+           //     var dirname  = lastSlash < 0 ? ''     : target.substring(0, lastSlash);
+           //     var basename = lastSlash < 0 ? target : target.substring(lastSlash +
1);
+    
+           //     var targetDir = path.join(wwwDir, dirname);
+           //      
+           //     shell.mkdir('-p', targetDir);
+    
+           //     var srcFile = path.join(pluginDir, asset.attrib.src);
+           //     var targetFile = path.join(targetDir, basename);
+    
+           //     var cpOptions = '-f';
+           //     
+           //     if(fs.statSync(srcFile).isDirectory()){
+           //         shell.mkdir('-p',targetFile);
+           //         srcFile = srcFile+'/*';
+           //         cpOptions = '-Rf';
+           //     }
+    
+           //     shell.cp(cpOptions, [srcFile], targetFile);
+           //     
+           // });
     
             // And then add the plugins dir to the platform's www.
             var platformPluginsDir = path.join(wwwDir, 'plugins');
+            // XXX this should not be here if there are no js-module. It leaves an empty
plugins/ directory
             shell.mkdir('-p', platformPluginsDir);
     
             var generalModules = xml.findall('./js-module');
@@ -94,13 +95,7 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir)
{
     
             allModules.forEach(function(module) {
                 // Copy the plugin's files into the www directory.
-                var dirname = module.attrib.src;
-                var lastSlash = dirname.lastIndexOf('/');
-                if (lastSlash >= 0) {
-                    dirname = dirname.substring(0, lastSlash);
-                } else {
-                    dirname = ''; // Just the file, no subdir.
-                }
+                var dirname = path.dirname(module.attrib.src);
     
                 var dir = path.join(platformPluginsDir, plugin_id, dirname);
                 shell.mkdir('-p', dir);


Mime
View raw message