felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1747831 [1/2] - in /felix/trunk/scr/src: main/java/org/apache/felix/scr/impl/manager/ test/java/org/apache/felix/scr/integration/
Date Sat, 11 Jun 2016 01:14:36 GMT
Author: djencks
Date: Sat Jun 11 01:14:36 2016
New Revision: 1747831

URL: http://svn.apache.org/viewvc?rev=1747831&view=rev
Log:
FELIX-5270 Don't set bundle location on configurations

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/RegionConfigurationSupport.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentDisposeTest.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationComponentFactoryTest.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/LocationTest.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/PersistentComponentFactoryTest.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/RegionConfigurationSupport.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/RegionConfigurationSupport.java?rev=1747831&r1=1747830&r2=1747831&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/RegionConfigurationSupport.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/RegionConfigurationSupport.java Sat Jun 11 01:14:36 2016
@@ -28,6 +28,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.felix.scr.impl.ComponentRegistry;
 import org.apache.felix.scr.impl.helper.SimpleLogger;
 import org.apache.felix.scr.impl.metadata.TargetedPID;
 import org.osgi.framework.Bundle;
@@ -46,18 +47,15 @@ import org.osgi.service.log.LogService;
 public abstract class RegionConfigurationSupport implements ConfigurationListener
 {
 
-    // the name of the ConfigurationAdmin service
-    public static final String CONFIGURATION_ADMIN = "org.osgi.service.cm.ConfigurationAdmin";
-
     private final SimpleLogger logger;
+    private final ServiceReference<ConfigurationAdmin> caReference;
     private final BundleContext caBundleContext;
     private final Long bundleId;
-    
-    private final AtomicInteger reference = new AtomicInteger(1);
+
+    private final AtomicInteger referenceCount = new AtomicInteger( 1 );
 
     // the service m_registration of the ConfigurationListener service
     private ServiceRegistration<ConfigurationListener> m_registration;
-    
 
     /**
      * 
@@ -67,47 +65,48 @@ public abstract class RegionConfiguratio
     public RegionConfigurationSupport(SimpleLogger logger, ServiceReference<ConfigurationAdmin> reference)
     {
         this.logger = logger;
+        this.caReference = reference;
         Bundle bundle = reference.getBundle();
         this.bundleId = bundle.getBundleId();
         this.caBundleContext = bundle.getBundleContext();
     }
-    
-    public void start() 
+
+    public void start()
     {
         // register as listener for configurations
         Dictionary<String, Object> props = new Hashtable<String, Object>();
-        props.put(Constants.SERVICE_DESCRIPTION, "Declarative Services Configuration Support Listener");
-        props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
-        this.m_registration = caBundleContext.registerService(ConfigurationListener.class, this, props);
+        props.put( Constants.SERVICE_DESCRIPTION, "Declarative Services Configuration Support Listener" );
+        props.put( Constants.SERVICE_VENDOR, "The Apache Software Foundation" );
+        this.m_registration = caBundleContext.registerService( ConfigurationListener.class, this, props );
 
     }
 
-	public Long getBundleId() 
-	{
-		return bundleId;
-	}
-
-	public boolean reference() 
-	{
-		if (reference.get() == 0)
-		{
-			return false;
-		}
-		reference.incrementAndGet();
-		return true;
-	}
-
-	public boolean dereference() 
-	{		
-		if ( reference.decrementAndGet() ==0 )
-		{
+    public Long getBundleId()
+    {
+        return bundleId;
+    }
+
+    public boolean reference()
+    {
+        if ( referenceCount.get() == 0 )
+        {
+            return false;
+        }
+        referenceCount.incrementAndGet();
+        return true;
+    }
+
+    public boolean dereference()
+    {
+        if ( referenceCount.decrementAndGet() == 0 )
+        {
             this.m_registration.unregister();
-            this.m_registration = null;		
+            this.m_registration = null;
             return true;
-		}
-		return false;
-	}
-	
+        }
+        return false;
+    }
+
     /**
      * The return value is only relevant for the call from {@link #configurationEvent(ConfigurationEvent)}
      * in the case of a deleted configuration which is not a factory configuration!
@@ -116,7 +115,7 @@ public abstract class RegionConfiguratio
     {
 
         // 112.7 configure unless configuration not required
-        if (!holder.getComponentMetadata().isConfigurationIgnored())
+        if ( !holder.getComponentMetadata().isConfigurationIgnored() )
         {
             final BundleContext bundleContext = holder.getActivator().getBundleContext();
             if ( bundleContext == null )
@@ -125,99 +124,71 @@ public abstract class RegionConfiguratio
             }
             final List<String> confPids = holder.getComponentMetadata().getConfigurationPid();
 
-            final ServiceReference<?> caRef = bundleContext.getServiceReference(CONFIGURATION_ADMIN);
-            if (caRef != null)
+            final ConfigurationAdmin ca = getConfigAdmin();
+            try
             {
-                final Object cao = bundleContext.getService(caRef);
-                if (cao != null)
+                for ( final String confPid : confPids )
                 {
-                    try
+                    final Collection<Configuration> factory = findFactoryConfigurations( ca, confPid,
+                        bundleContext.getBundle() );
+                    if ( !factory.isEmpty() )
                     {
-                        if ( cao instanceof ConfigurationAdmin )
+                        boolean created = false;
+                        for ( Configuration config : factory )
                         {
-                            final ConfigurationAdmin ca = ( ConfigurationAdmin ) cao;
-                            for (final String confPid : confPids )
+                            logger.log( LogService.LOG_DEBUG,
+                                "Configuring holder {0} with factory configuration {1}, change count {2}",
+                                new Object[] { holder, config, config.getChangeCount() }, null );
+                            if ( checkBundleLocation( config, bundleContext.getBundle() ) )
                             {
-                                final Collection<Configuration> factory = findFactoryConfigurations( ca, confPid,
-                                        bundleContext.getBundle() );
-                                if ( !factory.isEmpty() )
-                                {
-                                    boolean created = false;
-                                    for ( Configuration config: factory )
-                                    {
-                                        logger.log( LogService.LOG_DEBUG,
-                                                "Configuring holder {0} with factory configuration {1}, change count {2}", new Object[] {
-                                                        holder, config, config.getChangeCount() }, null );
-                                        config = getConfiguration( ca, config.getPid() );
-                                        if ( checkBundleLocation( config, bundleContext.getBundle() ) )
-                                        {
-                                            long changeCount = config.getChangeCount();
-                                            created |= holder.configurationUpdated( new TargetedPID( config.getPid() ),
-                                            		new TargetedPID( config.getFactoryPid() ),
-                                                    config.getProperties(),
-                                                    changeCount );
-                                        }
-                                    }
-                                    if ( !created )
-                                    {
-                                        return false;
-                                    }
-                                }
-                                else
-                                {
-                                    // check for configuration and configure the holder
-                                    Configuration singleton = findSingletonConfiguration( ca, confPid,
-                                            bundleContext.getBundle() );
-                                    if ( singleton != null )
-                                    {
-                                        singleton = getConfiguration( ca, singleton.getPid() );
-                                        logger.log( LogService.LOG_DEBUG,
-                                                "Configuring holder {0} with configuration {1}, change count {2}", new Object[] { holder,
-                                                        singleton, singleton.getChangeCount() }, null );
-                                        if ( singleton != null
-                                                && checkBundleLocation( singleton, bundleContext.getBundle() ) )
-                                        {
-                                            long changeCount = singleton.getChangeCount();
-                                            holder.configurationUpdated( new TargetedPID( singleton.getPid() ), null,
-                                                    singleton.getProperties(), changeCount );
-                                        }
-                                        else
-                                        {
-                                        	return false;
-                                        }
-                                    }
-                                    else
-                                    {
-                                    	return false;
-                                    }
-                                }
+                                long changeCount = config.getChangeCount();
+                                created |= holder.configurationUpdated( new TargetedPID( config.getPid() ),
+                                    new TargetedPID( config.getFactoryPid() ), config.getProperties(), changeCount );
                             }
-                            return !confPids.isEmpty();
                         }
-                        else
+                        if ( !created )
                         {
-                            logger.log( LogService.LOG_WARNING, "Cannot configure component {0}",
-                                 new Object[] {holder.getComponentMetadata().getName()}, null );
-                            logger.log( LogService.LOG_WARNING,
-                                "Component Bundle's Configuration Admin is not compatible with "
-                                    + "ours. This happens if multiple Configuration Admin API versions "
-                                    + "are deployed and different bundles wire to different versions", null );
                             return false;
-
                         }
                     }
-                    finally
+                    else
                     {
-                        try
+                        // check for configuration and configure the holder
+                        Configuration singleton = findSingletonConfiguration( ca, confPid, bundleContext.getBundle() );
+                        if ( singleton != null )
                         {
-                            bundleContext.ungetService( caRef );
+                            logger.log( LogService.LOG_DEBUG,
+                                "Configuring holder {0} with configuration {1}, change count {2}",
+                                new Object[] { holder, singleton, singleton.getChangeCount() }, null );
+                            if ( singleton != null && checkBundleLocation( singleton, bundleContext.getBundle() ) )
+                            {
+                                long changeCount = singleton.getChangeCount();
+                                holder.configurationUpdated( new TargetedPID( singleton.getPid() ), null,
+                                    singleton.getProperties(), changeCount );
+                            }
+                            else
+                            {
+                                return false;
+                            }
                         }
-                        catch ( IllegalStateException e )
+                        else
                         {
-                            // ignore, bundle context was shut down during the above.
+                            return false;
                         }
                     }
                 }
+                return !confPids.isEmpty();
+            }
+            finally
+            {
+                try
+                {
+                    bundleContext.ungetService( caReference );
+                }
+                catch ( IllegalStateException e )
+                {
+                    // ignore, bundle context was shut down during the above.
+                }
             }
         }
         return false;
@@ -241,154 +212,164 @@ public abstract class RegionConfiguratio
      */
     public void configurationEvent(ConfigurationEvent event)
     {
-        final TargetedPID pid = new TargetedPID( event.getPid());
+        final TargetedPID pid = new TargetedPID( event.getPid() );
         String rawFactoryPid = event.getFactoryPid();
-        final TargetedPID factoryPid = rawFactoryPid == null? null: new TargetedPID( rawFactoryPid);
+        final TargetedPID factoryPid = rawFactoryPid == null? null: new TargetedPID( rawFactoryPid );
 
         // iterate over all components which must be configured with this pid
         // (since DS 1.2, components may specify a specific configuration PID (112.4.4 configuration-pid)
-        Collection<ComponentHolder<?>> holders = getComponentHolders(factoryPid != null ? factoryPid : pid);
+        Collection<ComponentHolder<?>> holders = getComponentHolders( factoryPid != null? factoryPid: pid );
 
-        logger.log(LogService.LOG_DEBUG, "configurationEvent: Handling {0}  of Configuration PID={1} for component holders {2}",
-                new Object[] {getEventType(event), pid, holders},
-                null);
+        logger.log( LogService.LOG_DEBUG,
+            "configurationEvent: Handling {0}  of Configuration PID={1} for component holders {2}",
+            new Object[] { getEventType( event ), pid, holders }, null );
 
-        for  ( ComponentHolder<?> componentHolder: holders )
+        for ( ComponentHolder<?> componentHolder : holders )
         {
-            if (!componentHolder.getComponentMetadata().isConfigurationIgnored())
+            if ( !componentHolder.getComponentMetadata().isConfigurationIgnored() )
             {
-                switch (event.getType()) {
-                case ConfigurationEvent.CM_DELETED:
-                    if ( factoryPid != null || !configureComponentHolder( componentHolder ) )
-                    {
-                        componentHolder.configurationDeleted( pid, factoryPid );
-                    }
-                    break;
-
-                case ConfigurationEvent.CM_UPDATED:
+                switch (event.getType())
                 {
-                    final ComponentActivator activator = componentHolder.getActivator();
-                    if (activator == null)
-                    {
+                    case ConfigurationEvent.CM_DELETED:
+                        if ( factoryPid != null || !configureComponentHolder( componentHolder ) )
+                        {
+                            componentHolder.configurationDeleted( pid, factoryPid );
+                        }
                         break;
-                    }
 
-                    final BundleContext bundleContext = activator.getBundleContext();
-                    if (bundleContext == null)
+                    case ConfigurationEvent.CM_UPDATED:
                     {
-                        break;
-                    }
+                        final ComponentActivator activator = componentHolder.getActivator();
+                        if ( activator == null )
+                        {
+                            break;
+                        }
 
-                    TargetedPID targetedPid = factoryPid == null? pid: factoryPid;
-                    TargetedPID oldTargetedPID = componentHolder.getConfigurationTargetedPID(pid, factoryPid);
-                    if ( factoryPid != null || targetedPid.equals(oldTargetedPID) || targetedPid.bindsStronger( oldTargetedPID ))
-                    {
-                        final ConfigurationInfo configInfo = getConfigurationInfo( pid, targetedPid, componentHolder, bundleContext );
-                        if ( configInfo != null )
+                        final BundleContext bundleContext = activator.getBundleContext();
+                        if ( bundleContext == null )
+                        {
+                            break;
+                        }
+
+                        TargetedPID targetedPid = factoryPid == null? pid: factoryPid;
+                        TargetedPID oldTargetedPID = componentHolder.getConfigurationTargetedPID( pid, factoryPid );
+                        if ( factoryPid != null || targetedPid.equals( oldTargetedPID )
+                            || targetedPid.bindsStronger( oldTargetedPID ) )
                         {
-                            if ( checkBundleLocation( configInfo.getBundleLocation(), bundleContext.getBundle() ) )
+                            final ConfigurationInfo configInfo = getConfigurationInfo( pid, targetedPid,
+                                componentHolder, bundleContext );
+                            if ( configInfo != null )
                             {
-                            	// The below seems to be unnecessary - and if put in, the behaviour is not spec compliant anymore:
-                            	// if a component has a required configuration and a modified method, the component must not be
-                            	// reactivated
-                                // If this is replacing a weaker targetedPID delete the old one.
-                                // if ( factoryPid == null && !targetedPid.equals(oldTargetedPID) && oldTargetedPID != null)
-                                //{
+                                if ( checkBundleLocation( configInfo.getBundleLocation(), bundleContext.getBundle() ) )
+                                {
+                                    // The below seems to be unnecessary - and if put in, the behaviour is not spec compliant anymore:
+                                    // if a component has a required configuration and a modified method, the component must not be
+                                    // reactivated
+                                    // If this is replacing a weaker targetedPID delete the old one.
+                                    // if ( factoryPid == null && !targetedPid.equals(oldTargetedPID) && oldTargetedPID != null)
+                                    //{
                                     //componentHolder.configurationDeleted( pid, factoryPid );
-                                //}
-                                componentHolder.configurationUpdated( pid, factoryPid, configInfo.getProps(), configInfo.getChangeCount() );
+                                    //}
+                                    componentHolder.configurationUpdated( pid, factoryPid, configInfo.getProps(),
+                                        configInfo.getChangeCount() );
+                                }
                             }
                         }
-                    }
 
-                    break;
-                }
-                case ConfigurationEvent.CM_LOCATION_CHANGED:
-                {
-                    //TODO is this logic correct for factory pids????
-                    final ComponentActivator activator = componentHolder.getActivator();
-                    if (activator == null)
-                    {
                         break;
                     }
-
-                    final BundleContext bundleContext = activator.getBundleContext();
-                    if (bundleContext == null)
+                    case ConfigurationEvent.CM_LOCATION_CHANGED:
                     {
-                        break;
-                    }
+                        //TODO is this logic correct for factory pids????
+                        final ComponentActivator activator = componentHolder.getActivator();
+                        if ( activator == null )
+                        {
+                            break;
+                        }
 
-                    TargetedPID targetedPid = factoryPid == null? pid: factoryPid;
-                    TargetedPID oldTargetedPID = componentHolder.getConfigurationTargetedPID(pid, factoryPid);
-                    if ( targetedPid.equals(oldTargetedPID))
-                    {
-                        //this sets the location to this component's bundle if not already set.  OK here
-                        //since it used to be set to this bundle, ok to reset it
-                        final ConfigurationInfo configInfo = getConfigurationInfo( pid, targetedPid, componentHolder, bundleContext );
-                        if ( configInfo != null )
-                        {
-                            logger.log(LogService.LOG_DEBUG, "LocationChanged event, same targetedPID {0}, location now {1}, change count {2}",
-                                    new Object[] {targetedPid, configInfo.getBundleLocation(), configInfo.getChangeCount()},
-                                    null);
-                            if (configInfo.getProps() == null)
-                            {
-                                throw new IllegalStateException("Existing Configuration with pid " + pid +
-                                        " has had its properties set to null and location changed.  We expected a delete event first.");
-                            }
-                            //this config was used on this component.  Does it still match?
-                            if (!checkBundleLocation( configInfo.getBundleLocation(), bundleContext.getBundle() ))
+                        final BundleContext bundleContext = activator.getBundleContext();
+                        if ( bundleContext == null )
+                        {
+                            break;
+                        }
+
+                        TargetedPID targetedPid = factoryPid == null? pid: factoryPid;
+                        TargetedPID oldTargetedPID = componentHolder.getConfigurationTargetedPID( pid, factoryPid );
+                        if ( targetedPid.equals( oldTargetedPID ) )
+                        {
+                            //this sets the location to this component's bundle if not already set.  OK here
+                            //since it used to be set to this bundle, ok to reset it
+                            final ConfigurationInfo configInfo = getConfigurationInfo( pid, targetedPid,
+                                componentHolder, bundleContext );
+                            if ( configInfo != null )
                             {
-                                //no, delete it
-                                componentHolder.configurationDeleted( pid, factoryPid );
-                                //maybe there's another match
-                                configureComponentHolder(componentHolder);
+                                logger.log( LogService.LOG_DEBUG,
+                                    "LocationChanged event, same targetedPID {0}, location now {1}, change count {2}",
+                                    new Object[] { targetedPid, configInfo.getBundleLocation(),
+                                            configInfo.getChangeCount() },
+                                    null );
+                                if ( configInfo.getProps() == null )
+                                {
+                                    throw new IllegalStateException( "Existing Configuration with pid " + pid
+                                        + " has had its properties set to null and location changed.  We expected a delete event first." );
+                                }
+                                //this config was used on this component.  Does it still match?
+                                if ( !checkBundleLocation( configInfo.getBundleLocation(), bundleContext.getBundle() ) )
+                                {
+                                    //no, delete it
+                                    componentHolder.configurationDeleted( pid, factoryPid );
+                                    //maybe there's another match
+                                    configureComponentHolder( componentHolder );
 
+                                }
+                                //else still matches
                             }
-                            //else still matches
+                            break;
                         }
-                        break;
-                    }
-                    boolean better = targetedPid.bindsStronger( oldTargetedPID );
-                    if ( better )
-                    {
-                        //this sets the location to this component's bundle if not already set.  OK here
-                        //because if it is set to this bundle we will use it.
-                        final ConfigurationInfo configInfo = getConfigurationInfo( pid, targetedPid, componentHolder, bundleContext );
-                        if ( configInfo != null )
-                        {
-                            logger.log(LogService.LOG_DEBUG, "LocationChanged event, better targetedPID {0} compared to {1}, location now {2}, change count {3}",
-                                    new Object[] {targetedPid, oldTargetedPID, configInfo.getBundleLocation(), configInfo.getChangeCount()},
-                                    null);
-                            if (configInfo.getProps() == null)
-                            {
-                                //location has been changed before any properties are set.  We don't care.  Wait for an updated event with the properties
-                                break;
-                            }
-                            //this component was not configured with this config.  Should it be now?
-                            if ( checkBundleLocation( configInfo.getBundleLocation(), bundleContext.getBundle() ) )
+                        boolean better = targetedPid.bindsStronger( oldTargetedPID );
+                        if ( better )
+                        {
+                            //this sets the location to this component's bundle if not already set.  OK here
+                            //because if it is set to this bundle we will use it.
+                            final ConfigurationInfo configInfo = getConfigurationInfo( pid, targetedPid,
+                                componentHolder, bundleContext );
+                            if ( configInfo != null )
                             {
-                                if ( oldTargetedPID != null )
+                                logger.log( LogService.LOG_DEBUG,
+                                    "LocationChanged event, better targetedPID {0} compared to {1}, location now {2}, change count {3}",
+                                    new Object[] { targetedPid, oldTargetedPID, configInfo.getBundleLocation(),
+                                            configInfo.getChangeCount() },
+                                    null );
+                                if ( configInfo.getProps() == null )
                                 {
-                                    //this is a better match, delete old before setting new
-                                    componentHolder.configurationDeleted( pid, factoryPid );
+                                    //location has been changed before any properties are set.  We don't care.  Wait for an updated event with the properties
+                                    break;
+                                }
+                                //this component was not configured with this config.  Should it be now?
+                                if ( checkBundleLocation( configInfo.getBundleLocation(), bundleContext.getBundle() ) )
+                                {
+                                    if ( oldTargetedPID != null )
+                                    {
+                                        //this is a better match, delete old before setting new
+                                        componentHolder.configurationDeleted( pid, factoryPid );
+                                    }
+                                    componentHolder.configurationUpdated( pid, factoryPid, configInfo.getProps(),
+                                        configInfo.getChangeCount() );
                                 }
-                                componentHolder.configurationUpdated( pid, factoryPid,
-                                        configInfo.getProps(), configInfo.getChangeCount() );
                             }
                         }
+                        //else worse match, do nothing
+                        else
+                        {
+                            logger.log( LogService.LOG_DEBUG,
+                                "LocationChanged event, worse targetedPID {0} compared to {1}, do nothing",
+                                new Object[] { targetedPid, oldTargetedPID }, null );
+                        }
+                        break;
                     }
-                    //else worse match, do nothing
-                    else
-                    {
-                        logger.log(LogService.LOG_DEBUG, "LocationChanged event, worse targetedPID {0} compared to {1}, do nothing",
-                                new Object[] {targetedPid, oldTargetedPID},
-                                null);
-                    }
-                    break;
-                }
-                default:
-                    logger.log(LogService.LOG_WARNING, "Unknown ConfigurationEvent type {0}", new Object[] {event.getType()},
-                        null);
+                    default:
+                        logger.log( LogService.LOG_WARNING, "Unknown ConfigurationEvent type {0}",
+                            new Object[] { event.getType() }, null );
                 }
             }
         }
@@ -396,19 +377,18 @@ public abstract class RegionConfiguratio
 
     protected abstract Collection<ComponentHolder<?>> getComponentHolders(TargetedPID pid);
 
-
     private String getEventType(ConfigurationEvent event)
     {
         switch (event.getType())
         {
-        case ConfigurationEvent.CM_UPDATED:
-            return "UPDATED";
-        case ConfigurationEvent.CM_DELETED:
-            return "DELETED";
-        case ConfigurationEvent.CM_LOCATION_CHANGED:
-            return "LOCATION CHANGED";
-        default:
-            return "Unkown event type: " + event.getType();
+            case ConfigurationEvent.CM_UPDATED:
+                return "UPDATED";
+            case ConfigurationEvent.CM_DELETED:
+                return "DELETED";
+            case ConfigurationEvent.CM_LOCATION_CHANGED:
+                return "LOCATION CHANGED";
+            default:
+                return "Unkown event type: " + event.getType();
         }
 
     }
@@ -455,64 +435,47 @@ public abstract class RegionConfiguratio
      * @return ConfigurationInfo object containing the info we need from the configuration.
      */
     private ConfigurationInfo getConfigurationInfo(final TargetedPID pid, TargetedPID targetedPid,
-            ComponentHolder<?> componentHolder, final BundleContext bundleContext)
+        ComponentHolder<?> componentHolder, final BundleContext bundleContext)
     {
-        final ServiceReference caRef = bundleContext.getServiceReference(CONFIGURATION_ADMIN);
-        if (caRef != null)
+        try
         {
+            final ConfigurationAdmin ca = getConfigAdmin();
             try
             {
-                final Object cao = bundleContext.getService(caRef);
-                if (cao != null)
+                Configuration[] configs = ca.listConfigurations( filter( pid.getRawPid() ) );
+                if ( configs != null && configs.length > 0 )
                 {
-                    try
-                    {
-                        if ( cao instanceof ConfigurationAdmin )
-                        {
-                            final ConfigurationAdmin ca = ( ConfigurationAdmin ) cao;
-                            final Configuration config = getConfiguration( ca, pid.getRawPid() );
-                            return new ConfigurationInfo(config.getProperties(), config.getBundleLocation(),
-                            		config.getChangeCount());
-                        }
-                        else
-                        {
-                            logger.log( LogService.LOG_WARNING, "Cannot reconfigure component {0}",
-                                new Object[] {componentHolder.getComponentMetadata().getName()}, null );
-                            logger.log( LogService.LOG_WARNING,
-                                "Component Bundle's Configuration Admin is not compatible with " +
-                                "ours. This happens if multiple Configuration Admin API versions " +
-                                "are deployed and different bundles wire to different versions",
-                                null );
-                        }
-                    }
-                    finally
-                    {
-                        bundleContext.ungetService( caRef );
-                    }
+                    Configuration config = configs[0];
+                    return new ConfigurationInfo( config.getProperties(), config.getBundleLocation(),
+                        config.getChangeCount() );
                 }
             }
-            catch (IllegalStateException ise)
+            catch ( IOException e )
             {
-                // If the bundle has been stopped concurrently
-                logger.log(LogService.LOG_WARNING, "Bundle in unexpected state",
-                    ise);
+                logger.log( LogService.LOG_WARNING, "Failed reading configuration for pid={0}", new Object[] { pid },
+                    e );
+            }
+            catch ( InvalidSyntaxException e )
+            {
+                logger.log( LogService.LOG_WARNING, "Failed reading configuration for pid={0}", new Object[] { pid },
+                    e );
+            }
+            finally
+            {
+                bundleContext.ungetService( caReference );
             }
         }
+        catch ( IllegalStateException ise )
+        {
+            // If the bundle has been stopped concurrently
+            logger.log( LogService.LOG_WARNING, "Bundle in unexpected state", ise );
+        }
         return null;
     }
 
-    private Configuration getConfiguration(final ConfigurationAdmin ca, final String pid)
+    private String filter(String rawPid)
     {
-        try
-        {
-            return ca.getConfiguration(pid);
-        }
-        catch (IOException ioe)
-        {
-            logger.log(LogService.LOG_WARNING, "Failed reading configuration for pid={0}", new Object[] {pid}, ioe);
-        }
-
-        return null;
+        return "(service.pid=" + rawPid + ")";
     }
 
     /**
@@ -527,19 +490,19 @@ public abstract class RegionConfiguratio
     public Configuration findSingletonConfiguration(final ConfigurationAdmin ca, final String pid, Bundle bundle)
     {
         final String filter = getTargetedPidFilter( pid, bundle, Constants.SERVICE_PID );
-        final Configuration[] cfg = findConfigurations(ca, filter);
-        if (cfg == null)
+        final Configuration[] cfg = findConfigurations( ca, filter );
+        if ( cfg == null )
         {
             return null;
         }
         String longest = null;
         Configuration best = null;
-        for (Configuration config: cfg)
+        for ( Configuration config : cfg )
         {
             if ( checkBundleLocation( config, bundle ) )
             {
                 String testPid = config.getPid();
-                if ( longest == null || testPid.length() > longest.length())
+                if ( longest == null || testPid.length() > longest.length() )
                 {
                     longest = testPid;
                     best = config;
@@ -559,16 +522,17 @@ public abstract class RegionConfiguratio
      * @param bundle bundle we're working for (for location and location permission)
      * @return the configurations specifying the supplied factory Pid.
      */
-    private Collection<Configuration> findFactoryConfigurations(final ConfigurationAdmin ca, final String factoryPid, Bundle bundle)
+    private Collection<Configuration> findFactoryConfigurations(final ConfigurationAdmin ca, final String factoryPid,
+        Bundle bundle)
     {
         final String filter = getTargetedPidFilter( factoryPid, bundle, ConfigurationAdmin.SERVICE_FACTORYPID );
-        Configuration[] configs = findConfigurations(ca, filter);
-        if (configs == null)
+        Configuration[] configs = findConfigurations( ca, filter );
+        if ( configs == null )
         {
             return Collections.emptyList();
         }
         Map<String, Configuration> configsByPid = new HashMap<String, Configuration>();
-        for (Configuration config: configs)
+        for ( Configuration config : configs )
         {
             if ( checkBundleLocation( config, bundle ) )
             {
@@ -593,7 +557,7 @@ public abstract class RegionConfiguratio
 
     private boolean checkBundleLocation(Configuration config, Bundle bundle)
     {
-        if (config == null)
+        if ( config == null )
         {
             return false;
         }
@@ -603,31 +567,34 @@ public abstract class RegionConfiguratio
 
     private boolean checkBundleLocation(String configBundleLocation, Bundle bundle)
     {
-        if ( configBundleLocation == null)
+        if ( configBundleLocation == null )
         {
             return true;
         }
-        if (configBundleLocation.startsWith( "?" ))
+        if ( configBundleLocation.startsWith( "?" ) )
         {
             //multilocation
-            return bundle.hasPermission(new ConfigurationPermission(configBundleLocation, ConfigurationPermission.TARGET));
+            return bundle.hasPermission(
+                new ConfigurationPermission( configBundleLocation, ConfigurationPermission.TARGET ) );
         }
-        return configBundleLocation.equals(bundle.getLocation());
+        return configBundleLocation.equals( bundle.getLocation() );
     }
 
     private Configuration[] findConfigurations(final ConfigurationAdmin ca, final String filter)
     {
         try
         {
-            return ca.listConfigurations(filter);
+            return ca.listConfigurations( filter );
         }
-        catch (IOException ioe)
+        catch ( IOException ioe )
         {
-            logger.log(LogService.LOG_WARNING, "Problem listing configurations for filter={0}", new Object[] {filter}, ioe);
+            logger.log( LogService.LOG_WARNING, "Problem listing configurations for filter={0}",
+                new Object[] { filter }, ioe );
         }
-        catch (InvalidSyntaxException ise)
+        catch ( InvalidSyntaxException ise )
         {
-            logger.log(LogService.LOG_ERROR, "Invalid Configuration selection filter {0}", new Object[] {filter}, ise);
+            logger.log( LogService.LOG_ERROR, "Invalid Configuration selection filter {0}", new Object[] { filter },
+                ise );
         }
 
         // no factories in case of problems
@@ -638,10 +605,9 @@ public abstract class RegionConfiguratio
     {
         String bsn = bundle.getSymbolicName();
         String version = bundle.getVersion().toString();
-        String location = escape(bundle.getLocation());
-        String f = String.format(
-                "(|(%1$s=%2$s)(%1$s=%2$s|%3$s)(%1$s=%2$s|%3$s|%4$s)(%1$s=%2$s|%3$s|%4$s|%5$s))",
-                key, pid, bsn, version, location );
+        String location = escape( bundle.getLocation() );
+        String f = String.format( "(|(%1$s=%2$s)(%1$s=%2$s|%3$s)(%1$s=%2$s|%3$s|%4$s)(%1$s=%2$s|%3$s|%4$s|%5$s))", key,
+            pid, bsn, version, location );
         return f;
     }
 
@@ -655,4 +621,9 @@ public abstract class RegionConfiguratio
         return value.replaceAll( "([\\\\\\*\\(\\)])", "\\\\$1" );
     }
 
+    private ConfigurationAdmin getConfigAdmin()
+    {
+        return caBundleContext.getService( caReference );
+    }
+
 }

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java?rev=1747831&r1=1747830&r2=1747831&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java Sat Jun 11 01:14:36 2016
@@ -506,8 +506,8 @@ public class ComponentConfigurationTest
         TestCase.assertTrue( SimpleComponent.INSTANCES.isEmpty() );
 
         // create two factory configurations expecting two components
-        final String pid0 = createFactoryConfiguration( factoryPid );
-        final String pid1 = createFactoryConfiguration( factoryPid );
+        final String pid0 = createFactoryConfiguration( factoryPid, "?" );
+        final String pid1 = createFactoryConfiguration( factoryPid, "?" );
         delay();
 
         // expect two active components, //TODO WTF?? only first is active, second is disabled
@@ -538,8 +538,8 @@ public class ComponentConfigurationTest
         deleteFactoryConfigurations( factoryPid );
 
         // create two factory configurations expecting two components
-        final String pid0 = createFactoryConfiguration( factoryPid );
-        final String pid1 = createFactoryConfiguration( factoryPid );
+        final String pid0 = createFactoryConfiguration( factoryPid, "?" );
+        final String pid1 = createFactoryConfiguration( factoryPid, "?" );
         delay();
 
         getConfigurationsDisabledThenEnable(factoryPid, 2, ComponentConfigurationDTO.ACTIVE);
@@ -570,8 +570,8 @@ public class ComponentConfigurationTest
         // no component config exists without configuration
 
         // create two factory configurations expecting two components
-        final String pid0 = createFactoryConfiguration( factoryPid );
-        final String pid1 = createFactoryConfiguration( factoryPid );
+        final String pid0 = createFactoryConfiguration( factoryPid, "?" );
+        final String pid1 = createFactoryConfiguration( factoryPid, "?" );
         delay();
 
         // expect two components, all active
@@ -583,7 +583,7 @@ public class ComponentConfigurationTest
 
 
         // create a configuration
-        final String pid3 = createFactoryConfiguration( factoryPid );
+        final String pid3 = createFactoryConfiguration( factoryPid, "?" );
         delay();
 
         getConfigurationsDisabledThenEnable(factoryPid, 3, ComponentConfigurationDTO.ACTIVE);

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentDisposeTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentDisposeTest.java?rev=1747831&r1=1747830&r2=1747831&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentDisposeTest.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentDisposeTest.java Sat Jun 11 01:14:36 2016
@@ -55,8 +55,8 @@ public class ComponentDisposeTest extend
         getConfigurationsDisabledThenEnable(factoryPid, 0, ComponentConfigurationDTO.ACTIVE);//there should be none
 
         // create two factory configurations expecting two components
-        final String pid0 = createFactoryConfiguration( factoryPid );
-        final String pid1 = createFactoryConfiguration( factoryPid );
+        final String pid0 = createFactoryConfiguration( factoryPid, "?" );
+        final String pid1 = createFactoryConfiguration( factoryPid, "?" );
         delay();
 
         Collection<ComponentConfigurationDTO> ccs = findComponentConfigurationsByName(factoryPid, ComponentConfigurationDTO.ACTIVE);

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java?rev=1747831&r1=1747830&r2=1747831&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java Sat Jun 11 01:14:36 2016
@@ -18,12 +18,11 @@
  */
 package org.apache.felix.scr.integration;
 
+import static org.junit.Assert.assertNotNull;
 
 import java.lang.reflect.InvocationTargetException;
 import java.util.Hashtable;
 
-import junit.framework.TestCase;
-
 import org.apache.felix.scr.integration.components.SimpleComponent;
 import org.apache.felix.scr.integration.components.SimpleService;
 import org.apache.felix.scr.integration.components.SimpleServiceImpl;
@@ -31,15 +30,13 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.component.ComponentConstants;
 import org.osgi.service.component.ComponentException;
 import org.osgi.service.component.ComponentFactory;
 import org.osgi.service.component.ComponentInstance;
 import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
 import org.osgi.service.log.LogService;
 
+import junit.framework.TestCase;
 
 @RunWith(JUnit4TestRunner.class)
 public class ComponentFactoryTest extends ComponentTestBase
@@ -49,7 +46,7 @@ public class ComponentFactoryTest extend
     {
         descriptorFile = "/integration_test_simple_factory_components.xml";
         // uncomment to enable debugging of this test class
-//        paxRunnerVmOption = DEBUG_VM_OPTION;
+        //        paxRunnerVmOption = DEBUG_VM_OPTION;
     }
 
     @Test
@@ -58,23 +55,22 @@ public class ComponentFactoryTest extend
         final String componentname = "factory.component";
         final String componentfactory = "factory.component.factory";
 
-        getConfigurationsDisabledThenEnable(componentname, 0, -1);
+        getConfigurationsDisabledThenEnable( componentname, 0, -1 );
 
         TestCase.assertNull( SimpleComponent.INSTANCE );
 
-        final ComponentInstance instance = createFactoryComponentInstance(componentfactory);
+        final ComponentInstance instance = createFactoryComponentInstance( componentfactory );
 
         // check registered components
-        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
+        checkConfigurationCount( componentname, 1, ComponentConfigurationDTO.ACTIVE );
 
         instance.dispose();
         TestCase.assertNull( SimpleComponent.INSTANCE );
         TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2
-        
-        checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
 
-    }
+        checkConfigurationCount( componentname, 0, ComponentConfigurationDTO.ACTIVE );
 
+    }
 
     @Test
     public void test_component_factory_disable_factory() throws Exception
@@ -84,16 +80,16 @@ public class ComponentFactoryTest extend
         final String componentname = "factory.component";
         final String componentfactory = "factory.component.factory";
 
-        getConfigurationsDisabledThenEnable(componentname, 0, -1);
+        getConfigurationsDisabledThenEnable( componentname, 0, -1 );
 
         TestCase.assertNull( SimpleComponent.INSTANCE );
 
-        final ComponentInstance instance = createFactoryComponentInstance(componentfactory);
+        final ComponentInstance instance = createFactoryComponentInstance( componentfactory );
 
-        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
+        checkConfigurationCount( componentname, 1, ComponentConfigurationDTO.ACTIVE );
 
         // disable the factory
-        disableAndCheck(componentname);
+        disableAndCheck( componentname );
         delay();
 
         // factory is disabled but the instance is still alive
@@ -105,14 +101,13 @@ public class ComponentFactoryTest extend
 
     }
 
-
     @Test
     public void test_component_factory_newInstance_failure() throws Exception
     {
         final String componentname = "factory.component";
         final String componentfactory = "factory.component.factory";
 
-        getConfigurationsDisabledThenEnable(componentname, 0, -1);
+        getConfigurationsDisabledThenEnable( componentname, 0, -1 );
         TestCase.assertNull( SimpleComponent.INSTANCE );
 
         try
@@ -120,7 +115,7 @@ public class ComponentFactoryTest extend
             Hashtable<String, String> props = new Hashtable<String, String>();
             props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
             props.put( SimpleComponent.PROP_ACTIVATE_FAILURE, "Requested Failure" );
-            createFactoryComponentInstance(componentfactory, props);
+            createFactoryComponentInstance( componentfactory, props );
             TestCase.fail( "Expected newInstance method to fail with ComponentException" );
         }
         catch ( ComponentException ce )
@@ -128,18 +123,17 @@ public class ComponentFactoryTest extend
             // this is expected !
         }
 
-        checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
+        checkConfigurationCount( componentname, 0, ComponentConfigurationDTO.ACTIVE );
     }
 
-
     @Test
     public void test_component_factory_require_configuration() throws Exception
     {
         final String componentname = "factory.component.configuration";
         final String componentfactory = "factory.component.factory.configuration";
 
-        testConfiguredFactory(componentname, componentfactory, false, false);
-        
+        testConfiguredFactory( componentname, componentfactory, false, false );
+
     }
 
     @Test
@@ -147,12 +141,12 @@ public class ComponentFactoryTest extend
     {
         final String componentname = "factory.component.configuration.obsolete";
 
-        TestCase.assertNull(SimpleComponent.INSTANCE);
+        TestCase.assertNull( SimpleComponent.INSTANCE );
 
-        createFactoryConfiguration(componentname);
+        createFactoryConfiguration( componentname, "?" );
         delay();
-        getConfigurationsDisabledThenEnable(componentname, 1, ComponentConfigurationDTO.ACTIVE);
-        TestCase.assertEquals(PROP_NAME, SimpleComponent.INSTANCE.getProperty(PROP_NAME));
+        getConfigurationsDisabledThenEnable( componentname, 1, ComponentConfigurationDTO.ACTIVE );
+        TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
     }
 
     @Test
@@ -161,8 +155,8 @@ public class ComponentFactoryTest extend
         final String componentname = "factory.component.configuration.optional";
         final String componentfactory = "factory.component.factory.configuration.optional";
 
-        testConfiguredFactory(componentname, componentfactory, true, false);
-        
+        testConfiguredFactory( componentname, componentfactory, true, false );
+
     }
 
     @Test
