@@ -339,43 +339,59 @@ public static IStatus updateLibraries(Set<IArduinoLibraryVersion> toUnInstallLib
339
339
return status ;
340
340
}
341
341
342
+ /**
343
+ * A convenience (and downward compatibility method of
344
+ * getLibrariesAll(BoardDescription boardDescriptor, true) {
345
+ *
346
+ * @param confDesc can be null
347
+ * @return A map of FQN IArduinoLibraryVersion
348
+ */
349
+ public static TreeMap <String , IArduinoLibraryVersion > getLibrariesAll (BoardDescription boardDescriptor ) {
350
+ return getLibrariesAll ( boardDescriptor , true );
351
+ }
352
+
342
353
/**
343
354
* Given a sloeber configuration provide all the libraries that can be used by
344
355
* this sketch This boils down to all libraries maintained by the Library
345
356
* manager plus all the libraries provided by the core plus all the libraries
346
357
* provided by the personal libraries
347
358
*
348
359
* @param confDesc can be null
349
- * @return
360
+ * @return if keyIsFQN is true: A map of FQN IArduinoLibraryVersion
361
+ * if keyIsFQN is false: A map of location IArduinoLibraryVersion
350
362
*/
351
- public static TreeMap <String , IArduinoLibraryVersion > getLibrariesAll (BoardDescription boardDescriptor ) {
363
+ public static TreeMap <String , IArduinoLibraryVersion > getLibrariesAll (BoardDescription boardDescriptor , boolean keyIsFQN ) {
352
364
TreeMap <String , IArduinoLibraryVersion > libraries = new TreeMap <>();
353
- libraries .putAll (getLibrariesdManaged ());
354
- libraries .putAll (getLibrariesPrivate ());
365
+ libraries .putAll (getLibrariesdManaged (keyIsFQN ));
366
+ libraries .putAll (getLibrariesPrivate (keyIsFQN ));
355
367
if (boardDescriptor != null ) {
356
- libraries .putAll (getLibrariesHarware (boardDescriptor ));
368
+ libraries .putAll (getLibrariesHarware (boardDescriptor , keyIsFQN ));
357
369
}
358
370
return libraries ;
359
371
}
360
372
361
- private static Map <String , IArduinoLibraryVersion > getLibrariesdManaged () {
373
+ private static Map <String , IArduinoLibraryVersion > getLibrariesdManaged (boolean keyIsFQN ) {
362
374
Map <String , IArduinoLibraryVersion > ret = new HashMap <>();
363
375
for (IArduinoLibraryIndex libindex : libraryIndices ) {
364
376
for (IArduinoLibrary curLib : libindex .getLibraries ()) {
365
377
IArduinoLibraryVersion instVersion = curLib .getInstalledVersion ();
366
378
if (instVersion != null ) {
367
- ret .put (instVersion .getFQN ().toPortableString (), instVersion );
379
+ if (keyIsFQN ) {
380
+ ret .put (instVersion .getFQN ().toPortableString (), instVersion );
381
+ } else {
382
+ ret .put (instVersion .getInstallPath ().toPortableString (), instVersion );
383
+ }
368
384
}
369
385
}
370
386
}
371
387
return ret ;
372
388
}
373
389
374
- private static Map <String , IArduinoLibraryVersion > getLibrariesPrivate () {
390
+ private static Map <String , IArduinoLibraryVersion > getLibrariesPrivate (boolean keyIsFQN ) {
375
391
Map <String , IArduinoLibraryVersion > ret = new HashMap <>();
376
392
String privateLibPaths [] = InstancePreferences .getPrivateLibraryPaths ();
377
393
for (String curLibPath : privateLibPaths ) {
378
- ret .putAll (getLibrariesFromFolder (new Path (curLibPath ), 2 , false ,true ));
394
+ ret .putAll (getLibrariesFromFolder (new Path (curLibPath ), 2 , false ,true , keyIsFQN ));
379
395
}
380
396
return ret ;
381
397
@@ -385,12 +401,13 @@ private static Map<String, IArduinoLibraryVersion> getLibrariesPrivate() {
385
401
* for a given folder return all subfolders
386
402
*
387
403
* @param ipath the folder you want the subfolders off
404
+ * @param keyIsFQN
388
405
* @return The subfolders of the ipath folder. May contain empty values. This
389
406
* method returns a key value pair of key equals foldername and value
390
407
* equals full path.
391
408
*/
392
409
private static Map <String , IArduinoLibraryVersion > getLibrariesFromFolder (IPath ipath , int depth ,
393
- boolean isHardwareLib ,boolean isPrivate ) {
410
+ boolean isHardwareLib ,boolean isPrivate , boolean keyIsFQN ) {
394
411
if (ConfigurationPreferences .getInstallationPathLibraries ().isPrefixOf (ipath )) {
395
412
System .err .println ("The method findAllPrivateLibs should not be called on Library manager installed libs" ); //$NON-NLS-1$
396
413
}
@@ -409,13 +426,9 @@ private static Map<String, IArduinoLibraryVersion> getLibrariesFromFolder(IPath
409
426
}
410
427
String fileExt = (new Path (curChild )).getFileExtension ();
411
428
if (LIBRARY_INDICATION_FILES .contains (curChild ) || CODE_EXTENSIONS .contains (fileExt )) {
412
- if (isHardwareLib ) {
413
- IArduinoLibraryVersion retVersion = new ArduinoHardwareLibrary (ipath );
414
- ret .put (retVersion .getFQN ().toPortableString (), retVersion );
415
- } else {
416
- IArduinoLibraryVersion retVersion = new ArduinoPrivateHardwareLibraryVersion (ipath );
417
- ret .put (retVersion .getFQN ().toPortableString (), retVersion );
418
- }
429
+ IArduinoLibraryVersion retVersion = isHardwareLib ?new ArduinoHardwareLibrary (ipath ):new ArduinoPrivateHardwareLibraryVersion (ipath );
430
+ String key =keyIsFQN ?retVersion .getFQN ().toPortableString ():retVersion .getInstallPath ().toPortableString ();
431
+ ret .put (key , retVersion );
419
432
420
433
return ret ;
421
434
}
@@ -429,7 +442,7 @@ private static Map<String, IArduinoLibraryVersion> getLibrariesFromFolder(IPath
429
442
IPath LibPath = ipath .append (curFolder );
430
443
File LibPathFile = LibPath .toFile ();
431
444
if (LibPathFile .isDirectory () && !LibPathFile .isHidden ()) {
432
- ret .putAll (getLibrariesFromFolder (LibPath , depth - 1 , isHardwareLib ,isPrivate ));
445
+ ret .putAll (getLibrariesFromFolder (LibPath , depth - 1 , isHardwareLib ,isPrivate , keyIsFQN ));
433
446
}
434
447
}
435
448
return ret ;
@@ -439,21 +452,22 @@ private static Map<String, IArduinoLibraryVersion> getLibrariesFromFolder(IPath
439
452
* Searches all the hardware dependent libraries of a project. If this is a
440
453
* board referencing a core then the libraries of the referenced core are added
441
454
* as well
455
+ * @param keyIsFQN
442
456
*
443
457
* @param project the project to find all hardware libraries for
444
458
* @return all the library folder names. May contain empty values.
445
459
*/
446
- public static Map <String , IArduinoLibraryVersion > getLibrariesHarware (BoardDescription boardDescriptor ) {
460
+ public static Map <String , IArduinoLibraryVersion > getLibrariesHarware (BoardDescription boardDescriptor , boolean keyIsFQN ) {
447
461
Map <String , IArduinoLibraryVersion > ret = new HashMap <>();
448
462
// first add the referenced
449
463
IPath libPath = boardDescriptor .getReferencedCoreLibraryPath ();
450
464
if (libPath != null ) {
451
- ret .putAll (getLibrariesFromFolder (libPath , 1 , true ,boardDescriptor .isPrivate ()));
465
+ ret .putAll (getLibrariesFromFolder (libPath , 1 , true ,boardDescriptor .isPrivate (), keyIsFQN ));
452
466
}
453
467
// then add the referencing
454
468
libPath = boardDescriptor .getReferencingLibraryPath ();
455
469
if (libPath != null ) {
456
- ret .putAll (getLibrariesFromFolder (libPath , 1 , true ,boardDescriptor .isPrivate ()));
470
+ ret .putAll (getLibrariesFromFolder (libPath , 1 , true ,boardDescriptor .isPrivate (), keyIsFQN ));
457
471
}
458
472
return ret ;
459
473
}
@@ -462,17 +476,15 @@ public static IArduinoLibraryVersion getLibraryVersionFromLocation(IFolder libFo
462
476
if (boardDescriptor != null ) {
463
477
IPath libPath =boardDescriptor .getReferencedCoreLibraryPath ();
464
478
if (libPath !=null && libPath .isPrefixOf (libFolder .getLocation ())) {
465
- String FQNLibName =ArduinoHardwareLibrary .calculateFQN (libFolder .getName ()).toString ();
466
- return getLibrariesHarware (boardDescriptor ).get (FQNLibName );
479
+ return getLibrariesHarware (boardDescriptor ,false ).get (libFolder .getLocation ().toPortableString ());
467
480
}
468
481
}
469
482
470
483
if (ConfigurationPreferences .getInstallationPathLibraries ().isPrefixOf (libFolder .getLocation ())) {
471
- String FQNLibName = ArduinoLibraryVersion .calculateFQN (libFolder .getName ()).toString ();
472
- return getLibrariesdManaged ().get (FQNLibName );
484
+ return getLibrariesdManaged (false ).get (libFolder .getLocation ().toPortableString ());
473
485
}
474
486
475
- return getLibrariesPrivate ().get (libFolder .getName ());
487
+ return getLibrariesPrivate (false ).get (libFolder .getLocation (). toPortableString ());
476
488
}
477
489
478
490
public static IArduinoLibraryVersion getLibraryVersionFromFQN (String FQNLibName , BoardDescription boardDescriptor ) {
@@ -489,12 +501,12 @@ public static IArduinoLibraryVersion getLibraryVersionFromFQN(String FQNLibName,
489
501
if (boardDescriptor == null ) {
490
502
return null ;
491
503
}
492
- return getLibrariesHarware (boardDescriptor ).get (FQNLibName );
504
+ return getLibrariesHarware (boardDescriptor , true ).get (FQNLibName );
493
505
}
494
- return getLibrariesdManaged ().get (FQNLibName );
506
+ return getLibrariesdManaged (true ).get (FQNLibName );
495
507
}
496
508
if (PRIVATE .equals (fqnParts [1 ])) {
497
- return getLibrariesPrivate ().get (FQNLibName );
509
+ return getLibrariesPrivate (true ).get (FQNLibName );
498
510
}
499
511
return null ;
500
512
}
0 commit comments