42
42
import io .sloeber .core .api .ConfigurationPreferences ;
43
43
import io .sloeber .core .api .IArduinoLibraryVersion ;
44
44
import io .sloeber .core .api .ISloeberConfiguration ;
45
+ import io .sloeber .core .api .LibraryManager ;
45
46
import io .sloeber .core .api .OtherDescription ;
46
47
import io .sloeber .core .tools .Helpers ;
47
48
import io .sloeber .core .tools .uploaders .UploadSketchWrapper ;
@@ -495,6 +496,70 @@ public Set<IFolder> getIncludeFolders() {
495
496
return ret ;
496
497
}
497
498
499
+ /**
500
+ * Get all the libraries that are linked to on disk
501
+ *
502
+ * @return
503
+ * @throws CoreException
504
+ */
505
+ private Map <String ,IArduinoLibraryVersion > getLibrariesFromLinks () throws CoreException {
506
+ Map <String , IArduinoLibraryVersion > ret = new HashMap <>();
507
+ IFolder libFolder = getArduinoLibraryFolder ();
508
+ for (IResource curResource : libFolder .members ()) {
509
+ if (curResource instanceof IFolder ) {
510
+ IFolder curFolder = (IFolder ) curResource ;
511
+ IArduinoLibraryVersion curLib = myLibraries .get (curFolder .getName ());
512
+ if (curLib != null ){
513
+ //We knbow the lib so it is ok
514
+ ret .put (curLib .getName (),curLib );
515
+ continue ;
516
+ }
517
+
518
+ curLib =LibraryManager .getLibraryVersionFromLocation (curFolder ,getBoardDescription ());
519
+ if (curLib != null ){
520
+ ret .put (curLib .getName (),curLib );
521
+ }
522
+ }
523
+ }
524
+ return ret ;
525
+ }
526
+
527
+
528
+ /**
529
+ * remove the links from the libraries on disk
530
+ *
531
+ */
532
+ private void removeLibraryLinks () {
533
+ IProgressMonitor monitor = new NullProgressMonitor ();
534
+ IFolder libFolder = getArduinoLibraryFolder ();
535
+ for (String curLib : myLibraries .keySet ()) {
536
+ IFolder curLibFolder =libFolder .getFolder (curLib );
537
+ if (curLibFolder .exists ()) {
538
+ try {
539
+ curLibFolder .delete (true , monitor );
540
+ } catch (CoreException e ) {
541
+ // TODO Auto-generated catch block
542
+ e .printStackTrace ();
543
+ }
544
+ }
545
+ }
546
+ }
547
+
548
+ /**
549
+ * remove the links from the libraries on disk
550
+ *
551
+ */
552
+ private void linkLibrariesToFolder () {
553
+ IFolder libFolder = getArduinoLibraryFolder ();
554
+ for (IArduinoLibraryVersion curLib : myLibraries .values ()) {
555
+ IFolder curLibFolder =libFolder .getFolder (curLib .getName ());
556
+ Helpers .linkDirectory (curLib .getInstallPath (), curLibFolder );
557
+ }
558
+ }
559
+
560
+
561
+
562
+
498
563
@ Override
499
564
public void reAttachLibraries () {
500
565
IProgressMonitor monitor = new NullProgressMonitor ();
@@ -632,20 +697,33 @@ public LinkedHashMap<String, String> getPostbuildSteps() {
632
697
* This apply is when this configuration is new.
633
698
*/
634
699
public void aboutToApplyConfigChange () {
635
- updateSourceEntries ();
700
+ try {
701
+ myLibraries =getLibrariesFromLinks ();
702
+ } catch (CoreException e ) {
703
+ // TODO Auto-generated catch block
704
+ e .printStackTrace ();
705
+ }
706
+ if (updateSourceEntries ()) {
707
+ //the config hasbeen renamed;
708
+ // remove the library links
709
+ removeLibraryLinks ();
710
+ }
636
711
configureWhenDirty () ;
637
712
638
713
}
639
714
640
715
public void appliedConfigChange () {
641
716
LinkToCore ();
717
+ linkLibrariesToFolder ();
642
718
}
643
719
644
720
/**
645
721
* Look at the source entries to see whether this is a rename
646
722
* If it is a rename update the source entries and update the arduino/[configName]
723
+ *
724
+ * return true if the config has been renamed otherwise false
647
725
*/
648
- private void updateSourceEntries () {
726
+ private boolean updateSourceEntries () {
649
727
650
728
IFolder curArduinoConfigurationfolder =getArduinoConfigurationFolder ();
651
729
IFolder oldArduinoConfigurationfolder =null ;
@@ -667,30 +745,31 @@ private void updateSourceEntries() {
667
745
newSourceEntries [curItem ]=orgSourceEntries [curItem ];
668
746
}
669
747
}
670
- if (oldArduinoConfigurationfolder !=null ) {
671
- try {
672
- if (oldArduinoConfigurationfolder .exists ()) {
673
- NullProgressMonitor monitor = new NullProgressMonitor ();
674
- IFolder deleteFolder =oldArduinoConfigurationfolder .getFolder (SLOEBER_VARIANT_FOLDER_NAME );
675
- if (deleteFolder .exists ()) {
676
- deleteFolder .delete (true , monitor );
677
- }
678
- deleteFolder =oldArduinoConfigurationfolder .getFolder (SLOEBER_CODE_FOLDER_NAME );
679
- if (deleteFolder .exists ()) {
680
- deleteFolder .delete (true , monitor );
681
- }
682
- if (oldArduinoConfigurationfolder .exists ()) {
683
- oldArduinoConfigurationfolder .delete (true , monitor );
684
- }
748
+ if (oldArduinoConfigurationfolder == null ) {
749
+ return false ;
750
+ }
751
+ try {
752
+ if (oldArduinoConfigurationfolder .exists ()) {
753
+ NullProgressMonitor monitor = new NullProgressMonitor ();
754
+ IFolder deleteFolder = oldArduinoConfigurationfolder .getFolder (SLOEBER_VARIANT_FOLDER_NAME );
755
+ if (deleteFolder .exists ()) {
756
+ deleteFolder .delete (true , monitor );
757
+ }
758
+ deleteFolder = oldArduinoConfigurationfolder .getFolder (SLOEBER_CODE_FOLDER_NAME );
759
+ if (deleteFolder .exists ()) {
760
+ deleteFolder .delete (true , monitor );
761
+ }
762
+ if (oldArduinoConfigurationfolder .exists ()) {
763
+ oldArduinoConfigurationfolder .delete (true , monitor );
685
764
}
686
- getAutoBuildDesc ().getCdtConfigurationDescription ().setSourceEntries (newSourceEntries );
687
-
688
- } catch (Exception e ) {
689
- Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID ,"Failed to modify configuration for rename" ,e ));
690
765
}
691
- }
766
+ getAutoBuildDesc (). getCdtConfigurationDescription (). setSourceEntries ( newSourceEntries );
692
767
693
- }
768
+ } catch (Exception e ) {
769
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID , "Failed to modify configuration for rename" , e ));
770
+ }
771
+ return true ;
772
+ }
694
773
695
774
private String getCDTConfName () {
696
775
return getAutoBuildDescription ().getCdtConfigurationDescription ().getName ();
0 commit comments