// Populate mandatory revisions; since these are mandatory
// revisions, failure throws a resolve exception.
for (Iterator<BundleRevision> it = mandatoryRevisions.iterator();
it.hasNext(); )
{
BundleRevision br = it.next();
if (Util.isFragment(br) || (br.getWiring() == null))
{
allCandidates.populate(state, br, Candidates.MANDATORY);
}
else
{
it.remove();
}
}
// Populate optional revisions; since these are optional
// revisions, failure does not throw a resolve exception.
for (BundleRevision br : optionalRevisions)
{
boolean isFragment = Util.isFragment(br);
if (isFragment || (br.getWiring() == null))
{
allCandidates.populate(state, br, Candidates.OPTIONAL);
}
}
// Populate ondemand fragments; since these are optional
// revisions, failure does not throw a resolve exception.
for (BundleRevision br : ondemandFragments)
{
boolean isFragment = Util.isFragment(br);
if (isFragment)
{
allCandidates.populate(state, br, Candidates.ON_DEMAND);
}
}
// Merge any fragments into hosts.
allCandidates.prepare(getResolvedSingletons(state));
// Create a combined list of populated revisions; for
// optional revisions. We do not need to consider ondemand
// fragments, since they will only be pulled in if their
// host is already present.
Set<BundleRevision> allRevisions =
new HashSet<BundleRevision>(mandatoryRevisions);
for (BundleRevision br : optionalRevisions)
{
if (allCandidates.isPopulated(br))
{
allRevisions.add(br);
}
}
// Record the initial candidate permutation.
m_usesPermutations.add(allCandidates);
ResolveException rethrow = null;
// If a populated revision is a fragment, then its host
// must ultimately be verified, so store its host requirement
// to use for package space calculation.
Map<BundleRevision, List<BundleRequirement>> hostReqs =
new HashMap<BundleRevision, List<BundleRequirement>>();
for (BundleRevision br : allRevisions)
{
if (Util.isFragment(br))
{
hostReqs.put(
br,
br.getDeclaredRequirements(BundleRevision.HOST_NAMESPACE));
}
}
do
{
rethrow = null;
revisionPkgMap.clear();
m_packageSourcesCache.clear();
allCandidates = (m_usesPermutations.size() > 0)
? m_usesPermutations.remove(0)
: m_importPermutations.remove(0);
//allCandidates.dump();
for (BundleRevision br : allRevisions)
{
BundleRevision target = br;
// If we are resolving a fragment, then get its
// host candidate and verify it instead.
List<BundleRequirement> hostReq = hostReqs.get(br);
if (hostReq != null)
{
target = allCandidates.getCandidates(hostReq.get(0))
.iterator().next().getRevision();
}
calculatePackageSpaces(
allCandidates.getWrappedHost(target), allCandidates, revisionPkgMap,
new HashMap<BundleCapability, List<BundleRevision>>(), new HashSet<BundleRevision>());
//System.out.println("+++ PACKAGE SPACES START +++");
//dumpRevisionPkgMap(revisionPkgMap);
//System.out.println("+++ PACKAGE SPACES END +++");
try
{
checkPackageSpaceConsistency(
false, allCandidates.getWrappedHost(target),
allCandidates, revisionPkgMap, new HashMap<BundleRevision, Object>());
}
catch (ResolveException ex)
{
rethrow = ex;
}
}
}
while ((rethrow != null)
&& ((m_usesPermutations.size() > 0) || (m_importPermutations.size() > 0)));
// If there is a resolve exception, then determine if an
// optionally resolved revision is to blame (typically a fragment).
// If so, then remove the optionally resolved resolved and try
// again; otherwise, rethrow the resolve exception.
if (rethrow != null)
{
BundleRevision faultyRevision =
getActualBundleRevision(rethrow.getRevision());
if (rethrow.getRequirement() instanceof HostedRequirement)
{
faultyRevision =
((HostedRequirement) rethrow.getRequirement())
.getOriginalRequirement().getRevision();
}
if (optionalRevisions.remove(faultyRevision))
{
retry = true;
}
else if (ondemandFragments.remove(faultyRevision))
{
retry = true;
}
else
{
throw rethrow;
}
}
// If there is no exception to rethrow, then this was a clean
// resolve, so populate the wire map.
else
{
for (BundleRevision br : allRevisions)
{
BundleRevision target = br;
// If we are resolving a fragment, then we
// actually want to populate its host's wires.
List<BundleRequirement> hostReq = hostReqs.get(br);
if (hostReq != null)