Author: gnodet
Date: Mon Oct 19 17:49:36 2009
New Revision: 826734
URL: http://svn.apache.org/viewvc?rev=826734&view=rev
Log:
FELIX-1718: karaf shell config:update command should persist / override
configurations from the etc/ folder
Modified:
felix/trunk/karaf/shell/config/src/main/java/org/apache/felix/karaf/shell/config/UpdateCommand.java
felix/trunk/karaf/shell/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml
Modified:
felix/trunk/karaf/shell/config/src/main/java/org/apache/felix/karaf/shell/config/UpdateCommand.java
URL:
http://svn.apache.org/viewvc/felix/trunk/karaf/shell/config/src/main/java/org/apache/felix/karaf/shell/config/UpdateCommand.java?rev=826734&r1=826733&r2=826734&view=diff
==============================================================================
---
felix/trunk/karaf/shell/config/src/main/java/org/apache/felix/karaf/shell/config/UpdateCommand.java
(original)
+++
felix/trunk/karaf/shell/config/src/main/java/org/apache/felix/karaf/shell/config/UpdateCommand.java
Mon Oct 19 17:49:36 2009
@@ -16,8 +16,13 @@
*/
package org.apache.felix.karaf.shell.config;
+import java.io.File;
+import java.io.FileOutputStream;
import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Properties;
+import org.apache.felix.gogo.commands.Option;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.apache.felix.gogo.commands.Command;
@@ -25,10 +30,41 @@
@Command(scope = "config", name = "update", description = "Save and propagate
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")
+ private boolean bypassStorage;
+
+ private File storage;
+
+ public File getStorage() {
+ return storage;
+ }
+
+ public void setStorage(File storage) {
+ this.storage = storage;
+ }
+
protected void doExecute(ConfigurationAdmin admin) throws Exception {
Dictionary props = getEditedProps();
if (props == null) {
System.err.println("No configuration is being edited. Run the edit
command first");
+ } else if (!bypassStorage && storage != null) {
+ Properties p = new Properties();
+ for (Enumeration keys = props.keys(); keys.hasMoreElements();) {
+ Object key = keys.nextElement();
+ if (!"service.pid".equals(key) &&
!"felix.fileinstall.filename".equals(key)) {
+ p.put(key, props.get(key));
+ }
+ }
+ storage.mkdirs();
+ String pid = (String) this.session.get(PROPERTY_CONFIG_PID);
+ FileOutputStream os = new FileOutputStream(new File(storage, pid +
".cfg"));
+ try {
+ p.store(os, null);
+ } finally {
+ os.close();
+ }
+ this.session.put(PROPERTY_CONFIG_PID, null);
+ this.session.put(PROPERTY_CONFIG_PROPS, null);
} else {
String pid = (String) this.session.get(PROPERTY_CONFIG_PID);
Configuration cfg = admin.getConfiguration(pid, null);
Modified:
felix/trunk/karaf/shell/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml
URL:
http://svn.apache.org/viewvc/felix/trunk/karaf/shell/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml?rev=826734&r1=826733&r2=826734&view=diff
==============================================================================
---
felix/trunk/karaf/shell/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml
(original)
+++
felix/trunk/karaf/shell/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml
Mon Oct 19 17:49:36 2009
@@ -18,6 +18,8 @@
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+
xmlns:cm="http://geronimo.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
+
xmlns:ext="http://geronimo.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
default-activation="lazy">
<command-bundle xmlns="http://felix.apache.org/karaf/xmlns/shell/v1.0.0">
@@ -59,7 +61,9 @@
</completers>
</command>
<command name="config/update">
- <action class="org.apache.felix.karaf.shell.config.UpdateCommand"/>
+ <action class="org.apache.felix.karaf.shell.config.UpdateCommand">
+ <property name="storage" value="${storage}" />
+ </action>
</command>
</command-bundle>
@@ -72,5 +76,12 @@
<reference id="configAdmin"
interface="org.osgi.service.cm.ConfigurationAdmin" />
+ <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]" />
+
+ <cm:property-placeholder
persistent-id="org.apache.felix.karaf.shell.config">
+ <cm:default-properties>
+ <cm:property name="storage" value="$[karaf.base]/etc/"/>
+ </cm:default-properties>
+ </cm:property-placeholder>
</blueprint>