felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tjwat...@apache.org
Subject svn commit: r1782373 - in /felix/trunk/resolver/src: main/java/org/apache/felix/resolver/ test/java/org/apache/felix/resolver/test/ test/java/org/apache/felix/resolver/test/util/
Date Thu, 09 Feb 2017 17:44:03 GMT
Author: tjwatson
Date: Thu Feb  9 17:44:03 2017
New Revision: 1782373

URL: http://svn.apache.org/viewvc?rev=1782373&view=rev
Log:
[FELIX-5514] Issues with substituted exports with require bundle

Modify solution to avoid adding API to wiring implementations

Removed:
    felix/trunk/resolver/src/main/java/org/apache/felix/resolver/FelixWiring.java
Modified:
    felix/trunk/resolver/src/main/java/org/apache/felix/resolver/FelixResolveContext.java
    felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java
    felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/ResolverTest.java
    felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/util/ResolveContextImpl.java

Modified: felix/trunk/resolver/src/main/java/org/apache/felix/resolver/FelixResolveContext.java
URL: http://svn.apache.org/viewvc/felix/trunk/resolver/src/main/java/org/apache/felix/resolver/FelixResolveContext.java?rev=1782373&r1=1782372&r2=1782373&view=diff
==============================================================================
--- felix/trunk/resolver/src/main/java/org/apache/felix/resolver/FelixResolveContext.java
(original)
+++ felix/trunk/resolver/src/main/java/org/apache/felix/resolver/FelixResolveContext.java
Thu Feb  9 17:44:03 2017
@@ -18,7 +18,11 @@
  */package org.apache.felix.resolver;
 
 import java.util.Collection;
+
+import org.osgi.framework.namespace.PackageNamespace;
 import org.osgi.resource.Resource;
+import org.osgi.resource.Wire;
+import org.osgi.resource.Wiring;
 
 public interface FelixResolveContext
 {
@@ -41,4 +45,19 @@ public interface FelixResolveContext
      * resources. The returned collection may be unmodifiable.
      */
     public Collection<Resource> getOndemandResources(Resource host);
+
+    /**
+     * Returns the subset of {@link Wiring#getRequiredResourceWires(String) require wires}
+     * that provide wires to {@link Capability capabilities} which substitute capabilities
+     * of the given wiring. For example, when a {@link PackageNamespace package} name is
both
+     * provided and required by the same resource. If the package requirement is resolved
+     * to a capability hosted by a different wiring then the package capability is
+     * considered to be substituted.
+     *
+     * @param wiring the wiring to get the substitution wires from
+     * @return A collection containing a snapshot of the substitution {@link Wire}s
+     * for the {@link Requirement requirements} of this wiring, or an empty list
+     * if this wiring has no substitution wires.
+     */
+    public Collection<Wire> getSubstitutionWires(Wiring wiring);
 }

Modified: felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java?rev=1782373&r1=1782372&r2=1782373&view=diff
==============================================================================
--- felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java (original)
+++ felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java Thu Feb
 9 17:44:03 2017
@@ -1608,9 +1608,10 @@ public class ResolverImpl implements Res
         if (wiring != null)
         {
             Collection<Wire> substitutionWires;
-            if (wiring instanceof FelixWiring)
+            if (session.getContext() instanceof FelixResolveContext)
             {
-                substitutionWires = ((FelixWiring) wiring).getSubstitutionWires();
+                substitutionWires = ((FelixResolveContext) session.getContext()).getSubstitutionWires(
+                    wiring);
             }
             else
             {

Modified: felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/ResolverTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/ResolverTest.java?rev=1782373&r1=1782372&r2=1782373&view=diff
==============================================================================
--- felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/ResolverTest.java (original)
+++ felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/ResolverTest.java Thu
Feb  9 17:44:03 2017
@@ -33,7 +33,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.felix.resolver.FelixWiring;
 import org.apache.felix.resolver.Logger;
 import org.apache.felix.resolver.ResolverImpl;
 import org.apache.felix.resolver.test.util.BundleCapability;
@@ -59,6 +58,7 @@ 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.ResolveContext;
 import org.osgi.service.resolver.Resolver;
 
 public class ResolverTest
@@ -860,101 +860,56 @@ public class ResolverTest
     @Test
     public void testScenario17_1() throws Exception
     {
-        Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
-        Map<Requirement, List<Capability>> candMap = new HashMap<Requirement,
List<Capability>>();
-        Map<String, Resource> resources = new HashMap<String, Resource>();
-        populateScenario17(false, false, wirings, candMap, resources);
+        ResolveContext rci = populateScenario17(false, false, false);
         ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG), 1);
-        ResolveContextImpl rci = new ResolveContextImpl(
-            Collections.<Resource, Wiring> emptyMap(), candMap,
-            Collections.singletonList((Resource) resources.get("requiresMisc")),
-            Collections.<Resource> emptyList());
-
         resolver.resolve(rci);
     }
 
     @Test
     public void testScenario17_2() throws Exception
     {
-        Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
-        Map<Requirement, List<Capability>> candMap = new HashMap<Requirement,
List<Capability>>();
-        Map<String, Resource> resources = new HashMap<String, Resource>();
-        populateScenario17(false, false, wirings, candMap, resources);
+        ResolveContext rci = populateScenario17(false, false, true);
         ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG), 1);
