You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:49:27 UTC

[sling-org-apache-sling-jcr-repoinit] annotated tag org.apache.sling.jcr.repoinit-1.0.2 created (now a32bab7)

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

rombert pushed a change to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git.


      at a32bab7  (tag)
 tagging dec91bd31a46b93382e67cc46dd460607615dfa5 (commit)
      by Bertrand Delacretaz
      on Mon Aug 22 16:22:34 2016 +0000

- Log -----------------------------------------------------------------
org.apache.sling.jcr.repoinit-1.0.2
-----------------------------------------------------------------------

This annotated tag includes the following new commits:

     new ae75f44  SLING-5355 - jcr module added, work in progress
     new eabeb26  SLING-5355 - rename jcr to oak-jcr
     new 4b89959  SLING-5355 - test with multiple users
     new d20da33  SLING-5355 - factor our TestUtil
     new d7a5f83  SLING-5355 - AclOperationVisitor partially implemented, and webconsole plugin added
     new a52d167  SLING-5355 - cleanup tests
     new 909608b  SLING-5355 - better error reporting
     new de7c980  SLING-5355 - parser service
     new 1d0ac30  SLING-5355 - it's ok for service user to already exist
     new 1bc8999  SLING-5355 - AclSetupComponent, work in progress
     new 8791efe  SLING-5355 - fail if Principal not found
     new 32f8cf8  SLING-5355 - test ACL definitions in provisioning model
     new 15ca220  Switch to parent pom 26
     new 77ca4b9  SLING-5449 - rename the modules to 'jcrinit'
     new 462ba19  SLING-5449 - the name is 'repoinit' instead as the parser is not JCR-specific
     new 6bc3f85  SLING-5449 - the name is 'repoinit' instead as the parser is not JCR-specific
     new 8296d7d  SLING-5449 - rename packages to repoinit
     new 22a05d6  SLING-5449 - remove AclSetup component and adapt integration tests
     new 7790424  SLING-5449 - rename the remaining things from ACL to 'repoinit'
     new 8a6aec6  SLING-5449 - rename one more thing from ACL to 'repoinit'
     new 9bd6e4b  SLING-5449 - remove console plugin, we don't want this module to be Sling specific
     new 2752857  SLING-5449 - move repoinit under commons
     new f8873b8  repoinit: fix SCM urls after move
     new 5e4f40b  repoinit/oak-jcr: second attempt to fix the scm urls
     new 70c5d7b  SLING-5449 - initial base tree creation language, see test-20.txt for examples
     new 7af1acb  SLING-5449 - Implement CreatePath in oak-jcr module
     new 5938771  SLING-5449 - move the repoinit modules under extensions, they do contain Sling-specific stuff
     new e5e302e  SLING-5449 - fix scm strings
     new e87acee  SLING-5355 - RepositoryInitializer created, reads from provisioning model, WIP:ProvisioningModelIT fails for now
     new 4fc1e21  SLING-5355 - ProvisioningModelIT passes
     new 029bbe3  SLING-5800 - remove unnecessary snapshots and use current jcr.api snapshot
     new 7b78070  SLING-5800 - depend on related releases while releasing this module
     new 3663d69  [maven-release-plugin] prepare release org.apache.sling.repoinit.oak-jcr-1.0.0
     new 60f5b7b  [maven-release-plugin] prepare for next development iteration
     new 7dff12f  SLING-5800 - back to current snapshots after releases
     new 713d36f  Rename o.a.s.repoinit.oak-jcr to o.a.s.jcr.repoinit
     new 1a15e86  SLING-5819 - jcr.repoinit bundle should only export what's strictly needed
     new 4273f56  Remove unused source files and folders
     new 92c4254  SLING-5819 - rename repoinit.jcr package to jcr.repoinit
     new 533713a  Remove unused source code folders
     new 014d655  Prepare for release
     new bb14f7d  [maven-release-plugin] prepare release org.apache.sling.jcr.repoinit-1.0.0
     new 370808a  [maven-release-plugin] prepare for next development iteration
     new fa4b8d9  SLING-5819 - move jcr.repoinit module under jcr folder
     new 2c3076e  SLING-5843 - add 'register namespace' statement to repoinit parser
     new 0eb0707  SLING-5842 - add 'register nodetypes' statement to repoinit parser
     new 552a131  SLING-5842, SLING-5843 - implement the register namespace and nodetype operations in the jcr.repoinit module
     new 71c098a  SLING-5902 RepositoryInitializer uses name component property instead of label
     new 2ea4d7f  SLING-5917 parseRawText flag in getRepoInitText() is ambiguous
     new 35302c8  SLING-5917 - add RepositoryInitializer tests
     new 177001a  SLING-5917 - fix 'null section' test
     new 4bb31e7  SLING-5923 - Support <RAW> marker in model.section.name config param, same meaning as empty string
     new 31b0cec  SLING-5923 - clarify description
     new 3581dbb  SLING-5943 - support explicit format in RepositoryInitializer configuration
     new ed70824  SLING-5943 - better config metadata + logging
     new 3fa0bab  SLING-5943 - support multiple model/raw references in RepositoryInitializer configuration
     new b233c66  Prepare to release parser + this module
     new 83ea12f  [maven-release-plugin] prepare release org.apache.sling.jcr.repoinit-1.0.2
     new dec91bd  [maven-release-plugin] copy for tag org.apache.sling.jcr.repoinit-1.0.2

The 59 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


-- 
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].

[sling-org-apache-sling-jcr-repoinit] 02/17: SLING-5819 - move jcr.repoinit module under jcr folder

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit fa4b8d9e27aacd1769d4b1a35569ff334866fb33
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Jul 11 14:34:14 2016 +0000

    SLING-5819 - move jcr.repoinit module under jcr folder
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1752162 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 6ad25f3..f4c4850 100644
--- a/pom.xml
+++ b/pom.xml
@@ -41,9 +41,9 @@
   </properties>
 
   <scm>
-    <connection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/repoinit/jcr</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/repoinit/jcr</developerConnection>
-    <url>https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/repoinit/jcr</url>
+    <connection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit</developerConnection>
+    <url>https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit</url>
   </scm>
   
   <build>
@@ -103,7 +103,7 @@
      <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.repoinit.parser</artifactId>
-      <version>1.0.2</version>
+      <version>1.0.3-SNAPSHOT</version>
       <scope>provided</scope>
     </dependency>
     <dependency>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 09/17: SLING-5917 - fix 'null section' test

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit 177001a1421aa0aa22dc773f74ba271085b9f1dc
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Jul 29 09:39:05 2016 +0000

    SLING-5917 - fix 'null section' test
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1754491 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/jcr/repoinit/RepositoryInitializerTest.java      | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java b/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java
index 8350af6..60615e9 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java
@@ -28,8 +28,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
-import javax.jcr.Session;
-
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.repoinit.impl.JcrRepoInitOpsProcessorImpl;
 import org.apache.sling.jcr.repoinit.impl.RepositoryInitializer;
@@ -70,7 +68,7 @@ public class RepositoryInitializerTest {
         result.add(new Object[] { "All empty, just setup + parsing", "", false });
         result.add(new Object[] { "Using provisioning model", "SECTION_" + UUID.randomUUID(), true }); 
         result.add(new Object[] { "Raw repoinit/empty section", "", true}); 
-        result.add(new Object[] { "Raw repoinit/null section", "", true}); 
+        result.add(new Object[] { "Default value of model section config", null, true}); 
         return result;
     }
     
