Repository: karaf Updated Branches: refs/heads/master 3b42fb5a5 -> 0cbb26858
Replace tabs in files Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/935006e6 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/935006e6 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/935006e6 Branch: refs/heads/master Commit: 935006e6d1ca68a5f84b2ad1584e7db84f939eb5 Parents: 3b42fb5 Author: Christian Schneider <[email protected]> Authored: Fri Aug 11 10:07:52 2017 +0200 Committer: Christian Schneider <[email protected]> Committed: Fri Aug 11 10:07:52 2017 +0200 ---------------------------------------------------------------------- .../service/FeatureConfigInstaller.java | 80 ++++++++--------- .../org/apache/karaf/features/AppendTest.java | 90 ++++++++++---------- .../org/apache/karaf/features/FeatureTest.java | 20 ++--- .../apache/karaf/features/RepositoryTest.java | 12 ++- 4 files changed, 104 insertions(+), 98 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/935006e6/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 d1fc525..77522c5 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 @@ -73,8 +73,9 @@ public class FeatureConfigInstaller { } } - private Configuration createConfiguration(ConfigurationAdmin configurationAdmin, - String pid, String factoryPid) throws IOException, InvalidSyntaxException { + private Configuration createConfiguration(ConfigurationAdmin configurationAdmin, String pid, + String factoryPid) + throws IOException, InvalidSyntaxException { if (factoryPid != null) { return configurationAdmin.createFactoryConfiguration(pid, null); } else { @@ -82,8 +83,9 @@ public class FeatureConfigInstaller { } } - private Configuration findExistingConfiguration(ConfigurationAdmin configurationAdmin, - String pid, String factoryPid) throws IOException, InvalidSyntaxException { + private Configuration findExistingConfiguration(ConfigurationAdmin configurationAdmin, String pid, + String factoryPid) + throws IOException, InvalidSyntaxException { String filter; if (factoryPid == null) { filter = "(" + Constants.SERVICE_PID + "=" + pid + ")"; @@ -99,7 +101,7 @@ public class FeatureConfigInstaller { } public void installFeatureConfigs(Feature feature) throws IOException, InvalidSyntaxException { - for (ConfigInfo config : feature.getConfigurations()) { + for (ConfigInfo config : feature.getConfigurations()) { TypedProperties props = new TypedProperties(); // trim lines String val = config.getValue(); @@ -108,14 +110,14 @@ public class FeatureConfigInstaller { } else { props.load(new StringReader(val)); } - String[] pid = parsePid(config.getName()); - Configuration cfg = findExistingConfiguration(configAdmin, pid[0], pid[1]); - if (cfg == null) { - Dictionary<String, Object> cfgProps = convertToDict(props); - cfg = createConfiguration(configAdmin, pid[0], pid[1]); - String key = createConfigurationKey(pid[0], pid[1]); - cfgProps.put(CONFIG_KEY, key); - props.put(CONFIG_KEY, key); + String[] pid = parsePid(config.getName()); + Configuration cfg = findExistingConfiguration(configAdmin, pid[0], pid[1]); + if (cfg == null) { + Dictionary<String, Object> cfgProps = convertToDict(props); + cfg = createConfiguration(configAdmin, pid[0], pid[1]); + String key = createConfigurationKey(pid[0], pid[1]); + cfgProps.put(CONFIG_KEY, key); + props.put(CONFIG_KEY, key); if (storage != null && configCfgStore) { File cfgFile; if (pid[1] != null) { @@ -125,15 +127,15 @@ public class FeatureConfigInstaller { } cfgProps.put(FILEINSTALL_FILE_NAME, cfgFile.getAbsoluteFile().toURI().toString()); } - cfg.update(cfgProps); + cfg.update(cfgProps); try { updateStorage(pid[0], pid[1], props, false); } catch (Exception e) { LOGGER.warn("Can't update cfg file", e); } - } else if (config.isAppend()) { + } else if (config.isAppend()) { boolean update = false; - Dictionary<String,Object> properties = cfg.getProperties(); + Dictionary<String, Object> properties = cfg.getProperties(); for (String key : props.keySet()) { if (properties.get(key) == null) { properties.put(key, props.get(key)); @@ -148,20 +150,21 @@ public class FeatureConfigInstaller { LOGGER.warn("Can't update cfg file", e); } } - } - } + } + } for (ConfigFileInfo configFile : feature.getConfigurationFiles()) { - installConfigurationFile(configFile.getLocation(), configFile.getFinalname(), configFile.isOverride()); + installConfigurationFile(configFile.getLocation(), configFile.getFinalname(), + configFile.isOverride()); } } - private Dictionary<String, Object> convertToDict(Map<String, Object> props) { - Dictionary<String, Object> cfgProps = new Hashtable<>(); + private Dictionary<String, Object> convertToDict(Map<String, Object> props) { + Dictionary<String, Object> cfgProps = new Hashtable<>(); for (Map.Entry<String, Object> e : props.entrySet()) { cfgProps.put(e.getKey(), e.getValue()); } - return cfgProps; - } + return cfgProps; + } private String createConfigurationKey(String pid, String factoryPid) { return factoryPid == null ? pid : pid + "-" + factoryPid; @@ -194,8 +197,8 @@ public class FeatureConfigInstaller { // Substitute all variables, but keep unknown ones. final String dummyKey = ""; try { - finalname = InterpolationHelper.substVars(finalname, dummyKey, null, null, null, - true, true, false); + finalname = InterpolationHelper.substVars(finalname, dummyKey, null, null, null, true, true, + false); } catch (final IllegalArgumentException ex) { LOGGER.info("Substitution failed. Skip substitution of variables of configuration final name ({}).", finalname); @@ -219,7 +222,8 @@ public class FeatureConfigInstaller { return finalname; } - private void installConfigurationFile(String fileLocation, String finalname, boolean override) throws IOException { + private void installConfigurationFile(String fileLocation, String finalname, boolean override) + throws IOException { finalname = substFinalName(finalname); File file = new File(finalname); @@ -256,7 +260,8 @@ public class FeatureConfigInstaller { } } - protected void updateStorage(String pid, String factoryPid, TypedProperties props, boolean append) throws Exception { + protected void updateStorage(String pid, String factoryPid, TypedProperties props, boolean append) + throws Exception { if (storage != null && configCfgStore) { // get the cfg file File cfgFile; @@ -271,13 +276,13 @@ public class FeatureConfigInstaller { Object val = cfg.getProperties().get(FILEINSTALL_FILE_NAME); try { if (val instanceof URL) { - cfgFile = new File(((URL) val).toURI()); + cfgFile = new File(((URL)val).toURI()); } if (val instanceof URI) { - cfgFile = new File((URI) val); + cfgFile = new File((URI)val); } if (val instanceof String) { - cfgFile = new File(new URL((String) val).toURI()); + cfgFile = new File(new URL((String)val).toURI()); } } catch (Exception e) { throw new IOException(e.getMessage(), e); @@ -289,11 +294,11 @@ public class FeatureConfigInstaller { props.save(cfgFile); } else { TypedProperties properties = new TypedProperties(); - properties.load( cfgFile ); + properties.load(cfgFile); for (String key : props.keySet()) { if (!Constants.SERVICE_PID.equals(key) - && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key) - && !FILEINSTALL_FILE_NAME.equals(key)) { + && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key) + && !FILEINSTALL_FILE_NAME.equals(key)) { List<String> comments = props.getComments(key); List<String> value = props.getRaw(key); if (!properties.containsKey(key)) { @@ -310,10 +315,9 @@ public class FeatureConfigInstaller { // remove "removed" properties from the cfg file ArrayList<String> propertiesToRemove = new ArrayList<>(); for (String key : properties.keySet()) { - if (!props.containsKey(key) - && !Constants.SERVICE_PID.equals(key) - && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key) - && !FILEINSTALL_FILE_NAME.equals(key)) { + if (!props.containsKey(key) && !Constants.SERVICE_PID.equals(key) + && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key) + && !FILEINSTALL_FILE_NAME.equals(key)) { propertiesToRemove.add(key); } } @@ -323,7 +327,7 @@ public class FeatureConfigInstaller { } // save the cfg file storage.mkdirs(); - properties.save( cfgFile ); + properties.save(cfgFile); } } } http://git-wip-us.apache.org/repos/asf/karaf/blob/935006e6/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 49daded..d6d5d20 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 @@ -28,58 +28,62 @@ import org.osgi.service.cm.ConfigurationAdmin; public class AppendTest extends TestCase { - public void testLoad() throws Exception { + public void testLoad() throws Exception { - System.setProperty("karaf.data", "data"); - System.setProperty("karaf.etc", "etc"); + System.setProperty("karaf.data", "data"); + System.setProperty("karaf.etc", "etc"); - RepositoryImpl r = new RepositoryImpl(getClass().getResource("internal/service/f08.xml").toURI()); - // Check repo - Feature[] features = r.getFeatures(); - assertNotNull(features); - assertEquals(1, features.length); - Feature feature = features[0]; + RepositoryImpl r = new RepositoryImpl(getClass().getResource("internal/service/f08.xml").toURI()); + // Check repo + Feature[] features = r.getFeatures(); + assertNotNull(features); + assertEquals(1, features.length); + Feature feature = features[0]; - ConfigInfo configInfo = feature.getConfigurations().get(0); - assertNotNull(configInfo); - assertTrue(configInfo.isAppend()); + ConfigInfo configInfo = feature.getConfigurations().get(0); + assertNotNull(configInfo); + assertTrue(configInfo.isAppend()); - Properties properties = configInfo.getProperties(); - assertNotNull(properties); - String property = properties.getProperty("javax.servlet.context.tempdir"); - assertNotNull(property); - assertFalse(property.contains("${")); + Properties properties = configInfo.getProperties(); + assertNotNull(properties); + String property = properties.getProperty("javax.servlet.context.tempdir"); + assertNotNull(property); + assertFalse(property.contains("${")); assertEquals(property, "data/pax-web-jsp"); - 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<>(); + 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("javax.servlet.context.tempdir", "data/pax-web-jsp"); - EasyMock.expect(config.getProperties()).andReturn(original); + EasyMock.expect(config.getProperties()).andReturn(original); - Hashtable<String, Object> expected = new Hashtable<>(); + Hashtable<String, Object> expected = new Hashtable<>(); expected.put("org.ops4j.pax.web", "data/pax-web-jsp"); - expected.put("org.apache.karaf.features.configKey", "org.ops4j.pax.web"); - expected.put("foo", "bar"); - EasyMock.expectLastCall(); - EasyMock.replay(admin, config); + expected.put("org.apache.karaf.features.configKey", "org.ops4j.pax.web"); + expected.put("foo", "bar"); + EasyMock.expectLastCall(); + EasyMock.replay(admin, config); - FeatureConfigInstaller installer = new FeatureConfigInstaller(admin); - installer.installFeatureConfigs(feature); - EasyMock.verify(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); - } + 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); + } } http://git-wip-us.apache.org/repos/asf/karaf/blob/935006e6/features/core/src/test/java/org/apache/karaf/features/FeatureTest.java ---------------------------------------------------------------------- diff --git a/features/core/src/test/java/org/apache/karaf/features/FeatureTest.java b/features/core/src/test/java/org/apache/karaf/features/FeatureTest.java index 33debdf..0cd66bb 100644 --- a/features/core/src/test/java/org/apache/karaf/features/FeatureTest.java +++ b/features/core/src/test/java/org/apache/karaf/features/FeatureTest.java @@ -19,14 +19,14 @@ package org.apache.karaf.features; import junit.framework.TestCase; public class FeatureTest extends TestCase { - - public void testValueOf() { - Feature feature = org.apache.karaf.features.internal.model.Feature.valueOf("name/1.0.0"); - assertEquals(feature.getName(), "name"); - assertEquals(feature.getVersion(), "1.0.0"); - feature = org.apache.karaf.features.internal.model.Feature.valueOf("name"); - assertEquals(feature.getName(), "name"); - assertEquals(feature.getVersion(), org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION); - } - + + public void testValueOf() { + Feature feature = org.apache.karaf.features.internal.model.Feature.valueOf("name/1.0.0"); + assertEquals(feature.getName(), "name"); + assertEquals(feature.getVersion(), "1.0.0"); + feature = org.apache.karaf.features.internal.model.Feature.valueOf("name"); + assertEquals(feature.getName(), "name"); + assertEquals(feature.getVersion(), org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION); + } + } http://git-wip-us.apache.org/repos/asf/karaf/blob/935006e6/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java ---------------------------------------------------------------------- diff --git a/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java b/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java index de543cd..c630c6f 100644 --- a/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java +++ b/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java @@ -43,7 +43,7 @@ public class RepositoryTest extends TestCase { assertNotNull(features[0].getConfigurations()); assertEquals(1, features[0].getConfigurations().size()); assertNotNull(features[0].getConfigurations().get(0).getName()); - assertEquals("c1", features[0].getConfigurations().get(0).getName()); + assertEquals("c1", features[0].getConfigurations().get(0).getName()); assertEquals(1, features[0].getConfigurations().get(0).getProperties().size()); assertEquals("v", features[0].getConfigurations().get(0).getProperties().get("k")); assertNotNull(features[0].getDependencies()); @@ -85,12 +85,10 @@ public class RepositoryTest extends TestCase { assertEquals("f1", features[0].getName()); assertNotNull(features[0].getConfigurations()); assertEquals(1, features[0].getConfigurations().size()); - assertNotNull(features[0].getConfigurations().get(0).getName()); - assertEquals("c1", features[0].getConfigurations().get(0).getName()); - assertEquals(1, features[0].getConfigurations().get(0).getProperties() - .size()); - assertEquals("v", features[0].getConfigurations().get(0) - .getProperties().get("k")); + assertNotNull(features[0].getConfigurations().get(0).getName()); + assertEquals("c1", features[0].getConfigurations().get(0).getName()); + assertEquals(1, features[0].getConfigurations().get(0).getProperties().size()); + assertEquals("v", features[0].getConfigurations().get(0).getProperties().get("k")); assertNotNull(features[0].getDependencies()); assertEquals(0, features[0].getDependencies().size()); assertNotNull(features[0].getBundles());
