Fixed some bugs and improved fragment version range intersection. (FELIX-1919)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@902296 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java b/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java
index 0d9594e..367ef0c 100644
--- a/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java
+++ b/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java
@@ -466,20 +466,8 @@
// If the existing version range floor is greater than the additional
// version range's floor, then they are inconflict since we cannot
// widen the constraint.
- if (existing.getTargetVersionRange().getLow().compareTo(
- additional.getTargetVersionRange().getLow()) > 0)
- {
- return true;
- }
- // If the existing version range ceiling is less than the additional
- // version range's ceiling, then they are inconflict since we cannot
- // widen the constraint.
- if (((existing.getTargetVersionRange().getHigh() != null)
- && (additional.getTargetVersionRange().getHigh() == null))
- || ((existing.getTargetVersionRange().getHigh() != null)
- && (additional.getTargetVersionRange().getHigh() != null)
- && (existing.getTargetVersionRange().getHigh().compareTo(
- additional.getTargetVersionRange().getHigh()) < 0)))
+ if (!existing.getTargetVersionRange().intersects(
+ additional.getTargetVersionRange()))
{
return true;
}
diff --git a/framework/src/main/java/org/apache/felix/framework/util/VersionRange.java b/framework/src/main/java/org/apache/felix/framework/util/VersionRange.java
index c313d9d..b3d4a55 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/VersionRange.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/VersionRange.java
@@ -80,8 +80,37 @@
return (version.compareTo(m_low) > 0) && (version.compareTo(m_high) < 0);
}
+ public boolean intersects(VersionRange vr)
+ {
+ // Check to see if the passed in floor is less than or equal to
+ // this ceiling and the passed in ceiling is greater than or
+ // equal to this floor.
+ boolean isFloorLessThanCeiling = false;
+ if ((m_high == null)
+ || (m_high.compareTo(vr.getLow()) > 0)
+ || ((m_high.compareTo(vr.getLow()) == 0)
+ && m_isHighInclusive && vr.isLowInclusive()))
+ {
+ isFloorLessThanCeiling = true;
+ }
+ boolean isCeilingGreaterThanFloor = false;
+ if ((vr.getHigh() == null)
+ || (m_low.compareTo(vr.getHigh()) < 0)
+ || ((m_low.compareTo(vr.getHigh()) == 0)
+ && m_isLowInclusive && vr.isHighInclusive()))
+ {
+ isCeilingGreaterThanFloor = true;
+ }
+ return isFloorLessThanCeiling && isCeilingGreaterThanFloor;
+ }
+
public VersionRange intersection(VersionRange vr)
{
+ if (!intersects(vr))
+ {
+ return null;
+ }
+
VersionRange floor = (m_low.compareTo(vr.getLow()) > 0) ? this : vr;
boolean floorInclusive = (getLow().equals(vr.getLow()))
? (isLowInclusive() & vr.isLowInclusive())