Skip to content

Commit 7f83949

Browse files
author
jan
committed
Configs with libs can now be renamed #1674
1 parent 6707778 commit 7f83949

File tree

2 files changed

+119
-23
lines changed

2 files changed

+119
-23
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.TreeMap;
1919
import java.util.TreeSet;
2020

21+
import org.eclipse.core.resources.IFolder;
2122
import org.eclipse.core.runtime.IPath;
2223
import org.eclipse.core.runtime.IProgressMonitor;
2324
import org.eclipse.core.runtime.IStatus;
@@ -450,4 +451,20 @@ private static Map<String, IArduinoLibraryVersion> getLibrariesHarware(BoardDesc
450451
return ret;
451452
}
452453

454+
public static IArduinoLibraryVersion getLibraryVersionFromLocation(IFolder libFolder,BoardDescription boardDescriptor) {
455+
// TODO Auto-generated method stub
456+
457+
if (boardDescriptor != null) {
458+
if(boardDescriptor.getReferencedCoreLibraryPath().isPrefixOf(libFolder.getLocation())) {
459+
return getLibrariesHarware(boardDescriptor).get(libFolder.getName());
460+
}
461+
}
462+
463+
if(ConfigurationPreferences.getInstallationPathLibraries().isPrefixOf(libFolder.getLocation())) {
464+
return getLibrariesdManaged().get(libFolder.getName());
465+
}
466+
467+
return getLibrariesPrivate().get(libFolder.getName());
468+
}
469+
453470
}

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

Lines changed: 102 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import io.sloeber.core.api.ConfigurationPreferences;
4343
import io.sloeber.core.api.IArduinoLibraryVersion;
4444
import io.sloeber.core.api.ISloeberConfiguration;
45+
import io.sloeber.core.api.LibraryManager;
4546
import io.sloeber.core.api.OtherDescription;
4647
import io.sloeber.core.tools.Helpers;
4748
import io.sloeber.core.tools.uploaders.UploadSketchWrapper;
@@ -495,6 +496,70 @@ public Set<IFolder> getIncludeFolders() {
495496
return ret;
496497
}
497498

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+
498563
@Override
499564
public void reAttachLibraries() {
500565
IProgressMonitor monitor = new NullProgressMonitor();
@@ -632,20 +697,33 @@ public LinkedHashMap<String, String> getPostbuildSteps() {
632697
* This apply is when this configuration is new.
633698
*/
634699
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+
}
636711
configureWhenDirty() ;
637712

638713
}
639714

640715
public void appliedConfigChange() {
641716
LinkToCore();
717+
linkLibrariesToFolder();
642718
}
643719

644720
/**
645721
* Look at the source entries to see whether this is a rename
646722
* 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
647725
*/
648-
private void updateSourceEntries() {
726+
private boolean updateSourceEntries() {
649727

650728
IFolder curArduinoConfigurationfolder=getArduinoConfigurationFolder();
651729
IFolder oldArduinoConfigurationfolder=null;
@@ -667,30 +745,31 @@ private void updateSourceEntries() {
667745
newSourceEntries[curItem]=orgSourceEntries[curItem];
668746
}
669747
}
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);
685764
}
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));
690765
}
691-
}
766+
getAutoBuildDesc().getCdtConfigurationDescription().setSourceEntries(newSourceEntries);
692767

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+
}
694773

695774
private String getCDTConfName() {
696775
return getAutoBuildDescription().getCdtConfigurationDescription().getName();

0 commit comments

Comments
 (0)