Skip to content

Commit 7cf5b72

Browse files
committed
Fixed issues about invalid targets. Menu selection of boards and libraries are now functional.
1 parent fa26825 commit 7cf5b72

File tree

3 files changed

+74
-13
lines changed

3 files changed

+74
-13
lines changed

app/src/processing/app/Base.java

+70-10
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ public void rebuildImportMenu(JMenu importMenu) {
959959
//Choose which library to add by chip platform
960960

961961
try {
962-
//Find the current target. Get the platform, and then select the correct name and core path.
962+
//Find the current target. Get the platform, and then select the correct name and core path.
963963
String platformname = this.getBoardPreferences().get("platform");
964964
String targetname = this.getPlatformPreferences(platformname).get("name");
965965
String libraryPath = this.getPlatformPreferences(platformname).get("library.core.path");
@@ -1553,11 +1553,20 @@ static public String getAvrBasePath() {
15531553

15541554

15551555
static public Target getTarget() {
1556-
return Base.targetsTable.get(Preferences.get("target"));
1556+
System.out.println("Base.targetsTable.get(Preferences.get(\"target\"))" + Base.targetsTable.get(Preferences.get("target")));
1557+
System.out.println("Preferences.get(\"target\")" + Preferences.get("target"));
1558+
Target target = Base.targetsTable.get(Preferences.get("target"));
1559+
if (target == null) {
1560+
System.out.println("default target is not in list. Replace with default.");
1561+
Preferences.set("target", "arduino");
1562+
target = Base.targetsTable.get(Preferences.get("target"));
1563+
}
1564+
return target;
15571565
}
15581566

15591567

15601568
static public Map<String, String> getPlatformPreferences() {
1569+
System.out.println("getPlatformPreferences() no arguments: start");
15611570
Target target = getTarget();
15621571
//if (target == null) return new LinkedHashMap();
15631572
Map map = target.getPlatforms();
@@ -1576,22 +1585,73 @@ static public Map<String, String> getPlatformPreferences() {
15761585

15771586
//Get a specific platform
15781587
static public Map<String, String> getPlatformPreferences(String platformname) {
1588+
if (platformname == null) {
1589+
platformname = Preferences.get("platform");
1590+
1591+
}
1592+
System.out.println("getlatformPreferences(String platformname)): start: platformname = " + platformname );
15791593
Target target = getTarget();
1580-
Map map = target.getPlatforms();
1581-
map = (Map) map.get(platformname);
1582-
return map;
1594+
if (target == null ) {
1595+
System.out.println("get target is null. trouble! ");
1596+
}
1597+
Map map = target.getPlatforms();
1598+
map = (Map) map.get(platformname);
1599+
1600+
//What if null or defaults to nonexisent platform
1601+
System.out.println("PlatformName: " + platformname);
1602+
if (map == null)
1603+
{
1604+
System.err.println("Error loading platforms preference from Target");
1605+
System.exit(0);
1606+
}
1607+
1608+
return map;
15831609
}
15841610

1585-
static public Map<String, String> getBoardPreferences() {
1611+
static public Map<String, String> bogusgetBoardPreferences() {
1612+
System.out.println("getBoardPrefences method: start");
15861613
Target target = getTarget();
1587-
if (target == null) return new LinkedHashMap();
1614+
if (target == null) {
1615+
System.out.println("getBoardPrefereces method: target == null");
1616+
return new LinkedHashMap();
1617+
}
15881618
Map map = target.getBoards();
1589-
if (map == null) return new LinkedHashMap();
1619+
if (map == null) {
1620+
System.out.println("getBoardPrefereces method: target.getBoards() == null");
1621+
return new LinkedHashMap();
1622+
}
15901623
map = (Map) map.get(Preferences.get("board"));
1591-
if (map == null) return new LinkedHashMap();
1624+
if (map == null) {
1625+
System.out.println("getBoardPrefereces method: Preferences.get(board) == null");
1626+
return new LinkedHashMap();
1627+
}
1628+
//Debug iterate the map
1629+
Iterator iterator = map.entrySet().iterator();
1630+
while(iterator.hasNext())
1631+
{
1632+
Map.Entry pair = (Map.Entry)iterator.next();
1633+
if (pair.getValue() == null)
1634+
{
1635+
System.out.println("KeyName: " + pair.getKey() + " val: null");
1636+
}
1637+
else
1638+
{
1639+
System.out.println("KeyName: " + pair.getKey() + " val" + pair.getValue());
1640+
}
1641+
}
1642+
15921643
return map;
15931644
}
1594-
1645+
1646+
static public Map<String, String> getBoardPreferences() {
1647+
Target target = getTarget();
1648+
Map map = new LinkedHashMap();
1649+
if (target != null) {
1650+
map = target.getBoards();
1651+
map = (Map) map.get(Preferences.get("board"));
1652+
}
1653+
return map;
1654+
}
15951655

15961656
static public File getSketchbookFolder() {
15971657
return new File(Preferences.get("sketchbook.path"));

app/src/processing/app/Sketch.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1331,10 +1331,9 @@ public String preprocess(String buildPath, PdePreprocessor preprocessor) throws
13311331
//Remember to clear library path before building it.
13321332
libraryPath = "";
13331333
for (String item : preprocessor.getExtraImports()) {
1334-
File libFolder = (File) Base.importToLibraryTable.get(item);
13351334

13361335
File libFolder = (File) Base.importToLibraryTable.get(item);
1337-
//Debug libraryPath
1336+
//If needed can Debug libraryPath here
13381337

13391338
if (libFolder != null && !importedLibraries.contains(libFolder)) {
13401339
importedLibraries.add(libFolder);

app/src/processing/app/debug/Target.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class Target {
3939
private Map platforms;
4040

4141
public Target(String name, File folder) {
42+
System.out.println("Target: constructor start, name: " + name);
4243
this.name = name;
4344
this.folder = folder;
4445
this.boards = new LinkedHashMap();
@@ -61,6 +62,7 @@ public Target(String name, File folder) {
6162
}
6263
} catch (Exception e) {
6364
System.err.println("Error loading boards from " + boardsFile + ": " + e);
65+
6466
}
6567

6668
File platformsFile = new File(folder,"platforms.txt");
@@ -80,7 +82,7 @@ public Target(String name, File folder) {
8082
} catch (Exception e) {
8183
System.err.println("Error loading platforms from " +
8284
platformsFile + ": " + e);
83-
// System.exit(0);
85+
System.exit(0);
8486

8587
}
8688

0 commit comments

Comments
 (0)