felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1667220 - in /felix/trunk/framework: ./ src/main/java/org/apache/felix/framework/ src/main/java/org/apache/felix/framework/capabilityset/ src/main/java/org/apache/felix/framework/resolver/ src/main/java/org/apache/felix/framework/util/
Date Tue, 17 Mar 2015 09:39:10 GMT
Author: gnodet
Date: Tue Mar 17 09:39:09 2015
New Revision: 1667220

URL: http://svn.apache.org/r1667220
Log:
[FELIX-4525] Integrate the standalone resolver in the framework

Removed:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolveContext.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolverWire.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolverWireImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ShadowList.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/SimpleHostedCapability.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/WrappedCapability.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/WrappedRequirement.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/WrappedRevision.java
Modified:
    felix/trunk/framework/pom.xml
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/DTOFactory.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/Logger.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/ResolveContextImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolveException.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java

Modified: felix/trunk/framework/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/framework/pom.xml?rev=1667220&r1=1667219&r2=1667220&view=diff
==============================================================================
--- felix/trunk/framework/pom.xml (original)
+++ felix/trunk/framework/pom.xml Tue Mar 17 09:39:09 2015
@@ -27,8 +27,7 @@
   <packaging>bundle</packaging>
   <name>Apache Felix Framework</name>
   <artifactId>org.apache.felix.framework</artifactId>
-  <version>4.7.0-SNAPSHOT</version>
-
+  <version>4.9.0-SNAPSHOT</version>
   <properties>
     <dollar>$</dollar>
   </properties>
@@ -68,7 +67,7 @@
                 org.osgi.util.tracker,
                 org.osgi.dto
             </Export-Package>
-            <Private-Package>org.apache.felix.framework.*</Private-Package>
+            <Private-Package>org.apache.felix.framework.*, org.apache.felix.resolver.*</Private-Package>
             <Import-Package>!*</Import-Package>
           </instructions>
         </configuration>
@@ -131,6 +130,12 @@
        <scope>provided</scope>
     </dependency>
     <dependency>
+       <groupId>org.apache.felix</groupId>
+       <artifactId>org.apache.felix.resolver</artifactId>
+       <version>1.1.0-SNAPSHOT</version>
+       <scope>provided</scope>
+    </dependency>
+    <dependency>
         <groupId>org.ow2.asm</groupId>
         <artifactId>asm-all</artifactId>
         <version>4.2</version>

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java?rev=1667220&r1=1667219&r2=1667220&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java Tue Mar 17 09:39:09 2015
@@ -1023,6 +1023,11 @@ class BundleImpl implements Bundle, Bund
                 AdminPermission.LIFECYCLE));
         }
 
+        Map headers = getCurrentLocalizedHeader(Locale.getDefault().toString());
+
+        // Uninstall the bundle.
+        getFramework().uninstallBundle(this);
+
         // After a bundle is uninstalled, the spec says getHeaders() should
         // return the localized headers for the default locale at the time of
         // of uninstall. So, let's clear the existing header cache to throw
@@ -1035,13 +1040,10 @@ class BundleImpl implements Bundle, Bund
         {
             if (m_uninstalledHeaders == null)
             {
-                m_uninstalledHeaders = getCurrentLocalizedHeader(Locale.getDefault().toString());
+                m_uninstalledHeaders = headers;
                 m_cachedHeaders.clear();
             }
         }
-
-        // Uninstall the bundle.
-        getFramework().uninstallBundle(this);
     }
 
     private static final SecurityManagerEx m_smEx = new SecurityManagerEx();

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java?rev=1667220&r1=1667219&r2=1667220&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java Tue Mar 17 09:39:09 2015
@@ -674,6 +674,6 @@ public class BundleRevisionImpl implemen
     @Override
     public String toString()
     {
-        return m_id;
+        return m_bundle.toString() + "(R " + m_id + ")";
     }
 }

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java?rev=1667220&r1=1667219&r2=1667220&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java Tue Mar 17 09:39:09 2015
@@ -44,7 +44,6 @@ import java.util.TreeSet;
 import org.apache.felix.framework.cache.Content;
 import org.apache.felix.framework.cache.JarContent;
 import org.apache.felix.framework.capabilityset.SimpleFilter;
-import org.apache.felix.framework.resolver.ResolveException;
 import org.apache.felix.framework.resolver.ResourceNotFoundException;
 import org.apache.felix.framework.util.CompoundEnumeration;
 import org.apache.felix.framework.util.FelixConstants;
@@ -75,6 +74,7 @@ import org.osgi.framework.wiring.BundleW
 import org.osgi.resource.Capability;
 import org.osgi.resource.Requirement;
 import org.osgi.resource.Wire;
+import org.osgi.service.resolver.ResolutionException;
 
 public class BundleWiringImpl implements BundleWiring
 {
@@ -1210,7 +1210,7 @@ public class BundleWiringImpl implements
             {
                 provider = m_resolver.resolve(m_revision, pkgName);
             }
-            catch (ResolveException ex)
+            catch (ResolutionException ex)
             {
                 // Ignore this since it is likely normal.
             }
@@ -1635,7 +1635,7 @@ public class BundleWiringImpl implements
         {
             provider = m_resolver.resolve(m_revision, pkgName);
         }
-        catch (ResolveException ex)
+        catch (ResolutionException ex)
         {
             // Ignore this since it is likely normal.
         }
@@ -2810,7 +2810,7 @@ public class BundleWiringImpl implements
             }
 
             String exporter = (exporters.isEmpty())
-                ? null : exporters.iterator().next().getRevision().getBundle().toString();
+                ? null : exporters.iterator().next().toString();
 
             StringBuffer sb = new StringBuffer("*** Class '");
             sb.append(name);
@@ -2855,7 +2855,7 @@ public class BundleWiringImpl implements
                 // Ignore
             }
 
