FELIX-4951 : [DS][RFC-190] Correct pid handling - use scalar if single pid
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1689515 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java b/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java
index c8ed9c5..b2ba734 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java
@@ -469,7 +469,14 @@
}
if (isDS13 && !pids.isEmpty())
{
- properties.put(Constants.SERVICE_PID, pids);
+ if ( pids.size() == 1 )
+ {
+ properties.put(Constants.SERVICE_PID, pids.get(0));
+ }
+ else
+ {
+ properties.put(Constants.SERVICE_PID, pids);
+ }
}
return properties;
}
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 0c81778..fa781e5 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
@@ -443,16 +443,29 @@
props.putAll(m_factoryProperties);
if (getComponentMetadata().getDSVersion().isDS13() && m_factoryProperties.containsKey(Constants.SERVICE_PID))
{
- List<String> servicePids = (List<String>) m_configurationProperties.get(Constants.SERVICE_PID);
- if (servicePids == null)
- {
- servicePids = new ArrayList<String>();
- }
+ final List<String> servicePids = new ArrayList<String>();
+ final Object configPropServicePids = m_configurationProperties.get(Constants.SERVICE_PID);
+ if ( configPropServicePids instanceof List )
+ {
+ servicePids.addAll((List)configPropServicePids);
+ }
+ else
+ {
+ servicePids.add(configPropServicePids.toString());
+ }
if (m_factoryProperties.get(Constants.SERVICE_PID) instanceof String)
{
servicePids.add((String)m_factoryProperties.get(Constants.SERVICE_PID));
}
- props.put(Constants.SERVICE_PID, servicePids);
+
+ if ( servicePids.size() == 1 )
+ {
+ props.put(Constants.SERVICE_PID, servicePids.get(0));
+ }
+ else
+ {
+ props.put(Constants.SERVICE_PID, servicePids);
+ }
}
}
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 951abc2..2a6b93d 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
@@ -214,7 +214,7 @@
}
else
{
- pidWithout = Collections.singletonList(pid + ".description");
+ pidWithout = pid + ".description";
pidWith = Arrays.asList(new String[] {pid + ".description", pid});
}
deleteConfig( pid );