Skip to content

Commit ce8a637

Browse files
author
jantje
committed
better recover from bad boardsfiles
in this case the boards file was not existing due to checkout from git
1 parent fe41d47 commit ce8a637

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

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

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ public TreeMap<String, String> getMenus() {
112112
}
113113

114114
/**
115-
* Get all the acceptable values for a option for a board The outcome of
116-
* this method can be used to fill a
115+
* Get all the acceptable values for a option for a board The outcome of this
116+
* method can be used to fill a
117117
*
118118
* @param menu
119119
* the id of a menu not the name
@@ -143,8 +143,8 @@ public String[] getMenuItemNamesFromMenuID(String menuID, String boardID) {
143143
}
144144

145145
/**
146-
* Get all the acceptable values for a option for a board The outcome of
147-
* this method can be used to fill a
146+
* Get all the acceptable values for a option for a board The outcome of this
147+
* method can be used to fill a
148148
*
149149
* @param menu
150150
* the id of a menu not the name
@@ -185,13 +185,13 @@ public String[] getAllNames() {
185185
}
186186

187187
/**
188-
* getAllNames returns all the "names" that are in the currently loaded
189-
* *.txt file. The toaddNames are added to the end result toaddNames should
190-
* be a string array and can not be null
188+
* getAllNames returns all the "names" that are in the currently loaded *.txt
189+
* file. The toaddNames are added to the end result toaddNames should be a
190+
* string array and can not be null
191191
*
192-
* For a boards.txt file that means all the board names. For a
193-
* programmers.txt file that means all the programmers For platform.txt the
194-
* outcome is not defined
192+
* For a boards.txt file that means all the board names. For a programmers.txt
193+
* file that means all the programmers For platform.txt the outcome is not
194+
* defined
195195
*
196196
* @return an empty list if no board file is loaded. In all other cases it
197197
* returns the list of boards found in the file
@@ -270,8 +270,8 @@ private boolean LoadBoardsFile() {
270270

271271
/**
272272
* Given a nice name look for the ID The assumption is that the txt file
273-
* contains a line like ID.name=[nice name] Given this this method returns
274-
* ID when given [nice name]
273+
* contains a line like ID.name=[nice name] Given this this method returns ID
274+
* when given [nice name]
275275
*/
276276
public String getBoardIDFromBoardName(String name) {
277277
if ((name == null) || name.isEmpty()) {
@@ -318,8 +318,8 @@ static public void load(File inputFile, Map<String, String> table) throws IOExce
318318
}
319319

320320
/**
321-
* Loads an input stream into an array of strings representing each line of
322-
* the input stream
321+
* Loads an input stream into an array of strings representing each line of the
322+
* input stream
323323
*
324324
* @param input
325325
* the input stream to load
@@ -408,29 +408,34 @@ public String getNameFromID(String myBoardID) {
408408
}
409409

410410
/*
411-
* Returns the package name based on the boardsfile name Caters for the
412-
* packages (with version number and for the old way
411+
* Returns the package name based on the boardsfile name Caters for the packages
412+
* (with version number and for the old way
413+
* if the boards file does not exists returns arduino
413414
*/
414415
public String getPackage() {
415-
IPath platformFile = new Path(this.mLastLoadedTxtFile.toString().trim());
416-
String architecture = platformFile.removeLastSegments(1).lastSegment();
417-
if (architecture.contains(Const.DOT)) { // This is a version number so
418-
// package
419-
return platformFile.removeLastSegments(4).lastSegment();
416+
if (this.mLastLoadedTxtFile.exists()) {
417+
IPath platformFile = new Path(this.mLastLoadedTxtFile.toString().trim());
418+
String architecture = platformFile.removeLastSegments(1).lastSegment();
419+
if (architecture.contains(Const.DOT)) { // This is a version number so
420+
// package
421+
return platformFile.removeLastSegments(4).lastSegment();
422+
}
423+
return platformFile.removeLastSegments(2).lastSegment();
420424
}
421-
return platformFile.removeLastSegments(2).lastSegment();
425+
return "arduino"; //$NON-NLS-1$
422426
}
423427

424428
/*
425429
* Returns the architecture based on the platform file name Caters for the
426430
* packages (with version number and for the old way
431+
* if the boards file does not exists returns avr
427432
*/
428433
public String getArchitecture() {
429434

430435
IPath platformFile = new Path(this.mLastLoadedTxtFile.toString().trim());
431436
String architecture = platformFile.removeLastSegments(1).lastSegment();
432-
if (architecture==null) {//for error conditions
433-
architecture="avr"; //$NON-NLS-1$
437+
if (architecture == null) {// for error conditions
438+
architecture = "avr"; //$NON-NLS-1$
434439
}
435440
if (architecture.contains(Const.DOT)) { // This is a version number so
436441
// package

0 commit comments

Comments
 (0)