diff --git a/arduino-core/src/cc/arduino/packages/contributions/ContributedTargetPlatform.java b/arduino-core/src/cc/arduino/packages/contributions/ContributedTargetPlatform.java index abd9dd3dc..c102ea2aa 100644 --- a/arduino-core/src/cc/arduino/packages/contributions/ContributedTargetPlatform.java +++ b/arduino-core/src/cc/arduino/packages/contributions/ContributedTargetPlatform.java @@ -28,16 +28,11 @@ */ package cc.arduino.packages.contributions; -import static processing.app.I18n._; -import static processing.app.I18n.format; - import java.io.File; -import java.util.Set; import processing.app.debug.LegacyTargetPlatform; import processing.app.debug.TargetPackage; import processing.app.debug.TargetPlatformException; -import processing.app.helpers.PreferencesMap; public class ContributedTargetPlatform extends LegacyTargetPlatform { @@ -46,35 +41,5 @@ public class ContributedTargetPlatform extends LegacyTargetPlatform { ContributionsIndex index) throws TargetPlatformException { super(_name, _folder, parent); - - // Populate tools - PreferencesMap toolsPrefs = preferences.subTree("tools"); - Set names = toolsPrefs.firstLevelMap().keySet(); - for (String name : names) { - String version = toolsPrefs.get(name + ".version"); - if (version == null) { - throw new TargetPlatformException( - format(_("Tool {0} must define a version property ({1})"), // - name, "tools." + name + ".version")); - } - - String packageName = getContainerPackage().getId(); - ContributedTool tool = index.findTool(packageName, name, version); - if (tool == null) { - throw new TargetPlatformException( - format(_("Tool {0} not found in package {1}"), - name + ":" + version, packageName)); - } - - DownloadableContribution download = tool.getDownloadableContribution(); - if (!download.isInstalled()) { - throw new TargetPlatformException( - format(_("Tool {0} is required but it's not installed."), // - name + ":" + version)); - } - preferences.put("tools." + name + ".path", // - download.getInstalledFolder().getAbsolutePath()); - } - } } diff --git a/arduino-core/src/cc/arduino/packages/contributions/ContributionsIndexer.java b/arduino-core/src/cc/arduino/packages/contributions/ContributionsIndexer.java index b744d49ec..c9265e538 100644 --- a/arduino-core/src/cc/arduino/packages/contributions/ContributionsIndexer.java +++ b/arduino-core/src/cc/arduino/packages/contributions/ContributionsIndexer.java @@ -35,7 +35,9 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import processing.app.debug.TargetPackage; import processing.app.debug.TargetPlatform; @@ -221,6 +223,20 @@ public class ContributionsIndexer { return false; } + public Set getInstalledTools() { + Set tools = new HashSet(); + for (ContributedPackage pack : index.getPackages()) { + for (ContributedPlatform platform : pack.getPlatforms()) { + if (!platform.isInstalled()) + continue; + for (ContributedTool tool : platform.getResolvedTools()) { + tools.add(tool); + } + } + } + return tools; + } + public ContributionsIndex getIndex() { return index; } diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index 51b4396ff..36c0a90ef 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -19,8 +19,8 @@ import org.apache.commons.logging.impl.NoOpLog; import cc.arduino.packages.DiscoveryManager; import cc.arduino.packages.Uploader; import processing.app.debug.Compiler; - import cc.arduino.libraries.contributions.LibrariesIndexer; +import cc.arduino.packages.contributions.ContributedTool; import cc.arduino.packages.contributions.ContributionsIndexer; import cc.arduino.utils.ArchiveExtractor; import processing.app.debug.TargetBoard; @@ -618,6 +618,7 @@ public class BaseNoGui { loadHardware(getHardwareFolder()); loadHardware(getSketchbookHardwareFolder()); loadContributedHardware(indexer); + createToolPreferences(indexer); librariesIndexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder()); File librariesIndexFile = librariesIndexer.getIndexFile(); @@ -771,6 +772,21 @@ public class BaseNoGui { } } + static private void createToolPreferences(ContributionsIndexer indexer) { + // Remove previous runtime preferences + final String prefix = "runtime.tools."; + PreferencesData.removeAllKeysWithPrefix(prefix); + + for (ContributedTool tool : indexer.getInstalledTools()) { + String path = tool.getDownloadableContribution().getInstalledFolder() + .getAbsolutePath(); + String toolId = tool.getName(); + PreferencesData.set(prefix + toolId + ".path", path); + toolId += "-" + tool.getVersion(); + PreferencesData.set(prefix + toolId + ".path", path); + } + } + static public void populateImportToLibraryTable() { // Populate importToLibraryTable importToLibraryTable = new HashMap(); diff --git a/arduino-core/src/processing/app/PreferencesData.java b/arduino-core/src/processing/app/PreferencesData.java index 94cc187c8..1052b380a 100644 --- a/arduino-core/src/processing/app/PreferencesData.java +++ b/arduino-core/src/processing/app/PreferencesData.java @@ -9,6 +9,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; +import java.util.Iterator; import java.util.MissingResourceException; import processing.app.helpers.PreferencesMap; @@ -205,6 +206,13 @@ public class PreferencesData { return new PreferencesMap(prefs); } + static public void removeAllKeysWithPrefix(String prefix) { + Iterator keys = prefs.keySet().iterator(); + while (keys.hasNext()) + if (keys.next().startsWith(prefix)) + keys.remove(); + } + // Decide wether changed preferences will be saved. When value is // false, Preferences.save becomes a no-op. static public void setDoSave(boolean value)