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 4705591438..7b84afe0ca 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 @@ -1082,8 +1082,8 @@ 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)); + context.setMetadataRepositories(getMetadataRepositories(target).toArray(URI[]::new)); + context.setArtifactRepositories(getArtifactRepositories(target).toArray(URI[]::new)); IProvisioningPlan plan = planner.getProvisioningPlan(request, context, subMonitor.split(20)); IStatus status = plan.getStatus(); @@ -1273,12 +1273,12 @@ private void resolveWithSlicer(ITargetDefinition target, IProgressMonitor monito // resolve IUs IInstallableUnit[] units = getRootIUs(target, subMonitor.split(40)); - URI[] repositories = getMetadataRepositories(target); - int repoCount = repositories.length; - if (repoCount == 0) { + Collection repositories = getMetadataRepositories(target); + if (repositories.isEmpty()) { return; } - IQueryable allMetadata = getQueryableMetadata(repositories, subMonitor.split(5)); + URI[] uris = repositories.toArray(URI[]::new); + IQueryable allMetadata = getQueryableMetadata(uris, subMonitor.split(5)); // do an initial slice to add everything the user requested IQueryResult queryResult = slice(units, allMetadata, target, subMonitor.split(5)); @@ -1303,8 +1303,8 @@ private void resolveWithSlicer(ITargetDefinition target, IProgressMonitor monito IEngine engine = getEngine(); ProvisioningContext context = new ProvisioningContext(getAgent()); - context.setMetadataRepositories(repositories); - context.setArtifactRepositories(getArtifactRepositories(target)); + context.setMetadataRepositories(uris); + context.setArtifactRepositories(getArtifactRepositories(target).toArray(URI[]::new)); context.setProperty(ProvisioningContext.FOLLOW_REPOSITORY_REFERENCES, Boolean.toString(true)); IProvisioningPlan plan = engine.createPlan(fProfile, context); setPlanProperties(plan, target, TargetDefinitionPersistenceHelper.MODE_SLICER); @@ -1392,7 +1392,7 @@ private IQueryResult slice(IInstallableUnit[] units, IQueryabl * @return URI's of repositories to use when getting artifacts * @exception CoreException */ - private URI[] getArtifactRepositories(ITargetDefinition target) throws CoreException { + private Collection getArtifactRepositories(ITargetDefinition target) throws CoreException { Set result = new HashSet<>(); ITargetLocation[] containers = target.getTargetLocations(); if (containers == null) { @@ -1407,6 +1407,10 @@ private URI[] getArtifactRepositories(ITargetDefinition target) throws CoreExcep } result.addAll(Arrays.asList(repos)); } + if (container instanceof TargetReferenceBundleContainer targetRefContainer) { + ITargetDefinition referencedTargetDefinition = targetRefContainer.getTargetDefinition(); + result.addAll(getArtifactRepositories(referencedTargetDefinition)); + } } if (useAdditionalLocalArtifacts()) { // get all the artifact repos we know in the manager currently @@ -1416,7 +1420,7 @@ private URI[] getArtifactRepositories(ITargetDefinition target) throws CoreExcep findProfileRepos(result); findWorkspaceRepos(result); } - return result.toArray(new URI[result.size()]); + return result; } /** @@ -1528,7 +1532,7 @@ private IInstallableUnit[] getRootIUs(ITargetDefinition definition, IProgressMon * @return URI's of repositories to use when resolving bundles * @exception CoreException */ - private URI[] getMetadataRepositories(ITargetDefinition target) throws CoreException { + private Collection getMetadataRepositories(ITargetDefinition target) throws CoreException { Set result = new HashSet<>(); ITargetLocation[] containers = target.getTargetLocations(); if (containers == null) { @@ -1536,15 +1540,19 @@ private URI[] getMetadataRepositories(ITargetDefinition target) throws CoreExcep } IMetadataRepositoryManager manager = getRepoManager(); for (ITargetLocation container : containers) { - if (container instanceof IUBundleContainer) { - URI[] repos = ((IUBundleContainer) container).getRepositories(); + if (container instanceof IUBundleContainer iuContainer) { + URI[] repos = iuContainer.getRepositories(); if (repos == null) { repos = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL); } result.addAll(Arrays.asList(repos)); } + if (container instanceof TargetReferenceBundleContainer targetRefContainer) { + ITargetDefinition referencedTargetDefinition = targetRefContainer.getTargetDefinition(); + result.addAll(getMetadataRepositories(referencedTargetDefinition)); + } } - return result.toArray(new URI[result.size()]); + return result; } private static final String NATIVE_ARTIFACTS = "nativeArtifacts"; //$NON-NLS-1$ diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetReferenceBundleContainer.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetReferenceBundleContainer.java index 44da8a83dc..0821782818 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetReferenceBundleContainer.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetReferenceBundleContainer.java @@ -86,7 +86,7 @@ public String getUri() { return uri; } - private synchronized ITargetDefinition getTargetDefinition() throws CoreException { + synchronized ITargetDefinition getTargetDefinition() throws CoreException { // only synchronize here, we just want to make sure not two threads are // loading the target in parallel but not block the targetDefinition or // reload operation as these might be called from the UI