{
r = new HostedRequirement(wire.getRequirer(), r);
}
// Wrap the capability as a hosted capability if it comes
// from a fragment, since we will need to know the host.
Capability c = wire.getCapability();
if (!c.getResource().equals(wire.getProvider()))
{
c = new HostedCapability(wire.getProvider(), c);
}
reqs.add(r);
caps.add(c);
}
// Since the revision is resolved, it could be dynamically importing,
// so check to see if there are candidates for any of its dynamic
// imports.
for (Requirement req
: Util.getDynamicRequirements(wiring.getResourceRequirements(null)))
{
// Get the candidates for the current requirement.
SortedSet<Capability> candCaps = allCandidates.getCandidates(req);
// Optional requirements may not have any candidates.
if (candCaps == null)
{
continue;
}
Capability cap = candCaps.iterator().next();
reqs.add(req);
caps.add(cap);
isDynamicImporting = true;
// Can only dynamically import one at a time, so break
// out of the loop after the first.
break;
}
}
else
{
for (Requirement req : resource.getRequirements(null))
{
String resolution = req.getDirectives()
.get(ResourceConstants.REQUIREMENT_RESOLUTION_DIRECTIVE);
// TODO: RFC-112 - Need dynamic constant.
if ((resolution == null) || !resolution.equals("dynamic"))
{
// Get the candidates for the current requirement.
SortedSet<Capability> candCaps = allCandidates.getCandidates(req);
// Optional requirements may not have any candidates.
if (candCaps == null)
{
continue;
}
Capability cap = candCaps.iterator().next();
reqs.add(req);
caps.add(cap);
}
}
}
// First, add all exported packages to the target revision's package space.
calculateExportedPackages(env, resource, allCandidates, revisionPkgMap);
Packages revisionPkgs = revisionPkgMap.get(resource);
// Second, add all imported packages to the target revision's package space.
for (int i = 0; i < reqs.size(); i++)
{
Requirement req = reqs.get(i);
Capability cap = caps.get(i);
calculateExportedPackages(env, cap.getResource(), allCandidates, revisionPkgMap);
mergeCandidatePackages(
env, resource, req, cap, revisionPkgMap, allCandidates,
new HashMap<Resource, List<Capability>>());
}
// Third, have all candidates to calculate their package spaces.
for (int i = 0; i < caps.size(); i++)
{
calculatePackageSpaces(
env, caps.get(i).getResource(), allCandidates, revisionPkgMap,
usesCycleMap, cycle);
}
// Fourth, if the target revision is unresolved or is dynamically importing,
// then add all the uses constraints implied by its imported and required
// packages to its package space.
// NOTE: We do not need to do this for resolved revisions because their
// package space is consistent by definition and these uses constraints
// are only needed to verify the consistency of a resolving revision. The
// only exception is if a resolved revision is dynamically importing, then
// we need to calculate its uses constraints again to make sure the new
// import is consistent with the existing package space.
if ((wiring == null) || isDynamicImporting)
{
// Merge uses constraints from required capabilities.
for (int i = 0; i < reqs.size(); i++)
{
Requirement req = reqs.get(i);
Capability cap = caps.get(i);
// Ignore bundle/package requirements, since they are
// considered below.
if (!req.getNamespace().equals(ResourceConstants.WIRING_BUNDLE_NAMESPACE)
&& !req.getNamespace().equals(ResourceConstants.WIRING_PACKAGE_NAMESPACE))
{