@@ -171,7 +165,7 @@ public class ComponentFactoryTest extend
         final String componentname = "factory.component.configuration.optional.13";
         final String componentfactory = "factory.component.factory.configuration.optional.13";
 
-        testConfiguredFactory(componentname, componentfactory, true, true);
+        testConfiguredFactory( componentname, componentfactory, true, true );
     }
 
     @Test
@@ -180,44 +174,43 @@ public class ComponentFactoryTest extend
         final String componentname = "factory.component.configuration.optional.nomodify";
         final String componentfactory = "factory.component.factory.configuration.optional.nomodify";
 
-        testConfiguredFactory(componentname, componentfactory, true, false);
-        
-    }
+        testConfiguredFactory( componentname, componentfactory, true, false );
 
+    }
 
-    private ComponentInstance testConfiguredFactory(final String componentname,
-        final String componentfactory, boolean optional, boolean expectComponent) throws InvocationTargetException,
-        InterruptedException, InvalidSyntaxException
+    private ComponentInstance testConfiguredFactory(final String componentname, final String componentfactory,
+        boolean optional, boolean expectComponent)
+        throws InvocationTargetException, InterruptedException, InvalidSyntaxException
     {
         // ensure there is no configuration for the component
         deleteConfig( componentname );
         delay();
 
-        getConfigurationsDisabledThenEnable(componentname, 0, -1);
+        getConfigurationsDisabledThenEnable( componentname, 0, -1 );
         TestCase.assertNull( SimpleComponent.INSTANCE );
 
         // At this point, since we don't have created the configuration, then the ComponentFactory
         // should not be available.
-        
-        checkFactory(componentfactory, optional);
-        
+
+        checkFactory( componentfactory, optional );
+
         // supply configuration now and ensure active
         configure( componentname );
-        delay();        
+        delay();
 
-        checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
+        checkConfigurationCount( componentname, 0, ComponentConfigurationDTO.ACTIVE );
         TestCase.assertNull( SimpleComponent.INSTANCE );
 
         // get the component factory service
-        final ComponentInstance instance = createFactoryComponentInstance(componentfactory);
+        final ComponentInstance instance = createFactoryComponentInstance( componentfactory );
 
         final Object instanceObject = instance.getInstance();
         TestCase.assertNotNull( instanceObject );
         TestCase.assertEquals( SimpleComponent.INSTANCE, instanceObject );
         TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME_FACTORY ) );
