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) {