felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1667030 - in /felix/trunk/scr: bnd.bnd pom.xml src/main/java/org/apache/felix/scr/impl/Activator.java src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java src/test/java/org/apache/felix/scr/integration/ExtenderTest.java
Date Mon, 16 Mar 2015 15:10:47 GMT
Author: djencks
Date: Mon Mar 16 15:10:46 2015
New Revision: 1667030

URL: http://svn.apache.org/r1667030
Log:
FELIX-4412 wire only to bundles that don't require an extender or are wired to us

Added:
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ExtenderTest.java   (with
props)
Modified:
    felix/trunk/scr/bnd.bnd
    felix/trunk/scr/pom.xml
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java

Modified: felix/trunk/scr/bnd.bnd
URL: http://svn.apache.org/viewvc/felix/trunk/scr/bnd.bnd?rev=1667030&r1=1667029&r2=1667030&view=diff
==============================================================================
--- felix/trunk/scr/bnd.bnd (original)
+++ felix/trunk/scr/bnd.bnd Mon Mar 16 15:10:46 2015
@@ -41,6 +41,7 @@ Import-Package: \
  org.osgi.framework;version="[1.6,2)", \
  org.osgi.service.log;version="[1.3,2)";resolution:=optional, \
  org.osgi.service.packageadmin;version="[1.2,2)";resolution:=optional, \
+ org.osgi.framework.wiring;version="[1.0,2)", \
  *
 
 DynamicImport-Package: \

Modified: felix/trunk/scr/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scr/pom.xml?rev=1667030&r1=1667029&r2=1667030&view=diff
==============================================================================
--- felix/trunk/scr/pom.xml (original)
+++ felix/trunk/scr/pom.xml Mon Mar 16 15:10:46 2015
@@ -398,6 +398,17 @@
                 <dependency>
                     <groupId>org.apache.felix</groupId>
                     <artifactId>org.apache.felix.framework</artifactId>
+                    <version>4.6.0</version>
+                    <scope>test</scope>
+                </dependency>
+            </dependencies>
+        </profile>
+        <profile>
+            <id>felix-R5</id>
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.felix</groupId>
+                    <artifactId>org.apache.felix.framework</artifactId>
                     <version>4.0.3</version>
                     <scope>test</scope>
                 </dependency>

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java?rev=1667030&r1=1667029&r2=1667030&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java Mon Mar 16 15:10:46
2015
@@ -22,6 +22,7 @@ package org.apache.felix.scr.impl;
 import java.io.PrintStream;
 import java.text.MessageFormat;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -34,6 +35,10 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
+import org.osgi.namespace.extender.ExtenderNamespace;
 import org.osgi.service.component.ComponentConstants;
 import org.osgi.service.component.runtime.ServiceComponentRuntime;
 import org.osgi.service.log.LogService;
@@ -280,7 +285,7 @@ public class Activator extends AbstractE
      */
     private void loadComponents( Bundle bundle )
     {
-        if ( bundle.getHeaders().get( "Service-Component" ) == null )
+        if ( bundle.getHeaders().get( ComponentConstants.SERVICE_COMPONENT ) == null )
         {
             // no components in the bundle, abandon
             return;
@@ -294,6 +299,31 @@ public class Activator extends AbstractE
                 new Object[] {bundle.getSymbolicName(), bundle.getBundleId()}, null );
             return;
         }
+        
+        //Examine bundle for extender requirement; if present check if bundle is wired to
us.
+        BundleWiring wiring = bundle.adapt(BundleWiring.class);
+        List<BundleWire> extenderWires = wiring.getRequiredWires(ExtenderNamespace.EXTENDER_NAMESPACE);
+        try 
+        {
+            for (BundleWire wire: extenderWires) 
+            {
+                if (ComponentConstants.COMPONENT_CAPABILITY_NAME.equals(wire.getCapability().getAttributes().get(ExtenderNamespace.EXTENDER_NAMESPACE)))
+                {
+                    if (!m_bundle.adapt(BundleRevision.class).equals(wire.getProvider()))
+                    {
+                        log( LogService.LOG_DEBUG, m_bundle, "Bundle {0}/{1} wired to a different
extender: {2}",
+                            new Object[] {bundle.getSymbolicName(), bundle.getBundleId(),
wire.getProvider().getSymbolicName()}, null );
+                        return;
+                    }
+                    break;
+                }
+            }
+        } 
+        catch (NoSuchMethodError e) 
+        {
+            log( LogService.LOG_DEBUG, m_bundle, "Cannot determine bundle wiring on pre R6
framework",
+                null, null );
+        }
 
         // FELIX-1666 method is called for the LAZY_ACTIVATION event and
         // the started event. Both events cause this method to be called;

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java?rev=1667030&r1=1667029&r2=1667030&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
Mon Mar 16 15:10:46 2015
@@ -76,6 +76,7 @@ import org.osgi.framework.FrameworkEvent
 import org.osgi.framework.FrameworkListener;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
+import org.osgi.namespace.extender.ExtenderNamespace;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.component.ComponentConstants;
 import org.osgi.service.component.ComponentFactory;
@@ -686,6 +687,7 @@ public abstract class ComponentTestBase
                 .set(Constants.BUNDLE_VERSION, version)
                 .set(Constants.IMPORT_PACKAGE, componentPackage)
                 .set("Service-Component", "OSGI-INF/components.xml")
+                .set(Constants.REQUIRE_CAPABILITY, ExtenderNamespace.EXTENDER_NAMESPACE +
";filter:=\"(&(osgi.extender=osgi.component)(version>=1.3)(!(version>=2.0)))\"")
                 .build(withBnd());
 
         try

Added: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ExtenderTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ExtenderTest.java?rev=1667030&view=auto
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ExtenderTest.java (added)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ExtenderTest.java Mon Mar
16 15:10:46 2015
@@ -0,0 +1,63 @@
+/*
+ * 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.scr.integration;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
+import org.osgi.namespace.extender.ExtenderNamespace;
+import org.osgi.service.component.ComponentConstants;
+
+@RunWith(JUnit4TestRunner.class)
+public class ExtenderTest extends ComponentTestBase
+{
+    static
+    {
+        // uncomment to enable debugging of this test class
+//          paxRunnerVmOption = DEBUG_VM_OPTION;
+    }
+    
+    @Test
+    public void testWired() throws BundleException 
+    {
+        if (isAtLeastR5())
+        {
+            BundleWiring scrWiring = bundle.adapt(BundleWiring.class);
+            List<BundleWire> extenderWires = scrWiring.getRequiredWires(ExtenderNamespace.EXTENDER_NAMESPACE);
+            boolean wired = false;
+            for (BundleWire wire: extenderWires) 
+            {
+                if (ComponentConstants.COMPONENT_CAPABILITY_NAME.equals(wire.getCapability().getAttributes().get(ExtenderNamespace.EXTENDER_NAMESPACE)))
+                {
+                    Assert.assertEquals("Not wired to us", "org.apache.felix.scr", wire.getProviderWiring().getBundle().getSymbolicName());
+                    wired = true;
+                    break;
+                }
+            }
+            Assert.assertTrue("should be wired to us", wired);
+        }
+    }
+
+}

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ExtenderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ExtenderTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ExtenderTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message