Skip to content

Commit 15f4ea7

Browse files
author
jan
committed
Add library shows SD in boards and managed #1712
1 parent 074a1fd commit 15f4ea7

File tree

4 files changed

+45
-34
lines changed

4 files changed

+45
-34
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.eclipse.core.resources.IFile;
1313
import org.eclipse.core.resources.IFolder;
1414
import org.eclipse.core.resources.IProject;
15+
import org.eclipse.core.runtime.IPath;
1516
import org.eclipse.core.runtime.IStatus;
1617
import org.eclipse.core.runtime.Status;
1718

@@ -119,7 +120,7 @@ public static ISloeberConfiguration getConfig(IAutoBuildConfigurationDescription
119120
* Add libraries to the configurations
120121
* Some libraries contain subfolders that need to be ignoreed.
121122
* Therefore the configuration description may change.
122-
*
123+
*
123124
* @param librariesToAdd
124125
* @return true if when cCorePlugin.setProjectDescription needs to be called
125126
*/
@@ -136,7 +137,7 @@ public static ISloeberConfiguration getConfig(IAutoBuildConfigurationDescription
136137
*/
137138
void reAttachLibraries();
138139

139-
Map<String, IArduinoLibraryVersion> getUsedLibraries();
140+
Map<IPath, IArduinoLibraryVersion> getUsedLibraries();
140141
void setLibraries(Set<IArduinoLibraryVersion> selectedLibraries);
141142
IFolder getArduinoRootFolder();
142143

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

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.LinkedList;
1010
import java.util.List;
1111
import java.util.Map;
12-
import java.util.Map.Entry;
1312
import java.util.Set;
1413
import static io.sloeber.core.api.Common.*;
1514
import static io.sloeber.core.api.Const.*;
@@ -57,7 +56,7 @@ public class SloeberConfiguration extends AutoBuildConfigurationExtensionDescrip
5756
private OtherDescription myOtherDesc;
5857
private CompileDescription myCompileDescription;
5958
// a map of foldername library
60-
private Map<String, IArduinoLibraryVersion> myLibraries = new HashMap<>();
59+
private Map<IPath, IArduinoLibraryVersion> myLibraries = new HashMap<>();
6160

6261
// operational data
6362
private boolean myMemoryIsDirty = true;
@@ -518,8 +517,8 @@ public Set<IFolder> getIncludeFolders() {
518517
* @return
519518
* @throws CoreException
520519
*/
521-
private Map<String, IArduinoLibraryVersion> getLibrariesFromLinks() {
522-
Map<String, IArduinoLibraryVersion> ret = new HashMap<>();
520+
private Map<IPath, IArduinoLibraryVersion> getLibrariesFromLinks() {
521+
Map<IPath, IArduinoLibraryVersion> ret = new HashMap<>();
523522
IFolder libFolder = getArduinoLibraryFolder();
524523
if (!libFolder.exists()) {
525524
return ret;
@@ -528,16 +527,22 @@ private Map<String, IArduinoLibraryVersion> getLibrariesFromLinks() {
528527
for (IResource curResource : libFolder.members()) {
529528
if (curResource instanceof IFolder) {
530529
IFolder curFolder = (IFolder) curResource;
531-
IArduinoLibraryVersion curLib = myLibraries.get(curFolder.getName());
530+
IArduinoLibraryVersion curLib=null;
531+
for(IArduinoLibraryVersion curknowLib: myLibraries.values()) {
532+
if(curknowLib.getName().equals(curFolder.getName())){
533+
curLib=curknowLib;
534+
continue;
535+
}
536+
}
532537
if (curLib != null) {
533-
// We knbow the lib so it is ok
534-
ret.put(curLib.getName(), curLib);
538+
// We know the lib so it is ok
539+
ret.put(curLib.getFQN(), curLib);
535540
continue;
536541
}
537542

538543
curLib = LibraryManager.getLibraryVersionFromLocation(curFolder, getBoardDescription());
539544
if (curLib != null) {
540-
ret.put(curLib.getName(), curLib);
545+
ret.put(curLib.getFQN(), curLib);
541546
}
542547
}
543548
}
@@ -555,8 +560,8 @@ private Map<String, IArduinoLibraryVersion> getLibrariesFromLinks() {
555560
private void removeLibraryLinks() {
556561
IProgressMonitor monitor = new NullProgressMonitor();
557562
IFolder libFolder = getArduinoLibraryFolder();
558-
for (String curLib : myLibraries.keySet()) {
559-
IFolder curLibFolder = libFolder.getFolder(curLib);
563+
for (IArduinoLibraryVersion curLib : myLibraries.values()) {
564+
IFolder curLibFolder = libFolder.getFolder(curLib.getName());
560565
if (curLibFolder.exists()) {
561566
try {
562567
curLibFolder.delete(true, monitor);
@@ -592,7 +597,7 @@ private void upDateHardwareLibraries() {
592597
if (referencingLibPath == null) {
593598
referencingLibPath = referenceLibPath;
594599
}
595-
Set<String> hardwareLibsFQN = new HashSet<>();
600+
Set<IPath> hardwareLibsFQN = new HashSet<>();
596601
for (IArduinoLibraryVersion curLib : myLibraries.values()) {
597602
if (curLib.isHardwareLib()) {
598603
IPath libPath = curLib.getInstallPath();
@@ -602,19 +607,19 @@ private void upDateHardwareLibraries() {
602607
}
603608
// The hardware lib is for a different hardware.
604609
// add it to the lists to reattach
605-
hardwareLibsFQN.add(curLib.getFQN().toPortableString());
610+
hardwareLibsFQN.add(curLib.getFQN());
606611
}
607612
}
608613
if (!hardwareLibsFQN.isEmpty()) {
609614
Map<String, IArduinoLibraryVersion> boardLibs = LibraryManager.getLibrariesHarware(boardDesc);
610-
for (String curReplaceLibFQN : hardwareLibsFQN) {
611-
IArduinoLibraryVersion newLib = boardLibs.get(curReplaceLibFQN);
615+
for (IPath curReplaceLibFQN : hardwareLibsFQN) {
616+
IArduinoLibraryVersion newLib = boardLibs.get(curReplaceLibFQN.toPortableString());
612617
if (newLib != null) {
613618
// a library with the same name was found so use this one
614-
myLibraries.put(newLib.getName(), newLib);
619+
myLibraries.put(newLib.getFQN(), newLib);
615620
} else {
616621
// no new library was found remove the old lib
617-
myLibraries.remove(Path.fromPortableString(curReplaceLibFQN).lastSegment());
622+
myLibraries.remove(curReplaceLibFQN);
618623
}
619624
}
620625
}
@@ -635,7 +640,14 @@ public void reAttachLibraries() {
635640
for (IResource curResource : libFolder.members()) {
636641
if (curResource instanceof IFolder) {
637642
IFolder curFolder = (IFolder) curResource;
638-
IArduinoLibraryVersion curLib = myLibraries.get(curFolder.getName());
643+
644+
IArduinoLibraryVersion curLib =null;
645+
for(IArduinoLibraryVersion curknowLib: myLibraries.values()) {
646+
if(curknowLib.getName().equals(curFolder.getName())){
647+
curLib=curknowLib;
648+
}
649+
}
650+
639651
if ((curLib == null) || (!curLib.getInstallPath().equals(curFolder.getLocation()))) {
640652
try {
641653
curFolder.delete(true, monitor);
@@ -659,7 +671,7 @@ public void reAttachLibraries() {
659671
}
660672

661673
@Override
662-
public Map<String, IArduinoLibraryVersion> getUsedLibraries() {
674+
public Map<IPath, IArduinoLibraryVersion> getUsedLibraries() {
663675
myLibraries = getLibrariesFromLinks();
664676
return new HashMap<>(myLibraries);
665677
}
@@ -679,7 +691,7 @@ public boolean addLibraries(Collection<IArduinoLibraryVersion> librartiesToAdd)
679691
}
680692
IFolder newLibFolder = libFolder.getFolder(curLib.getName());
681693
Helpers.LinkFolderToFolder(curLib.getInstallPath(), newLibFolder);
682-
myLibraries.put(curLib.getName(), curLib);
694+
myLibraries.put(curLib.getFQN(), curLib);
683695

684696
// exclude bad folders
685697
File[] subFolders;
@@ -722,9 +734,9 @@ public boolean removeLibraries(Collection<IArduinoLibraryVersion> librariesToRem
722734
IProgressMonitor monitor = new NullProgressMonitor();
723735
IFolder libFolder = getArduinoLibraryFolder();
724736
for (IArduinoLibraryVersion curLib : librariesToRemove) {
725-
if (myLibraries.containsKey(curLib.getName())) {
737+
if (myLibraries.containsKey(curLib.getFQN())) {
726738
ret = true;
727-
myLibraries.remove(curLib.getName());
739+
myLibraries.remove(curLib.getFQN());
728740
try {
729741
libFolder.getFolder(curLib.getName()).delete(true, monitor);
730742
} catch (CoreException e) {
@@ -759,10 +771,8 @@ public boolean equals(AutoBuildConfigurationExtensionDescription base) {
759771
myOtherDesc.equals(other.myOtherDesc) &&
760772
myCompileDescription.equals(other.myCompileDescription) &&
761773
myLibraries.size()==other.myLibraries.size()) {
762-
for (Entry<String, IArduinoLibraryVersion> curLib : myLibraries.entrySet()) {
763-
String key = curLib.getKey();
764-
IArduinoLibraryVersion localValue = curLib.getValue();
765-
IArduinoLibraryVersion otherValue = other.myLibraries.get(key);
774+
for ( IArduinoLibraryVersion localValue : myLibraries.values()) {
775+
IArduinoLibraryVersion otherValue = other.myLibraries.get(localValue.getFQN());
766776
if (!localValue.equals(otherValue)) {
767777
return false;
768778
}

io.sloeber.core/src/io/sloeber/core/listeners/IndexerListener.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public void indexChanged(IIndexerStateEvent event) {
9393
}
9494

9595
private static boolean checkLibraries(ISloeberConfiguration SloeberCfg) {
96-
Map<String, IArduinoLibraryVersion> alreadyAddedLibs = SloeberCfg.getUsedLibraries();
9796
Set<String> UnresolvedIncludedHeaders = getUnresolvedProjectIncludes(SloeberCfg.getProject());
9897
// remove pgmspace as it gives a problem
9998
UnresolvedIncludedHeaders.remove("pgmspace"); //$NON-NLS-1$
@@ -102,12 +101,12 @@ private static boolean checkLibraries(ISloeberConfiguration SloeberCfg) {
102101
}
103102

104103
//The line below is for cases where libs have been excluded from the build
105-
for(String curLib:alreadyAddedLibs.keySet()) {
106-
IFolder libFolder =SloeberCfg.getArduinoLibraryFolder().getFolder(curLib);
104+
for(IArduinoLibraryVersion curLib:SloeberCfg.getUsedLibraries().values()) {
105+
IFolder libFolder =SloeberCfg.getArduinoLibraryFolder().getFolder(curLib.getName());
107106
if(libFolder.exists()) {
108-
UnresolvedIncludedHeaders.remove(curLib);
107+
UnresolvedIncludedHeaders.remove(curLib.getName());
109108
}else {
110-
UnresolvedIncludedHeaders.add(curLib);
109+
UnresolvedIncludedHeaders.add(curLib.getName());
111110
}
112111
}
113112

io.sloeber.ui/src/io/sloeber/ui/Import_Libraries_Page.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
1212
import org.eclipse.core.resources.IProject;
1313
import org.eclipse.core.runtime.CoreException;
14+
import org.eclipse.core.runtime.IPath;
1415
import org.eclipse.jface.viewers.IStructuredSelection;
1516
import org.eclipse.jface.viewers.ITreeContentProvider;
1617
import org.eclipse.swt.SWT;
@@ -67,7 +68,7 @@ public void createControl(Composite parent) {
6768
class ItemSorter {
6869
private TreeMap<String, ItemSorter> myItems = new TreeMap<>();
6970
private IArduinoLibraryVersion myLib = null;
70-
private static Map<String, IArduinoLibraryVersion> myCurrentInstalledLibs =null;
71+
private static Map<IPath, IArduinoLibraryVersion> myCurrentInstalledLibs =null;
7172

7273
ItemSorter() {
7374
}
@@ -87,7 +88,7 @@ public void createChildren(TreeItem curItem) {
8788
if (myLib == null) {
8889
curItem.setGrayed(true);
8990
}else {
90-
boolean isSelected = myCurrentInstalledLibs.get(myLib.getName()) != null;
91+
boolean isSelected = myCurrentInstalledLibs.get(myLib.getFQN()) != null;
9192
curItem.setChecked(isSelected);
9293
curItem.setData(myLib);
9394
if (isSelected) {

0 commit comments

Comments
 (0)