incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r630169 - in /incubator/sling/trunk/jcr: base/src/main/java/org/apache/sling/jcr/base/util/ jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/
Date Fri, 22 Feb 2008 12:09:16 GMT
Author: bdelacretaz
Date: Fri Feb 22 04:09:08 2008
New Revision: 630169

URL: http://svn.apache.org/viewvc?rev=630169&view=rev
Log:
SLING-254 - sling.repository.url.override property is now used by bundle Activator to create
default configuration

Modified:
    incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java
    incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/Activator.java
    incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/SlingServerRepository.java

Modified: incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java?rev=630169&r1=630168&r2=630169&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java
(original)
+++ incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java
Fri Feb 22 04:09:08 2008
@@ -40,6 +40,12 @@
     
     /** Prefix for JNDI Repository URLs */
     public static final String JNDI_PREFIX = "jndi://";
+    
+    /** Name of the property that the jcr client and server bundles
+     *  to override their default configuration settings and connect
+     *  to the specified repository instead (SLING-254 and SLING-260)
+     */
+    public static final String REPOSITORY_URL_OVERRIDE_PROPERTY = "sling.repository.url.override";
  
     public static class RepositoryUrlException extends SlingException {
         RepositoryUrlException(String reason) {

Modified: incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/Activator.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/Activator.java?rev=630169&r1=630168&r2=630169&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/Activator.java
(original)
+++ incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/Activator.java
Fri Feb 22 04:09:08 2008
@@ -17,8 +17,11 @@
 package org.apache.sling.jcr.jackrabbit.server;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.Hashtable;
 
+import org.apache.sling.jcr.base.util.RepositoryAccessor;
+
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -136,36 +139,22 @@
                 return;
             }
 
-            String slingHome = bundleContext.getProperty("sling.home");
-
-            // make sure jackrabbit home exists
-            File homeDir = new File(slingHome, this.getRepositoryName());
-            if (!homeDir.isDirectory()) {
-                if (!homeDir.mkdirs()) {
-                    log.info("verifyConfiguration: Cannot create Jackrabbit home "
-                        + homeDir + ", failed creating default configuration");
-                    return;
-                }
+            // No config, create a default one.
+            Hashtable<String, String> defaultConfig = new Hashtable<String, String>();
+            final String overrideUrl = bundleContext.getProperty(RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY);
+            if(overrideUrl != null && overrideUrl.length() > 0) {
+                // Ignore other parameters if override URL (SLING-254) is set 
+                defaultConfig.put(RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY, overrideUrl);
+                log.debug(RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY + "=" + overrideUrl
+ 
+                    ", using it to create the default configuration");
+                
+            } else {
+               initDefaultConfig(defaultConfig, bundleContext); 
             }
-
-            // ensure the configuration file
-            File configFile = new File(slingHome, "repository.xml");
-            SlingServerRepository.copyFile(bundleContext.getBundle(),
-                "repository.xml", configFile);
-
-            // we have no configuration, create from default settings
-            Hashtable<String, String> props = new Hashtable<String, String>();
-            props.put(SLING_CONTEXT, slingContext);
-            props.put(SlingServerRepository.REPOSITORY_CONFIG_URL,
-                configFile.getPath());
-            props.put(SlingServerRepository.REPOSITORY_HOME_DIR,
-                homeDir.getPath());
-            props.put(SlingServerRepository.REPOSITORY_REGISTRATION_NAME,
-                this.getRepositoryName());
-
+            
             // create the factory and set the properties
             Configuration config = ca.createFactoryConfiguration(SERVER_REPOSITORY_FACTORY_PID);
-            config.update(props);
+            config.update(defaultConfig);
 
             log.debug("verifyConfiguration: Created configuration {} for {}",
                 config.getPid(), config.getFactoryPid());
@@ -176,5 +165,34 @@
         } finally {
             bundleContext.ungetService(ref);
         }
+    }
+    
+    private void initDefaultConfig(Hashtable<String, String> props, BundleContext bundleContext)
throws IOException {
+        String slingHome = bundleContext.getProperty("sling.home");
+        log.debug("Creating default config, sling.home=" + slingHome);
+
+        // make sure jackrabbit home exists
+        File homeDir = new File(slingHome, this.getRepositoryName());
+        if (!homeDir.isDirectory()) {
+            if (!homeDir.mkdirs()) {
+                log.info("verifyConfiguration: Cannot create Jackrabbit home "
+                    + homeDir + ", failed creating default configuration");
+                return;
+            }
+        }
+
+        // ensure the configuration file
+        File configFile = new File(slingHome, "repository.xml");
+        SlingServerRepository.copyFile(bundleContext.getBundle(),
+            "repository.xml", configFile);
+
+        // default config values
+        props.put(SLING_CONTEXT, slingContext);
+        props.put(SlingServerRepository.REPOSITORY_CONFIG_URL,
+            configFile.getPath());
+        props.put(SlingServerRepository.REPOSITORY_HOME_DIR,
+            homeDir.getPath());
+        props.put(SlingServerRepository.REPOSITORY_REGISTRATION_NAME,
+            this.getRepositoryName());
     }
 }

Modified: incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/SlingServerRepository.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/SlingServerRepository.java?rev=630169&r1=630168&r2=630169&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/SlingServerRepository.java
(original)
+++ incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/SlingServerRepository.java
Fri Feb 22 04:09:08 2008
@@ -98,11 +98,6 @@
     public static final String REPOSITORY_REGISTRATION_NAME = "name";
 
     /**
-     * @scr.property value="sling.repository.url.override"
-     */
-    public static final String REPOSITORY_URL_OVERRIDE_NAME = "repository.url.override.property";

-
-    /**
      * @scr.reference
      */
     private LogService log;
@@ -166,23 +161,20 @@
         @SuppressWarnings("unchecked")
         Dictionary<String, Object> environment = this.getComponentContext().getProperties();
         
-        final String urlOverrideProperty = (String) environment.get(REPOSITORY_URL_OVERRIDE_NAME);
-        String repositoryUrl = null;
-        if(urlOverrideProperty!=null && urlOverrideProperty.length() > 0) {
-            repositoryUrl = System.getProperty(urlOverrideProperty);
-        }
+        // if the environment provides a repository override URL, other settings are ignored
+        final String overrideUrl = (String) environment.get(RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY);
         
-        if(repositoryUrl != null) {
+        if(overrideUrl != null && overrideUrl.length() > 0) {
             log.log(LogService.LOG_INFO, 
-                    "Will not use embedded repository due to system property " + urlOverrideProperty

-                    + "=" + repositoryUrl
+                    "Will not use embedded repository due to property " + RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY

+                    + "=" + overrideUrl
                     + ", acquiring repository using that URL"
                     );
-            return getRepositoryFromUrl(repositoryUrl);
+            return getRepositoryFromUrl(overrideUrl);
             
         } else {
             log.log(LogService.LOG_INFO, 
-                    "Repository URL override system property (" + urlOverrideProperty 
+                    "Repository URL override property (" +  RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY
                     + ") not set, using embedded repository"); 
             return getEmbeddedRepository(environment);
         }



Mime
View raw message