Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 67050 invoked from network); 19 Nov 2008 11:45:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Nov 2008 11:45:02 -0000 Received: (qmail 98114 invoked by uid 500); 19 Nov 2008 11:45:10 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 98067 invoked by uid 500); 19 Nov 2008 11:45:10 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 98058 invoked by uid 99); 19 Nov 2008 11:45:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Nov 2008 03:45:10 -0800 X-ASF-Spam-Status: No, hits=-1998.9 required=10.0 tests=ALL_TRUSTED,FB_GET_MEDS X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Nov 2008 11:43:45 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0583D23888E6; Wed, 19 Nov 2008 03:44:00 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r718935 - in /incubator/sling/trunk: jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/ launchpad/base/src/main/java/org/apache/sling/launcher/app/ launchpad/base/src/main/java/org/apache/sling/launcher/webapp/ laun... Date: Wed, 19 Nov 2008 11:43:59 -0000 To: sling-commits@incubator.apache.org From: jvazquez@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081119114400.0583D23888E6@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jvazquez Date: Wed Nov 19 03:43:59 2008 New Revision: 718935 URL: http://svn.apache.org/viewvc?rev=718935&view=rev Log: RESOLVED - issue SLING-739: Improve the Sling Embedded repository config to make it more flexible https://issues.apache.org/jira/browse/SLING-739 Modified: incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/Activator.java incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/webapp/SlingServlet.java incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties incubator/sling/trunk/launchpad/webapp/src/main/webapp/WEB-INF/web.xml 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=718935&r1=718934&r2=718935&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 Wed Nov 19 03:43:59 2008 @@ -18,6 +18,8 @@ import java.io.File; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Hashtable; import org.apache.sling.jcr.base.util.RepositoryAccessor; @@ -65,7 +67,11 @@ private String slingContext; protected String getRepositoryName() { - return "jackrabbit"; + String repoName = bundleContext.getProperty("sling.repository.name"); + if (repoName != null) + return repoName; // the repository name is set + else + return "jackrabbit"; } public void start(BundleContext context) { @@ -167,28 +173,11 @@ } private void initDefaultConfig(Hashtable props, BundleContext bundleContext) throws IOException { - File homeDir; - String slingHomePath = bundleContext.getProperty("sling.home"); - if (slingHomePath != null) { - homeDir = new File(slingHomePath, getRepositoryName()); - } else { - homeDir = new File(getRepositoryName()); - } - - // make sure jackrabbit home exists - log.info("Creating default config for Jackrabbit in " + homeDir); - if (!homeDir.isDirectory()) { - if (!homeDir.mkdirs()) { - log.info("verifyConfiguration: Cannot create Jackrabbit home " - + homeDir + ", failed creating default configuration"); - return; - } - } - - // ensure the configuration file (inside the home Dir !) - File configFile = new File(homeDir, "repository.xml"); - SlingServerRepository.copyFile(bundleContext.getBundle(), - "repository.xml", configFile); + File homeDir = getHomeDir(bundleContext); + if (homeDir == null) + return; + + File configFile = getConfigFile(bundleContext, homeDir); // default config values props.put(SLING_CONTEXT, slingContext); @@ -199,4 +188,58 @@ props.put(SlingServerRepository.REPOSITORY_REGISTRATION_NAME, this.getRepositoryName()); } + + private File getHomeDir(BundleContext bundleContext) throws IOException { + File homeDir; + + String repoHomePath = bundleContext.getProperty("sling.repository.home"); + String slingHomePath = bundleContext.getProperty("sling.home"); + + if (repoHomePath != null) { + homeDir = new File(repoHomePath, getRepositoryName()); + } else if (slingHomePath != null) { + homeDir = new File(slingHomePath, getRepositoryName()); + } else { + homeDir = new File(getRepositoryName()); + } + + // make sure jackrabbit home exists + log.info("Creating default config for Jackrabbit in " + homeDir); + if (!homeDir.isDirectory()) { + if (!homeDir.mkdirs()) { + log.info("verifyConfiguration: Cannot create Jackrabbit home " + + homeDir + ", failed creating default configuration"); + return null; + } + } + + return homeDir; + } + + private File getConfigFile(BundleContext bundleContext, File homeDir) throws IOException { + File configFile; + + String repoConfigFileUrl = bundleContext.getProperty("sling.repository.config.file.url"); + if (repoConfigFileUrl != null) { + // the repository config file is set + URL configFileUrl = null; + try { + configFileUrl = new URL(repoConfigFileUrl); + } catch (MalformedURLException e) { + // this not an url, trying with "file:" + configFileUrl = new URL("file://" + repoConfigFileUrl); + } + + // local support only + configFile = new File(configFileUrl.getFile()); + if (configFile.canRead()) + return configFile; + } + + // ensure the configuration file (inside the home Dir !) + configFile = new File(homeDir, "repository.xml"); + SlingServerRepository.copyFile(bundleContext.getBundle(), "repository.xml", configFile); + return configFile; + } + } Modified: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java?rev=718935&r1=718934&r2=718935&view=diff ============================================================================== --- incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java (original) +++ incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java Wed Nov 19 03:43:59 2008 @@ -109,6 +109,28 @@ * @see #SLING_HOME */ public static final String SLING_HOME_URL = "sling.home.url"; + + /** + * The name of the configuration property defining the JCR home directory + * (value is "sling.repository.home"). + *

