//# 0 errors, 37 messages
//#
/*
    //#TaskRunner.java:1:1: class: org.apache.roller.weblogger.business.runnable.TaskRunner
    //#TaskRunner.java:1:1: method: org.apache.roller.weblogger.business.runnable.TaskRunner.org.apache.roller.weblogger.business.runnable.TaskRunner__static_init
* 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.weblogger.business.runnable;
        
import java.io.File;
import org.apache.roller.weblogger.util.StandaloneWebappClassLoader;

/**
 * Sets up classpath for running a Roller task outside of the Roller webapp. 
 */
public class TaskRunner {   
    
    public TaskRunner() {} 
    //#TaskRunner.java:28: method: void org.apache.roller.weblogger.business.runnable.TaskRunner.org.apache.roller.weblogger.business.runnable.TaskRunner()
    //#TaskRunner.java:28: end of method: void org.apache.roller.weblogger.business.runnable.TaskRunner.org.apache.roller.weblogger.business.runnable.TaskRunner()
    
    public static void main(String[] args) throws Exception {
        if (args.length < 3) {
    //#TaskRunner.java:31: method: void org.apache.roller.weblogger.business.runnable.TaskRunner.main(String[])
    //#TaskRunner.java:31: Warning: test always goes same way
    //#    test predetermined because args.length >= 3
    //#    severity: LOW
    //#    class: org.apache.roller.weblogger.business.runnable.TaskRunner
    //#    method: void main(String[])
    //#    from bb: Entry_BB_1
    //#    live edge: Entry_BB_1-->bb_3
    //#    tested vn: args.length - 3
    //#    tested vn values: {0..+Inf}
    //#input(void main(String[])): "CLASSNAME = "._tainted
    //#input(void main(String[])): "JARSDIR   = "._tainted
    //#input(void main(String[])): "WEBAPPDIR = "._tainted
    //#input(void main(String[])): args
    //#input(void main(String[])): args.length
    //#input(void main(String[])): args[0]
    //#input(void main(String[])): args[0]._tainted
    //#input(void main(String[])): args[1]
    //#input(void main(String[])): args[1]._tainted
    //#input(void main(String[])): args[2]
    //#input(void main(String[])): args[2]._tainted
    //#input(void main(String[])): java.lang.System.err
    //#input(void main(String[])): java.lang.System.out
    //#pre[1] (void main(String[])): args != null
    //#pre[2] (void main(String[])): args.length >= 3
    //#pre[3] (void main(String[])): init'ed(args[0])
    //#pre[5] (void main(String[])): init'ed(args[1])
    //#pre[7] (void main(String[])): init'ed(args[2])
    //#presumption(void main(String[])): java.lang.ClassLoader:loadClass(...)@60 != null
    //#presumption(void main(String[])): java.lang.System.err != null
    //#presumption(void main(String[])): java.lang.System.out != null
    //#presumption(void main(String[])): java.lang.Thread:currentThread(...)@57 != null
    //#test_vector(void main(String[])): java.io.File:isDirectory(...)@49: {0}, {1}
    //#test_vector(void main(String[])): java.io.File:isDirectory(...)@49: {1}, {0}
            System.err.println("USAGE: java -cp roller-planet.jar TaskRunner WEBAPPDIR JARSDIR CLASSNAME");
    //#TaskRunner.java:32: Warning: dead code
    //#    dead code here because args.length >= 3
    //#    severity: LOW
    //#    class: org.apache.roller.weblogger.business.runnable.TaskRunner
    //#    method: void main(String[])
    //#    dead bb: bb_2
            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 webappDir     = args[0];
        String jarsDir       = args[1];
        String taskClassName = args[2];
        System.out.println("WEBAPPDIR = " + webappDir); 
        System.out.println("JARSDIR   = " + jarsDir);
        System.out.println("CLASSNAME = " + taskClassName);
        
        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);
        }        
        
        ClassLoader cl = new StandaloneWebappClassLoader(webappDir, jarsDir, null);
    //#TaskRunner.java:54: Warning: method not available
    //#    -- call on void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.business.runnable.TaskRunner
    //#    method: void main(String[])
    //#    unanalyzed callee: void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)
       
        // We're using the new classloader from here on out
        Thread.currentThread().setContextClassLoader(cl);

        // Go!
        Class taskClass = cl.loadClass(taskClassName);
        Runnable task = (Runnable)taskClass.newInstance();
        task.run();
    }
    //#TaskRunner.java:63: end of method: void org.apache.roller.weblogger.business.runnable.TaskRunner.main(String[])
}


/* for example:
 
java \
    -Dplanet.custom.config=planet-custom.properties \
    -Dcatalina.base=. \
    -cp ./build/webapp/WEB-INF/lib/roller-business.jar \
    org.apache.roller.weblogger.business.runnable.TaskRunner \
    ~/roller_trunk/sandbox/planetroller/build/webapp \
    /Applications/Java/jakarta-tomcat-5.5.9/common/lib \
    org.apache.roller.weblogger.planet.tasks.GeneratePlanetTask
 
 */
    //#output(org.apache.roller.weblogger.business.runnable.TaskRunner__static_init): __Descendant_Table[org/apache/roller/weblogger/business/runnable/TaskRunner]
    //#post(org.apache.roller.weblogger.business.runnable.TaskRunner__static_init): __Descendant_Table[org/apache/roller/weblogger/business/runnable/TaskRunner] == &__Dispatch_Table
    //#TaskRunner.java:: end of method: org.apache.roller.weblogger.business.runnable.TaskRunner.org.apache.roller.weblogger.business.runnable.TaskRunner__static_init
    //#TaskRunner.java:: end of class: org.apache.roller.weblogger.business.runnable.TaskRunner
