FELIX-2404: Use felix utils instead of various classes from karaf

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@953588 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/assembly/src/main/descriptors/unix-bin.xml b/karaf/assembly/src/main/descriptors/unix-bin.xml
index 211dcf2..fb3fead 100644
--- a/karaf/assembly/src/main/descriptors/unix-bin.xml
+++ b/karaf/assembly/src/main/descriptors/unix-bin.xml
@@ -178,15 +178,6 @@
                 <include>org.ops4j.pax.url:pax-url-wrap</include>
             </includes>
         </dependencySet>
-       <dependencySet>
-            <outputDirectory>/system</outputDirectory>
-            <unpack>false</unpack>
-            <useProjectArtifact>false</useProjectArtifact>
-            <outputFileNameMapping>org/apache/felix/karaf/${artifact.artifactId}/${artifact.baseVersion}/${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
-            <includes>
-                <include>org.apache.felix.karaf:org.apache.felix.karaf.commons</include>
-            </includes>
-        </dependencySet>
         <dependencySet>
             <outputDirectory>/system</outputDirectory>
             <unpack>false</unpack>
diff --git a/karaf/assembly/src/main/descriptors/windows-bin.xml b/karaf/assembly/src/main/descriptors/windows-bin.xml
index 307d319..3b03a21 100644
--- a/karaf/assembly/src/main/descriptors/windows-bin.xml
+++ b/karaf/assembly/src/main/descriptors/windows-bin.xml
@@ -176,15 +176,6 @@
             <useProjectArtifact>false</useProjectArtifact>
             <outputFileNameMapping>org/apache/felix/karaf/${artifact.artifactId}/${artifact.baseVersion}/${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
             <includes>
-                <include>org.apache.felix.karaf:org.apache.felix.karaf.commons</include>
-            </includes>
-        </dependencySet>
-        <dependencySet>
-            <outputDirectory>/system</outputDirectory>
-            <unpack>false</unpack>
-            <useProjectArtifact>false</useProjectArtifact>
-            <outputFileNameMapping>org/apache/felix/karaf/${artifact.artifactId}/${artifact.baseVersion}/${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
-            <includes>
                 <include>org.apache.felix.karaf:org.apache.felix.karaf.management</include>
             </includes>
         </dependencySet>
diff --git a/karaf/assembly/src/main/filtered-resources/etc/startup.properties b/karaf/assembly/src/main/filtered-resources/etc/startup.properties
index bf7a1aa..0ed8095 100644
--- a/karaf/assembly/src/main/filtered-resources/etc/startup.properties
+++ b/karaf/assembly/src/main/filtered-resources/etc/startup.properties
@@ -36,7 +36,6 @@
 #
 org/apache/aries/blueprint/org.apache.aries.blueprint/${aries.blueprint.version}/org.apache.aries.blueprint-${aries.blueprint.version}.jar=20
 
-org/apache/felix/karaf/org.apache.felix.karaf.commons/${project.version}/org.apache.felix.karaf.commons-${project.version}.jar=30
 org/apache/felix/gogo/org.apache.felix.gogo.runtime/${felix.gogo.version}/org.apache.felix.gogo.runtime-${felix.gogo.version}.jar=30
 org/apache/felix/karaf/shell/org.apache.felix.karaf.shell.console/${project.version}/org.apache.felix.karaf.shell.console-${project.version}.jar=30
 org/apache/felix/karaf/deployer/org.apache.felix.karaf.deployer.spring/${project.version}/org.apache.felix.karaf.deployer.spring-${project.version}.jar=30
diff --git a/karaf/commons/pom.xml b/karaf/commons/pom.xml
deleted file mode 100644
index 1083670..0000000
--- a/karaf/commons/pom.xml
+++ /dev/null
@@ -1,68 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
-  <!--
-
-      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.
-  -->
-
-  <modelVersion>4.0.0</modelVersion>
-
-  <parent>
-    <artifactId>karaf</artifactId>
-    <groupId>org.apache.felix.karaf</groupId>
-    <version>1.7.0-SNAPSHOT</version>
-  </parent>
-
-  <groupId>org.apache.felix.karaf</groupId>
-  <artifactId>org.apache.felix.karaf.commons</artifactId>
-  <version>1.7.0-SNAPSHOT</version>
-  <packaging>bundle</packaging>
-  <name>Apache Felix Karaf :: Commons</name>
-
-  <properties>
-    <appendedResourcesDirectory>${basedir}/../etc/appended-resources</appendedResourcesDirectory>
-  </properties>
-
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.felix</groupId>
-      <artifactId>org.osgi.core</artifactId>
-      <scope>provided</scope>
-    </dependency>    
-  </dependencies>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.felix</groupId>
-        <artifactId>maven-bundle-plugin</artifactId>
-        <configuration>
-          <instructions>
-            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
-            <Export-Package>${project.artifactId}*;version=${project.version}</Export-Package>
-            <Import-Package>
-                !${project.artifactId}*,
-                *
-            </Import-Package>
-            <_versionpolicy>${bnd.version.policy}</_versionpolicy>
-          </instructions>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
-
-</project>
\ No newline at end of file
diff --git a/karaf/commons/src/main/java/org/apache/felix/karaf/commons/osgi/VersionRange.java b/karaf/commons/src/main/java/org/apache/felix/karaf/commons/osgi/VersionRange.java
deleted file mode 100644
index 47045de..0000000
--- a/karaf/commons/src/main/java/org/apache/felix/karaf/commons/osgi/VersionRange.java
+++ /dev/null
@@ -1,158 +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.felix.karaf.commons.osgi;
-
-import org.osgi.framework.Version;
-
-public class VersionRange
-{
-    private final Version m_low;
-    private final boolean m_isLowInclusive;
-    private final Version m_high;
-    private final boolean m_isHighInclusive;
-    public static final VersionRange infiniteRange = new VersionRange(Version.emptyVersion, true, null, true);
-
-    public VersionRange(
-        Version low, boolean isLowInclusive,
-        Version high, boolean isHighInclusive)
-    {
-        m_low = low;
-        m_isLowInclusive = isLowInclusive;
-        m_high = high;
-        m_isHighInclusive = isHighInclusive;
-    }
-
-    public Version getLow()
-    {
-        return m_low;
-    }
-
-    public boolean isLowInclusive()
-    {
-        return m_isLowInclusive;
-    }
-
-    public Version getHigh()
-    {
-        return m_high;
-    }
-
-    public boolean isHighInclusive()
-    {
-        return m_isHighInclusive;
-    }
-
-    public boolean isInRange(Version version)
-    {
-        // We might not have an upper end to the range.
-        if (m_high == null)
-        {
-            return (version.compareTo(m_low) >= 0);
-        }
-        else if (isLowInclusive() && isHighInclusive())
-        {
-            return (version.compareTo(m_low) >= 0) && (version.compareTo(m_high) <= 0);
-        }
-        else if (isHighInclusive())
-        {
-            return (version.compareTo(m_low) > 0) && (version.compareTo(m_high) <= 0);
-        }
-        else if (isLowInclusive())
-        {
-            return (version.compareTo(m_low) >= 0) && (version.compareTo(m_high) < 0);
-        }
-        return (version.compareTo(m_low) > 0) && (version.compareTo(m_high) < 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_low != other.m_low && (m_low == null || !m_low.equals(other.m_low)))
-        {
-            return false;
-        }
-        if (m_isLowInclusive != other.m_isLowInclusive)
-        {
-            return false;
-        }
-        if (m_high != other.m_high && (m_high == null || !m_high.equals(other.m_high)))
-        {
-            return false;
-        }
-        if (m_isHighInclusive != other.m_isHighInclusive)
-        {
-            return false;
-        }
-        return true;
-    }
-
-    public int hashCode()
-    {
-        int hash = 5;
-        hash = 97 * hash + (m_low != null ? m_low.hashCode() : 0);
-        hash = 97 * hash + (m_isLowInclusive ? 1 : 0);
-        hash = 97 * hash + (m_high != null ? m_high.hashCode() : 0);
-        hash = 97 * hash + (m_isHighInclusive ? 1 : 0);
-        return hash;
-    }
-
-    public String toString()
-    {
-        if (m_high != null)
-        {
-            StringBuffer sb = new StringBuffer();
-            sb.append(m_isLowInclusive ? '[' : '(');
-            sb.append(m_low.toString());
-            sb.append(',');
-            sb.append(m_high.toString());
-            sb.append(m_isHighInclusive ? ']' : ')');
-            return sb.toString();
-        }
-        else
-        {
-            return m_low.toString();
-        }
-    }
-}
\ No newline at end of file
diff --git a/karaf/features/core/pom.xml b/karaf/features/core/pom.xml
index cde5a66..c6fe665 100644
--- a/karaf/features/core/pom.xml
+++ b/karaf/features/core/pom.xml
@@ -51,12 +51,12 @@
 
         <dependency>
             <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.bundlerepository</artifactId>
+            <artifactId>org.apache.felix.utils</artifactId>
+            <scope>provided</scope>
         </dependency>
-
         <dependency>
-            <groupId>org.apache.felix.karaf</groupId>
-            <artifactId>org.apache.felix.karaf.commons</artifactId>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.bundlerepository</artifactId>
         </dependency>
 
         <dependency>
@@ -109,7 +109,11 @@
                             org.apache.felix.karaf.shell.console,
                             *
                         </Import-Package>
-                        <Private-Package>org.apache.felix.karaf.features.internal</Private-Package>
+                        <Private-Package>
+                            org.apache.felix.karaf.features.internal,
+                            org.apache.felix.utils.version,
+                            org.apache.felix.utils.manifest
+                        </Private-Package>
                         <_versionpolicy>${bnd.version.policy}</_versionpolicy>
                     </instructions>
                 </configuration>
diff --git a/karaf/features/core/src/main/java/org/apache/felix/karaf/features/internal/FeaturesServiceImpl.java b/karaf/features/core/src/main/java/org/apache/felix/karaf/features/internal/FeaturesServiceImpl.java
index 178a6b5..c8815df 100644
--- a/karaf/features/core/src/main/java/org/apache/felix/karaf/features/internal/FeaturesServiceImpl.java
+++ b/karaf/features/core/src/main/java/org/apache/felix/karaf/features/internal/FeaturesServiceImpl.java
@@ -22,32 +22,22 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.jar.JarInputStream;
 import java.util.jar.Manifest;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.felix.karaf.commons.osgi.VersionRange;
-import org.apache.felix.karaf.features.FeaturesService;
 import org.apache.felix.karaf.features.Feature;
-import org.apache.felix.karaf.features.Repository;
-import org.apache.felix.karaf.features.FeaturesListener;
 import org.apache.felix.karaf.features.FeatureEvent;
+import org.apache.felix.karaf.features.FeaturesListener;
+import org.apache.felix.karaf.features.FeaturesService;
+import org.apache.felix.karaf.features.Repository;
 import org.apache.felix.karaf.features.RepositoryEvent;
+import org.apache.felix.utils.manifest.Clause;
+import org.apache.felix.utils.manifest.Parser;
+import org.apache.felix.utils.version.VersionRange;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
@@ -56,10 +46,10 @@
 import org.osgi.framework.Version;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.service.prefs.BackingStoreException;
 import org.osgi.service.prefs.Preferences;
 import org.osgi.service.prefs.PreferencesService;
-import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.service.startlevel.StartLevel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -406,15 +396,15 @@
         for (Bundle b : state.installed) {
             String hostHeader = (String) b.getHeaders().get(Constants.FRAGMENT_HOST);
             if (hostHeader != null) {
-                List<HeaderParser.PathElement> header = HeaderParser.parseHeader(hostHeader);
-                if (header != null && header.size() > 0) {
-                    HeaderParser.PathElement path = header.get(0);
+                Clause[] clauses = Parser.parseHeader(hostHeader);
+                if (clauses != null && clauses.length > 0) {
+                    Clause path = clauses[0];
                     for (Bundle hostBundle : state.bundles) {
                         if (hostBundle.getSymbolicName().equals(path.getName())) {
                             String ver = path.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE);
                             if (ver != null) {
-                                VersionRange v = VersionRange.parse(ver);
-                                if (v.isInRange(hostBundle.getVersion())) {
+                                VersionRange v = VersionRange.parseVersionRange(ver);
+                                if (v.contains(hostBundle.getVersion())) {
                                     bundles.add(hostBundle);
                                 }
                             } else {
@@ -436,16 +426,16 @@
             return bundles;
         }
         // Second pass: for each bundle, check if there is any unresolved optional package that could be resolved
-        Map<Bundle, List<HeaderParser.PathElement>> imports = new HashMap<Bundle, List<HeaderParser.PathElement>>();
+        Map<Bundle, List<Clause>> imports = new HashMap<Bundle, List<Clause>>();
         for (Iterator<Bundle> it = bundles.iterator(); it.hasNext();) {
             Bundle b = it.next();
             String importsStr = (String) b.getHeaders().get(Constants.IMPORT_PACKAGE);
             if (importsStr == null) {
                 it.remove();
             } else {
-                List<HeaderParser.PathElement> importsList = HeaderParser.parseHeader(importsStr);
-                for (Iterator<HeaderParser.PathElement> itp = importsList.iterator(); itp.hasNext();) {
-                    HeaderParser.PathElement p = itp.next();
+                List<Clause> importsList = Arrays.asList(Parser.parseHeader(importsStr));
+                for (Iterator<Clause> itp = importsList.iterator(); itp.hasNext();) {
+                    Clause p = itp.next();
                     String resolution = p.getDirective(Constants.RESOLUTION_DIRECTIVE);
                     if (!Constants.RESOLUTION_OPTIONAL.equals(resolution)) {
                         itp.remove();
@@ -463,27 +453,27 @@
         }
         // Third pass: compute a list of packages that are exported by our bundles and see if
         //             some exported packages can be wired to the optional imports
-        List<HeaderParser.PathElement> exports = new ArrayList<HeaderParser.PathElement>();
+        List<Clause> exports = new ArrayList<Clause>();
         for (Bundle b : state.installed) {
             String exportsStr = (String) b.getHeaders().get(Constants.EXPORT_PACKAGE);
             if (exportsStr != null) {
-                List<HeaderParser.PathElement> exportsList = HeaderParser.parseHeader(exportsStr);
-                exports.addAll(exportsList);
+                Clause[] exportsList = Parser.parseHeader(exportsStr);
+                exports.addAll(Arrays.asList(exportsList));
             }
         }
         for (Iterator<Bundle> it = bundles.iterator(); it.hasNext();) {
             Bundle b = it.next();
-            List<HeaderParser.PathElement> importsList = imports.get(b);
-            for (Iterator<HeaderParser.PathElement> itpi = importsList.iterator(); itpi.hasNext();) {
-                HeaderParser.PathElement pi = itpi.next();
+            List<Clause> importsList = imports.get(b);
+            for (Iterator<Clause> itpi = importsList.iterator(); itpi.hasNext();) {
+                Clause pi = itpi.next();
                 boolean matching = false;
-                for (HeaderParser.PathElement pe : exports) {
+                for (Clause pe : exports) {
                     if (pi.getName().equals(pe.getName())) {
                         String evStr = pe.getAttribute(Constants.VERSION_ATTRIBUTE);
                         String ivStr = pi.getAttribute(Constants.VERSION_ATTRIBUTE);
                         Version exported = evStr != null ? Version.parseVersion(evStr) : Version.emptyVersion;
-                        VersionRange imported = ivStr != null ? VersionRange.parse(ivStr) : VersionRange.infiniteRange;
-                        if (imported.isInRange(exported)) {
+                        VersionRange imported = ivStr != null ? VersionRange.parseVersionRange(ivStr) : VersionRange.ANY_VERSION;
+                        if (imported.contains(exported)) {
                             matching = true;
                             break;
                         }
@@ -497,7 +487,7 @@
                 it.remove();
             } else {
                 LOGGER.debug("Refeshing bundle {} ({}) to solve the following optional imports", b.getSymbolicName(), b.getBundleId());
-                for (HeaderParser.PathElement p : importsList) {
+                for (Clause p : importsList) {
                     LOGGER.debug("    {}", p);
                 }
 
diff --git a/karaf/features/core/src/main/java/org/apache/felix/karaf/features/internal/HeaderParser.java b/karaf/features/core/src/main/java/org/apache/felix/karaf/features/internal/HeaderParser.java
deleted file mode 100644
index e06c636..0000000
--- a/karaf/features/core/src/main/java/org/apache/felix/karaf/features/internal/HeaderParser.java
+++ /dev/null
@@ -1,204 +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.felix.karaf.features.internal;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Utility class to parse a standard OSGi header with paths.
- *
- * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
- * @version $Rev: 786132 $, $Date: 2009-06-18 17:47:58 +0200 (Thu, 18 Jun 2009) $
- */
-public final class HeaderParser  {
-
-    // Private constructor for static final class
-    private HeaderParser() {
-    }
-
-    /**
-     * Parse a given OSGi header into a list of paths
-     *
-     * @param header the OSGi header to parse
-     * @return the list of paths extracted from this header
-     */
-    public static List<PathElement> parseHeader(String header) {
-        List<PathElement> elements = new ArrayList<PathElement>();
-        if (header == null || header.trim().length() == 0) {
-            return elements;
-        }
-        String[] clauses = parseDelimitedString(header, ",");
-        for (String clause : clauses) {
-            String[] tokens = clause.split(";");
-            if (tokens.length < 1) {
-                throw new IllegalArgumentException("Invalid header clause: " + clause);
-            }
-            PathElement elem = new PathElement(tokens[0].trim());
-            elements.add(elem);
-            for (int i = 1; i < tokens.length; i++) {
-                int pos = tokens[i].indexOf('=');
-                if (pos != -1) {
-                    if (pos > 0 && tokens[i].charAt(pos - 1) == ':') {
-                        String name = tokens[i].substring(0, pos - 1).trim();
-                        String value = tokens[i].substring(pos + 1).trim();
-                        if (value.startsWith("\"") && value.endsWith("\"")) {
-                            value = value.substring(1, value.length() - 1);
-                        }
-                        elem.addDirective(name, value);
-                    } else {
-                        String name = tokens[i].substring(0, pos).trim();
-                        String value = tokens[i].substring(pos + 1).trim();
-                        if (value.startsWith("\"") && value.endsWith("\"")) {
-                            value = value.substring(1, value.length() - 1);
-                        }
-                        elem.addAttribute(name, value);
-                    }
-                } else {
-                    elem = new PathElement(tokens[i].trim());
-                    elements.add(elem);
-                }
-            }
-        }
-        return elements;
-    }
-
-    /**
-     * Parses delimited string and returns an array containing the tokens. This
-     * parser obeys quotes, so the delimiter character will be ignored if it is
-     * inside of a quote. This method assumes that the quote character is not
-     * included in the set of delimiter characters.
-     * @param value the delimited string to parse.
-     * @param delim the characters delimiting the tokens.
-     * @return an array of string tokens or null if there were no tokens.
-    **/
-    public static String[] parseDelimitedString(String value, String delim)
-    {
-        if (value == null)
-        {
-           value = "";
-        }
-
-        List list = new ArrayList();
-
-        int CHAR = 1;
-        int DELIMITER = 2;
-        int STARTQUOTE = 4;
-        int ENDQUOTE = 8;
-
-        StringBuffer sb = new StringBuffer();
-
-        int expecting = (CHAR | DELIMITER | STARTQUOTE);
-
-        for (int i = 0; i < value.length(); i++)
-        {
-            char c = value.charAt(i);
-
-            boolean isDelimiter = (delim.indexOf(c) >= 0);
-            boolean isQuote = (c == '"');
-
-            if (isDelimiter && ((expecting & DELIMITER) > 0))
-            {
-                list.add(sb.toString().trim());
-                sb.delete(0, sb.length());
-                expecting = (CHAR | DELIMITER | STARTQUOTE);
-            }
-            else if (isQuote && ((expecting & STARTQUOTE) > 0))
-            {
-                sb.append(c);
-                expecting = CHAR | ENDQUOTE;
-            }
-            else if (isQuote && ((expecting & ENDQUOTE) > 0))
-            {
-                sb.append(c);
-                expecting = (CHAR | STARTQUOTE | DELIMITER);
-            }
-            else if ((expecting & CHAR) > 0)
-            {
-                sb.append(c);
-            }
-            else
-            {
-                throw new IllegalArgumentException("Invalid delimited string: " + value);
-            }
-        }
-
-        if (sb.length() > 0)
-        {
-            list.add(sb.toString().trim());
-        }
-
-        return (String[]) list.toArray(new String[list.size()]);
-    }
-
-    public static class PathElement {
-
-        private String path;
-        private Map<String, String> attributes;
-        private Map<String, String> directives;
-
-        public PathElement(String path) {
-            this.path = path;
-            this.attributes = new HashMap<String, String>();
-            this.directives = new HashMap<String, String>();
-        }
-
-        public String getName() {
-            return this.path;
-        }
-
-        public Map<String, String> getAttributes() {
-            return attributes;
-        }
-
-        public String getAttribute(String name) {
-            return attributes.get(name);
-        }
-
-        public void addAttribute(String name, String value) {
-            attributes.put(name, value);
-        }
-
-        public Map<String, String> getDirectives() {
-            return directives;
-        }
-
-        public String getDirective(String name) {
-            return directives.get(name);
-        }
-
-        public void addDirective(String name, String value) {
-            directives.put(name, value);
-        }
-
-        public String toString() {
-            StringBuilder sb = new StringBuilder(this.path);
-            for (Map.Entry<String,String> directive : this.directives.entrySet()) {
-                sb.append(";").append(directive.getKey()).append(":=").append(directive.getValue());
-            }
-            for (Map.Entry<String,String> attribute : this.attributes.entrySet()) {
-                sb.append(";").append(attribute.getKey()).append("=").append(attribute.getValue());
-            }
-            return sb.toString(); 
-        }
-
-    }
-}
diff --git a/karaf/pom.xml b/karaf/pom.xml
index 93c7fcd..5f85582 100644
--- a/karaf/pom.xml
+++ b/karaf/pom.xml
@@ -36,7 +36,6 @@
 
     <modules>
         <module>main</module>
-        <module>commons</module>
         <module>features</module>
         <module>admin</module>
         <module>deployer</module>
@@ -84,6 +83,7 @@
         <felix.osgi.version>1.4.0</felix.osgi.version>
         <felix.plugin.version>2.1.0</felix.plugin.version>
         <felix.prefs.version>1.0.4</felix.prefs.version>
+        <felix.utils.version>1.0.0</felix.utils.version>
         <felix.webconsole.version>3.0.1-SNAPSHOT</felix.webconsole.version>
         <felix.metatype.version>1.0.2</felix.metatype.version>
         <aries.blueprint.version>0.1-incubating</aries.blueprint.version>
@@ -179,11 +179,6 @@
                 <version>${project.version}</version>
             </dependency>
             <dependency>
-                <groupId>org.apache.felix.karaf</groupId>
-                <artifactId>org.apache.felix.karaf.commons</artifactId>
-                <version>${project.version}</version>
-            </dependency>
-            <dependency>
                 <groupId>org.apache.felix.karaf.deployer</groupId>
                 <artifactId>org.apache.felix.karaf.deployer.spring</artifactId>
                 <version>${project.version}</version>
@@ -398,6 +393,11 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.felix</groupId>
+                <artifactId>org.apache.felix.utils</artifactId>
+                <version>${felix.utils.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.felix</groupId>
                 <artifactId>org.apache.felix.webconsole</artifactId>
                 <version>${felix.webconsole.version}</version>
             </dependency>
diff --git a/karaf/shell/dev/pom.xml b/karaf/shell/dev/pom.xml
index 8781ff2..15a4ca2 100644
--- a/karaf/shell/dev/pom.xml
+++ b/karaf/shell/dev/pom.xml
@@ -37,11 +37,6 @@
     </dependency>
 
     <dependency>
-        <groupId>org.apache.felix.karaf</groupId>
-        <artifactId>org.apache.felix.karaf.commons</artifactId>
-    </dependency>
-
-    <dependency>
         <groupId>org.ops4j.pax.url</groupId>
         <artifactId>pax-url-wrap</artifactId>
     </dependency>
@@ -56,7 +51,13 @@
         <groupId>org.apache.felix</groupId>
         <artifactId>org.osgi.compendium</artifactId>
         <scope>provided</scope>
-    </dependency>    
+    </dependency>
+
+    <dependency>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>org.apache.felix.utils</artifactId>
+        <scope>provided</scope>
+    </dependency>
   </dependencies>
 
   <build>
@@ -75,7 +76,10 @@
                           org.apache.felix.karaf.shell.console,
                           *
                       </Import-Package>
-                      <Private-Package>!*</Private-Package>
+                      <Private-Package>
+                          org.apache.felix.utils.version,
+                          !*
+                      </Private-Package>
                       <_versionpolicy>${bnd.version.policy}</_versionpolicy>
                   </instructions>
               </configuration>
diff --git a/karaf/shell/dev/src/main/java/org/apache/felix/karaf/shell/dev/ShowBundleTree.java b/karaf/shell/dev/src/main/java/org/apache/felix/karaf/shell/dev/ShowBundleTree.java
index c461274..5c2cbea 100644
--- a/karaf/shell/dev/src/main/java/org/apache/felix/karaf/shell/dev/ShowBundleTree.java
+++ b/karaf/shell/dev/src/main/java/org/apache/felix/karaf/shell/dev/ShowBundleTree.java
@@ -148,7 +148,7 @@
         boolean foundMatch = false;
         if (exporters != null) {
             for (ExportedPackage ep : exporters) {
-                if (i.getVersion().isInRange(ep.getVersion())) {
+                if (i.getVersion().contains(ep.getVersion())) {
                     if (bundle.equals(ep.getExportingBundle())) {
                         foundMatch = true;
                     } else {
diff --git a/karaf/shell/dev/src/main/java/org/apache/felix/karaf/shell/dev/util/Import.java b/karaf/shell/dev/src/main/java/org/apache/felix/karaf/shell/dev/util/Import.java
index 3215707..66ee9c4 100644
--- a/karaf/shell/dev/src/main/java/org/apache/felix/karaf/shell/dev/util/Import.java
+++ b/karaf/shell/dev/src/main/java/org/apache/felix/karaf/shell/dev/util/Import.java
@@ -19,7 +19,7 @@
 import java.util.LinkedList;
 import java.util.List;
 
-import org.apache.felix.karaf.commons.osgi.VersionRange;
+import org.apache.felix.utils.version.VersionRange;
 
 /**
  * Simple class to model an OSGi Import-Package
@@ -42,7 +42,7 @@
         if (value.contains("version=")) {
             this.version = extractVersion(value);
         } else {
-            this.version = VersionRange.infiniteRange;
+            this.version = VersionRange.ANY_VERSION;
         }
     }
 
@@ -53,9 +53,9 @@
         int begin = value.indexOf("version=") + 8;
         int end = value.indexOf(";", begin);
         if (end < 0) {
-            return VersionRange.parse(unquote(value.substring(begin)));
+            return VersionRange.parseVersionRange(unquote(value.substring(begin)));
         } else {
-            return VersionRange.parse(unquote(value.substring(begin, end)));
+            return VersionRange.parseVersionRange(unquote(value.substring(begin, end)));
         }
     }
 
diff --git a/karaf/shell/dev/src/test/java/org/apache/felix/karaf/shell/dev/util/ImportTest.java b/karaf/shell/dev/src/test/java/org/apache/felix/karaf/shell/dev/util/ImportTest.java
index 8a2aa14..f8edd13 100644
--- a/karaf/shell/dev/src/test/java/org/apache/felix/karaf/shell/dev/util/ImportTest.java
+++ b/karaf/shell/dev/src/test/java/org/apache/felix/karaf/shell/dev/util/ImportTest.java
@@ -21,7 +21,7 @@
 import static junit.framework.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import org.apache.felix.karaf.commons.osgi.VersionRange;
+import org.apache.felix.utils.version.VersionRange;
 import org.junit.Test;
 
 /**
@@ -39,7 +39,7 @@
     public void createWithPackageNameAndVersion() {
         Import i = new Import("org.wip.bar;version=\"2.0.0\"");
         assertEquals("org.wip.bar", i.getPackage());
-        assertEquals(VersionRange.parse("2.0.0"), i.getVersion());
+        assertEquals(VersionRange.parseVersionRange("2.0.0"), i.getVersion());
     }
 
     @Test