-            String exporter = exports.iterator().next().getRevision().getBundle().toString();
+            String exporter = exports.iterator().next().toString();
 
             StringBuffer sb = new StringBuffer("*** Class '");
             sb.append(name);

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/DTOFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/DTOFactory.java?rev=1667220&r1=1667219&r2=1667220&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/DTOFactory.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/DTOFactory.java Tue Mar 17 09:39:09 2015
@@ -313,10 +313,6 @@ public class DTOFactory
 
     private static ServiceReferenceDTO[] createServiceReferenceDTOArray(Bundle bundle)
     {
-        BundleContext ctx = bundle.getBundleContext();
-        if (ctx == null)
-            return null;
-
         ServiceReference<?>[] svcs = bundle.getRegisteredServices();
         if (svcs == null)
             return new ServiceReferenceDTO[0];

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java?rev=1667220&r1=1667219&r2=1667220&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java Tue Mar 17 09:39:09 2015
@@ -57,7 +57,6 @@ import org.apache.felix.framework.cache.
 import org.apache.felix.framework.capabilityset.CapabilitySet;
 import org.apache.felix.framework.capabilityset.SimpleFilter;
 import org.apache.felix.framework.ext.SecurityProvider;
-import org.apache.felix.framework.resolver.ResolveException;
 import org.apache.felix.framework.util.EventDispatcher;
 import org.apache.felix.framework.util.FelixConstants;
 import org.apache.felix.framework.util.ListenerInfo;
@@ -102,6 +101,7 @@ import org.osgi.framework.wiring.BundleW
 import org.osgi.framework.wiring.FrameworkWiring;
 import org.osgi.resource.Requirement;
 import org.osgi.service.packageadmin.ExportedPackage;
+import org.osgi.service.resolver.ResolutionException;
 
 public class Felix extends BundleImpl implements Framework
 {
@@ -412,8 +412,16 @@ public class Felix extends BundleImpl im
         // Create default bundle stream handler.
         m_bundleStreamHandler = new URLHandlersBundleStreamHandler(this);
 
+        // Create service registry.
+        m_registry = new ServiceRegistry(m_logger, new ServiceRegistryCallbacks() {
+            public void serviceChanged(ServiceEvent event, Dictionary oldProps)
+            {
+                fireServiceEvent(event, oldProps);
+            }
+        });
+
         // Create a resolver and its state.
-        m_resolver = new StatefulResolver(this);
+        m_resolver = new StatefulResolver(this, m_registry);
 
         // Create the extension manager, which we will use as the
         // revision for the system bundle.
@@ -429,14 +437,6 @@ public class Felix extends BundleImpl im
             throw new RuntimeException(ex.getMessage());
         }
 
-        // Create service registry.
-        m_registry = new ServiceRegistry(m_logger, new ServiceRegistryCallbacks() {
-            public void serviceChanged(ServiceEvent event, Dictionary oldProps)
-            {
-                fireServiceEvent(event, oldProps);
-            }
-        });
-
         // Create event dispatcher.
         m_dispatcher = new EventDispatcher(m_logger, m_registry);
 
@@ -734,12 +734,12 @@ public class Felix extends BundleImpl im
                         Collections.singleton(adapt(BundleRevision.class)),
                         Collections.EMPTY_SET);
                 }
-                catch (ResolveException ex)
+                catch (ResolutionException ex)
                 {
                     // This should never happen.
                     throw new BundleException(
                         "Unresolved constraint in System Bundle:"
-                        + ex.getRequirement());
+                        + ex.getUnresolvedRequirements());
                 }
 
                 // Reload the cached bundles before creating and starting the
@@ -833,6 +833,7 @@ public class Felix extends BundleImpl im
                 }
 
                 // Start services
+                m_resolver.start();
                 m_fwkWiring.start();
                 m_fwkStartLevel.start();
 
@@ -4062,7 +4063,7 @@ public class Felix extends BundleImpl im
                         }
                     }
                 }
-                catch (ResolveException ex)
+                catch (ResolutionException ex)
                 {
                     result = false;
                 }
@@ -4087,19 +4088,11 @@ public class Felix extends BundleImpl im
         {
             m_resolver.resolve(Collections.singleton(revision), Collections.EMPTY_SET);
         }
-        catch (ResolveException ex)
+        catch (ResolutionException ex)
         {
-            if (ex.getRevision() != null)
-            {
-                Bundle b = ex.getRevision().getBundle();
-                throw new BundleException(
-                    "Unresolved constraint in bundle "
-                    + b + ": " + ex.getMessage(), BundleException.RESOLVE_ERROR);
-            }
-            else
-            {
-                throw new BundleException(ex.getMessage(), BundleException.RESOLVE_ERROR);
-            }
+            throw new BundleException(ex.getMessage() +
+                " Unresolved requirements: " + ex.getUnresolvedRequirements(),
+                BundleException.RESOLVE_ERROR);
         }
     }
 

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/Logger.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/Logger.java?rev=1667220&r1=1667219&r2=1667220&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/Logger.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/Logger.java Tue Mar 17 09:39:09 2015
@@ -20,7 +20,14 @@ package org.apache.felix.framework;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import org.osgi.framework.*;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
 
 /**
  * <p>
@@ -41,14 +48,9 @@ import org.osgi.framework.*;
  * the log service's method to avoid a dependency on the log interface.
  * </p>
 **/
