From d2505a08f681aa8915b2ee668eff05b5d799a605 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Mon, 14 Apr 2014 15:12:32 +0200 Subject: [PATCH 1/2] Process platform-specific suffixes immediately In preferences files, platform-specific versions can be indicated by a .linux, .windows or .macos suffix on the key name. Previously, these keys were loaded as normal and then afterwards, all keys were scanned after loading them and any platform-specific versions replaced the regular ones. However, this means that these platform-specific versions get an unexpected form of priority. Normally, when a single key is set twice, the latter overrides the first. However, the platform-specific values could override the regular versions, even when the regular version occurs later in the file. This problem was particularly confusing when using the new platform.local.txt: a regular preference in platform.local.txt did not override a platform-specific preference in platform.txt. This commit changes behaviour to process these suffixes directly as they are read from the preference files. If a suffix for the current platform is found, the line is processed as if the suffix was not present. If a suffix for another platform is found, the line is ignored altogether. This can slightly change the way preferences files are parsed, but as long as platform-specific preferences are defined after the corresponding regular preferences, the behaviour should be the same. --- .../app/helpers/PreferencesMap.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/app/src/processing/app/helpers/PreferencesMap.java b/app/src/processing/app/helpers/PreferencesMap.java index 39c6f394f..de6bf78b1 100644 --- a/app/src/processing/app/helpers/PreferencesMap.java +++ b/app/src/processing/app/helpers/PreferencesMap.java @@ -77,6 +77,19 @@ public class PreferencesMap extends LinkedHashMap { load(new FileInputStream(file)); } + protected String processPlatformSuffix(String key, String suffix, boolean isCurrentPlatform) { + if (key == null) + return null; + // Key does not end with the given suffix? Process as normal + if (!key.endsWith(suffix)) + return key; + // Not the current platform? Ignore this key + if (!isCurrentPlatform) + return null; + // Strip the suffix from the key + return key.substring(0, key.length() - suffix.length()); + } + /** * Parse a property list stream and put key/value pairs into the Map * @@ -91,28 +104,15 @@ public class PreferencesMap extends LinkedHashMap { int equals = line.indexOf('='); if (equals != -1) { - String key = line.substring(0, equals); - String value = line.substring(equals + 1); - put(key.trim(), value.trim()); - } - } + String key = line.substring(0, equals).trim(); + String value = line.substring(equals + 1).trim(); - // This is needed to avoid ConcurrentAccessExceptions - Set keys = new LinkedHashSet(keySet()); + key = processPlatformSuffix(key, ".linux", Base.isLinux()); + key = processPlatformSuffix(key, ".windows", Base.isWindows()); + key = processPlatformSuffix(key, ".macos", Base.isMacOS()); - // Override keys that have OS specific versions - for (String key : keys) { - boolean replace = false; - if (Base.isLinux() && key.endsWith(".linux")) - replace = true; - if (Base.isWindows() && key.endsWith(".windows")) - replace = true; - if (Base.isMacOS() && key.endsWith(".macos")) - replace = true; - if (replace) { - int dot = key.lastIndexOf('.'); - String overridenKey = key.substring(0, dot); - put(overridenKey, get(key)); + if (key != null) + put(key, value); } } } From aa46fdb978606345b026f8ce373fcb6d559150d3 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Mon, 14 Apr 2014 15:29:54 +0200 Subject: [PATCH 2/2] Change the MacOS preference suffix to .macosx Previously, preferences suffixed with .macos were treated specially, but the default preferences.txt used .macosx. I couldn't find when or how this was broken exactly - it seems Processing used .macosx but this code was reimplemented for Arduino in commit 33f5c53 (Implemented OS specific preferences) using .macos. The effects of this have not been tested on OSX, but this might fix some problems caused by wrong defaults on OSX. --- app/src/processing/app/helpers/PreferencesMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/processing/app/helpers/PreferencesMap.java b/app/src/processing/app/helpers/PreferencesMap.java index de6bf78b1..b4f60848a 100644 --- a/app/src/processing/app/helpers/PreferencesMap.java +++ b/app/src/processing/app/helpers/PreferencesMap.java @@ -109,7 +109,7 @@ public class PreferencesMap extends LinkedHashMap { key = processPlatformSuffix(key, ".linux", Base.isLinux()); key = processPlatformSuffix(key, ".windows", Base.isWindows()); - key = processPlatformSuffix(key, ".macos", Base.isMacOS()); + key = processPlatformSuffix(key, ".macosx", Base.isMacOS()); if (key != null) put(key, value);