Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache loaded repos in ProvisioningContext #517

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,22 @@ private void getLoadedRepository(URI location, IArtifactRepositoryManager repoMa
}

private Set<IMetadataRepository> getLoadedMetadataRepositories(IProgressMonitor monitor) {
IMetadataRepositoryManager repoManager = agent.getService(IMetadataRepositoryManager.class);
URI[] repositories = metadataRepositories == null ? repoManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL) : metadataRepositories;

Map<String, IMetadataRepository> repos = new HashMap<>();
SubMonitor sub = SubMonitor.convert(monitor, repositories.length);

// Clear out the list of remembered artifact repositories
referencedArtifactRepositories = new HashMap<>();
for (URI repositorie : repositories) {
loadMetadataRepository(repoManager, repositorie, repos, shouldFollowReferences(), sub.split(1));
if (loadedRepos == null) {
IMetadataRepositoryManager repoManager = agent.getService(IMetadataRepositoryManager.class);
URI[] repositories = metadataRepositories == null
? repoManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL)
: metadataRepositories;

loadedRepos = new HashMap<>();
SubMonitor sub = SubMonitor.convert(monitor, repositories.length);

// Clear out the list of remembered artifact repositories
referencedArtifactRepositories = new HashMap<>();
for (URI repository : repositories) {
loadMetadataRepository(repoManager, repository, loadedRepos, shouldFollowReferences(), sub.split(1));
}
}
return new HashSet<>(repos.values());
return new HashSet<>(loadedRepos.values());
}

private void loadMetadataRepository(IMetadataRepositoryManager manager, URI location,
Expand Down Expand Up @@ -406,6 +410,7 @@ private <T, R extends IRepository<T>> void loadRepository(IRepositoryManager<T>
private static final Comparator<IArtifactKey> ARTIFACT_KEY_COMPARATOR = Comparator //
.comparing(IArtifactKey::getId) //
.thenComparing(IArtifactKey::getVersion);
private Map<String, IMetadataRepository> loadedRepos;

/**
* Returns a map from simple artifact repository location to a subset of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil;
import org.eclipse.equinox.p2.planner.IProfileChangeRequest;
import org.eclipse.equinox.p2.query.*;
import org.eclipse.equinox.p2.query.ExpressionMatchQuery;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
Expand Down Expand Up @@ -199,6 +202,12 @@ public void testFollowHelpsResolve() {
context.setArtifactRepositories(new URI[0]);
IProvisioningPlan plan = getPlanner(getAgent()).getProvisioningPlan(request, context, getMonitor());
assertFalse("resolve should fail with missing requirements", plan.getStatus().isOK());
// we need to create a new context as the planner is calling
// ProvisioningContext.getMetadata(IProgressMonitor) and after that call
// repositories are fixed as per API...
context = new ProvisioningContext(getAgent());
context.setMetadataRepositories(new URI[] { repoA.getLocation() });
context.setArtifactRepositories(new URI[0]);
context.setProperty(ProvisioningContext.FOLLOW_REPOSITORY_REFERENCES, "true");
plan = getPlanner(getAgent()).getProvisioningPlan(request, context, getMonitor());
assertTrue("resolve should pass", plan.getStatus().isOK());
Expand Down
Loading