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 58cc5a6cc2bab48706ca6dec57759539f2d50c23
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Tue Sep 23 06:11:52 2014 +0000

    Add simple txt parser
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/tooling/support/slingstart-model@1626948
 13f79535-47bb-0310-9956-ffa450edef68
---
 .../slingstart/model/txt/TXTSSMModelReader.java    | 121 +++++++++++++++++++++
 .../sling/slingstart/model/txt/package-info.java   |  24 ++++
 .../slingstart/model/xml/XMLSSMModelReader.java    |   2 +-
 3 files changed, 146 insertions(+), 1 deletion(-)

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
new file mode 100644
index 0000000..9c9ccd5
--- /dev/null
+++ b/src/main/java/org/apache/sling/slingstart/model/txt/TXTSSMModelReader.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.slingstart.model.txt;
+
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.Reader;
+
+import org.apache.sling.slingstart.model.SSMArtifact;
+import org.apache.sling.slingstart.model.SSMConfiguration;
+import org.apache.sling.slingstart.model.SSMDeliverable;
+import org.apache.sling.slingstart.model.SSMFeature;
+
+
+public class TXTSSMModelReader {
+
+    /**
+     * Reads the deliverable file
+     * The reader is not closed.
+     * @throws IOException
+     */
+    public static SSMDeliverable read(final Reader reader)
+    throws IOException {
+        final SSMDeliverable model = new SSMDeliverable();
+        final LineNumberReader lnr = new LineNumberReader(reader);
+        String line;
+        while ( (line = lnr.readLine()) != null ) {
+            if ( ignore(line) ) {
+                continue;
+            }
+
+            // Command must start with a verb, optionally followed
+            // by properties
+            if (!isVerb(line)) {
+                throw new IOException("Expecting verb, current line is " + 
line);
+            }
+
+            // Parse verb and qualifier from first line
+            final String [] firstLine= line.split(" ");
+            final String verb = firstLine[0];
+            final StringBuilder qualifier = new StringBuilder();
+            for(int i=1; i < firstLine.length; i++) {
+                if (qualifier.length() > 0) {
+                    qualifier.append(' ');
+                }
+                qualifier.append(firstLine[i]);
+            }
+
+            // Parse properties from optional indented lines
+            // that follow verb line
+            StringBuilder props = null;
+            do {
+                line = lnr.readLine();
+                if (line != null && !isVerb(line)) {
+                    if (props == null) {
+                        props = new StringBuilder();
+                    }
+                    addProperty(props, line);
+                }
+            } while ( line != null && !isVerb(line));
+
+            if ( "classpath".equals("verb") ) {
+                final SSMFeature boot = model.getOrCreateFeature(new String[] 
{SSMFeature.RUN_MODE_BOOT});
+                final SSMArtifact artifact = 
SSMArtifact.fromMvnUrl(qualifier.toString());
+                boot.getOrCreateStartLevel(0).artifacts.add(artifact);
+            } else if ( "bundle".equals(verb) ) {
+                final SSMFeature feature = model.getOrCreateFeature(null);
+                final SSMArtifact artifact = 
SSMArtifact.fromMvnUrl(qualifier.toString());
+                feature.getOrCreateStartLevel(0).artifacts.add(artifact);
+            } else if ( "configuration".equals(verb) ) {
+                final SSMFeature feature = model.getOrCreateFeature(null);
+                final SSMConfiguration config = new SSMConfiguration();
+                if ( props != null ) {
+                    config.properties = props.toString();
+                }
+                feature.configurations.add(config);
+            }
+        }
+
+        return model;
+    }
+
+    private static boolean ignore(final String line) {
+        return line.trim().length() == 0 || line.startsWith("#");
+    }
+
+    private static boolean isVerb(final String line) {
+        return line.length() > 0 && !Character.isWhitespace(line.charAt(0));
+    }
+
+   private static void addProperty(final StringBuilder builder, final String 
line)
+   throws IOException {
+        final int equalsPos = line.indexOf('=');
+        final String key = line.substring(0, equalsPos).trim();
+        final String value = line.substring(equalsPos + 1).trim();
+        if (key.trim().isEmpty() || value.trim().isEmpty() ) {
+            throw new IOException("Invalid property line [" + line + "]");
+        }
+
+        builder.append(key);
+        builder.append('=');
+        builder.append(value);
+        builder.append('\n');
+    }
+}
+
+
diff --git 
a/src/main/java/org/apache/sling/slingstart/model/txt/package-info.java 
b/src/main/java/org/apache/sling/slingstart/model/txt/package-info.java
new file mode 100644
index 0000000..5a2902a
--- /dev/null
+++ b/src/main/java/org/apache/sling/slingstart/model/txt/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+@Version("1.0")
+package org.apache.sling.slingstart.model.txt;
+
+import aQute.bnd.annotation.Version;
+
diff --git 
a/src/main/java/org/apache/sling/slingstart/model/xml/XMLSSMModelReader.java 
b/src/main/java/org/apache/sling/slingstart/model/xml/XMLSSMModelReader.java
index 3c678f0..cc45c0e 100644
--- a/src/main/java/org/apache/sling/slingstart/model/xml/XMLSSMModelReader.java
+++ b/src/main/java/org/apache/sling/slingstart/model/xml/XMLSSMModelReader.java
@@ -76,7 +76,7 @@ public class XMLSSMModelReader {
     }
 
     /**
-     * Reads the properties file
+     * Reads the deliverable file
      * The reader is not closed.
      * @throws IOException
      */

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to