Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Invalid
-
resolver-1.16.0
-
None
-
None
Description
When creating a custom ResolveContext we need to build a collection of mandatory resources using the method getMandatoryResources().
Normally we will create such collection using a custom built Resource containing only a IdentityNamespace.IDENTITY_NAMESPACE capability, because it is enough in order to search for more details of such resource in the installed bundles/fragments or in the registered bundle repositories inside the findProviders() method.
The error that I'm getting is due the fact that the resolver, most precisely, the Candidates class is using getMandatoryResources() after the getInitialCandidates(session) been executed and inferring that it has a information about fragments that it doesn't have.
public Map<Resource, Resource> getRootHosts() { Map<Resource, Resource> hosts = new LinkedHashMap<Resource, Resource>(); for (Resource res : *m_session.getMandatoryResources()*) { addHost(res, hosts); } for (Resource res : m_session.getOptionalResources()) { if (isPopulated(res)) { addHost(res, hosts); } } return hosts; }
private void addHost(Resource res, Map<Resource, Resource> hosts) { if (res instanceof WrappedResource) { res = ((WrappedResource) res).getDeclaredResource(); } if (!Util.isFragment(res)) { hosts.put(res, getWrappedHost(res)); } else { // The error is happening here: *Requirement hostReq = res.getRequirements(HostNamespace.HOST_NAMESPACE).get(0);* Capability hostCap = getFirstCandidate(hostReq); // If the resource is an already resolved fragment and can not // be attached to new hosts, there will be no matching host, // so ignore this resource if (hostCap != null) { res = getWrappedHost(hostCap.getResource()); if (res instanceof WrappedResource) { hosts.put(((WrappedResource) res).getDeclaredResource(), res); } } } }
Wouldn't be possible to use the processed initial candidates resources instead ?