-        ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap,
-            Collections.singletonList((Resource) resources.get("requiresMisc")),
-            Collections.<Resource> emptyList());
-
         resolver.resolve(rci);
     }
 
     @Test
     public void testScenario17_3() throws Exception
     {
-        Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
-        Map<Requirement, List<Capability>> candMap = new HashMap<Requirement,
List<Capability>>();
-        Map<String, Resource> resources = new HashMap<String, Resource>();
-        populateScenario17(true, false, wirings, candMap, resources);
+        ResolveContext rci = populateScenario17(true, false, false);
         ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG), 1);
-        ResolveContextImpl rci = new ResolveContextImpl(
-            Collections.<Resource, Wiring> emptyMap(), candMap,
-            Collections.singletonList((Resource) resources.get("requiresMisc")),
-            Collections.<Resource> emptyList());
-
         resolver.resolve(rci);
     }
 
     @Test
     public void testScenario17_4() throws Exception
     {
-        Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
-        Map<Requirement, List<Capability>> candMap = new HashMap<Requirement,
List<Capability>>();
-        Map<String, Resource> resources = new HashMap<String, Resource>();
-        populateScenario17(true, false, wirings, candMap, resources);
+        ResolveContext rci = populateScenario17(true, false, true);
         ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG), 1);
-        ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap,
-            Collections.singletonList((Resource) resources.get("requiresMisc")),
-            Collections.<Resource> emptyList());
-
         resolver.resolve(rci);
     }
 
     @Test
     public void testScenario17_5() throws Exception
     {
-        Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
-        Map<Requirement, List<Capability>> candMap = new HashMap<Requirement,
List<Capability>>();
-        Map<String, Resource> resources = new HashMap<String, Resource>();
-        populateScenario17(false, true, wirings, candMap, resources);
+        ResolveContext rci = populateScenario17(false, true, true);
         ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG), 1);
-        ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap,
-            Collections.singletonList((Resource) resources.get("requiresMisc")),
-            Collections.<Resource> emptyList());
-
         resolver.resolve(rci);
     }
 
     @Test
     public void testScenario17_6() throws Exception
     {
-        Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
-        Map<Requirement, List<Capability>> candMap = new HashMap<Requirement,
List<Capability>>();
-        Map<String, Resource> resources = new HashMap<String, Resource>();
-        populateScenario17(true, true, wirings, candMap, resources);
+        ResolveContext rci = populateScenario17(true, true, true);
         ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG), 1);
-        ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap,
-            Collections.singletonList((Resource) resources.get("requiresMisc")),
-            Collections.<Resource> emptyList());
-
         resolver.resolve(rci);
     }
 
-    private void populateScenario17(boolean realSubstitute, boolean felixWiring,
-        Map<Resource, Wiring> wirings,
-        Map<Requirement, List<Capability>> candMap, Map<String, Resource>
resources)
+    private ResolveContext populateScenario17(boolean realSubstitute,
+        boolean felixResolveContext, boolean existingWirings)
     {
+        Map<Requirement, List<Capability>> candMap = new HashMap<Requirement,
List<Capability>>();
         ResourceImpl core = new ResourceImpl("core");
-        resources.put("core", core);
         Capability core_pkgCap = addCap(core, PackageNamespace.PACKAGE_NAMESPACE, "pkg1");
         Capability core_bundleCap = addCap(core, BundleNamespace.BUNDLE_NAMESPACE,
             "core");
@@ -962,7 +917,6 @@ public class ResolverTest
             "pkg1");
 
         ResourceImpl misc = new ResourceImpl("misc");
