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/08 20:23:57 UTC
svn commit: r888529 - in
/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver:
RequirementImpl.java cs/Attribute.java cs/CapabilitySet.java
prototype/ProtoResolver.java
Author: rickhall
Date: Tue Dec 8 19:23:56 2009
New Revision: 888529
URL: http://svn.apache.org/viewvc?rev=888529&view=rev
Log:
Hack in support for VersionRanges.
Modified:
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/RequirementImpl.java
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Attribute.java
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/CapabilitySet.java
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/prototype/ProtoResolver.java
Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/RequirementImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/RequirementImpl.java?rev=888529&r1=888528&r2=888529&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/RequirementImpl.java (original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/RequirementImpl.java Tue Dec 8 19:23:56 2009
@@ -84,8 +84,7 @@
if (n.equalsIgnoreCase(Constants.VERSION_ATTRIBUTE)
|| n.equalsIgnoreCase(Constants.BUNDLE_VERSION_ATTRIBUTE))
{
-// m_attrs.put(n, new Attribute(n, VersionRange.parse(v), false));
- m_attrs.put(n, new Attribute(n, Version.parseVersion(v), false));
+ m_attrs.put(n, new Attribute(n, VersionRange.parse(v), false));
}
else
{
@@ -97,9 +96,9 @@
return this;
}
- public boolean isSatistfiedBy(Capability ep)
+ public boolean isSatistfiedBy(Capability cap)
{
- boolean result = m_name.equals(ep.getAttribute(Capability.PACKAGE_ATTR).getValue());
+ boolean result = m_name.equals(cap.getAttribute(Capability.PACKAGE_ATTR).getValue());
// Check specified import attributes.
if (result)
@@ -107,20 +106,21 @@
for (Iterator<Entry<String, Attribute>> it = m_attrs.entrySet().iterator(); it.hasNext(); )
{
Attribute attr = it.next().getValue();
- Attribute epAttr = ep.getAttribute(attr.getName());
- if (epAttr != null)
+ Attribute capAttr = cap.getAttribute(attr.getName());
+ if (capAttr != null)
{
- if (epAttr.getValue() instanceof Version)
+ if (capAttr.getValue() instanceof Version)
{
- result = ((Version) attr.getValue()).compareTo(epAttr.getValue()) <= 0;
+ result = ((VersionRange) attr.getValue()).isInRange(
+ (Version) capAttr.getValue());
}
else
{
- result = ep.getAttribute(attr.getName()).getValue().equals(attr.getValue());
+ result = cap.getAttribute(attr.getName()).getValue().equals(attr.getValue());
}
break;
}
- else if (ep.getAttribute(attr.getName()) == null)
+ else if (cap.getAttribute(attr.getName()) == null)
{
result = false;
break;
@@ -178,14 +178,13 @@
for (Iterator<Entry<String, Attribute>> it = m_attrs.entrySet().iterator(); it.hasNext(); )
{
Entry<String, Attribute> entry = it.next();
-/*
- if (m_attrs.get(i).getValue() instanceof VersionRange)
+ if (entry.getValue().getValue() instanceof VersionRange)
{
- VersionRange vr = (VersionRange) m_attributes[i].getValue();
+ VersionRange vr = (VersionRange) entry.getValue().getValue();
if (vr.isLowInclusive())
{
sb.append("(");
- sb.append(m_attributes[i].getName());
+ sb.append(entry.getValue().getName());
sb.append(">=");
sb.append(vr.getLow().toString());
sb.append(")");
@@ -193,7 +192,7 @@
else
{
sb.append("(!(");
- sb.append(m_attributes[i].getName());
+ sb.append(entry.getValue().getName());
sb.append("<=");
sb.append(vr.getLow().toString());
sb.append("))");
@@ -204,7 +203,7 @@
if (vr.isHighInclusive())
{
sb.append("(");
- sb.append(m_attributes[i].getName());
+ sb.append(entry.getValue().getName());
sb.append("<=");
sb.append(vr.getHigh().toString());
sb.append(")");
@@ -212,22 +211,21 @@
else
{
sb.append("(!(");
- sb.append(m_attributes[i].getName());
+ sb.append(entry.getValue().getName());
sb.append(">=");
sb.append(vr.getHigh().toString());
sb.append("))");
}
}
}
-*/
-// else
-// {
+ else
+ {
sb.append("(");
sb.append(entry.getValue().getName());
sb.append("=");
sb.append(entry.getValue().getValue().toString());
sb.append(")");
-// }
+ }
}
if ((m_attrs != null) && (m_attrs.size() > 0))
Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Attribute.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Attribute.java?rev=888529&r1=888528&r2=888529&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Attribute.java (original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Attribute.java Tue Dec 8 19:23:56 2009
@@ -21,10 +21,10 @@
public class Attribute
{
private final String m_name;
- private final Comparable m_value;
+ private final Object m_value; // Always comparable except VersionRange
private final boolean m_isMandatory;
- public Attribute(String name, Comparable value, boolean isMandatory)
+ public Attribute(String name, Object value, boolean isMandatory)
{
m_name = name;
m_value = value;
@@ -36,7 +36,7 @@
return m_name;
}
- public Comparable getValue()
+ public Object getValue()
{
return m_value;
}
Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/CapabilitySet.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/CapabilitySet.java?rev=888529&r1=888528&r2=888529&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/CapabilitySet.java (original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/CapabilitySet.java Tue Dec 8 19:23:56 2009
@@ -52,11 +52,12 @@
if (cap.getAttribute(entry.getKey()) != null)
{
Map<Comparable, Set<Capability>> index = entry.getValue();
- Set<Capability> caps = index.get(cap.getAttribute(entry.getKey()).getValue());
+ Set<Capability> caps = index.get(
+ (Comparable) cap.getAttribute(entry.getKey()).getValue());
if (caps == null)
{
caps = new HashSet<Capability>();
- index.put(cap.getAttribute(entry.getKey()).getValue(), caps);
+ index.put((Comparable) cap.getAttribute(entry.getKey()).getValue(), caps);
}
caps.add(cap);
}
@@ -155,27 +156,17 @@
{
Capability cap = it.next();
Attribute attr = cap.getAttribute(sf.getName());
- Comparable value = (attr == null) ? null : cap.getAttribute(sf.getName()).getValue();
+ Comparable value = (Comparable)
+ ((attr == null) ? null : cap.getAttribute(sf.getName()).getValue());
if (value != null)
{
switch (sf.getOperation())
{
case SimpleFilter.EQ:
- // Special hack, since a VersionRange is not a Comparable
- if (value instanceof Version)
- {
- if (value.compareTo(coerceType(value, (String) sf.getValue())) >= 0)
- {
- matches.add(cap);
- }
- }
- else
- {
if (value.compareTo(coerceType(value, (String) sf.getValue())) == 0)
{
matches.add(cap);
}
- }
break;
case SimpleFilter.LTE:
if (value.compareTo(coerceType(value, (String) sf.getValue())) <= 0)
@@ -282,27 +273,17 @@
{
matched = false;
Attribute attr = cap.getAttribute(sf.getName());
- Comparable value = (attr == null) ? null : cap.getAttribute(sf.getName()).getValue();
+ Comparable value = (Comparable)
+ ((attr == null) ? null : cap.getAttribute(sf.getName()).getValue());
if (value != null)
{
switch (sf.getOperation())
{
case SimpleFilter.EQ:
- // Special hack, since a VersionRange is not a Comparable
- if (value instanceof Version)
- {
- if (value.compareTo(coerceType(value, (String) sf.getValue())) >= 0)
- {
- matched = true;
- }
- }
- else
- {
if (value.compareTo(coerceType(value, (String) sf.getValue())) == 0)
{
matched = true;
}
- }
break;
case SimpleFilter.LTE:
if (value.compareTo(coerceType(value, (String) sf.getValue())) <= 0)
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=888529&r1=888528&r2=888529&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 Tue Dec 8 19:23:56 2009
@@ -507,8 +507,8 @@
{
Capability cap1 = (Capability) arg1;
Capability cap2 = (Capability) arg2;
- int c = cap1.getAttribute(Capability.PACKAGE_ATTR).getValue().compareTo(
- cap2.getAttribute(Capability.PACKAGE_ATTR).getValue());
+ int c = ((Comparable) cap1.getAttribute(Capability.PACKAGE_ATTR).getValue())
+ .compareTo(cap2.getAttribute(Capability.PACKAGE_ATTR).getValue());
if (c == 0)
{
Version v1 = (cap1.getAttribute(Capability.VERSION_ATTR) == null)