You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2017/06/07 08:10:58 UTC

svn commit: r1797888 - in /sling/trunk/bundles/jcr/repoinit: pom.xml src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializerFactory.java

Author: cziegeler
Date: Wed Jun  7 08:10:58 2017
New Revision: 1797888

URL: http://svn.apache.org/viewvc?rev=1797888&view=rev
Log:
SLING-6941 : RepositoryInitializer should be configurable through multiple configurations

Added:
    sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializerFactory.java   (with props)
Modified:
    sling/trunk/bundles/jcr/repoinit/pom.xml

Modified: sling/trunk/bundles/jcr/repoinit/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/pom.xml?rev=1797888&r1=1797887&r2=1797888&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/repoinit/pom.xml (original)
+++ sling/trunk/bundles/jcr/repoinit/pom.xml Wed Jun  7 08:10:58 2017
@@ -67,6 +67,11 @@
                 <configuration>
                     <!-- Export SCR metadata to classpath to have them available in unit tests -->
                     <exportScr>true</exportScr>
+                    <instructions>
+                        <Provide-Capability>
+                            osgi.implementation;osgi.implementation="org.apache.sling.jcr.repoinit";version:Version="1.0"
+                        </Provide-Capability>
+                    </instructions>
                  </configuration>
             </plugin>
             <plugin>

Added: sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializerFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializerFactory.java?rev=1797888&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializerFactory.java (added)
+++ sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializerFactory.java Wed Jun  7 08:10:58 2017
@@ -0,0 +1,96 @@
+/*
+ * 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 java.util.Arrays;
+import java.util.List;
+
+import javax.jcr.Session;
+
+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.repoinit.parser.RepoInitParser;
+import org.apache.sling.repoinit.parser.operations.Operation;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.metatype.annotations.Designate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SlingRepositoryInitializer Factory that executes repoinit statements read
+ * from a configurable URL.
+ */
+@Designate(ocd = RepositoryInitializer.Config.class, factory=true)
+@Component(service = SlingRepositoryInitializer.class,
+    configurationPolicy=ConfigurationPolicy.REQUIRE,
+    configurationPid = "org.apache.sling.jcr.repoinit.RepositoryInitializer",
+    property = {
+            Constants.SERVICE_VENDOR + "=The Apache Software Foundation",
+            // SlingRepositoryInitializers are executed in ascending
+            // order of their service ranking
+            Constants.SERVICE_RANKING + ":Integer=100"
+    })
+public class RepositoryInitializerFactory implements SlingRepositoryInitializer {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+
+    @Reference
+    private RepoInitParser parser;
+
+    @Reference
+    private JcrRepoInitOpsProcessor processor;
+
+    private RepositoryInitializer.Config config;
+
+    @Activate
+    public void activate(final RepositoryInitializer.Config config) {
+        this.config = config;
+        log.debug("Activated: {}", this.toString());
+    }
+
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + ", references=" + Arrays.toString(config.references());
+    }
+
+    @Override
+    public void processRepository(SlingRepository repo) throws Exception {
+        if ( config.references() != null && config.references().length > 0 ) {
+            // loginAdministrative is ok here, definitely an admin operation
+            final Session s = repo.loginAdministrative(null);
+            try {
+                final RepoinitTextProvider p = new RepoinitTextProvider();
+                for(String reference : config.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();
+            }
+        }
+    }
+}

Propchange: sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializerFactory.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url