FELIX-2526 Implement workaround for CT bugs and add framework property to enable the workarounds
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@982892 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
index 7fad6e5..e9f4d39 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
@@ -73,6 +73,10 @@
// thread acting upon configurations
private ComponentActorThread m_componentActor;
+ // whether to support two workarounds to run the OSGi R 4.2 CT
+ // See hasCtWorkaround()
+ private static boolean m_ctWorkaround;
+
/**
* Registers this instance as a (synchronous) bundle listener and loads the
* components of already registered bundles.
@@ -100,6 +104,9 @@
log( LogService.LOG_INFO, context.getBundle(), " Version = "
+ context.getBundle().getHeaders().get( Constants.BUNDLE_VERSION ), null );
+ // check whether we workaround OSGi CT issues
+ m_ctWorkaround = ScrConfiguration.hasCtWorkaround( context );
+
// create and start the component actor
m_componentActor = new ComponentActorThread();
Thread t = new Thread(m_componentActor, "SCR Component Actor");
@@ -474,4 +481,33 @@
return m_packageAdmin.getService();
}
+
+
+ /**
+ * Returns <code>true</code> if the <code>ds.ctworkaround</code> framework
+ * property has been set to <code>true</code>. Otherwise <code>false</code>
+ * is returned.
+ * <p>
+ * If this method returns <code>true</code>, two workarounds for the OSGi
+ * Compendium R 4.2 CT for Declarative Services are active:
+ * <ul>
+ * <li>The <code>ComponentContext.getProperties()</code> implementation
+ * always returns the same writeable <code>Dictionary</code> instead of
+ * a read-only dictionary</li>
+ * <li>Location binding of <code>Configuration</code> objects supplied to
+ * components is ignored.</li>
+ * </ul>
+ * <p>
+ * Setting the <code>ds.ctworkaround</code> framework property is required
+ * to pass the CT but setting the property in a productive environment
+ * is strongly discouraged.
+ *
+ * @return <code>true</code> if the <code>ds.ctworkaround</code> framework
+ * property is set to <code>true</code>.
+ * @see <a href="https://issues.apache.org/jira/browse/FELIX-2526">FELIX-2526</a>
+ */
+ public static boolean hasCtWorkaround()
+ {
+ return m_ctWorkaround;
+ }
}
\ No newline at end of file
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java b/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java
index 027d1ca..069cf82 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java
@@ -235,6 +235,10 @@
cm = getComponentHolder( factoryPid );
}
+ Activator.log( LogService.LOG_DEBUG, null, "configurationEvent: Handling "
+ + ( ( event.getType() == ConfigurationEvent.CM_DELETED ) ? "DELETE" : "UPDATE" ) + " of Configuration PID="
+ + pid, null );
+
if ( cm != null && !cm.getComponentMetadata().isConfigurationIgnored() )
{
switch ( event.getType() )
@@ -299,7 +303,7 @@
try
{
final Configuration cfg = ca.getConfiguration( pid );
- if ( bundleLocation.equals( cfg.getBundleLocation() ) )
+ if ( Activator.hasCtWorkaround() || bundleLocation.equals( cfg.getBundleLocation() ) )
{
return cfg.getProperties();
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java
index 4883d36..8428750 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java
@@ -22,6 +22,7 @@
import java.util.Dictionary;
import java.util.Hashtable;
+import org.apache.felix.scr.impl.Activator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.service.cm.ConfigurationException;
@@ -46,6 +47,9 @@
static final String PROP_LOGLEVEL = "ds.loglevel";
+ // framework property to enable the CT workarounds (see FELIX-2526)
+ private static final String PROP_CT_WORKAROUND = "ds.ctworkaround";
+
private static final String LOG_LEVEL_DEBUG = "debug";
private static final String LOG_LEVEL_INFO = "info";
@@ -64,6 +68,8 @@
private boolean factoryEnabled;
+ private boolean ctWorkaround;
+
static final String PID = "org.apache.felix.scr.ScrService";
public ScrConfiguration( BundleContext bundleContext )
@@ -109,7 +115,6 @@
{
if ( config == null )
{
-
logLevel = getDefaultLogLevel();
factoryEnabled = getDefaultFactoryEnabled();
}
@@ -132,7 +137,30 @@
}
- private boolean getDefaultFactoryEnabled() {
+ public static boolean hasCtWorkaround( final BundleContext bundleContext )
+ {
+ boolean ctWorkaround = VALUE_TRUE.equals( bundleContext.getProperty( PROP_CT_WORKAROUND ) );
+ if ( ctWorkaround )
+ {
+ Activator
+ .log(
+ LogService.LOG_WARNING,
+ bundleContext.getBundle(),
+ "OSGi CT Workaround enabled. This Declarative Services instance is not operating specification compliant:",
+ null );
+ Activator.log( LogService.LOG_WARNING, bundleContext.getBundle(),
+ " - Dictionary returned from ComponentContext.getProperties() is writeable", null );
+ Activator.log( LogService.LOG_WARNING, bundleContext.getBundle(),
+ " - Location Binding of Configuration is ignored", null );
+ Activator.log( LogService.LOG_WARNING, bundleContext.getBundle(), "Remove " + PROP_CT_WORKAROUND
+ + " framework property to operate specification compliant", null );
+ }
+ return ctWorkaround;
+ }
+
+
+ private boolean getDefaultFactoryEnabled()
+ {
return VALUE_TRUE.equals( bundleContext.getProperty( PROP_FACTORY_ENABLED ) );
}
@@ -203,7 +231,8 @@
{
return new MetaTypeProviderImpl( getDefaultLogLevel(), getDefaultFactoryEnabled(),
( ManagedService ) managedService );
- } catch (Throwable t)
+ }
+ catch ( Throwable t )
{
// we simply ignore this
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
index 537e61a..3d5b925 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
@@ -21,6 +21,7 @@
import java.util.Dictionary;
+import org.apache.felix.scr.impl.Activator;
import org.apache.felix.scr.impl.helper.ReadOnlyDictionary;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -52,8 +53,13 @@
public final Dictionary getProperties()
{
- // 112.11.3.5 The Dictionary is read-only and cannot be modified
- return new ReadOnlyDictionary( m_componentManager.getProperties() );
+ // 112.12.3.5 The Dictionary is read-only and cannot be modified
+ Dictionary ctxProperties = m_componentManager.getProperties();
+ if ( !Activator.hasCtWorkaround() )
+ {
+ ctxProperties = new ReadOnlyDictionary( ctxProperties );
+ }
+ return ctxProperties;
}