-        resources.put("misc", misc);
         Capability misc_pkgCap = addCap(misc, PackageNamespace.PACKAGE_NAMESPACE, "pkg1");
         Capability misc_bundleCap = addCap(misc, BundleNamespace.BUNDLE_NAMESPACE,
             "misc");
@@ -970,21 +924,18 @@ public class ResolverTest
             "core");
 
         ResourceImpl importsCore = new ResourceImpl("importsCore");
-        resources.put("ImportsCore", importsCore);
         Capability importsCore_pkgCap = addCap(importsCore,
             PackageNamespace.PACKAGE_NAMESPACE, "pkg2", "pkg1");
         Requirement importsCore_pkgReq = addReq(importsCore,
             PackageNamespace.PACKAGE_NAMESPACE, "pkg1");
 
         ResourceImpl requiresMisc = new ResourceImpl("requiresMisc");
-        resources.put("requiresMisc", requiresMisc);
         Requirement requiresMisc_pkgReq = addReq(requiresMisc,
             PackageNamespace.PACKAGE_NAMESPACE, "pkg2");
         Requirement requiresMisc_bundleReq = addReq(requiresMisc,
             BundleNamespace.BUNDLE_NAMESPACE, "misc");
 
         ResourceImpl substitutesCore = new ResourceImpl("substitutesCore");
-        resources.put("substitutesCore", substitutesCore);
         Capability substitutesCore_pkgCap = addCap(substitutesCore,
             PackageNamespace.PACKAGE_NAMESPACE, "pkg1");
 
@@ -1006,46 +957,46 @@ public class ResolverTest
         wires.put(misc, new ArrayList<Wire>());
         wires.get(misc).add(new SimpleWire(misc_bundleReq, core_bundleCap));
 
-        Map<Resource, List<Wire>> invertedWires = new HashMap<Resource, List<Wire>>();
-        invertedWires.put(substitutesCore, new ArrayList<Wire>());
-        if (realSubstitute)
-        {
-            invertedWires.get(substitutesCore).add(
-                new SimpleWire(core_pkgReq, substitutesCore_pkgCap));
-        }
-        invertedWires.put(core, new ArrayList<Wire>());
-        invertedWires.get(core).add(new SimpleWire(misc_bundleReq, core_bundleCap));
-        invertedWires.put(misc, new ArrayList<Wire>());
-
-        wirings.put(substitutesCore, new SimpleWiring(substitutesCore,
-            Arrays.asList(substitutesCore_pkgCap), wires, invertedWires));
-
-        Wiring coreWiring;
-        if (felixWiring)
+        Wiring coreWiring = null;
+        Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
+        if (existingWirings)
         {
+            Map<Resource, List<Wire>> invertedWires = new HashMap<Resource,
List<Wire>>();
+            invertedWires.put(substitutesCore, new ArrayList<Wire>());
             if (realSubstitute)
             {
-                coreWiring = new SimpleFelixWiring(core,
-                    Arrays.asList(core_bundleCap, core_pkgCap), wires, invertedWires,
-                    Arrays.<Wire> asList(
-                        new SimpleWire(core_pkgReq, substitutesCore_pkgCap)));
+                invertedWires.get(substitutesCore).add(
+                    new SimpleWire(core_pkgReq, substitutesCore_pkgCap));
             }
-            else
+            invertedWires.put(core, new ArrayList<Wire>());
+            invertedWires.get(core).add(new SimpleWire(misc_bundleReq, core_bundleCap));
+            invertedWires.put(misc, new ArrayList<Wire>());
+
+            wirings.put(substitutesCore, new SimpleWiring(substitutesCore,
+                Arrays.asList(substitutesCore_pkgCap), wires, invertedWires));
+
+            coreWiring = new SimpleWiring(core,
+                Arrays.asList(core_bundleCap, core_pkgCap), wires, invertedWires);
+            wirings.put(core, coreWiring);
+            wirings.put(misc, new SimpleWiring(misc,
+                Arrays.asList(misc_bundleCap, misc_pkgCap), wires, invertedWires));
+        }
+        Collection<Resource> mandatory = Collections.<Resource> singletonList(requiresMisc);
+        if (felixResolveContext) {
+            Map<Wiring, Collection<Wire>> substitutions = new HashMap<Wiring,
Collection<Wire>>();
+            if (realSubstitute && coreWiring != null)
             {
-                coreWiring = new SimpleFelixWiring(core,
-                    Arrays.asList(core_bundleCap, core_pkgCap), wires, invertedWires,
-                    Collections.<Wire> emptyList());
+                substitutions.put(coreWiring, Arrays.<Wire> asList(
+                    new SimpleWire(core_pkgReq, substitutesCore_pkgCap)));
             }
+            return new ResolveContextImpl.FelixResolveContextImpl(wirings, candMap,
+                mandatory, Collections.<Resource> emptyList(), substitutions);
         }
         else
         {
-            coreWiring = new SimpleWiring(core,
-                Arrays.asList(core_bundleCap, core_pkgCap), wires, invertedWires);
+            return new ResolveContextImpl(wirings, candMap, mandatory,
+                Collections.<Resource> emptyList());
         }
