in config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java [222:273]
protected void persistConfiguration(Configuration cfg, Dictionary clusterDictionary) {
try {
File storageFile = getStorageFile(cfg.getProperties());
if (storageFile == null && cfg.getProperties().get(ConfigurationAdmin.SERVICE_FACTORYPID) != null) {
storageFile = new File(storage, cfg.getPid() + ".cfg");
}
if (storageFile == null) {
// it's a factory configuration without filename specified, cannot save
return;
}
String content = clusterDictionary == null ? null : (String) clusterDictionary.get(KARAF_CELLAR_CONTENT);
if (content == null) {
org.apache.felix.utils.properties.Properties p = new org.apache.felix.utils.properties.Properties(storageFile);
List<String> propertiesToRemove = new ArrayList<String>();
Set<String> set = p.keySet();
for (String key : set) {
if (!org.osgi.framework.Constants.SERVICE_PID.equals(key)
&& !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
&& !KARAF_CELLAR_FILENAME.equals(key)
&& !FELIX_FILEINSTALL_FILENAME.equals(key)) {
propertiesToRemove.add(key);
}
}
for (String key : propertiesToRemove) {
p.remove(key);
}
Dictionary props = cfg.getProperties();
for (Enumeration<String> keys = props.keys(); keys.hasMoreElements(); ) {
String key = keys.nextElement();
if (!org.osgi.framework.Constants.SERVICE_PID.equals(key)
&& !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
&& !KARAF_CELLAR_FILENAME.equals(key)
&& !FELIX_FILEINSTALL_FILENAME.equals(key)) {
p.put(key, (String) props.get(key));
}
}
// save the cfg file
storage.mkdirs();
p.save();
} else {
writeFile(storageFile, content);
}
} catch (Exception e) {
LOGGER.error("CELLAR CONFIG: Issue when trying to persist configuration file", e);
}
}