@@ -52,6 +52,7 @@ public class SloeberConfiguration extends AutoBuildConfigurationExtensionDescrip
52
52
private BoardDescription myBoardDescription ;
53
53
private OtherDescription myOtherDesc ;
54
54
private CompileDescription myCompileDescription ;
55
+ //a map of foldername library
55
56
private Map <String , IArduinoLibraryVersion > myLibraries = new HashMap <>();
56
57
57
58
// operational data
@@ -92,7 +93,7 @@ public SloeberConfiguration(AutoBuildConfigurationDescription owner,
92
93
setBoardDescription (src .getBoardDescription ());
93
94
setOtherDescription (src .getOtherDescription ());
94
95
setCompileDescription (src .getCompileDescription ());
95
- myLibraries = src .myLibraries ;
96
+ myLibraries = src .getLibrariesFromLinks () ;
96
97
}
97
98
98
99
public SloeberConfiguration (BoardDescription boardDesc , OtherDescription otherDesc ,
@@ -518,27 +519,32 @@ public Set<IFolder> getIncludeFolders() {
518
519
* @return
519
520
* @throws CoreException
520
521
*/
521
- private Map <String ,IArduinoLibraryVersion > getLibrariesFromLinks () throws CoreException {
522
+ private Map <String ,IArduinoLibraryVersion > getLibrariesFromLinks () {
522
523
Map <String , IArduinoLibraryVersion > ret = new HashMap <>();
523
524
IFolder libFolder = getArduinoLibraryFolder ();
524
525
if (!libFolder .exists ()) {
525
526
return ret ;
526
527
}
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
+ }
536
538
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
+ }
540
543
}
541
544
}
545
+ } catch (CoreException e ) {
546
+ e .printStackTrace ();
547
+ ret .putAll (myLibraries );
542
548
}
543
549
return ret ;
544
550
}
@@ -572,15 +578,58 @@ private void linkLibrariesToFolder() {
572
578
IFolder libFolder = getArduinoLibraryFolder ();
573
579
for (IArduinoLibraryVersion curLib : myLibraries .values ()) {
574
580
IFolder curLibFolder =libFolder .getFolder (curLib .getName ());
575
- Helpers .linkDirectory (curLib .getInstallPath (), curLibFolder );
581
+ Helpers .LinkFolderToFolder (curLib .getInstallPath (), curLibFolder );
576
582
}
577
583
}
578
584
579
585
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
+
580
626
581
627
582
628
@ Override
583
629
public void reAttachLibraries () {
630
+ upDateHardwareLibraries ();
631
+
632
+
584
633
IProgressMonitor monitor = new NullProgressMonitor ();
585
634
IFolder libFolder = getArduinoLibraryFolder ();
586
635
// Remove all existing lib folders that are not known or are linking to the
@@ -617,11 +666,7 @@ public void reAttachLibraries() {
617
666
618
667
@ Override
619
668
public Map <String , IArduinoLibraryVersion > getUsedLibraries () {
620
- try {
621
- myLibraries =getLibrariesFromLinks ();
622
- } catch (CoreException e ) {
623
- e .printStackTrace ();
624
- }
669
+ myLibraries =getLibrariesFromLinks ();
625
670
return new HashMap <>(myLibraries );
626
671
}
627
672
@@ -716,22 +761,23 @@ public LinkedHashMap<String, String> getPostbuildSteps() {
716
761
717
762
/**
718
763
* 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
720
766
* at the time the SloeberConfiguration is changed
721
767
*
722
768
* 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.
724
770
* This apply is when this configuration is new.
725
771
*/
726
772
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
+ // }
733
779
if (updateSourceEntries ()) {
734
- //the config hasbeen renamed;
780
+ //the config has been renamed;
735
781
// remove the library links
736
782
removeLibraryLinks ();
737
783
}
@@ -741,6 +787,7 @@ public void aboutToApplyConfigChange() {
741
787
742
788
public void appliedConfigChange () {
743
789
LinkToCore ();
790
+ upDateHardwareLibraries ();
744
791
linkLibrariesToFolder ();
745
792
}
746
793
0 commit comments