-        TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );                        
+        TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
 
-        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
+        checkConfigurationCount( componentname, 1, ComponentConfigurationDTO.ACTIVE );
 
         // delete config, ensure factory is not active anymore and component instance gone 
         //(configuration required >> dispose of instance.  Also for pre-1.3 components, removing config unconditionally
@@ -225,15 +218,15 @@ public class ComponentFactoryTest extend
         deleteConfig( componentname );
         delay();
 
-        checkFactory(componentfactory, optional);
+        checkFactory( componentfactory, optional );
 
-        if (expectComponent) 
+        if ( expectComponent )
         {
             TestCase.assertNotNull( instance.getInstance() );
             TestCase.assertNotNull( SimpleComponent.INSTANCE );
 
             // with removal of the factory, the created instance should also be removed
-            checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);            
+            checkConfigurationCount( componentname, 1, ComponentConfigurationDTO.ACTIVE );
         }
         else
         {
@@ -241,12 +234,11 @@ public class ComponentFactoryTest extend
             TestCase.assertNull( SimpleComponent.INSTANCE );
 
             // with removal of the factory, the created instance should also be removed
-            checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);            
+            checkConfigurationCount( componentname, 0, ComponentConfigurationDTO.ACTIVE );
         }
         return instance;
     }
 
