Skip to content

Commit f0788b1

Browse files
author
jan
committed
Fix for #1723
1 parent ea28dd8 commit f0788b1

File tree

2 files changed

+42
-30
lines changed

2 files changed

+42
-30
lines changed

io.sloeber.core/src/io/sloeber/arduinoFramework/api/LibraryManager.java

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -339,43 +339,59 @@ public static IStatus updateLibraries(Set<IArduinoLibraryVersion> toUnInstallLib
339339
return status;
340340
}
341341

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+
342353
/**
343354
* Given a sloeber configuration provide all the libraries that can be used by
344355
* this sketch This boils down to all libraries maintained by the Library
345356
* manager plus all the libraries provided by the core plus all the libraries
346357
* provided by the personal libraries
347358
*
348359
* @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
350362
*/
351-
public static TreeMap<String, IArduinoLibraryVersion> getLibrariesAll(BoardDescription boardDescriptor) {
363+
public static TreeMap<String, IArduinoLibraryVersion> getLibrariesAll(BoardDescription boardDescriptor, boolean keyIsFQN) {
352364
TreeMap<String, IArduinoLibraryVersion> libraries = new TreeMap<>();
353-
libraries.putAll(getLibrariesdManaged());
354-
libraries.putAll(getLibrariesPrivate());
365+
libraries.putAll(getLibrariesdManaged(keyIsFQN));
366+
libraries.putAll(getLibrariesPrivate(keyIsFQN));
355367
if (boardDescriptor != null) {
356-
libraries.putAll(getLibrariesHarware(boardDescriptor));
368+
libraries.putAll(getLibrariesHarware(boardDescriptor,keyIsFQN));
357369
}
358370
return libraries;
359371
}
360372

361-
private static Map<String, IArduinoLibraryVersion> getLibrariesdManaged() {
373+
private static Map<String, IArduinoLibraryVersion> getLibrariesdManaged(boolean keyIsFQN) {
362374
Map<String, IArduinoLibraryVersion> ret = new HashMap<>();
363375
for (IArduinoLibraryIndex libindex : libraryIndices) {
364376
for (IArduinoLibrary curLib : libindex.getLibraries()) {
365377
IArduinoLibraryVersion instVersion = curLib.getInstalledVersion();
366378
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+
}
368384
}
369385
}
370386
}
371387
return ret;
372388
}
373389

374-
private static Map<String, IArduinoLibraryVersion> getLibrariesPrivate() {
390+
private static Map<String, IArduinoLibraryVersion> getLibrariesPrivate(boolean keyIsFQN) {
375391
Map<String, IArduinoLibraryVersion> ret = new HashMap<>();
376392
String privateLibPaths[] = InstancePreferences.getPrivateLibraryPaths();
377393
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));
379395
}
380396
return ret;
381397