-public class Logger implements ServiceListener
+public class Logger extends org.apache.felix.resolver.Logger implements ServiceListener
 {
-    public static final int LOG_ERROR = 1;
-    public static final int LOG_WARNING = 2;
-    public static final int LOG_INFO = 3;
-    public static final int LOG_DEBUG = 4;
-
-    private int m_logLevel = 1;
+    // TODO see if this class can be cleaned up a little more
     private BundleContext m_context = null;
 
     private final static int LOGGER_OBJECT_IDX = 0;
@@ -58,42 +60,23 @@ public class Logger implements ServiceLi
 
     public Logger()
     {
-    }
-
-    public final synchronized void setLogLevel(int i)
-    {
-        m_logLevel = i;
-    }
-
-    public final synchronized int getLogLevel()
-    {
-        return m_logLevel;
+        super(LOG_ERROR);
     }
 
     protected void setSystemBundleContext(BundleContext context)
     {
         // TODO: Find a way to log to a log service inside the framework.
         // The issue is that we log messages while holding framework
-        // internal locks -- hence, when a log service calls back into 
-        // the framework (e.g., by loading a class) we might deadlock. 
+        // internal locks -- hence, when a log service calls back into
+        // the framework (e.g., by loading a class) we might deadlock.
         // One instance of this problem is tracked in FELIX-536.
         // For now we just disable logging to log services inside the
-        // framework. 
+        // framework.
 
         // m_context = context;
         // startListeningForLogService();
     }
 
-    public final void log(int level, String msg)
-    {
-        _log(null, null, level, msg, null);
-    }
-
-    public final void log(int level, String msg, Throwable throwable)
-    {
-        _log(null, null, level, msg, throwable);
-    }
-
     public final void log(ServiceReference sr, int level, String msg)
     {
         _log(null, sr, level, msg, null);
@@ -168,7 +151,7 @@ public class Logger implements ServiceLi
         // more conservative locking here, but let's be optimistic.
         Object[] logger = m_logger;
 
-        if (m_logLevel >= level)
+        if (getLogLevel() >= level)
         {
             // Use the log service if available.
             if (logger != null)

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/ResolveContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/ResolveContextImpl.java?rev=1667220&r1=1667219&r2=1667220&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/ResolveContextImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/ResolveContextImpl.java Tue Mar 17 09:39:09 2015
@@ -26,29 +26,32 @@ import java.util.Map;
 
 import org.apache.felix.framework.StatefulResolver.ResolverHookRecord;
 import org.apache.felix.framework.resolver.CandidateComparator;
-import org.apache.felix.framework.resolver.HostedCapability;
-import org.apache.felix.framework.resolver.ResolveContext;
-import org.apache.felix.framework.resolver.ResolveException;
+import org.apache.felix.resolver.FelixResolveContext;
 import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleRequirement;
 import org.osgi.framework.wiring.BundleRevision;
-import org.osgi.framework.wiring.BundleWiring;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+import org.osgi.resource.Wiring;
+import org.osgi.service.resolver.HostedCapability;
+import org.osgi.service.resolver.ResolveContext;
 
 /**
  *
  * @author rickhall
  */
-public class ResolveContextImpl extends ResolveContext
+public class ResolveContextImpl extends ResolveContext implements FelixResolveContext
 {
     private final StatefulResolver m_state;
-    private final Map<BundleRevision, BundleWiring> m_wirings;
+    private final Map<Resource, Wiring> m_wirings;
     private final ResolverHookRecord m_resolverHookrecord;
     private final Collection<BundleRevision> m_mandatory;
     private final Collection<BundleRevision> m_optional;
     private final Collection<BundleRevision> m_ondemand;
 
     ResolveContextImpl(
-        StatefulResolver state, Map<BundleRevision, BundleWiring> wirings,
+        StatefulResolver state, Map<Resource, Wiring> wirings,
         ResolverHookRecord resolverHookRecord, Collection<BundleRevision> mandatory,
         Collection<BundleRevision> optional, Collection<BundleRevision> ondemand)
     {
@@ -61,30 +64,41 @@ public class ResolveContextImpl extends
     }
 
     @Override
-    public Collection<BundleRevision> getMandatoryRevisions()
+    public Collection<Resource> getMandatoryResources()
     {
-        return new ArrayList<BundleRevision>(m_mandatory);
+        return new ArrayList<Resource>(m_mandatory);
     }
 
     @Override
-    public Collection<BundleRevision> getOptionalRevisions()
+    public Collection<Resource> getOptionalResources()
     {
-        return new ArrayList<BundleRevision>(m_optional);
+        return new ArrayList<Resource>(m_optional);
     }
 
-    public Collection<BundleRevision> getOndemandRevisions()
+    public Collection<Resource> getOndemandResources(Resource host)
     {
-        return new ArrayList<BundleRevision>(m_ondemand);
+        return new ArrayList<Resource>(m_ondemand);
     }
 
     @Override
-    public List<BundleCapability> findProviders(BundleRequirement br, boolean obeyMandatory)
+    public List<Capability> findProviders(Requirement br)
     {
-        return m_state.findProvidersInternal(m_resolverHookrecord, br, obeyMandatory, true);
+        if (!(br instanceof BundleRequirement))
+            throw new IllegalStateException("Expected a BundleRequirement");
+
+        List<BundleCapability> result = m_state.findProvidersInternal(
+            m_resolverHookrecord, br, true, true);
+
+        // Casting the result to a List of Capability.
+        // TODO Can we do this without the strang double-cast?
+        @SuppressWarnings("unchecked")
+        List<Capability> caps =
+            (List<Capability>) (List<? extends Capability>) result;
+        return caps;
     }
 
     @Override
-    public int insertHostedCapability(List<BundleCapability> caps, HostedCapability hc)
+    public int insertHostedCapability(List<Capability> caps, HostedCapability hc)
     {
         int idx = Collections.binarySearch(caps, hc, new CandidateComparator());
         if (idx < 0)
@@ -96,19 +110,14 @@ public class ResolveContextImpl extends
     }
 
     @Override
-    public boolean isEffective(BundleRequirement br)
+    public boolean isEffective(Requirement br)
     {
         return m_state.isEffective(br);
     }
 
     @Override
-    public Map<BundleRevision, BundleWiring> getWirings()
+    public Map<Resource, Wiring> getWirings()
     {
         return m_wirings;
     }
-
-    public void checkNativeLibraries(BundleRevision rev) throws ResolveException
-    {
-        m_state.checkNativeLibraries(rev);
-    }
 }
\ No newline at end of file

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java?rev=1667220&r1=1667219&r2=1667220&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java Tue Mar 17 09:39:09 2015
@@ -42,7 +42,6 @@ import org.osgi.framework.ServiceExcepti
 import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
-import org.osgi.framework.wiring.BundleCapability;
 
 public class ServiceRegistry
 {

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java?rev=1667220&r1=1667219&r2=1667220&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java Tue Mar 17 09:39:09 2015
@@ -36,14 +36,12 @@ import org.apache.felix.framework.capabi
 import org.apache.felix.framework.capabilityset.SimpleFilter;
 import org.apache.felix.framework.resolver.CandidateComparator;
 import org.apache.felix.framework.resolver.ResolveException;
-import org.apache.felix.framework.resolver.Resolver;
-import org.apache.felix.framework.resolver.ResolverImpl;
-import org.apache.felix.framework.resolver.ResolverWire;
 import org.apache.felix.framework.util.ShrinkableCollection;
 import org.apache.felix.framework.util.Util;
 import org.apache.felix.framework.util.manifestparser.NativeLibrary;
 import org.apache.felix.framework.wiring.BundleRequirementImpl;
 import org.apache.felix.framework.wiring.BundleWireImpl;
+import org.apache.felix.resolver.ResolverImpl;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleEvent;
 import org.osgi.framework.BundleException;
@@ -60,12 +58,19 @@ import org.osgi.framework.wiring.BundleR
 import org.osgi.framework.wiring.BundleWire;
 import org.osgi.framework.wiring.BundleWiring;
 import org.osgi.resource.Requirement;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Resource;
+import org.osgi.resource.Wire;
+import org.osgi.resource.Wiring;
+import org.osgi.service.resolver.ResolutionException;
+import org.osgi.service.resolver.Resolver;
 
 class StatefulResolver
 {
     private final Logger m_logger;
     private final Felix m_felix;
-    private final Resolver m_resolver;
+    private final ServiceRegistry m_registry;
+    private final ResolverImpl m_resolver;
     private boolean m_isResolving = false;
 
     // Set of all revisions.
@@ -83,9 +88,10 @@ class StatefulResolver
     // Parsed framework environments
     private final Set<String> m_fwkExecEnvSet;
 
-    StatefulResolver(Felix felix)
+    StatefulResolver(Felix felix, ServiceRegistry registry)
     {
         m_felix = felix;
+        m_registry = registry;
         m_logger = m_felix.getLogger();
         m_resolver = new ResolverImpl(m_logger);
 
@@ -113,6 +119,14 @@ class StatefulResolver
         m_capSets.put(BundleRevision.HOST_NAMESPACE,  new CapabilitySet(indices, true));
     }
 
+    void start()
+    {
+        m_registry.registerService(m_felix._getBundleContext(),
+                new String[] { Resolver.class.getName() },
+                m_resolver,
+                null);
+    }
+
     synchronized void addRevision(BundleRevision br)
     {
         // Always attempt to remove the revision, since
@@ -165,7 +179,7 @@ class StatefulResolver
         }
     }
 
-    boolean isEffective(BundleRequirement req)
+    boolean isEffective(Requirement req)
     {
         String effective = req.getDirectives().get(Constants.EFFECTIVE_DIRECTIVE);
         return ((effective == null) || effective.equals(Constants.EFFECTIVE_RESOLVE));
@@ -212,24 +226,29 @@ class StatefulResolver
             }
 
             // Find the matching candidates.
-            Set<BundleCapability> matches = capSet.match(sf, obeyMandatory);
+            Set<Capability> matches = capSet.match(sf, obeyMandatory);
             // Filter matching candidates.
-            for (BundleCapability cap : matches)
+            for (Capability cap : matches)
             {
+                if (!(cap instanceof BundleCapability))
+                    continue;
+
+                BundleCapability bcap = (BundleCapability) cap;
+
                 // Filter according to security.
-                if (invokeHooksAndSecurity && filteredBySecurity((BundleRequirement)req, cap))
+                if (invokeHooksAndSecurity && filteredBySecurity((BundleRequirement)req, bcap))
                 {
                     continue;
                 }
                 // Filter already resolved hosts, since we don't support
                 // dynamic attachment of fragments.
                 if (req.getNamespace().equals(BundleRevision.HOST_NAMESPACE)
-                    && (cap.getRevision().getWiring() != null))
+                    && (bcap.getRevision().getWiring() != null))
                 {
                     continue;
                 }
 
-                result.add(cap);
+                result.add(bcap);
             }
         }
 
@@ -341,7 +360,7 @@ class StatefulResolver
     void resolve(
         Set<BundleRevision> mandatory,
         Set<BundleRevision> optional)
-        throws ResolveException, BundleException
+        throws ResolutionException, BundleException
     {
         // Acquire global lock.
         boolean locked = m_felix.acquireGlobalLock();
@@ -360,7 +379,7 @@ class StatefulResolver
         }
         m_isResolving = true;
 
-        Map<BundleRevision, List<ResolverWire>> wireMap = null;
+        Map<Resource, List<Wire>> wireMap = null;
         try
         {
             // Make our own copy of revisions.
@@ -405,7 +424,7 @@ class StatefulResolver
 
             // Catch any resolve exception to rethrow later because
             // we may need to call end() on resolver hooks.
-            ResolveException rethrow = null;
+            ResolutionException rethrow = null;
             try
             {
                 // Resolve the revision.
@@ -418,7 +437,7 @@ class StatefulResolver
                         optional,
                         getFragments()));
             }
-            catch (ResolveException ex)
+            catch (ResolutionException ex)
             {
                 rethrow = ex;
             }
@@ -447,7 +466,7 @@ class StatefulResolver
     }
 
     BundleRevision resolve(BundleRevision revision, String pkgName)
