FELIX-2513 : Support richer format for configurations
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@982991 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/fileinstall/pom.xml b/fileinstall/pom.xml
index dfff0c9..9ba034a 100644
--- a/fileinstall/pom.xml
+++ b/fileinstall/pom.xml
@@ -42,6 +42,12 @@
<artifactId>org.osgi.compendium</artifactId>
<version>4.1.0</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.configadmin</artifactId>
+ <version>1.2.4</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
@@ -68,6 +74,9 @@
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
<Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
<_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))</_versionpolicy>
+ <Embed-Dependency>
+ org.apache.felix.configadmin;inline="org/apache/felix/cm/file/ConfigurationHandler.*"
+ </Embed-Dependency>
</instructions>
</configuration>
</plugin>
diff --git a/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java b/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java
index f9cc701..73e45c8 100644
--- a/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java
+++ b/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java
@@ -18,13 +18,10 @@
*/
package org.apache.felix.fileinstall.internal;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.util.Hashtable;
-import java.util.Properties;
+import java.io.*;
+import java.util.*;
+import org.apache.felix.cm.file.ConfigurationHandler;
import org.apache.felix.fileinstall.ArtifactInstaller;
import org.apache.felix.fileinstall.internal.Util.Logger;
import org.osgi.framework.BundleContext;
@@ -48,7 +45,8 @@
public boolean canHandle(File artifact)
{
- return artifact.getName().endsWith(".cfg");
+ return artifact.getName().endsWith(".cfg")
+ || artifact.getName().endsWith(".config");
}
public void install(File artifact) throws Exception
@@ -79,29 +77,43 @@
* @return
* @throws Exception
*/
- boolean setConfig(File f) throws Exception
+ boolean setConfig(final File f) throws Exception
{
- Properties p = new Properties();
- InputStream in = new BufferedInputStream(new FileInputStream(f));
+ final Hashtable ht = new Hashtable();
+ final InputStream in = new BufferedInputStream(new FileInputStream(f));
try
{
- in.mark(1);
- boolean isXml = in.read() == '<';
- in.reset();
- if (isXml) {
- p.loadFromXML(in);
- } else {
- p.load(in);
+ if ( f.getName().endsWith(".cfg") )
+ {
+ final Properties p = new Properties();
+ in.mark(1);
+ boolean isXml = in.read() == '<';
+ in.reset();
+ if (isXml) {
+ p.loadFromXML(in);
+ } else {
+ p.load(in);
+ }
+ Util.performSubstitution(p);
+ ht.putAll(p);
+ }
+ else
+ {
+ final Dictionary config = ConfigurationHandler.read(in);
+ final Enumeration i = config.keys();
+ while ( i.hasMoreElements() )
+ {
+ final Object key = i.nextElement();
+ ht.put(key, config.get(key));
+ }
}
}
finally
{
in.close();
}
- Util.performSubstitution(p);
+
String pid[] = parsePid(f.getName());
- Hashtable ht = new Hashtable();
- ht.putAll(p);
ht.put(DirectoryWatcher.FILENAME, f.getName());
Configuration config = getConfiguration(pid[0], pid[1]);
if (config.getBundleLocation() != null)