3838import io .sloeber .core .common .InstancePreferences ;
3939import io .sloeber .core .core .DefaultInstallHandler ;
4040import io .sloeber .core .internal .ArduinoHardwareLibrary ;
41- import io .sloeber .core .internal .ArduinoPrivateLibraryVersion ;
41+ import io .sloeber .core .internal .ArduinoPrivateHardwareLibraryVersion ;
4242import io .sloeber .core .internal .Example ;
4343import io .sloeber .core .tools .FileModifiers ;
4444import io .sloeber .core .tools .PackageManager ;
@@ -87,6 +87,10 @@ public static String getPrivateLibraryPathsString() {
8787 return InstancePreferences .getPrivateLibraryPathsString ();
8888 }
8989
90+ public static String [] getPrivateLibraryPaths () {
91+ return InstancePreferences .getPrivateLibraryPaths ();
92+ }
93+
9094 public static void setPrivateLibraryPaths (String [] libraryPaths ) {
9195 InstancePreferences .setPrivateLibraryPaths (libraryPaths );
9296
@@ -335,43 +339,59 @@ public static IStatus updateLibraries(Set<IArduinoLibraryVersion> toUnInstallLib
335339 return status ;
336340 }
337341
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+
338353 /**
339354 * Given a sloeber configuration provide all the libraries that can be used by
340355 * this sketch This boils down to all libraries maintained by the Library
341356 * manager plus all the libraries provided by the core plus all the libraries
342357 * provided by the personal libraries
343358 *
344359 * @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
346362 */
347- public static TreeMap <String , IArduinoLibraryVersion > getLibrariesAll (BoardDescription boardDescriptor ) {
363+ public static TreeMap <String , IArduinoLibraryVersion > getLibrariesAll (BoardDescription boardDescriptor , boolean keyIsFQN ) {
348364 TreeMap <String , IArduinoLibraryVersion > libraries = new TreeMap <>();
349- libraries .putAll (getLibrariesdManaged ());
350- libraries .putAll (getLibrariesPrivate ());
365+ libraries .putAll (getLibrariesdManaged (keyIsFQN ));
366+ libraries .putAll (getLibrariesPrivate (keyIsFQN ));
351367 if (boardDescriptor != null ) {
352- libraries .putAll (getLibrariesHarware (boardDescriptor ));
368+ libraries .putAll (getLibrariesHarware (boardDescriptor , keyIsFQN ));
353369 }
354370 return libraries ;
355371 }
356372
357- private static Map <String , IArduinoLibraryVersion > getLibrariesdManaged () {
373+ private static Map <String , IArduinoLibraryVersion > getLibrariesdManaged (boolean keyIsFQN ) {
358374 Map <String , IArduinoLibraryVersion > ret = new HashMap <>();
359375 for (IArduinoLibraryIndex libindex : libraryIndices ) {
360376 for (IArduinoLibrary curLib : libindex .getLibraries ()) {
361377 IArduinoLibraryVersion instVersion = curLib .getInstalledVersion ();
362378 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+ }
364384 }
365385 }
366386 }
367387 return ret ;
368388 }
369389
370- private static Map <String , IArduinoLibraryVersion > getLibrariesPrivate () {
390+ private static Map <String , IArduinoLibraryVersion > getLibrariesPrivate (boolean keyIsFQN ) {
371391 Map <String , IArduinoLibraryVersion > ret = new HashMap <>();
372392 String privateLibPaths [] = InstancePreferences .getPrivateLibraryPaths ();
373393 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 ));
375395 }
376396 return ret ;
377397
@@ -381,12 +401,13 @@ private static Map<String, IArduinoLibraryVersion> getLibrariesPrivate() {
381401 * for a given folder return all subfolders
382402 *
383403 * @param ipath the folder you want the subfolders off
404+ * @param keyIsFQN
384405 * @return The subfolders of the ipath folder. May contain empty values. This
385406 * method returns a key value pair of key equals foldername and value
386407 * equals full path.
387408 */
388409 private static Map <String , IArduinoLibraryVersion > getLibrariesFromFolder (IPath ipath , int depth ,
389- boolean isHardwareLib ,boolean isPrivate ) {
410+ boolean isHardwareLib ,boolean isPrivate , boolean keyIsFQN ) {
390411 if (ConfigurationPreferences .getInstallationPathLibraries ().isPrefixOf (ipath )) {
391412 System .err .println ("The method findAllPrivateLibs should not be called on Library manager installed libs" ); //$NON-NLS-1$
392413 }
@@ -405,13 +426,9 @@ private static Map<String, IArduinoLibraryVersion> getLibrariesFromFolder(IPath
405426 }
406427 String fileExt = (new Path (curChild )).getFileExtension ();
407428 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 );
415432
416433 return ret ;
417434 }
@@ -425,7 +442,7 @@ private static Map<String, IArduinoLibraryVersion> getLibrariesFromFolder(IPath
425442 IPath LibPath = ipath .append (curFolder );
426443 File LibPathFile = LibPath .toFile ();
427444 if (LibPathFile .isDirectory () && !LibPathFile .isHidden ()) {
428- ret .putAll (getLibrariesFromFolder (LibPath , depth - 1 , isHardwareLib ,isPrivate ));
445+ ret .putAll (getLibrariesFromFolder (LibPath , depth - 1 , isHardwareLib ,isPrivate , keyIsFQN ));
429446 }
430447 }
431448 return ret ;
@@ -435,21 +452,22 @@ private static Map<String, IArduinoLibraryVersion> getLibrariesFromFolder(IPath
435452 * Searches all the hardware dependent libraries of a project. If this is a
436453 * board referencing a core then the libraries of the referenced core are added
437454 * as well
455+ * @param keyIsFQN
438456 *
439457 * @param project the project to find all hardware libraries for
440458 * @return all the library folder names. May contain empty values.
441459 */
442- public static Map <String , IArduinoLibraryVersion > getLibrariesHarware (BoardDescription boardDescriptor ) {
460+ public static Map <String , IArduinoLibraryVersion > getLibrariesHarware (BoardDescription boardDescriptor , boolean keyIsFQN ) {
443461 Map <String , IArduinoLibraryVersion > ret = new HashMap <>();
444462 // first add the referenced
445463 IPath libPath = boardDescriptor .getReferencedCoreLibraryPath ();
446464 if (libPath != null ) {
447- ret .putAll (getLibrariesFromFolder (libPath , 1 , true ,boardDescriptor .isPrivate ()));
465+ ret .putAll (getLibrariesFromFolder (libPath , 1 , true ,boardDescriptor .isPrivate (), keyIsFQN ));
448466 }
449467 // then add the referencing
450468 libPath = boardDescriptor .getReferencingLibraryPath ();
451469 if (libPath != null ) {
452- ret .putAll (getLibrariesFromFolder (libPath , 1 , true ,boardDescriptor .isPrivate ()));
470+ ret .putAll (getLibrariesFromFolder (libPath , 1 , true ,boardDescriptor .isPrivate (), keyIsFQN ));
453471 }
454472 return ret ;
455473 }
@@ -458,17 +476,39 @@ public static IArduinoLibraryVersion getLibraryVersionFromLocation(IFolder libFo
458476 if (boardDescriptor != null ) {
459477 IPath libPath =boardDescriptor .getReferencedCoreLibraryPath ();
460478 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 ());
463480 }
464481 }
465482
466483 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 ());
469485 }
470486
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 ;
472512 }
473513
474514 /**
0 commit comments