From 27e3dcc93470873bd17f7ddda4bb2f6b03ea664c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Thu, 21 Sep 2023 16:52:10 +0200 Subject: [PATCH] Enable referenced repositories when resolving the target content Currently referenced repositories are ignored, that prevents sharing of items that are already available in the referenced repository. This enables searching references (if possible) to find IUs and dependencies in these referenced repositories as well. Fix https://github.com/eclipse-pde/eclipse.pde/issues/720 --- .../internal/core/target/P2TargetUtils.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/P2TargetUtils.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/P2TargetUtils.java index 88e6febe43..f84c3cb5b7 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/P2TargetUtils.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/P2TargetUtils.java @@ -1008,14 +1008,17 @@ static IQueryable getQueryableMetadata(URI[] repos, IProgressM } int repoCount = repos.length; - SubMonitor subMonitor = SubMonitor.convert(monitor, repoCount); - + SubMonitor subMonitor = SubMonitor.convert(monitor, repoCount * 2); + Set seen = new HashSet<>(); List result = new ArrayList<>(repoCount); + List additional = new ArrayList<>(); MultiStatus repoStatus = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.IUBundleContainer_ProblemsLoadingRepositories, null); for (int i = 0; i < repoCount; ++i) { try { - result.add(manager.loadRepository(repos[i], subMonitor.split(1))); + IMetadataRepository repository = manager.loadRepository(repos[i], subMonitor.split(1)); + result.add(repository); + addReferences(repository, additional, seen, manager, subMonitor.split(1)); } catch (ProvisionException e) { repoStatus.add(e.getStatus()); } @@ -1024,12 +1027,33 @@ static IQueryable getQueryableMetadata(URI[] repos, IProgressM if (result.size() != repos.length) { throw new CoreException(repoStatus); } + result.addAll(additional); if (result.size() == 1) { return result.get(0); } return QueryUtil.compoundQueryable(result); } + private static void addReferences(IMetadataRepository repository, List result, + Set seen, IMetadataRepositoryManager manager, IProgressMonitor monitor) { + Collection references = repository.getReferences(); + SubMonitor subMonitor = SubMonitor.convert(monitor, references.size() * 2); + for (IRepositoryReference reference : references) { + if (reference.getType() == IRepository.TYPE_METADATA && seen.add(reference)) { + try { + IMetadataRepository referencedRepository = manager.loadRepository(reference.getLocation(), + subMonitor.split(1)); + result.add(referencedRepository); + addReferences(referencedRepository, result, seen, manager, subMonitor.split(1)); + } catch (ProvisionException e) { + //if reference can't be loaded just ignore it here but log the error just in case the user wants to act on this + PDECore.log(e); + } + } + } + + } + /** * Used to resolve the contents of this container if the user is including all required software. The p2 planner is used * to determine the complete set of IUs required to run the selected software. If all requirements are met, the bundles @@ -1056,6 +1080,7 @@ private void resolveWithPlanner(ITargetDefinition target, IProgressMonitor monit } ProvisioningContext context = new ProvisioningContext(getAgent()); + context.setProperty(ProvisioningContext.FOLLOW_REPOSITORY_REFERENCES, Boolean.toString(true)); context.setMetadataRepositories(getMetadataRepositories(target)); context.setArtifactRepositories(getArtifactRepositories(target));