Skip to content

Commit 28ab910

Browse files
committed
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.
1 parent 94ef1f8 commit 28ab910

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndex.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,20 @@ public boolean resolveDependeciesOf(List<ContributedLibrary> solution,
138138
continue;
139139
}
140140

141-
// Pick the latest version among possible deps
142-
ContributedLibrary last = possibleDeps.stream()
143-
.reduce((a, b) -> b.isBefore(a) ? a : b).get();
141+
// Pick the installed version if available
142+
ContributedLibrary selected;
143+
Optional<ContributedLibrary> installed = possibleDeps.stream()
144+
.filter(l -> l.getInstalledLibrary().isPresent()).findAny();
145+
if (installed.isPresent()) {
146+
selected = installed.get();
147+
} else {
148+
// otherwise pick the latest version
149+
selected = possibleDeps.stream().reduce((a, b) -> b.isBefore(a) ? a : b).get();
150+
}
144151

145-
// Add dependecy to the solution and process recursively
146-
solution.add(last);
147-
if (!resolveDependeciesOf(solution, last)) {
152+
// Add dependency to the solution and process recursively
153+
solution.add(selected);
154+
if (!resolveDependeciesOf(solution, selected)) {
148155
return false;
149156
}
150157
}

0 commit comments

Comments
 (0)