From 492553cde0cdfd4d26f4244b682f5dd9f62f322f Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 20 Feb 2017 13:41:25 +0100 Subject: [PATCH] When resolving dependencies consider installed contributions first Consider a case where the user decides to install a library `A` that depends on library `B` and `B` is not up-to-date (i.e. is installed a version that is not the latest), then the user is asked to "install" both libraries `A` and `B`, effectively upgrading `B`. With this change the already installed library `B` is left untouched and not displayed in the missing dependencies. --- .../libraries/LibrariesIndex.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndex.java b/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndex.java index 8c15a95c9..b42a6afb7 100644 --- a/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndex.java +++ b/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndex.java @@ -138,13 +138,20 @@ public abstract class LibrariesIndex { continue; } - // Pick the latest version among possible deps - ContributedLibrary last = possibleDeps.stream() - .reduce((a, b) -> b.isBefore(a) ? a : b).get(); + // Pick the installed version if available + ContributedLibrary selected; + Optional installed = possibleDeps.stream() + .filter(l -> l.getInstalledLibrary().isPresent()).findAny(); + if (installed.isPresent()) { + selected = installed.get(); + } else { + // otherwise pick the latest version + selected = possibleDeps.stream().reduce((a, b) -> b.isBefore(a) ? a : b).get(); + } - // Add dependecy to the solution and process recursively - solution.add(last); - if (!resolveDependeciesOf(solution, last)) { + // Add dependency to the solution and process recursively + solution.add(selected); + if (!resolveDependeciesOf(solution, selected)) { return false; } }