karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject karaf git commit: [KARAF-3527] Appending config from feature doesn't work
Date Fri, 20 Feb 2015 12:16:31 GMT
Repository: karaf
Updated Branches:
  refs/heads/master 47414d989 -> 9ecba38a4


[KARAF-3527] Appending config from feature doesn't work

Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/9ecba38a
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/9ecba38a
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/9ecba38a

Branch: refs/heads/master
Commit: 9ecba38a4569fad00fc7a454b05bd486d8e63ae3
Parents: 47414d9
Author: Guillaume Nodet <gnodet@gmail.com>
Authored: Fri Feb 20 13:15:47 2015 +0100
Committer: Guillaume Nodet <gnodet@gmail.com>
Committed: Fri Feb 20 13:15:47 2015 +0100

----------------------------------------------------------------------
 .../service/FeatureConfigInstaller.java         | 31 +++++++---------
 .../org/apache/karaf/features/AppendTest.java   | 38 ++++++++++++++++++--
 2 files changed, 48 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/9ecba38a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
index aa5c21e..1940868 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
@@ -89,41 +89,34 @@ public class FeatureConfigInstaller {
         return null;
     }
 
-    void installFeatureConfigs(Feature feature) throws IOException, InvalidSyntaxException
{
+    public void installFeatureConfigs(Feature feature) throws IOException, InvalidSyntaxException
{
     	for (ConfigInfo config : feature.getConfigurations()) {
-    		String name = config.getName();
 			Properties props = config.getProperties();
 			String[] pid = parsePid(config.getName());
-			Configuration cfg = findExistingConfiguration(configAdmin, pid[0],
-					pid[1]);
+			Configuration cfg = findExistingConfiguration(configAdmin, pid[0], pid[1]);
 			if (cfg == null) {
 				Dictionary<String, String> cfgProps = convertToDict(props);
-
 				cfg = createConfiguration(configAdmin, pid[0], pid[1]);
 				String key = createConfigurationKey(pid[0], pid[1]);
 				cfgProps.put(CONFIG_KEY, key);
 				cfg.update(cfgProps);
 			} else if (config.isAppend()) {
+                boolean update = false;
 				Dictionary<String,Object> properties = cfg.getProperties();
-				for (Enumeration<String> propKeys = properties.keys(); propKeys
-						.hasMoreElements();) {
-					String key = propKeys.nextElement();
-					// remove existing entry, since it's about appending.
-					if (props.containsKey(key)) {
-						props.remove(key);
-					} 
-				}
-				if (props.size() > 0) {
-					// convert props to dictionary
-					Dictionary<String, String> cfgProps = convertToDict(props);
-					cfg.update(cfgProps);
-				}
+                for (String key : props.stringPropertyNames()) {
+                    if (properties.get(key) == null) {
+                        properties.put(key, props.getProperty(key));
+                        update = true;
+                    }
+                }
+                if (update) {
+                    cfg.update(properties);
+                }
 			}
 		}
         for (ConfigFileInfo configFile : feature.getConfigurationFiles()) {
             installConfigurationFile(configFile.getLocation(), configFile.getFinalname(),
configFile.isOverride());
         }
-
     }
 
 	private Dictionary<String, String> convertToDict(Properties props) {

http://git-wip-us.apache.org/repos/asf/karaf/blob/9ecba38a/features/core/src/test/java/org/apache/karaf/features/AppendTest.java
----------------------------------------------------------------------
diff --git a/features/core/src/test/java/org/apache/karaf/features/AppendTest.java b/features/core/src/test/java/org/apache/karaf/features/AppendTest.java
index da7e3cc..f0fb326 100644
--- a/features/core/src/test/java/org/apache/karaf/features/AppendTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/AppendTest.java
@@ -16,10 +16,15 @@
  */
 package org.apache.karaf.features;
 
+import java.util.Hashtable;
 import java.util.Properties;
 
 import junit.framework.TestCase;
+import org.apache.karaf.features.internal.service.FeatureConfigInstaller;
 import org.apache.karaf.features.internal.service.RepositoryImpl;
+import org.easymock.EasyMock;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
 
 public class AppendTest extends TestCase {
 
@@ -39,10 +44,39 @@ public class AppendTest extends TestCase {
 
 		Properties properties = configInfo.getProperties();
 		assertNotNull(properties);
-		String property = properties
-				.getProperty("javax.servlet.context.tempdir");
+		String property = properties.getProperty("javax.servlet.context.tempdir");
 		assertNotNull(property);
 		assertFalse(property.contains("${"));
 
+		ConfigurationAdmin admin = EasyMock.createMock(ConfigurationAdmin.class);
+		Configuration config = EasyMock.createMock(Configuration.class);
+		EasyMock.expect(admin.listConfigurations(EasyMock.eq("(service.pid=org.ops4j.pax.web)")))
+				.andReturn(new Configuration[] { config });
+		Hashtable<String, Object> original = new Hashtable<>();
+		original.put("org.apache.karaf.features.configKey", "org.ops4j.pax.web");
+		original.put("foo", "bar");
+		EasyMock.expect(config.getProperties()).andReturn(original);
+		Hashtable<String, Object> expected = new Hashtable<>();
+		expected.put("org.apache.karaf.features.configKey", "org.ops4j.pax.web");
+		expected.put("javax.servlet.context.tempdir", "data/pax-web-jsp");
+		expected.put("foo", "bar");
+		config.update(EasyMock.eq(expected));
+		EasyMock.expectLastCall();
+		EasyMock.replay(admin, config);
+		FeatureConfigInstaller installer = new FeatureConfigInstaller(admin);
+		installer.installFeatureConfigs(feature);
+		EasyMock.verify(admin, config);
+
+		EasyMock.reset(admin, config);
+		EasyMock.expect(admin.listConfigurations(EasyMock.eq("(service.pid=org.ops4j.pax.web)")))
+				.andReturn(new Configuration[]{config});
+		original = new Hashtable<>();
+		original.put("org.apache.karaf.features.configKey", "org.ops4j.pax.web");
+		original.put("javax.servlet.context.tempdir", "value");
+		original.put("foo", "bar");
+		EasyMock.expect(config.getProperties()).andReturn(original);
+		EasyMock.replay(admin, config);
+		installer.installFeatureConfigs(feature);
+		EasyMock.verify(admin, config);
 	}
 }


Mime
View raw message