From 2d6fc0c43d70ba803c4e79133813bbca72e8f4ce Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sun, 13 Oct 2024 10:10:14 +0200 Subject: [PATCH] [TP] Ensure the latest matching IU is queried when caching artifacts 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. --- .../internal/core/target/IUBundleContainer.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/IUBundleContainer.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/IUBundleContainer.java index 1ac6ab01cd..df07075d3f 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/IUBundleContainer.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/IUBundleContainer.java @@ -267,8 +267,7 @@ private void cacheIUs() throws CoreException { List result = new ArrayList<>(); MultiStatus status = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.IUBundleContainer_ProblemsLoadingRepositories); for (IVersionedId unit : fIUs) { - IQuery query = QueryUtil.createIUQuery(unit); - addQueryResult(profile, query, unit, result, status); + queryIU(profile, unit, status).ifPresent(result::add); } if (!status.isOK()) { fResolutionStatus = status; @@ -687,9 +686,7 @@ Collection getRootIUs(IProgressMonitor monitor) throws CoreExc MultiStatus status = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.IUBundleContainer_ProblemsLoadingRepositories); List 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 query = QueryUtil.createLatestQuery(QueryUtil.createIUQuery(iu)); - addQueryResult(repos, query, iu, result, status); + queryIU(repos, iu, status).ifPresent(result::add); } if (!status.isOK()) { fResolutionStatus = status; @@ -698,14 +695,16 @@ Collection getRootIUs(IProgressMonitor monitor) throws CoreExc return result; } - private void addQueryResult(IQueryable queryable, IQuery query, IVersionedId iu, - List result, MultiStatus status) { + private Optional queryIU(IQueryable 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 query = QueryUtil.createLatestQuery(QueryUtil.createIUQuery(iu)); Optional 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 Optional queryFirst(IQueryable queryable, IQuery query, IProgressMonitor monitor) {