-
-        wirings.put(core, coreWiring);
-        wirings.put(misc, new SimpleWiring(misc,
-            Arrays.asList(misc_bundleCap, misc_pkgCap), wires, invertedWires));
     }
 
     private static String getResourceName(Resource r)
@@ -1482,23 +1433,6 @@ public class ResolverTest
         }
     }
 
-    private static class SimpleFelixWiring extends SimpleWiring implements FelixWiring
-    {
-        final Collection<Wire> substitutionWires;
-
-        public SimpleFelixWiring(Resource resource, List<Capability> resourceCapabilities,
Map<Resource, List<Wire>> wires, Map<Resource, List<Wire>> invertedWires,
Collection<Wire> substitutionWires)
-        {
-            super(resource, resourceCapabilities, wires, invertedWires);
-            this.substitutionWires = substitutionWires;
-        }
-
-        public Collection<Wire> getSubstitutionWires()
-        {
-            return substitutionWires;
-        }
-
-    }
-
     private static class SimpleWiring implements Wiring {
         final Resource resource;
         final Map<Resource, List<Wire>> wires;

Modified: felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/util/ResolveContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/util/ResolveContextImpl.java?rev=1782373&r1=1782372&r2=1782373&view=diff
==============================================================================
--- felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/util/ResolveContextImpl.java
(original)
+++ felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/util/ResolveContextImpl.java
Thu Feb  9 17:44:03 2017
@@ -20,11 +20,15 @@ package org.apache.felix.resolver.test.u
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+
+import org.apache.felix.resolver.FelixResolveContext;
 import org.osgi.resource.Capability;
 import org.osgi.resource.Requirement;
 import org.osgi.resource.Resource;
+import org.osgi.resource.Wire;
 import org.osgi.resource.Wiring;
 import org.osgi.service.resolver.HostedCapability;
 import org.osgi.service.resolver.ResolveContext;
@@ -88,4 +92,27 @@ public class ResolveContextImpl extends
     {
         return m_wirings;
     }
+
+    public static class FelixResolveContextImpl extends ResolveContextImpl implements FelixResolveContext
+    {
+        private final Map<Wiring, Collection<Wire>> m_substitutions;
+
+        public FelixResolveContextImpl(Map<Resource, Wiring> wirings, Map<Requirement,
List<Capability>> candMap, Collection<Resource> mandatory, Collection<Resource>
optional, Map<Wiring, Collection<Wire>> substitutions)
+        {
+            super(wirings, candMap, mandatory, optional);
+            this.m_substitutions = substitutions;
+        }
+
+        public Collection<Resource> getOndemandResources(Resource host)
+        {
+            return Collections.emptyList();
+        }
+
+        public Collection<Wire> getSubstitutionWires(Wiring wiring)
+        {
+            Collection<Wire> result = m_substitutions.get(wiring);
+            return result == null ? Collections.<Wire> emptyList() : result;
+        }
+
+    }
 }
\ No newline at end of file



Mime
View raw message