Skip to content

Commit c95305e

Browse files
author
jan
committed
Change the linked board libs on board changes #1679
1 parent 89c7a42 commit c95305e

File tree

3 files changed

+110
-63
lines changed

3 files changed

+110
-63
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public boolean createFiles(IContainer scrContainer, IProgressMonitor monitor) {
369369
if (myMakeLinks) {
370370
if(scrContainer instanceof IFolder) {
371371
IFolder folder=(IFolder)scrContainer;
372-
Helpers.linkDirectory( curPath, folder);
372+
Helpers.LinkFolderToFolder( curPath, folder);
373373
}
374374
else {
375375
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID,

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

Lines changed: 76 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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

io.sloeber.core/src/io/sloeber/core/tools/Helpers.java

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -289,38 +289,38 @@ public static void deleteBuildFolder(IProject project, String cfgName) {
289289
autoData.deleteBuildFolder(new NullProgressMonitor());
290290
}
291291

292-
/**
293-
* creates links to the root files and folders of the source location
294-
*
295-
* @param source
296-
* the location where the files are that need to be linked to
297-
* @param target
298-
* the location where the links are to be created
299-
*/
300-
public static void linkDirectory(IPath source, IFolder target) {
301-
302-
File[] sourceFiles = source.toFile().listFiles();
303-
if (sourceFiles == null) {
304-
if (!myHasBeenLogged) {
305-
Activator.log(new Status(IStatus.INFO, CORE_PLUGIN_ID,
306-
Messages.Helpers_error_link_folder_is_empty.replace(FILE, source.toOSString()), null));
307-
myHasBeenLogged = true;
308-
}
309-
return;
310-
}
311-
for (File curFile : sourceFiles) {
312-
if (curFile.isDirectory()) {
313-
LinkFolderToFolder(source.append(curFile.getName()), target.getFolder(curFile.getName()));
314-
} else {
315-
try {
316-
target.getFile(curFile.getName()).createLink(source.append(curFile.getName()),
317-
IResource.REPLACE | IResource.ALLOW_MISSING_LOCAL, null);
318-
} catch (CoreException e) {
319-
e.printStackTrace();
320-
}
321-
}
322-
}
323-
324-
}
292+
// /**
293+
// * creates links to the root files and folders of the source location
294+
// *
295+
// * @param source
296+
// * the location where the files are that need to be linked to
297+
// * @param target
298+
// * the location where the links are to be created
299+
// */
300+
// public static void linkDirectory(IPath source, IFolder target) {
301+
//
302+
// File[] sourceFiles = source.toFile().listFiles();
303+
// if (sourceFiles == null) {
304+
// if (!myHasBeenLogged) {
305+
// Activator.log(new Status(IStatus.INFO, CORE_PLUGIN_ID,
306+
// Messages.Helpers_error_link_folder_is_empty.replace(FILE, source.toOSString()), null));
307+
// myHasBeenLogged = true;
308+
// }
309+
// return;
310+
// }
311+
// for (File curFile : sourceFiles) {
312+
// if (curFile.isDirectory()) {
313+
// LinkFolderToFolder(source.append(curFile.getName()), target.getFolder(curFile.getName()));
314+
// } else {
315+
// try {
316+
// target.getFile(curFile.getName()).createLink(source.append(curFile.getName()),
317+
// IResource.REPLACE | IResource.ALLOW_MISSING_LOCAL, null);
318+
// } catch (CoreException e) {
319+
// e.printStackTrace();
320+
// }
321+
// }
322+
// }
323+
//
324+
// }
325325

326326
}

0 commit comments

Comments
 (0)