@@ -52,6 +52,7 @@ public class SloeberConfiguration extends AutoBuildConfigurationExtensionDescrip
5252 private BoardDescription myBoardDescription ;
5353 private OtherDescription myOtherDesc ;
5454 private CompileDescription myCompileDescription ;
55+ //a map of foldername library
5556 private Map <String , IArduinoLibraryVersion > myLibraries = new HashMap <>();
5657
5758 // operational data
@@ -92,7 +93,7 @@ public SloeberConfiguration(AutoBuildConfigurationDescription owner,
9293 setBoardDescription (src .getBoardDescription ());
9394 setOtherDescription (src .getOtherDescription ());
9495 setCompileDescription (src .getCompileDescription ());
95- myLibraries = src .myLibraries ;
96+ myLibraries = src .getLibrariesFromLinks () ;
9697 }
9798
9899 public SloeberConfiguration (BoardDescription boardDesc , OtherDescription otherDesc ,
@@ -518,27 +519,32 @@ public Set<IFolder> getIncludeFolders() {
518519 * @return
519520 * @throws CoreException
520521 */
521- private Map <String ,IArduinoLibraryVersion > getLibrariesFromLinks () throws CoreException {
522+ private Map <String ,IArduinoLibraryVersion > getLibrariesFromLinks () {
522523 Map <String , IArduinoLibraryVersion > ret = new HashMap <>();
523524 IFolder libFolder = getArduinoLibraryFolder ();
524525 if (!libFolder .exists ()) {
525526 return ret ;
526527 }
527- for (IResource curResource : libFolder .members ()) {
528- if (curResource instanceof IFolder ) {
529- IFolder curFolder = (IFolder ) curResource ;
530- IArduinoLibraryVersion curLib = myLibraries .get (curFolder .getName ());
531- if (curLib != null ){
532- //We knbow the lib so it is ok
533- ret .put (curLib .getName (),curLib );
534- continue ;
535- }
528+ try {
529+ for (IResource curResource : libFolder .members ()) {
530+ if (curResource instanceof IFolder ) {
531+ IFolder curFolder = (IFolder ) curResource ;
532+ IArduinoLibraryVersion curLib = myLibraries .get (curFolder .getName ());
533+ if (curLib != null ){
534+ //We knbow the lib so it is ok
535+ ret .put (curLib .getName (),curLib );
536+ continue ;
537+ }
536538
537- curLib =LibraryManager .getLibraryVersionFromLocation (curFolder ,getBoardDescription ());
538- if (curLib != null ){
539- ret .put (curLib .getName (),curLib );
539+ curLib =LibraryManager .getLibraryVersionFromLocation (curFolder ,getBoardDescription ());
540+ if (curLib != null ){
541+ ret .put (curLib .getName (),curLib );
542+ }
540543 }
541544 }
545+ } catch (CoreException e ) {
546+ e .printStackTrace ();
547+ ret .putAll (myLibraries );
542548 }
543549 return ret ;
544550 }
@@ -572,15 +578,58 @@ private void linkLibrariesToFolder() {
572578 IFolder libFolder = getArduinoLibraryFolder ();
573579 for (IArduinoLibraryVersion curLib : myLibraries .values ()) {
574580 IFolder curLibFolder =libFolder .getFolder (curLib .getName ());
575- Helpers .linkDirectory (curLib .getInstallPath (), curLibFolder );
581+ Helpers .LinkFolderToFolder (curLib .getInstallPath (), curLibFolder );
576582 }
577583 }
578584
579585
586+ /**
587+ * For libraries of with FQN Libraries/hardware/X make sure that the location
588+ * point to a valid location of the given boardDescriptor
589+ */
590+ private void upDateHardwareLibraries () {
591+ //make sure the libraries that link to hardware are the correct ones
592+ BoardDescription boardDesc =getBoardDescription ();
593+ IPath referenceLibPath =boardDesc .getReferencedCoreLibraryPath ();
594+ IPath referencingLibPath =boardDesc .getReferencingLibraryPath ();
595+ if (referencingLibPath ==null ) {
596+ referencingLibPath =referenceLibPath ;
597+ }
598+ Set <String > hardwareLibsFQN =new HashSet <>();
599+ for (IArduinoLibraryVersion curLib :myLibraries .values ()) {
600+ if (curLib .isHardwareLib ()) {
601+ IPath libPath =curLib .getInstallPath ();
602+ if (referencingLibPath .isPrefixOf (libPath )||referenceLibPath .isPrefixOf (libPath )) {
603+ //the hardware lib is ok
604+ continue ;
605+ }
606+ // The hardware lib is for a different hardware.
607+ //add it to the lists to reattach
608+ hardwareLibsFQN .add (curLib .getFQN ().toPortableString ());
609+ }
610+ }
611+ if (!hardwareLibsFQN .isEmpty ()) {
612+ Map <String , IArduinoLibraryVersion > boardLibs =LibraryManager .getLibrariesHarware (boardDesc );
613+ for (String curReplaceLibFQN : hardwareLibsFQN ) {
614+ IArduinoLibraryVersion newLib =boardLibs .get (curReplaceLibFQN );
615+ if (newLib !=null ) {
616+ // a library with the same name was found so use this one
617+ myLibraries .put (newLib .getName (), newLib );
618+ }else {
619+ //no new library was found remove the old lib
620+ myLibraries .remove (Path .fromPortableString (curReplaceLibFQN ).lastSegment ());
621+ }
622+ }
623+ }
624+ }
625+
580626
581627
582628 @ Override
583629 public void reAttachLibraries () {
630+ upDateHardwareLibraries ();
631+
632+
584633 IProgressMonitor monitor = new NullProgressMonitor ();
585634 IFolder libFolder = getArduinoLibraryFolder ();
586635 // Remove all existing lib folders that are not known or are linking to the
@@ -617,11 +666,7 @@ public void reAttachLibraries() {
617666
618667 @ Override
619668 public Map <String , IArduinoLibraryVersion > getUsedLibraries () {
620- try {
621- myLibraries =getLibrariesFromLinks ();
622- } catch (CoreException e ) {
623- e .printStackTrace ();
624- }
669+ myLibraries =getLibrariesFromLinks ();
625670 return new HashMap <>(myLibraries );
626671 }
627672
@@ -716,22 +761,23 @@ public LinkedHashMap<String, String> getPostbuildSteps() {
716761
717762 /**
718763 * Because SloeberConfiguration are copied and can be changed at all times
719- * but there is only 1 disk representation we can not update the disk
764+ * but there is only 1 disk representation of each config
765+ * we can not update the disk
720766 * at the time the SloeberConfiguration is changed
721767 *
722768 * When a configuration becomes "the active" configuration this method will
723- * create the necessary resources on disk.
769+ * create/update the necessary resources on disk.
724770 * This apply is when this configuration is new.
725771 */
726772 public void aboutToApplyConfigChange () {
727- try {
728- myLibraries =getLibrariesFromLinks ();
729- } catch (CoreException e ) {
730- // TODO Auto-generated catch block
731- e .printStackTrace ();
732- }
773+ // try {
774+ // myLibraries =getLibrariesFromLinks();
775+ // } catch (CoreException e) {
776+ // // TODO Auto-generated catch block
777+ // e.printStackTrace();
778+ // }
733779 if (updateSourceEntries ()) {
734- //the config hasbeen renamed;
780+ //the config has been renamed;
735781 // remove the library links
736782 removeLibraryLinks ();
737783 }
@@ -741,6 +787,7 @@ public void aboutToApplyConfigChange() {
741787
742788 public void appliedConfigChange () {
743789 LinkToCore ();
790+ upDateHardwareLibraries ();
744791 linkLibrariesToFolder ();
745792 }
746793
0 commit comments