|
5 | 5 | import cc.arduino.UploaderUtils;
|
6 | 6 | import cc.arduino.contributions.GPGDetachedSignatureVerifier;
|
7 | 7 | import cc.arduino.contributions.SignatureVerificationFailedException;
|
| 8 | +import cc.arduino.contributions.VersionComparator; |
8 | 9 | import cc.arduino.contributions.libraries.LibrariesIndexer;
|
| 10 | +import cc.arduino.contributions.packages.ContributedPlatform; |
9 | 11 | import cc.arduino.contributions.packages.ContributedTool;
|
10 | 12 | import cc.arduino.contributions.packages.ContributionsIndexer;
|
11 | 13 | import cc.arduino.files.DeleteFilesOnShutdown;
|
@@ -160,6 +162,33 @@ static public PreferencesMap getBoardPreferences() {
|
160 | 162 | }
|
161 | 163 | }
|
162 | 164 | prefs.put("name", extendedName);
|
| 165 | + |
| 166 | + // Resolve tools needed for this board |
| 167 | + List<ContributedTool> requiredTools = new ArrayList<>(); |
| 168 | + |
| 169 | + // Add all tools dependencies specified in package index |
| 170 | + ContributedPlatform platform = indexer.getContributedPlaform(getTargetPlatform()); |
| 171 | + if (platform != null) |
| 172 | + requiredTools.addAll(platform.getResolvedTools()); |
| 173 | + |
| 174 | + // Add all tools dependencies from the (possibily) referenced core |
| 175 | + String core = prefs.get("build.core"); |
| 176 | + if (core.contains(":")) { |
| 177 | + String split[] = core.split(":"); |
| 178 | + TargetPlatform referenced = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]); |
| 179 | + ContributedPlatform referencedPlatform = indexer.getContributedPlaform(referenced); |
| 180 | + if (referencedPlatform != null) |
| 181 | + requiredTools.addAll(referencedPlatform.getResolvedTools()); |
| 182 | + } |
| 183 | + |
| 184 | + String prefix = "runtime.tools."; |
| 185 | + for (ContributedTool tool : requiredTools) { |
| 186 | + File folder = tool.getDownloadableContribution(getPlatform()).getInstalledFolder(); |
| 187 | + String toolPath = folder.getAbsolutePath(); |
| 188 | + prefs.put(prefix + tool.getName() + ".path", toolPath); |
| 189 | + PreferencesData.set(prefix + tool.getName() + ".path", toolPath); |
| 190 | + PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", toolPath); |
| 191 | + } |
163 | 192 | return prefs;
|
164 | 193 | }
|
165 | 194 |
|
@@ -852,16 +881,25 @@ public static void createToolPreferences(Collection<ContributedTool> installedTo
|
852 | 881 | PreferencesData.removeAllKeysWithPrefix(prefix);
|
853 | 882 | }
|
854 | 883 |
|
| 884 | + Map<String, String> latestVersions = new HashMap<>(); |
| 885 | + VersionComparator comparator = new VersionComparator(); |
855 | 886 | for (ContributedTool tool : installedTools) {
|
856 | 887 | File installedFolder = tool.getDownloadableContribution(getPlatform()).getInstalledFolder();
|
857 |
| - String absolutePath; |
| 888 | + String toolPath; |
858 | 889 | if (installedFolder != null) {
|
859 |
| - absolutePath = installedFolder.getAbsolutePath(); |
| 890 | + toolPath = installedFolder.getAbsolutePath(); |
860 | 891 | } else {
|
861 |
| - absolutePath = Constants.PREF_REMOVE_PLACEHOLDER; |
| 892 | + toolPath = Constants.PREF_REMOVE_PLACEHOLDER; |
| 893 | + } |
| 894 | + String toolName = tool.getName(); |
| 895 | + String toolVersion = tool.getVersion(); |
| 896 | + PreferencesData.set(prefix + toolName + "-" + toolVersion + ".path", toolPath); |
| 897 | + PreferencesData.set(prefix + tool.getPackager() + "-" + toolName + "-" + toolVersion + ".path", toolPath); |
| 898 | + // In the generic tool property put the path of the latest version if more are available |
| 899 | + if (!latestVersions.containsKey(toolName) || comparator.greaterThan(toolVersion, latestVersions.get(toolName))) { |
| 900 | + latestVersions.put(toolName, toolVersion); |
| 901 | + PreferencesData.set(prefix + toolName + ".path", toolPath); |
862 | 902 | }
|
863 |
| - PreferencesData.set(prefix + tool.getName() + ".path", absolutePath); |
864 |
| - PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", absolutePath); |
865 | 903 | }
|
866 | 904 | }
|
867 | 905 |
|
|
0 commit comments