You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Mike Billau (JIRA)" <ji...@apache.org> on 2013/10/10 22:11:42 UTC

[jira] [Commented] (CB-5016) add then rm of dependent plugin as top level plugin breaks environment

    [ https://issues.apache.org/jira/browse/CB-5016?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13791938#comment-13791938 ] 

Mike Billau commented on CB-5016:
---------------------------------

Think I have found the issue, pull request is here: https://github.com/apache/cordova-plugman/pull/26
Tested with npm test, it passed without any problems.
Do you guys see any issues with this?  The main problem was that we were always telling plugman that a dependent plugin was not a "top_level_plugin" and thus could be found in plugins/{platform}.json in the "dependency_plugins" object. This is not always the case, like when you install File, then File-Transfer....both of these plugins would be a "top_level_plugin" and found in installed_plugins, but when the tools recurse into removing File, it only tries to remove the entry from dependency_plugins. This means that cordova plugin ls would show no plugins, but the platform.json would still list an independently installed plugin in "installed_plugins".

This has nothing to do with a separate issue that if you install a dependent plugin as a top level plugin, it should not be automatically removed when a consuming plugin is removed. That is, 
cordova plugin add File
cordova plugin add File-Transfer
cordova plugin rm File-Transfer
cordova plugin ls
Reality:  []
Expected: [File]  - I would not expect it to automatically remove a plugin that I manually added. 


> add then rm of dependent plugin as top level plugin breaks environment 
> -----------------------------------------------------------------------
>
>                 Key: CB-5016
>                 URL: https://issues.apache.org/jira/browse/CB-5016
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Plugman
>         Environment: Windows 7
>            Reporter: Mike Billau
>
> Removing a dependent plugin that was installed as a default top level plugin breaks the environment because during plugin add, the plugin name gets added to plugins/platform.json under "installed_plugins" and not  under "dependent_plugins". However, in plugin rm, the plugin code gets fully removed from the work space but the name is left in "installed_plugins" because the tools search for it in "dependent_plugins."
> *Scenario 1* - Install the dependent plugin first
> cordova create Sample && cd Sample
> cordova platform add android
> cordova plugin add org.apache.cordova.file
> cordova plugin add org.apache.cordova.file-transfer (depends on File)
> cordova plugin ls
> [org.apache.cordova.file, org.apache.cordova.file-transfer]
> *Now if you look at platforms/android.json, you will see that both plugins were added to "installed_plugins"*:
> cat platforms/android.json
> {noformat}
>     "installed_plugins": {
>         "org.apache.cordova.file": {
>             "PACKAGE_NAME": "io.cordova.hellocordova"
>         },
>         "org.apache.cordova.file-transfer": {
>             "PACKAGE_NAME": "io.cordova.hellocordova"
>         }
>     },
>     "dependent_plugins": {}
> {noformat}
> This leaves us in an invalid state when you go to remove the file-transfer plugin because for some reason it removes both the file-transfer and file plugin code, but it does not remove the file entry from "installed_plugins".
> cordova plugin rm org.apache.cordova.file-transfer
> cat platforms/android.json:
> {noformat}
> "installed_plugins":{"org.apache.cordova.file":{"PACKAGE_NAME":"io.cordova.hellocordova"}},"dependent_plugins":{}}
> {noformat}
> but:
> cordova plugin ls
> [No plugins added. Use cordova plugin add <plugin>]
> and:
> cordova build (and cordova prepare, etc.) 
> [Error: ENOENT, no such file or directory, "C:\.........plugins\org.apache.cordova.file]
> *Scenario 2* - Install the lower level plugin and let plugman automatically install the dependencies:
> cordova create Sample2 && cd Sample2
> cordova platform add android
> cordova plugin add org.apache.cordova.file-transfer (depends on File, it will automatically get pulled down and installed)
> cordova plugin ls
> [org.apache.cordova.file, org.apache.cordova.file-transfer]
> *Now if you look, /platforms/android.json will be different than in Scenario 1*
> cat platforms/android.json:
> {noformat}
>     "installed_plugins": {
>         "org.apache.cordova.file-transfer": {
>             "PACKAGE_NAME": "io.cordova.hellocordova"
>         }
>     },
>     "dependent_plugins": {
>         "org.apache.cordova.file": {
>             "PACKAGE_NAME": "io.cordova.hellocordova"
>         }
>     }
> {noformat}
> You can see that now the File plugin is listed as a dependent_plugin. This is great, because now when you remove file-transfer, it will also remove file plugin:
> cordova plugin rm org.apache.cordova.file-transfer
> cat plugins/android.js:
> {noformat}
>     "installed_plugins": {},
>     "dependent_plugins": {}
> {noformat}
> and cordova build android will work just fine. 
> So the problem here seems to be that if a dependent plugin was added manually, it will be added under installed_plugins and not dependent_plugins. Later when the consuming plugin is deleted, the tools delete the plugin code from the workspace but are not able to remove this plugin from the installed_plugins entry (presumably because it searches in the dependent_plugin object.) This leaves the project in a broken state because *plugin ls* does not show the installed plugin, but the tools will try to copy the file at MyApp/plugins/org.apache.cordova.****, whatever is listed in plugins/android.json file.
> I think the fix would be:  When doing plugin uninstall, only remove plugins from the workspace if:
> 1) the plugin is detected to be a dependent plugin, (already being done since *cordova plugin rm org.apache.cordova.file-transfer removes the org.apache.cordova.file code) and
> 2. the plugin is listed in "dependent_plugins" section of  /plugins/platform.json



--
This message was sent by Atlassian JIRA
(v6.1#6144)