List<Candidates> importPermutations = session.getImportPermutations();
// Record the initial candidate permutation.
usesPermutations.add(allCandidates);
ResolutionException rethrow = null;
do
{
rethrow = null;
resourcePkgMap.clear();
session.getPackageSourcesCache().clear();
allCandidates = (usesPermutations.size() > 0)
? usesPermutations.remove(0)
: importPermutations.remove(0);
//allCandidates.dump();
try
{
allCandidates.checkSubstitutes(importPermutations);
}
catch (ResolutionException e)
{
rethrow = e;
continue;
}
// For a dynamic import, the instigating resource
// will never be a fragment since fragments never
// execute code, so we don't need to check for
// this case like we do for a normal resolve.
calculatePackageSpaces(session,
allCandidates.getWrappedHost(host), allCandidates,
resourcePkgMap, new HashMap(), new HashSet());
//System.out.println("+++ PACKAGE SPACES START +++");
//dumpResourcePkgMap(resourcePkgMap);
//System.out.println("+++ PACKAGE SPACES END +++");
try
{
checkDynamicPackageSpaceConsistency(session,
allCandidates.getWrappedHost(host),
allCandidates, resourcePkgMap, new HashMap());
}
catch (ResolutionException ex)
{
rethrow = ex;
}
}
while ((rethrow != null)
&& ((usesPermutations.size() > 0) || (importPermutations.size() > 0)));
// If there is a resolve exception, then determine if an
// optionally resolved resource is to blame (typically a fragment).
// If so, then remove the optionally resolved resource and try
// again; otherwise, rethrow the resolve exception.
if (rethrow != null)
{
Collection<Requirement> exReqs = rethrow.getUnresolvedRequirements();
Requirement faultyReq = ((exReqs == null) || (exReqs.isEmpty()))
? null : exReqs.iterator().next();
Resource faultyResource = (faultyReq == null)
? null : getDeclaredResource(faultyReq.getResource());
// If the faulty requirement is wrapped, then it may