You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2018/04/17 09:20:07 UTC
[sling-whiteboard] branch master updated: Use OSGi VersionRange
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
The following commit(s) were added to refs/heads/master by this push:
new c35afbd Use OSGi VersionRange
c35afbd is described below
commit c35afbdc466790ff81ebe6eb06b08fedc1ebe4dd
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Apr 17 11:19:57 2018 +0200
Use OSGi VersionRange
---
.../feature/support/util/CapabilityMatcher.java | 5 +-
.../sling/feature/support/util/ManifestParser.java | 5 +-
.../sling/feature/support/util/SimpleFilter.java | 19 +--
.../sling/feature/support/util/VersionRange.java | 157 ---------------------
4 files changed, 17 insertions(+), 169 deletions(-)
diff --git a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/CapabilityMatcher.java b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/CapabilityMatcher.java
index 8888331..3d2995c 100644
--- a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/CapabilityMatcher.java
+++ b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/CapabilityMatcher.java
@@ -35,6 +35,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
+import org.osgi.framework.VersionRange;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;
@@ -243,7 +244,7 @@ public class CapabilityMatcher
if(rhs != null && rhs instanceof VersionRange)
{
- return ((VersionRange)rhs).isInRange((Version)lhs);
+ return ((VersionRange)rhs).includes((Version)lhs);
}
}
@@ -429,7 +430,7 @@ public class CapabilityMatcher
}
else if(lhs instanceof Version && rhsString.indexOf(',') >= 0)
{
- rhs = VersionRange.parse(rhsString);
+ rhs = VersionRange.valueOf(rhsString);
}
else
{
diff --git a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/ManifestParser.java b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/ManifestParser.java
index 9246004..7031cbe 100644
--- a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/ManifestParser.java
+++ b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/ManifestParser.java
@@ -30,6 +30,7 @@ import org.apache.sling.feature.OSGiRequirement;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
+import org.osgi.framework.VersionRange;
import org.osgi.framework.namespace.BundleNamespace;
import org.osgi.framework.namespace.ExecutionEnvironmentNamespace;
import org.osgi.framework.namespace.IdentityNamespace;
@@ -523,7 +524,7 @@ public class ManifestParser {
{
clauses.get(0).m_attrs.put(
Constants.BUNDLE_VERSION_ATTRIBUTE,
- VersionRange.parse(value.toString()));
+ VersionRange.valueOf(value.toString()));
}
// Note that we use a linked hash map here to ensure the
@@ -704,7 +705,7 @@ public class ManifestParser {
{
clause.m_attrs.put(
Constants.BUNDLE_VERSION_ATTRIBUTE,
- VersionRange.parse(value.toString()));
+ VersionRange.valueOf(value.toString()));
}
}
}
diff --git a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/SimpleFilter.java b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/SimpleFilter.java
index a56b57c..3cf3d89 100644
--- a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/SimpleFilter.java
+++ b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/SimpleFilter.java
@@ -21,6 +21,8 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import org.osgi.framework.VersionRange;
+
public class SimpleFilter
{
public static final int MATCH_ALL = 0;
@@ -60,6 +62,7 @@ public class SimpleFilter
return m_op;
}
+ @Override
public String toString()
{
String s = null;
@@ -555,19 +558,19 @@ public class SimpleFilter
// Rather than building a filter string to be parsed into a SimpleFilter,
// we will just create the parsed SimpleFilter directly.
- List<SimpleFilter> filters = new ArrayList<SimpleFilter>();
+ List<SimpleFilter> filters = new ArrayList<>();
for (Entry<String, Object> entry : attrs.entrySet())
{
if (entry.getValue() instanceof VersionRange)
{
VersionRange vr = (VersionRange) entry.getValue();
- if (vr.isFloorInclusive())
+ if (vr.getLeftType() == VersionRange.LEFT_CLOSED)
{
filters.add(
new SimpleFilter(
entry.getKey(),
- vr.getFloor().toString(),
+ vr.getLeft().toString(),
SimpleFilter.GTE));
}
else
@@ -577,19 +580,19 @@ public class SimpleFilter
((List) not.getValue()).add(
new SimpleFilter(
entry.getKey(),
- vr.getFloor().toString(),
+ vr.getLeft().toString(),
SimpleFilter.LTE));
filters.add(not);
}
- if (vr.getCeiling() != null)
+ if (vr.getRight() != null)
{
- if (vr.isCeilingInclusive())
+ if (vr.getRightType() == VersionRange.RIGHT_CLOSED)
{
filters.add(
new SimpleFilter(
entry.getKey(),
- vr.getCeiling().toString(),
+ vr.getRight().toString(),
SimpleFilter.LTE));
}
else
@@ -599,7 +602,7 @@ public class SimpleFilter
((List) not.getValue()).add(
new SimpleFilter(
entry.getKey(),
- vr.getCeiling().toString(),
+ vr.getRight().toString(),
SimpleFilter.GTE));
filters.add(not);
}
diff --git a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/VersionRange.java b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/VersionRange.java
deleted file mode 100644
index 3d4ee86..0000000
--- a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/VersionRange.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sling.feature.support.util;
-
-import org.osgi.framework.Version;
-
-public class VersionRange
-{
- private final Version m_floor;
- private final boolean m_isFloorInclusive;
- private final Version m_ceiling;
- private final boolean m_isCeilingInclusive;
- public static final VersionRange infiniteRange
- = new VersionRange(Version.emptyVersion, true, null, true);
-
- public VersionRange(
- Version low, boolean isLowInclusive,
- Version high, boolean isHighInclusive)
- {
- m_floor = low;
- m_isFloorInclusive = isLowInclusive;
- m_ceiling = high;
- m_isCeilingInclusive = isHighInclusive;
- }
-
- public Version getFloor()
- {
- return m_floor;
- }
-
- public boolean isFloorInclusive()
- {
- return m_isFloorInclusive;
- }
-
- public Version getCeiling()
- {
- return m_ceiling;
- }
-
- public boolean isCeilingInclusive()
- {
- return m_isCeilingInclusive;
- }
-
- public boolean isInRange(Version version)
- {
- // We might not have an upper end to the range.
- if (m_ceiling == null)
- {
- return (version.compareTo(m_floor) >= 0);
- }
- else if (isFloorInclusive() && isCeilingInclusive())
- {
- return (version.compareTo(m_floor) >= 0) && (version.compareTo(m_ceiling) <= 0);
- }
- else if (isCeilingInclusive())
- {
- return (version.compareTo(m_floor) > 0) && (version.compareTo(m_ceiling) <= 0);
- }
- else if (isFloorInclusive())
- {
- return (version.compareTo(m_floor) >= 0) && (version.compareTo(m_ceiling) < 0);
- }
- return (version.compareTo(m_floor) > 0) && (version.compareTo(m_ceiling) < 0);
- }
-
- public static VersionRange parse(String range)
- {
- // Check if the version is an interval.
- if (range.indexOf(',') >= 0)
- {
- String s = range.substring(1, range.length() - 1);
- String vlo = s.substring(0, s.indexOf(',')).trim();
- String vhi = s.substring(s.indexOf(',') + 1, s.length()).trim();
- return new VersionRange (
- new Version(vlo), (range.charAt(0) == '['),
- new Version(vhi), (range.charAt(range.length() - 1) == ']'));
- }
- else
- {
- return new VersionRange(new Version(range), true, null, false);
- }
- }
-
- public boolean equals(Object obj)
- {
- if (obj == null)
- {
- return false;
- }
- if (getClass() != obj.getClass())
- {
- return false;
- }
- final VersionRange other = (VersionRange) obj;
- if (m_floor != other.m_floor && (m_floor == null || !m_floor.equals(other.m_floor)))
- {
- return false;
- }
- if (m_isFloorInclusive != other.m_isFloorInclusive)
- {
- return false;
- }
- if (m_ceiling != other.m_ceiling && (m_ceiling == null || !m_ceiling.equals(other.m_ceiling)))
- {
- return false;
- }
- if (m_isCeilingInclusive != other.m_isCeilingInclusive)
- {
- return false;
- }
- return true;
- }
-
- public int hashCode()
- {
- int hash = 5;
- hash = 97 * hash + (m_floor != null ? m_floor.hashCode() : 0);
- hash = 97 * hash + (m_isFloorInclusive ? 1 : 0);
- hash = 97 * hash + (m_ceiling != null ? m_ceiling.hashCode() : 0);
- hash = 97 * hash + (m_isCeilingInclusive ? 1 : 0);
- return hash;
- }
-
- public String toString()
- {
- if (m_ceiling != null)
- {
- StringBuffer sb = new StringBuffer();
- sb.append(m_isFloorInclusive ? '[' : '(');
- sb.append(m_floor.toString());
- sb.append(',');
- sb.append(m_ceiling.toString());
- sb.append(m_isCeilingInclusive ? ']' : ')');
- return sb.toString();
- }
- else
- {
- return m_floor.toString();
- }
- }
-}
--
To stop receiving notification emails like this one, please contact
cziegeler@apache.org.