jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1392352 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/ oak-core/src/main/java/org/apache/jackrabbi...
Date Mon, 01 Oct 2012 14:36:58 GMT
Author: mreutegg
Date: Mon Oct  1 14:36:57 2012
New Revision: 1392352

URL: http://svn.apache.org/viewvc?rev=1392352&view=rev
Log:
OAK-41: Initial repository setup

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/AbstractServiceTracker.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiMicroKernelTracker.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/InitialContent.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/CompositeMicroKernelTracker.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/DefaultMicroKernelTracker.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/MicroKernelTracker.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentSessionImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiValidatorProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/BuiltInNodeTypes.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractOakTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java?rev=1392352&r1=1392351&r2=1392352&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java Mon Oct  1 14:36:57 2012
@@ -23,7 +23,11 @@ import javax.annotation.Nonnull;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
+import org.apache.jackrabbit.oak.core.RootImpl;
+import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.CompositeHook;
 import org.apache.jackrabbit.oak.spi.commit.CompositeValidatorProvider;
@@ -33,6 +37,7 @@ import org.apache.jackrabbit.oak.spi.com
 import org.apache.jackrabbit.oak.spi.query.CompositeQueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
@@ -81,6 +86,13 @@ public class Oak {
     }
 
     public ContentRepository createContentRepository() {
+        return new ContentRepositoryImpl(
+                kernel,
+                CompositeQueryIndexProvider.compose(providers),
+                createCommitHook());
+    }
+
+    private CommitHook createCommitHook() {
         CommitHook hook;
         if (!validators.isEmpty()) {
             hook = CompositeHook.compose(ImmutableList.<CommitHook>builder()
@@ -91,11 +103,35 @@ public class Oak {
         } else {
             hook = CompositeHook.compose(hooks);
         }
-        return new ContentRepositoryImpl(
-                kernel,
-                CompositeQueryIndexProvider.compose(providers),
-                hook);
+        return hook;
     }
 
+    /**
+     * Creates a {@link NodeStore} based on the previously set micro kernel,
+     * hooks and validators.
+     * <p/>
+     * This method will return an in memory node store without hooks nor
+     * validators if no {@link MicroKernel} was set.
+     *
+     * @return a {@link NodeStore}.
+     */
+    public NodeStore createNodeStore() {
+        if (kernel != null) {
+            KernelNodeStore nodeStore = new KernelNodeStore(kernel);
+            nodeStore.setHook(createCommitHook());
+            return nodeStore;
+        } else {
+            return new MemoryNodeStore();
+        }
+    }
 
+    /**
+     * Creates a {@link Root} based on the previously set {@link MicroKernel},
+     * {@link CommitHook} and {@link ValidatorProvider}.
+     *
+     * @return a {@link Root} instance.
+     */
+    public Root createRoot() {
+        return new RootImpl(createNodeStore(), null);
+    }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java?rev=1392352&r1=1392351&r2=1392352&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java Mon Oct  1 14:36:57 2012
@@ -39,7 +39,6 @@ import org.apache.jackrabbit.oak.spi.com
 import org.apache.jackrabbit.oak.spi.query.CompositeQueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.security.authentication.LoginContextProvider;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -121,24 +120,6 @@ public class ContentRepositoryImpl imple
 
         // TODO: use configurable context provider
         loginContextProvider = new LoginContextProviderImpl(this);
-
-        // FIXME: repository setup must be done elsewhere...
-        // FIXME: depends on CoreValue's name mangling
-        NodeState root = nodeStore.getRoot();
-        if (root.hasChildNode("jcr:system")) {
-            microKernel.commit("/", "^\"jcr:primaryType\":\"nam:rep:root\" ", null, null);
-        } else {
-            microKernel.commit("/", "^\"jcr:primaryType\":\"nam:rep:root\"" +
-                "+\"jcr:system\":{" +
-                    "\"jcr:primaryType\"    :\"nam:rep:system\"," +
-                    // FIXME: user-mgt related unique properties are implementation detail and not generic for repo
-                    // FIXME: rep:principalName only needs to be unique if defined with user/group nodes -> add defining nt-info to uniqueness constraint
-                    "\":unique\"            :{\"jcr:uuid\":{},\"rep:authorizableId\":{},\"rep:principalName\":{}}," +
-                    "\"jcr:versionStorage\" :{\"jcr:primaryType\":\"nam:rep:versionStorage\"}," +
-                    "\"jcr:nodeTypes\"      :{\"jcr:primaryType\":\"nam:rep:nodeTypes\"}," +
-                    "\"jcr:activities\"     :{\"jcr:primaryType\":\"nam:rep:Activities\"}," +
-                    "\"rep:privileges\"     :{\"jcr:primaryType\":\"nam:rep:Privileges\"}}", null, null);
-        }
     }
 
     @Nonnull

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentSessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentSessionImpl.java?rev=1392352&r1=1392351&r2=1392352&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentSessionImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentSessionImpl.java Mon Oct  1 14:36:57 2012
@@ -28,7 +28,6 @@ import org.apache.jackrabbit.oak.api.Con
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.SessionQueryEngine;
-import org.apache.jackrabbit.oak.plugins.type.BuiltInNodeTypes;
 import org.apache.jackrabbit.oak.query.QueryEngineImpl;
 import org.apache.jackrabbit.oak.query.SessionQueryEngineImpl;
 import org.apache.jackrabbit.oak.spi.commit.ConflictHandlerProvider;
@@ -51,8 +50,6 @@ class ContentSessionImpl implements Cont
     private final ConflictHandlerProvider conflictHandlerProvider;
     private final SessionQueryEngine queryEngine;
 
-    private boolean initialised;
-
     public ContentSessionImpl(LoginContext loginContext, String workspaceName,
             NodeStore store, ConflictHandlerProvider conflictHandlerProvider,
             QueryEngineImpl queryEngine) {
@@ -77,14 +74,6 @@ class ContentSessionImpl implements Cont
     @Nonnull
     @Override
     public Root getLatestRoot() {
-        // TODO: improve initial repository/session. See OAK-41
-        synchronized (this) {
-            if (!initialised) {
-                initialised = true;
-                BuiltInNodeTypes.register(getLatestRoot());
-            }
-        }
-
         RootImpl root = new RootImpl(store, workspaceName, loginContext.getSubject());
         if (conflictHandlerProvider != null) {
             root.setConflictHandler(conflictHandlerProvider.getConflictHandler(getCoreValueFactory()));

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java?rev=1392352&r1=1392351&r2=1392352&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java Mon Oct  1 14:36:57 2012
@@ -30,7 +30,9 @@ import org.apache.jackrabbit.oak.api.Cha
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.plugins.commit.DefaultConflictHandler;
 import org.apache.jackrabbit.oak.spi.commit.ConflictHandler;
+import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.TreeLocation;
 import org.apache.jackrabbit.oak.security.authorization.AccessControlContextImpl;
 import org.apache.jackrabbit.oak.spi.security.authorization.AccessControlContext;
@@ -55,6 +57,11 @@ public class RootImpl implements Root {
      */
     private static final int PURGE_LIMIT = 100;
 
+    /**
+     * A dummy subject used when no subject is provided in the constructor.
+     */
+    private static final Subject DUMMY_SUBJECT = new Subject();
+
     /** The underlying store to which this root belongs */
     private final NodeStore store;
 
@@ -107,6 +114,16 @@ public class RootImpl implements Root {
         refresh();
     }
 
+    /**
+     * New instance bases on a given {@link NodeStore} and a workspace
+     * @param store  node store
+     * @param workspaceName  name of the workspace
+     */
+    @SuppressWarnings("UnusedParameters")
+    public RootImpl(NodeStore store, String workspaceName) {
+        this(store, workspaceName, DUMMY_SUBJECT);
+    }
+
     public void setConflictHandler(ConflictHandler conflictHandler) {
         this.conflictHandler = conflictHandler;
     }
@@ -263,9 +280,13 @@ public class RootImpl implements Root {
     }
 
     CompiledPermissions getPermissions() {
-        AccessControlContext context = new AccessControlContextImpl();
-        context.initialize(subject.getPrincipals());
-        return context.getPermissions();
+        if (subject == DUMMY_SUBJECT) {
+            return new AllPermissions();
+        } else {
+            AccessControlContext context = new AccessControlContextImpl();
+            context.initialize(subject.getPrincipals());
+            return context.getPermissions();
+        }
     }
 
     //------------------------------------------------------------< private >---
@@ -288,4 +309,28 @@ public class RootImpl implements Root {
         }
     }
 
+    private static final class AllPermissions implements CompiledPermissions {
+        @Override
+        public boolean canRead(String path, boolean isProperty) {
+            return true;
+        }
+
+        @Override
+        public boolean isGranted(int permissions) {
+            return true;
+        }
+
+        @Override
+        public boolean isGranted(Tree tree, int permissions) {
+            return true;
+        }
+
+        @Override
+        public boolean isGranted(Tree parent,
+                                 PropertyState property,
+                                 int permissions) {
+            return true;
+        }
+    }
+
 }

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/AbstractServiceTracker.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/AbstractServiceTracker.java?rev=1392352&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/AbstractServiceTracker.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/AbstractServiceTracker.java Mon Oct  1 14:36:57 2012
@@ -0,0 +1,101 @@
+/*
+ * 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.jackrabbit.oak.osgi;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+/**
+ * <code>AbstractServiceTracker</code> is a base class for the various OSGi based
+ * providers.
+ */
+public abstract class AbstractServiceTracker<T> implements ServiceTrackerCustomizer {
+
+    private BundleContext context;
+
+    private ServiceTracker tracker;
+
+    private final Map<ServiceReference, T> services =
+            new HashMap<ServiceReference, T>();
+
+    private final Class<T> serviceClass;
+
+    public AbstractServiceTracker(Class<T> serviceClass) {
+        this.serviceClass = serviceClass;
+    }
+
+    public void start(BundleContext bundleContext) throws Exception {
+        context = bundleContext;
+        tracker = new ServiceTracker(
+                bundleContext, serviceClass.getName(), this);
+        tracker.open();
+    }
+
+    public void stop() throws Exception {
+        tracker.close();
+    }
+
+    /**
+     * Returns all services of type <code>T</code> currently available.
+     *
+     * @return services currently available.
+     */
+    protected List<T> getServices() {
+        synchronized (this) {
+            return new ArrayList<T>(services.values());
+        }
+    }
+
+    //------------------------< ServiceTrackerCustomizer >----------------------
+
+    @Override
+    public Object addingService(ServiceReference reference) {
+        Object service = context.getService(reference);
+
+        if (serviceClass.isInstance(service)) {
+            synchronized (this) {
+                services.put(reference, (T) service);
+            }
+            return service;
+        } else {
+            context.ungetService(reference);
+            return null;
+        }
+    }
+
+    @Override
+    public void modifiedService(ServiceReference reference, Object service) {
+        // nothing to do
+    }
+
+    @Override
+    public void removedService(ServiceReference reference, Object service) {
+        synchronized (this) {
+            services.remove(reference);
+        }
+        context.ungetService(reference);
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/AbstractServiceTracker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/AbstractServiceTracker.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java?rev=1392352&r1=1392351&r2=1392352&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java Mon Oct  1 14:36:57 2012
@@ -21,10 +21,9 @@ import java.util.Map;
 import java.util.Properties;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.oak.Oak;
 import org.apache.jackrabbit.oak.api.ContentRepository;
-import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
 import org.apache.jackrabbit.oak.plugins.type.DefaultTypeEditor;
-import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.CompositeHook;
 import org.apache.jackrabbit.oak.spi.commit.ValidatingHook;
 import org.osgi.framework.BundleActivator;
@@ -44,6 +43,8 @@ public class Activator implements Bundle
 
     private final OsgiValidatorProvider validatorProvider = new OsgiValidatorProvider();
 
+    private final OsgiMicroKernelTracker kernelTracker = new OsgiMicroKernelTracker();
+
     private final Map<ServiceReference, ServiceRegistration> services =
             new HashMap<ServiceReference, ServiceRegistration>();
 
@@ -55,6 +56,7 @@ public class Activator implements Bundle
 
         indexProvider.start(bundleContext);
         validatorProvider.start(bundleContext);
+        kernelTracker.start(bundleContext);
 
         tracker = new ServiceTracker(
                 context, MicroKernel.class.getName(), this);
@@ -67,6 +69,7 @@ public class Activator implements Bundle
 
         indexProvider.stop();
         validatorProvider.stop();
+        kernelTracker.stop();
     }
 
     //-------------------------------------------< ServiceTrackerCustomizer >---
@@ -75,15 +78,18 @@ public class Activator implements Bundle
     public Object addingService(ServiceReference reference) {
         Object service = context.getService(reference);
         if (service instanceof MicroKernel) {
-            CommitHook hook = new CompositeHook(
-                    new DefaultTypeEditor(),
-                    new ValidatingHook(validatorProvider));
-                    // new LuceneEditor());
-
             MicroKernel kernel = (MicroKernel) service;
+            kernelTracker.available(kernel);
+            Oak oak = new Oak(kernel)
+                    .with(new CompositeHook(
+                        // TODO: DefaultTypeEditor is JCR specific and does not belong here
+                        new DefaultTypeEditor(),
+                        new ValidatingHook(validatorProvider)))
+                        // new LuceneEditor());
+                    .with(indexProvider);
             services.put(reference, context.registerService(
                     ContentRepository.class.getName(),
-                    new ContentRepositoryImpl(kernel, indexProvider, hook),
+                    oak.createContentRepository(),
                     new Properties()));
             return service;
         } else {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java?rev=1392352&r1=1392351&r2=1392352&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java Mon Oct  1 14:36:57 2012
@@ -18,9 +18,7 @@
  */
 package org.apache.jackrabbit.oak.osgi;
 
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import javax.annotation.Nonnull;
 
@@ -28,63 +26,23 @@ import org.apache.jackrabbit.oak.spi.que
 import org.apache.jackrabbit.oak.spi.query.QueryIndex;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
 
 /**
  * This index provider combines all indexes of all available OSGi index
  * providers.
  */
-public class OsgiIndexProvider implements ServiceTrackerCustomizer, QueryIndexProvider {
+public class OsgiIndexProvider
+        extends AbstractServiceTracker<QueryIndexProvider>
+        implements QueryIndexProvider {
 
-    private BundleContext context;
-
-    private ServiceTracker tracker;
-
-    private final Map<ServiceReference, QueryIndexProvider> providers =
-        new HashMap<ServiceReference, QueryIndexProvider>();
-
-    public void start(BundleContext bundleContext) throws Exception {
-        context = bundleContext;
-        tracker = new ServiceTracker(
-                bundleContext, QueryIndexProvider.class.getName(), this);
-        tracker.open();
-    }
-
-    public void stop() throws Exception {
-        tracker.close();
-    }
-
-    @Override
-    public Object addingService(ServiceReference reference) {
-        Object service = context.getService(reference);
-        if (service instanceof QueryIndexProvider) {
-            QueryIndexProvider provider = (QueryIndexProvider) service;
-            providers.put(reference, provider);
-            return service;
-        } else {
-            context.ungetService(reference);
-            return null;
-        }
-    }
-
-    @Override
-    public void modifiedService(ServiceReference reference, Object service) {
-        // nothing to do
-    }
-
-    @Override
-    public void removedService(ServiceReference reference, Object service) {
-        providers.remove(reference);
-        context.ungetService(reference);
+    public OsgiIndexProvider() {
+        super(QueryIndexProvider.class);
     }
 
     @Override @Nonnull
     public List<? extends QueryIndex> getQueryIndexes(NodeStore nodeStore) {
         QueryIndexProvider composite =
-                CompositeQueryIndexProvider.compose(providers.values());
+                CompositeQueryIndexProvider.compose(getServices());
         return composite.getQueryIndexes(nodeStore);
     }
 

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiMicroKernelTracker.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiMicroKernelTracker.java?rev=1392352&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiMicroKernelTracker.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiMicroKernelTracker.java Mon Oct  1 14:36:57 2012
@@ -0,0 +1,64 @@
+/*
+ * 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.jackrabbit.oak.osgi;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.oak.spi.lifecycle.MicroKernelTracker;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Implements a service tracker that keeps track of all
+ * {@link MicroKernelTracker}s in the system and calls the available
+ * method once the micro kernel is available.
+ */
+public class OsgiMicroKernelTracker
+        extends AbstractServiceTracker<MicroKernelTracker>
+        implements MicroKernelTracker {
+
+    /**
+     * The reference to the micro kernel once available.
+     */
+    private volatile MicroKernel mk;
+
+    public OsgiMicroKernelTracker() {
+        super(MicroKernelTracker.class);
+    }
+
+    @Override
+    public void available(MicroKernel mk) {
+        this.mk = mk;
+        if (mk != null) {
+            for (MicroKernelTracker mki : getServices()) {
+                mki.available(mk);
+            }
+        }
+    }
+
+    @Override
+    public Object addingService(ServiceReference reference) {
+        MicroKernelTracker mki =
+                (MicroKernelTracker) super.addingService(reference);
+        MicroKernel microKernel = mk;
+        if (microKernel != null) {
+            mki.available(mk);
+        }
+        return mki;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiMicroKernelTracker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiMicroKernelTracker.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiValidatorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiValidatorProvider.java?rev=1392352&r1=1392351&r2=1392352&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiValidatorProvider.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiValidatorProvider.java Mon Oct  1 14:36:57 2012
@@ -22,69 +22,24 @@ import org.apache.jackrabbit.oak.spi.com
 import org.apache.jackrabbit.oak.spi.commit.Validator;
 import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
-
-import java.util.HashMap;
-import java.util.Map;
 
 /**
  * This validator provider combines all validators of all available OSGi validator
  * providers.
  */
-public class OsgiValidatorProvider implements ServiceTrackerCustomizer, ValidatorProvider {
-
-    private BundleContext context;
-
-    private ServiceTracker tracker;
-
-    private final Map<ServiceReference, ValidatorProvider> providers =
-        new HashMap<ServiceReference, ValidatorProvider>();
-
-    public void start(BundleContext bundleContext) throws Exception {
-        context = bundleContext;
-        tracker = new ServiceTracker(
-                bundleContext, ValidatorProvider.class.getName(), this);
-        tracker.open();
-    }
-
-    public void stop() throws Exception {
-        tracker.close();
-    }
+public class OsgiValidatorProvider
+        extends AbstractServiceTracker<ValidatorProvider>
+        implements ValidatorProvider {
 
-    //------------------------------------------------------------< ServiceTrackerCustomizer >---
-
-    @Override
-    public Object addingService(ServiceReference reference) {
-        Object service = context.getService(reference);
-        if (service instanceof ValidatorProvider) {
-            ValidatorProvider provider = (ValidatorProvider) service;
-            providers.put(reference, provider);
-            return service;
-        } else {
-            context.ungetService(reference);
-            return null;
-        }
-    }
-
-    @Override
-    public void modifiedService(ServiceReference reference, Object service) {
-        // nothing to do
-    }
-
-    @Override
-    public void removedService(ServiceReference reference, Object service) {
-        providers.remove(reference);
-        context.ungetService(reference);
+    public OsgiValidatorProvider() {
+        super(ValidatorProvider.class);
     }
 
     //------------------------------------------------------------< ValidatorProvider >---
 
     @Override
     public Validator getRootValidator(NodeState before, NodeState after) {
-        return CompositeValidatorProvider.compose(providers.values())
+        return CompositeValidatorProvider.compose(getServices())
                 .getRootValidator(before, after);
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/BuiltInNodeTypes.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/BuiltInNodeTypes.java?rev=1392352&r1=1392351&r2=1392352&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/BuiltInNodeTypes.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/BuiltInNodeTypes.java Mon Oct  1 14:36:57 2012
@@ -18,14 +18,11 @@ package org.apache.jackrabbit.oak.plugin
 
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.security.PrivilegedAction;
 
 import javax.annotation.Nonnull;
-import javax.security.auth.Subject;
 
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal;
 
 import static org.apache.jackrabbit.oak.plugins.type.NodeTypeConstants.NODE_TYPES_PATH;
 
@@ -68,25 +65,17 @@ public class BuiltInNodeTypes {
         //        not have sufficient permission to register node types or may
         //        even have limited read-permission on the jcr:nodetypes path.
         if (!nodeTypesInContent()) {
-            Subject admin = new Subject();
-            admin.getPrincipals().add(AdminPrincipal.INSTANCE);
-            Subject.doAs(admin, new PrivilegedAction<Void>() {
-                @Override
-                public Void run() {
-                    try {
-                        InputStream stream = BuiltInNodeTypes.class.getResourceAsStream("builtin_nodetypes.cnd");
-                        try {
-                            ntMgr.registerNodeTypes(new InputStreamReader(stream, "UTF-8"));
-                        } finally {
-                            stream.close();
-                        }
-                    } catch (Exception e) {
-                        throw new IllegalStateException(
-                                "Unable to load built-in node types", e);
-                    }
-                    return null;
+            try {
+                InputStream stream = BuiltInNodeTypes.class.getResourceAsStream("builtin_nodetypes.cnd");
+                try {
+                    ntMgr.registerNodeTypes(new InputStreamReader(stream, "UTF-8"));
+                } finally {
+                    stream.close();
                 }
-            });
+            } catch (Exception e) {
+                throw new IllegalStateException(
+                        "Unable to load built-in node types", e);
+            }
         }
     }
 

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/InitialContent.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/InitialContent.java?rev=1392352&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/InitialContent.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/InitialContent.java Mon Oct  1 14:36:57 2012
@@ -0,0 +1,56 @@
+/*
+ * 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.jackrabbit.oak.plugins.type;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.oak.Oak;
+import org.apache.jackrabbit.oak.spi.lifecycle.DefaultMicroKernelTracker;
+import org.apache.jackrabbit.oak.spi.lifecycle.MicroKernelTracker;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+
+/**
+ * <code>InitialContent</code> implements a {@link MicroKernelTracker} and
+ * registers built-in node types when the micro kernel becomes available.
+ */
+@Component
+@Service(MicroKernelTracker.class)
+public class InitialContent extends DefaultMicroKernelTracker {
+
+    @Override
+    public void available(MicroKernel mk) {
+        NodeStore nodeStore = new Oak(mk).createNodeStore();
+        // FIXME: depends on CoreValue's name mangling
+        NodeState root = nodeStore.getRoot();
+        if (root.hasChildNode("jcr:system")) {
+            mk.commit("/", "^\"jcr:primaryType\":\"nam:rep:root\" ", null, null);
+        } else {
+            mk.commit("/", "^\"jcr:primaryType\":\"nam:rep:root\"" +
+                    "+\"jcr:system\":{" +
+                    "\"jcr:primaryType\"    :\"nam:rep:system\"," +
+                    "\":unique\"            :{\"jcr:uuid\":{},\"rep:authorizableId\":{},\"rep:principalName\":{}}," +
+                    "\"jcr:versionStorage\" :{\"jcr:primaryType\":\"nam:rep:versionStorage\"}," +
+                    "\"jcr:nodeTypes\"      :{\"jcr:primaryType\":\"nam:rep:nodeTypes\"}," +
+                    "\"jcr:activities\"     :{\"jcr:primaryType\":\"nam:rep:Activities\"}," +
+                    "\"rep:privileges\"     :{\"jcr:primaryType\":\"nam:rep:Privileges\"}}", null, null);
+        }
+
+        BuiltInNodeTypes.register(new Oak(mk).createRoot());
+    }
+}

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/CompositeMicroKernelTracker.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/CompositeMicroKernelTracker.java?rev=1392352&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/CompositeMicroKernelTracker.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/CompositeMicroKernelTracker.java Mon Oct  1 14:36:57 2012
@@ -0,0 +1,50 @@
+/*
+ * 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.jackrabbit.oak.spi.lifecycle;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+
+/**
+ * <code>CompositeMicroKernelTracker</code> consists of multiple micro kernel
+ * trackers and calls them all on {@link #available(MicroKernel)}.
+ */
+public class CompositeMicroKernelTracker implements MicroKernelTracker {
+
+    private final List<MicroKernelTracker> trackers = new ArrayList<MicroKernelTracker>();
+
+    public CompositeMicroKernelTracker(Collection<MicroKernelTracker> trackers) {
+        this.trackers.addAll(trackers);
+    }
+
+    public CompositeMicroKernelTracker(MicroKernelTracker... trackers) {
+        this.trackers.addAll(Arrays.asList(trackers));
+    }
+
+    @Override
+    public void available(MicroKernel mk) {
+        for (MicroKernelTracker tracker : trackers) {
+            tracker.available(mk);
+        }
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/CompositeMicroKernelTracker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/CompositeMicroKernelTracker.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/DefaultMicroKernelTracker.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/DefaultMicroKernelTracker.java?rev=1392352&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/DefaultMicroKernelTracker.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/DefaultMicroKernelTracker.java Mon Oct  1 14:36:57 2012
@@ -0,0 +1,36 @@
+/*
+ * 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.jackrabbit.oak.spi.lifecycle;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+
+/**
+ * <code>DefaultMicroKernelTracker</code> is a default implementation of all methods
+ * specified in {@link MicroKernelTracker}. The methods immediately return and do
+ * nothing.
+ * </p>
+ * This class can be used when a tracker only wants to get callbacks for some of
+ * the life cycle events and does not want to implement all methods specified
+ * in {@link MicroKernelTracker}. This also guarantees forward compatibility when
+ * new methods are introduced in later versions.
+ */
+public class DefaultMicroKernelTracker implements MicroKernelTracker {
+
+    @Override
+    public void available(MicroKernel mk) {
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/DefaultMicroKernelTracker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/DefaultMicroKernelTracker.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/MicroKernelTracker.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/MicroKernelTracker.java?rev=1392352&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/MicroKernelTracker.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/MicroKernelTracker.java Mon Oct  1 14:36:57 2012
@@ -0,0 +1,37 @@
+/*
+ * 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.jackrabbit.oak.spi.lifecycle;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.oak.api.ContentRepository;
+
+/**
+ * This interface is mainly used in an OSGi environment where various components
+ * of Oak are started by container and one would like to plug in some code that
+ * is executed when the micro kernel becomes available in the system.
+ */
+public interface MicroKernelTracker {
+
+    /**
+     * This method is called when both the {@link MicroKernel} service and this
+     * tracker become available in the system.
+     * @param mk the {@link MicroKernel} instance.
+     */
+    public void available(MicroKernel mk);
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/MicroKernelTracker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/MicroKernelTracker.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractOakTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractOakTest.java?rev=1392352&r1=1392351&r2=1392352&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractOakTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractOakTest.java Mon Oct  1 14:36:57 2012
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.oak;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.jcr.Credentials;
 import javax.jcr.GuestCredentials;
 import javax.jcr.NoSuchWorkspaceException;
@@ -25,6 +28,9 @@ import javax.security.auth.login.LoginEx
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
+import org.apache.jackrabbit.oak.plugins.type.InitialContent;
+import org.apache.jackrabbit.oak.spi.lifecycle.CompositeMicroKernelTracker;
+import org.apache.jackrabbit.oak.spi.lifecycle.MicroKernelTracker;
 import org.junit.Before;
 
 /**
@@ -62,4 +68,10 @@ public abstract class AbstractOakTest {
         return new SimpleCredentials("admin", "admin".toCharArray());
     }
 
+    protected static MicroKernelTracker createDefaultKernelTracker() {
+        List<MicroKernelTracker> hooks = new ArrayList<MicroKernelTracker>();
+        hooks.add(new InitialContent());
+        return new CompositeMicroKernelTracker(hooks);
+    }
+
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java?rev=1392352&r1=1392351&r2=1392352&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java Mon Oct  1 14:36:57 2012
@@ -16,10 +16,9 @@
  */
 package org.apache.jackrabbit.oak.plugins.lucene;
 
-import static org.apache.jackrabbit.oak.spi.query.IndexUtils.DEFAULT_INDEX_HOME;
-
 import java.text.ParseException;
 
+import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.apache.jackrabbit.oak.AbstractOakTest;
 import org.apache.jackrabbit.oak.api.ContentRepository;
@@ -37,6 +36,8 @@ import org.apache.jackrabbit.oak.spi.que
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
 import org.junit.Before;
 
+import static org.apache.jackrabbit.oak.spi.query.IndexUtils.DEFAULT_INDEX_HOME;
+
 /**
  * base class for lucene search tests
  */
@@ -67,7 +68,9 @@ public abstract class AbstractLuceneQuer
                 new LuceneIndexProvider(DEFAULT_INDEX_HOME));
         CommitHook ch = new CompositeHook(new LuceneReindexHook(
                 DEFAULT_INDEX_HOME), new LuceneHook(DEFAULT_INDEX_HOME));
-        return new ContentRepositoryImpl(new MicroKernelImpl(), qip, ch);
+        MicroKernel mk = new MicroKernelImpl();
+        createDefaultKernelTracker().available(mk);
+        return new ContentRepositoryImpl(mk, qip, ch);
     }
 
     protected void createIndexNode() throws Exception {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java?rev=1392352&r1=1392351&r2=1392352&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java Mon Oct  1 14:36:57 2012
@@ -55,6 +55,7 @@ public abstract class AbstractQueryTest 
         PropertyIndexer pi = new PropertyIndexer(indexer);
         QueryIndexProvider qip = new CompositeQueryIndexProvider(pi);
         CompositeHook hook = new CompositeHook(pi);
+        createDefaultKernelTracker().available(mk);
         return new ContentRepositoryImpl(mk, qip, hook);
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java?rev=1392352&r1=1392351&r2=1392352&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java Mon Oct  1 14:36:57 2012
@@ -34,6 +34,7 @@ import org.apache.jackrabbit.oak.api.Con
 import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
 import org.apache.jackrabbit.oak.plugins.name.NameValidatorProvider;
 import org.apache.jackrabbit.oak.plugins.name.NamespaceValidatorProvider;
+import org.apache.jackrabbit.oak.plugins.type.InitialContent;
 import org.apache.jackrabbit.oak.plugins.type.TypeValidatorProvider;
 import org.apache.jackrabbit.oak.plugins.unique.UniqueIndexHook;
 import org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider;
@@ -90,8 +91,8 @@ public class RepositoryImpl implements R
 
     public RepositoryImpl(
             MicroKernel kernel, ScheduledExecutorService executor) {
-        this(new ContentRepositoryImpl(kernel, null, DEFAULT_COMMIT_HOOK),
-                executor);
+        this(new ContentRepositoryImpl(setupInitialContent(kernel), null,
+                DEFAULT_COMMIT_HOOK), executor);
     }
 
     /**
@@ -214,4 +215,9 @@ public class RepositoryImpl implements R
     public Session login(String workspace) throws RepositoryException {
         return login(null, workspace);
     }
+
+    private static MicroKernel setupInitialContent(MicroKernel mk) {
+        new InitialContent().available(mk);
+        return mk;
+    }
 }
\ No newline at end of file



Mime
View raw message