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