Skip to content

Commit

Permalink
When resolving dependencies consider installed contributions first
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cmaglie authored and facchinm committed Jul 18, 2019
1 parent ed81292 commit 492553c
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,20 @@ public boolean resolveDependeciesOf(List<ContributedLibrary> solution,
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<ContributedLibrary> 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;
}
}
Expand Down

0 comments on commit 492553c

Please sign in to comment.