Author: rickhall
Date: Sun Jan 10 01:23:52 2010
New Revision: 897584
URL: http://svn.apache.org/viewvc?rev=897584&view=rev
Log:
Uses constraints do not need to be applied recursively. Fixed bug in candidate
comparator.
Modified:
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CandidateComparator.java
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/ResolverStateImpl.java
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/StatefulResolver.java
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
Modified:
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CandidateComparator.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CandidateComparator.java?rev=897584&r1=897583&r2=897584&view=diff
==============================================================================
---
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CandidateComparator.java
(original)
+++
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CandidateComparator.java
Sun Jan 10 01:23:52 2010
@@ -30,15 +30,16 @@
Capability cap2 = (Capability) arg2;
// First check resolved state, since resolved capabilities have
priority
- // over unresolved ones.
+ // over unresolved ones. Compare in reverse order since we want to sort
+ // in descending order.
int c = 0;
if (cap1.getModule().isResolved() && !cap2.getModule().isResolved())
{
- c = 1;
+ c = -1;
}
- if (!cap1.getModule().isResolved() && cap2.getModule().isResolved())
+ else if (!cap1.getModule().isResolved() &&
cap2.getModule().isResolved())
{
- c = -1;
+ c = 1;
}
// Next compare version numbers.
@@ -52,9 +53,9 @@
Version v1 =
(cap1.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE) == null)
? Version.emptyVersion
: (Version)
cap1.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE).getValue();
- Version v2 =
(cap1.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE) == null)
+ Version v2 =
(cap2.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE) == null)
? Version.emptyVersion
- : (Version)
cap1.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE).getValue();
+ : (Version)
cap2.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE).getValue();
// Compare these in reverse order, since we want
// highest version to have priority.
c = v2.compareTo(v1);
@@ -72,9 +73,9 @@
Version v1 = (cap1.getAttribute(Capability.VERSION_ATTR) ==
null)
? Version.emptyVersion
: (Version)
cap1.getAttribute(Capability.VERSION_ATTR).getValue();
- Version v2 = (cap1.getAttribute(Capability.VERSION_ATTR) ==
null)
+ Version v2 = (cap2.getAttribute(Capability.VERSION_ATTR) ==
null)
? Version.emptyVersion
- : (Version)
cap1.getAttribute(Capability.VERSION_ATTR).getValue();
+ : (Version)
cap2.getAttribute(Capability.VERSION_ATTR).getValue();
// Compare these in reverse order, since we want
// highest version to have priority.
c = v2.compareTo(v1);
Modified:
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java?rev=897584&r1=897583&r2=897584&view=diff
==============================================================================
---
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java
(original)
+++
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java
Sun Jan 10 01:23:52 2010
@@ -150,6 +150,7 @@
// SOLUTION:
// A: bar->B, woz->C
// C: bar->B, dit->D
+ // D: dot->E
private static Module scenario2(List<Module> moduleList)
{
Module m, target;
@@ -605,7 +606,7 @@
}
// SOLUTION:
- // A: require->[C,D]
+ // A: require->[B,C]
// B: foo->D
// C: foo->E
private static Module scenario12(List<Module> moduleList)
@@ -879,4 +880,40 @@
return target;
}
+
+ // SOLUTION:
+ // A: foo->B, bar->C, woz->D
+ // B: bar->C
+ // C: woz-D
+ private static Module scenario19(List<Module> moduleList)
+ {
+ Module m, target;
+
+ // Bundle A
+ moduleList.add(
+ target = (m = new Module("A"))
+ .requiring(new
RequirementImpl(Capability.PACKAGE_NAMESPACE).with("package=foo"))
+ .requiring(new
RequirementImpl(Capability.PACKAGE_NAMESPACE).with("package=woz"))
+ .requiring(new
RequirementImpl(Capability.PACKAGE_NAMESPACE).with("package=bar")));
+ // Bundle B
+ moduleList.add(
+ (m = new Module("B"))
+ .providing(new CapabilityImpl(m,
Capability.PACKAGE_NAMESPACE).with("package=foo").using("bar"))
+ .requiring(new
RequirementImpl(Capability.PACKAGE_NAMESPACE).with("package=bar")));
+ // Bundle C
+ moduleList.add(
+ (m = new Module("C"))
+ .providing(new CapabilityImpl(m,
Capability.PACKAGE_NAMESPACE).with("package=bar").using("woz"))
+ .requiring(new
RequirementImpl(Capability.PACKAGE_NAMESPACE).with("package=woz").with("version=[1.0.0,2.0.0)")));
+ // Bundle D
+ moduleList.add(
+ (m = new Module("D"))
+ .providing(new CapabilityImpl(m,
Capability.PACKAGE_NAMESPACE).with("package=woz").with("version=1.0.0")));
+ // Bundle E
+ moduleList.add(
+ (m = new Module("E"))
+ .providing(new CapabilityImpl(m,
Capability.PACKAGE_NAMESPACE).with("package=woz").with("version=2.0.0")));
+
+ return target;
+ }
}
\ No newline at end of file
Modified:
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/ResolverStateImpl.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/ResolverStateImpl.java?rev=897584&r1=897583&r2=897584&view=diff
==============================================================================
---
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/ResolverStateImpl.java
(original)
+++
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/ResolverStateImpl.java
Sun Jan 10 01:23:52 2010
@@ -98,114 +98,4 @@
{
throw new UnsupportedOperationException("Not supported yet.");
}
-
- private static Capability getSatisfyingCapability(Module module,
Requirement req)
- {
- List<Capability> caps = module.getCapabilities();
- for (Capability cap : caps)
- {
- if (((RequirementImpl) req).isSatistfiedBy(cap))
- {
- return cap;
- }
- }
- return null;
- }
-
- public void moduleResolved(Module module)
- {
- if (module.isResolved())
- {
-/*
- // At this point, we need to remove all of the resolved module's
- // capabilities from the "unresolved" package map and put them in
- // in the "resolved" package map, with the exception of any
- // package exports that are also imported. In that case we need
- // to make sure that the import actually points to the resolved
- // module and not another module. If it points to another module
- // then the capability should be ignored, since the framework
- // decided to honor the import and discard the export.
- List<Capability> caps = module.getCapabilities();
-
- // First remove all existing capabilities from the "unresolved"
map.
- for (int capIdx = 0; (caps != null) && (capIdx < caps.length);
capIdx++)
- {
- if
(caps[capIdx].getNamespace().equals(ICapability.PACKAGE_NAMESPACE))
- {
- // Get package name.
- String pkgName = (String)
-
caps[capIdx].getProperties().get(ICapability.PACKAGE_PROPERTY);
- // Remove the module's capability for the package.
- List capList = (List) m_unresolvedPkgIndex.get(pkgName);
- capList.remove(caps[capIdx]);
- }
- }
-
- // Next create a copy of the module's capabilities so we can
- // null out any capabilities that should be ignored.
- ICapability[] capsCopy = (caps == null) ? null : new
ICapability[caps.length];
- if (capsCopy != null)
- {
- System.arraycopy(caps, 0, capsCopy, 0, caps.length);
- }
- // Loop through the module's capabilities to determine which ones
- // can be ignored by seeing which ones satifies the wire
requirements.
-// TODO: RB - Bug here because a requirement for a package need not overlap the
-// capability for that package and this assumes it does. This might
-// require us to introduce the notion of a substitutable capability.
- IWire[] wires = module.getWires();
- for (int capIdx = 0; (capsCopy != null) && (capIdx <
capsCopy.length); capIdx++)
- {
- // Loop through all wires to see if the current capability
- // satisfies any of the wire requirements.
- for (int wireIdx = 0; (wires != null) && (wireIdx <
wires.length); wireIdx++)
- {
- // If one of the module's capabilities satifies the
requirement
- // for an existing wire, this means the capability was
- // substituted with another provider by the resolver and
- // the module's capability was not used. Therefore, we
should
- // null it here so it doesn't get added the list of
resolved
- // capabilities for this module.
- if
(wires[wireIdx].getRequirement().isSatisfied(capsCopy[capIdx]))
- {
- capsCopy[capIdx] = null;
- break;
- }
- }
- }
-
- // Now loop through all capabilities and add them to the "resolved"
- // capability and package index maps, ignoring any that were
nulled out.
- for (int capIdx = 0; (capsCopy != null) && (capIdx <
capsCopy.length); capIdx++)
- {
- if (capsCopy[capIdx] != null)
- {
- List resolvedCaps = (List) m_resolvedCapMap.get(module);
- if (resolvedCaps == null)
- {
- m_resolvedCapMap.put(module, resolvedCaps = new
ArrayList());
- }
- if (!resolvedCaps.contains(capsCopy[capIdx]))
- {
- resolvedCaps.add(capsCopy[capIdx]);
- }
-
- // If the capability is a package, then add the exporter
module
- // of the wire to the "resolved" package index and remove
it
- // from the "unresolved" package index.
- if
(capsCopy[capIdx].getNamespace().equals(ICapability.PACKAGE_NAMESPACE))
- {
- // Add to "resolved" package index.
- indexPackageCapability(m_resolvedPkgIndex,
capsCopy[capIdx]);
- }
- }
- }
-*/
- }
-
-//System.out.println("UNRESOLVED PACKAGES:");
-//dumpPackageIndex(m_unresolvedPkgIndex);
-//System.out.println("RESOLVED PACKAGES:");
-//dumpPackageIndex(m_resolvedPkgIndex);
- }
}
\ No newline at end of file
Modified:
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/StatefulResolver.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/StatefulResolver.java?rev=897584&r1=897583&r2=897584&view=diff
==============================================================================
---
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/StatefulResolver.java
(original)
+++
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/StatefulResolver.java
Sun Jan 10 01:23:52 2010
@@ -18,11 +18,9 @@
*/
package org.apache.felix.resolver;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.logging.Logger;
import org.apache.felix.resolver.Resolver.ResolverState;
public class StatefulResolver
@@ -61,16 +59,11 @@
// only modules may not have wires.
// TODO: RESOLVER - Seems stupid that we package these up as wires to tear
them apart.
List<Wire> wires = entry.getValue();
- if (wires.size() > 0)
+ for (int wireIdx = 0; wireIdx < wires.size(); wireIdx++)
{
- for (int wireIdx = 0; wireIdx < wires.size(); wireIdx++)
- {
- System.out.println("WIRE: " + wires.get(wireIdx));
- }
- entry.getKey().resolve(wires);
+ System.out.println("WIRE: " + wires.get(wireIdx));
}
-
-// m_state.moduleResolved(module);
+ entry.getKey().resolve(wires);
}
}
}
Modified:
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java?rev=897584&r1=897583&r2=897584&view=diff
==============================================================================
---
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java
(original)
+++
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java
Sun Jan 10 01:23:52 2010
@@ -358,10 +358,9 @@
try
{
-Module target = getTarget(moduleList);
-// for (Module target = getTarget(moduleList);
-// target != null;
-// target = getTarget(moduleList))
+ for (Module target = getTarget(moduleList);
+ target != null;
+ target = getTarget(moduleList))
{
resolver.resolve(target);
@@ -396,11 +395,26 @@
private static Module getTarget(List<Module> modules)
{
- return getTargetByUnresolved(modules);
+ return getTargetByOrder(modules);
+// return getTargetByUnresolved(modules);
// return getTargetBySymbolicName(modules, "org.springframework.faces");
// return getTargetBySymbolicName(modules, "bundle1");
}
+ private static Module getTargetByOrder(List<Module> modules)
+ {
+ for (int modIdx = 0; modIdx < modules.size(); modIdx++)
+ {
+ Module m = modules.get(modIdx);
+ if (!m.isResolved())
+ {
+ return m;
+ }
+ }
+
+ return null;
+ }
+
private static Module getTargetByUnresolved(List<Module> modules)
{
Module maxImporter = null;
Modified:
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java?rev=897584&r1=897583&r2=897584&view=diff
==============================================================================
---
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
(original)
+++
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
Sun Jan 10 01:23:52 2010
@@ -69,6 +69,7 @@
if (!module.isResolved())
{
+System.out.println("+++ RESOLVING " + module);
Map<Requirement, Set<Capability>> candidateMap =
new HashMap<Requirement, Set<Capability>>();
@@ -82,7 +83,7 @@
rethrow = null;
candidateMap = m_candidatePermutations.remove(0);
-//dumpCandidateMap(candidateMap);
+dumpCandidateMap(state, candidateMap);
try
{
@@ -174,6 +175,68 @@
}
}
+ private static void populateCandidates(
+ ResolverState state, Module module,
+ Map<Requirement, Set<Capability>> candidateMap, Set<Module> cycles)
+ {
+ if (m_isInvokeCount)
+ {
+ String methodName = new
Exception().fillInStackTrace().getStackTrace()[0].getMethodName();
+ Long count = m_invokeCounts.get(methodName);
+ count = (count == null) ? new Long(1) : new Long(count.longValue()
+ 1);
+ m_invokeCounts.put(methodName, count);
+ }
+
+ // Detect cycles.
+ if (cycles.contains(module))
+ {
+ return;
+ }
+ cycles.add(module);
+
+ // Store candidates in a local map first, just in case the module
+ // is not resolvable.
+ Map<Requirement, Set<Capability>> localCandidateMap = new HashMap();
+
+ // Find candidates for all requirements for the target module.
+ List<Requirement> reqs = module.getRequirements();
+ for (Requirement req : reqs)
+ {
+ Set<Capability> candidates = state.getCandidates(module, req);
+ for (Iterator<Capability> itCandCap = candidates.iterator();
itCandCap.hasNext(); )
+ {
+ Capability candCap = itCandCap.next();
+ if (!candCap.getModule().isResolved())
+ {
+ try
+ {
+ populateCandidates(state, candCap.getModule(),
candidateMap, cycles);
+ }
+ catch (ResolveException ex)
+ {
+System.out.println("RE: Candidate not resolveable: " + ex);
+ itCandCap.remove();
+ }
+ }
+ }
+ if ((candidates.size() == 0) && !req.isOptional())
+ {
+ throw new ResolveException("Unable to resolve " + module
+ + ": missing requirement " + req);
+ }
+ else if (candidates.size() > 0)
+ {
+ localCandidateMap.put(req, candidates);
+ }
+ }
+
+ // Put candidates for all requirements into the global candidate map.
+ if (localCandidateMap.size() > 0)
+ {
+ candidateMap.putAll(localCandidateMap);
+ }
+ }
+
private void findConsistentCandidates(
Module module, List<Requirement> incomingReqs, Map<Requirement,
Set<Capability>> candidateMap,
Map<Module, Packages> modulePkgMap, Map<Module, Object> cycleMap)
@@ -219,7 +282,7 @@
for (Iterator<Capability> it = candCaps.iterator(); it.hasNext(); )
{
Capability candCap = it.next();
-//System.out.println("+++ TRYING CAND " + candCap + " FOR " + req);
+System.out.println("+++ TRYING CAND " + candCap + " FOR " + req);
try
{
// Try to resolve the candidate.
@@ -254,58 +317,6 @@
}
}
- private static void populateCandidates(
- ResolverState state, Module module,
- Map<Requirement, Set<Capability>> candidateMap, Set<Module> cycles)
- {
- if (m_isInvokeCount)
- {
- String methodName = new
Exception().fillInStackTrace().getStackTrace()[0].getMethodName();
- Long count = m_invokeCounts.get(methodName);
- count = (count == null) ? new Long(1) : new Long(count.longValue()
+ 1);
- m_invokeCounts.put(methodName, count);
- }
-
- // Detect cycles.
- if (cycles.contains(module))
- {
- return;
- }
- cycles.add(module);
-
- // Find candidates for all requirements for the target module.
- List<Requirement> reqs = module.getRequirements();
- for (Requirement req : reqs)
- {
- Set<Capability> candidates = state.getCandidates(module, req);
- for (Iterator<Capability> itCandCap = candidates.iterator();
itCandCap.hasNext(); )
- {
- Capability candCap = itCandCap.next();
- if (!candCap.getModule().isResolved())
- {
- try
- {
- populateCandidates(state, candCap.getModule(),
candidateMap, cycles);
- }
- catch (ResolveException ex)
- {
-System.out.println("RE: Candidate not resolveable: " + ex);
- itCandCap.remove();
- }
- }
- }
- if ((candidates.size() == 0) && !req.isOptional())
- {
- throw new RuntimeException("Unable to resolve " + module
- + ": missing requirement " + req);
- }
- else if (candidates.size() > 0)
- {
- candidateMap.put(req, candidates);
- }
- }
- }
-
private static void calculateExportedPackages(
Module module, List<Requirement> incomingReqs, Map<Module, Packages>
modulePkgMap)
{
@@ -415,7 +426,7 @@
if
(candBlame.m_cap.getNamespace().equals(Capability.PACKAGE_NAMESPACE))
{
-//System.out.println("+++ MERGING " + candBlame.m_cap + " INTO " + current);
+System.out.println("+++ MERGING " + candBlame.m_cap + " INTO " + current);
String pkgName = (String)
candBlame.m_cap.getAttribute(Capability.PACKAGE_ATTR).getValue();
Packages candPkgs = modulePkgMap.get(candBlame.m_cap.getModule());
@@ -493,7 +504,7 @@
currentPkgs.m_importedPkgs.putAll(currentPkgsCopy.m_importedPkgs);
currentPkgs.m_requiredPkgs.putAll(currentPkgsCopy.m_requiredPkgs);
currentPkgs.m_usedPkgs.putAll(currentPkgsCopy.m_usedPkgs);
-//dumpModulePkgs(current, currentPkgs);
+dumpModulePkgs(current, currentPkgs);
}
}
@@ -580,6 +591,10 @@
List<Blame> currentRequiredBlames =
currentPkgs.m_requiredPkgs.get(usedPkgName);
Packages sourcePkgs =
modulePkgMap.get(candCapSource.getModule());
+System.out.println("+++ candCapSource " + candCapSource);
+System.out.println("+++ candCapSource.getModule() " +
candCapSource.getModule());
+System.out.println("+++ sourcePkgs " + sourcePkgs);
+System.out.println("+++ sourcePkgs.m_exportedPkgs " +
sourcePkgs.m_exportedPkgs);
Blame sourceBlame = sourcePkgs.m_exportedPkgs.get(usedPkgName);
sourceBlame = (sourceBlame != null)
? sourceBlame
@@ -657,14 +672,15 @@
+ sourceBlame);
}
- // Verify the candidate's uses constraints do not conflict.
- verifyAndMergeUses(
- current,
- currentPkgs,
- sourceBlame,
- modulePkgMap,
- candidateMap,
- cycleMap);
+ // This does not need to be recursive, even though "uses"
constraints
+ // are transitive.
+// verifyAndMergeUses(
+// current,
+// currentPkgs,
+// sourceBlame,
+// modulePkgMap,
+// candidateMap,
+// cycleMap);
}
}
}