-        throws ResolveException, BundleException
+        throws ResolutionException, BundleException
     {
         BundleRevision provider = null;
 
@@ -475,7 +494,7 @@ class StatefulResolver
             }
             m_isResolving = true;
 
-            Map<BundleRevision, List<ResolverWire>> wireMap = null;
+            Map<Resource, List<Wire>> wireMap = null;
             try
             {
                 // Double check to make sure that someone hasn't beaten us to
@@ -496,20 +515,74 @@ class StatefulResolver
 
                     // Catch any resolve exception to rethrow later because
                     // we may need to call end() on resolver hooks.
-                    ResolveException rethrow = null;
+                    ResolutionException rethrow = null;
                     try
                     {
+                        List<BundleRequirement> dynamics =
+                                Util.getDynamicRequirements(revision.getWiring().getRequirements(null));
+
+                        // Loop through the importer's dynamic requirements to determine if
+                        // there is a matching one for the package from which we want to
+                        // load a class.
+                        Map<String, Object> attrs = Collections.singletonMap(
+                                BundleRevision.PACKAGE_NAMESPACE, (Object) pkgName);
+                        BundleRequirementImpl req = new BundleRequirementImpl(
+                                revision,
+                                BundleRevision.PACKAGE_NAMESPACE,
+                                Collections.EMPTY_MAP,
+                                attrs);
+                        List<BundleCapability> candidates = findProvidersInternal(record, req, false, true);
+
+                        // Try to find a dynamic requirement that matches the capabilities.
+                        BundleRequirementImpl dynReq = null;
+                        for (int dynIdx = 0;
+                             (candidates.size() > 0) && (dynReq == null) && (dynIdx < dynamics.size());
+                             dynIdx++)
+                        {
+                            for (Iterator<BundleCapability> itCand = candidates.iterator();
+                                 (dynReq == null) && itCand.hasNext(); )
+                            {
+                                Capability cap = itCand.next();
+                                if (CapabilitySet.matches(
+                                        cap,
+                                        ((BundleRequirementImpl) dynamics.get(dynIdx)).getFilter()))
+                                {
+                                    dynReq = (BundleRequirementImpl) dynamics.get(dynIdx);
+                                }
+                            }
+                        }
+
+                        // If we found a matching dynamic requirement, then filter out
+                        // any candidates that do not match it.
+                        if (dynReq != null)
+                        {
+                            for (Iterator<BundleCapability> itCand = candidates.iterator();
+                                 itCand.hasNext(); )
+                            {
+                                Capability cap = itCand.next();
+                                if (!CapabilitySet.matches(
+                                        cap, dynReq.getFilter()))
+                                {
+                                    itCand.remove();
+                                }
+                            }
+                        }
+                        else
+                        {
+                            candidates.clear();
+                        }
+
                         wireMap = m_resolver.resolve(
                             new ResolveContextImpl(
                                 this,
                                 getWirings(),
                                 record,
-                                Collections.EMPTY_LIST,
-                                Collections.EMPTY_LIST,
+                                Collections.<BundleRevision>emptyList(),
+                                Collections.<BundleRevision>emptyList(),
                                 getFragments()),
-                            revision, pkgName);
+                            revision, dynReq, new ArrayList<Capability>(candidates));
                     }
