@@ -128,11 +128,14 @@ export class CordovaProjectPluginsService implements IPluginsService {
128
128
if ( config ) {
129
129
corePlugins = this . $project . getProperty ( CordovaProjectPluginsService . CORE_PLUGINS_PROPERTY_NAME , config ) ;
130
130
} else {
131
- corePlugins = < string [ ] > _ . union ( this . $project . getProperty ( CordovaProjectPluginsService . CORE_PLUGINS_PROPERTY_NAME , this . $projectConstants . DEBUG_CONFIGURATION_NAME ) , this . $project . getProperty ( CordovaProjectPluginsService . CORE_PLUGINS_PROPERTY_NAME , this . $projectConstants . RELEASE_CONFIGURATION_NAME ) ) ;
131
+ corePlugins = _ . union < string > ( this . $project . getProperty ( CordovaProjectPluginsService . CORE_PLUGINS_PROPERTY_NAME , this . $projectConstants . DEBUG_CONFIGURATION_NAME ) ,
132
+ this . $project . getProperty ( CordovaProjectPluginsService . CORE_PLUGINS_PROPERTY_NAME , this . $projectConstants . RELEASE_CONFIGURATION_NAME ) ) ;
132
133
}
133
134
134
135
return _ . map ( corePlugins , pluginIdentifier => {
135
- let plugin = this . identifierToPlugin [ pluginIdentifier ] ;
136
+ let [ name , version ] = pluginIdentifier . split ( "@" ) ;
137
+ let plugin = this . getBestMatchingPlugin ( name , version ) ;
138
+
136
139
if ( ! plugin ) {
137
140
let failMessage = config ?
138
141
`You have enabled an invalid plugin: ${ pluginIdentifier } for the ${ config } build configuration. Check your .${ config } .abproject file in the project root and correct or remove the invalid plugin entry.` :
@@ -144,6 +147,11 @@ export class CordovaProjectPluginsService implements IPluginsService {
144
147
} ) ;
145
148
}
146
149
150
+ private getBestMatchingPlugin ( name : string , version : string ) : IPlugin {
151
+ let plugins = this . getPluginInstancesByName ( name , version ) ;
152
+ return _ . find ( plugins , pl => pl . type === PluginType . MarketplacePlugin ) || plugins [ 0 ] ;
153
+ }
154
+
147
155
public getAvailablePlugins ( pluginsCount ?: number ) : IPlugin [ ] {
148
156
let plugins = _ . values ( this . identifierToPlugin ) ;
149
157
if ( this . $project . projectData ) {
@@ -183,8 +191,13 @@ export class CordovaProjectPluginsService implements IPluginsService {
183
191
if ( installedPluginInstances && installedPluginInstances . length > 0 ) {
184
192
let installedPluginsType = _ . chain ( installedPluginInstances ) . groupBy ( ( pl : IPlugin ) => pl . type ) . keys ( ) . value ( ) ;
185
193
if ( installedPluginsType . length > 1 ) {
186
- // We should NEVER get here. CorePlugins and Marketplace plugins cannot have duplicate identifiers.
187
- this . $errors . failWithoutHelp ( "There are several plugins with name '%s' and they have different types: '%s'" , pluginName , installedPluginsType . join ( ", " ) ) ;
194
+ // In case integrated and Marketplace plugins have duplicate identifiers, try using MarketplacePlugin
195
+ let mpPlugin = _ . find ( installedPluginInstances , pl => pl . type === PluginType . MarketplacePlugin ) ;
196
+ if ( mpPlugin ) {
197
+ return this . modifyInstalledMarketplacePlugin ( mpPlugin . data . Identifier , version ) . wait ( ) ;
198
+ } else {
199
+ this . $errors . failWithoutHelp ( "There are several plugins with name '%s' and they have different types: '%s'" , pluginName , installedPluginsType . join ( ", " ) ) ;
200
+ }
188
201
} else if ( installedPluginsType . length === 1 ) {
189
202
if ( installedPluginsType [ 0 ] . toString ( ) === PluginType . MarketplacePlugin . toString ( ) ) {
190
203
return this . modifyInstalledMarketplacePlugin ( installedPluginInstances [ 0 ] . data . Identifier , version ) . wait ( ) ;
@@ -199,11 +212,11 @@ export class CordovaProjectPluginsService implements IPluginsService {
199
212
}
200
213
}
201
214
202
- let pluginToAdd = this . getPluginByName ( pluginName ) ;
215
+ let pluginToAdd = this . getBestMatchingPlugin ( pluginName , version ) ;
203
216
if ( pluginToAdd . type === PluginType . MarketplacePlugin ) {
204
217
version = this . selectPluginVersion ( version , pluginToAdd ) . wait ( ) ;
205
218
if ( ! this . isPluginSupported ( pluginToAdd , this . $project . projectData . FrameworkVersion , version ) ) {
206
- this . $errors . failWithoutHelp ( `Plugin ${ pluginName } is not avaialble for framework version '${ this . $project . projectData . FrameworkVersion } '.` ) ;
219
+ this . $errors . failWithoutHelp ( `Plugin ${ pluginName } is not available for framework version '${ this . $project . projectData . FrameworkVersion } '.` ) ;
207
220
}
208
221
}
209
222
@@ -327,7 +340,7 @@ export class CordovaProjectPluginsService implements IPluginsService {
327
340
328
341
private configurePluginCore ( pluginName : string , configuration ?: string , version ?: string ) : IFuture < void > {
329
342
return ( ( ) => {
330
- let plugin = this . getPluginByName ( pluginName ) ;
343
+ let plugin = this . getBestMatchingPlugin ( pluginName , version ) ;
331
344
let pluginData = < IMarketplacePluginData > plugin . data ;
332
345
let cordovaPluginVariables = this . $project . getProperty ( CordovaProjectPluginsService . CORDOVA_PLUGIN_VARIABLES_PROPERTY_NAME , configuration ) || { } ;
333
346
@@ -346,10 +359,7 @@ export class CordovaProjectPluginsService implements IPluginsService {
346
359
347
360
let newCorePlugins = this . $project . getProperty ( CordovaProjectPluginsService . CORE_PLUGINS_PROPERTY_NAME , configuration ) || [ ] ;
348
361
// remove all instances of the plugin from current configuration
349
- let lowerCasePluginIdentifier = plugin . data . Identifier . toLowerCase ( ) ;
350
- let installedPlugin = this . getInstalledPluginsForConfiguration ( configuration ) . filter ( ( pl : IPlugin ) => pl . data . Identifier . toLowerCase ( ) === lowerCasePluginIdentifier ) ;
351
-
352
- _ . each ( installedPlugin , pl => newCorePlugins = _ . without ( newCorePlugins , pl . toProjectDataRecord ( pl . data . Version ) ) ) ;
362
+ newCorePlugins = _ . without ( newCorePlugins , ...this . getPluginInstancesByName ( plugin . data . Identifier ) . map ( plug => plug . toProjectDataRecord ( ) ) ) ;
353
363
354
364
newCorePlugins . push ( plugin . toProjectDataRecord ( version ) ) ;
355
365
this . $project . setProperty ( CordovaProjectPluginsService . CORE_PLUGINS_PROPERTY_NAME , newCorePlugins , configuration ) ;
@@ -408,12 +418,11 @@ export class CordovaProjectPluginsService implements IPluginsService {
408
418
_ . each ( configurations , ( configData : IDictionary < any > , configuration :string ) => {
409
419
if ( configData ) {
410
420
let corePlugins = configData [ CordovaProjectPluginsService . CORE_PLUGINS_PROPERTY_NAME ] ;
411
- if ( corePlugins && _ . contains ( corePlugins , projectDataRecord ) ) {
421
+ if ( corePlugins && ( _ . contains ( corePlugins , projectDataRecord ) || _ . contains ( corePlugins , pluginData . data . Identifier ) ) ) {
412
422
pluginData . configurations . push ( configuration ) ;
413
423
}
414
424
}
415
425
} ) ;
416
-
417
426
this . _identifierToPlugin [ projectDataRecord ] = pluginData ;
418
427
} else {
419
428
this . $logger . warn ( "Unable to fetch data for plugin %s." , plugin . Identifier ) ;
@@ -445,11 +454,10 @@ export class CordovaProjectPluginsService implements IPluginsService {
445
454
} ) . future < any > ( ) ( ) ;
446
455
}
447
456
448
- private getPluginByName ( pluginName : string , version ?: string ) : IPlugin {
457
+ private getPluginInstancesByName ( pluginName : string , version ?: string ) : IPlugin [ ] {
449
458
let plugins = this . getAvailablePlugins ( ) ;
450
459
let toLowerCasePluginName = pluginName . toLowerCase ( ) ;
451
-
452
- let plugin = _ . find ( plugins , ( _plugin : IPlugin ) => {
460
+ let matchingPlugins = _ . filter ( plugins , ( _plugin : IPlugin ) => {
453
461
let condition = _plugin . data . Name . toLowerCase ( ) === toLowerCasePluginName || _plugin . data . Identifier . toLowerCase ( ) === toLowerCasePluginName ;
454
462
if ( version ) {
455
463
condition = condition && _plugin . data . Version === version ;
@@ -458,11 +466,11 @@ export class CordovaProjectPluginsService implements IPluginsService {
458
466
return condition ;
459
467
} ) ;
460
468
461
- if ( ! plugin ) {
469
+ if ( ! matchingPlugins || ! matchingPlugins . length ) {
462
470
this . $errors . fail ( "Invalid plugin name: %s" , pluginName ) ;
463
471
}
464
472
465
- return plugin ;
473
+ return matchingPlugins ;
466
474
}
467
475
468
476
private promptForVersion ( pluginName : string , versions : any [ ] ) : IFuture < string > {
@@ -505,10 +513,10 @@ export class CordovaProjectPluginsService implements IPluginsService {
505
513
pluginName = pluginName . toLowerCase ( ) ;
506
514
let isConsoleInteractive = helpers . isInteractive ( ) ;
507
515
let allInstalledPlugins = this . getInstalledPluginsForConfiguration ( ) ;
508
- let installedPluginInstances = _ . filter ( allInstalledPlugins , ( plugin : IPlugin ) => plugin . data . Name . toLowerCase ( ) === pluginName || plugin . data . Identifier . toLowerCase ( ) === pluginName ) ;
516
+ let installedPluginInstances = _ . filter ( allInstalledPlugins , ( plugin : IPlugin ) => plugin . data . Name . toLowerCase ( ) === pluginName || plugin . data . Identifier . toLowerCase ( ) === pluginName ) ;
509
517
let selectedVersion : string ;
510
518
if ( installedPluginInstances . length > 1 ) {
511
- this . $logger . warn ( `Plugin '${ pluginName } ' is enabled with different versions in your project configurations. You must use the same version in all configurations.' ` ) ;
519
+ this . $logger . warn ( `Plugin '${ pluginName } ' is enabled with different versions in your project configurations. You must use the same version in all configurations.` ) ;
512
520
}
513
521
514
522
_ . each ( installedPluginInstances , ( pl : IPlugin ) => {
0 commit comments