From 5bc1d2d799a59b4323589b764d8f0954934e77ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Thu, 16 May 2024 07:55:13 +0200 Subject: [PATCH] Fix ProvisioningContextTest.testFollowHelpsResolve is violating API Currently ProvisioningContextTest.testFollowHelpsResolve() assumes it can modify the context repositories after using the context but this is not valid according to API. --- .../equinox/p2/engine/ProvisioningContext.java | 4 ++-- .../p2/tests/engine/ProvisioningContextTest.java | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningContext.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningContext.java index 84daa94305..e0a051395c 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningContext.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningContext.java @@ -219,8 +219,8 @@ private Set getLoadedMetadataRepositories(IProgressMonitor // Clear out the list of remembered artifact repositories referencedArtifactRepositories = new HashMap<>(); - for (URI repositorie : repositories) { - loadMetadataRepository(repoManager, repositorie, loadedRepos, shouldFollowReferences(), sub.split(1)); + for (URI repository : repositories) { + loadMetadataRepository(repoManager, repository, loadedRepos, shouldFollowReferences(), sub.split(1)); } } return new HashSet<>(loadedRepos.values()); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProvisioningContextTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProvisioningContextTest.java index 4fe0b58794..adb8b19c44 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProvisioningContextTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProvisioningContextTest.java @@ -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; @@ -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());