diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/HierarchicalProperties.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/HierarchicalProperties.java index 54508295031..565d8405958 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/HierarchicalProperties.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/HierarchicalProperties.java @@ -22,11 +22,24 @@ public class HierarchicalProperties { private String value; private Map children; + private String platName; public HierarchicalProperties() { + switch (Platform.getOS()) { + case Platform.OS_WIN32: + platName = "windows"; //$NON-NLS-1$ + break; + case Platform.OS_MACOSX: + platName = "macosx"; //$NON-NLS-1$ + break; + case Platform.OS_LINUX: + platName = "linux"; //$NON-NLS-1$ + break; + } } public HierarchicalProperties(LinkedProperties properties) { + this(); for (Object keyObj : properties.orderedKeys()) { String key = (String) keyObj; String value = (String) properties.get(key); @@ -81,25 +94,15 @@ public class HierarchicalProperties { } public String getValue() { - if (value == null) { - // Try a platform child - String platName = null; - switch (Platform.getOS()) { - case Platform.OS_WIN32: - platName = "windows"; //$NON-NLS-1$ - break; - case Platform.OS_MACOSX: - platName = "macosx"; //$NON-NLS-1$ - break; - case Platform.OS_LINUX: - platName = "linux"; //$NON-NLS-1$ - break; - } - if (platName != null) { - HierarchicalProperties platChild = getChild(platName); - if (platChild != null) { - return platChild.getValue(); - } + // Try a platform child + if (platName != null && hasChild(platName)) { + HierarchicalProperties child = getChild(platName); + + // return the child's value if + // - it has a property + // - it has no more children. In that case the value could even be null (specifically overridden) + if ((null != child.getValue()) || (!child.hasChildren())) { + return child.getValue(); } } return value; @@ -113,6 +116,14 @@ public class HierarchicalProperties { return children; } + private boolean hasChildren() { + return (children != null && children.size() > 0); + } + + private boolean hasChild(String key) { + return (children != null && children.containsKey(key)); + } + public HierarchicalProperties getChild(String key) { return children != null ? children.get(key) : null; } @@ -180,5 +191,4 @@ public class HierarchicalProperties { } } } - } diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoPlatform.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoPlatform.java index af2bf642a48..c0a5bccc966 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoPlatform.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoPlatform.java @@ -58,7 +58,7 @@ public class ArduinoPlatform { private Path installPath; private ArduinoPackage pkg; private HierarchicalProperties boardsProperties; - private LinkedProperties platformProperties; + private HierarchicalProperties platformProperties; private HierarchicalProperties programmerProperties; private Map menus = new HashMap<>(); private Map libraries; @@ -109,7 +109,7 @@ public class ArduinoPlatform { return size; } - public void setPlatformProperties(LinkedProperties platformProperties) { + public void setPlatformProperties(HierarchicalProperties platformProperties) { this.platformProperties = platformProperties; } @@ -187,9 +187,9 @@ public class ArduinoPlatform { return null; } - public LinkedProperties getPlatformProperties() throws CoreException { + public HierarchicalProperties getPlatformProperties() throws CoreException { if (platformProperties == null) { - platformProperties = new LinkedProperties(); + LinkedProperties rawPlatformProps = new LinkedProperties(); try (BufferedReader reader = new BufferedReader( new FileReader(getInstallPath().resolve("platform.txt").toFile()))) { //$NON-NLS-1$ // There are regex's here and need to preserve the \'s @@ -199,11 +199,12 @@ public class ArduinoPlatform { buffer.append('\n'); } try (Reader reader1 = new StringReader(buffer.toString())) { - platformProperties.load(reader1); + rawPlatformProps.load(reader1); } } catch (IOException e) { throw Activator.coreException(e); } + platformProperties = new HierarchicalProperties(rawPlatformProps); } return platformProperties; } diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfiguration.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfiguration.java index 38441826f54..62d0ccaa47e 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfiguration.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfiguration.java @@ -187,13 +187,13 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration ArduinoPlatform superPlatform = manager.getInstalledPlatform(segments[0], platform.getArchitecture()); if (superPlatform != null) { - boardProperties.putAll(superPlatform.getPlatformProperties()); + boardProperties.putAll(superPlatform.getPlatformProperties().flatten()); } } } // Platform - boardProperties.putAll(platform.getPlatformProperties()); + boardProperties.putAll(platform.getPlatformProperties().flatten()); // Tools for (ToolDependency toolDep : platform.getToolsDependencies()) { @@ -520,8 +520,7 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration properties.put("config.path", "{tools." + toolName + ".config.path}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ // properties for the tool flattened - HierarchicalProperties toolsProps = new HierarchicalProperties(platform.getPlatformProperties()) - .getChild("tools"); //$NON-NLS-1$ + HierarchicalProperties toolsProps = platform.getPlatformProperties().getChild("tools"); //$NON-NLS-1$ if (toolsProps != null) { HierarchicalProperties toolProps = toolsProps.getChild(toolName); if (toolProps != null) {