+ * The value of this property could be set as a system property, init-param in + * web.xml or property in sling.properties. + *

+ * Default value to #SLING_HOME/repository_name + */ + public static final String JCR_REPO_HOME = "sling.repository.home"; + + /** + * The name of the configuration property defining the URL of an existing + * repository config file (repository.xml). + *

+ * The value of this property could be set as a system property, init-param in + * web.xml or property in sling.properties. + *

+ * Default value to #SLING_HOME/repository_name/repository.xml + */ + public static final String JCR_REPO_CONFIG_FILE_URL = "sling.repository.config.file.url"; /** * The name of the configuration property defining a properties file @@ -172,7 +194,7 @@ */ public Sling(Logger logger, ResourceProvider resourceProvider, Map propOverwrite) throws BundleException { - + this.logger = logger; this.resourceProvider = resourceProvider; Modified: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/webapp/SlingServlet.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/webapp/SlingServlet.java?rev=718935&r1=718934&r2=718935&view=diff ============================================================================== --- incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/webapp/SlingServlet.java (original) +++ incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/webapp/SlingServlet.java Wed Nov 19 03:43:59 2008 @@ -18,6 +18,7 @@ import static org.apache.felix.framework.util.FelixConstants.LOG_LEVEL_PROP; +import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -122,7 +123,7 @@ * The name of the configuration property defining the obr repository. */ private static final String OBR_REPOSITORY_URL = "obr.repository.url"; - + /** * The Felix instance loaded on {@link #init()} and stopped * on {@link #destroy()}. @@ -284,18 +285,37 @@ // assume that this location is inside the webapp and create the correct // full url final String repoLocation = props.get(OBR_REPOSITORY_URL); - if (repoLocation != null && repoLocation.indexOf(":/") < 1 - && repoLocation.startsWith("/")) { - try { - final URL url = getServletContext().getResource(repoLocation); - // only if we get back a resource url, we update it - if (url != null) { - props.put(OBR_REPOSITORY_URL, url.toExternalForm()); - } - } catch (MalformedURLException e) { - // if an exception occurs, we ignore it - } + if (insideWebapp(repoLocation)) { + final URL url = getUrl(repoLocation); + // only if we get back a resource url, we update it + if (url != null) + props.put(OBR_REPOSITORY_URL, url.toExternalForm()); + } + + // idem to jcr repo home + final String jcrRepoHome = props.get(Sling.JCR_REPO_HOME); + if (insideWebapp(jcrRepoHome)) { + // ensure exists + final URL webroot = getUrl("/"); + File jcrRepoHomeDir = new File(webroot.getPath() + jcrRepoHome); + if (!jcrRepoHomeDir.isDirectory()) + jcrRepoHomeDir.mkdirs(); + + final URL url = getUrl(jcrRepoHome); + // only if we get back a resource url, we update it + if (url != null) + props.put(Sling.JCR_REPO_HOME, url.getPath()); } + + // idem to jcr repo config file + final String jcrRepoConfigFile = props.get(Sling.JCR_REPO_CONFIG_FILE_URL); + if (insideWebapp(jcrRepoConfigFile)) { + final URL url = getUrl(jcrRepoConfigFile); + // only if we get back a resource url, we update it + if (url != null) + props.put(Sling.JCR_REPO_CONFIG_FILE_URL, url.toExternalForm()); + } + return props; } @@ -317,6 +337,21 @@ props.put(LOG_LEVEL_PROP, String.valueOf(logLevel)); } } + + private boolean insideWebapp(String path) { + if (path != null && path.indexOf(":/") < 1 && path.startsWith("/")) + return true; + else + return false; + } + + private URL getUrl(String path) { + try { + return getServletContext().getResource(path); + } catch (MalformedURLException e) { + return null; + } + } private static class ServletContextLogger extends Logger { private ServletContext servletContext; Modified: incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties?rev=718935&r1=718934&r2=718935&view=diff ============================================================================== --- incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties (original) +++ incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties Wed Nov 19 03:43:59 2008 @@ -37,6 +37,19 @@ # property of such generated configurations. sling.context.default = default +# +# The name of the JCR repository. Default is "jackrabbit". +# sling.repository.name = + +# +# The JCR repository home directory. Default is sling.home/sling.repository.name. +# sling.repository.home = + +# +# The JCR repository url config file (repository.xml). Default is repository.xml in +# bundle Embedded JCR Repository +# sling.repository.config.file.url = + # # List of packages to append to the org.osgi.framework.system.packages property Modified: incubator/sling/trunk/launchpad/webapp/src/main/webapp/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/webapp/src/main/webapp/WEB-INF/web.xml?rev=718935&r1=718934&r2=718935&view=diff ============================================================================== --- incubator/sling/trunk/launchpad/webapp/src/main/webapp/WEB-INF/web.xml (original) +++ incubator/sling/trunk/launchpad/webapp/src/main/webapp/WEB-INF/web.xml Wed Nov 19 03:43:59 2008 @@ -29,6 +29,36 @@ org.apache.sling.launcher.webapp.SlingServlet + + + + + + 100