roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r465057 - in /incubator/roller/trunk: ./ metadata/database/hibernate/ sandbox/planetroller/ sandbox/planetroller/src/org/apache/roller/planet/business/hibernate/ sandbox/scripting/groovy/ src/org/apache/roller/business/hibernate/ src/org/ap...
Date Tue, 17 Oct 2006 21:16:34 GMT
Author: snoopdave
Date: Tue Oct 17 14:16:33 2006
New Revision: 465057

URL: http://svn.apache.org/viewvc?view=rev&rev=465057
Log:
Added TaskRunner so make it easier to run Roller tasks from the command line
and from cron or cron-like O/S facilities.

Added these properties to make the Hibernate dialect and config configurable 
from a roller-custom.properties override file:

    # Hibernate dialect: You must override this to use a database other than MySQL4
    hibernate.dialect=org.hibernate.dialect.MySQLDialect

    # Hibernate config resource (a classpath-based path)
    # NO NEED TO OVERRIDE this unless you are customizing Roller
    hibernate.configResource=/hibernate.cfg.xml

    # JDBC configuration parameters for standalone tasks
    # Don't override these in the roller-custom.properties file you use with the 
    # Roller webapp, but for the standalone tasks that you run outside of Roller 
    # (e.g. refresh entries) you'll need to override these properties. Do it in a 
    # separate roller-custom.properties file.
    jdbc.driverClass=
    jdbc.connectionURL=
    jdbc.username=
    jdbc.password=

And changed HibernateRollerImpl to use JDBC params if jdbc.driverClass is 
not null or empty.

Added:
    incubator/roller/trunk/src/org/apache/roller/business/runnable/TaskRunner.java
Removed:
    incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/business/hibernate/PlanetHibernatePersistenceStrategy.java
    incubator/roller/trunk/testdata/WEB-INF/classes/hibernate.cfg.xml
Modified:
    incubator/roller/trunk/build.xml
    incubator/roller/trunk/metadata/database/hibernate/hibernate.cfg.xml
    incubator/roller/trunk/sandbox/planetroller/build.xml
    incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/business/hibernate/HibernatePlanetImpl.java
    incubator/roller/trunk/sandbox/scripting/groovy/run-groovy
    incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernatePersistenceStrategy.java
    incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java
    incubator/roller/trunk/testdata/roller-custom.properties
    incubator/roller/trunk/web/WEB-INF/classes/roller.properties

Modified: incubator/roller/trunk/build.xml
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/build.xml?view=diff&rev=465057&r1=465056&r2=465057
==============================================================================
--- incubator/roller/trunk/build.xml (original)
+++ incubator/roller/trunk/build.xml Tue Oct 17 14:16:33 2006
@@ -872,8 +872,7 @@
         includeantruntime="false"
         debug="${build.debug}" 
         source="${build.sourcelevel}"
-        deprecation="${build.deprecation}">
-        
+        deprecation="${build.deprecation}">        
         <src path="${ro.tests}" />
         
         &custom-src-tests;
@@ -883,7 +882,7 @@
             &custom-jars;
         </classpath>
     </javac>
-    
+                
     <!-- Copy test resources -->
     <copy todir="${build.compile.tests}">
         <fileset dir="${ro.tests}" 
@@ -907,6 +906,11 @@
         </fileset>
     </copy>
     
+    <copy todir="${build.tests}/WEB-INF/classes">
+        <fileset dir="${basedir}/metadata/database/hibernate/" 
+            includes="hibernate.cfg.xml" />
+    </copy>
+
     <!-- 
     Copy custom testing files which will overwrite some config files 
     -->
@@ -943,21 +947,21 @@
         <formatter type="xml"/>
         <batchtest toDir="${build.reports}/business/xml">
             <fileset dir="${build.compile.tests}">
