Skip to content

Commit

Permalink
Discover URIs from referenced target locations
Browse files Browse the repository at this point in the history
Currently URIs are not discovered when they are defined in a referenced
target location.

This now also look into referenced target for locations that are
suitable to supply additional URIs.

This relates to #207
  • Loading branch information
laeubi committed Oct 22, 2023
1 parent 6790bd3 commit bcd30a1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<URI> repositories = getMetadataRepositories(target);
if (repositories.isEmpty()) {
return;
}
IQueryable<IInstallableUnit> allMetadata = getQueryableMetadata(repositories, subMonitor.split(5));
URI[] uris = repositories.toArray(URI[]::new);
IQueryable<IInstallableUnit> allMetadata = getQueryableMetadata(uris, subMonitor.split(5));

// do an initial slice to add everything the user requested
IQueryResult<IInstallableUnit> queryResult = slice(units, allMetadata, target, subMonitor.split(5));
Expand All @@ -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);
Expand Down Expand Up @@ -1392,7 +1392,7 @@ private IQueryResult<IInstallableUnit> 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<URI> getArtifactRepositories(ITargetDefinition target) throws CoreException {
Set<URI> result = new HashSet<>();
ITargetLocation[] containers = target.getTargetLocations();
if (containers == null) {
Expand All @@ -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
Expand All @@ -1416,7 +1420,7 @@ private URI[] getArtifactRepositories(ITargetDefinition target) throws CoreExcep
findProfileRepos(result);
findWorkspaceRepos(result);
}
return result.toArray(new URI[result.size()]);
return result;
}

/**
Expand Down Expand Up @@ -1528,23 +1532,27 @@ 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<URI> getMetadataRepositories(ITargetDefinition target) throws CoreException {
Set<URI> result = new HashSet<>();
ITargetLocation[] containers = target.getTargetLocations();
if (containers == null) {
containers = new ITargetLocation[0];
}
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$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bcd30a1

Please sign in to comment.