This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.provisioning.model-1.0.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-provisioning-model.git
commit ca9289e26a561c44d149d067ae1e48ea28782974 Author: Carsten Ziegeler <cziege...@apache.org> AuthorDate: Sat Sep 27 15:41:56 2014 +0000 Finish configuration support git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/support/slingstart-model@1627981 13f79535-47bb-0310-9956-ffa450edef68 --- .../sling/slingstart/model/SSMConstants.java | 10 ++++ .../org/apache/sling/slingstart/model/SSMUtil.java | 62 ++++++++++++++++++++-- .../slingstart/model/txt/TXTSSMModelReader.java | 46 ++++++---------- .../slingstart/model/txt/TXTSSMModelWriter.java | 16 +++++- 4 files changed, 98 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/apache/sling/slingstart/model/SSMConstants.java b/src/main/java/org/apache/sling/slingstart/model/SSMConstants.java index 3b0fa18..064bb79 100644 --- a/src/main/java/org/apache/sling/slingstart/model/SSMConstants.java +++ b/src/main/java/org/apache/sling/slingstart/model/SSMConstants.java @@ -25,6 +25,16 @@ public abstract class SSMConstants { /** Name of the configuration for the bootstrap contents. */ public static final String CFG_BOOTSTRAP = ":bootstrap"; + /** Unprocessed configuration values. */ + public static final String CFG_UNPROCESSED = ":rawconfig"; + + /** Format of the unprocessed configuration values. */ + public static final String CFG_UNPROCESSED_FORMAT = ":rawconfig.format"; + + public static final String CFG_FORMAT_FELIX_CA = "felixca"; + + public static final String CFG_FORMAT_PROPERTIES = "properties"; + /** Name of the base run mode for the Sling launchpad. */ public static final String RUN_MODE_BASE = ":base"; diff --git a/src/main/java/org/apache/sling/slingstart/model/SSMUtil.java b/src/main/java/org/apache/sling/slingstart/model/SSMUtil.java index e600690..fa09bc8 100644 --- a/src/main/java/org/apache/sling/slingstart/model/SSMUtil.java +++ b/src/main/java/org/apache/sling/slingstart/model/SSMUtil.java @@ -16,8 +16,15 @@ */ package org.apache.sling.slingstart.model; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.StringReader; +import java.util.Dictionary; import java.util.Enumeration; import java.util.Map; +import java.util.Properties; + +import org.apache.felix.cm.file.ConfigurationHandler; /** * Utility methods @@ -28,7 +35,7 @@ public abstract class SSMUtil { * Replace all variables in the model and return a new model with the replaced values. * @param base The base model. * @return The model with replaced variables. - * @throws IllegalArgumentException If a variable can't be replaced. + * @throws IllegalArgumentException If a variable can't be replaced or configuration properties can't be parsed */ public static SSMDeliverable getEffectiveModel(final SSMDeliverable base) { final SSMDeliverable result = new SSMDeliverable(); @@ -64,10 +71,55 @@ public abstract class SSMUtil { newConfig.setComment(config.getComment()); newConfig.setLocation(config.getLocation()); - final Enumeration<String> i = config.getProperties().keys(); - while ( i.hasMoreElements() ) { - final String key = i.nextElement(); - newConfig.getProperties().put(key, config.getProperties().get(key)); + // check for raw configuration + final String rawConfig = (String)config.getProperties().get(SSMConstants.CFG_UNPROCESSED); + if ( rawConfig != null ) { + final String format = (String)config.getProperties().get(SSMConstants.CFG_UNPROCESSED_FORMAT); + + if ( SSMConstants.CFG_FORMAT_PROPERTIES.equals(format) ) { + // properties + final Properties props = new Properties(); + try { + props.load(new StringReader(rawConfig)); + } catch ( final IOException ioe) { + throw new IllegalArgumentException("Unable to read configuration properties.", ioe); + } + final Enumeration<Object> i = props.keys(); + while ( i.hasMoreElements() ) { + final String key = (String)i.nextElement(); + newConfig.getProperties().put(key, props.get(key)); + } + } else { + // Apache Felix CA format + ByteArrayInputStream bais = null; + try { + bais = new ByteArrayInputStream(rawConfig.getBytes("UTF-8")); + @SuppressWarnings("unchecked") + final Dictionary<String, Object> props = ConfigurationHandler.read(bais); + final Enumeration<String> i = props.keys(); + while ( i.hasMoreElements() ) { + final String key = i.nextElement(); + newConfig.getProperties().put(key, props.get(key)); + } + } catch ( final IOException ioe) { + throw new IllegalArgumentException("Unable to read configuration properties.", ioe); + } finally { + if ( bais != null ) { + try { + bais.close(); + } catch ( final IOException ignore ) { + // ignore + } + } + } + } + } else { + // simply copy + final Enumeration<String> i = config.getProperties().keys(); + while ( i.hasMoreElements() ) { + final String key = i.nextElement(); + newConfig.getProperties().put(key, config.getProperties().get(key)); + } } newFeature.getConfigurations().add(newConfig); diff --git a/src/main/java/org/apache/sling/slingstart/model/txt/TXTSSMModelReader.java b/src/main/java/org/apache/sling/slingstart/model/txt/TXTSSMModelReader.java index bd439bd..2451d99 100644 --- a/src/main/java/org/apache/sling/slingstart/model/txt/TXTSSMModelReader.java +++ b/src/main/java/org/apache/sling/slingstart/model/txt/TXTSSMModelReader.java @@ -16,16 +16,13 @@ */ package org.apache.sling.slingstart.model.txt; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.LineNumberReader; import java.io.Reader; -import java.util.Dictionary; -import java.util.Enumeration; -import org.apache.felix.cm.file.ConfigurationHandler; import org.apache.sling.slingstart.model.SSMArtifact; import org.apache.sling.slingstart.model.SSMConfiguration; +import org.apache.sling.slingstart.model.SSMConstants; import org.apache.sling.slingstart.model.SSMDeliverable; import org.apache.sling.slingstart.model.SSMFeature; import org.apache.sling.slingstart.model.SSMStartLevel; @@ -69,7 +66,6 @@ public class TXTSSMModelReader { private String comment = null; private StringBuilder configBuilder = null; - private boolean configFelixFormat = false; private LineNumberReader lineNumberReader; @@ -139,14 +135,24 @@ public class TXTSSMModelReader { this.init(startLevel); mode = MODE.START_LEVEL; - } else if ( trimmedLine.startsWith("config:FELIX ") || trimmedLine.startsWith("config: ") ) { + } else if ( trimmedLine.startsWith("config:") ) { checkConfig(); if ( feature == null ) { throw new IOException("configuration outside of feature in line " + this.lineNumberReader.getLineNumber()); } - mode = MODE.CONFIGURATION; + String format = SSMConstants.CFG_FORMAT_FELIX_CA; + if ( trimmedLine.length() > 7 && !Character.isWhitespace(trimmedLine.charAt(7)) ) { + String formatDef = trimmedLine.substring(7); + if ( formatDef.equals(SSMConstants.CFG_FORMAT_PROPERTIES) || formatDef.startsWith(SSMConstants.CFG_FORMAT_PROPERTIES + " ")) { + format = SSMConstants.CFG_FORMAT_PROPERTIES; + } else if ( formatDef.equals(SSMConstants.CFG_FORMAT_FELIX_CA) || formatDef.startsWith(SSMConstants.CFG_FORMAT_FELIX_CA + " ")) { + format = SSMConstants.CFG_FORMAT_FELIX_CA; + } else { + throw new IOException("Unknown configuration format: " + formatDef + " in line " + this.lineNumberReader.getLineNumber()); + } + } final int factoryPos = params.indexOf('-'); if ( factoryPos == -1 ) { config = new SSMConfiguration(params, null); @@ -154,9 +160,10 @@ public class TXTSSMModelReader { config = new SSMConfiguration(params.substring(pos + 1), params.substring(0, pos)); } this.init(config); + config.getProperties().put(SSMConstants.CFG_UNPROCESSED_FORMAT, format); feature.getConfigurations().add(config); configBuilder = new StringBuilder(); - configFelixFormat = trimmedLine.startsWith("config:FELIX "); + mode = MODE.CONFIGURATION; } else if ( trimmedLine.startsWith("settings:") ) { checkConfig(); @@ -224,28 +231,9 @@ public class TXTSSMModelReader { } } - private void checkConfig() - throws IOException { + private void checkConfig() { if ( config != null ) { - ByteArrayInputStream bais = null; - try { - bais = new ByteArrayInputStream(configBuilder.toString().getBytes("UTF-8")); - @SuppressWarnings("unchecked") - final Dictionary<String, Object> props = ConfigurationHandler.read(bais); - final Enumeration<String> e = props.keys(); - while ( e.hasMoreElements() ) { - final String key = e.nextElement(); - config.getProperties().put(key, props.get(key)); - } - } finally { - if ( bais != null ) { - try { - bais.close(); - } catch ( final IOException ignore ) { - // ignore - } - } - } + config.getProperties().put(SSMConstants.CFG_UNPROCESSED, configBuilder.toString()); } config = null; configBuilder = null; diff --git a/src/main/java/org/apache/sling/slingstart/model/txt/TXTSSMModelWriter.java b/src/main/java/org/apache/sling/slingstart/model/txt/TXTSSMModelWriter.java index 0df8848..12534c5 100644 --- a/src/main/java/org/apache/sling/slingstart/model/txt/TXTSSMModelWriter.java +++ b/src/main/java/org/apache/sling/slingstart/model/txt/TXTSSMModelWriter.java @@ -27,6 +27,7 @@ import java.util.Map; import org.apache.felix.cm.file.ConfigurationHandler; import org.apache.sling.slingstart.model.SSMArtifact; import org.apache.sling.slingstart.model.SSMConfiguration; +import org.apache.sling.slingstart.model.SSMConstants; import org.apache.sling.slingstart.model.SSMDeliverable; import org.apache.sling.slingstart.model.SSMFeature; import org.apache.sling.slingstart.model.SSMStartLevel; @@ -158,7 +159,16 @@ public class TXTSSMModelWriter { // configurations for(final SSMConfiguration config : feature.getConfigurations()) { writeComment(pw, config); - pw.print(" config: "); + final String raw = (String)config.getProperties().get(SSMConstants.CFG_UNPROCESSED); + String format = (String)config.getProperties().get(SSMConstants.CFG_UNPROCESSED_FORMAT); + if ( format == null ) { + format = SSMConstants.CFG_FORMAT_FELIX_CA; + } + pw.print(" config:"); + if ( !SSMConstants.CFG_FORMAT_FELIX_CA.equals(format) ) { + pw.print(format); + } + pw.print(" "); if ( config.getFactoryPid() != null ) { pw.print(config.getFactoryPid()); pw.print("-"); @@ -166,7 +176,9 @@ public class TXTSSMModelWriter { pw.print(config.getPid()); pw.println(); final String configString; - if ( config.isSpecial() ) { + if ( raw != null ) { + configString = raw; + } else if ( config.isSpecial() ) { configString = config.getProperties().get(config.getPid()).toString(); } else { final ByteArrayOutputStream os = new ByteArrayOutputStream(); -- To stop receiving notification emails like this one, please contact "commits@sling.apache.org" <commits@sling.apache.org>.