-		<include name="org/apache/roller/business/BookmarkTest.class"/>
-		<include name="org/apache/roller/business/UserTest.class"/> 
-	        <include name="org/apache/roller/business/WeblogTest.class"/>
-	        <include name="org/apache/roller/business/PermissionTest.class"/>
-	        <include name="org/apache/roller/business/WeblogPageTest.class"/>
-	        <include name="org/apache/roller/business/PingsTest.class"/>
-	        <include name="org/apache/roller/business/PropertiesTest.class"/>
-	        <include name="org/apache/roller/business/WeblogEntryTest.class"/>
-	        <include name="org/apache/roller/business/WeblogCategoryTest.class"/>
-	        <include name="org/apache/roller/business/CommentTest.class"/>
-		<include name="org/apache/roller/business/FileManagerTest.class"/>
-		<include name="org/apache/roller/business/IndexManagerTest.class"/>
-	        <include name="org/apache/roller/business/PlanetManagerTest.class"/>
-		<include name="org/apache/roller/business/RefererTest.class"/>
-		<include name="org/apache/roller/business/PluginManagerTest.class"/>
+                <include name="org/apache/roller/business/BookmarkTest.class"/>
+                <include name="org/apache/roller/business/UserTest.class"/> 
+                <include name="org/apache/roller/business/WeblogTest.class"/>
+                <include name="org/apache/roller/business/PermissionTest.class"/>
+                <include name="org/apache/roller/business/WeblogPageTest.class"/>
+                <include name="org/apache/roller/business/PingsTest.class"/>
+                <include name="org/apache/roller/business/PropertiesTest.class"/>
+                <include name="org/apache/roller/business/WeblogEntryTest.class"/>
+                <include name="org/apache/roller/business/WeblogCategoryTest.class"/>
+                <include name="org/apache/roller/business/CommentTest.class"/>
+                <include name="org/apache/roller/business/FileManagerTest.class"/>
+                <include name="org/apache/roller/business/IndexManagerTest.class"/>
+                <include name="org/apache/roller/business/PlanetManagerTest.class"/>
+                <include name="org/apache/roller/business/RefererTest.class"/>
+                <include name="org/apache/roller/business/PluginManagerTest.class"/>
             </fileset>
         </batchtest>
     </junit>

Modified: incubator/roller/trunk/metadata/database/hibernate/hibernate.cfg.xml
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/metadata/database/hibernate/hibernate.cfg.xml?view=diff&rev=465057&r1=465056&r2=465057
==============================================================================
--- incubator/roller/trunk/metadata/database/hibernate/hibernate.cfg.xml (original)
+++ incubator/roller/trunk/metadata/database/hibernate/hibernate.cfg.xml Tue Oct 17 14:16:33
2006
@@ -21,53 +21,18 @@
         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
 <hibernate-configuration>
     <session-factory>
-    
-        <!-- By default Roller uses a JNDI DataSource -->
+        
+        <!-- You can override this via the jdbc.XXX properties in roller-custom.properties
-->
         <property name="connection.datasource">java:comp/env/jdbc/rollerdb</property>
+                        
+        <!-- You can override this via the hibernate.dialect property in roller-custom.properties
-->
+        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
+                       
         <property name="show_sql">false</property>
-        
+
         <!-- use thread local Session context -->
         <property name="hibernate.current_session_context_class">thread</property>
-        
-        
-        <!-- select SQL dialect, MySQL 3.X or 4.X by default -->
-        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
-        <!--
-        If you want to use HSQLDB, PostgreSQL, DB2 or Derby, Oracle, SQLServer then use the
right dialect   
-        <property name="dialect">org.hibernate.dialect.HQLDBDialect</property>

-        <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
-        <property name="dialect">org.hibernate.dialect.DB2Dialect</property>
-        <property name="dialect">org.hibernate.dialect.DerbyDialect</property>
-        <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
-        <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
-
-        For MySQL 5.X, use the MySQL5 dialect and J/Connector 3.1.X
-        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
-        -->
-
-        <!--
-        Examples for configuring Hibernate to use the JDBC Driver Manager
-        <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
-        <property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost:3219</property>
-        <property name="hibernate.connection.username">sa</property>
-        <property name="hibernate.connection.password"></property>
-        <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
 
-        <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
-        <property name="hibernate.connection.url">
-                        jdbc:mysql://localhost/roller?user=roller&amp;password=tiger</property>
-        <property name="hibernate.connection.username">roller</property>
-        <property name="hibernate.connection.password">tiger</property>
-        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
-
-        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
-        <property name="hibernate.connection.url">jdbc:postgresql://localhost/rollerdb</property>
-        <property name="hibernate.connection.username">scott</property>
-        <property name="hibernate.connection.password">tiger</property>
-        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
-        -->
-
-        
         <!-- Hibernate L2 Caching -->
         <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
         <property name="hibernate.generate_statistics">true</property>