-                    catch (ResolveException ex)
+                    catch (ResolutionException ex)
                     {
                         rethrow = ex;
                     }
@@ -525,8 +598,8 @@ class StatefulResolver
 
                     if ((wireMap != null) && wireMap.containsKey(revision))
                     {
-                        List<ResolverWire> dynamicWires = wireMap.remove(revision);
-                        ResolverWire dynamicWire = dynamicWires.get(0);
+                        List<Wire> dynamicWires = wireMap.remove(revision);
+                        Wire dynamicWire = dynamicWires.get(0);
 
                         // Mark all revisions as resolved.
                         markResolvedRevisions(wireMap);
@@ -534,22 +607,35 @@ class StatefulResolver
                         // Dynamically add new wire to importing revision.
                         if (dynamicWire != null)
                         {
-                            BundleWire bw = new BundleWireImpl(
-                                dynamicWire.getRequirer(),
-                                dynamicWire.getRequirement(),
-                                dynamicWire.getProvider(),
-                                dynamicWire.getCapability());
-
-                            m_felix.getDependencies().addDependent(bw);
-
-                            ((BundleWiringImpl) revision.getWiring()).addDynamicWire(bw);
-
-                            m_felix.getLogger().log(
-                                Logger.LOG_DEBUG,
-                                "DYNAMIC WIRE: " + dynamicWire);
+                            // TODO is a rw already a BundleWire?
+                            // TODO can we optimize this?
+                            if (dynamicWire.getRequirer() instanceof BundleRevision &&
+                                dynamicWire.getRequirement() instanceof BundleRequirement &&
+                                dynamicWire.getProvider() instanceof BundleRevision &&
+                                dynamicWire.getCapability() instanceof BundleCapability)
+                            {
+                                BundleRevision dwRequirer = (BundleRevision) dynamicWire.getRequirer();
+                                BundleRequirement dwRequirement = (BundleRequirement) dynamicWire.getRequirement();
+                                BundleRevision dwProvider = (BundleRevision) dynamicWire.getProvider();
+                                BundleCapability dwCapability = (BundleCapability) dynamicWire.getCapability();
+
+                                BundleWire bw = new BundleWireImpl(
+                                    dwRequirer,
+                                    dwRequirement,
+                                    dwProvider,
+                                    dwCapability);
+
+                                m_felix.getDependencies().addDependent(bw);
+
+                                ((BundleWiringImpl) revision.getWiring()).addDynamicWire(bw);
+
+                                m_felix.getLogger().log(
+                                    Logger.LOG_DEBUG,
+                                    "DYNAMIC WIRE: " + dynamicWire);
 
-                            provider = ((BundleWiringImpl) revision.getWiring())
-                                .getImportedPackageSource(pkgName);
+                                provider = ((BundleWiringImpl) revision.getWiring())
+                                    .getImportedPackageSource(pkgName);
+                            }
                         }
                     }
                 }
@@ -570,7 +656,7 @@ class StatefulResolver
 
     private ResolverHookRecord prepareResolverHooks(
         Set<BundleRevision> mandatory, Set<BundleRevision> optional)
