Fully support Apach Felix config file format. Move from properties to getter and setter methods

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1627263 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 622ebeb..e7fb6de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -114,6 +114,13 @@
             <version>3.3</version>
             <scope>provided</scope>
         </dependency>
+      <!-- We use a class from the config admin implementation to read config files -->
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.configadmin</artifactId>
+            <version>1.2.8</version>
+            <scope>provided</scope>
+        </dependency>
         <dependency>
             <groupId>org.codehaus.plexus</groupId>
             <artifactId>plexus-archiver</artifactId>
diff --git a/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java b/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java
index c3616c6..4b3d973 100644
--- a/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java
+++ b/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java
@@ -138,12 +138,12 @@
     }
 
     private static void addDependencies(final SSMDeliverable model, final Logger log, final MavenProject project) {
-        for(final SSMFeature feature : model.features) {
+        for(final SSMFeature feature : model.getFeatures()) {
             // skip base
             if ( feature.isRunMode(SSMFeature.RUN_MODE_BASE) ) {
                 continue;
             }
-            for(final SSMStartLevel sl : feature.startLevels) {
+            for(final SSMStartLevel sl : feature.getStartLevels()) {
                 for(final SSMArtifact a : sl.artifacts) {
                     final Dependency dep = new Dependency();
                     dep.setGroupId(a.groupId);
diff --git a/src/main/java/org/apache/sling/maven/slingstart/ModelUtils.java b/src/main/java/org/apache/sling/maven/slingstart/ModelUtils.java
index b213c4e..6895e23 100644
--- a/src/main/java/org/apache/sling/maven/slingstart/ModelUtils.java
+++ b/src/main/java/org/apache/sling/maven/slingstart/ModelUtils.java
@@ -30,8 +30,8 @@
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 import org.apache.sling.slingstart.model.SSMArtifact;
-import org.apache.sling.slingstart.model.SSMFeature;
 import org.apache.sling.slingstart.model.SSMDeliverable;
+import org.apache.sling.slingstart.model.SSMFeature;
 import org.apache.sling.slingstart.model.xml.XMLSSMModelReader;
 import org.codehaus.plexus.logging.Logger;
 
@@ -142,17 +142,17 @@
         if ( base == null ) {
             throw new MojoExecutionException("No base run mode found.");
         }
-        if ( base.startLevels.size() == 0 ) {
+        if ( base.getStartLevels().size() == 0 ) {
             throw new MojoExecutionException("No base artifacts defined.");
         }
-        if ( base.startLevels.size() > 1 ) {
+        if ( base.getStartLevels().size() > 1 ) {
             throw new MojoExecutionException("Base run mode should only have a single start level.");
         }
-        if ( base.startLevels.get(0).artifacts.size() != 1 ) {
+        if ( base.getStartLevels().get(0).artifacts.size() != 1 ) {
             throw new MojoExecutionException("Base run mode should contain exactly one artifact.");
         }
 
-        return base.startLevels.get(0).artifacts.get(0);
+        return base.getStartLevels().get(0).artifacts.get(0);
     }
 
     /**
diff --git a/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java b/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java
index ffc643b..f066ad0 100644
--- a/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java
+++ b/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java
@@ -17,12 +17,14 @@
 package org.apache.sling.maven.slingstart;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
+import org.apache.felix.cm.file.ConfigurationHandler;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -126,7 +128,7 @@
                 if ( webConfig != null ) {
                     final File webXML = new File(webappDir, "web.xml");
                     try {
-                        FileUtils.fileWrite(webXML, webConfig.properties);
+                        FileUtils.fileWrite(webXML, webConfig.getProperties().get(SSMConstants.CFG_WEB_XML).toString());
                     } catch (final IOException e) {
                         throw new MojoExecutionException("Unable to write configuration to " + webXML, e);
                     }
@@ -149,7 +151,7 @@
             final Artifact artifact = getBaseArtifact(model, null, BuildConstants.TYPE_JAR);
             contentsMap.put(BASE_DESTINATION + "/"+ artifact.getArtifactId() + "." + artifact.getArtifactHandler().getExtension(), artifact.getFile());
         }
-        for(final SSMFeature feature : model.features) {
+        for(final SSMFeature feature : model.getFeatures()) {
             if ( packageRunMode == null ) {
                 if ( feature.isSpecial()
                      && !feature.isRunMode(SSMFeature.RUN_MODE_BOOT)) {
@@ -169,17 +171,17 @@
      */
     private void buildContentsMap(final SSMDeliverable model, final SSMFeature runMode, final Map<String, File> contentsMap)
     throws MojoExecutionException{
-        for(final SSMStartLevel sl : runMode.startLevels) {
+        for(final SSMStartLevel sl : runMode.getStartLevels()) {
             for(final SSMArtifact a : sl.artifacts) {
                 final Artifact artifact = ModelUtils.getArtifact(this.project, a.groupId, a.artifactId, model.getValue(a.version), a.type, a.classifier);
                 final File artifactFile = artifact.getFile();
-                contentsMap.put(getPathForArtifact(sl.level, artifactFile.getName(), runMode), artifactFile);
+                contentsMap.put(getPathForArtifact(sl.getLevel(), artifactFile.getName(), runMode), artifactFile);
             }
         }
 
         final File rootConfDir = new File(this.getTmpDir(), "global-config");
         boolean hasConfig = false;
-        for(final SSMConfiguration config : runMode.configurations) {
+        for(final SSMConfiguration config : runMode.getConfigurations()) {
             // skip special configurations
             if ( config.isSpecial() ) {
                 continue;
@@ -189,7 +191,12 @@
             getLog().debug(String.format("Creating configuration at %s", configFile.getPath()));
             configFile.getParentFile().mkdirs();
             try {
-                FileUtils.fileWrite(configFile, config.properties);
+                final FileOutputStream os = new FileOutputStream(configFile);
+                try {
+                    ConfigurationHandler.write(os, config.getProperties());
+                } finally {
+                    os.close();
+                }
             } catch (final IOException e) {
                 throw new MojoExecutionException("Unable to write configuration to " + configFile, e);
             }
@@ -207,18 +214,18 @@
     throws MojoExecutionException {
         String settings = null;
         final SSMFeature baseRM = model.getRunMode(SSMFeature.RUN_MODE_BASE);
-        if ( baseRM != null && baseRM.settings != null ) {
-            settings = baseRM.settings.properties + "\n";
+        if ( baseRM != null && baseRM.getSettings() != null ) {
+            settings = baseRM.getSettings().properties + "\n";
         } else {
             settings = "";
         }
         final SSMFeature bootRM = model.getRunMode(SSMFeature.RUN_MODE_BOOT);
-        if ( bootRM != null && bootRM.settings != null ) {
-            settings = settings + bootRM.settings.properties + "\n";
+        if ( bootRM != null && bootRM.getSettings() != null ) {
+            settings = settings + bootRM.getSettings().properties + "\n";
         }
         final SSMFeature packageRM = model.getRunMode(packageRunMode);
-        if ( packageRM != null && packageRM.settings != null ) {
-            settings = settings + packageRM.settings.properties;
+        if ( packageRM != null && packageRM.getSettings() != null ) {
+            settings = settings + packageRM.getSettings().properties;
         }
 
         if ( settings != null ) {
@@ -237,34 +244,37 @@
      */
     private void buildBootstrapFile(final SSMDeliverable model, final String packageRunMode, final File outputDir)
     throws MojoExecutionException {
-        String bootstrapTxt = "";
+        final StringBuilder sb = new StringBuilder();
         final SSMFeature baseRM = model.getRunMode(SSMFeature.RUN_MODE_BASE);
         if ( baseRM != null ) {
             final SSMConfiguration c = baseRM.getConfiguration(SSMConstants.CFG_BOOTSTRAP);
             if ( c != null ) {
-                bootstrapTxt = c.properties + "\n";
+                sb.append(c.getProperties().get(c.getPid()));
+                sb.append('\n');
             }
         }
         final SSMFeature bootRM = model.getRunMode(SSMFeature.RUN_MODE_BOOT);
         if ( bootRM != null ) {
             final SSMConfiguration c = bootRM.getConfiguration(SSMConstants.CFG_BOOTSTRAP);
             if ( c != null ) {
-                bootstrapTxt = bootstrapTxt + c.properties;
+                sb.append(c.getProperties().get(c.getPid()));
+                sb.append('\n');
             }
         }
         final SSMFeature packageRM = model.getRunMode(packageRunMode);
         if ( packageRM != null ) {
             final SSMConfiguration c = packageRM.getConfiguration(SSMConstants.CFG_BOOTSTRAP);
             if ( c != null ) {
-                bootstrapTxt = bootstrapTxt + c.properties;
+                sb.append(c.getProperties().get(c.getPid()));
+                sb.append('\n');
             }
         }
 
-        if ( bootstrapTxt != null ) {
+        if ( sb.length() > 0 ) {
             final File file = new File(outputDir, BOOTSTRAP_FILE);
             getLog().debug(String.format("Creating bootstrap file at %s", file.getPath()));
             try {
-                FileUtils.fileWrite(file, bootstrapTxt);
+                FileUtils.fileWrite(file, sb.toString());
             } catch ( final IOException ioe ) {
                 throw new MojoExecutionException("Unable to write bootstrap file.", ioe);
             }
@@ -335,8 +345,8 @@
      */
     private String getPathForArtifact(final int startLevel, final String artifactName, final SSMFeature rm) {
         final Set<String> runModesList = new TreeSet<String>();
-        if (rm.runModes != null ) {
-            for(final String mode : rm.runModes) {
+        if (rm.getRunModes() != null ) {
+            for(final String mode : rm.getRunModes()) {
                 runModesList.add(mode);
             }
         }
@@ -367,8 +377,8 @@
      */
     private String getPathForConfiguration(final SSMConfiguration config, final SSMFeature rm) {
         final Set<String> runModesList = new TreeSet<String>();
-        if (rm.runModes != null ) {
-            for(final String mode : rm.runModes) {
+        if (rm.getRunModes() != null ) {
+            for(final String mode : rm.getRunModes()) {
                 runModesList.add(mode);
             }
         }
@@ -390,8 +400,8 @@
             runModeExt = sb.toString();
         }
 
-        final String mainName = (config.factoryPid != null ? config.factoryPid : config.pid);
-        final String alias = (config.factoryPid != null ? "-" + config.pid : "");
+        final String mainName = (config.getFactoryPid() != null ? config.getFactoryPid() : config.getPid());
+        final String alias = (config.getFactoryPid() != null ? "-" + config.getPid() : "");
         return String.format("%s/%s%s/%s%s.cfg", BASE_DESTINATION, CONFIG_DIRECTORY,
                 runModeExt,
                 mainName,