Index: management/mbeans/config/pom.xml =================================================================== --- management/mbeans/config/pom.xml (revision 1296251) +++ management/mbeans/config/pom.xml (working copy) @@ -50,6 +50,15 @@ org.apache.felix org.apache.felix.utils + + + + org.apache.karaf.shell + org.apache.karaf.shell.config + Index: management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/ConfigMBean.java =================================================================== --- management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/ConfigMBean.java (revision 1296251) +++ management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/ConfigMBean.java (working copy) @@ -11,9 +11,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.karaf.management.mbeans.config; +import java.io.IOException; import java.util.List; import java.util.Map; @@ -28,7 +28,7 @@ * @return the list of all configuration PIDs. * @throws Exception */ - List list() throws Exception; + List getConfigs() throws Exception; /** * Create a new configuration for the given PID. @@ -36,7 +36,10 @@ * @param pid the configuration PID. * @throws Exception */ + @Deprecated void create(String pid) throws Exception; + + void update(String pid, Map properties) throws IOException; /** * Delete a configuration identified by the given PID. @@ -53,7 +56,7 @@ * @return the list of properties. * @throws Exception */ - Map proplist(String pid) throws Exception; + Map listProperties(String pid) throws Exception; /** * Remove the configuration property identified by the given key. @@ -62,7 +65,7 @@ * @param key the property key. * @throws Exception */ - void propdel(String pid, String key) throws Exception; + void deleteProperty(String pid, String key) throws Exception; /** * Append (or add) a value for the given configuration key. @@ -72,7 +75,7 @@ * @param value the value to append to the current property value. * @throws Exception */ - void propappend(String pid, String key, String value) throws Exception; + void appendProperty(String pid, String key, String value) throws Exception; /** * Set a configuration property. @@ -82,6 +85,6 @@ * @param value the property value. * @throws Exception */ - void propset(String pid, String key, String value) throws Exception; + void setProperty(String pid, String key, String value) throws Exception; } Index: management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java =================================================================== --- management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java (revision 1296251) +++ management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java (working copy) @@ -13,49 +13,57 @@ */ package org.apache.karaf.management.mbeans.config.internal; -import org.apache.felix.utils.properties.Properties; -import org.apache.karaf.management.mbeans.config.ConfigMBean; -import org.osgi.framework.Constants; -import org.osgi.service.cm.Configuration; -import org.osgi.service.cm.ConfigurationAdmin; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Dictionary; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; import javax.management.NotCompliantMBeanException; import javax.management.StandardMBean; -import java.io.File; -import java.util.*; +import org.apache.karaf.management.mbeans.config.ConfigMBean; +import org.apache.karaf.shell.config.ConfigRepository; +import org.osgi.service.cm.Configuration; + /** * Implementation of the ConfigMBean. */ public class ConfigMBeanImpl extends StandardMBean implements ConfigMBean { - private final String FELIX_FILEINSTALL_FILENAME = "felix.fileinstall.filename"; + private ConfigRepository configRepo; - private ConfigurationAdmin configurationAdmin; - private File storage; - - public ConfigurationAdmin getConfigurationAdmin() { - return this.configurationAdmin; + public ConfigMBeanImpl() throws NotCompliantMBeanException { + super(ConfigMBean.class); } - public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) { - this.configurationAdmin = configurationAdmin; + private Configuration getConfiguration(String pid) throws IOException { + Configuration configuration = configRepo.getConfigAdmin().getConfiguration(pid); + if (configuration == null) { + throw new IllegalArgumentException("Configuration PID " + pid + " doesn't exist"); + } + return configuration; } + + @SuppressWarnings("rawtypes") + private Dictionary getConfigProperties(String pid) throws IOException { + Configuration configuration = getConfiguration(pid); - public File getStorage() { - return this.storage; + Dictionary dictionary = configuration.getProperties(); + if (dictionary == null) { + dictionary = new java.util.Properties(); + } + return dictionary; } - public void setStorage(File storage) { - this.storage = storage; - } - - public ConfigMBeanImpl() throws NotCompliantMBeanException { - super(ConfigMBean.class); - } - - public List list() throws Exception { - Configuration[] configurations = configurationAdmin.listConfigurations(null); + /** + * Get all config pids + */ + public List getConfigs() throws Exception { + Configuration[] configurations = this.configRepo.getConfigAdmin().listConfigurations(null); List pids = new ArrayList(); for (int i = 0; i < configurations.length; i++) { pids.add(configurations[i].getPid()); @@ -63,32 +71,30 @@ return pids; } + @SuppressWarnings("rawtypes") public void create(String pid) throws Exception { - store(pid, new Hashtable(), false); + configRepo.update(pid, new Hashtable()); } + - public void delete(String pid) throws Exception { - Configuration configuration = configurationAdmin.getConfiguration(pid); - if (configuration == null) { - throw new IllegalArgumentException("Configuration PID " + pid + " doesn't exist"); + public void update(String pid, Map properties) throws IOException { + if (properties == null) { + properties = new HashMap(); } - configuration.delete(); - if (storage != null) { - File cfgFile = new File(storage, pid + ".cfg"); - cfgFile.delete(); + Dictionary dictionary = new Hashtable(); + for (String key : properties.keySet()) { + dictionary.put(key, properties.get(key)); } + configRepo.update(pid, dictionary); } - public Map proplist(String pid) throws Exception { - Configuration configuration = configurationAdmin.getConfiguration(pid); - if (configuration == null) { - throw new IllegalArgumentException("Configuration PID " + pid + " doesn't exist"); - } - Dictionary dictionary = configuration.getProperties(); + public void delete(String pid) throws Exception { + this.configRepo.delete(pid); + } - if (dictionary == null) { - dictionary = new java.util.Properties(); - } + @SuppressWarnings("rawtypes") + public Map listProperties(String pid) throws Exception { + Dictionary dictionary = getConfigProperties(pid); Map propertiesMap = new HashMap(); for (Enumeration e = dictionary.keys(); e.hasMoreElements(); ) { @@ -99,32 +105,16 @@ return propertiesMap; } - public void propdel(String pid, String key) throws Exception { - Configuration configuration = configurationAdmin.getConfiguration(pid); - if (configuration == null) { - throw new IllegalArgumentException("Configuration PID " + pid + " doesn't exist"); - } - Dictionary dictionary = configuration.getProperties(); - - if (dictionary == null) { - dictionary = new java.util.Properties(); - } - + @SuppressWarnings("rawtypes") + public void deleteProperty(String pid, String key) throws Exception { + Dictionary dictionary = getConfigProperties(pid); dictionary.remove(key); - store(pid, dictionary, false); + configRepo.update(pid, dictionary, false); } - public void propappend(String pid, String key, String value) throws Exception { - Configuration configuration = configurationAdmin.getConfiguration(pid); - if (configuration == null) { - throw new IllegalArgumentException("Configuration PID " + pid + " doesn't exist"); - } - Dictionary dictionary = configuration.getProperties(); - - if (dictionary == null) { - dictionary = new java.util.Properties(); - } - + @SuppressWarnings({"rawtypes", "unchecked"}) + public void appendProperty(String pid, String key, String value) throws Exception { + Dictionary dictionary = getConfigProperties(pid); Object currentValue = dictionary.get(key); if (currentValue == null) { dictionary.put(key, value); @@ -133,94 +123,18 @@ } else { throw new IllegalStateException("Current value is not a String"); } - store(pid, dictionary, false); + configRepo.update(pid, dictionary, false); } - public void propset(String pid, String key, String value) throws Exception { - Configuration configuration = configurationAdmin.getConfiguration(pid); - if (configuration == null) { - throw new IllegalArgumentException("Configuration PID " + pid + " doesn't exist"); - } - Dictionary dictionary = configuration.getProperties(); - - if (dictionary == null) { - dictionary = new java.util.Properties(); - } - + @SuppressWarnings({"rawtypes", "unchecked"}) + public void setProperty(String pid, String key, String value) throws Exception { + Dictionary dictionary = getConfigProperties(pid); dictionary.put(key, value); - store(pid, dictionary, false); + configRepo.update(pid, dictionary, false); } - /** - * Store/flush a configuration PID into the configuration file. - * - * @param pid the configuration PID. - * @param properties the configuration properties. - * @throws Exception - */ - private void store(String pid, Dictionary properties, boolean bypassStorage) throws Exception { - if (!bypassStorage && storage != null) { - File storageFile = new File(storage, pid + ".cfg"); - Configuration configuration = configurationAdmin.getConfiguration(pid, null); - if (configuration != null && configuration.getProperties() != null) { - Object val = configuration.getProperties().get(FELIX_FILEINSTALL_FILENAME); - if (val instanceof String) { - if (((String) val).startsWith("file:")) { - val = ((String) val).substring("file:".length()); - } - storageFile = new File((String) val); - } - } - Properties p = new Properties(storageFile); - p.clear(); - for (Enumeration keys = properties.keys(); keys.hasMoreElements(); ) { - Object key = keys.nextElement(); - if (!Constants.SERVICE_PID.equals(key) - && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key) - && !FELIX_FILEINSTALL_FILENAME.equals(key)) { - p.put((String) key, (String) properties.get(key)); - } - } - // remove "removed" properties from the file - ArrayList propertiesToRemove = new ArrayList(); - for (Object key : p.keySet()) { - if (properties.get(key) == null - && !Constants.SERVICE_PID.equals(key) - && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key) - && !FELIX_FILEINSTALL_FILENAME.equals(key)) { - propertiesToRemove.add(key.toString()); - } - } - for (String key : propertiesToRemove) { - p.remove(key); - } - // save the cfg file - storage.mkdirs(); - p.save(); - } else { - Configuration cfg = configurationAdmin.getConfiguration(pid, null); - if (cfg.getProperties() == null) { - String[] pids = parsePid(pid); - if (pids[1] != null) { - cfg = configurationAdmin.createFactoryConfiguration(pids[0], null); - } - } - if (cfg.getBundleLocation() != null) { - cfg.setBundleLocation(null); - } - cfg.update(properties); - } + public void setConfigRepo(ConfigRepository configRepo) { + this.configRepo = configRepo; } - private String[] parsePid(String pid) { - int n = pid.indexOf('-'); - if (n > 0) { - String factoryPid = pid.substring(n + 1); - pid = pid.substring(0, n); - return new String[] { pid, factoryPid }; - } else { - return new String[] { pid, null }; - } - } - } Index: management/mbeans/config/src/main/resources/OSGI-INF/blueprint/config-management.xml =================================================================== --- management/mbeans/config/src/main/resources/OSGI-INF/blueprint/config-management.xml (revision 1296251) +++ management/mbeans/config/src/main/resources/OSGI-INF/blueprint/config-management.xml (working copy) @@ -21,13 +21,11 @@ - - + - - + Index: shell/config/pom.xml =================================================================== --- shell/config/pom.xml (revision 1296251) +++ shell/config/pom.xml (working copy) @@ -47,6 +47,12 @@ org.apache.karaf.util + org.apache.felix + org.apache.felix.fileinstall + 3.1.10 + + + org.osgi org.osgi.core provided Index: shell/config/src/main/java/org/apache/karaf/shell/config/CancelCommand.java =================================================================== --- shell/config/src/main/java/org/apache/karaf/shell/config/CancelCommand.java (revision 1296251) +++ shell/config/src/main/java/org/apache/karaf/shell/config/CancelCommand.java (working copy) @@ -16,15 +16,15 @@ */ package org.apache.karaf.shell.config; -import org.osgi.service.cm.ConfigurationAdmin; import org.apache.felix.gogo.commands.Command; @Command(scope = "config", name = "cancel", description = "Cancels the changes to the configuration being edited.") public class CancelCommand extends ConfigCommandSupport { - protected void doExecute(ConfigurationAdmin admin) throws Exception { + protected Object doExecute() throws Exception { session.put(PROPERTY_CONFIG_PID, null); session.put(PROPERTY_CONFIG_PROPS, null); + return null; } } Index: shell/config/src/main/java/org/apache/karaf/shell/config/completers/ConfigurationCompleter.java =================================================================== --- shell/config/src/main/java/org/apache/karaf/shell/config/completers/ConfigurationCompleter.java (revision 1296251) +++ shell/config/src/main/java/org/apache/karaf/shell/config/completers/ConfigurationCompleter.java (working copy) @@ -33,7 +33,7 @@ /** * {@link jline.Completor} for Configuration Admin configurations. * - * Displays a list of existing config admin configurations for completion. + * Displays a list of existing config instance configurations for completion. * */ public class ConfigurationCompleter implements Completer, ConfigurationListener { @@ -65,6 +65,7 @@ delegate.getStrings().addAll(pids); } + @SuppressWarnings("rawtypes") public int complete(final String buffer, final int cursor, final List candidates) { return delegate.complete(buffer, cursor, candidates); } Index: shell/config/src/main/java/org/apache/karaf/shell/config/completers/ConfigurationPropertyCompleter.java =================================================================== --- shell/config/src/main/java/org/apache/karaf/shell/config/completers/ConfigurationPropertyCompleter.java (revision 1296251) +++ shell/config/src/main/java/org/apache/karaf/shell/config/completers/ConfigurationPropertyCompleter.java (working copy) @@ -50,6 +50,7 @@ private ConfigurationAdmin configAdmin; + @SuppressWarnings("rawtypes") public int complete(final String buffer, final int cursor, final List candidates) { CommandSession session = CommandSessionHolder.getSession(); if (session != null) { @@ -96,6 +97,7 @@ * @param pid * @return */ + @SuppressWarnings("rawtypes") private Set getPropertyNames(String pid) { Set propertyNames = new HashSet(); if (pid != null) { Index: shell/config/src/main/java/org/apache/karaf/shell/config/ConfigCommandSupport.java =================================================================== --- shell/config/src/main/java/org/apache/karaf/shell/config/ConfigCommandSupport.java (revision 1296251) +++ shell/config/src/main/java/org/apache/karaf/shell/config/ConfigCommandSupport.java (working copy) @@ -16,18 +16,9 @@ */ package org.apache.karaf.shell.config; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; import java.util.Dictionary; -import java.util.Enumeration; + import org.apache.karaf.shell.console.OsgiCommandSupport; -import org.apache.karaf.util.Properties; -import org.osgi.framework.Constants; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; -import org.osgi.service.cm.Configuration; -import org.osgi.service.cm.ConfigurationAdmin; /** * Abstract class from which all commands related to the ConfigurationAdmin @@ -36,193 +27,17 @@ * calling another method to actually process the command. */ public abstract class ConfigCommandSupport extends OsgiCommandSupport { - public static final String PROPERTY_CONFIG_PID = "ConfigCommand.PID"; public static final String PROPERTY_CONFIG_PROPS = "ConfigCommand.Props"; - private static final String PID_FILTER = "(service.pid=%s*)"; - private static final String FILE_PREFIX = "file:"; - private static final String CONFIG_SUFFIX = ".cfg"; - private static final String FACTORY_SEPARATOR = "-"; - private static final String FILEINSTALL_FILE_NAME = "felix.fileinstall.filename"; + protected ConfigRepository configRepository; - protected File storage; - - protected Object doExecute() throws Exception { - // Get config admin service. - ServiceReference ref = getBundleContext().getServiceReference(ConfigurationAdmin.class.getName()); - if (ref == null) { - System.out.println("ConfigurationAdmin service is unavailable."); - return null; - } - ConfigurationAdmin admin = getConfigurationAdmin(); - if (admin == null) { - System.out.println("ConfigAdmin service is unavailable."); - return null; - } - - doExecute(admin); - return null; - } - + @SuppressWarnings("rawtypes") protected Dictionary getEditedProps() throws Exception { return (Dictionary) this.session.get(PROPERTY_CONFIG_PROPS); } - - protected ConfigurationAdmin getConfigurationAdmin() { - ServiceReference ref = getBundleContext().getServiceReference(ConfigurationAdmin.class.getName()); - if (ref == null) { - return null; - } - try { - ConfigurationAdmin admin = (ConfigurationAdmin) getBundleContext().getService(ref); - if (admin == null) { - return null; - } else { - return admin; - } - } finally { - getBundleContext().ungetService(ref); - } + + public void setConfigRepository(ConfigRepository configRepository) { + this.configRepository = configRepository; } - protected abstract void doExecute(ConfigurationAdmin admin) throws Exception; - - /** - *

- * Returns the Configuration object of the given (felix fileinstall) file name. - *

- * - * @param fileName - * @return - */ - public Configuration findConfigurationByFileName(ConfigurationAdmin admin, String fileName) throws IOException, InvalidSyntaxException { - if (fileName != null && fileName.contains(FACTORY_SEPARATOR)) { - String factoryPid = fileName.substring(0, fileName.lastIndexOf(FACTORY_SEPARATOR)); - String absoluteFileName = FILE_PREFIX + storage.getAbsolutePath() + File.separator + fileName + CONFIG_SUFFIX; - Configuration[] configurations = admin.listConfigurations(String.format(PID_FILTER, factoryPid)); - if (configurations != null) { - for (Configuration configuration : configurations) { - Dictionary dictionary = configuration.getProperties(); - if (dictionary != null) { - String fileInstallFileName = (String) dictionary.get(FILEINSTALL_FILE_NAME); - if (absoluteFileName.equals(fileInstallFileName)) { - return configuration; - } - } - } - } - } - return null; - } - - /** - * Saves config to storage or ConfigurationAdmin. - * - * @param admin - * @param pid - * @param props - * @param bypassStorage - * @throws IOException - */ - protected void update(ConfigurationAdmin admin, String pid, Dictionary props, boolean bypassStorage) throws IOException { - if (!bypassStorage && storage != null) { - persistConfiguration(admin, pid, props); - } else { - updateConfiguration(admin, pid, props); - } - } - - /** - * Persists configuration to storage. - * - * @param admin - * @param pid - * @param props - * @throws IOException - */ - protected void persistConfiguration(ConfigurationAdmin admin, String pid, Dictionary props) throws IOException { - File storageFile = new File(storage, pid + ".cfg"); - Configuration cfg = admin.getConfiguration(pid, null); - if (cfg != null && cfg.getProperties() != null) { - Object val = cfg.getProperties().get(FILEINSTALL_FILE_NAME); - if (val instanceof String) { - if (((String) val).startsWith("file:")) { - val = ((String) val).substring("file:".length()); - } - storageFile = new File((String) val); - } - } - Properties p = new Properties(storageFile); - for (Enumeration keys = props.keys(); keys.hasMoreElements(); ) { - Object key = keys.nextElement(); - if (!Constants.SERVICE_PID.equals(key) - && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key) - && !FILEINSTALL_FILE_NAME.equals(key)) { - p.put((String) key, (String) props.get(key)); - } - } - // remove "removed" properties from the file - ArrayList propertiesToRemove = new ArrayList(); - for (Object key : p.keySet()) { - if (props.get(key) == null - && !Constants.SERVICE_PID.equals(key) - && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key) - && !FILEINSTALL_FILE_NAME.equals(key)) { - propertiesToRemove.add(key.toString()); - } - } - for (String key : propertiesToRemove) { - p.remove(key); - } - // save the cfg file - storage.mkdirs(); - p.save(); - - } - - /** - * Updates the configuration to the {@link ConfigurationAdmin} service. - * - * @param admin - * @param pid - * @param props - * @throws IOException - */ - public void updateConfiguration(ConfigurationAdmin admin, String pid, Dictionary props) throws IOException { - Configuration cfg = admin.getConfiguration(pid, null); - if (cfg.getProperties() == null) { - String[] pids = parsePid(pid); - if (pids[1] != null) { - cfg = admin.createFactoryConfiguration(pids[0], null); - } - } - if (cfg.getBundleLocation() != null) { - cfg.setBundleLocation(null); - } - cfg.update(props); - } - - protected String[] parsePid(String pid) { - int n = pid.indexOf('-'); - if (n > 0) { - String factoryPid = pid.substring(n + 1); - pid = pid.substring(0, n); - return new String[]{pid, factoryPid}; - } else { - return new String[]{pid, null}; - } - } - - protected void deleteStorage(String pid) throws Exception { - File cfgFile = new File(storage, pid + ".cfg"); - cfgFile.delete(); - } - - public File getStorage() { - return storage; - } - - public void setStorage(File storage) { - this.storage = storage; - } } Index: shell/config/src/main/java/org/apache/karaf/shell/config/ConfigPropertyCommandSupport.java =================================================================== --- shell/config/src/main/java/org/apache/karaf/shell/config/ConfigPropertyCommandSupport.java (revision 1296251) +++ shell/config/src/main/java/org/apache/karaf/shell/config/ConfigPropertyCommandSupport.java (working copy) @@ -1,11 +1,9 @@ package org.apache.karaf.shell.config; import java.util.Dictionary; +import java.util.Properties; import org.apache.felix.gogo.commands.Option; -import java.util.Properties; -import org.osgi.service.cm.Configuration; -import org.osgi.service.cm.ConfigurationAdmin; /** * Abstract class which commands that are related to property processing should extend. @@ -19,7 +17,8 @@ protected boolean bypassStorage; - protected void doExecute(ConfigurationAdmin admin) throws Exception { + @SuppressWarnings("rawtypes") + protected Object doExecute() throws Exception { Dictionary props = getEditedProps(); if (props == null && pid == null) { System.err.println("No configuration is being edited--run the edit command first"); @@ -29,15 +28,17 @@ } propertyAction(props); if(requiresUpdate(pid)) { - update(admin, pid, props, bypassStorage); + this.configRepository.update(pid, props, bypassStorage); } } + return null; } /** * Perform an action on the properties. * @param props */ + @SuppressWarnings("rawtypes") protected abstract void propertyAction(Dictionary props); /** @@ -60,17 +61,10 @@ * @return * @throws Exception */ + @SuppressWarnings("rawtypes") @Override protected Dictionary getEditedProps() throws Exception { - if(pid != null) { - ConfigurationAdmin configurationAdmin = getConfigurationAdmin(); - if(configurationAdmin != null) { - Configuration configuration = configurationAdmin.getConfiguration(pid); - if(configuration != null) { - return configuration.getProperties(); - } - } - } - return super.getEditedProps(); + Dictionary props = this.configRepository.getConfigProperties(pid); + return (props != null) ? props : super.getEditedProps(); } } Index: shell/config/src/main/java/org/apache/karaf/shell/config/DeleteCommand.java =================================================================== --- shell/config/src/main/java/org/apache/karaf/shell/config/DeleteCommand.java (revision 1296251) +++ shell/config/src/main/java/org/apache/karaf/shell/config/DeleteCommand.java (working copy) @@ -20,7 +20,6 @@ import org.apache.felix.gogo.commands.Command; import org.apache.felix.gogo.commands.Option; import org.osgi.service.cm.Configuration; -import org.osgi.service.cm.ConfigurationAdmin; @Command(scope = "config", name = "delete", description = "Delete a configuration.") public class DeleteCommand extends ConfigCommandSupport { @@ -31,38 +30,39 @@ @Option(name = "--force", aliases = {}, description = "Force the edition of this config, even if another one was under edition", required = false, multiValued = false) boolean force; - @Option(name = "--no-delete-cfg-file", aliases = { }, description = "Do not delete the configuration file from the etc folder", required = false, multiValued = false) + @Option(name = "--no-delete-cfg-file", aliases = {}, description = "Do not delete the configuration file from the etc folder", required = false, multiValued = false) boolean noDeleteCfgFile = false; @Option(name = "-f", aliases = {"--use-file"}, description = "Configuration lookup using the filename instead of the pid", required = false, multiValued = false) boolean useFile; - protected void doExecute(ConfigurationAdmin admin) throws Exception { + protected Object doExecute() throws Exception { String oldPid = (String) this.session.get(PROPERTY_CONFIG_PID); if (oldPid != null && oldPid.equals(pid) && !force) { System.err.println("This config is being edited. Cancel / update first, or use the --force option"); - return; + return null; } // User selected to use file instead. if (useFile) { - Configuration configuration = this.findConfigurationByFileName(admin, pid); + Configuration configuration = this.configRepository.findConfigurationByFileName(pid); if(configuration == null) { System.err.println("Could not find configuration with file install property set to: " + pid); - return; + return null; } configuration.delete(); } else { - Configuration configuration = admin.getConfiguration(pid); + Configuration configuration = this.configRepository.getConfigAdmin().getConfiguration(pid); configuration.delete(); } if (!noDeleteCfgFile) { - deleteStorage(pid); + this.configRepository.deleteStorage(pid); } if (oldPid != null && oldPid.equals(pid) && !force) { this.session.put(PROPERTY_CONFIG_PID, null); this.session.put(PROPERTY_CONFIG_PROPS, null); } + return null; } } Index: shell/config/src/main/java/org/apache/karaf/shell/config/EditCommand.java =================================================================== --- shell/config/src/main/java/org/apache/karaf/shell/config/EditCommand.java (revision 1296251) +++ shell/config/src/main/java/org/apache/karaf/shell/config/EditCommand.java (working copy) @@ -23,7 +23,6 @@ import org.apache.felix.gogo.commands.Command; import org.apache.felix.gogo.commands.Option; import org.osgi.service.cm.Configuration; -import org.osgi.service.cm.ConfigurationAdmin; @Command(scope = "config", name = "edit", description = "Creates or edits a configuration.", detailedDescription="classpath:edit.txt") public class EditCommand extends ConfigCommandSupport { @@ -37,25 +36,26 @@ @Option(name = "-f", aliases = {"--use-file"}, description = "Configuration lookup using the filename instead of the pid", required = false, multiValued = false) boolean useFile; - protected void doExecute(ConfigurationAdmin admin) throws Exception { + @SuppressWarnings("rawtypes") + protected Object doExecute() throws Exception { String oldPid = (String) this.session.get(PROPERTY_CONFIG_PID); if (oldPid != null && !oldPid.equals(pid) && !force) { System.err.println("Another config is being edited. Cancel / update first, or use the --force option"); - return; + return null; } Dictionary props; //User selected to use file instead. if (useFile) { - Configuration configuration = this.findConfigurationByFileName(admin, pid); + Configuration configuration = this.configRepository.findConfigurationByFileName(pid); if(configuration == null) { System.err.println("Could not find configuration with file install property set to: " + pid); - return; + return null; } props = configuration.getProperties(); pid = configuration.getPid(); } else { - Configuration configuration = admin.getConfiguration(pid, null); + Configuration configuration = this.configRepository.getConfigAdmin().getConfiguration(pid, null); props = configuration.getProperties(); if (props == null) { props = new Properties(); @@ -63,6 +63,7 @@ } this.session.put(PROPERTY_CONFIG_PID, pid); this.session.put(PROPERTY_CONFIG_PROPS, props); + return null; } } Index: shell/config/src/main/java/org/apache/karaf/shell/config/ListCommand.java =================================================================== --- shell/config/src/main/java/org/apache/karaf/shell/config/ListCommand.java (revision 1296251) +++ shell/config/src/main/java/org/apache/karaf/shell/config/ListCommand.java (working copy) @@ -19,10 +19,9 @@ import java.util.Dictionary; import java.util.Enumeration; -import org.osgi.service.cm.Configuration; -import org.osgi.service.cm.ConfigurationAdmin; import org.apache.felix.gogo.commands.Argument; import org.apache.felix.gogo.commands.Command; +import org.osgi.service.cm.Configuration; @Command(scope = "config", name = "list", description = "Lists existing configurations.") public class ListCommand extends ConfigCommandSupport { @@ -30,8 +29,9 @@ @Argument(index = 0, name = "query", description = "Specify a LDAP query", required = false, multiValued = false) String query; - protected void doExecute(ConfigurationAdmin admin) throws Exception { - Configuration[] configs = admin.listConfigurations(query); + @SuppressWarnings("rawtypes") + protected Object doExecute() throws Exception { + Configuration[] configs = configRepository.getConfigAdmin().listConfigurations(query); if (configs != null) { for (Configuration config : configs) { System.out.println("----------------------------------------------------------------"); @@ -50,5 +50,6 @@ } } } + return null; } } Index: shell/config/src/main/java/org/apache/karaf/shell/config/PropAppendCommand.java =================================================================== --- shell/config/src/main/java/org/apache/karaf/shell/config/PropAppendCommand.java (revision 1296251) +++ shell/config/src/main/java/org/apache/karaf/shell/config/PropAppendCommand.java (working copy) @@ -17,13 +17,14 @@ package org.apache.karaf.shell.config; import java.util.Dictionary; + import org.apache.felix.gogo.commands.Argument; import org.apache.felix.gogo.commands.Command; /** * Appends a value to the current property value. */ -@Command(scope = "config", name = "propappend", description = "Appends the given value to an existing property or creates the property with the specified name and value.") +@Command(scope = "config", name = "append-property", description = "Appends the given value to an existing property or creates the property with the specified name and value.") public class PropAppendCommand extends ConfigPropertyCommandSupport { @Argument(index = 0, name = "name", description = "The name of the property", required = true, multiValued = false) @@ -32,6 +33,7 @@ @Argument(index = 1, name = "value", description = "The value to append to the property", required = true, multiValued = false) String value; + @SuppressWarnings({"unchecked", "rawtypes"}) @Override public void propertyAction(Dictionary props) { final Object currentValue = props.get(prop); Index: shell/config/src/main/java/org/apache/karaf/shell/config/PropDelCommand.java =================================================================== --- shell/config/src/main/java/org/apache/karaf/shell/config/PropDelCommand.java (revision 1296251) +++ shell/config/src/main/java/org/apache/karaf/shell/config/PropDelCommand.java (working copy) @@ -17,15 +17,17 @@ package org.apache.karaf.shell.config; import java.util.Dictionary; + import org.apache.felix.gogo.commands.Argument; import org.apache.felix.gogo.commands.Command; -@Command(scope = "config", name = "propdel", description = "Deletes a property from configuration being edited.") +@Command(scope = "config", name = "delete-property", description = "Deletes a property from the configuration being edited.") public class PropDelCommand extends ConfigPropertyCommandSupport { @Argument(index = 0, name = "property", description = "The name of the property to delete", required = true, multiValued = false) String prop; + @SuppressWarnings("rawtypes") @Override public void propertyAction(Dictionary props) { props.remove(prop); Index: shell/config/src/main/java/org/apache/karaf/shell/config/PropListCommand.java =================================================================== --- shell/config/src/main/java/org/apache/karaf/shell/config/PropListCommand.java (revision 1296251) +++ shell/config/src/main/java/org/apache/karaf/shell/config/PropListCommand.java (working copy) @@ -18,11 +18,14 @@ import java.util.Dictionary; import java.util.Enumeration; + import org.apache.felix.gogo.commands.Command; -@Command(scope = "config", name = "proplist", description = "Lists properties from the currently edited configuration.") + +@Command(scope = "config", name = "list-property", description = "Lists properties from the currently edited configuration.") public class PropListCommand extends ConfigPropertyCommandSupport { + @SuppressWarnings("rawtypes") @Override public void propertyAction(Dictionary props) { for (Enumeration e = props.keys(); e.hasMoreElements(); ) { Index: shell/config/src/main/java/org/apache/karaf/shell/config/PropSetCommand.java =================================================================== --- shell/config/src/main/java/org/apache/karaf/shell/config/PropSetCommand.java (revision 1296251) +++ shell/config/src/main/java/org/apache/karaf/shell/config/PropSetCommand.java (working copy) @@ -20,9 +20,8 @@ import org.apache.felix.gogo.commands.Argument; import org.apache.felix.gogo.commands.Command; -import org.osgi.service.cm.ConfigurationAdmin; -@Command(scope = "config", name = "propset", description = "Sets a property in the currently edited configuration.") +@Command(scope = "config", name = "set-property", description = "Sets a property in the currently edited configuration.") public class PropSetCommand extends ConfigPropertyCommandSupport { @Argument(index = 0, name = "property", description = "The name of the property to set", required = true, multiValued = false) @@ -31,6 +30,7 @@ @Argument(index = 1, name = "value", description = "The value of the property", required = true, multiValued = false) String value; + @SuppressWarnings({"unchecked", "rawtypes"}) @Override public void propertyAction(Dictionary props) { props.put(prop, value); Index: shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java =================================================================== --- shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java (revision 1296251) +++ shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java (working copy) @@ -17,26 +17,28 @@ package org.apache.karaf.shell.config; import java.util.Dictionary; + import org.apache.felix.gogo.commands.Command; import org.apache.felix.gogo.commands.Option; -import org.osgi.service.cm.ConfigurationAdmin; @Command(scope = "config", name = "update", description = "Saves and propagates changes from the configuration being edited.") public class UpdateCommand extends ConfigCommandSupport { - @Option(name = "-b", aliases = {"--bypass-storage"}, multiValued = false, required = false, description = "Do not store the configuration in a properties file, but feed it directly to ConfigAdmin") + @Option(name = "-b", aliases = { "--bypass-storage" }, multiValued = false, required = false, description = "Do not store the configuration in a properties file, but feed it directly to ConfigAdmin") protected boolean bypassStorage; - protected void doExecute(ConfigurationAdmin admin) throws Exception { + @SuppressWarnings("rawtypes") + protected Object doExecute() throws Exception { Dictionary props = getEditedProps(); if (props == null) { System.err.println("No configuration is being edited--run the edit command first"); - return; + return null; } String pid = (String) this.session.get(PROPERTY_CONFIG_PID); - update(admin, pid, props, bypassStorage); + this.configRepository.update(pid, props, bypassStorage); this.session.put(PROPERTY_CONFIG_PID, null); this.session.put(PROPERTY_CONFIG_PROPS, null); + return null; } } Index: shell/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml =================================================================== --- shell/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml (revision 1296251) +++ shell/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml (working copy) @@ -24,11 +24,13 @@ - + + + - + @@ -37,7 +39,7 @@ - + @@ -45,53 +47,60 @@ - + + + + + + - + - + - - - - + + + + + + - + - + - + - + - + @@ -105,7 +114,16 @@ + + + + + + + + + Index: shell/config/src/test/java/org/apache/karaf/shell/config/EditCommandTest.java =================================================================== --- shell/config/src/test/java/org/apache/karaf/shell/config/EditCommandTest.java (revision 1296251) +++ shell/config/src/test/java/org/apache/karaf/shell/config/EditCommandTest.java (working copy) @@ -16,21 +16,21 @@ */ package org.apache.karaf.shell.config; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; + import java.util.Dictionary; import java.util.Properties; import junit.framework.TestCase; + import org.apache.felix.service.command.CommandSession; import org.easymock.EasyMock; import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; import org.osgi.service.cm.Configuration; import org.osgi.service.cm.ConfigurationAdmin; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; - /** * Test cases for {@link EditCommand} */ @@ -42,21 +42,19 @@ private BundleContext context; private ConfigurationAdmin admin; private CommandSession session; - + @Override protected void setUp() throws Exception { command = new EditCommand(); + context = EasyMock.createMock(BundleContext.class); command.setBundleContext(context); - ServiceReference reference = createMock(ServiceReference.class); - expect(context.getServiceReference(ConfigurationAdmin.class.getName())).andReturn(reference).anyTimes(); - admin = createMock(ConfigurationAdmin.class); - expect(context.getService(reference)).andReturn(admin); - expect(context.ungetService(reference)).andReturn(Boolean.TRUE); - + command.setConfigRepository(new ConfigRepository(null, admin, null)); + expect(context.getBundle(0)).andReturn(null).anyTimes(); + replay(context); session = new MockCommandSession(); @@ -82,7 +80,7 @@ props, session.get(ConfigCommandSupport.PROPERTY_CONFIG_PROPS)); } - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") public void testExecuteOnNewPid() throws Exception { Configuration config = createMock(Configuration.class); expect(admin.getConfiguration(PID, null)).andReturn(config); Index: shell/config/src/test/java/org/apache/karaf/shell/config/UpdateCommandTest.java =================================================================== --- shell/config/src/test/java/org/apache/karaf/shell/config/UpdateCommandTest.java (revision 1296251) +++ shell/config/src/test/java/org/apache/karaf/shell/config/UpdateCommandTest.java (working copy) @@ -17,20 +17,20 @@ package org.apache.karaf.shell.config; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; + import java.util.Properties; import junit.framework.TestCase; + import org.apache.felix.service.command.CommandSession; import org.easymock.EasyMock; import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; import org.osgi.service.cm.Configuration; import org.osgi.service.cm.ConfigurationAdmin; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; - /** * Test cases for {@link EditCommand} */ @@ -50,12 +50,9 @@ context = EasyMock.createMock(BundleContext.class); command.setBundleContext(context); - ServiceReference reference = createMock(ServiceReference.class); - expect(context.getServiceReference(ConfigurationAdmin.class.getName())).andReturn(reference).anyTimes(); - admin = createMock(ConfigurationAdmin.class); - expect(context.getService(reference)).andReturn(admin); - expect(context.ungetService(reference)).andReturn(Boolean.TRUE); + command.setConfigRepository(new ConfigRepository(null, admin, null)); + expect(context.getBundle(0)).andReturn(null).anyTimes(); replay(context);