Modified: incubator/roller/trunk/sandbox/planetroller/build.xml
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/planetroller/build.xml?view=diff&rev=465057&r1=465056&r2=465057
==============================================================================
--- incubator/roller/trunk/sandbox/planetroller/build.xml (original)
+++ incubator/roller/trunk/sandbox/planetroller/build.xml Tue Oct 17 14:16:33 2006
@@ -21,7 +21,7 @@
 
     <property file="./ant.properties" />
     
-    <fileset id="roller-jars" dir="${rollerjars.dir}">        
+    <fileset id="roller-jars" dir="${rollersrc.dir}/build/webapp/WEB-INF/lib">    
   
         <include name="roller-business.jar"/>        
         
         <include name="hibernate3.jar"/>

Modified: incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/business/hibernate/HibernatePlanetImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/business/hibernate/HibernatePlanetImpl.java?view=diff&rev=465057&r1=465056&r2=465057
==============================================================================
--- incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/business/hibernate/HibernatePlanetImpl.java
(original)
+++ incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/business/hibernate/HibernatePlanetImpl.java
Tue Oct 17 14:16:33 2006
@@ -25,8 +25,6 @@
 import org.apache.roller.planet.config.PlanetConfig;
 import org.apache.roller.planet.model.PlanetManager;
 import org.apache.roller.planet.model.Planet;
-import org.hibernate.cfg.Configuration;
-
 
 /**
  * A Hibernate specific implementation of the Roller business layer.
@@ -53,7 +51,7 @@
         try {
             if (StringUtils.isNotEmpty(PlanetConfig.getProperty("jdbc.driverClass"))) {
                 // create and configure for JDBC access
-                strategy = new PlanetHibernatePersistenceStrategy(
+                strategy = new HibernatePersistenceStrategy(
                     PlanetConfig.getProperty("hibernate.configResource"),
                     PlanetConfig.getProperty("hibernate.dialect"),
                     PlanetConfig.getProperty("jdbc.driverClass"),
@@ -62,7 +60,9 @@
                     PlanetConfig.getProperty("jdbc.password"));
             } else {
                 // create an configure via config resource only
-                strategy = new HibernatePersistenceStrategy(true); 
+                strategy = new HibernatePersistenceStrategy(
+                    PlanetConfig.getProperty("hibernate.configResource"),
+                    PlanetConfig.getProperty("hibernate.dialect")); 
             }
         } catch(Throwable t) {
             // if this happens then we are screwed

Modified: incubator/roller/trunk/sandbox/scripting/groovy/run-groovy
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/scripting/groovy/run-groovy?view=diff&rev=465057&r1=465056&r2=465057
==============================================================================
--- incubator/roller/trunk/sandbox/scripting/groovy/run-groovy (original)
+++ incubator/roller/trunk/sandbox/scripting/groovy/run-groovy Tue Oct 17 14:16:33 2006
@@ -1,8 +1,9 @@
 #!/bin/bash
 
-export GROOVY_HOME=/Applications/Java/groovy
+export GROOVY_HOME=~/java/groovy
 export ROLLER_HOME=~/roller_trunk/build/webapp
-export JDBCJAR=$CATALINA_HOME/common/lib/derbyclient.jar
+export JDBCJAR=$CATALINA_HOME/common/lib/mysql-connector-java-3.1.13-bin.jar
+#export JDBCJAR=$CATALINA_HOME/common/lib/derbyclient.jar
 
 #export GROOVY_HOME=~/java/groovy
 #export ROLLER_HOME=../../standalone/build/roller-demo/webapps/roller

Modified: incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernatePersistenceStrategy.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernatePersistenceStrategy.java?view=diff&rev=465057&r1=465056&r2=465057
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernatePersistenceStrategy.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernatePersistenceStrategy.java
Tue Oct 17 14:16:33 2006
@@ -18,6 +18,7 @@
 
 package org.apache.roller.business.hibernate;
 
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -32,6 +33,11 @@
 import org.apache.roller.pojos.Assoc;
 import org.apache.roller.pojos.HierarchicalPersistentObject;
 import org.apache.roller.pojos.PersistentObject;
+import org.jdom.Attribute;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.DOMOutputter;
 
 
 /**
@@ -52,18 +58,120 @@
     
     
     public HibernatePersistenceStrategy() {
+    }   
+
+    /** 
+     * Construct self using Hibernate config resource and optional dialect.
+     * @param configResouce Classpath-based path to Hibernate config file (e.g. "/hibernate.cgf.xml")
+     * @parma dialect Classname of Hibernate dialect to be used (overriding any specified
in the configResource)
+     */
+    public HibernatePersistenceStrategy(
+            String configResource,
+            String dialect) throws Exception {
+        
+        // read configResource into DOM form
+        SAXBuilder builder = new SAXBuilder();
+        Document configDoc = builder.build(
+            getClass().getResourceAsStream(configResource));
+        Element root = configDoc.getRootElement();
+        Element sessionFactoryElem = root.getChild("session-factory");
+        
+        // remove any existing connection.datasource and dialect properties
+        List propertyElems = sessionFactoryElem.getChildren("property");
+        List removeList = new ArrayList();
+        for (Iterator it = propertyElems.iterator(); it.hasNext();) {
+            Element elem = (Element) it.next();
+            if (elem.getAttribute("name") != null 
+                && elem.getAttribute("name").getValue().equals("dialect")) {
+                removeList.add(elem);           
+            }
+        }
+        for (Iterator it = removeList.iterator(); it.hasNext();) {
+            Element elem = (Element) it.next();
+            sessionFactoryElem.removeContent(elem); 
+        }
+        
+        // add Roller dialect property      
+        Element prop = new Element("property").setAttribute(
+            new Attribute("name","dialect"));
+        prop.addContent(dialect);
+        sessionFactoryElem.addContent(prop);
+        
+        Configuration config = new Configuration();
+        DOMOutputter outputter = new DOMOutputter();
+        config.configure(outputter.output(configDoc));
+        this.sessionFactory = config.buildSessionFactory(); 
     }
     
