diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index b8e6fc03c..11cd52e28 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -959,7 +959,7 @@ public class Base { //Choose which library to add by chip platform try { - //Find the current target. Get the platform, and then select the correct name and core path. + //Find the current target. Get the platform, and then select the correct name and core path. String platformname = this.getBoardPreferences().get("platform"); String targetname = this.getPlatformPreferences(platformname).get("name"); String libraryPath = this.getPlatformPreferences(platformname).get("library.core.path"); @@ -1553,11 +1553,20 @@ public class Base { static public Target getTarget() { - return Base.targetsTable.get(Preferences.get("target")); + System.out.println("Base.targetsTable.get(Preferences.get(\"target\"))" + Base.targetsTable.get(Preferences.get("target"))); + System.out.println("Preferences.get(\"target\")" + Preferences.get("target")); + Target target = Base.targetsTable.get(Preferences.get("target")); + if (target == null) { + System.out.println("default target is not in list. Replace with default."); + Preferences.set("target", "arduino"); + target = Base.targetsTable.get(Preferences.get("target")); + } + return target; } static public Map getPlatformPreferences() { + System.out.println("getPlatformPreferences() no arguments: start"); Target target = getTarget(); //if (target == null) return new LinkedHashMap(); Map map = target.getPlatforms(); @@ -1576,22 +1585,73 @@ static public Map getPlatformPreferences() { //Get a specific platform static public Map getPlatformPreferences(String platformname) { + if (platformname == null) { + platformname = Preferences.get("platform"); + + } + System.out.println("getlatformPreferences(String platformname)): start: platformname = " + platformname ); Target target = getTarget(); - Map map = target.getPlatforms(); - map = (Map) map.get(platformname); + if (target == null ) { + System.out.println("get target is null. trouble! "); + } + Map map = target.getPlatforms(); + map = (Map) map.get(platformname); + + //What if null or defaults to nonexisent platform + System.out.println("PlatformName: " + platformname); + if (map == null) + { + System.err.println("Error loading platforms preference from Target"); + System.exit(0); + } + + return map; + } + + static public Map bogusgetBoardPreferences() { + System.out.println("getBoardPrefences method: start"); + Target target = getTarget(); + if (target == null) { + System.out.println("getBoardPrefereces method: target == null"); + return new LinkedHashMap(); + } + Map map = target.getBoards(); + if (map == null) { + System.out.println("getBoardPrefereces method: target.getBoards() == null"); + return new LinkedHashMap(); + } + map = (Map) map.get(Preferences.get("board")); + if (map == null) { + System.out.println("getBoardPrefereces method: Preferences.get(board) == null"); + return new LinkedHashMap(); + } + //Debug iterate the map + Iterator iterator = map.entrySet().iterator(); + while(iterator.hasNext()) + { + Map.Entry pair = (Map.Entry)iterator.next(); + if (pair.getValue() == null) + { + System.out.println("KeyName: " + pair.getKey() + " val: null"); + } + else + { + System.out.println("KeyName: " + pair.getKey() + " val" + pair.getValue()); + } + } + return map; } - static public Map getBoardPreferences() { +static public Map getBoardPreferences() { Target target = getTarget(); - if (target == null) return new LinkedHashMap(); - Map map = target.getBoards(); - if (map == null) return new LinkedHashMap(); - map = (Map) map.get(Preferences.get("board")); - if (map == null) return new LinkedHashMap(); + Map map = new LinkedHashMap(); + if (target != null) { + map = target.getBoards(); + map = (Map) map.get(Preferences.get("board")); + } return map; - } - + } static public File getSketchbookFolder() { return new File(Preferences.get("sketchbook.path")); diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index f2c919d94..499b655a9 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -1331,10 +1331,9 @@ public class Sketch { //Remember to clear library path before building it. libraryPath = ""; for (String item : preprocessor.getExtraImports()) { - File libFolder = (File) Base.importToLibraryTable.get(item); File libFolder = (File) Base.importToLibraryTable.get(item); - //Debug libraryPath + //If needed can Debug libraryPath here if (libFolder != null && !importedLibraries.contains(libFolder)) { importedLibraries.add(libFolder); diff --git a/app/src/processing/app/debug/Target.java b/app/src/processing/app/debug/Target.java index c515d2cf3..649c2827a 100644 --- a/app/src/processing/app/debug/Target.java +++ b/app/src/processing/app/debug/Target.java @@ -39,6 +39,7 @@ public class Target { private Map platforms; public Target(String name, File folder) { + System.out.println("Target: constructor start, name: " + name); this.name = name; this.folder = folder; this.boards = new LinkedHashMap(); @@ -61,6 +62,7 @@ public class Target { } } catch (Exception e) { System.err.println("Error loading boards from " + boardsFile + ": " + e); + } File platformsFile = new File(folder,"platforms.txt"); @@ -80,7 +82,7 @@ public class Target { } catch (Exception e) { System.err.println("Error loading platforms from " + platformsFile + ": " + e); - // System.exit(0); + System.exit(0); }