Skip to content

Commit 6e7a835

Browse files
author
jan
committed
Add libraries from the original project to the sloeber converted project
1 parent 1706127 commit 6e7a835

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

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

+31-5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import io.sloeber.arduinoFramework.api.BoardDescription;
3838
import io.sloeber.arduinoFramework.api.IArduinoLibraryVersion;
3939
import io.sloeber.arduinoFramework.api.LibraryManager;
40+
import io.sloeber.arduinoFramework.internal.ArduinoLibraryVersion;
4041
import io.sloeber.autoBuild.api.AutoBuildProject;
4142
import io.sloeber.autoBuild.api.IAutoBuildConfigurationDescription;
4243
import io.sloeber.autoBuild.buildTools.api.IBuildTools;
@@ -48,6 +49,8 @@
4849
import io.sloeber.autoBuild.schema.api.IProjectType;
4950
import io.sloeber.core.Activator;
5051
import io.sloeber.core.Messages;
52+
import io.sloeber.core.internal.ArduinoHardwareLibrary;
53+
import io.sloeber.core.internal.ArduinoPrivateLibraryVersion;
5154
import io.sloeber.core.internal.SloeberConfiguration;
5255
import io.sloeber.core.listeners.IndexerController;
5356
import io.sloeber.core.natures.SloeberNature;
@@ -134,7 +137,7 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
134137

135138
// Get the libraries used
136139
Set<String> libNames = new HashSet<>();
137-
IFolder libFolder = OldCoreFolder.getFolder("libraries"); //$NON-NLS-1$
140+
IFolder libFolder = project.getFolder("libraries"); //$NON-NLS-1$
138141
if (libFolder.exists()) {
139142
for (IResource curResource : libFolder.members()) {
140143
if (curResource instanceof IFolder) {
@@ -210,18 +213,41 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
210213
SloeberConfiguration sloeberConfiguration = new SloeberConfiguration(boardDescriptor, otherDesc,
211214
compileDescriptor);
212215

216+
217+
218+
//Save the sloeber configuration in the autoBuild configuration
219+
autoConf.setAutoBuildConfigurationExtensionDescription(sloeberConfiguration);
220+
213221
// Add the libraries
214222
TreeMap<String, IArduinoLibraryVersion> availableLibs = LibraryManager
215223
.getLibrariesAll(boardDescriptor);
216224
// find the libs we can add
217225
Set<IArduinoLibraryVersion> toInstallLibs = new HashSet<>();
218226
for (String curLibName : libNames) {
219-
toInstallLibs.add(availableLibs.get(curLibName));
227+
IPath boardLibFQN = ArduinoHardwareLibrary.calculateFQN(curLibName);
228+
IArduinoLibraryVersion foundLib = availableLibs.get(boardLibFQN.toString());
229+
if (foundLib != null) {
230+
toInstallLibs.add(foundLib);
231+
continue;
232+
}
233+
234+
IPath managedLibFQN = ArduinoLibraryVersion.calculateFQN(curLibName);
235+
foundLib = availableLibs.get(managedLibFQN.toString());
236+
if (foundLib != null) {
237+
toInstallLibs.add(foundLib);
238+
continue;
239+
}
240+
241+
IPath privateLibFQN = ArduinoPrivateLibraryVersion.calculateFQN(curLibName);
242+
foundLib = availableLibs.get(privateLibFQN.toString());
243+
if (foundLib != null) {
244+
toInstallLibs.add(foundLib);
245+
continue;
246+
}
247+
220248
}
249+
toInstallLibs.remove(null);
221250
sloeberConfiguration.addLibraries(toInstallLibs);
222-
223-
//Save the sloeber configuration in the autoBuild configuration
224-
autoConf.setAutoBuildConfigurationExtensionDescription(sloeberConfiguration);
225251
}
226252

227253
SubMonitor refreshMonitor = SubMonitor.convert(internalMonitor, 3);

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ArduinoHardwareLibrary implements IArduinoLibraryVersion {
2121
public ArduinoHardwareLibrary(IPath installPath) {
2222
myInstallPath = installPath;
2323
myName = myInstallPath.lastSegment();
24-
calculateFQN();
24+
myFQN=calculateFQN(getName());
2525
}
2626

2727
public ArduinoHardwareLibrary(String curSaveString, BoardDescription boardDesc) {
@@ -31,7 +31,7 @@ public ArduinoHardwareLibrary(String curSaveString, BoardDescription boardDesc)
3131
if(!myInstallPath.toFile().exists()) {
3232
myInstallPath=boardDesc.getReferencedCoreLibraryPath().append(myName);
3333
}
34-
calculateFQN();
34+
myFQN=calculateFQN(getName());
3535
}
3636

3737
@Override
@@ -64,9 +64,8 @@ public IPath getExamplePath() {
6464
}
6565

6666

67-
private void calculateFQN() {
68-
myFQN= Path.fromPortableString(SLOEBER_LIBRARY_FQN);
69-
myFQN= myFQN.append(BOARD).append(getName());
67+
public static IPath calculateFQN(String libName) {
68+
return Path.fromPortableString(SLOEBER_LIBRARY_FQN).append(BOARD).append(libName);
7069
}
7170

7271
@Override

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ public class ArduinoPrivateLibraryVersion implements IArduinoLibraryVersion {
2020
public ArduinoPrivateLibraryVersion(IPath installPath) {
2121
myInstallPath = installPath;
2222
myName = myInstallPath.lastSegment();
23-
calcFQN();
23+
myFQN= calculateFQN(getName());
2424
}
2525

2626
public ArduinoPrivateLibraryVersion(String curSaveString) {
2727
String[] parts=curSaveString.split(SEMI_COLON);
2828
myName=parts[parts.length-1];
29-
calcFQN();
29+
myFQN= calculateFQN(getName());
3030
String privateLibPaths[] = InstancePreferences.getPrivateLibraryPaths();
3131
for (String curLibPath : privateLibPaths) {
3232
Path curPrivPath=new Path(curLibPath);
@@ -67,9 +67,8 @@ public IPath getExamplePath() {
6767
return getInstallPath().append(EXAMPLES_FOLDER);
6868
}
6969

70-
private void calcFQN() {
71-
myFQN= Path.fromPortableString(SLOEBER_LIBRARY_FQN);
72-
myFQN= myFQN.append(PRIVATE).append(getName());
70+
static public IPath calculateFQN(String libName) {
71+
return Path.fromPortableString(SLOEBER_LIBRARY_FQN).append(PRIVATE).append(libName);
7372
}
7473

7574
@Override

0 commit comments

Comments
 (0)