-    /**
-     * Construct using Hibernate Session Factory.
+    /** 
+     * Construct self using Hibernate config resource and optional dialect.
+     * @param configResouce Classpath-based path to Hibernate config file (e.g. "/hibernate.cgf.xml")
+     * @parma dialect Classname of Hibernate dialect to be used (or null to use one specified
in configResource)
      */
-    public HibernatePersistenceStrategy(boolean configure) throws Exception {
-        if (configure) {
-            log.debug("Initializing Hibernate SessionFactory");
-            Configuration config = new Configuration();
-            config.configure("/hibernate.cfg.xml");
-            this.sessionFactory = config.buildSessionFactory();
+    public HibernatePersistenceStrategy(
+            String configResource,
+            String dialect,
+            String driverClass,
+            String connectionURL,
+            String username,
+            String password) throws Exception {
+        
+        // read configResource into DOM form
+        SAXBuilder builder = new SAXBuilder();
+        Document configDoc = builder.build(
+            getClass().getResourceAsStream(configResource));
+        Element root = configDoc.getRootElement();
+        Element sessionFactoryElem = root.getChild("session-factory");
+        
+        // remove any existing connection.datasource and dialect properties
+        List propertyElems = sessionFactoryElem.getChildren("property");
+        List removeList = new ArrayList();
+        for (Iterator it = propertyElems.iterator(); it.hasNext();) {
+            Element elem = (Element) it.next();
+            if (elem.getAttribute("name") != null 
+                && elem.getAttribute("name").getValue().equals("connection.datasource"))
{
+                removeList.add(elem);
+            }
+            if (elem.getAttribute("name") != null 
+                && elem.getAttribute("name").getValue().equals("dialect")) {
+                removeList.add(elem);
+            }
+        }
+        for (Iterator it = removeList.iterator(); it.hasNext();) {
+            Element elem = (Element) it.next();
+            sessionFactoryElem.removeContent(elem); 
         }
+                                       
+        // add JDBC connection params instead
+        Element prop = new Element("property").setAttribute(
+            new Attribute("name","hibernate.connection.driver_class"));
+        prop.addContent(driverClass);
+        sessionFactoryElem.addContent(prop);
+
+        prop = new Element("property").setAttribute(
+            new Attribute("name","hibernate.connection.url"));
+        prop.addContent(connectionURL);
+        sessionFactoryElem.addContent(prop);
+        
+        prop = new Element("property").setAttribute(
+            new Attribute("name","hibernate.connection.username"));
+        prop.addContent(username);
+        sessionFactoryElem.addContent(prop);
+        
+        prop = new Element("property").setAttribute(
+            new Attribute("name","hibernate.connection.password"));
+        prop.addContent(password);
+        sessionFactoryElem.addContent(prop);
+        
+        prop = new Element("property").setAttribute(
+            new Attribute("name","dialect"));
+        prop.addContent(dialect);
+        sessionFactoryElem.addContent(prop);
+        
+        Configuration config = new Configuration();
+        DOMOutputter outputter = new DOMOutputter();
+        config.configure(outputter.output(configDoc));
+        this.sessionFactory = config.buildSessionFactory();
     }
     
     

Modified: incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java?view=diff&rev=465057&r1=465056&r2=465057
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java
Tue Oct 17 14:16:33 2006
@@ -18,11 +18,12 @@
 
 package org.apache.roller.business.hibernate;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.RollerException;
 import org.apache.roller.business.RollerImpl;
-import org.apache.roller.business.ThreadManagerImpl;
+import org.apache.roller.config.RollerConfig;
 import org.apache.roller.model.BookmarkManager;
 import org.apache.roller.model.ConfigManager;
 import org.apache.roller.model.AutoPingManager;
@@ -68,7 +69,21 @@
     
     protected HibernateRollerImpl() throws RollerException {
         try {
-            strategy = new HibernatePersistenceStrategy(true);
+            if (StringUtils.isNotEmpty(RollerConfig.getProperty("jdbc.driverClass"))) {
+                // create and configure for JDBC access
+                strategy = new HibernatePersistenceStrategy(
+                    RollerConfig.getProperty("hibernate.configResource"),
+                    RollerConfig.getProperty("hibernate.dialect"),
+                    RollerConfig.getProperty("jdbc.driverClass"),
+                    RollerConfig.getProperty("jdbc.connectionURL"),
+                    RollerConfig.getProperty("jdbc.username"),
+                    RollerConfig.getProperty("jdbc.password"));
+            } else {
+                // create an configure via config resource only
+                strategy = new HibernatePersistenceStrategy(
+                    RollerConfig.getProperty("hibernate.configResource"),
+                    RollerConfig.getProperty("hibernate.dialect"));
+            }
         } catch(Throwable t) {
             // if this happens then we are screwed
             mLogger.fatal("Error initializing Hibernate", t);

Added: incubator/roller/trunk/src/org/apache/roller/business/runnable/TaskRunner.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/runnable/TaskRunner.java?view=auto&rev=465057
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/runnable/TaskRunner.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/business/runnable/TaskRunner.java Tue Oct
17 14:16:33 2006
@@ -0,0 +1,110 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+*  contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.roller.business.runnable;
+        
+import java.io.File;
+import java.io.FilenameFilter;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Sets up classpath for Roller and runs a task. 
+ * Expects these JVM parameters:
+ * webapp.dir must specify Roller webapp directory
+ * jars.dir must specify additional jars directory (e.g. Tomcat commons/lib)
+ */
+public class TaskRunner {
+    
+    public static String WEBAPP_DIR = "webapp.dir"; 
+    public static String JARS_DIR = "jars.dir"; 
+    public static String FS = File.separator;
+    
+    public TaskRunner() {}
+    
+    public static void main(String[] args) throws Exception {
+        if (args.length < 1) {
+            System.err.println("USAGE: java -Dwebapp.dir=WEBAPPDIR -Djars.dir=JARSDIR -cp
roller-planet.jar TaskRunner CLASSNAME");
+            System.err.println("WEBAPPDIR: The directory path to the web application ");
+            System.err.println("           (e.g. $CATALINA_HOME/webapps/roller)");
+            System.err.println("JARSDIR:   The directory path to the additional jars ");
+            System.err.println("           directory (e.g. $CATALINA_HOME/common/lib)");
+            System.err.println("CLASSNAME: The name of the class to be executed by TaskRunner
");
+            System.exit(-1);
+        }
+        String taskClassName = args[0];
+        String webappDir = System.getProperties().getProperty(WEBAPP_DIR);
+        String jarsDir = System.getProperties().getProperty(WEBAPP_DIR);
+        if (webappDir == null || jarsDir == null) {
+            System.err.println("ERROR: system properties webapp.dir and jars.dir not found");
+            System.exit(-1);
+        }
+        
+        File webappDirFile = new File(webappDir);
+        File jarsDirFile = new File(jarsDir);
+        if (!webappDirFile.isDirectory() || !jarsDirFile.isDirectory()) {
+            System.err.println("ERROR: webapp.dir and jars.dir must specify existing directories");
+            System.exit(-1);
+        }        
+        
+        // Create collection of URLs needed for classloader
+        List urlList = new ArrayList();
+
+        // Add WEB-INF/lib jars
+        String libPath = webappDir + FS + "WEB-INF" + FS + "lib";
+        addURLs(libPath, urlList);
+        
+        // Added WEB-INF/classes
+        String classesPath = System.getProperties().getProperty(WEBAPP_DIR) 
+                + FS + "WEB-INF" + FS + "classes" + FS;
+        urlList.add(new URL("file://" + classesPath));
+        
+        // Add additional jars
+        String jarsPath = System.getProperties().getProperty(JARS_DIR);
+        addURLs(jarsPath, urlList);
+        
+        // Create classloader and make it load the task class to be run
+        URLClassLoader cl = URLClassLoader.newInstance(
+            (URL[])urlList.toArray(new URL[urlList.size()]), null);
+        Class taskClass = cl.loadClass(taskClassName);
+        Runnable task = (Runnable)taskClass.newInstance();
+        
+        // We're using the new classloader from here on out
+        Thread.currentThread().setContextClassLoader(cl);
+        
+        // Go!
+        task.run();
+    }
+    
+    private static void addURLs(String dirPath, List urlList) throws Exception {
+        File libDir = new File(dirPath);
+        String[] libJarNames = libDir.list(new FilenameFilter() {
+            public boolean accept(File dir, String pathname) {
+                if (pathname.endsWith(".jar")) {
+                    return true;
+                }
+                return false;
+            }
+        });       
+        for (int i=0; i<libJarNames.length; i++) {
+            String url = "file://" + dirPath + FS + libJarNames[i];
+            urlList.add(new URL(url));
+        }
+    }
+}

Modified: incubator/roller/trunk/testdata/roller-custom.properties
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/testdata/roller-custom.properties?view=diff&rev=465057&r1=465056&r2=465057
==============================================================================
--- incubator/roller/trunk/testdata/roller-custom.properties (original)
+++ incubator/roller/trunk/testdata/roller-custom.properties Tue Oct 17 14:16:33 2006
@@ -1,3 +1,12 @@
+
 # Uncomment this to use JDO backend
 #persistence.roller.classname=org.apache.roller.business.JDO.JDORollerImpl
-search.index.dir=search-index
\ No newline at end of file
+
+search.index.dir=search-index
+
+jdbc.driverClass=org.hsqldb.jdbcDriver
+jdbc.connectionURL=jdbc:hsqldb:hsql://localhost:3219
+jdbc.username=sa
+jdbc.password=
+
+hibernate.dialect=org.hibernate.dialect.HSQLDialect
\ No newline at end of file

Modified: incubator/roller/trunk/web/WEB-INF/classes/roller.properties
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/web/WEB-INF/classes/roller.properties?view=diff&rev=465057&r1=465056&r2=465057
==============================================================================
--- incubator/roller/trunk/web/WEB-INF/classes/roller.properties (original)
+++ incubator/roller/trunk/web/WEB-INF/classes/roller.properties Tue Oct 17 14:16:33 2006
@@ -41,6 +41,26 @@
 #    RollerConfig.getProperty("propname");
 
 #---------------------------------
+# Database configuration settings
+
+# Hibernate dialect: You must override this to use a database other than MySQL4
+hibernate.dialect=org.hibernate.dialect.MySQLDialect
+
+# Hibernate config resource (a classpath-based path)
+# NO NEED TO OVERRIDE this unless you are customizing Roller
+hibernate.configResource=/hibernate.cfg.xml
+
+# JDBC configuration parameters for standalone tasks
+# Don't override these in the roller-custom.properties file you use with the 
+# Roller webapp, but for the standalone tasks that you run outside of Roller 
+# (e.g. refresh entries) you'll need to override these properties. Do it in a 
+# separate roller-custom.properties file.
+jdbc.driverClass=
+jdbc.connectionURL=
+jdbc.username=
+jdbc.password=
+
+#---------------------------------
 # User management settings
 
 # True to enable group blogging. False to prevent users from creating more 



Mime
View raw message