You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2009/12/02 16:34:57 UTC
svn commit: r886175 [3/3] - in
/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver:
./ cs/ felix/ manifestparser/ prototype/
Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/prototype/ProtoResolver.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/prototype/ProtoResolver.java?rev=886175&r1=886174&r2=886175&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/prototype/ProtoResolver.java (original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/prototype/ProtoResolver.java Wed Dec 2 15:34:56 2009
@@ -40,8 +40,8 @@
new HashMap<Module, Map<String, Blame>>();
private final Map<Module, Map<String, Blame>> m_resolvingConstraintCache =
new HashMap<Module, Map<String, Blame>>();
- private final Map<ExportedPackage, Map<String, Blame>> m_resolvedConstraintCache =
- new HashMap<ExportedPackage, Map<String, Blame>>();
+ private final Map<CapabilityImpl, Map<String, Blame>> m_resolvedConstraintCache =
+ new HashMap<CapabilityImpl, Map<String, Blame>>();
private Map<Module, Map<String, Object>> m_verifyCache =
new HashMap<Module, Map<String, Object>>();
@@ -58,7 +58,7 @@
m_pkgCapSet = new CapabilitySet(indices);
for (int modIdx = 0; modIdx < m_moduleList.size(); modIdx++)
{
- List<ExportedPackage> exports = m_moduleList.get(modIdx).getExports();
+ List<CapabilityImpl> exports = m_moduleList.get(modIdx).getExports();
for (int expIdx = 0; expIdx < exports.size(); expIdx++)
{
m_pkgCapSet.addCapability(exports.get(expIdx));
@@ -82,8 +82,8 @@
}
private Module m_rootModule = null;
- private List<Map<ImportedPackage, Set<Capability>>> m_candidatePermutations
- = new ArrayList<Map<ImportedPackage, Set<Capability>>>();
+ private List<Map<RequirementImpl, Set<Capability>>> m_candidatePermutations
+ = new ArrayList<Map<RequirementImpl, Set<Capability>>>();
public Map<Module, List<Wire>> resolve(Module module)
{
@@ -92,11 +92,11 @@
m_resolvingConstraintCache.clear();
m_resolvedConstraintCache.clear();
m_verifyCache.clear();
- Map<ImportedPackage, Set<Capability>> candidateMap = resolve(
+ Map<RequirementImpl, Set<Capability>> candidateMap = resolve(
module,
null,
module,
- new HashMap<ImportedPackage, Set<Capability>>(),
+ new HashMap<RequirementImpl, Set<Capability>>(),
new HashMap<String, Blame>(),
new HashMap<Module, Boolean>());
@@ -107,9 +107,9 @@
return populateWireMap(module, candidateMap, new HashMap<Module, List<Wire>>());
}
- private Map<ImportedPackage, Set<Capability>> resolve(
- Module module, ExportedPackage epGoal, Module blameModule,
- Map<ImportedPackage, Set<Capability>> candidateMap,
+ private Map<RequirementImpl, Set<Capability>> resolve(
+ Module module, CapabilityImpl epGoal, Module blameModule,
+ Map<RequirementImpl, Set<Capability>> candidateMap,
Map<String, Blame> existingConstrains,
Map<Module, Boolean> cycleMap)
{
@@ -167,8 +167,8 @@
}
// Find candidates for all imports for the target module.
- List<ImportedPackage> imports = module.getImports();
- for (ImportedPackage ip : imports)
+ List<RequirementImpl> imports = module.getImports();
+ for (RequirementImpl ip : imports)
{
// If we are using a permutated candidate map, then the target
// module's candidates may have already been calculated, so use
@@ -202,7 +202,7 @@
repeat = false;
// Loop through all of the target module's imports and v
- for (ImportedPackage ip : imports)
+ for (RequirementImpl ip : imports)
{
// Get the current candidate capability for the current import.
Set<Capability> exporters = candidateMap.get(ip);
@@ -217,14 +217,15 @@
{
mergeResolvedConstraints(
module, candidateMap, currentConstraintsCopy,
- (ExportedPackage) cap);
+ (CapabilityImpl) cap);
}
// If current candidate is the same as the module being
// resolved, then just directly add it as a constraint.
else if (cap.getModule().equals(module))
{
currentConstraintsCopy.put(
- cap.getName(), new Blame((ExportedPackage) cap, blameModule));
+ (String) cap.getAttribute(Capability.PACKAGE_ATTR).getValue(),
+ new Blame((CapabilityImpl) cap, blameModule));
}
// If the current candidate is not resolved, then try to resolve
// it, which will also merge packages while verify constraints.
@@ -232,7 +233,7 @@
{
resolve(
cap.getModule(),
- (ExportedPackage) cap,
+ (CapabilityImpl) cap,
module,
candidateMap,
currentConstraintsCopy,
@@ -343,7 +344,7 @@
return constraintsCopy;
}
- private Set<Capability> findExporters(ImportedPackage ip)
+ private Set<Capability> findExporters(RequirementImpl ip)
{
if (m_isInvokeCount)
{
@@ -356,17 +357,18 @@
Set<Capability> result = new TreeSet(new Comparator() {
public int compare(Object arg1, Object arg2)
{
- ExportedPackage ep1 = (ExportedPackage) arg1;
- ExportedPackage ep2 = (ExportedPackage) arg2;
- int c = ep1.getName().compareTo(ep2.getName());
+ CapabilityImpl ep1 = (CapabilityImpl) arg1;
+ CapabilityImpl ep2 = (CapabilityImpl) arg2;
+ int c = ep1.getAttribute(Capability.PACKAGE_ATTR).getValue().compareTo(
+ ep2.getAttribute(Capability.PACKAGE_ATTR).getValue());
if (c == 0)
{
- Version v1 = (ep1.getAttribute("version") == null)
+ Version v1 = (ep1.getAttribute(Capability.VERSION_ATTR) == null)
? Version.emptyVersion
- : (Version) ep1.getAttribute("version").getValue();
- Version v2 = (ep1.getAttribute("version") == null)
+ : (Version) ep1.getAttribute(Capability.VERSION_ATTR).getValue();
+ Version v2 = (ep1.getAttribute(Capability.VERSION_ATTR) == null)
? Version.emptyVersion
- : (Version) ep1.getAttribute("version").getValue();
+ : (Version) ep1.getAttribute(Capability.VERSION_ATTR).getValue();
// Compare these in reverse order, since we want
// highest version to have priority.
c = v2.compareTo(v1);
@@ -400,14 +402,16 @@
{
constraints = new HashMap<String, Blame>();
- List<ExportedPackage> exports = module.getExports();
+ List<CapabilityImpl> exports = module.getExports();
for (int i = 0; i < exports.size(); i++)
{
// TODO: PROTO RESOLVER - Assume if a module imports the same package it
// exports that the import will overlap the export.
if (!hasOverlappingImport(module, exports.get(i)))
{
- constraints.put(exports.get(i).getName(), new Blame(exports.get(i), blameModule));
+ constraints.put(
+ (String) exports.get(i).getAttribute(Capability.PACKAGE_ATTR).getValue(),
+ new Blame(exports.get(i), blameModule));
}
}
@@ -432,7 +436,7 @@
return constraints;
}
- private boolean hasOverlappingImport(Module module, ExportedPackage ep)
+ private boolean hasOverlappingImport(Module module, CapabilityImpl ep)
{
if (m_isInvokeCount)
{
@@ -442,7 +446,7 @@
m_invokeCounts.put(methodName, count);
}
- List<ImportedPackage> imports = module.getImports();
+ List<RequirementImpl> imports = module.getImports();
for (int i = 0; i < imports.size(); i++)
{
if (m_pkgCapSet.matches(ep, imports.get(i).getFilter()))
@@ -454,8 +458,8 @@
}
private void mergeResolvedConstraints(
- Module blameModule, Map<ImportedPackage, Set<Capability>> candidateMap,
- Map<String, Blame> currentConstraints, ExportedPackage epTarget)
+ Module blameModule, Map<RequirementImpl, Set<Capability>> candidateMap,
+ Map<String, Blame> currentConstraints, CapabilityImpl epTarget)
{
if (m_isInvokeCount)
{
@@ -466,7 +470,7 @@
}
Map<String, Blame> actualConstraints = calculateResolvedConstraints(blameModule, epTarget);
- verifyUses(blameModule, epTarget.getName(),
+ verifyUses(blameModule, (String) epTarget.getAttribute(Capability.PACKAGE_ATTR).getValue(),
candidateMap, currentConstraints, actualConstraints,
new HashMap<String, List<Module>>());
//System.out.println("+++ ACTUAL FOR " + epTarget + " = " + actualConstraints);
@@ -481,7 +485,8 @@
{
throw new ResolveConflictException("Unable to resolve "
+ blameModule + ": constraint conflict with '"
- + current.m_exportedPackage.getName() + "' between " + current + " and "
+ + current.m_exportedPackage.getAttribute(Capability.PACKAGE_ATTR).getValue()
+ + "' between " + current + " and "
+ entry.getValue());
}
else if (current == null)
@@ -492,7 +497,7 @@
}
private Map<String, Blame> calculateResolvedConstraints(
- Module blameModule, ExportedPackage epTarget)
+ Module blameModule, CapabilityImpl epTarget)
{
if (m_isInvokeCount)
{
@@ -511,13 +516,14 @@
constraints = new HashMap<String, Blame>();
// The capability itself is a constraint, so add it.
- constraints.put(epTarget.getName(), new Blame(epTarget, blameModule));
+ constraints.put((String) epTarget.getAttribute(Capability.PACKAGE_ATTR).getValue(),
+ new Blame(epTarget, blameModule));
// Calculate implied constraints.
calculateResolvedUsesConstraints(
epTarget,
constraints,
- new HashMap<ExportedPackage, ExportedPackage>());
+ new HashMap<CapabilityImpl, CapabilityImpl>());
// Cache answer.
m_resolvedConstraintCache.put(epTarget, constraints);
@@ -548,8 +554,8 @@
}
private void calculateResolvedUsesConstraints(
- ExportedPackage epTarget, Map<String, Blame> constraints,
- Map<ExportedPackage, ExportedPackage> cycleMap)
+ CapabilityImpl epTarget, Map<String, Blame> constraints,
+ Map<CapabilityImpl, CapabilityImpl> cycleMap)
{
if (m_isInvokeCount)
{
@@ -570,7 +576,7 @@
{
// We need to find the source of the package name for the current target.
// It can either be from an importer or an exporter.
- ExportedPackage epSource = null;
+ CapabilityImpl epSource = null;
// Search the target module's wires for the package.
for (int wireIdx = 0;
@@ -578,7 +584,8 @@
wireIdx++)
{
if (epTarget.getModule().getWires().get(wireIdx)
- .getExportedPackage().getName().equals(uses.get(usesIdx)))
+ .getExportedPackage().getAttribute(Capability.PACKAGE_ATTR).getValue()
+ .equals(uses.get(usesIdx)))
{
epSource = epTarget.getModule().getWires().get(wireIdx).getExportedPackage();
}
@@ -590,7 +597,8 @@
(epSource == null) && (expIdx < epTarget.getModule().getExports().size());
expIdx++)
{
- if (epTarget.getModule().getExports().get(expIdx).getName().equals(uses.get(usesIdx)))
+ if (epTarget.getModule().getExports().get(expIdx)
+ .getAttribute(Capability.PACKAGE_ATTR).getValue().equals(uses.get(usesIdx)))
{
epSource = epTarget.getModule().getExports().get(expIdx);
}
@@ -605,7 +613,7 @@
}
private void checkConsistency(
- Module targetModule, ExportedPackage epGoal, Map<ImportedPackage,
+ Module targetModule, CapabilityImpl epGoal, Map<RequirementImpl,
Set<Capability>> candidateMap, Map<String, Blame> existingConstraints,
Map<String, Blame> currentConstraints)
@@ -626,7 +634,9 @@
// Find matching providing for requirement.
if (epGoal != null)
{
- verifyUses(targetModule, epGoal.getName(),
+ verifyUses(
+ targetModule,
+ (String) epGoal.getAttribute(Capability.PACKAGE_ATTR).getValue(),
candidateMap, existingConstraints, currentConstraints,
new HashMap<String, List<Module>>());
}
@@ -646,7 +656,7 @@
}
private void verifyUses(Module targetModule, String pkgName,
- Map<ImportedPackage, Set<Capability>> candidateMap,
+ Map<RequirementImpl, Set<Capability>> candidateMap,
Map<String, Blame> existingConstraints,
Map<String, Blame> currentConstraints, Map<String, List<Module>> cycleMap)
{
@@ -696,7 +706,7 @@
{
//System.out.println("Conflict: " + existing.m_exportedPackage + " WITH " + current.m_exportedPackage);
//System.out.println("Blame: " + existing.m_blameModules + " AND " + current.m_blameModules);
- Map<ImportedPackage, Set<Capability>> candidateMapCopy = copyCandidateMap(candidateMap);
+ Map<RequirementImpl, Set<Capability>> candidateMapCopy = copyCandidateMap(candidateMap);
boolean modified = false;
boolean invalid = false;
for (int blameIdx = 0; blameIdx < existing.m_blameModules.size(); blameIdx++)
@@ -706,7 +716,7 @@
// to them.
if (!existing.m_blameModules.get(blameIdx).isResolved())
{
- List<ImportedPackage> blameImports =
+ List<RequirementImpl> blameImports =
existing.m_blameModules.get(blameIdx).getImports();
for (int impIdx = 0; impIdx < blameImports.size(); impIdx++)
{
@@ -793,8 +803,8 @@
answers.put(pkgName, Boolean.TRUE);
}
- private static Map<ImportedPackage, Set<Capability>> copyCandidateMap(
- Map<ImportedPackage, Set<Capability>> candidateMap)
+ private static Map<RequirementImpl, Set<Capability>> copyCandidateMap(
+ Map<RequirementImpl, Set<Capability>> candidateMap)
{
if (m_isInvokeCount)
{
@@ -804,18 +814,18 @@
m_invokeCounts.put(methodName, count);
}
- Map<ImportedPackage, Set<Capability>> copy = new HashMap<ImportedPackage, Set<Capability>>();
- for (Iterator<Entry<ImportedPackage, Set<Capability>>> it = candidateMap.entrySet().iterator();
+ Map<RequirementImpl, Set<Capability>> copy = new HashMap<RequirementImpl, Set<Capability>>();
+ for (Iterator<Entry<RequirementImpl, Set<Capability>>> it = candidateMap.entrySet().iterator();
it.hasNext(); )
{
- Entry<ImportedPackage, Set<Capability>> entry = it.next();
+ Entry<RequirementImpl, Set<Capability>> entry = it.next();
copy.put(entry.getKey(), new HashSet(entry.getValue()));
}
return copy;
}
private static Map<Module, List<Wire>> populateWireMap(
- Module module, Map<ImportedPackage, Set<Capability>> candidateMap,
+ Module module, Map<RequirementImpl, Set<Capability>> candidateMap,
Map<Module, List<Wire>> wireMap)
{
if (m_isInvokeCount)
@@ -831,7 +841,7 @@
List<Wire> moduleWires = new ArrayList<Wire>();
wireMap.put(module, moduleWires);
- List<ImportedPackage> imports = module.getImports();
+ List<RequirementImpl> imports = module.getImports();
for (int i = 0; i < imports.size(); i++)
{
Capability cap = candidateMap.get(imports.get(i)).iterator().next();
@@ -847,7 +857,7 @@
new Wire(module,
imports.get(i),
cap.getModule(),
- (ExportedPackage) cap));
+ (CapabilityImpl) cap));
}
}
}
@@ -856,9 +866,9 @@
public static class Blame
{
- public final ExportedPackage m_exportedPackage;
+ public final CapabilityImpl m_exportedPackage;
public final List<Module> m_blameModules;
- public Blame(ExportedPackage exportedPackage, Module blameModule)
+ public Blame(CapabilityImpl exportedPackage, Module blameModule)
{
m_exportedPackage = exportedPackage;
m_blameModules = new ArrayList<Module>();