SLING-5449 - RepositoryInitializer integration test, creates a system user

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1727946 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 76a3fc1..879555a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -190,6 +190,18 @@
             <version>2.1.2</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.repoinit.parser</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.repoinit.oak-jcr</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>compile</scope>
diff --git a/src/main/java/org/apache/sling/launchpad/testservices/repository/SystemUsersInitializer.java b/src/main/java/org/apache/sling/launchpad/testservices/repository/SystemUsersInitializer.java
new file mode 100644
index 0000000..51f7660
--- /dev/null
+++ b/src/main/java/org/apache/sling/launchpad/testservices/repository/SystemUsersInitializer.java
@@ -0,0 +1,75 @@
+/*
+ * 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.launchpad.testservices.repository;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import javax.jcr.Session;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.jcr.api.SlingRepositoryInitializer;
+import org.apache.sling.repoinit.jcr.JcrRepoInitOpVisitor;
+import org.apache.sling.repoinit.parser.RepoInitParser;
+import org.apache.sling.repoinit.parser.operations.Operation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SlingRepositoryInitializer that creates system users and sets their ACLs.
+ * Meant to be used for our integration tests until we can create those from
+ * the provisioning model.
+ */
+@Component
+@Service(SlingRepositoryInitializer.class)
+public class SystemUsersInitializer implements SlingRepositoryInitializer {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    public static final String REPOINIT_FILE = "/repoinit.txt";
+
+    @Reference
+    private RepoInitParser parser;
+    
+    @Override
+    public void processRepository(SlingRepository repo) throws Exception {
+        final Session s = repo.loginAdministrative(null);
+        final InputStream is = getClass().getResourceAsStream(REPOINIT_FILE);
+        try {
+            if(is == null) {
+                throw new IOException("Class Resource not found:" + REPOINIT_FILE);
+            }
+            final Reader r = new InputStreamReader(is, "UTF-8");
+            JcrRepoInitOpVisitor v = new JcrRepoInitOpVisitor(s);
+            int count = 0;
+            for(Operation op : parser.parse(r)) {
+                op.accept(v);
+                count++;
+            }
+            s.save();
+            log.info("{} repoinit Operations executed", count);
+        } finally {
+            s.logout();
+            is.close();
+        }
+    }
+}
diff --git a/src/main/resources/repoinit.txt b/src/main/resources/repoinit.txt
new file mode 100644
index 0000000..ba6670a
--- /dev/null
+++ b/src/main/resources/repoinit.txt
@@ -0,0 +1,22 @@
+#
+#  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.
+#
+
+# No tests rely on this so far but we can add
+# more repoinit statements here as needed.
+create service user launchpad_testing
\ No newline at end of file