From 3b574622817ed6b9ed84b7e7744d44e713965040 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 2 Aug 2016 14:11:12 +0200 Subject: [PATCH] Use latest tools version for generic tool.paths properties --- arduino-core/src/processing/app/BaseNoGui.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index bfe808332..027c60a84 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -5,6 +5,7 @@ import cc.arduino.Constants; import cc.arduino.UploaderUtils; import cc.arduino.contributions.GPGDetachedSignatureVerifier; import cc.arduino.contributions.SignatureVerificationFailedException; +import cc.arduino.contributions.VersionComparator; import cc.arduino.contributions.libraries.LibrariesIndexer; import cc.arduino.contributions.packages.ContributedPlatform; import cc.arduino.contributions.packages.ContributedTool; @@ -866,6 +867,8 @@ public class BaseNoGui { PreferencesData.removeAllKeysWithPrefix(prefix); } + Map latestVersions = new HashMap<>(); + VersionComparator comparator = new VersionComparator(); for (ContributedTool tool : installedTools) { File installedFolder = tool.getDownloadableContribution(getPlatform()).getInstalledFolder(); String toolPath; @@ -874,10 +877,15 @@ public class BaseNoGui { } else { toolPath = Constants.PREF_REMOVE_PLACEHOLDER; } - PreferencesData.set(prefix + tool.getName() + ".path", toolPath); - PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", toolPath); - PreferencesData.set(prefix + tool.getPackager() + "-" + tool.getName() + "-" + tool.getVersion() + ".path", - toolPath); + String toolName = tool.getName(); + String toolVersion = tool.getVersion(); + PreferencesData.set(prefix + toolName + "-" + toolVersion + ".path", toolPath); + PreferencesData.set(prefix + tool.getPackager() + "-" + toolName + "-" + toolVersion + ".path", toolPath); + // In the generic tool property put the path of the latest version if more are available + if (!latestVersions.containsKey(toolName) || comparator.greaterThan(toolVersion, latestVersions.get(toolName))) { + latestVersions.put(toolName, toolVersion); + PreferencesData.set(prefix + toolName + ".path", toolPath); + } } }