Skip to content

Commit

Permalink
[TP] Ensure the latest matching IU is queried when caching artifacts
Browse files Browse the repository at this point in the history
Currently when caching IUs it's not ensured that the latest version
matching the declaration is selected. This could have the consequence
that for a '0.0.0'-version not the latest version of an IU is selected,
if multiple versions are in the profile/container.
  • Loading branch information
HannesWell committed Oct 13, 2024
1 parent 7479498 commit 2d6fc0c
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ private void cacheIUs() throws CoreException {
List<IInstallableUnit> result = new ArrayList<>();
MultiStatus status = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.IUBundleContainer_ProblemsLoadingRepositories);
for (IVersionedId unit : fIUs) {
IQuery<IInstallableUnit> query = QueryUtil.createIUQuery(unit);
addQueryResult(profile, query, unit, result, status);
queryIU(profile, unit, status).ifPresent(result::add);
}
if (!status.isOK()) {
fResolutionStatus = status;
Expand Down Expand Up @@ -687,9 +686,7 @@ Collection<IInstallableUnit> getRootIUs(IProgressMonitor monitor) throws CoreExc
MultiStatus status = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.IUBundleContainer_ProblemsLoadingRepositories);
List<IInstallableUnit> result = new ArrayList<>();
for (IVersionedId iu : fIUs) {
// For versions such as 0.0.0, the IU query may return multiple IUs, so we check which is the latest version
IQuery<IInstallableUnit> query = QueryUtil.createLatestQuery(QueryUtil.createIUQuery(iu));
addQueryResult(repos, query, iu, result, status);
queryIU(repos, iu, status).ifPresent(result::add);
}
if (!status.isOK()) {
fResolutionStatus = status;
Expand All @@ -698,14 +695,16 @@ Collection<IInstallableUnit> getRootIUs(IProgressMonitor monitor) throws CoreExc
return result;
}

private void addQueryResult(IQueryable<IInstallableUnit> queryable, IQuery<IInstallableUnit> query, IVersionedId iu,
List<IInstallableUnit> result, MultiStatus status) {
private Optional<IInstallableUnit> queryIU(IQueryable<IInstallableUnit> queryable, IVersionedId iu,
MultiStatus status) {
// For versions such as 0.0.0, the IU query may return multiple IUs, so
// we check which is the latest version
IQuery<IInstallableUnit> query = QueryUtil.createLatestQuery(QueryUtil.createIUQuery(iu));
Optional<IInstallableUnit> queryResult = queryFirst(queryable, query, null);
if (queryResult.isEmpty()) {
status.add(Status.error(NLS.bind(Messages.IUBundleContainer_1, iu)));
} else {
result.add(queryResult.get());
}
return queryResult;
}

static <T> Optional<T> queryFirst(IQueryable<T> queryable, IQuery<T> query, IProgressMonitor monitor) {
Expand Down

0 comments on commit 2d6fc0c

Please sign in to comment.