This is an automated email from the ASF dual-hosted git repository.

pauls pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-launcher.git


The following commit(s) were added to refs/heads/master by this push:
     new 789c050  Allow repoinit extension to be of type json.
789c050 is described below

commit 789c050a0da1726a3b1d06d4d8d77d1a7ab66b0f
Author: Karl Pauls <[email protected]>
AuthorDate: Thu May 3 22:24:02 2018 +0200

    Allow repoinit extension to be of type json.
---
 .../feature/launcher/impl/FeatureProcessor.java    | 41 +++++++++++++++++-----
 1 file changed, 32 insertions(+), 9 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java 
b/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
index 557ec90..bc9cd00 100644
--- a/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
+++ b/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
@@ -35,9 +35,16 @@ import java.io.File;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.StringReader;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonReader;
+import javax.json.JsonString;
+import javax.json.JsonValue;
 
 public class FeatureProcessor {
 
@@ -113,19 +120,35 @@ public class FeatureProcessor {
                     final ArtifactHandler handler = 
artifactManager.getArtifactHandler(":" + a.getId().toMvnPath());
                     
config.getInstallation().addInstallableArtifact(handler.getFile());
                 }
-            } else {
-                if ( 
ext.getName().equals(FeatureConstants.EXTENSION_NAME_REPOINIT) ) {
-                    if ( ext.getType() != ExtensionType.TEXT ) {
-                        throw new 
Exception(FeatureConstants.EXTENSION_NAME_REPOINIT + " extension must be of 
type text and not json");
+            } else if ( 
ext.getName().equals(FeatureConstants.EXTENSION_NAME_REPOINIT) ) {
+                    String text;
+                    if ( ext.getType() == ExtensionType.TEXT ) {
+                        text = ext.getText();
+                    }
+                    else if (ext.getType() == ExtensionType.JSON) {
+                        try (JsonReader reader = Json.createReader(new 
StringReader(ext.getJSON()))){
+                            JsonArray array = reader.readArray();
+                            if (array.size() > 0) {
+                                text = array.getString(0);
+                                for (int i = 1; i < array.size(); i++) {
+                                    text += "\n" + array.getString(i);
+                                }
+                            }
+                            else {
+                                text = "";
+                            }
+                        }
+                    }
+                    else {
+                        throw new 
Exception(FeatureConstants.EXTENSION_NAME_REPOINIT + " extension must be of 
type text or json");
                     }
                     final Configuration cfg = new 
Configuration("org.apache.sling.jcr.repoinit.RepositoryInitializer", "repoinit" 
+ String.valueOf(index));
                     index++;
-                    cfg.getProperties().put("scripts", ext.getText());
+                    cfg.getProperties().put("scripts", text);
                     config.getInstallation().addConfiguration(cfg.getName(), 
cfg.getFactoryPid(), cfg.getProperties());
-                } else {
-                    if ( ext.isRequired() ) {
-                        throw new Exception("Unknown required extension " + 
ext.getName());
-                    }
+            } else {
+                if ( ext.isRequired() ) {
+                    throw new Exception("Unknown required extension " + 
ext.getName());
                 }
             }
         }

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

Reply via email to