@@ -78,8 +76,10 @@ public class RepositoryInitializerTest {
         serviceUser = getClass().getSimpleName() + "-" + UUID.randomUUID();
         
         String txt = "create service user " + serviceUser; 
-        if(modelSection != null && modelSection.length() > 0) {
-            txt = "[feature name=foo]\n[:" + modelSection + "]\n" + txt; 
+        if(modelSection == null) {
+            txt = "[feature name=foo]\n[:repoinit]\n" + txt; 
+        } else if(modelSection.length() > 0) {
+            txt = "[feature name=bar]\n[:" + modelSection + "]\n" + txt; 
         }
         this.repoInitText = txt + "\n";
         this.url = getTestUrl(repoInitText);
@@ -94,7 +94,9 @@ public class RepositoryInitializerTest {
         initializer = new RepositoryInitializer();
         config = new HashMap<String, Object>();
         config.put(RepositoryInitializer.PROP_TEXT_URL, url);
-        config.put(RepositoryInitializer.PROP_MODEL_SECTION_NAME, modelSection);
+        if(modelSection != null) {
+            config.put(RepositoryInitializer.PROP_MODEL_SECTION_NAME, modelSection);
+        }
         initializer.activate(config);
         
         context.registerInjectActivateService(new RepoInitParserService());

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 11/17: SLING-5923 - clarify description

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit 31b0cec32a784839263e7f607bc1a5eb23a1a0d9
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Jul 29 12:19:46 2016 +0000

    SLING-5923 - clarify description
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1754503 13f79535-47bb-0310-9956-ffa450edef68
---
 .../java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
index 87b55d7..5c83c90 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
@@ -84,7 +84,7 @@ public class RepositoryInitializer implements SlingRepositoryInitializer {
             label="Model section name", 
             description=
                 "Optional provisioning model additional section name (without leading colon) used to extract"
-                + " repoinit statements from the raw text provided by our text URL. Leave empty or set to <RAW> to consider the content"
+                + " repoinit statements from the raw text provided by the configured source text URL. Leave empty or set to <RAW> to consider the content"
                 + " provided by that URL to already be in repoinit format", 
             value=DEFAULT_MODEL_SECTION_NAME)
     public static final String PROP_MODEL_SECTION_NAME = "model.section.name";

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 05/17: SLING-5842, SLING-5843 - implement the register namespace and nodetype operations in the jcr.repoinit module

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit 552a1314e7881c9aad130248a5999cd542ec183d
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Jul 19 15:54:38 2016 +0000

    SLING-5842, SLING-5843 - implement the register namespace and nodetype operations in the jcr.repoinit module
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1753399 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/jcr/repoinit/impl/DoNothingVisitor.java  | 87 ++++++++++++++++++++++
 .../repoinit/impl/JcrRepoInitOpsProcessorImpl.java | 19 ++++-
 .../sling/jcr/repoinit/impl/NamespacesVisitor.java | 48 ++++++++++++
 .../sling/jcr/repoinit/impl/NodetypesVisitor.java  | 49 ++++++++++++
 ...ationVisitor.java => ServiceAndAclVisitor.java} | 29 ++------
 .../sling/jcr/repoinit/ExecutionOrderTest.java     | 71 ++++++++++++++++++
 .../sling/jcr/repoinit/RegisterNamespacesTest.java | 70 +++++++++++++++++
 .../sling/jcr/repoinit/RegisterNodetypesTest.java  | 69 +++++++++++++++++
 .../apache/sling/jcr/repoinit/impl/TestUtil.java   | 27 ++++++-
 9 files changed, 440 insertions(+), 29 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/DoNothingVisitor.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/DoNothingVisitor.java
new file mode 100644
index 0000000..3c4d08c
--- /dev/null
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/DoNothingVisitor.java
@@ -0,0 +1,87 @@
+/*
+ * 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.jcr.repoinit.impl;
+
+import javax.jcr.Session;
+
+import org.apache.sling.repoinit.parser.operations.CreatePath;
+import org.apache.sling.repoinit.parser.operations.CreateServiceUser;
+import org.apache.sling.repoinit.parser.operations.DeleteServiceUser;
+import org.apache.sling.repoinit.parser.operations.OperationVisitor;
+import org.apache.sling.repoinit.parser.operations.RegisterNamespace;
+import org.apache.sling.repoinit.parser.operations.RegisterNodetypes;
+import org.apache.sling.repoinit.parser.operations.SetAclPaths;
+import org.apache.sling.repoinit.parser.operations.SetAclPrincipals;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Base class for specialized OperationVisitors.
+ */
+class DoNothingVisitor implements OperationVisitor {
+
+    protected final Logger log = LoggerFactory.getLogger(getClass());
+    
+    protected final Session session;
+    
+    /** Create a visitor using the supplied JCR Session.
+     * @param s must have sufficient rights to create users
+     *      and set ACLs.
+     */
+    protected DoNothingVisitor(Session s) {
+        session = s;
+    }
+    
+    protected void report(Exception e, String message) {
+        throw new RuntimeException(message, e);
+    }
+    
+    protected static String excerpt(String s, int maxLength) {
+        if(s.length() < maxLength) {
+            return s;
+        } else {
+            return s.substring(0, maxLength -1) + "...";
+        }
+    }
+    
+    @Override
+    public void visitCreateServiceUser(CreateServiceUser s) {
+    }
+
+    @Override
+    public void visitDeleteServiceUser(DeleteServiceUser s) {
+    }
+
+    @Override
+    public void visitSetAclPrincipal(SetAclPrincipals s) {
+     }
+
+    @Override
+    public void visitSetAclPaths(SetAclPaths s) {
+    }
+
+    @Override
+    public void visitCreatePath(CreatePath cp) {
+    }
+
+    @Override
+    public void visitRegisterNamespace(RegisterNamespace rn) {
+    }
+
+    @Override
+    public void visitRegisterNodetypes(RegisterNodetypes rn) {
+    }
+}
diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java
index 4b633d2..bcf96b7 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java
@@ -24,15 +24,28 @@ import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.jcr.repoinit.JcrRepoInitOpsProcessor;
 import org.apache.sling.repoinit.parser.operations.Operation;
+import org.apache.sling.repoinit.parser.operations.OperationVisitor;
 
 /** Apply Operations produced by the repoinit parser to a JCR Repository */
 @Component
 @Service(JcrRepoInitOpsProcessor.class)
 public class JcrRepoInitOpsProcessorImpl implements JcrRepoInitOpsProcessor {
+    
+    /** Apply the supplied operations: first the namespaces and nodetypes
+     *  registrations, then the service users, paths and ACLs.
+     */
     public void apply(Session session, List<Operation> ops) {
-        final JcrRepoInitOperationVisitor v = new JcrRepoInitOperationVisitor(session);
-        for(Operation op : ops) {
-            op.accept(v);
+        
+        final OperationVisitor [] visitors = {
+                new NamespacesVisitor(session),
+                new NodetypesVisitor(session),
+                new ServiceAndAclVisitor(session)
+        };
+        
+        for(OperationVisitor v : visitors) {
+            for(Operation op : ops) {
+                op.accept(v);
+            }
         }
     }
 }
diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/NamespacesVisitor.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/NamespacesVisitor.java
new file mode 100644
index 0000000..b4d0ebb
--- /dev/null
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/NamespacesVisitor.java
@@ -0,0 +1,48 @@
+/*
+ * 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.jcr.repoinit.impl;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.Session;
+
+import org.apache.sling.repoinit.parser.operations.RegisterNamespace;
+
+/** OperationVisitor which processes only operations related to
+ *  namespaces and nodetypes. Having several such specialized visitors 
+ *  makes it easy to control the execution order.
+ */
+class NamespacesVisitor extends DoNothingVisitor {
+
+    /** Create a visitor using the supplied JCR Session.
+     * @param s must have sufficient rights to create users
+     *      and set ACLs.
+     */
+    public NamespacesVisitor(Session s) {
+        super(s);
+    }
+    
+    @Override
+    public void visitRegisterNamespace(RegisterNamespace rn) {
+        try {
+            final NamespaceRegistry reg = session.getWorkspace().getNamespaceRegistry();
+            log.info("Registering namespace from {}", rn);
+            reg.registerNamespace(rn.getPrefix(), rn.getURI());
+        } catch(Exception e) {
+            report(e, "Unable to register namespace from " + rn);
+        }
+    }
+}
diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/NodetypesVisitor.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/NodetypesVisitor.java
new file mode 100644
index 0000000..e1a4534
--- /dev/null
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/NodetypesVisitor.java
@@ -0,0 +1,49 @@
+/*
+ * 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.jcr.repoinit.impl;
+
+import java.io.StringReader;
+
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.commons.cnd.CndImporter;
+import org.apache.sling.repoinit.parser.operations.RegisterNodetypes;
+
+/** OperationVisitor which processes only operations related to
+ *  namespaces and nodetypes. Having several such specialized visitors 
+ *  makes it easy to control the execution order.
+ */
+class NodetypesVisitor extends DoNothingVisitor {
+
+    /** Create a visitor using the supplied JCR Session.
+     * @param s must have sufficient rights to create users
+     *      and set ACLs.
+     */
+    public NodetypesVisitor(Session s) {
+        super(s);
+    }
+    
+    @Override
+    public void visitRegisterNodetypes(RegisterNodetypes rn) {
+        try {
+            log.info("Registering nodetypes from {}", excerpt(rn.getCndStatements(), 100));
+            CndImporter.registerNodeTypes(new StringReader(rn.getCndStatements()), session);
+        } catch(Exception e) {
+            report(e, "Unable to register nodetypes from " + rn);
+        }
+    }
+}
diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/ServiceAndAclVisitor.java
similarity index 88%
rename from src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java
rename to src/main/java/org/apache/sling/jcr/repoinit/impl/ServiceAndAclVisitor.java
index 53a2af5..4d71c6b 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/ServiceAndAclVisitor.java
@@ -38,23 +38,18 @@ import org.apache.sling.repoinit.parser.operations.SetAclPrincipals;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/** JCR visitor for the Operations produced by the repoinit parser */
-class JcrRepoInitOperationVisitor implements OperationVisitor {
+/** OperationVisitor which processes only operations related to
+ *  service users and ACLs. Having several such specialized visitors 
+ *  makes it easy to control the execution order. 
+ */
+class ServiceAndAclVisitor extends DoNothingVisitor {
 
-    private final Logger log = LoggerFactory.getLogger(getClass());
-    
-    private Session session;
-    
     /** Create a visitor using the supplied JCR Session.
      * @param s must have sufficient rights to create users
      *      and set ACLs.
      */
-    public JcrRepoInitOperationVisitor(Session s) {
-        session = s;
-    }
-    
-    private void report(Exception e, String message) {
-        throw new RuntimeException(message, e);
+    public ServiceAndAclVisitor(Session s) {
+        super(s);
     }
     
     @Override
@@ -141,14 +136,4 @@ class JcrRepoInitOperationVisitor implements OperationVisitor {
             throw new RuntimeException("Session.save failed: "+ e, e);
         }
     }
-
-    @Override
-    public void visitRegisterNamespace(RegisterNamespace rn) {
-        throw new UnsupportedOperationException(rn.toString());
-    }
-
-    @Override
-    public void visitRegisterNodetypes(RegisterNodetypes b) {
-        throw new UnsupportedOperationException(b.getClass().getName());
-    }
 }
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/ExecutionOrderTest.java b/src/test/java/org/apache/sling/jcr/repoinit/ExecutionOrderTest.java
new file mode 100644
index 0000000..0369d88
--- /dev/null
+++ b/src/test/java/org/apache/sling/jcr/repoinit/ExecutionOrderTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.jcr.repoinit;
+
+import static org.junit.Assert.assertEquals;
+import java.util.UUID;
+
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+
+import org.apache.sling.jcr.repoinit.impl.TestUtil;
+import org.apache.sling.repoinit.parser.RepoInitParsingException;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/** Verify that namespaces and nodetypes are executed before path creation */
+public class ExecutionOrderTest {
+
+    @Rule
+    public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
+    
+    private TestUtil U;
+    
+    private static final String TEST_ID = UUID.randomUUID().toString();
+    private static final String NS_PREFIX = ExecutionOrderTest.class.getSimpleName();
+    private static final String NS_URI = "uri:" + NS_PREFIX + ":" + TEST_ID;
+    private static final String REL_PATH = ExecutionOrderTest.class.getSimpleName() + "-" + TEST_ID;
+    
+    @Before
+    public void setup() throws RepositoryException, RepoInitParsingException {
+        U = new TestUtil(context);
+        
+        final String stmt = 
+            "create path (" + NS_PREFIX + ":foo) /" + REL_PATH + "\n"
+            + U.getTestCndStatement(NS_PREFIX, NS_URI) + "\n"
+            + "register namespace (" + NS_PREFIX + ") " + NS_URI + "\n";
+        ;
+        
+        U.parseAndExecute(stmt);
+    }
+
+    @After
+    public void cleanup() throws RepositoryException, RepoInitParsingException {
+        U.cleanup();
+    }
+    
+    @Test
+    public void pathCreated() throws PathNotFoundException, RepositoryException {
+        final Node n = U.getAdminSession().getNode("/" + REL_PATH);
+        assertEquals(NS_PREFIX + ":foo", n.getProperty("jcr:primaryType").getString());
+    }
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/RegisterNamespacesTest.java b/src/test/java/org/apache/sling/jcr/repoinit/RegisterNamespacesTest.java
new file mode 100644
index 0000000..03d1df9
--- /dev/null
+++ b/src/test/java/org/apache/sling/jcr/repoinit/RegisterNamespacesTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.jcr.repoinit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.UUID;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+
+import org.apache.sling.jcr.repoinit.impl.TestUtil;
+import org.apache.sling.repoinit.parser.RepoInitParsingException;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/** Test register namespace statements */
+public class RegisterNamespacesTest {
+
+    @Rule
+    public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
+    
+    private TestUtil U;
+    private NamespaceRegistry ns;
+    
+    private static final String TEST_ID = UUID.randomUUID().toString();
+    private static final String NS1 = "uri:ns:test1:" + TEST_ID;
+    private static final String NS2 = "http://example.com/ns/" + TEST_ID;
+   
+    @Before
+    public void setup() throws RepositoryException, RepoInitParsingException {
+        U = new TestUtil(context);
+        U.parseAndExecute("register namespace (one) " + NS1);
+        U.parseAndExecute("register namespace (two) " + NS2);
+        ns = U.getAdminSession().getWorkspace().getNamespaceRegistry();
+    }
+
+    @After
+    public void cleanup() throws RepositoryException, RepoInitParsingException {
+        U.cleanup();
+    }
+    
+    @Test
+    public void NS1registered() throws Exception {
+        assertEquals(NS1, ns.getURI("one"));
+    }
+    
+    @Test
+    public void NS2registered() throws Exception {
+        assertEquals(NS2, ns.getURI("two"));
+    }
+}
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/RegisterNodetypesTest.java b/src/test/java/org/apache/sling/jcr/repoinit/RegisterNodetypesTest.java
new file mode 100644
index 0000000..8b652d1
--- /dev/null
+++ b/src/test/java/org/apache/sling/jcr/repoinit/RegisterNodetypesTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.jcr.repoinit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.UUID;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+
+import org.apache.sling.jcr.repoinit.impl.TestUtil;
+import org.apache.sling.repoinit.parser.RepoInitParsingException;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/** Test register nodetypes statements. Also registers a namespace */
+public class RegisterNodetypesTest {
+
+    @Rule
+    public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
+    
+    private TestUtil U;
+    
+    private static final String TEST_ID = UUID.randomUUID().toString();
+    private static final String NS_PREFIX = RegisterNodetypesTest.class.getSimpleName();
+    private static final String NS_URI = "uri:" + NS_PREFIX + ":" + TEST_ID;
+    
+    @Before
+    public void setup() throws RepositoryException, RepoInitParsingException {
+        U = new TestUtil(context);
+        U.parseAndExecute("register namespace (" + NS_PREFIX + ") " + NS_URI);
+        U.parseAndExecute(U.getTestCndStatement(NS_PREFIX, NS_URI));
+    }
+
+    @After
+    public void cleanup() throws RepositoryException, RepoInitParsingException {
+        U.cleanup();
+    }
+    
+    @Test
+    public void NSregistered() throws Exception {
+        final NamespaceRegistry ns = U.getAdminSession().getWorkspace().getNamespaceRegistry();
+        assertEquals(NS_URI, ns.getURI(NS_PREFIX));
+    }
+    
+    @Test
+    public void fooNodetypeRegistered() throws Exception {
+        U.getAdminSession().getRootNode().addNode("test_" + TEST_ID, NS_PREFIX + ":foo");
+    }
+ }
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java b/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java
index 2561ad1..615e5db 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java
@@ -93,10 +93,8 @@ public class TestUtil {
     }
     
     public void parseAndExecute(String input) throws RepositoryException, RepoInitParsingException {
-        final JcrRepoInitOperationVisitor v = new JcrRepoInitOperationVisitor(adminSession);
-        for(Operation o : parse(input)) {
-            o.accept(v);
-        }
+        final JcrRepoInitOpsProcessorImpl p = new JcrRepoInitOpsProcessorImpl();
+        p.apply(adminSession, parse(input));
         adminSession.save();
     }
     
@@ -109,4 +107,25 @@ public class TestUtil {
         final SimpleCredentials cred = new SimpleCredentials(serviceUsername, new char[0]);
         return adminSession.impersonate(cred);
     }
+    
+    public Session getAdminSession() {
+        return adminSession;
+    }
+    
+    public void cleanup() {
+        adminSession.logout();
+    }
+    
+    public String getTestCndStatement(String nsPrefix, String nsURI) throws RepositoryException, RepoInitParsingException {
+        return "register nodetypes\n"
+                + "<<===\n"
+                + getTestCND(nsPrefix, nsURI)
+                + "===>>\n"
+        ;
+    }
+    
+    public String getTestCND(String nsPrefix, String nsURI) {
+        return "<" + nsPrefix + "='" + nsURI + "'>\n"
+                + "[" + nsPrefix + ":foo] > nt:unstructured\n";
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 16/17: [maven-release-plugin] prepare release org.apache.sling.jcr.repoinit-1.0.2

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit 83ea12f1aabd526d76b49a306bd2de2858c769a4
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Aug 22 16:22:20 2016 +0000

    [maven-release-plugin] prepare release org.apache.sling.jcr.repoinit-1.0.2
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1757225 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 22bd5b1..48c779b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
 
   <artifactId>org.apache.sling.jcr.repoinit</artifactId>
   <packaging>bundle</packaging>
-  <version>1.0.1-SNAPSHOT</version>
+  <version>1.0.2</version>
   <name>Apache Sling RepoInit JCR module</name>
   <description>
 	  Initializes a JCR repository based on the output
@@ -41,9 +41,9 @@
   </properties>
 
   <scm>
-    <connection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit</developerConnection>
-    <url>https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit</url>
+    <connection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.jcr.repoinit-1.0.2</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.jcr.repoinit-1.0.2</developerConnection>
+    <url>https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.jcr.repoinit-1.0.2</url>
   </scm>
   
   <build>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 13/17: SLING-5943 - better config metadata + logging

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit ed70824c2192e932e24a7f54365b32ddb96c734c
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Aug 2 14:16:38 2016 +0000

    SLING-5943 - better config metadata + logging
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1754936 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/jcr/repoinit/impl/RepositoryInitializer.java       | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
index 0c6475f..9b5c686 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
@@ -33,6 +33,7 @@ import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Properties;
 import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyOption;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.commons.osgi.PropertiesUtil;
@@ -69,8 +70,7 @@ public class RepositoryInitializer implements SlingRepositoryInitializer {
     
     @Property(
             label="Text URL", 
-            description="URL of the source text that provides repoinit statements."
-                + " That text is processed according to the model section name parameter.", 
+            description="URL of the source text that provides repoinit statements.",
             value=DEFAULT_TEXT_URL)
     public static final String PROP_TEXT_URL = "text.url";
     private String textURL;
@@ -92,7 +92,11 @@ public class RepositoryInitializer implements SlingRepositoryInitializer {
                 "The format to use to interpret the text provided by the configured source text URL. "
                 + "That text can be either a Sling provisioning model with repoinit statements embedded in additional sections,"
                 + " or raw repoinit statements",
-            value=DEFAULT_MODEL_SECTION_NAME)
+            options = {
+                    @PropertyOption(name = "MODEL", value = "Provisioning Model (MODEL)"),
+                    @PropertyOption(name = "RAW", value = "Raw Repoinit statements (RAW)")
+                },                
+            value="MODEL")
     public static final String PROP_TEXT_FORMAT = "text.format";
     public static enum TextFormat { RAW, MODEL };
     private TextFormat textFormat;
@@ -184,7 +188,7 @@ public class RepositoryInitializer implements SlingRepositoryInitializer {
             log.info("Parsing raw repoinit statements from {}", textURL);
             return rawText;
         } else {
-            log.info("Extracting repoinit statements from section '{}' of provisioning model {}", modelSectionName, textURL);
+            log.info("Extracting repoinit statements from section ':{}' of provisioning model {}", modelSectionName, textURL);
             final StringReader reader = new StringReader(rawText);
             try {
                 final Model model = ModelReader.read(reader, textURL);

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 04/17: SLING-5842 - add 'register nodetypes' statement to repoinit parser

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit 0eb0707f55227a73b74218b94f9670ca38adeeaf
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Jul 18 15:08:18 2016 +0000

    SLING-5842 - add 'register nodetypes' statement to repoinit parser
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1753237 13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java
index 6c032db..53a2af5 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java
@@ -32,6 +32,7 @@ import org.apache.sling.repoinit.parser.operations.DeleteServiceUser;
 import org.apache.sling.repoinit.parser.operations.OperationVisitor;
 import org.apache.sling.repoinit.parser.operations.PathSegmentDefinition;
 import org.apache.sling.repoinit.parser.operations.RegisterNamespace;
+import org.apache.sling.repoinit.parser.operations.RegisterNodetypes;
 import org.apache.sling.repoinit.parser.operations.SetAclPaths;
 import org.apache.sling.repoinit.parser.operations.SetAclPrincipals;
 import org.slf4j.Logger;
@@ -145,4 +146,9 @@ class JcrRepoInitOperationVisitor implements OperationVisitor {
     public void visitRegisterNamespace(RegisterNamespace rn) {
         throw new UnsupportedOperationException(rn.toString());
     }
+
+    @Override
+    public void visitRegisterNodetypes(RegisterNodetypes b) {
+        throw new UnsupportedOperationException(b.getClass().getName());
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 08/17: SLING-5917 - add RepositoryInitializer tests

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit 35302c8c2ea1e782bb7869eeed343a8d4a340f3b
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Jul 29 09:33:32 2016 +0000

    SLING-5917 - add RepositoryInitializer tests
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1754490 13f79535-47bb-0310-9956-ffa450edef68
---
 .../jcr/repoinit/RepositoryInitializerTest.java    | 129 +++++++++++++++++++++
 1 file changed, 129 insertions(+)

diff --git a/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java b/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java
new file mode 100644
index 0000000..8350af6
--- /dev/null
+++ b/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java
@@ -0,0 +1,129 @@
+/*
+ * 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.jcr.repoinit;
+
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.jcr.Session;
+
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.jcr.repoinit.impl.JcrRepoInitOpsProcessorImpl;
+import org.apache.sling.jcr.repoinit.impl.RepositoryInitializer;
+import org.apache.sling.jcr.repoinit.impl.TestUtil;
+import org.apache.sling.repoinit.parser.impl.RepoInitParserService;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/** Test the two ways in which our RepositoryInitializer
+ *  can read repoinit statements: either from a provisioning
+ *  model file or directly as raw repoinit statements. 
+ */
+@RunWith(Parameterized.class)
+public class RepositoryInitializerTest {
+    
+    @Rule
+    public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
+    
+    private RepositoryInitializer initializer;
+    private Map<String, Object> config;
+    private TestUtil U;
+    private final String repoInitText;
+    private final String url;
+    private final String modelSection;
+    private final boolean testLogin;
+    private final String serviceUser;
+    
+    @Parameters(name="{0}")
+    public static Collection<Object[]> data() {
+        final List<Object []> result = new ArrayList<Object[]>();
+        
+        result.add(new Object[] { "All empty, just setup + parsing", "", false });
+        result.add(new Object[] { "Using provisioning model", "SECTION_" + UUID.randomUUID(), true }); 
+        result.add(new Object[] { "Raw repoinit/empty section", "", true}); 
+        result.add(new Object[] { "Raw repoinit/null section", "", true}); 
+        return result;
+    }
+    
+    public RepositoryInitializerTest(String description, String modelSection, boolean testLogin) throws IOException {
+        serviceUser = getClass().getSimpleName() + "-" + UUID.randomUUID();
+        
+        String txt = "create service user " + serviceUser; 
+        if(modelSection != null && modelSection.length() > 0) {
+            txt = "[feature name=foo]\n[:" + modelSection + "]\n" + txt; 
+        }
+        this.repoInitText = txt + "\n";
+        this.url = getTestUrl(repoInitText);
+        this.modelSection = modelSection;
+        this.testLogin = testLogin;
+    }
+    
+    @Before
+    public void setup() throws Exception {
+        U = new TestUtil(context);
+
+        initializer = new RepositoryInitializer();
+        config = new HashMap<String, Object>();
+        config.put(RepositoryInitializer.PROP_TEXT_URL, url);
+        config.put(RepositoryInitializer.PROP_MODEL_SECTION_NAME, modelSection);
+        initializer.activate(config);
+        
+        context.registerInjectActivateService(new RepoInitParserService());
+        context.registerInjectActivateService(new JcrRepoInitOpsProcessorImpl());
+        context.registerInjectActivateService(initializer, config);
+        
+        // Mock environment doesn't cause this to be called
+        initializer.processRepository(context.getService(SlingRepository.class));
+    }
+    
+    @Test
+    public void testLogin() throws Exception {
+        if(testLogin) {
+            try {
+                U.loginService(serviceUser);
+            } catch(Exception e) {
+                fail("Login failed for " + serviceUser + " repoinit statements (" + repoInitText + ") not applied?");
+            }
+        }
+    }
+    
+    /** Return the URL of a temporary file that contains repoInitText */
+    private String getTestUrl(String repoInitText) throws IOException {
+        final File tmpFile = File.createTempFile(getClass().getSimpleName(), "txt");
+        tmpFile.deleteOnExit();
+        final FileWriter w = new FileWriter(tmpFile);
+        w.write(repoInitText);
+        w.flush();
+        w.close();
+        return "file://" + tmpFile.getAbsolutePath();
+    }
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 03/17: SLING-5843 - add 'register namespace' statement to repoinit parser

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit 2c3076eeab7537305fe2555081d74ce5eb542984
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Jul 18 08:50:04 2016 +0000

    SLING-5843 - add 'register namespace' statement to repoinit parser
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1753177 13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java
index 153ff40..6c032db 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java
@@ -31,6 +31,7 @@ import org.apache.sling.repoinit.parser.operations.CreateServiceUser;
 import org.apache.sling.repoinit.parser.operations.DeleteServiceUser;
 import org.apache.sling.repoinit.parser.operations.OperationVisitor;
 import org.apache.sling.repoinit.parser.operations.PathSegmentDefinition;
+import org.apache.sling.repoinit.parser.operations.RegisterNamespace;
 import org.apache.sling.repoinit.parser.operations.SetAclPaths;
 import org.apache.sling.repoinit.parser.operations.SetAclPrincipals;
 import org.slf4j.Logger;
@@ -139,4 +140,9 @@ class JcrRepoInitOperationVisitor implements OperationVisitor {
             throw new RuntimeException("Session.save failed: "+ e, e);
         }
     }
+
+    @Override
+    public void visitRegisterNamespace(RegisterNamespace rn) {
+        throw new UnsupportedOperationException(rn.toString());
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 17/17: [maven-release-plugin] copy for tag org.apache.sling.jcr.repoinit-1.0.2

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit dec91bd31a46b93382e67cc46dd460607615dfa5
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Aug 22 16:22:34 2016 +0000

    [maven-release-plugin] copy for tag org.apache.sling.jcr.repoinit-1.0.2
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.jcr.repoinit-1.0.2@1757226 13f79535-47bb-0310-9956-ffa450edef68

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 01/17: [maven-release-plugin] prepare for next development iteration

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit 370808ab940a5f60dc52c7570046cd1c2a21a6e9
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Wed Jul 6 09:09:34 2016 +0000

    [maven-release-plugin] prepare for next development iteration
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/repoinit/jcr@1751639 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 6c2556a..6ad25f3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
 
   <artifactId>org.apache.sling.jcr.repoinit</artifactId>
   <packaging>bundle</packaging>
-  <version>1.0.0</version>
+  <version>1.0.1-SNAPSHOT</version>
   <name>Apache Sling RepoInit JCR module</name>
   <description>
 	  Initializes a JCR repository based on the output
@@ -41,9 +41,9 @@
   </properties>
 
   <scm>
-    <connection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.jcr.repoinit-1.0.0</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.jcr.repoinit-1.0.0</developerConnection>
-    <url>https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.jcr.repoinit-1.0.0</url>
+    <connection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/repoinit/jcr</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/repoinit/jcr</developerConnection>
+    <url>https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/repoinit/jcr</url>
   </scm>
   
   <build>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 12/17: SLING-5943 - support explicit format in RepositoryInitializer configuration

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit 3581dbbe4fb3d339e734fc7432d8d774a722ec51
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Aug 2 13:45:35 2016 +0000

    SLING-5943 - support explicit format in RepositoryInitializer configuration
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1754918 13f79535-47bb-0310-9956-ffa450edef68
---
 .../jcr/repoinit/impl/RepositoryInitializer.java   | 58 ++++++++++++++++++----
 .../jcr/repoinit/RepositoryInitializerTest.java    | 47 ++++++++++++++----
 2 files changed, 86 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
index 5c83c90..0c6475f 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
@@ -22,6 +22,7 @@ import java.io.StringReader;
 import java.io.StringWriter;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -66,10 +67,6 @@ public class RepositoryInitializer implements SlingRepositoryInitializer {
 
     public static final String DEFAULT_TEXT_URL = "context:/resources/provisioning/model.txt";
     
-    /** Special value for model section name config parameter, which indicates that
-     *  the configured URL provides raw repoinit statements */ 
-    public static final String RAW_SECTION_MARKER = "<RAW>";
-    
     @Property(
             label="Text URL", 
             description="URL of the source text that provides repoinit statements."
@@ -83,13 +80,23 @@ public class RepositoryInitializer implements SlingRepositoryInitializer {
     @Property(
             label="Model section name", 
             description=
-                "Optional provisioning model additional section name (without leading colon) used to extract"
-                + " repoinit statements from the raw text provided by the configured source text URL. Leave empty or set to <RAW> to consider the content"
-                + " provided by that URL to already be in repoinit format", 
+                "If using the provisioning model format, this specifies the additional section name (without leading colon) used to extract"
+                + " repoinit statements from the raw text provided by the configured source text URL.",
             value=DEFAULT_MODEL_SECTION_NAME)
     public static final String PROP_MODEL_SECTION_NAME = "model.section.name";
     private String modelSectionName;
     
+    @Property(
+            label="Text format", 
+            description=
+                "The format to use to interpret the text provided by the configured source text URL. "
+                + "That text can be either a Sling provisioning model with repoinit statements embedded in additional sections,"
+                + " or raw repoinit statements",
+            value=DEFAULT_MODEL_SECTION_NAME)
+    public static final String PROP_TEXT_FORMAT = "text.format";
+    public static enum TextFormat { RAW, MODEL };
+    private TextFormat textFormat;
+    
     @Reference
     private RepoInitParser parser;
     
@@ -99,13 +106,44 @@ public class RepositoryInitializer implements SlingRepositoryInitializer {
     @Activate
     public void activate(Map<String, Object> config) {
         textURL = PropertiesUtil.toString(config.get(PROP_TEXT_URL), DEFAULT_TEXT_URL);
+        
+        final String fmt = PropertiesUtil.toString(config.get(PROP_TEXT_FORMAT), TextFormat.MODEL.toString());
+        try {
+            textFormat = TextFormat.valueOf(fmt);
+        } catch(Exception e) {
+            throw new IllegalArgumentException("Invalid text format '" + fmt + "',"
+                    + " valid values are " + Arrays.asList(TextFormat.values()));
+        }
+        
         modelSectionName = PropertiesUtil.toString(config.get(PROP_MODEL_SECTION_NAME), DEFAULT_MODEL_SECTION_NAME);
+        
+        log.debug("Activated: {}", this.toString());
+    }
+    
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName()).append(": ");
+        sb.append(PROP_TEXT_URL).append("=").append(textURL).append(", ");
+        sb.append(PROP_TEXT_FORMAT).append("=").append(textFormat).append(", ");
+        sb.append(PROP_MODEL_SECTION_NAME).append("=").append(modelSectionName);
+        return sb.toString();
     }
     
     @Override
     public void processRepository(SlingRepository repo) throws Exception {
         final String repoinit = getRepoInitText();
         
+        if(TextFormat.MODEL.equals(textFormat)) {
+            if(modelSectionName == null) {
+                throw new IllegalStateException("Section name is null, cannot read model");
+            }
+            if(modelSectionName.trim().length() == 0) {
+                throw new IllegalStateException("Empty " + PROP_MODEL_SECTION_NAME + " is not supported anymore, please use " 
+                        + PROP_TEXT_FORMAT + " to specify the input text format");
+            }
+        }
+        
         // loginAdministrative is ok here, definitely an admin operation
         final Session s = repo.loginAdministrative(null);
         try {
@@ -142,8 +180,7 @@ public class RepositoryInitializer implements SlingRepositoryInitializer {
         final String rawText = getRawRepoInitText();
         log.debug("Raw text from {}: \n{}", textURL, rawText);
         log.info("Got {} characters from {}", rawText.length(), textURL);
-        final boolean parseRawText = modelSectionName.trim().length() == 0 || RAW_SECTION_MARKER.equals(modelSectionName);
-        if (parseRawText) {
+        if(TextFormat.RAW.equals(textFormat)) {
             log.info("Parsing raw repoinit statements from {}", textURL);
             return rawText;
         } else {
@@ -152,6 +189,9 @@ public class RepositoryInitializer implements SlingRepositoryInitializer {
             try {
                 final Model model = ModelReader.read(reader, textURL);
                 final StringBuilder sb = new StringBuilder();
+                if(modelSectionName == null) {
+                    throw new IllegalStateException("Model section name is null, cannot read model");
+                }
                 for (final Feature feature : model.getFeatures()) {
                     for (final Section section : feature.getAdditionalSections(modelSectionName)) {
                         sb.append("# ").append(modelSectionName).append(" from ").append(feature.getName()).append("\n");
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java b/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java
index 4c977a3..4081050 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sling.jcr.repoinit;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
 import java.io.File;
@@ -31,6 +32,7 @@ import java.util.UUID;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.repoinit.impl.JcrRepoInitOpsProcessorImpl;
 import org.apache.sling.jcr.repoinit.impl.RepositoryInitializer;
+import org.apache.sling.jcr.repoinit.impl.RepositoryInitializer.TextFormat;
 import org.apache.sling.jcr.repoinit.impl.TestUtil;
 import org.apache.sling.repoinit.parser.impl.RepoInitParserService;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
@@ -58,22 +60,33 @@ public class RepositoryInitializerTest {
     private final String repoInitText;
     private final String url;
     private final String modelSection;
+    private final String textFormat;
     private final boolean testLogin;
     private final String serviceUser;
+    private final Class<?> expectedActivateException;
     
     @Parameters(name="{0}")
     public static Collection<Object[]> data() {
         final List<Object []> result = new ArrayList<Object[]>();
         
-        result.add(new Object[] { "All empty, just setup + parsing", "", false, false });
-        result.add(new Object[] { "Using provisioning model", "SECTION_" + UUID.randomUUID(), true, true }); 
-        result.add(new Object[] { "Raw repoinit/empty section", "", false, true}); 
-        result.add(new Object[] { "Raw repoinit/special section name", "<RAW>", false, true}); 
-        result.add(new Object[] { "Default value of model section config", null, true, true}); 
+        // Realistic cases
+        result.add(new Object[] { "Using provisioning model", "SECTION_" + UUID.randomUUID(), TextFormat.MODEL.toString(), true, true, null }); 
+        result.add(new Object[] { "Default value of model section config", null, TextFormat.MODEL.toString(), true, true, null });
+        result.add(new Object[] { "Raw repoinit/empty section", "", TextFormat.RAW.toString(), false, true, null }); 
+        result.add(new Object[] { "Raw repoinit/ignored section name", "IGNORED_SectionName", TextFormat.RAW.toString(), false, true, null }); 
+        
+        // Edge and failure cases 
+        result.add(new Object[] { "All empty, just setup + parsing", "", TextFormat.RAW.toString(), false, false, null });
+        result.add(new Object[] { "Raw repoinit/null format", null, null, true, false, RuntimeException.class });
+        result.add(new Object[] { "With model/null format", null, null, false, false, RuntimeException.class });
+        result.add(new Object[] { "Invalid format", null, "invalidFormat", false, false, RuntimeException.class }); 
+        result.add(new Object[] { "Empty model section", "", TextFormat.MODEL.toString(), false, false, IllegalStateException.class }); 
+        result.add(new Object[] { "Null model section", null, TextFormat.MODEL.toString(), false, false, IllegalStateException.class }); 
         return result;
     }
     
-    public RepositoryInitializerTest(String description, String modelSection, boolean useProvisioningModel, boolean testLogin) throws IOException {
+    public RepositoryInitializerTest(String description, String modelSection, String textFormat, 
+            boolean useProvisioningModel, boolean testLogin, Class<?> expectedException) throws IOException {
         serviceUser = getClass().getSimpleName() + "-" + UUID.randomUUID();
         
         String txt = "create service user " + serviceUser; 
@@ -86,6 +99,8 @@ public class RepositoryInitializerTest {
         this.url = getTestUrl(repoInitText);
         this.modelSection = modelSection;
         this.testLogin = testLogin;
+        this.textFormat = textFormat;
+        this.expectedActivateException = expectedException;
     }
     
     @Before
@@ -98,14 +113,26 @@ public class RepositoryInitializerTest {
         if(modelSection != null) {
             config.put(RepositoryInitializer.PROP_MODEL_SECTION_NAME, modelSection);
         }
-        initializer.activate(config);
+        if(textFormat != null) {
+            config.put(RepositoryInitializer.PROP_TEXT_FORMAT, textFormat);
+        }
         
         context.registerInjectActivateService(new RepoInitParserService());
         context.registerInjectActivateService(new JcrRepoInitOpsProcessorImpl());
-        context.registerInjectActivateService(initializer, config);
         
-        // Mock environment doesn't cause this to be called
-        initializer.processRepository(context.getService(SlingRepository.class));
+        try {
+            context.registerInjectActivateService(initializer, config);
+            
+            // Mock environment doesn't cause this to be called
+            initializer.processRepository(context.getService(SlingRepository.class));
+        } catch(Exception e) {
+            if(expectedActivateException != null) {
+                assertEquals(expectedActivateException, e.getClass());
+            } else {
+                fail("Got unexpected " + e.getClass().getName() + " in activation");
+            }
+        }
+        
     }
     
     @Test

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 06/17: SLING-5902 RepositoryInitializer uses name component property instead of label

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit 71c098abe6ca84c94cc8052178f07d822ce5962b
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Tue Jul 26 10:58:04 2016 +0000

    SLING-5902 RepositoryInitializer uses name component property instead of label
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1754107 13f79535-47bb-0310-9956-ffa450edef68
---
 .../java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
index 50e6f41..62a433d 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
@@ -52,7 +52,7 @@ import org.slf4j.LoggerFactory;
  *  from a configurable URL.
  */
 @Component(
-        name="Apache Sling Repository Initializer",
+        label="Apache Sling Repository Initializer",
         description="Initializes the JCR content repository using repoinit statements",
         metatype=true)
 @Service(SlingRepositoryInitializer.class)

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 14/17: SLING-5943 - support multiple model/raw references in RepositoryInitializer configuration

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit 3fa0bab78247d746e44f8ccbc081732e13e764ad
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Aug 16 14:28:28 2016 +0000

    SLING-5943 - support multiple model/raw references in RepositoryInitializer configuration
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1756518 13f79535-47bb-0310-9956-ffa450edef68
---
 .../jcr/repoinit/impl/RepoinitTextProvider.java    | 141 +++++++++++++++++
 .../jcr/repoinit/impl/RepositoryInitializer.java   | 170 +++++----------------
 .../jcr/repoinit/RepositoryInitializerTest.java    |  38 +++--
 .../jcr/repoinit/impl/RepoinitReferenceTest.java   |  91 +++++++++++
 4 files changed, 294 insertions(+), 146 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepoinitTextProvider.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepoinitTextProvider.java
new file mode 100644
index 0000000..7b07636
--- /dev/null
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepoinitTextProvider.java
@@ -0,0 +1,141 @@
+/*
+ * 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.jcr.repoinit.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.sling.provisioning.model.Feature;
+import org.apache.sling.provisioning.model.Model;
+import org.apache.sling.provisioning.model.Section;
+import org.apache.sling.provisioning.model.io.ModelReader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Retrieves repoinit statements from URLs that return either
+ *  raw repoinit text or Sling provisioning models that are parsed
+ *  to extract the repoinit text.
+ *  
+ *  Uses references like
+ *  
+ *  <code>model@repoinit:context:/resources/provisioning/model</code>,
+ *  
+ *  meaning that the supplied context:/ URI returns a provisioning model 
+ *  containing repoinit statements in its "repoinit" additional section, or
+ *    
+ *
+ *  <code>raw:classpath://com.example.sling.repoinit/repoinit.txt</code>
+ *  
+ *  meaning that the supplied classpath: URI returns raw repoinit statements.
+ */
+public class RepoinitTextProvider {
+    public static enum TextFormat { raw, model };
+    private static final String DEFAULT_MODEL_SECTION = "repoinit";
+    
+    public static final Pattern REF_PATTERN = Pattern.compile("([a-z]+)(@([a-zA-Z0-9_-]+))?:(.*)");
+    
+    private Logger log = LoggerFactory.getLogger(getClass());
+    
+    static class Reference {
+        final TextFormat format;
+        final String modelSection;
+        final String url;
+        
+        Reference(String ref) {
+            if(ref == null) {
+                throw new IllegalArgumentException("Null reference");
+            }
+            final Matcher m = REF_PATTERN.matcher(ref);
+            if(!m.matches()) {
+                throw new IllegalArgumentException("Invalid reference '" + ref + "', should match " + REF_PATTERN);
+            }
+            format = TextFormat.valueOf(m.group(1));
+            if(format.equals(TextFormat.raw)) {
+                modelSection = null;
+            } else if(format.equals(TextFormat.model) && m.group(3) == null) {
+                modelSection = DEFAULT_MODEL_SECTION;
+            } else {
+                modelSection = m.group(3);
+            }
+            url = m.group(4);
+        }
+        
+        @Override
+        public String toString() {
+            final StringBuilder sb = new StringBuilder();
+            sb.append(getClass().getSimpleName()).append(":");
+            sb.append("format=").append(format);
+            if(modelSection != null) {
+                sb.append(", model section=").append(modelSection);
+            }
+            sb.append(", URL=").append(url);
+            return sb.toString();
+        }
+    }
+    
+    public String getRepoinitText(String referenceString) throws IOException {
+        final Reference ref = new Reference(referenceString);
+        log.info("Reading repoinit statements from {}", ref);
+        final String rawText = getRawText(ref.url);
+        log.debug("Raw text from {}: \n{}", ref.url, rawText);
+        if(TextFormat.model.equals(ref.format)) {
+            log.debug("Extracting provisioning model section {}", ref.modelSection);
+            return extractFromModel(ref.url, rawText, ref.modelSection); 
+        } else {
+            return rawText;
+        }
+    }
+    
+    private String extractFromModel(String sourceInfo, String rawText, String modelSection) throws IOException {
+        final StringReader reader = new StringReader(rawText);
+        final Model model = ModelReader.read(reader, sourceInfo);
+        final StringBuilder sb = new StringBuilder();
+        if(modelSection == null) {
+            throw new IllegalStateException("Model section name is null, cannot read model");
+        }
+        for (final Feature feature : model.getFeatures()) {
+            for (final Section section : feature.getAdditionalSections(modelSection)) {
+                sb.append("# ").append(modelSection).append(" from ").append(feature.getName()).append("\n");
+                sb.append("# ").append(section.getComment()).append("\n");
+                sb.append(section.getContents()).append("\n");
+            }
+        }
+        return sb.toString();
+    }
+    
+    private String getRawText(String urlString) throws IOException {
+        String result = "";
+        final URL url = new URL(urlString);
+        final URLConnection c = url.openConnection();
+        final InputStream is = c.getInputStream();
+        if(is == null) {
+            log.warn("Cannot get InputStream for {}", url);
+        } else {
+            final StringWriter w = new StringWriter();
+            IOUtils.copy(is, w, "UTF-8");
+            result = w.toString();
+        }
+        return result;
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
index 9b5c686..9dbab2c 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
@@ -16,34 +16,23 @@
  */
 package org.apache.sling.jcr.repoinit.impl;
 
-import java.io.IOException;
-import java.io.InputStream;
 import java.io.StringReader;
-import java.io.StringWriter;
-import java.net.URL;
-import java.net.URLConnection;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
 import javax.jcr.Session;
 
-import org.apache.commons.io.IOUtils;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Properties;
 import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.PropertyOption;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.api.SlingRepositoryInitializer;
 import org.apache.sling.jcr.repoinit.JcrRepoInitOpsProcessor;
-import org.apache.sling.provisioning.model.Feature;
-import org.apache.sling.provisioning.model.Model;
-import org.apache.sling.provisioning.model.Section;
-import org.apache.sling.provisioning.model.io.ModelReader;
 import org.apache.sling.repoinit.parser.RepoInitParser;
 import org.apache.sling.repoinit.parser.operations.Operation;
 import org.osgi.framework.Constants;
@@ -66,40 +55,18 @@ import org.slf4j.LoggerFactory;
 public class RepositoryInitializer implements SlingRepositoryInitializer {
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    public static final String DEFAULT_TEXT_URL = "context:/resources/provisioning/model.txt";
+    public static final String DEFAULT_REFERENCE = "model@repoinit:context:/resources/provisioning/model.txt";
     
     @Property(
-            label="Text URL", 
-            description="URL of the source text that provides repoinit statements.",
-            value=DEFAULT_TEXT_URL)
-    public static final String PROP_TEXT_URL = "text.url";
-    private String textURL;
-    
-    public static final String DEFAULT_MODEL_SECTION_NAME = "repoinit";
-    
-    @Property(
-            label="Model section name", 
-            description=
-                "If using the provisioning model format, this specifies the additional section name (without leading colon) used to extract"
-                + " repoinit statements from the raw text provided by the configured source text URL.",
-            value=DEFAULT_MODEL_SECTION_NAME)
-    public static final String PROP_MODEL_SECTION_NAME = "model.section.name";
-    private String modelSectionName;
-    
-    @Property(
-            label="Text format", 
+            label="Repoinit references", 
             description=
-                "The format to use to interpret the text provided by the configured source text URL. "
-                + "That text can be either a Sling provisioning model with repoinit statements embedded in additional sections,"
-                + " or raw repoinit statements",
-            options = {
-                    @PropertyOption(name = "MODEL", value = "Provisioning Model (MODEL)"),
-                    @PropertyOption(name = "RAW", value = "Raw Repoinit statements (RAW)")
-                },                
-            value="MODEL")
-    public static final String PROP_TEXT_FORMAT = "text.format";
-    public static enum TextFormat { RAW, MODEL };
-    private TextFormat textFormat;
+                 "References to the source text that provides repoinit statements."
+                + " format is either model@repoinit:<provisioning model URL> or raw:<raw URL>"
+            ,
+            cardinality=Integer.MAX_VALUE,
+            value={ DEFAULT_REFERENCE })
+    public static final String PROP_REFERENCES = "references";
+    private String [] references;
     
     @Reference
     private RepoInitParser parser;
@@ -109,106 +76,47 @@ public class RepositoryInitializer implements SlingRepositoryInitializer {
     
     @Activate
     public void activate(Map<String, Object> config) {
-        textURL = PropertiesUtil.toString(config.get(PROP_TEXT_URL), DEFAULT_TEXT_URL);
-        
-        final String fmt = PropertiesUtil.toString(config.get(PROP_TEXT_FORMAT), TextFormat.MODEL.toString());
-        try {
-            textFormat = TextFormat.valueOf(fmt);
-        } catch(Exception e) {
-            throw new IllegalArgumentException("Invalid text format '" + fmt + "',"
-                    + " valid values are " + Arrays.asList(TextFormat.values()));
-        }
-        
-        modelSectionName = PropertiesUtil.toString(config.get(PROP_MODEL_SECTION_NAME), DEFAULT_MODEL_SECTION_NAME);
-        
+        warnForOldConfigParameters(config);
+        references = PropertiesUtil.toStringArray(config.get(PROP_REFERENCES));
         log.debug("Activated: {}", this.toString());
     }
     
+    /** Some config parameters are not used anymore as of V1.0.2, this logs 
+     *  warnings if they are still used.
+     */
+    private void warnForOldConfigParameters(Map<String, Object> config) {
+        final String [] names = {
+                "text.url",
+                "text.format",
+                "model.section.name"
+        };
+        for(String name : names) {
+            if(config.containsKey(name)) {
+                log.warn("Configuration parameter '{}' is not used anymore, will be ignored", name);
+            }
+        }
+        }
+    
     @Override
     public String toString() {
-        final StringBuilder sb = new StringBuilder();
-        sb.append(getClass().getSimpleName()).append(": ");
-        sb.append(PROP_TEXT_URL).append("=").append(textURL).append(", ");
-        sb.append(PROP_TEXT_FORMAT).append("=").append(textFormat).append(", ");
-        sb.append(PROP_MODEL_SECTION_NAME).append("=").append(modelSectionName);
-        return sb.toString();
+        return getClass().getSimpleName() + ", references=" + Arrays.asList(references);
     }
-    
+
     @Override
     public void processRepository(SlingRepository repo) throws Exception {
-        final String repoinit = getRepoInitText();
-        
-        if(TextFormat.MODEL.equals(textFormat)) {
-            if(modelSectionName == null) {
-                throw new IllegalStateException("Section name is null, cannot read model");
-            }
-            if(modelSectionName.trim().length() == 0) {
-                throw new IllegalStateException("Empty " + PROP_MODEL_SECTION_NAME + " is not supported anymore, please use " 
-                        + PROP_TEXT_FORMAT + " to specify the input text format");
-            }
-        }
-        
         // loginAdministrative is ok here, definitely an admin operation
         final Session s = repo.loginAdministrative(null);
         try {
-            final List<Operation> ops = parser.parse(new StringReader(repoinit));
-            log.info("Executing {} repoinit operations", ops.size());
-            processor.apply(s, ops);
-            s.save();
+            final RepoinitTextProvider p = new RepoinitTextProvider();
+            for(String reference : references) {
+                final String repoinitText = p.getRepoinitText(reference);
+                final List<Operation> ops = parser.parse(new StringReader(repoinitText));
+                log.info("Executing {} repoinit operations", ops.size());
+                processor.apply(s, ops);
+                s.save();
+            }
         } finally {
             s.logout();
         }
-    }
-    
-    /** Get the repoinit statements to execute */
-    private String getRawRepoInitText() {
-        String result = "";
-        try {
-            final URL url = new URL(textURL);
-            final URLConnection c = url.openConnection();
-            final InputStream is = c.getInputStream();
-            if(is == null) {
-                log.warn("Cannot get InputStream for {}", url);
-            } else {
-                final StringWriter w = new StringWriter();
-                IOUtils.copy(is, w, "UTF-8");
-                result = w.toString();
-            }
-        } catch(Exception e) {
-            log.warn("Error reading repoinit statements from " + textURL, e);
-        }
-        return result;
-    }
-    
-    private String getRepoInitText() {
-        final String rawText = getRawRepoInitText();
-        log.debug("Raw text from {}: \n{}", textURL, rawText);
-        log.info("Got {} characters from {}", rawText.length(), textURL);
-        if(TextFormat.RAW.equals(textFormat)) {
-            log.info("Parsing raw repoinit statements from {}", textURL);
-            return rawText;
-        } else {
-            log.info("Extracting repoinit statements from section ':{}' of provisioning model {}", modelSectionName, textURL);
-            final StringReader reader = new StringReader(rawText);
-            try {
-                final Model model = ModelReader.read(reader, textURL);
-                final StringBuilder sb = new StringBuilder();
-                if(modelSectionName == null) {
-                    throw new IllegalStateException("Model section name is null, cannot read model");
-                }
-                for (final Feature feature : model.getFeatures()) {
-                    for (final Section section : feature.getAdditionalSections(modelSectionName)) {
-                        sb.append("# ").append(modelSectionName).append(" from ").append(feature.getName()).append("\n");
-                        sb.append("# ").append(section.getComment()).append("\n");
-                        sb.append(section.getContents()).append("\n");
-                    }
-                }
-                return sb.toString();
-            } catch (IOException e) {
-                log.warn("Error parsing provisioning model from " + textURL, e);
-                return "";
-            }
-        }
-    }
-
-}
+    }   
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java b/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java
index 4081050..7167385 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java
@@ -31,9 +31,10 @@ import java.util.UUID;
 
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.repoinit.impl.JcrRepoInitOpsProcessorImpl;
+import org.apache.sling.jcr.repoinit.impl.RepoinitTextProvider.TextFormat;
 import org.apache.sling.jcr.repoinit.impl.RepositoryInitializer;
-import org.apache.sling.jcr.repoinit.impl.RepositoryInitializer.TextFormat;
 import org.apache.sling.jcr.repoinit.impl.TestUtil;
+import org.apache.sling.repoinit.parser.RepoInitParsingException;
 import org.apache.sling.repoinit.parser.impl.RepoInitParserService;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.junit.SlingContext;
@@ -70,18 +71,19 @@ public class RepositoryInitializerTest {
         final List<Object []> result = new ArrayList<Object[]>();
         
         // Realistic cases
-        result.add(new Object[] { "Using provisioning model", "SECTION_" + UUID.randomUUID(), TextFormat.MODEL.toString(), true, true, null }); 
-        result.add(new Object[] { "Default value of model section config", null, TextFormat.MODEL.toString(), true, true, null });
-        result.add(new Object[] { "Raw repoinit/empty section", "", TextFormat.RAW.toString(), false, true, null }); 
-        result.add(new Object[] { "Raw repoinit/ignored section name", "IGNORED_SectionName", TextFormat.RAW.toString(), false, true, null }); 
+        result.add(new Object[] { "Using provisioning model", "SECTION_" + UUID.randomUUID(), TextFormat.model.toString(), true, true, null }); 
+        result.add(new Object[] { "Default value of model section config", null, TextFormat.model.toString(), true, true, null });
+        result.add(new Object[] { "Raw repoinit/empty section", "", TextFormat.raw.toString(), false, true, null }); 
+        result.add(new Object[] { "Raw repoinit/ignored section name", "IGNORED_SectionName", TextFormat.raw.toString(), false, true, null }); 
         
         // Edge and failure cases 
-        result.add(new Object[] { "All empty, just setup + parsing", "", TextFormat.RAW.toString(), false, false, null });
-        result.add(new Object[] { "Raw repoinit/null format", null, null, true, false, RuntimeException.class });
+        result.add(new Object[] { "All empty, just setup + parsing", "", TextFormat.raw.toString(), false, false, null });
+        result.add(new Object[] { "Raw repoinit/null format", null, null, true, false, RepoInitParsingException.class });
         result.add(new Object[] { "With model/null format", null, null, false, false, RuntimeException.class });
         result.add(new Object[] { "Invalid format", null, "invalidFormat", false, false, RuntimeException.class }); 
-        result.add(new Object[] { "Empty model section", "", TextFormat.MODEL.toString(), false, false, IllegalStateException.class }); 
-        result.add(new Object[] { "Null model section", null, TextFormat.MODEL.toString(), false, false, IllegalStateException.class }); 
+        result.add(new Object[] { "Empty model section", "", TextFormat.model.toString(), false, false, IllegalArgumentException.class }); 
+        result.add(new Object[] { "Null model section", null, TextFormat.model.toString(), false, false, IOException.class });
+        
         return result;
     }
     
@@ -109,14 +111,20 @@ public class RepositoryInitializerTest {
 
         initializer = new RepositoryInitializer();
         config = new HashMap<String, Object>();
-        config.put(RepositoryInitializer.PROP_TEXT_URL, url);
-        if(modelSection != null) {
-            config.put(RepositoryInitializer.PROP_MODEL_SECTION_NAME, modelSection);
-        }
-        if(textFormat != null) {
-            config.put(RepositoryInitializer.PROP_TEXT_FORMAT, textFormat);
+        
+        String ref = null;
+        if(TextFormat.model.toString().equals(textFormat)) {
+            if(modelSection != null) {
+                ref = "model@" + modelSection + ":" + url;
+            } else {
+                ref = "model:" + url;
+            }
+        } else {
+            ref = "raw:" + url;
         }
         
+        config.put(RepositoryInitializer.PROP_REFERENCES, new String[] { ref });
+        
         context.registerInjectActivateService(new RepoInitParserService());
         context.registerInjectActivateService(new JcrRepoInitOpsProcessorImpl());
         
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/impl/RepoinitReferenceTest.java b/src/test/java/org/apache/sling/jcr/repoinit/impl/RepoinitReferenceTest.java
new file mode 100644
index 0000000..5b6b775
--- /dev/null
+++ b/src/test/java/org/apache/sling/jcr/repoinit/impl/RepoinitReferenceTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.jcr.repoinit.impl;
+
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertEquals;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.sling.jcr.repoinit.impl.RepoinitTextProvider.Reference;
+import org.apache.sling.jcr.repoinit.impl.RepoinitTextProvider.TextFormat;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/** Test the RepoinitTextProvider references parsing */
+@RunWith(Parameterized.class)
+public class RepoinitReferenceTest {
+    
+    @Parameters(name="{0}")
+    public static Collection<Object[]> data() {
+        final List<Object []> result = new ArrayList<Object[]>();
+        
+        // Valid references
+        result.add(new Object[] { "model@foo:uri:1234", TextFormat.model, "foo", "uri:1234", null }); 
+        result.add(new Object[] { "model:uri:2345", TextFormat.model, "repoinit", "uri:2345", null }); 
+        result.add(new Object[] { "raw:uri:4567", TextFormat.raw , null, "uri:4567", null }); 
+        result.add(new Object[] { "raw:uri@5678", TextFormat.raw, null, "uri@5678", null });
+
+        // Invalid references
+        result.add(new Object[] { "model@foo", null, null, null, IllegalArgumentException.class });
+        result.add(new Object[] { "model#foo:url", TextFormat.model, "repoinit", "url", IllegalArgumentException.class });
+        result.add(new Object[] { "", null, null, null, IllegalArgumentException.class });
+        result.add(new Object[] { null, null, null, null, IllegalArgumentException.class });
+        result.add(new Object[] { "foo:url", null, null, null, IllegalArgumentException.class });
+        
+        // foo is ignored, by design
+        result.add(new Object[] { "raw@foo:url", TextFormat.raw, null, "url", null });
+        
+        return result;
+    }
+    
+    private final String input;
+    private final RepoinitTextProvider.TextFormat format;
+    private final String modelSection;
+    private final String url;
+    private final Class<?> expectedException;
+    
+    public RepoinitReferenceTest(String input, TextFormat format, String modelSection, String url, Class<? >expectedException) {
+        this.input = input;
+        this.format = format;
+        this.modelSection = modelSection;
+        this.url = url;
+        this.expectedException = expectedException;
+    }
+    
+    @Test
+    public void testParsing() {
+        try {
+            final Reference ref = new Reference(input);
+            if(expectedException != null) {
+                fail("Expected a " + expectedException.getName());
+            }
+            assertEquals(format, ref.format);
+            assertEquals(modelSection, ref.modelSection);
+            assertEquals(url, ref.url);
+        } catch(Exception e) {
+            if(expectedException != null) {
+                assertEquals(expectedException, e.getClass());
+            } else {
+                fail("Unexpected " + e);
+            }
+        }
+    }
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 10/17: SLING-5923 - Support marker in model.section.name config param, same meaning as empty string

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit 4bb31e7159ae61ea8d714fc515a395ebce1fa179
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Jul 29 12:17:45 2016 +0000

    SLING-5923 - Support <RAW> marker in model.section.name config param, same meaning as empty string
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1754501 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/jcr/repoinit/impl/RepositoryInitializer.java    |  8 ++++++--
 .../sling/jcr/repoinit/RepositoryInitializerTest.java     | 15 ++++++++-------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
index 0c948f8..87b55d7 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
@@ -66,6 +66,10 @@ public class RepositoryInitializer implements SlingRepositoryInitializer {
 
     public static final String DEFAULT_TEXT_URL = "context:/resources/provisioning/model.txt";
     
+    /** Special value for model section name config parameter, which indicates that
+     *  the configured URL provides raw repoinit statements */ 
+    public static final String RAW_SECTION_MARKER = "<RAW>";
+    
     @Property(
             label="Text URL", 
             description="URL of the source text that provides repoinit statements."
@@ -80,7 +84,7 @@ public class RepositoryInitializer implements SlingRepositoryInitializer {
             label="Model section name", 
             description=
                 "Optional provisioning model additional section name (without leading colon) used to extract"
-                + " repoinit statements from the raw text provided by our text URL. Leave empty to consider the content"
+                + " repoinit statements from the raw text provided by our text URL. Leave empty or set to <RAW> to consider the content"
                 + " provided by that URL to already be in repoinit format", 
             value=DEFAULT_MODEL_SECTION_NAME)
     public static final String PROP_MODEL_SECTION_NAME = "model.section.name";
@@ -138,7 +142,7 @@ public class RepositoryInitializer implements SlingRepositoryInitializer {
         final String rawText = getRawRepoInitText();
         log.debug("Raw text from {}: \n{}", textURL, rawText);
         log.info("Got {} characters from {}", rawText.length(), textURL);
-        final boolean parseRawText = modelSectionName.trim().length() == 0;
+        final boolean parseRawText = modelSectionName.trim().length() == 0 || RAW_SECTION_MARKER.equals(modelSectionName);
         if (parseRawText) {
             log.info("Parsing raw repoinit statements from {}", textURL);
             return rawText;
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java b/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java
index 60615e9..4c977a3 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java
@@ -65,20 +65,21 @@ public class RepositoryInitializerTest {
     public static Collection<Object[]> data() {
         final List<Object []> result = new ArrayList<Object[]>();
         
-        result.add(new Object[] { "All empty, just setup + parsing", "", false });
-        result.add(new Object[] { "Using provisioning model", "SECTION_" + UUID.randomUUID(), true }); 
-        result.add(new Object[] { "Raw repoinit/empty section", "", true}); 
-        result.add(new Object[] { "Default value of model section config", null, true}); 
+        result.add(new Object[] { "All empty, just setup + parsing", "", false, false });
+        result.add(new Object[] { "Using provisioning model", "SECTION_" + UUID.randomUUID(), true, true }); 
+        result.add(new Object[] { "Raw repoinit/empty section", "", false, true}); 
+        result.add(new Object[] { "Raw repoinit/special section name", "<RAW>", false, true}); 
+        result.add(new Object[] { "Default value of model section config", null, true, true}); 
         return result;
     }
     
-    public RepositoryInitializerTest(String description, String modelSection, boolean testLogin) throws IOException {
+    public RepositoryInitializerTest(String description, String modelSection, boolean useProvisioningModel, boolean testLogin) throws IOException {
         serviceUser = getClass().getSimpleName() + "-" + UUID.randomUUID();
         
         String txt = "create service user " + serviceUser; 
-        if(modelSection == null) {
+        if(useProvisioningModel && modelSection == null) {
             txt = "[feature name=foo]\n[:repoinit]\n" + txt; 
-        } else if(modelSection.length() > 0) {
+        } else if(useProvisioningModel) {
             txt = "[feature name=bar]\n[:" + modelSection + "]\n" + txt; 
         }
         this.repoInitText = txt + "\n";

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 07/17: SLING-5917 parseRawText flag in getRepoInitText() is ambiguous

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit 2ea4d7ff8b650049e72b52edc0437817c310dbc4
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Fri Jul 29 07:11:24 2016 +0000

    SLING-5917 parseRawText flag in getRepoInitText() is ambiguous
    
    fix meaning of parseRawText flag and make getRepoInitText() more readable
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1754481 13f79535-47bb-0310-9956-ffa450edef68
---
 .../jcr/repoinit/impl/RepositoryInitializer.java   | 39 +++++++++++-----------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
index 62a433d..0c948f8 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
@@ -135,33 +135,32 @@ public class RepositoryInitializer implements SlingRepositoryInitializer {
     }
     
     private String getRepoInitText() {
-        final boolean parseRawText = modelSectionName.trim().length() > 0;
-        if(parseRawText) {
-            log.info("Reading repoinit statements from {}", textURL);
+        final String rawText = getRawRepoInitText();
+        log.debug("Raw text from {}: \n{}", textURL, rawText);
+        log.info("Got {} characters from {}", rawText.length(), textURL);
+        final boolean parseRawText = modelSectionName.trim().length() == 0;
+        if (parseRawText) {
+            log.info("Parsing raw repoinit statements from {}", textURL);
+            return rawText;
         } else {
-            log.info("Extracting repoinit statements from section {} of provisioning model {}", modelSectionName, textURL);
-        }
-        String result = getRawRepoInitText();
-        log.debug("Raw text from {}: \n{}", textURL, result);
-        log.info("Got {} characters from {}", result.length(), textURL);
-        if(parseRawText) {
-            final StringReader r = new StringReader(result);
+            log.info("Extracting repoinit statements from section '{}' of provisioning model {}", modelSectionName, textURL);
+            final StringReader reader = new StringReader(rawText);
             try {
-                final Model m = ModelReader.read(r, textURL);
-                final StringBuilder b = new StringBuilder();
-                for(Feature f : m.getFeatures()) {
-                    for(Section s : f.getAdditionalSections(modelSectionName)) {
-                        b.append("# ").append(modelSectionName).append(" from ").append(f.getName()).append("\n");
-                        b.append("# ").append(s.getComment()).append("\n");
-                        b.append(s.getContents()).append("\n");
+                final Model model = ModelReader.read(reader, textURL);
+                final StringBuilder sb = new StringBuilder();
+                for (final Feature feature : model.getFeatures()) {
+                    for (final Section section : feature.getAdditionalSections(modelSectionName)) {
+                        sb.append("# ").append(modelSectionName).append(" from ").append(feature.getName()).append("\n");
+                        sb.append("# ").append(section.getComment()).append("\n");
+                        sb.append(section.getContents()).append("\n");
                     }
                 }
-                result = b.toString();
+                return sb.toString();
             } catch (IOException e) {
-                result = "";
                 log.warn("Error parsing provisioning model from " + textURL, e);
+                return "";
             }
         }
-        return result;
     }
+
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-jcr-repoinit] 15/17: Prepare to release parser + this module

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit b233c66a486325dd707a0a5a51c01245a9435dac
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Aug 22 16:21:46 2016 +0000

    Prepare to release parser + this module
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1757224 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index f4c4850..22bd5b1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -103,7 +103,7 @@
      <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.repoinit.parser</artifactId>
-      <version>1.0.3-SNAPSHOT</version>
+      <version>1.0.4</version>
       <scope>provided</scope>
     </dependency>
     <dependency>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.