[FELIX-4022] Implement spec compliant behavior for pre and post 1.3 with a flag to get reasonable behavior pre-1.3. Question is whether deleting a config calls modify(1.3) or deactivates(pre 1.3)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1591423 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java
index 61ca8b8..00e01f9 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java
@@ -667,6 +667,12 @@
private boolean modify()
{
+ //0 SCR 112.7.1 If configuration is deleted, and version is < 1.3 and no flag set, then deactivate unconditionally.
+ // For version 1.3 and later, or with a flag, more sensible behavior is allowed.
+ if ( m_configurationProperties == null && !getComponentMetadata().isDeleteCallsModify()){
+ return false;
+ }
+
// 1. no live update if there is no declared method
if ( getComponentMetadata().getModified() == null )
{
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/metadata/ComponentMetadata.java b/scr/src/main/java/org/apache/felix/scr/impl/metadata/ComponentMetadata.java
index c0d3208..f24785b 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/metadata/ComponentMetadata.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/metadata/ComponentMetadata.java
@@ -463,6 +463,16 @@
{
return getNamespaceCode() >= XmlHandler.DS_VERSION_1_2_FELIX;
}
+
+ /**
+ * Returns <code>true</code> if the metadata declaration has used the
+ * Declarative Services version 1.3 namespace or a later namespace.
+ */
+ public boolean isDS13()
+ {
+ return getNamespaceCode() >= XmlHandler.DS_VERSION_1_3;
+ }
+
/**
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
index 749495b..6483df3 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
@@ -183,7 +183,29 @@
public void test_SimpleComponent_dynamic_configuration()
{
final String pid = "DynamicConfigurationComponent";
- final Component component = findComponentByName( pid );
+ boolean pre13 = true;
+ dynamicConfigTest(pid, pre13);
+ }
+
+ @Test
+ public void test_SimpleComponent_dynamic_configuration_13()
+ {
+ final String pid = "DynamicConfigurationComponent13";
+ boolean pre13 = false;
+ dynamicConfigTest(pid, pre13);
+ }
+
+ @Test
+ public void test_SimpleComponent_dynamic_configuration_flag()
+ {
+ final String pid = "DynamicConfigurationComponentFlag";
+ boolean pre13 = false;
+ dynamicConfigTest(pid, pre13);
+ }
+
+
+ private void dynamicConfigTest(final String pid, boolean pre13) {
+ final Component component = findComponentByName( pid );
deleteConfig( pid );
delay();
@@ -216,7 +238,14 @@
delay();
TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
- TestCase.assertSame( instance, SimpleComponent.INSTANCE );
+ if (pre13)
+ {
+ TestCase.assertNotSame( instance, SimpleComponent.INSTANCE );
+ }
+ else
+ {
+ TestCase.assertSame( instance, SimpleComponent.INSTANCE );
+ }
TestCase.assertNull( SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );
@@ -225,7 +254,7 @@
TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
TestCase.assertNull( SimpleComponent.INSTANCE );
- }
+ }
@Test
@@ -486,7 +515,7 @@
// optional ref missing --> component active
TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
- TestCase.assertEquals( instance, SimpleComponent.INSTANCE );
+ TestCase.assertNotSame( instance, SimpleComponent.INSTANCE );
TestCase.assertNull( SimpleComponent.INSTANCE.m_singleRef );
component.disable();
diff --git a/scr/src/test/resources/integration_test_simple_components.xml b/scr/src/test/resources/integration_test_simple_components.xml
index 07de31a..86a784b 100644
--- a/scr/src/test/resources/integration_test_simple_components.xml
+++ b/scr/src/test/resources/integration_test_simple_components.xml
@@ -50,6 +50,19 @@
<property name="service.pid" value="DynamicConfigurationComponent" />
</scr:component>
+ <scr13:component xmlns:scr13="http://www.osgi.org/xmlns/scr/v1.3.0" name="DynamicConfigurationComponent13"
+ enabled="false" modified="configure">
+ <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+ <property name="service.pid" value="DynamicConfigurationComponent13" />
+ </scr13:component>
+
+ <scr:component xmlns:felix="http://felix.apache.org/xmlns/scr/extensions/v1.0.0" name="DynamicConfigurationComponentFlag"
+ enabled="false" modified="configure"
+ felix:deleteCallsModify="true">
+ <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+ <property name="service.pid" value="DynamicConfigurationComponentFlag" />
+ </scr:component>
+
<!-- component dynamically updates configuration with a required reference plus target-->
<scr:component name="DynamicConfigurationComponentWithRequiredReference"
enabled="false" modified="configure">