From 5a71dcef608a1f5098bed3f69456d1cf04c0a7c7 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Tue, 19 Dec 2023 14:31:01 -0600 Subject: [PATCH] Fix for TCK test ResolverHookTests.testBeginTriggers The PR #95 changed some of the logic with the triggers that get passed to resolver hooks. When doing a refresh the triggers got replaced with all unresolved revisions when the triggers were not mandatory. That is the case when doing a refreshBundles call. That changed what the framework passed to resolver hooks for triggers. This fix saves the original triggers list so that calls to the resolver hooks use the correct list of revisioins for the triggers. --- .../osgi/container/ModuleResolver.java | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolver.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolver.java index 344a55ddac0..4acd61943b7 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolver.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolver.java @@ -167,10 +167,6 @@ private static int parseInteger(String sInteger, int defaultValue, int minValue) * merged into the moduleDatabase */ ModuleResolutionReport resolveDelta(Collection triggers, boolean triggersMandatory, Collection unresolved, Map wiringCopy, ModuleDatabase moduleDatabase) { - if (!triggersMandatory) { - // we are just resolving all bundles optionally - triggers = unresolved; - } ResolveProcess resolveProcess = new ResolveProcess(unresolved, triggers, triggersMandatory, wiringCopy, moduleDatabase); return resolveProcess.resolve(); } @@ -500,8 +496,9 @@ protected void doLog(int level, String msg, Throwable throwable) { * back later for other reasons. */ private final Collection disabled; - private final Collection triggers; - private final boolean triggersMandatory; + private final Collection toResolve; + private final boolean toResolveMandatory; + private final Collection triggersForHook; final ModuleDatabase moduleDatabase; final Map wirings; private final Set previouslyResolved; @@ -528,8 +525,14 @@ protected void doLog(int level, String msg, Throwable throwable) { ResolveProcess(Collection unresolved, Collection triggers, boolean triggersMandatory, Map wirings, ModuleDatabase moduleDatabase) { this.unresolved = unresolved; this.disabled = new HashSet<>(unresolved); - this.triggers = new ArrayList<>(triggers); - this.triggersMandatory = triggersMandatory; + if (!triggersMandatory) { + // we are just resolving all bundles optionally + this.toResolve = new ArrayList<>(unresolved); + } else { + this.toResolve = new ArrayList<>(triggers); + } + this.triggersForHook = Collections.unmodifiableList(new ArrayList<>(triggers)); + this.toResolveMandatory = triggersMandatory; this.wirings = new HashMap<>(wirings); this.previouslyResolved = new HashSet<>(wirings.keySet()); this.moduleDatabase = moduleDatabase; @@ -540,9 +543,10 @@ protected void doLog(int level, String msg, Throwable throwable) { this.unresolved = unresolved; this.disabled = new HashSet<>(unresolved); ModuleRevision revision = dynamicReq.getRevision(); - this.triggers = new ArrayList<>(1); - this.triggers.add(revision); - this.triggersMandatory = false; + this.toResolve = new ArrayList<>(1); + this.toResolve.add(revision); + this.toResolveMandatory = false; + this.triggersForHook = Collections.singletonList(revision); this.wirings = wirings; this.previouslyResolved = new HashSet<>(wirings.keySet()); this.moduleDatabase = moduleDatabase; @@ -859,7 +863,8 @@ ModuleResolutionReport resolve() { threadResolving.set(Boolean.TRUE); try { try { - hook = adaptor.getResolverHookFactory().begin(InternalUtils.asList((List) triggers)); + hook = adaptor.getResolverHookFactory() + .begin(InternalUtils.asList((List) triggersForHook)); } catch (RuntimeException e) { if (e.getCause() instanceof BundleException) { BundleException be = (BundleException) e.getCause(); @@ -877,7 +882,7 @@ ModuleResolutionReport resolve() { filterResolvable(); selectSingletons(); // remove disabled from triggers to prevent the resolver from resolving them - if (triggers.removeAll(disabled) && triggersMandatory) { + if (toResolve.removeAll(disabled) && toResolveMandatory) { throw new ResolutionException(Msg.ModuleResolver_SingletonDisabledError + disabled); } if (dynamicReq != null) { @@ -890,11 +895,11 @@ ModuleResolutionReport resolve() { // be sure to remove the revisions from the optional and triggers // so they no longer attempt to be resolved Set fragmentResources = dynamicAttachWirings.keySet(); - triggers.removeAll(fragmentResources); + toResolve.removeAll(fragmentResources); result.putAll(dynamicAttachWirings); } - resolveRevisionsInBatch(triggers, triggersMandatory, logger, result); + resolveRevisionsInBatch(toResolve, toResolveMandatory, logger, result); } } catch (ResolutionException e) { re = e;