Updated Branches: refs/heads/master 43fbb2807 -> 8d92da7df
added error code for plugin installed, added check of plugin value to see if installed Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/6f102ebe Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/6f102ebe Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/6f102ebe Branch: refs/heads/master Commit: 6f102ebefeffd9331329b3a99fd9848761030da3 Parents: e3592a1 Author: Steven Gill <[email protected]> Authored: Tue Apr 23 00:03:47 2013 -0700 Committer: Steven Gill <[email protected]> Committed: Tue Apr 23 00:03:47 2013 -0700 ---------------------------------------------------------------------- platforms/android.js | 22 ++++++++++++---------- platforms/blackberry.js | 15 +++++++++------ platforms/ios.js | 16 ++++++++++------ plugman.js | 1 + 4 files changed, 32 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/6f102ebe/platforms/android.js ---------------------------------------------------------------------- diff --git a/platforms/android.js b/platforms/android.js index 323ff28..ba25586 100644 --- a/platforms/android.js +++ b/platforms/android.js @@ -42,23 +42,24 @@ exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et, var , configChanges = getConfigChanges(platformTag); variables = variables || {} - + // get config.xml filename var config_xml_filename = 'res/xml/config.xml'; if(fs.existsSync(path.resolve(project_dir, 'res/xml/plugins.xml'))) { config_xml_filename = 'res/xml/plugins.xml'; } - + // collision detection if(action.match(/force-/) == null) { if(action == "install" && pluginInstalled(plugin_et, project_dir, config_xml_filename)) { - throw "Plugin "+plugin_id+" already installed" + throw new Error("Plugin "+plugin_id+" already installed"); } else if(action == "uninstall" && !pluginInstalled(plugin_et, project_dir, config_xml_filename)) { - throw "Plugin "+plugin_id+" not installed" + throw new Error("Plugin "+plugin_id+" not installed"); } } else { action = action.replace('force-', ''); } + root = et.Element("config-file"); root.attrib['parent'] = '.' @@ -212,13 +213,14 @@ function androidPackageName(project_dir) { function pluginInstalled(plugin_et, project_dir, config_xml_filename) { var tag_xpath = util.format('./platform[@name="android"]/config-file[@target="%s"]/plugin', config_xml_filename); - - var plugin_tag = plugin_et.find(tag_xpath); + var plugin_tag = plugin_et.find(tag_xpath); if (!plugin_tag) { return false; } - var plugin_name = plugin_tag.attrib.name; - - return (fs.readFileSync(path.resolve(project_dir, config_xml_filename), 'utf8') - .match(new RegExp(plugin_name, "g")) != null); + var plugin_name = plugin_tag.attrib.name, + plugin_id = plugin_et._root.attrib['id'], + readfile = fs.readFileSync(path.resolve(project_dir, config_xml_filename), 'utf8'); + if ((readfile.match(new RegExp(plugin_name, "g")) != null) || (readfile.match(new RegExp(plugin_id, "g")) != null)){ + return true; + } } http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/6f102ebe/platforms/blackberry.js ---------------------------------------------------------------------- diff --git a/platforms/blackberry.js b/platforms/blackberry.js index c927181..f189eb3 100644 --- a/platforms/blackberry.js +++ b/platforms/blackberry.js @@ -48,9 +48,9 @@ exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et) { // collision detection if(action.match(/force-/) == null) { if(action == "install" && pluginInstalled(plugin_et, project_dir)) { - throw "Plugin "+plugin_id+" already installed" + throw new Error("Plugin "+plugin_id+" already installed") } else if(action == "uninstall" && !pluginInstalled(plugin_et, project_dir)) { - throw "Plugin "+plugin_id+" not installed" + throw new Error("Plugin "+plugin_id+" not installed") } } else { action = action.replace('force-', ''); @@ -174,7 +174,10 @@ function pluginInstalled(plugin_et, project_dir) { if (!config_tag) { return false; } - var plugin_name = config_tag.attrib.id; - return (fs.readFileSync(path.resolve(project_dir, 'config.xml'), 'utf8') - .match(new RegExp(plugin_name, "g")) != null); -} + var plugin_name = plugin_tag.attrib.name, + plugin_id = plugin_et._root.attrib['id'], + readfile = fs.readFileSync(path.resolve(project_dir, config_xml_filename), 'utf8'); + if ((readfile.match(new RegExp(plugin_name, "g")) != null) || (readfile.match(new RegExp(plugin_id, "g")) != null)){ + return true; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/6f102ebe/platforms/ios.js ---------------------------------------------------------------------- diff --git a/platforms/ios.js b/platforms/ios.js index 6473936..4e68082 100644 --- a/platforms/ios.js +++ b/platforms/ios.js @@ -41,7 +41,7 @@ exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et, var // we don't want CordovaLib's xcode project var project_files = glob.sync(project_dir + '/*.xcodeproj/project.pbxproj'); - if (!project_files.length) throw "does not appear to be an xcode project (no xcode project file)"; + if (!project_files.length) throw new Error("does not appear to be an xcode project (no xcode project file)"); var pbxPath = project_files[0]; var xcodeproj = xcode.project(project_files[0]); @@ -58,7 +58,7 @@ exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et, var }); if (!config_files.length) { - throw "does not appear to be a PhoneGap project"; + throw new Error("does not appear to be a PhoneGap project"); } var config_file = config_files[0]; @@ -73,9 +73,9 @@ exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et, var // collision detection if(action.match(/force-/) == null) { if(action == "install" && pluginInstalled(plugin_et, config_file)) { - throw "Plugin "+plugin_id+" already installed" + throw new Error("Plugin "+plugin_id+" already installed") } else if(action == "uninstall" && !pluginInstalled(plugin_et, config_file)) { - throw "Plugin "+plugin_id+" not installed" + throw new Error("Plugin "+plugin_id+" not installed") } } else { action = action.replace('force-', ''); @@ -287,8 +287,12 @@ function pluginInstalled(plugin_et, config_path) { if (!config_tag) { return false; } - var plugin_name = config_tag.attrib.name || config_tag.attrib.key; - return (fs.readFileSync(config_path, 'utf8').match(new RegExp(plugin_name, "g")) != null); + var plugin_name = config_tag.attrib.name || config_tag.attrib.key, + plugin_id = plugin_et._root.attrib['id'], + readfile = fs.readFileSync(path.resolve(project_dir, config_xml_filename), 'utf8'); + if ((readfile.match(new RegExp(plugin_name, "g")) != null) || (readfile.match(new RegExp(plugin_id, "g")) != null)){ + return true; + } } function updateConfigXml(action, config_path, plugin_et) { http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/6f102ebe/plugman.js ---------------------------------------------------------------------- diff --git a/plugman.js b/plugman.js index a422dab..73b434e 100755 --- a/plugman.js +++ b/plugman.js @@ -130,6 +130,7 @@ function execAction(action, platform, project_dir, plugin_dir, cli_variables) { platform_modules[platform].handlePlugin(revert, project_dir, plugin_dir, plugin_et, filtered_variables); } catch(e) { console.log("Changes might have not been reverted: "+e.message); + process.exit(1); } } }