-        throws BundleException
+        throws BundleException, ResolutionException
     {
         // This map maps the hook factory service to the actual hook objects. It
         // needs to be a map that preserves insertion order to ensure that we call
@@ -829,7 +915,7 @@ class StatefulResolver
             for (Iterator<BundleCapability> itCand = candidates.iterator();
                 (dynReq == null) && itCand.hasNext(); )
             {
-                BundleCapability cap = itCand.next();
+                Capability cap = itCand.next();
                 if (CapabilitySet.matches(
                     cap,
                     ((BundleRequirementImpl) dynamics.get(dynIdx)).getFilter()))
@@ -846,7 +932,7 @@ class StatefulResolver
             for (Iterator<BundleCapability> itCand = candidates.iterator();
                 itCand.hasNext(); )
             {
-                BundleCapability cap = itCand.next();
+                Capability cap = itCand.next();
                 if (!CapabilitySet.matches(
                     cap, dynReq.getFilter()))
                 {
@@ -862,7 +948,7 @@ class StatefulResolver
         return !candidates.isEmpty();
     }
 
-    private void markResolvedRevisions(Map<BundleRevision, List<ResolverWire>> wireMap)
+    private void markResolvedRevisions(Map<Resource, List<Wire>> wireMap)
         throws ResolveException
     {
         boolean debugLog = m_felix.getLogger().getLogLevel() >= Logger.LOG_DEBUG;
@@ -878,26 +964,28 @@ class StatefulResolver
         {
             // First pass: Loop through the wire map to find the host wires
             // for any fragments and map a host to all of its fragments.
-            Map<BundleRevision, List<BundleRevision>> hosts =
-                new HashMap<BundleRevision, List<BundleRevision>>();
-            for (Entry<BundleRevision, List<ResolverWire>> entry : wireMap.entrySet())
+            Map<Resource, List<BundleRevision>> hosts =
+                new HashMap<Resource, List<BundleRevision>>();
+            for (Entry<Resource, List<Wire>> entry : wireMap.entrySet())
             {
-                BundleRevision revision = entry.getKey();
-                List<ResolverWire> wires = entry.getValue();
+                Resource revision = entry.getKey();
+                List<Wire> wires = entry.getValue();
 
                 if (Util.isFragment(revision))
                 {
-                    for (Iterator<ResolverWire> itWires = wires.iterator();
+                    for (Iterator<Wire> itWires = wires.iterator();
                         itWires.hasNext(); )
                     {
-                        ResolverWire w = itWires.next();
+                        Wire w = itWires.next();
                         List<BundleRevision> fragments = hosts.get(w.getProvider());
                         if (fragments == null)
                         {
                             fragments = new ArrayList<BundleRevision>();
                             hosts.put(w.getProvider(), fragments);
                         }
-                        fragments.add(w.getRequirer());
+
+                        if (w.getRequirer() instanceof BundleRevision)
+                            fragments.add((BundleRevision) w.getRequirer());
                     }
                 }
             }
@@ -911,10 +999,14 @@ class StatefulResolver
             // all wirings.
             Map<BundleRevision, BundleWiringImpl> wirings =
                 new HashMap<BundleRevision, BundleWiringImpl>(wireMap.size());
-            for (Entry<BundleRevision, List<ResolverWire>> entry : wireMap.entrySet())
+            for (Entry<Resource, List<Wire>> entry : wireMap.entrySet())
             {
-                BundleRevision revision = entry.getKey();
-                List<ResolverWire> resolverWires = entry.getValue();
+                Resource resource = entry.getKey();
+                if (!(resource instanceof BundleRevision))
+                    continue;
+
+                BundleRevision revision = (BundleRevision) resource;
+                List<Wire> resolverWires = entry.getValue();
 
                 List<BundleWire> bundleWires =
                     new ArrayList<BundleWire>(resolverWires.size());
@@ -936,13 +1028,28 @@ class StatefulResolver
                     new HashMap<String, BundleRevision>();
                 Map<String, List<BundleRevision>> requiredPkgs =
                     new HashMap<String, List<BundleRevision>>();
-                for (ResolverWire rw : resolverWires)
+                for (Wire rw : resolverWires)
                 {
+                    // TODO is a rw already a BundleWire?
+                    // TODO can we optimize this?
+                    if (!(rw.getRequirer() instanceof BundleRevision))
+                        continue;
+                    BundleRevision requirer = (BundleRevision) rw.getRequirer();
+                    if (!(rw.getRequirement() instanceof BundleRequirement))
+                        continue;
+                    BundleRequirement requirement = (BundleRequirement) rw.getRequirement();
+                    if (!(rw.getProvider() instanceof BundleRevision))
+                        continue;
+                    BundleRevision provider = (BundleRevision) rw.getProvider();
+                    if (!(rw.getCapability() instanceof BundleCapability))
+                        continue;
+                    BundleCapability capability = (BundleCapability) rw.getCapability();
+
                     BundleWire bw = new BundleWireImpl(
-                        rw.getRequirer(),
-                        rw.getRequirement(),
-                        rw.getProvider(),
-                        rw.getCapability());
+                        requirer,
+                        requirement,
+                        provider,
+                        capability);
                     bundleWires.add(bw);
 
                     if (Util.isFragment(revision))
@@ -961,19 +1068,19 @@ class StatefulResolver
                             m_felix.getLogger().log(Logger.LOG_DEBUG, "WIRE: " + rw.toString());
                         }
 
-                        if (rw.getCapability().getNamespace()
+                        if (capability.getNamespace()
                             .equals(BundleRevision.PACKAGE_NAMESPACE))
                         {
                             importedPkgs.put(
-                                (String) rw.getCapability().getAttributes()
+                                (String) capability.getAttributes()
                                     .get(BundleRevision.PACKAGE_NAMESPACE),
-                                rw.getProvider());
+                                provider);
                         }
-                        else if (rw.getCapability().getNamespace()
+                        else if (capability.getNamespace()
                             .equals(BundleRevision.BUNDLE_NAMESPACE))
                         {
                             Set<String> pkgs = calculateExportedAndReexportedPackages(
-                                    rw.getProvider(),
+                                    provider,
                                     wireMap,
                                     new HashSet<String>(),
                                     new HashSet<BundleRevision>());
@@ -985,7 +1092,7 @@ class StatefulResolver
                                     revs = new ArrayList<BundleRevision>();
                                     requiredPkgs.put(pkg, revs);
                                 }
-                                revs.add(rw.getProvider());
+                                revs.add(provider);
                             }
                         }
                     }
@@ -1110,17 +1217,21 @@ class StatefulResolver
         }
     }
 
-    private void fireResolvedEvents(Map<BundleRevision, List<ResolverWire>> wireMap)
+    private void fireResolvedEvents(Map<Resource, List<Wire>> wireMap)
     {
         if (wireMap != null)
         {
-            Iterator<Entry<BundleRevision, List<ResolverWire>>> iter =
+            Iterator<Entry<Resource, List<Wire>>> iter =
                 wireMap.entrySet().iterator();
             // Iterate over the map to fire necessary RESOLVED events.
             while (iter.hasNext())
             {
-                Entry<BundleRevision, List<ResolverWire>> entry = iter.next();
-                BundleRevision revision = entry.getKey();
+                Entry<Resource, List<Wire>> entry = iter.next();
+                Resource resource = entry.getKey();
+                if (!(resource instanceof BundleRevision))
+                    continue;
+
+                BundleRevision revision = (BundleRevision) resource;
 
                 // Fire RESOLVED events for all fragments.
                 List<BundleRevision> fragments =
@@ -1137,7 +1248,7 @@ class StatefulResolver
 
     private static Set<String> calculateExportedAndReexportedPackages(
         BundleRevision br,
-        Map<BundleRevision, List<ResolverWire>> wireMap,
+        Map<Resource, List<Wire>> wireMap,
         Set<String> pkgs,
         Set<BundleRevision> cycles)
     {
@@ -1159,7 +1270,7 @@ class StatefulResolver
             // visibility, since we need to include those packages too.
             if (br.getWiring() == null)
             {
-                for (ResolverWire rw : wireMap.get(br))
+                for (Wire rw : wireMap.get(br))
                 {
                     if (rw.getCapability().getNamespace().equals(
                         BundleRevision.BUNDLE_NAMESPACE))
@@ -1169,7 +1280,8 @@ class StatefulResolver
                         if ((dir != null) && (dir.equals(Constants.VISIBILITY_REEXPORT)))
                         {
                             calculateExportedAndReexportedPackages(
-                                rw.getProvider(),
+                                // TODO need to fix the cast
+                                (BundleRevision) rw.getProvider(),
                                 wireMap,
                                 pkgs,
                                 cycles);
@@ -1526,9 +1638,9 @@ class StatefulResolver
         return unresolved;
     }
 
-    private synchronized Map<BundleRevision, BundleWiring> getWirings()
+    private synchronized Map<Resource, Wiring> getWirings()
     {
-        Map<BundleRevision, BundleWiring> wirings = new HashMap<BundleRevision, BundleWiring>();
+        Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
 
         for (BundleRevision revision : m_revisions)
         {

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java?rev=1667220&r1=1667219&r2=1667220&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java Tue Mar 17 09:39:09 2015
@@ -39,11 +39,12 @@ import org.apache.felix.framework.util.V
 import org.apache.felix.framework.wiring.BundleCapabilityImpl;
 import org.osgi.framework.Version;
 import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.resource.Capability;
 
 public class CapabilitySet
 {
     private final Map<String, Map<Object, Set<BundleCapability>>> m_indices;
-    private final Set<BundleCapability> m_capSet = new HashSet<BundleCapability>();
+    private final Set<Capability> m_capSet = new HashSet<Capability>();
     private final static SecureAction m_secureAction = new SecureAction();
 
     public void dump()
@@ -180,17 +181,17 @@ public class CapabilitySet
         }
     }
 
-    public Set<BundleCapability> match(SimpleFilter sf, boolean obeyMandatory)
+    public Set<Capability> match(SimpleFilter sf, boolean obeyMandatory)
     {
-        Set<BundleCapability> matches = match(m_capSet, sf);
+        Set<Capability> matches = match(m_capSet, sf);
         return (obeyMandatory)
             ? matchMandatory(matches, sf)
             : matches;
     }
 
-    private Set<BundleCapability> match(Set<BundleCapability> caps, SimpleFilter sf)
+    private Set<Capability> match(Set<Capability> caps, SimpleFilter sf)
     {
-        Set<BundleCapability> matches = new HashSet<BundleCapability>();
+        Set<Capability> matches = new HashSet<Capability>();
 
         if (sf.getOperation() == SimpleFilter.MATCH_ALL)
         {
@@ -247,9 +248,9 @@ public class CapabilitySet
             }
             else
             {
-                for (Iterator<BundleCapability> it = caps.iterator(); it.hasNext(); )
+                for (Iterator<Capability> it = caps.iterator(); it.hasNext(); )
                 {
-                    BundleCapability cap = it.next();
+                    Capability cap = it.next();
                     Object lhs = cap.getAttributes().get(sf.getName());
                     if (lhs != null)
                     {
@@ -265,12 +266,12 @@ public class CapabilitySet
         return matches;
     }
 
-    public static boolean matches(BundleCapability cap, SimpleFilter sf)
+    public static boolean matches(Capability cap, SimpleFilter sf)
     {
         return matchesInternal(cap, sf) && matchMandatory(cap, sf);
     }
 
-    private static boolean matchesInternal(BundleCapability cap, SimpleFilter sf)
+    private static boolean matchesInternal(Capability cap, SimpleFilter sf)
     {
         boolean matched = true;
 
@@ -324,12 +325,12 @@ public class CapabilitySet
         return matched;
     }
 
-    private static Set<BundleCapability> matchMandatory(
-        Set<BundleCapability> caps, SimpleFilter sf)
+    private static Set<Capability> matchMandatory(
+        Set<Capability> caps, SimpleFilter sf)
     {
-        for (Iterator<BundleCapability> it = caps.iterator(); it.hasNext(); )
+        for (Iterator<Capability> it = caps.iterator(); it.hasNext(); )
         {
-            BundleCapability cap = it.next();
+            Capability cap = it.next();
             if (!matchMandatory(cap, sf))
             {
                 it.remove();
@@ -338,7 +339,7 @@ public class CapabilitySet
         return caps;
     }
 
-    private static boolean matchMandatory(BundleCapability cap, SimpleFilter sf)
+    private static boolean matchMandatory(Capability cap, SimpleFilter sf)
     {
         Map<String, Object> attrs = cap.getAttributes();
         for (Entry<String, Object> entry : attrs.entrySet())
@@ -468,7 +469,7 @@ public class CapabilitySet
                         return false;
                     }
                 case SimpleFilter.APPROX :
-                    return compareApproximate(((Comparable) lhs), rhs);
+                    return compareApproximate(lhs, rhs);
                 case SimpleFilter.SUBSTRING :
                     return SimpleFilter.compareSubstring((List<String>) rhs, (String) lhs);
                 default:

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java?rev=1667220&r1=1667219&r2=1667220&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java Tue Mar 17 09:39:09 2015
@@ -19,29 +19,42 @@
 package org.apache.felix.framework.resolver;
 
 import java.util.Comparator;
+
 import org.apache.felix.framework.wiring.BundleCapabilityImpl;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Version;
 import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.resource.Capability;
 
-public class CandidateComparator implements Comparator<BundleCapability>
+public class CandidateComparator implements Comparator<Capability>
 {
-    public int compare(BundleCapability cap1, BundleCapability cap2)
+    public int compare(Capability cap1, Capability cap2)
     {
         // First check resolved state, since resolved capabilities have priority
         // over unresolved ones. Compare in reverse order since we want to sort
         // in descending order.
         int c = 0;
-        if ((cap1.getRevision().getWiring() != null)
-            && (cap2.getRevision().getWiring() == null))
-        {
-            c = -1;
-        }
-        else if ((cap1.getRevision().getWiring() == null)
-            && (cap2.getRevision().getWiring() != null))
+
+        BundleCapability bcap1 = null;
+        BundleCapability bcap2 = null;
+
+        if (cap1 instanceof BundleCapability &&
+            cap2 instanceof BundleCapability)
         {
-            c = 1;
+            bcap1 = (BundleCapability) cap1;
+            bcap2 = (BundleCapability) cap2;
+
+            if ((bcap1.getRevision().getWiring() != null)
+                && (bcap2.getRevision().getWiring() == null))
+            {
+                c = -1;
+            }
+            else if ((bcap1.getRevision().getWiring() == null)
+                && (bcap2.getRevision().getWiring() != null))
+            {
+                c = 1;
+            }
         }
 
         // Compare revision capabilities.
@@ -82,15 +95,15 @@ public class CandidateComparator impleme
         }
 
         // Finally, compare bundle identity.
-        if (c == 0)
+        if (c == 0 && bcap1 != null && bcap2 != null)
         {
-            if (cap1.getRevision().getBundle().getBundleId() <
-                cap2.getRevision().getBundle().getBundleId())
+            if (bcap1.getRevision().getBundle().getBundleId() <
+                bcap2.getRevision().getBundle().getBundleId())
             {
                 c = -1;
             }
-            else if (cap1.getRevision().getBundle().getBundleId() >
-                cap2.getRevision().getBundle().getBundleId())
+            else if (bcap1.getRevision().getBundle().getBundleId() >
+                bcap2.getRevision().getBundle().getBundleId())
             {
                 c = 1;
             }

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolveException.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolveException.java?rev=1667220&r1=1667219&r2=1667220&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolveException.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolveException.java Tue Mar 17 09:39:09 2015
@@ -20,8 +20,9 @@ package org.apache.felix.framework.resol
 
 import org.osgi.framework.wiring.BundleRequirement;
 import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.service.resolver.ResolutionException;
 
-public class ResolveException extends RuntimeException
+public class ResolveException extends ResolutionException
 {
     private final BundleRevision m_revision;
     private final BundleRequirement m_req;

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java?rev=1667220&r1=1667219&r2=1667220&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java Tue Mar 17 09:39:09 2015
@@ -18,7 +18,11 @@
  */
 package org.apache.felix.framework.util;
 
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.URL;
 import java.security.SecureRandom;
 import java.util.ArrayList;
@@ -31,9 +35,6 @@ import java.util.Properties;
 import java.util.Set;
 
 import org.apache.felix.framework.Logger;
-import org.apache.felix.framework.capabilityset.CapabilitySet;
-import org.apache.felix.framework.wiring.BundleCapabilityImpl;
-import org.apache.felix.framework.wiring.BundleRequirementImpl;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
@@ -42,6 +43,7 @@ import org.osgi.framework.wiring.BundleR
 import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.framework.wiring.BundleWire;
 import org.osgi.framework.wiring.BundleWiring;
+import org.osgi.resource.Resource;
 
 public class Util
 {
@@ -665,7 +667,7 @@ public class Util
                 {
                     if (entry.getKey().equalsIgnoreCase(Constants.SINGLETON_DIRECTIVE))
                     {
-                        return Boolean.valueOf((String) entry.getValue());
+                        return Boolean.valueOf(entry.getValue());
                     }
                 }
                 // Can only have one bundle capability, so break.
@@ -687,6 +689,14 @@ public class Util
         return ((revision.getTypes() & BundleRevision.TYPE_FRAGMENT) > 0);
     }
 
+    public static boolean isFragment(Resource resource)
+    {
+        if (resource instanceof BundleRevision)
+            return isFragment((BundleRevision) resource);
+        else
+            return false;
+    }
+
     public static List<BundleRevision> getFragments(BundleWiring wiring)
     {
         List<BundleRevision> fragments = Collections.EMPTY_LIST;



Mime
View raw message