You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2014/05/27 11:55:40 UTC

svn commit: r1597731 - in /jackrabbit/oak/trunk/oak-pojosr: ./ src/main/resources/ src/main/resources/META-INF/ src/main/resources/META-INF/services/ src/test/java/org/apache/jackrabbit/oak/run/osgi/ src/test/resources/

Author: chetanm
Date: Tue May 27 09:55:39 2014
New Revision: 1597731

URL: http://svn.apache.org/r1597731
Log:
OAK-1522 - Provide PojoSR based RepositoryFactory implementation

Adding service file to enable loading via ServiceLoader

Added:
    jackrabbit/oak/trunk/oak-pojosr/src/main/resources/
    jackrabbit/oak/trunk/oak-pojosr/src/main/resources/META-INF/
    jackrabbit/oak/trunk/oak-pojosr/src/main/resources/META-INF/services/
    jackrabbit/oak/trunk/oak-pojosr/src/main/resources/META-INF/services/javax.jcr.RepositoryFactory
    jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/SimpleRepositoryFactoryTest.java   (with props)
    jackrabbit/oak/trunk/oak-pojosr/src/test/resources/oak-tar-config.json
Modified:
    jackrabbit/oak/trunk/oak-pojosr/README.md

Modified: jackrabbit/oak/trunk/oak-pojosr/README.md
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/README.md?rev=1597731&r1=1597730&r2=1597731&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-pojosr/README.md (original)
+++ jackrabbit/oak/trunk/oak-pojosr/README.md Tue May 27 09:55:39 2014
@@ -13,4 +13,45 @@ To make use of this following dependenci
 3. Apache Felix Config Admin
 4. Apache Felix Fileinstall - To provision configuration
 
+Usage
+-----
+
+The JCR 2.0 specification defines a pattern that uses the Java SE Service Loader facility to 
+find `javax.jcr.RepositoryFactory` instances and use them to get your Repository instance.
+
+    import org.apache.jackrabbit.commons.JcrUtils;
+    
+    Map<String,String> config = new HashMap<String, String>();
+    config.put("org.apache.jackrabbit.repository.home", "/path/to/repo");
+    config.put("org.apache.jackrabbit.oak.repository.configFile", "/path/to/oak-config.json");
+
+    Repository repository = JcrUtils.getRepository(config);
+    
+Where the configFile is json file capturing the required OSGi configuration
+
+    {
+        "org.apache.felix.jaas.Configuration.factory-GuestLoginModule": {
+            "jaas.controlFlag": "optional",
+            "jaas.classname": "org.apache.jackrabbit.oak.spi.security.authentication.GuestLoginModule",
+            "jaas.ranking": 300
+        },
+        "org.apache.felix.jaas.Configuration.factory-LoginModuleImpl": {
+            "jaas.controlFlag": "required",
+            "jaas.classname": "org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl",
+            "jaas.ranking": 100
+        },
+        "org.apache.felix.jaas.Configuration.factory-TokenLoginModule": {
+            "jaas.controlFlag": "sufficient",
+            "jaas.classname": "org.apache.jackrabbit.oak.security.authentication.token.TokenLoginModule",
+            "jaas.ranking": 200
+        },
+        "org.apache.felix.jaas.ConfigurationSpi": {
+            "jaas.defaultRealmName": "jackrabbit.oak",
+            "jaas.globalConfigPolicy": "proxy",
+            "jaas.configProviderName": "FelixJaasProvider"
+        },
+        "org.apache.jackrabbit.oak.jcr.osgi.RepositoryManager": {},
+        "org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStoreService" : {}
+    }
+
 [1]: https://code.google.com/p/pojosr/
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-pojosr/src/main/resources/META-INF/services/javax.jcr.RepositoryFactory
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/main/resources/META-INF/services/javax.jcr.RepositoryFactory?rev=1597731&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-pojosr/src/main/resources/META-INF/services/javax.jcr.RepositoryFactory (added)
+++ jackrabbit/oak/trunk/oak-pojosr/src/main/resources/META-INF/services/javax.jcr.RepositoryFactory Tue May 27 09:55:39 2014
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+org.apache.jackrabbit.oak.run.osgi.OakOSGiRepositoryFactory
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/SimpleRepositoryFactoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/SimpleRepositoryFactoryTest.java?rev=1597731&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/SimpleRepositoryFactoryTest.java (added)
+++ jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/SimpleRepositoryFactoryTest.java Tue May 27 09:55:39 2014
@@ -0,0 +1,77 @@
+/*
+ * 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.run.osgi;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.Repository;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.jackrabbit.commons.JcrUtils;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+
+public class SimpleRepositoryFactoryTest {
+    private File workDir;
+
+    @Before
+    public void setUp() throws IOException {
+        workDir = new File(FilenameUtils.concat(getBaseDir(), "target/repository"));
+        if(workDir.exists()){
+            FileUtils.cleanDirectory(workDir);
+        }
+    }
+
+    @Test
+    public void testRepositoryService() throws Exception{
+        Map<String,String> config = new HashMap<String, String>();
+        config.put("org.apache.jackrabbit.repository.home",
+                workDir.getAbsolutePath());
+        config.put("org.apache.jackrabbit.oak.repository.configFile",
+                path("oak-base-config.json")+","+path("oak-tar-config.json"));
+
+        Repository repository = JcrUtils.getRepository(config);
+        assertNotNull(repository);
+    }
+
+
+
+    private static String getBaseDir() {
+        // 'basedir' is set by Maven Surefire. It always points to the current subproject,
+        // even in reactor builds.
+        String baseDir = System.getProperty("basedir");
+        if(baseDir != null) {
+            return baseDir;
+        }
+        return new File(".").getAbsolutePath();
+    }
+
+    private static String path(String path){
+        File file = new File(FilenameUtils.concat(getBaseDir(), "src/test/resources/"+path));
+        assert file.exists() : "No file found at " + file.getAbsolutePath();
+        return file.getAbsolutePath();
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/SimpleRepositoryFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/oak-tar-config.json
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/resources/oak-tar-config.json?rev=1597731&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-pojosr/src/test/resources/oak-tar-config.json (added)
+++ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/oak-tar-config.json Tue May 27 09:55:39 2014
@@ -0,0 +1,3 @@
+{
+    "org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStoreService" : {}
+}
\ No newline at end of file