-
     @Test
     public void test_component_factory_reference() throws Exception
     {
@@ -255,7 +247,7 @@ public class ComponentFactoryTest extend
 
         SimpleServiceImpl.create( bundleContext, "ignored" ).setFilterProperty( "ignored" );
 
-        getConfigurationsDisabledThenEnable(componentname, 0, -1);
+        getConfigurationsDisabledThenEnable( componentname, 0, -1 );
         TestCase.assertNull( SimpleComponent.INSTANCE );
 
         // register a service : filterprop=match
@@ -264,24 +256,23 @@ public class ComponentFactoryTest extend
 
         TestCase.assertNull( SimpleComponent.INSTANCE );
 
-        final ComponentInstance instance = createFactoryComponentInstance(componentfactory);
+        final ComponentInstance instance = createFactoryComponentInstance( componentfactory );
         TestCase.assertEquals( 1, SimpleComponent.INSTANCE.m_multiRef.size() );
         TestCase.assertTrue( SimpleComponent.INSTANCE.m_multiRef.contains( match ) );
 
         // check registered components
-        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
+        checkConfigurationCount( componentname, 1, ComponentConfigurationDTO.ACTIVE );
 
         instance.dispose();
         TestCase.assertNull( SimpleComponent.INSTANCE );
         TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2
-        checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
-
+        checkConfigurationCount( componentname, 0, ComponentConfigurationDTO.ACTIVE );
 
         // overwritten filterprop
         Hashtable<String, String> propsNonMatch = new Hashtable<String, String>();
         propsNonMatch.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
         propsNonMatch.put( "ref.target", "(filterprop=nomatch)" );
-        ComponentFactory factory = getComponentFactory(componentfactory);
+        ComponentFactory factory = getComponentFactory( componentfactory );
         try
         {
             factory.newInstance( propsNonMatch );
@@ -308,20 +299,20 @@ public class ComponentFactoryTest extend
         TestCase.assertTrue( SimpleComponent.INSTANCE.m_multiRef.contains( noMatch ) );
 
         // check registered components
-        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
+        checkConfigurationCount( componentname, 1, ComponentConfigurationDTO.ACTIVE );
 
         match.getRegistration().unregister();
         delay();
 
         // check registered components (ComponentFactory aint no longer)
-        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
+        checkConfigurationCount( componentname, 1, ComponentConfigurationDTO.ACTIVE );
 
         //it has already been deactivated.... this should cause an exception?
         noMatch.getRegistration().unregister();
         delay();
 
         // check registered components (ComponentFactory aint no longer)
-        checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
+        checkConfigurationCount( componentname, 0, ComponentConfigurationDTO.ACTIVE );
 
         // deactivated due to unsatisfied reference
         TestCase.assertNull( instanceNonMatch.getInstance() );
@@ -338,17 +329,18 @@ public class ComponentFactoryTest extend
     {
         //set up the component that refers to the service the factory will create.
         final String referringComponentName = "ComponentReferringToFactoryObject";
-        getConfigurationsDisabledThenEnable(referringComponentName, 1, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
+        getConfigurationsDisabledThenEnable( referringComponentName, 1,
+            ComponentConfigurationDTO.UNSATISFIED_REFERENCE );
 
         final String componentname = "factory.component.referred";
         final String componentfactory = "factory.component.factory.referred";
 
-        getConfigurationsDisabledThenEnable(componentname, 0, -1);
+        getConfigurationsDisabledThenEnable( componentname, 0, -1 );
         TestCase.assertNull( SimpleComponent.INSTANCE );
 
         Hashtable<String, String> props = new Hashtable<String, String>();
         props.put( "service.pid", "myFactoryInstance" );
-        final ComponentFactory factory = getComponentFactory(componentfactory);
+        final ComponentFactory factory = getComponentFactory( componentfactory );
 
         final ComponentInstance instance = factory.newInstance( props );
         TestCase.assertNotNull( instance );
@@ -356,72 +348,75 @@ public class ComponentFactoryTest extend
         TestCase.assertNotNull( instance.getInstance() );
         TestCase.assertTrue( instance.getInstance() instanceof SimpleService );
         //The referring service should now be active
-        checkConfigurationCount(referringComponentName, 1, ComponentConfigurationDTO.ACTIVE);
+        checkConfigurationCount( referringComponentName, 1, ComponentConfigurationDTO.ACTIVE );
 
         instance.dispose();
         TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2
 
         //make sure it's unsatisfied (service is no longer available)
-        checkConfigurationCount(referringComponentName, 1, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
+        checkConfigurationCount( referringComponentName, 1, ComponentConfigurationDTO.UNSATISFIED_REFERENCE );
     }
 
     @Test
     public void test_component_factory_with_target_filters() throws Exception
     {
         final String componentfactory = "factory.component.reference.targetfilter";
-        getConfigurationsDisabledThenEnable(componentfactory, 0, -1);
+        getConfigurationsDisabledThenEnable( componentfactory, 0, -1 );
 
-        SimpleServiceImpl s1 = SimpleServiceImpl.create(bundleContext, "service1");
-        SimpleServiceImpl s2 = SimpleServiceImpl.create(bundleContext, "service2");
+        SimpleServiceImpl s1 = SimpleServiceImpl.create( bundleContext, "service1" );
+        SimpleServiceImpl s2 = SimpleServiceImpl.create( bundleContext, "service2" );
 
         // supply configuration now and ensure active
         configure( componentfactory );
-        delay();        
+        delay();
 
         TestCase.assertNull( SimpleComponent.INSTANCE );
-        
+
         Hashtable<String, String> props = new Hashtable<String, String>();
         props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
-        props.put("ref.target", "(value=service2)");
-        final ComponentInstance instance = createFactoryComponentInstance(componentfactory, props);
+        props.put( "ref.target", "(value=service2)" );
+        final ComponentInstance instance = createFactoryComponentInstance( componentfactory, props );
 
-        log.log(LogService.LOG_WARNING, "Bound Services: " +  SimpleComponent.INSTANCE.m_multiRef);
+        log.log( LogService.LOG_WARNING, "Bound Services: " + SimpleComponent.INSTANCE.m_multiRef );
         TestCase.assertFalse( SimpleComponent.INSTANCE.m_multiRef.contains( s1 ) );
         TestCase.assertTrue( SimpleComponent.INSTANCE.m_multiRef.contains( s2 ) );
 
         instance.dispose();
         TestCase.assertNull( SimpleComponent.INSTANCE );
         TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2
-        
+
         s2.drop();
         s1.drop();
     }
-    
+
     @Test
-    public void test_component_factory_set_bundle_location_null() throws Exception
+    public void test_component_factory_set_bundle_location() throws Exception
     {
-        final String componentfactory = "factory.component.reference.targetfilter";
-        getConfigurationsDisabledThenEnable(componentfactory, 0, -1);
-        SimpleServiceImpl s1 = SimpleServiceImpl.create(bundleContext, "service1");
+        final String componentfactoryPid = "factory.component.configuration";
+        final String componentFactoryName = "factory.component.factory.configuration";
+        getConfigurationsDisabledThenEnable( componentfactoryPid, 0, -1 );
+        checkFactory( componentFactoryName, false );
 
-        ConfigurationAdmin ca = getConfigurationAdmin();
-        org.osgi.service.cm.Configuration config = ca.getConfiguration( componentfactory, null );
-        config.setBundleLocation( null );
+        org.osgi.service.cm.Configuration config = configure( componentfactoryPid );
         delay();
-        if ( isAtLeastR5() )
-        {
-            //check that ConfigurationSupport got a Location changed event and set the bundle location
-            TestCase.assertNotNull( config.getBundleLocation() );
-        } 
-        // supply configuration now and ensure active
-        configure( componentfactory );
-        delay();        
+        assertNotNull( getComponentFactory( componentFactoryName ) );
+
+        config.setBundleLocation( "foo" );
+        delay();
+        checkFactory( componentFactoryName, false );
+
+        config.setBundleLocation( bundle.getLocation() );
+        delay();
+        assertNotNull( getComponentFactory( componentFactoryName ) );
+
+        config.setBundleLocation( "foo" );
+        delay();
+        checkFactory( componentFactoryName, false );
+
+        config.setBundleLocation( "?" );
+        delay();
+        assertNotNull( getComponentFactory( componentFactoryName ) );
 
-        TestCase.assertNull( SimpleComponent.INSTANCE );
-        
-        final ComponentFactory factory = getComponentFactory(componentfactory);
-        
-        s1.drop();
     }
-    
+
 }

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=1747831&r1=1747830&r2=1747831&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 Sat Jun 11 01:14:36 2016
@@ -535,7 +535,7 @@ public abstract class ComponentTestBase
         }
     }
 
-    protected String createFactoryConfiguration(String factoryPid)
+    protected String createFactoryConfiguration(String factoryPid, String bundleLocation)
     {
         ConfigurationAdmin ca = getConfigurationAdmin();
         try

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationComponentFactoryTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationComponentFactoryTest.java?rev=1747831&r1=1747830&r2=1747831&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationComponentFactoryTest.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationComponentFactoryTest.java Sat Jun 11 01:14:36 2016
@@ -18,24 +18,17 @@
  */
 package org.apache.felix.scr.integration;
 
-
-import java.io.IOException;
 import java.util.Dictionary;
 
-import junit.framework.TestCase;
 import org.apache.felix.scr.integration.components.SimpleComponent;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.Configuration;
-import org.osgi.service.component.ComponentConstants;
-import org.osgi.service.component.ComponentException;
 import org.osgi.service.component.ComponentFactory;
-import org.osgi.service.component.ComponentInstance;
 import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
 
+import junit.framework.TestCase;
 
 /**
  * Tests of nonstandard ComponentFactory behavior
@@ -55,8 +48,6 @@ public class ConfigurationComponentFacto
         // paxRunnerVmOption = DEBUG_VM_OPTION;
     }
 
-
-
     @Test
     public void test_non_spec_component_factory_with_factory_configuration() throws Exception
     {
@@ -65,23 +56,23 @@ public class ConfigurationComponentFacto
         final String componentname = "factory.component";
         final String componentfactory = "factory.component.factory";
 
-        getConfigurationsDisabledThenEnable(componentname, 0, -1);
+        getConfigurationsDisabledThenEnable( componentname, 0, -1 );
 
         TestCase.assertNull( SimpleComponent.INSTANCE );
 
-        final ComponentFactory factory = getComponentFactory(componentfactory);
+        final ComponentFactory factory = getComponentFactory( componentfactory );
 
-        final String factoryConfigPid = createFactoryConfiguration( componentname );
+        final String factoryConfigPid = createFactoryConfiguration( componentname, "?" );
         delay();
 
         TestCase.assertNotNull( SimpleComponent.INSTANCE );
         TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
 
         // check registered components
-        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
+        checkConfigurationCount( componentname, 1, ComponentConfigurationDTO.ACTIVE );
 
         // modify the configuration
-        Configuration config = getConfigurationAdmin().getConfiguration( factoryConfigPid );
+        Configuration config = getConfigurationAdmin().getConfiguration( factoryConfigPid, "?" );
         Dictionary<String, Object> props = config.getProperties();
         props.put( PROP_NAME, PROP_NAME_FACTORY );
         config.update( props );
@@ -92,15 +83,14 @@ public class ConfigurationComponentFacto
         TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
 
         // check registered components
-        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
+        checkConfigurationCount( componentname, 1, ComponentConfigurationDTO.ACTIVE );
 
         // disable the factory
-        disableAndCheck(componentname);
+        disableAndCheck( componentname );
         delay();
 
         // enabled the factory, factory configuration results in component instance
-        getConfigurationsDisabledThenEnable(componentname, 1, ComponentConfigurationDTO.ACTIVE);
-
+        getConfigurationsDisabledThenEnable( componentname, 1, ComponentConfigurationDTO.ACTIVE );
 
         // delete the configuration
         getConfigurationAdmin().getConfiguration( factoryConfigPid ).delete();
@@ -109,7 +99,7 @@ public class ConfigurationComponentFacto
         // factory is enabled but instance has been removed
 
         // check registered components
-        checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
+        checkConfigurationCount( componentname, 0, ComponentConfigurationDTO.ACTIVE );
     }
 
 }

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/LocationTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/LocationTest.java?rev=1747831&r1=1747830&r2=1747831&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/LocationTest.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/LocationTest.java Sat Jun 11 01:14:36 2016
@@ -18,8 +18,6 @@
  */
 package org.apache.felix.scr.integration;
 
-import junit.framework.TestCase;
-
 import org.apache.felix.scr.integration.components.SimpleComponent;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -32,10 +30,12 @@ import org.osgi.service.cm.Configuration
 import org.osgi.service.cm.ConfigurationPermission;
 import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
 
+import junit.framework.TestCase;
+
 @RunWith(JUnit4TestRunner.class)
 public class LocationTest extends ComponentTestBase
 {
-    
+
     private static final String COMPONENT_NAME = "SimpleComponent.configuration.require";
     private static final String REGION = "?foo";
     private boolean eventReceived;
@@ -44,138 +44,140 @@ public class LocationTest extends Compon
     {
         descriptorFile = "/integration_test_simple_components_location.xml";
         // uncomment to enable debugging of this test class
-//         paxRunnerVmOption = DEBUG_VM_OPTION;
+        //         paxRunnerVmOption = DEBUG_VM_OPTION;
     }
 
-
+    /*
+     * tests that ds does not override a dynamic (null) location binding.
+     */
     @Test
     public void testLocationBinding() throws Exception
     {
         final String pid = COMPONENT_NAME;
         deleteConfig( pid );
         delay();
-        checkConfigurationCount(pid, 0, -1);
+        checkConfigurationCount( pid, 0, -1 );
         TestCase.assertNull( SimpleComponent.INSTANCE );
 
         Configuration config = configure( pid );
         delay();
 
-        findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
+        findComponentConfigurationByName( pid, ComponentConfigurationDTO.ACTIVE );
         TestCase.assertNotNull( SimpleComponent.INSTANCE );
         TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
-        
-        
+
+        //dynamic (null) bundle location not overridden by ds, so all bundles can use the config.
         Bundle b2 = installBundle( descriptorFile, COMPONENT_PACKAGE, "simplecomponent2", "0.0.11", null );
         b2.start();
-        checkConfigurationCount(b2, pid, 0, -1);
-        
+        checkConfigurationCount( b2, pid, 1, -1 );
+
         bundle.stop();
         delay();
-        
-        checkConfigurationCount(b2, pid, 0, -1);
 
-        ConfigurationListener listener = new ConfigurationListener() {
+        checkConfigurationCount( b2, pid, 1, -1 );
+
+        ConfigurationListener listener = new ConfigurationListener()
+        {
 
             public void configurationEvent(ConfigurationEvent event)
             {
-                if (event.getType() == ConfigurationEvent.CM_LOCATION_CHANGED)
+                if ( event.getType() == ConfigurationEvent.CM_LOCATION_CHANGED )
                 {
                     eventReceived = true;
                 }
             }
-            
+
         };
-        ServiceRegistration<ConfigurationListener> sr = bundleContext.registerService( ConfigurationListener.class, listener, null );
+        ServiceRegistration<ConfigurationListener> sr = bundleContext.registerService( ConfigurationListener.class,
+            listener, null );
         config.setBundleLocation( null );
         delay();
-        
+
         if ( eventReceived )
         {
-            checkConfigurationCount(b2, pid, 1, ComponentConfigurationDTO.ACTIVE);
+            checkConfigurationCount( b2, pid, 1, ComponentConfigurationDTO.ACTIVE );
         }
-        
+
         sr.unregister();
-        
-        
+
     }
 
     @Test
     public void testLocationChangeToRegionBinding() throws Exception
     {
         final String pid = COMPONENT_NAME;
-        checkConfigurationCount(pid, 0, -1);
+        checkConfigurationCount( pid, 0, -1 );
         TestCase.assertNull( SimpleComponent.INSTANCE );
 
         Configuration config = configure( pid );
         delay();
 
-        findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
+        findComponentConfigurationByName( pid, ComponentConfigurationDTO.ACTIVE );
         TestCase.assertNotNull( SimpleComponent.INSTANCE );
         TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
-        
-        
+
         Bundle b2 = installBundle( descriptorFile, COMPONENT_PACKAGE, "simplecomponent2", "0.0.11", null );
         b2.start();
-        checkConfigurationCount(b2, pid, 0, -1);
-        
+        checkConfigurationCount( b2, pid, 1, -1 );
+
         bundle.stop();
         delay();
-        
-        checkConfigurationCount(b2, pid, 0, -1);
 
-        ConfigurationListener listener = new ConfigurationListener() {
+        checkConfigurationCount( b2, pid, 1, -1 );
+
+        ConfigurationListener listener = new ConfigurationListener()
+        {
 
             public void configurationEvent(ConfigurationEvent event)
             {
-                if (event.getType() == ConfigurationEvent.CM_LOCATION_CHANGED)
+                if ( event.getType() == ConfigurationEvent.CM_LOCATION_CHANGED )
                 {
                     eventReceived = true;
                 }
             }
-            
+
         };
-        ServiceRegistration<ConfigurationListener> sr = bundleContext.registerService( ConfigurationListener.class, listener, null );
+        ServiceRegistration<ConfigurationListener> sr = bundleContext.registerService( ConfigurationListener.class,
+            listener, null );
         config.setBundleLocation( REGION );
         delay();
-        
+
         if ( eventReceived )
         {
-            checkConfigurationCount(b2, pid, 1, ComponentConfigurationDTO.ACTIVE);
+            checkConfigurationCount( b2, pid, 1, ComponentConfigurationDTO.ACTIVE );
         }
-        
+
         sr.unregister();
-        
-        
+
     }
-    
+
     @Test
     public void testRegionBinding() throws Exception
     {
         try
         {
-            new ConfigurationPermission(REGION, ConfigurationPermission.TARGET);
+            new ConfigurationPermission( REGION, ConfigurationPermission.TARGET );
         }
-        catch (IllegalArgumentException e)
+        catch ( IllegalArgumentException e )
         {
             return;//not an R5 CA
         }
-        
+
         final String pid = COMPONENT_NAME;
         deleteConfig( pid );
-        checkConfigurationCount(pid, 0, -1);
+        checkConfigurationCount( pid, 0, -1 );
         TestCase.assertNull( SimpleComponent.INSTANCE );
 
         Configuration config = configure( pid, REGION );
         delay();
 
-        findComponentConfigurationByName(pid,  ComponentConfigurationDTO.ACTIVE);
+        findComponentConfigurationByName( pid, ComponentConfigurationDTO.ACTIVE );
         TestCase.assertNotNull( SimpleComponent.INSTANCE );
         TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
-        
-        
+
         Bundle b2 = installBundle( descriptorFile, COMPONENT_PACKAGE, "simplecomponent2", "0.0.11", null );
         b2.start();
-        checkConfigurationCount(b2, pid, 1, ComponentConfigurationDTO.ACTIVE);
+        checkConfigurationCount( b2, pid, 1, ComponentConfigurationDTO.ACTIVE );
 
     }
 



Mime
View raw message