File Source: TaskRunner.java

         /* 
    P/P   *  Method: org.apache.roller.weblogger.business.runnable.TaskRunner__static_init
          */
     1  /*
     2  * Licensed to the Apache Software Foundation (ASF) under one or more
     3  *  contributor license agreements.  The ASF licenses this file to You
     4  * under the Apache License, Version 2.0 (the "License"); you may not
     5  * use this file except in compliance with the License.
     6  * You may obtain a copy of the License at
     7  *
     8  *     http://www.apache.org/licenses/LICENSE-2.0
     9  *
    10  * Unless required by applicable law or agreed to in writing, software
    11  * distributed under the License is distributed on an "AS IS" BASIS,
    12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  * See the License for the specific language governing permissions and
    14  * limitations under the License.  For additional information regarding
    15  * copyright in this work, please see the NOTICE file in the top level
    16  * directory of this distribution.
    17  */
    18  package org.apache.roller.weblogger.business.runnable;
    19          
    20  import java.io.File;
    21  import org.apache.roller.weblogger.util.StandaloneWebappClassLoader;
    22  
    23  /**
    24   * Sets up classpath for running a Roller task outside of the Roller webapp. 
    25   */
    26  public class TaskRunner {   
    27      
             /* 
    P/P       *  Method: void org.apache.roller.weblogger.business.runnable.TaskRunner()
              */
    28      public TaskRunner() {} 
    29      
    30      public static void main(String[] args) throws Exception {
                 /* 
    P/P           *  Method: void main(String[])
                  * 
                  *  Preconditions:
                  *    args != null
                  *    args.length >= 3
                  *    init'ed(args[0])
                  *    init'ed(args[1])
                  *    init'ed(args[2])
                  * 
                  *  Presumptions:
                  *    java.lang.ClassLoader:loadClass(...)@60 != null
                  *    java.lang.System.err != null
                  *    java.lang.System.out != null
                  *    java.lang.Thread:currentThread(...)@57 != null
                  * 
                  *  Test Vectors:
                  *    java.io.File:isDirectory(...)@49: {0}, {1}
                  *    java.io.File:isDirectory(...)@49: {1}, {0}
                  */
+   31          if (args.length < 3) {
+   32              System.err.println("USAGE: java -cp roller-planet.jar TaskRunner WEBAPPDIR JARSDIR CLASSNAME");
    33              System.err.println("WEBAPPDIR: The directory path to the web application ");
    34              System.err.println("           (e.g. $CATALINA_HOME/webapps/roller)");
    35              System.err.println("JARSDIR:   The directory path to the additional jars ");
    36              System.err.println("           directory (e.g. $CATALINA_HOME/common/lib)");
    37              System.err.println("CLASSNAME: The name of the class to be executed by TaskRunner ");
    38              System.exit(-1);
    39          }
    40          String webappDir     = args[0];
    41          String jarsDir       = args[1];
    42          String taskClassName = args[2];
    43          System.out.println("WEBAPPDIR = " + webappDir); 
    44          System.out.println("JARSDIR   = " + jarsDir);
    45          System.out.println("CLASSNAME = " + taskClassName);
    46          
    47          File webappDirFile = new File(webappDir);
    48          File jarsDirFile = new File(jarsDir);
    49          if (!webappDirFile.isDirectory() || !jarsDirFile.isDirectory()) {
    50              System.err.println("ERROR: webapp.dir and jars.dir must specify existing directories");
    51              System.exit(-1);
    52          }        
    53          
    54          ClassLoader cl = new StandaloneWebappClassLoader(webappDir, jarsDir, null);
    55         
    56          // We're using the new classloader from here on out
    57          Thread.currentThread().setContextClassLoader(cl);
    58  
    59          // Go!
    60          Class taskClass = cl.loadClass(taskClassName);
    61          Runnable task = (Runnable)taskClass.newInstance();
    62          task.run();
    63      }
    64  }
    65  
    66  
    67  /* for example:
    68   
    69  java \
    70      -Dplanet.custom.config=planet-custom.properties \
    71      -Dcatalina.base=. \
    72      -cp ./build/webapp/WEB-INF/lib/roller-business.jar \
    73      org.apache.roller.weblogger.business.runnable.TaskRunner \
    74      ~/roller_trunk/sandbox/planetroller/build/webapp \
    75      /Applications/Java/jakarta-tomcat-5.5.9/common/lib \
    76      org.apache.roller.weblogger.planet.tasks.GeneratePlanetTask
    77   
    78   */








SofCheck Inspector Build Version : 2.18479
TaskRunner.java 2009-Jan-02 14:24:50
TaskRunner.class 2009-Sep-04 03:12:31