From 4443911746bfa4781bcc7b0c4f2b57cf73d28360 Mon Sep 17 00:00:00 2001 From: Claudio Indellicati Date: Thu, 21 Aug 2014 13:38:28 +0200 Subject: [PATCH] Moved getBoardPreferences() and related methods from Base to BaseNoGui (work in progress). --- app/src/processing/app/Base.java | 15 +------------- app/src/processing/app/BaseNoGui.java | 24 ++++++++++++++++++++++ app/src/processing/app/debug/Compiler.java | 10 ++++----- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 20e14edee..7ac04de10 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -2091,20 +2091,7 @@ public class Base { } static public PreferencesMap getBoardPreferences() { - TargetBoard board = getTargetBoard(); - - PreferencesMap prefs = new PreferencesMap(board.getPreferences()); - for (String menuId : board.getMenuIds()) { - String entry = Preferences.get("custom_" + menuId); - if (board.hasMenu(menuId) && entry != null && - entry.startsWith(board.getId())) { - String selectionId = entry.substring(entry.indexOf("_") + 1); - prefs.putAll(board.getMenuPreferences(menuId, selectionId)); - prefs.put("name", prefs.get("name") + ", " + - board.getMenuLabel(menuId, selectionId)); - } - } - return prefs; + return BaseNoGui.getBoardPreferences(); } public static TargetBoard getTargetBoard() { diff --git a/app/src/processing/app/BaseNoGui.java b/app/src/processing/app/BaseNoGui.java index fa4326641..7d6891928 100644 --- a/app/src/processing/app/BaseNoGui.java +++ b/app/src/processing/app/BaseNoGui.java @@ -7,10 +7,12 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import processing.app.debug.TargetBoard; import processing.app.debug.TargetPackage; import processing.app.debug.TargetPlatform; import processing.app.debug.TargetPlatformException; import processing.app.helpers.OSUtils; +import processing.app.helpers.PreferencesMap; import processing.app.helpers.filefilters.OnlyDirs; public class BaseNoGui { @@ -54,6 +56,23 @@ public class BaseNoGui { return path; } + static public PreferencesMap getBoardPreferences() { + TargetBoard board = getTargetBoard(); + + PreferencesMap prefs = new PreferencesMap(board.getPreferences()); + for (String menuId : board.getMenuIds()) { + String entry = Preferences.get("custom_" + menuId); + if (board.hasMenu(menuId) && entry != null && + entry.startsWith(board.getId())) { + String selectionId = entry.substring(entry.indexOf("_") + 1); + prefs.putAll(board.getMenuPreferences(menuId, selectionId)); + prefs.put("name", prefs.get("name") + ", " + + board.getMenuLabel(menuId, selectionId)); + } + } + return prefs; + } + static public File getContentFile(String name) { String path = System.getProperty("user.dir"); @@ -99,6 +118,11 @@ public class BaseNoGui { return new File(getSketchbookFolder(), "hardware"); } + public static TargetBoard getTargetBoard() { + String boardId = Preferences.get("board"); + return getTargetPlatform().getBoard(boardId); + } + /** * Returns the currently selected TargetPlatform. * diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index 32848ed0c..258a37750 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -178,7 +178,7 @@ public class Compiler implements MessageConsumer { String _primaryClassName) throws RunnerException { - if (Base.getBoardPreferences() == null) { + if (BaseNoGui.getBoardPreferences() == null) { RunnerException re = new RunnerException( _("No board selected; please choose a board from the Tools > Board menu.")); re.hideStackTrace(); @@ -188,12 +188,12 @@ public class Compiler implements MessageConsumer { // Check if the board needs a platform from another package TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform(); TargetPlatform corePlatform = null; - PreferencesMap boardPreferences = Base.getBoardPreferences(); + PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences(); String core = boardPreferences.get("build.core"); if (core.contains(":")) { String[] split = core.split(":"); core = split[1]; - corePlatform = Base.getTargetPlatform(split[0], targetPlatform.getId()); + corePlatform = BaseNoGui.getTargetPlatform(split[0], targetPlatform.getId()); if (corePlatform == null) { RunnerException re = new RunnerException(I18n .format(_("Selected board depends on '{0}' core (not installed)."), @@ -209,7 +209,7 @@ public class Compiler implements MessageConsumer { if (corePlatform != null) p.putAll(corePlatform.getPreferences()); p.putAll(targetPlatform.getPreferences()); - p.putAll(Base.getBoardPreferences()); + p.putAll(BaseNoGui.getBoardPreferences()); for (String k : p.keySet()) { if (p.get(k) == null) p.put(k, ""); @@ -250,7 +250,7 @@ public class Compiler implements MessageConsumer { t = targetPlatform; } else { String[] split = variant.split(":", 2); - t = Base.getTargetPlatform(split[0], targetPlatform.getId()); + t = BaseNoGui.getTargetPlatform(split[0], targetPlatform.getId()); variant = split[1]; } File variantFolder = new File(t.getFolder(), "variants");