Skip to content

Commit 59ee10f

Browse files
author
jan
committed
Fiddle with when to use jsonurl and when not
Also includes some library code during project migration This may break "private hardware" based projects. Now teensy is no longer a private hardware I need a replacement for it
1 parent f9169f4 commit 59ee10f

File tree

3 files changed

+59
-62
lines changed

3 files changed

+59
-62
lines changed

io.sloeber.core/src/io/sloeber/arduinoFramework/api/BoardDescription.java

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import io.sloeber.core.Activator;
3838
import io.sloeber.core.Messages;
3939
import io.sloeber.core.api.ConfigurationPreferences;
40-
import io.sloeber.core.api.Const;
4140
import io.sloeber.core.api.VersionNumber;
4241
import io.sloeber.core.tools.KeyValue;
4342
import io.sloeber.core.txt.BoardTxtFile;
@@ -66,14 +65,10 @@ public class BoardDescription {
6665
private IArduinoPlatformVersion myReferencedPlatformVariant = null;
6766
private IArduinoPlatformVersion myReferencedPlatformCore = null;
6867
private IArduinoPlatformVersion myReferencedPlatformUpload = null;
69-
private String myJsonFileName = null;
7068
private String myJsonURL = null;
7169

7270
private boolean myIsDirty = true;
7371

74-
public String jsonURL() {
75-
return myJsonURL;
76-
}
7772

7873
@Override
7974
public String toString() {
@@ -281,7 +276,7 @@ public static List<BoardDescription> makeBoardDescriptors(File boardFile) {
281276
Map<String, String> boardSection = txtFile.getSection(curboardID);
282277
if (boardSection != null) {
283278
if (!"true".equalsIgnoreCase(boardSection.get("hide"))) { //$NON-NLS-1$ //$NON-NLS-2$
284-
boards.add(new BoardDescription(boardFile, curboardID, null));
279+
boards.add(new BoardDescription(null,boardFile, curboardID, null));
285280
}
286281
}
287282
}
@@ -296,16 +291,21 @@ public static List<BoardDescription> makeBoardDescriptors(File boardFile) {
296291
* @param options
297292
* if null default options are taken
298293
*/
299-
public BoardDescription(File boardsFile, String boardID, Map<String, String> options) {
294+
public BoardDescription(String jsonURL,File boardsFile, String boardID, Map<String, String> options) {
295+
300296
File expandedBoardsFile = resolvePathEnvironmentString(boardsFile);
301297
if (!expandedBoardsFile.exists()) {
302298
Activator.log(new Status(IStatus.ERROR, Activator.getId(), "BoardsFile " + boardsFile + " does not exist")); //$NON-NLS-1$//$NON-NLS-2$
303299
return;
304300
}
301+
if (jsonURL != null) {
302+
myJsonURL = jsonURL;
303+
} else {
304+
myJsonURL = BoardsManager.getjsonURLFormBoardsFile(expandedBoardsFile);
305+
}
305306
myBoardID = boardID;
306307
myUserSelectedBoardsTxtFile = boardsFile;
307308
mySloeberBoardTxtFile = new BoardTxtFile(expandedBoardsFile);
308-
getJSonInfo();
309309
setDefaultOptions();
310310
if (options != null) {
311311
myOptions.putAll(options);
@@ -316,13 +316,13 @@ public BoardDescription() {
316316
myUserSelectedBoardsTxtFile = new File(myStorageNode.get(KEY_LAST_USED_BOARDS_FILE, EMPTY));
317317
if (!myUserSelectedBoardsTxtFile.exists()) {
318318

319-
IArduinoPlatformVersion platform = BoardsManager.getNewestInstalledPlatform(VENDOR_ARDUINO, AVR);
319+
IArduinoPlatformVersion platform = BoardsManager.getNewestInstalledPlatform( VENDOR_ARDUINO, AVR);
320320
if (platform == null) {
321321
platform = BoardsManager.getAnyInstalledPlatform();
322322
}
323323
myUserSelectedBoardsTxtFile = platform.getBoardsFile();
324324
mySloeberBoardTxtFile = new BoardTxtFile(myUserSelectedBoardsTxtFile);
325-
getJSonInfo(platform);
325+
myJsonURL= BoardsManager.getjsonURLFormBoardsFile(myUserSelectedBoardsTxtFile);
326326

327327
if (mySloeberBoardTxtFile.getAllBoardIDs().contains(UNO)) {
328328
myBoardID = UNO;
@@ -335,38 +335,16 @@ public BoardDescription() {
335335
myBoardID = myStorageNode.get(KEY_LAST_USED_BOARD, EMPTY);
336336
myUploadPort = myStorageNode.get(KEY_LAST_USED_UPLOAD_PORT, EMPTY);
337337
myProgrammer = myStorageNode.get(KEY_LAST_USED_UPLOAD_PROTOCOL, EMPTY);
338-
myJsonFileName = myStorageNode.get(KEY_LAST_USED_JSON_FILENAME, EMPTY);
339338
myJsonURL = myStorageNode.get(KEY_LAST_USED_JSON_URL, EMPTY);
340339
myOptions = KeyValue.makeMap(myStorageNode.get(KEY_LAST_USED_BOARD_MENU_OPTIONS, EMPTY));
341340
}
342341

343342
}
344343

345-
private void getJSonInfo(IArduinoPlatformVersion platform) {
346-
IArduinoPlatformPackageIndex packageIndex = platform.getParent().getParent().getPackageIndex();
347-
myJsonFileName = packageIndex.getJsonFile().getName();
348-
myJsonURL = packageIndex.getJsonURL();
349-
}
350-
351-
private void getJSonInfo() {
352-
IArduinoPlatformVersion platform = BoardsManager.getNewestInstalledPlatform(getVendor(), getArchitecture());
353-
if (platform == null) {
354-
platform = BoardsManager.getNewestInstalledPlatform(VENDOR_ARDUINO, AVR);
355-
}
356-
if (platform == null) {
357-
platform = BoardsManager.getAnyInstalledPlatform();
358-
}
359-
if (platform != null) {
360-
myUserSelectedBoardsTxtFile = platform.getBoardsFile();
361-
mySloeberBoardTxtFile = new BoardTxtFile(myUserSelectedBoardsTxtFile);
362-
getJSonInfo(platform);
363-
}
364-
}
365344

366345
public BoardDescription(BoardDescription srcObject) {
367346
myUserSelectedBoardsTxtFile = srcObject.myUserSelectedBoardsTxtFile;
368347
mySloeberBoardTxtFile = srcObject.mySloeberBoardTxtFile;
369-
myJsonFileName = srcObject.myJsonFileName;
370348
myJsonURL = srcObject.myJsonURL;
371349
myBoardID = srcObject.myBoardID;
372350
myUploadPort = srcObject.myUploadPort;
@@ -424,7 +402,6 @@ public void saveUserSelection() {
424402
myStorageNode.put(KEY_LAST_USED_BOARD, myBoardID);
425403
myStorageNode.put(KEY_LAST_USED_UPLOAD_PORT, myUploadPort);
426404
myStorageNode.put(KEY_LAST_USED_UPLOAD_PROTOCOL, myProgrammer);
427-
myStorageNode.put(KEY_LAST_USED_JSON_FILENAME, myJsonFileName);
428405
myStorageNode.put(KEY_LAST_USED_JSON_URL, myJsonURL);
429406
myStorageNode.put(KEY_LAST_USED_BOARD_MENU_OPTIONS, KeyValue.makeString(myOptions));
430407
}
@@ -768,13 +745,6 @@ public boolean isNetworkUpload() {
768745
return getHost() != null;
769746
}
770747

771-
protected BoardDescription(File boardsFile, String boardID) {
772-
myBoardID = boardID;
773-
myUserSelectedBoardsTxtFile = boardsFile;
774-
mySloeberBoardTxtFile = new BoardTxtFile(myUserSelectedBoardsTxtFile);
775-
calculateDerivedFields();
776-
getJSonInfo();
777-
}
778748

779749
BoardDescription(TxtFile configFile, String prefix) {
780750

@@ -788,7 +758,6 @@ protected BoardDescription(File boardsFile, String boardID) {
788758
Map<String, String> options = optionsTree.toKeyValues(EMPTY);
789759

790760
KeyValueTree boardSection = tree.getChild(BOARD);
791-
myJsonFileName = boardSection.getValue(JSON_NAME);
792761
myJsonURL = boardSection.getValue(JSON_URL);
793762

794763
myUserSelectedBoardsTxtFile = resolvePathEnvironmentString(new File(board_txt));
@@ -814,7 +783,6 @@ public BoardDescription(KeyValueTree keyValues) {
814783
String txtFile = boardvalueTree.getValue(KEY_SLOEBER_BOARD_TXT);
815784

816785
KeyValueTree jSonvalueTree = keyValues.getChild(KEY_JSON);
817-
myJsonFileName = jSonvalueTree.getValue(KEY_JSON_FILENAME);
818786
myJsonURL = jSonvalueTree.getValue(KEY_JSON_URL);
819787

820788
myUserSelectedBoardsTxtFile = resolvePathEnvironmentString(new File(txtFile));
@@ -869,26 +837,12 @@ public void serialize(KeyValueTree keyValueTree) {
869837
boardvalueTree.addChild(KEY_SLOEBER_BOARD_TXT, board_txt);
870838

871839
KeyValueTree jSonvalueTree = keyValueTree.addChild(KEY_JSON);
872-
jSonvalueTree.addChild(KEY_JSON_FILENAME, myJsonFileName);
873840
jSonvalueTree.addChild(KEY_JSON_URL, myJsonURL);
874841

875842
KeyValueTree menuvalueTree = keyValueTree.addChild(KEY_SLOEBER_MENU_SELECTION);
876843
for (Entry<String, String> curOption : myOptions.entrySet()) {
877844
menuvalueTree.addValue(curOption.getKey(), curOption.getValue());
878845
}
879-
880-
// allVars.put(KEY_SLOEBER_PROGRAMMER, myProgrammer);
881-
// allVars.put(KEY_SLOEBER_BOARD_ID, myBoardID);
882-
// allVars.put(KEY_SLOEBER_BOARD_TXT, board_txt);
883-
// allVars.put(KEY_SLOEBER_UPLOAD_PORT, myUploadPort);
884-
//
885-
// allVars.put(KEY_JSON_FILENAME, myJsonFileName);
886-
// allVars.put(KEY_JSON_URL, myJsonURL);
887-
//
888-
// for (Entry<String, String> curOption : myOptions.entrySet()) {
889-
// allVars.put(KEY_SLOEBER_MENU_SELECTION + DOT + curOption.getKey(), curOption.getValue());
890-
// }
891-
// return allVars;
892846
}
893847

894848
private Map<String, String> onlyKeepValidOptions(Map<String, String> options) {
@@ -1065,7 +1019,7 @@ private Map<String, String> getEnVarPlatformInfo() throws IOException {
10651019
ret.putAll(getEnvVarPlatformFileTools(myReferencedPlatformCore));
10661020

10671021
BoardsManager.update(false);// This way we know the boardsmanager is started or we wait for the lock
1068-
IArduinoPlatformVersion latestArduinoPlatform = BoardsManager.getNewestInstalledPlatform(Const.VENDOR_ARDUINO,
1022+
IArduinoPlatformVersion latestArduinoPlatform = BoardsManager.getNewestInstalledPlatform(VENDOR_ARDUINO,
10691023
getArchitecture());
10701024
ret.putAll(getEnvVarPlatformFileTools(latestArduinoPlatform));
10711025

io.sloeber.core/src/io/sloeber/arduinoFramework/api/BoardsManager.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static boolean isReady() {
103103
static public BoardDescription getBoardDescription(String jsonURL, String packageName, String architectureID,
104104
String boardID, Map<String, String> options) {
105105
if (LOCAL.equals(jsonURL)) {
106-
return new BoardDescription(new File(packageName), boardID, options);
106+
return new BoardDescription(jsonURL,new File(packageName), boardID, options);
107107
}
108108
update(false);
109109
return getNewestBoardIDFromBoardsManager(jsonURL, packageName, architectureID, boardID, options);
@@ -124,7 +124,7 @@ static private BoardDescription getNewestBoardIDFromBoardsManager(String jsonURL
124124
}
125125
IArduinoPlatformVersion platformVersion = platform.getNewestVersion();
126126
java.io.File boardsFile = platformVersion.getBoardsFile();
127-
BoardDescription boardid = new BoardDescription(boardsFile, boardID, options);
127+
BoardDescription boardid = new BoardDescription(jsonURL,boardsFile, boardID, options);
128128

129129
return boardid;
130130
}
@@ -680,7 +680,7 @@ public static List<IArduinoPlatformPackageIndex> getPackageIndices() {
680680
// return platforms;
681681
// }
682682

683-
public static IArduinoPlatform getPlatform(String vendor, String architecture) {
683+
public static IArduinoPlatform getPlatform( String vendor, String architecture) {
684684
if (myIsDirty) {
685685
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
686686
return null;
@@ -835,7 +835,7 @@ private static void onlyKeepLatestPlatforms(IArduinoPackage curPackage) {
835835
}
836836
}
837837

838-
public static IArduinoPlatformVersion getPlatform(String vendor, String architecture, VersionNumber refVersion) {
838+
public static IArduinoPlatformVersion getPlatform( String vendor, String architecture, VersionNumber refVersion) {
839839
IArduinoPlatform platform = getPlatform(vendor, architecture);
840840
if (platform != null) {
841841
return platform.getVersion(refVersion);
@@ -909,4 +909,21 @@ public static void update(boolean reloadFromInternet) {
909909
myIsUpdating=false;
910910
}
911911

912+
public static String getjsonURLFormBoardsFile(File boardsFile) {
913+
File expandedBoardsFile = resolvePathEnvironmentString(boardsFile);
914+
String ret=null;
915+
for (IArduinoPlatformPackageIndex index : packageIndices) {
916+
ret=index.getJsonURL();
917+
for (IArduinoPackage pkg : index.getPackages()) {
918+
for (IArduinoPlatformVersion platformVersion : pkg.getInstalledPlatforms()) {
919+
920+
if(platformVersion.getBoardsFile().equals(expandedBoardsFile)) {
921+
return ret;
922+
}
923+
}
924+
}
925+
}
926+
return ret;
927+
}
928+
912929
}

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.util.HashSet;
1010
import java.util.Map;
1111
import java.util.Set;
12+
import java.util.TreeMap;
13+
1214
import org.eclipse.cdt.core.CCProjectNature;
1315
import org.eclipse.cdt.core.CCorePlugin;
1416
import org.eclipse.cdt.core.settings.model.CSourceEntry;
@@ -34,6 +36,7 @@
3436

3537
import io.sloeber.arduinoFramework.api.BoardDescription;
3638
import io.sloeber.arduinoFramework.api.IArduinoLibraryVersion;
39+
import io.sloeber.arduinoFramework.api.LibraryManager;
3740
import io.sloeber.autoBuild.api.AutoBuildProject;
3841
import io.sloeber.autoBuild.api.IAutoBuildConfigurationDescription;
3942
import io.sloeber.autoBuild.buildTools.api.IBuildTools;
@@ -129,6 +132,18 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
129132
SloeberNature.addNature(project, internalMonitor);
130133
ICProjectDescription prjCDesc = cCorePlugin.getProjectDescription(project, true);
131134

135+
// Get the libraries used
136+
Set<String> libNames = new HashSet<>();
137+
IFolder libFolder = OldCoreFolder.getFolder("libraries"); //$NON-NLS-1$
138+
if (libFolder.exists()) {
139+
for (IResource curResource : libFolder.members()) {
140+
if (curResource instanceof IFolder) {
141+
IFolder curFolder = (IFolder) curResource;
142+
libNames.add(curFolder.getName());
143+
}
144+
}
145+
}
146+
132147

133148
IConfiguration defaultConfig = projectType.getConfigurations()[0];
134149
for(String cfgName:cfgNames) {
@@ -194,6 +209,17 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
194209
autoConf.setIsParallelBuild(compileDescriptor.isParallelBuildEnabled());
195210
SloeberConfiguration sloeberConfiguration = new SloeberConfiguration(boardDescriptor, otherDesc,
196211
compileDescriptor);
212+
213+
// Add the libraries
214+
TreeMap<String, IArduinoLibraryVersion> availableLibs = LibraryManager
215+
.getLibrariesAll(boardDescriptor);
216+
// find the libs we can add
217+
Set<IArduinoLibraryVersion> toInstallLibs = new HashSet<>();
218+
for (String curLibName : libNames) {
219+
toInstallLibs.add(availableLibs.get(curLibName));
220+
}
221+
sloeberConfiguration.addLibraries(toInstallLibs);
222+
197223
//Save the sloeber configuration in the autoBuild configuration
198224
autoConf.setAutoBuildConfigurationExtensionDescription(sloeberConfiguration);
199225
}
@@ -301,7 +327,7 @@ private static BoardDescription getBoardDescription(KeyValueTree oldConfig) {
301327
}
302328
File boardsFile=foundBoardsFilePath.toFile();// new File(boardsFileString);
303329

304-
BoardDescription ret= new BoardDescription( boardsFile, boardID, options);
330+
BoardDescription ret= new BoardDescription( null,boardsFile, boardID, options);
305331
String uploadPort=oldConfig.getValue("board.UPLOAD.PORT"); //$NON-NLS-1$
306332
ret.setUploadPort(uploadPort);
307333

0 commit comments

Comments
 (0)