You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ro...@apache.org on 2021/05/09 16:05:22 UTC
[felix-dev] branch master updated: [FELIX-6411] use friendly name
as factory name when creating new configurations
This is an automated email from the ASF dual-hosted git repository.
rotty3000 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new 131ceab [FELIX-6411] use friendly name as factory name when creating new configurations
131ceab is described below
commit 131ceab4f21b8a151b3d2b5234a4994320658ed7
Author: Raymond Augé <ro...@apache.org>
AuthorDate: Sun May 9 11:36:01 2021 -0400
[FELIX-6411] use friendly name as factory name when creating new configurations
Signed-off-by: Raymond Augé <ro...@apache.org>
---
.../fileinstall/internal/ConfigInstaller.java | 39 +++++++++++++++-------
.../fileinstall/internal/ConfigInstallerTest.java | 14 +++++---
2 files changed, 37 insertions(+), 16 deletions(-)
diff --git a/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java b/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java
index 78bd5cb..fa38f94 100644
--- a/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java
+++ b/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java
@@ -70,6 +70,7 @@ public class ConfigInstaller implements ArtifactInstaller, ConfigurationListener
private final ConfigurationAdmin configAdmin;
private final FileInstall fileInstall;
private final Map<String, String> pidToFile = new HashMap<>();
+ private final Method getFactoryConfigurationMethod;
private final Method addAttributesMethod;
private final Method getAttributesMethod;
private final Method removeAttributesMethod;
@@ -83,12 +84,20 @@ public class ConfigInstaller implements ArtifactInstaller, ConfigurationListener
this.configAdmin = configAdmin;
this.fileInstall = fileInstall;
+ Method gfcMethod = null;
Method aaMethod = null;
Method gaMethod = null;
Method raMethod = null;
Method uidMethod = null;
if (this.configAdmin != null) {
+ for (Method method : ConfigurationAdmin.class.getDeclaredMethods())
+ {
+ if ("getFactoryConfiguration".equals(method.getName()) && (method.getParameterCount() == 3))
+ {
+ gfcMethod = method;
+ }
+ }
for (Method method : Configuration.class.getDeclaredMethods())
{
if ("addAttributes".equals(method.getName()))
@@ -110,6 +119,7 @@ public class ConfigInstaller implements ArtifactInstaller, ConfigurationListener
}
}
+ this.getFactoryConfigurationMethod = gfcMethod;
this.addAttributesMethod = aaMethod;
this.getAttributesMethod = gaMethod;
this.removeAttributesMethod = raMethod;
@@ -391,12 +401,12 @@ public class ConfigInstaller implements ArtifactInstaller, ConfigurationListener
{
ht.put(DirectoryWatcher.FILENAME, toConfigKey(f));
if (old == null) {
- Util.log(context, Logger.LOG_INFO, "Creating configuration {" + pid[0]
- + (pid[1] == null ? "" : "-" + pid[1])
+ Util.log(context, Logger.LOG_INFO, "Creating configuration {"
+ + config.getPid()
+ "} from " + f.getAbsolutePath(), null);
} else {
- Util.log(context, Logger.LOG_INFO, "Updating configuration {" + pid[0]
- + (pid[1] == null ? "" : "-" + pid[1])
+ Util.log(context, Logger.LOG_INFO, "Updating configuration {"
+ + config.getPid()
+ "} from " + f.getAbsolutePath(), null);
}
update0(config, ht);
@@ -423,10 +433,10 @@ public class ConfigInstaller implements ArtifactInstaller, ConfigurationListener
boolean deleteConfig(File f) throws Exception
{
String pid[] = parsePid(f.getName());
- Util.log(context, Logger.LOG_INFO, "Deleting configuration {" + pid[0]
- + (pid[1] == null ? "" : "-" + pid[1])
- + "} from " + f.getAbsolutePath(), null);
Configuration config = getConfiguration(toConfigKey(f), pid[0], pid[1]);
+ Util.log(context, Logger.LOG_INFO, "Deleting configuration {"
+ + config.getPid()
+ + "} from " + f.getAbsolutePath(), null);
config.delete();
return true;
}
@@ -476,7 +486,12 @@ public class ConfigInstaller implements ArtifactInstaller, ConfigurationListener
Configuration newConfiguration;
if (factoryPid != null)
{
- newConfiguration = getConfigurationAdmin().createFactoryConfiguration(pid, "?");
+ if (getFactoryConfigurationMethod != null) {
+ newConfiguration = (Configuration)getFactoryConfigurationMethod.invoke(getConfigurationAdmin(), pid, factoryPid, "?");
+ }
+ else {
+ newConfiguration = getConfigurationAdmin().createFactoryConfiguration(pid, "?");
+ }
}
else
{
@@ -544,8 +559,8 @@ public class ConfigInstaller implements ArtifactInstaller, ConfigurationListener
try {
if (Util.canWrite(f) && isReadOnly(configuration)) {
- Util.log(context, Logger.LOG_INFO, "Removing READ_ONLY attribute from configuration {" + pid[0]
- + (pid[1] == null ? "" : "-" + pid[1])
+ Util.log(context, Logger.LOG_INFO, "Removing READ_ONLY attribute from configuration {"
+ + configuration.getPid()
+ "} from " + f.getAbsolutePath(), null);
removeAttributesMethod.invoke(configuration, READ_ONLY_ATTRIBUTE_ARRAY);
}
@@ -570,8 +585,8 @@ public class ConfigInstaller implements ArtifactInstaller, ConfigurationListener
try {
if (!Util.canWrite(f)) {
- Util.log(context, Logger.LOG_INFO, "Adding READ_ONLY attribute to configuration {" + pid[0]
- + (pid[1] == null ? "" : "-" + pid[1])
+ Util.log(context, Logger.LOG_INFO, "Adding READ_ONLY attribute to configuration {"
+ + configuration.getPid()
+ "} from " + f.getAbsolutePath(), null);
addAttributesMethod.invoke(configuration, READ_ONLY_ATTRIBUTE_ARRAY);
diff --git a/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java b/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java
index 3eb872d..1f8b3ac 100644
--- a/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java
+++ b/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java
@@ -96,6 +96,7 @@ public class ConfigInstallerTest extends TestCase {
EasyMock.expect(mockConfigurationAdmin.getConfiguration(pid, "?"))
.andReturn(mockConfiguration);
EasyMock.expect(mockConfiguration.getAttributes()).andReturn(Collections.emptySet());
+ EasyMock.expect(mockConfiguration.getPid()).andReturn(pid);
EasyMock.expect(mockConfiguration.getProperties())
.andReturn(null);
EasyMock.expect(mockBundleContext.getProperty((String) EasyMock.anyObject()))
@@ -133,6 +134,7 @@ public class ConfigInstallerTest extends TestCase {
.andReturn(Collections.emptySet());
EasyMock.expect(mockConfiguration.getProperties())
.andReturn(null);
+ EasyMock.expect(mockConfiguration.getPid()).andReturn(pid);
EasyMock.expect(mockBundleContext.getProperty((String) EasyMock.anyObject()))
.andReturn(null)
.anyTimes();
@@ -155,7 +157,7 @@ public class ConfigInstallerTest extends TestCase {
EasyMock.expect(mockBundle.loadClass(ConfigurationAttribute.class.getName())).andReturn((Class)ConfigurationAttribute.class).anyTimes();
EasyMock.expect(mockConfigurationAdmin.listConfigurations((String) EasyMock.anyObject()))
.andReturn(null);
- EasyMock.expect(mockConfigurationAdmin.createFactoryConfiguration( "pid", "?" ))
+ EasyMock.expect(mockConfigurationAdmin.getFactoryConfiguration( "pid", "factoryPid", "?" ))
.andReturn(mockConfiguration);
EasyMock.replay(mockConfiguration, mockConfigurationAdmin, mockBundleContext, mockBundle);
@@ -173,7 +175,7 @@ public class ConfigInstallerTest extends TestCase {
EasyMock.expect(mockBundle.loadClass(ConfigurationAttribute.class.getName())).andReturn((Class)ConfigurationAttribute.class).anyTimes();
EasyMock.expect(mockConfigurationAdmin.listConfigurations((String) EasyMock.anyObject()))
.andReturn(null);
- EasyMock.expect(mockConfigurationAdmin.createFactoryConfiguration( "pid", "?" ))
+ EasyMock.expect(mockConfigurationAdmin.getFactoryConfiguration( "pid", "factoryPid", "?" ))
.andReturn(mockConfiguration);
EasyMock.replay(mockConfiguration, mockConfigurationAdmin, mockBundleContext, mockBundle);
@@ -206,6 +208,7 @@ public class ConfigInstallerTest extends TestCase {
public void testDeleteConfig() throws Exception
{
mockConfiguration.delete();
+ EasyMock.expect(mockConfiguration.getPid()).andReturn("pid");
EasyMock.expect(mockBundleContext.getBundle()).andReturn(mockBundle).anyTimes();
EasyMock.expect(mockBundle.loadClass(ConfigurationAttribute.class.getName())).andReturn((Class)ConfigurationAttribute.class).anyTimes();
EasyMock.expect(mockBundleContext.getProperty((String) EasyMock.anyObject()))
@@ -261,7 +264,7 @@ public class ConfigInstallerTest extends TestCase {
}
});
EasyMock.expect(mockConfiguration.getPid())
- .andReturn(pid);
+ .andReturn(pid).times(2);
EasyMock.replay(mockConfiguration, mockConfigurationAdmin, mockBundleContext, mockBundle, sr);
@@ -377,7 +380,7 @@ public class ConfigInstallerTest extends TestCase {
.anyTimes();
EasyMock.expect(cachingPersistenceConfiguration.getPid())
- .andReturn(pid);
+ .andReturn(pid).times(2);
EasyMock.expect(mockConfigurationAdmin.getConfiguration(pid, "?"))
.andReturn(cachingPersistenceConfiguration)
@@ -438,6 +441,7 @@ public class ConfigInstallerTest extends TestCase {
EasyMock.expect(mockBundleContext.getProperty(DirectoryWatcher.LOG_LEVEL)).andReturn(null);
EasyMock.expect(mockConfiguration.getProperties()).andReturn(new Hashtable<String, Object>());
EasyMock.expect(mockConfiguration.getAttributes()).andReturn(Collections.emptySet());
+ EasyMock.expect(mockConfiguration.getPid()).andReturn("firstcfg");
EasyMock.reportMatcher(new IArgumentMatcher()
{
public boolean matches( Object argument )
@@ -559,6 +563,8 @@ public class ConfigInstallerTest extends TestCase {
}
};
+ EasyMock.expect(cachingPersistenceConfiguration.getPid())
+ .andReturn(pid).times(3);
EasyMock.expect(cachingPersistenceConfiguration.getProperties())
.andReturn(cachedProps)
.anyTimes();