@@ -385,12 +401,13 @@ private static Map<String, IArduinoLibraryVersion> getLibrariesPrivate() {
385401
* for a given folder return all subfolders
386402
*
387403
* @param ipath the folder you want the subfolders off
404+
* @param keyIsFQN
388405
* @return The subfolders of the ipath folder. May contain empty values. This
389406
* method returns a key value pair of key equals foldername and value
390407
* equals full path.
391408
*/
392409
private static Map<String, IArduinoLibraryVersion> getLibrariesFromFolder(IPath ipath, int depth,
393-
boolean isHardwareLib,boolean isPrivate) {
410+
boolean isHardwareLib,boolean isPrivate, boolean keyIsFQN) {
394411
if (ConfigurationPreferences.getInstallationPathLibraries().isPrefixOf(ipath)) {
395412
System.err.println("The method findAllPrivateLibs should not be called on Library manager installed libs"); //$NON-NLS-1$
396413
}
@@ -409,13 +426,9 @@ private static Map<String, IArduinoLibraryVersion> getLibrariesFromFolder(IPath
409426
}
410427
String fileExt = (new Path(curChild)).getFileExtension();
411428
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);
419432

420433
return ret;
421434
}
@@ -429,7 +442,7 @@ private static Map<String, IArduinoLibraryVersion> getLibrariesFromFolder(IPath
429442
IPath LibPath = ipath.append(curFolder);
430443
File LibPathFile = LibPath.toFile();
431444
if (LibPathFile.isDirectory() && !LibPathFile.isHidden()) {
432-
ret.putAll(getLibrariesFromFolder(LibPath, depth - 1, isHardwareLib,isPrivate));
445+
ret.putAll(getLibrariesFromFolder(LibPath, depth - 1, isHardwareLib,isPrivate,keyIsFQN));
433446
}
434447
}
435448
return ret;
@@ -439,21 +452,22 @@ private static Map<String, IArduinoLibraryVersion> getLibrariesFromFolder(IPath
439452
* Searches all the hardware dependent libraries of a project. If this is a
440453
* board referencing a core then the libraries of the referenced core are added
441454
* as well
455+
* @param keyIsFQN
442456
*
443457
* @param project the project to find all hardware libraries for
444458
* @return all the library folder names. May contain empty values.
445459
*/
446-
public static Map<String, IArduinoLibraryVersion> getLibrariesHarware(BoardDescription boardDescriptor) {
460+
public static Map<String, IArduinoLibraryVersion> getLibrariesHarware(BoardDescription boardDescriptor, boolean keyIsFQN) {
447461
Map<String, IArduinoLibraryVersion> ret = new HashMap<>();
448462
// first add the referenced
449463
IPath libPath = boardDescriptor.getReferencedCoreLibraryPath();
450464
if (libPath != null) {
451-
ret.putAll(getLibrariesFromFolder(libPath, 1, true,boardDescriptor.isPrivate()));
465+
ret.putAll(getLibrariesFromFolder(libPath, 1, true,boardDescriptor.isPrivate(),keyIsFQN));
452466
}
453467
// then add the referencing
454468
libPath = boardDescriptor.getReferencingLibraryPath();
455469
if (libPath != null) {
456-
ret.putAll(getLibrariesFromFolder(libPath, 1, true,boardDescriptor.isPrivate()));
470+
ret.putAll(getLibrariesFromFolder(libPath, 1, true,boardDescriptor.isPrivate(),keyIsFQN));
457471
}
458472
return ret;
459473
}
@@ -462,17 +476,15 @@ public static IArduinoLibraryVersion getLibraryVersionFromLocation(IFolder libFo
462476
if (boardDescriptor != null) {
463477
IPath libPath=boardDescriptor.getReferencedCoreLibraryPath();
464478
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());
467480
}
468481
}
469482

470483
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());
473485
}
474486

475-
return getLibrariesPrivate().get(libFolder.getName());
487+
return getLibrariesPrivate(false).get(libFolder.getLocation().toPortableString());
476488
}
477489

478490
public static IArduinoLibraryVersion getLibraryVersionFromFQN(String FQNLibName, BoardDescription boardDescriptor) {
@@ -489,12 +501,12 @@ public static IArduinoLibraryVersion getLibraryVersionFromFQN(String FQNLibName,
489501
if (boardDescriptor == null) {
490502
return null;
491503
}
492-
return getLibrariesHarware(boardDescriptor).get(FQNLibName);
504+
return getLibrariesHarware(boardDescriptor,true).get(FQNLibName);
493505
}
494-
return getLibrariesdManaged().get(FQNLibName);
506+
return getLibrariesdManaged(true).get(FQNLibName);
495507
}
496508
if (PRIVATE.equals(fqnParts[1])) {
497-
return getLibrariesPrivate().get(FQNLibName);
509+
return getLibrariesPrivate(true).get(FQNLibName);
498510
}
499511
return null;
500512
}

io.sloeber.core/src/io/sloeber/core/internal/SloeberConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ private void upDateHardwareLibraries() {
611611
}
612612
}
613613
if (!hardwareLibsFQN.isEmpty()) {
614-
Map<String, IArduinoLibraryVersion> boardLibs = LibraryManager.getLibrariesHarware(boardDesc);
614+
Map<String, IArduinoLibraryVersion> boardLibs = LibraryManager.getLibrariesHarware(boardDesc,true);
615615
for (IPath curReplaceLibFQN : hardwareLibsFQN) {
616616
IArduinoLibraryVersion newLib = boardLibs.get(curReplaceLibFQN.toPortableString());
617617
if (newLib != null) {

0 commit comments

Comments
 (0)