//# 1 errors, 113 messages
//#
/*
    //#StandaloneWebappClassLoader.java:1:1: class: org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1
    //#StandaloneWebappClassLoader.java:1:1: method: org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1.org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1__static_init
    //#StandaloneWebappClassLoader.java:1:1: class: org.apache.roller.weblogger.util.StandaloneWebappClassLoader
 * 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.
 *
 * StandaloneWebappClassLoader.java
 * Created on October 20, 2006, 11:11 PM
 */

package org.apache.roller.weblogger.util;

import java.io.File;
import java.io.FilenameFilter;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;

/**
 * ClassLoader to enable running webapp classes outside of webapp.  
 * You provide webappDir and jarsDir paths and the classloader will include 
 * webappDir/WEB-INF/classes, webappDir/WEB-INF/lib/*jar and jarsDir/*.jar.
 */
public class StandaloneWebappClassLoader extends URLClassLoader {
    public static String FS = File.separator;
    //#StandaloneWebappClassLoader.java:37: method: org.apache.roller.weblogger.util.StandaloneWebappClassLoader.org.apache.roller.weblogger.util.StandaloneWebappClassLoader__static_init
    //#input(org.apache.roller.weblogger.util.StandaloneWebappClassLoader__static_init): java.io.File.separator
    //#output(org.apache.roller.weblogger.util.StandaloneWebappClassLoader__static_init): FS
    //#output(org.apache.roller.weblogger.util.StandaloneWebappClassLoader__static_init): __Descendant_Table[org/apache/roller/weblogger/util/StandaloneWebappClassLoader]
    //#presumption(org.apache.roller.weblogger.util.StandaloneWebappClassLoader__static_init): init'ed(java.io.File.separator)
    //#post(org.apache.roller.weblogger.util.StandaloneWebappClassLoader__static_init): FS == java.io.File.separator
    //#post(org.apache.roller.weblogger.util.StandaloneWebappClassLoader__static_init): (soft) init'ed(FS)
    //#post(org.apache.roller.weblogger.util.StandaloneWebappClassLoader__static_init): __Descendant_Table[org/apache/roller/weblogger/util/StandaloneWebappClassLoader] == &__Dispatch_Table
    //#StandaloneWebappClassLoader.java:37: end of method: org.apache.roller.weblogger.util.StandaloneWebappClassLoader.org.apache.roller.weblogger.util.StandaloneWebappClassLoader__static_init
    
    /** Use calling class's parent classloader */
    public StandaloneWebappClassLoader(String webappDir, String jarsDir) throws Exception {
        super(buildURLsArray(webappDir, jarsDir));
    //#StandaloneWebappClassLoader.java:41: method: void org.apache.roller.weblogger.util.StandaloneWebappClassLoader.org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): "WEB-INF"._tainted
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): "classes"._tainted
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): "file:.."._tainted
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): "lib"._tainted
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): FS
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): FS._tainted
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): jarsDir
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): jarsDir._tainted
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): this
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): webappDir
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): webappDir._tainted
    //#pre[1] (void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): init'ed(FS)
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): Effects-of-calling:java.io.File
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): Effects-of-calling:java.io.File:list
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): Effects-of-calling:java.lang.StringBuilder
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): Effects-of-calling:java.lang.StringBuilder:append
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): Effects-of-calling:java.lang.StringBuilder:toString
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): Effects-of-calling:java.net.URL
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): Effects-of-calling:java.util.List:add
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): Effects-of-calling:java.util.ArrayList
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): Effects-of-calling:java.util.List:size
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)): Effects-of-calling:java.util.List:toArray
    }
    //#StandaloneWebappClassLoader.java:42: end of method: void org.apache.roller.weblogger.util.StandaloneWebappClassLoader.org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)
    
    /** Use a specific parent classloader, or null for no parent */
    public StandaloneWebappClassLoader(String webappDir, String jarsDir, ClassLoader cl) throws Exception {
        super(buildURLsArray(webappDir, jarsDir), cl);
    //#StandaloneWebappClassLoader.java:46: method: void org.apache.roller.weblogger.util.StandaloneWebappClassLoader.org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): "WEB-INF"._tainted
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): "classes"._tainted
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): "file:.."._tainted
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): "lib"._tainted
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): FS
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): FS._tainted
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): cl
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): jarsDir
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): jarsDir._tainted
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): this
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): webappDir
    //#input(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): webappDir._tainted
    //#pre[1] (void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): init'ed(FS)
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): Effects-of-calling:java.io.File
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): Effects-of-calling:java.io.File:list
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): Effects-of-calling:java.lang.StringBuilder
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): Effects-of-calling:java.lang.StringBuilder:append
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): Effects-of-calling:java.lang.StringBuilder:toString
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): Effects-of-calling:java.net.URL
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): Effects-of-calling:java.util.List:add
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): Effects-of-calling:java.util.ArrayList
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): Effects-of-calling:java.util.List:size
    //#unanalyzed(void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)): Effects-of-calling:java.util.List:toArray
    }
    //#StandaloneWebappClassLoader.java:47: end of method: void org.apache.roller.weblogger.util.StandaloneWebappClassLoader.org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)
    
    private static URL[] buildURLsArray(String webappDir, String jarsDir) throws Exception {
        // Create collection of URLs needed for classloader
        List urlList = new ArrayList();
    //#StandaloneWebappClassLoader.java:51: method: URL[] org.apache.roller.weblogger.util.StandaloneWebappClassLoader.buildURLsArray(String, String)
    //#input(URL[] buildURLsArray(String, String)): "WEB-INF"._tainted
    //#input(URL[] buildURLsArray(String, String)): "classes"._tainted
    //#input(URL[] buildURLsArray(String, String)): "file:.."._tainted
    //#input(URL[] buildURLsArray(String, String)): "lib"._tainted
    //#input(URL[] buildURLsArray(String, String)): FS
    //#input(URL[] buildURLsArray(String, String)): FS._tainted
    //#input(URL[] buildURLsArray(String, String)): jarsDir
    //#input(URL[] buildURLsArray(String, String)): jarsDir._tainted
    //#input(URL[] buildURLsArray(String, String)): webappDir
    //#input(URL[] buildURLsArray(String, String)): webappDir._tainted
    //#output(URL[] buildURLsArray(String, String)): return_value
    //#pre[1] (URL[] buildURLsArray(String, String)): init'ed(FS)
    //#presumption(URL[] buildURLsArray(String, String)): java.util.List:size(...)@64 >= 0
    //#post(URL[] buildURLsArray(String, String)): init'ed(return_value)
    //#unanalyzed(URL[] buildURLsArray(String, String)): Effects-of-calling:java.io.File
    //#unanalyzed(URL[] buildURLsArray(String, String)): Effects-of-calling:java.io.File:list
    //#unanalyzed(URL[] buildURLsArray(String, String)): Effects-of-calling:java.lang.StringBuilder
    //#unanalyzed(URL[] buildURLsArray(String, String)): Effects-of-calling:java.lang.StringBuilder:append
    //#unanalyzed(URL[] buildURLsArray(String, String)): Effects-of-calling:java.lang.StringBuilder:toString
    //#unanalyzed(URL[] buildURLsArray(String, String)): Effects-of-calling:java.net.URL
    //#unanalyzed(URL[] buildURLsArray(String, String)): Effects-of-calling:java.util.List:add

        // Add WEB-INF/lib jars
        String libPath = webappDir + FS + "WEB-INF" + FS + "lib";
        addURLs(libPath, urlList);
        
        // Added WEB-INF/classes
        String classesPath = webappDir + FS + "WEB-INF" + FS + "classes" + FS;
        urlList.add(new URL("file://" + classesPath));
        
        // Add additional jars
        addURLs(jarsDir, urlList);
                
        return (URL[])urlList.toArray(new URL[urlList.size()]);  
    //#StandaloneWebappClassLoader.java:64: end of method: URL[] org.apache.roller.weblogger.util.StandaloneWebappClassLoader.buildURLsArray(String, String)
    }
    
    private static void addURLs(String dirPath, List urlList) throws Exception {
        File libDir = new File(dirPath);
    //#StandaloneWebappClassLoader.java:68: method: void org.apache.roller.weblogger.util.StandaloneWebappClassLoader.addURLs(String, List)
    //#input(void addURLs(String, List)): "file:.."._tainted
    //#input(void addURLs(String, List)): FS
    //#input(void addURLs(String, List)): FS._tainted
    //#input(void addURLs(String, List)): dirPath
    //#input(void addURLs(String, List)): dirPath._tainted
    //#input(void addURLs(String, List)): urlList
    //#pre[1] (void addURLs(String, List)): (soft) init'ed(FS)
    //#pre[6] (void addURLs(String, List)): (soft) urlList != null
    //#presumption(void addURLs(String, List)): java.io.File:list(...)@69 != null
    //#presumption(void addURLs(String, List)): libJarNames.length@69 <= 4_294_967_295
        String[] libJarNames = libDir.list(new FilenameFilter() {
    //#StandaloneWebappClassLoader.java:69: method: void org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1.org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1()
    //#StandaloneWebappClassLoader.java:69: end of method: void org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1.org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1()
            public boolean accept(File dir, String pathname) {
                if (pathname.endsWith(".jar")) {
    //#StandaloneWebappClassLoader.java:71: method: bool org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1.accept(File, String)
    //#input(bool accept(File, String)): pathname
    //#output(bool accept(File, String)): return_value
    //#pre[1] (bool accept(File, String)): pathname != null
    //#post(bool accept(File, String)): init'ed(return_value)
    //#test_vector(bool accept(File, String)): java.lang.String:endsWith(...)@71: {0}, {1}
                    return true;
                }
                return false;
    //#StandaloneWebappClassLoader.java:74: end of method: bool org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1.accept(File, String)
            }
        });       
        for (int i=0; i<libJarNames.length; i++) {
            String url = "file://" + dirPath + FS + libJarNames[i];
    //#StandaloneWebappClassLoader.java:78: ?use of default init
    //#    init'ed(libJarNames[i])
    //#    severity: SUPPRESSED
    //#    class: org.apache.roller.weblogger.util.StandaloneWebappClassLoader
    //#    method: void addURLs(String, List)
    //#    basic block: bb_3
    //#    assertion: init'ed(libJarNames[i])
    //#    VN: undefined
    //#    Expected: Univ-VN-Set
    //#    Bad: {Invalid}
    //#    Attribs:  Ptr  Bad only invalid
            urlList.add(new URL(url));
        }
    }
    //#StandaloneWebappClassLoader.java:81: end of method: void org.apache.roller.weblogger.util.StandaloneWebappClassLoader.addURLs(String, List)
}
    //#output(org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1__static_init): __Descendant_Table[org/apache/roller/weblogger/util/StandaloneWebappClassLoader$1]
    //#output(org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1__static_init): __Dispatch_Table.accept(Ljava/io/File;Ljava/lang/String;)Z
    //#post(org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1__static_init): __Descendant_Table[org/apache/roller/weblogger/util/StandaloneWebappClassLoader$1] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1__static_init): __Dispatch_Table.accept(Ljava/io/File;Ljava/lang/String;)Z == &accept
    //#StandaloneWebappClassLoader.java:: end of method: org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1.org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1__static_init
    //#StandaloneWebappClassLoader.java:: end of class: org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1
    //#StandaloneWebappClassLoader.java:: end of class: org.apache.roller.weblogger.util.StandaloneWebappClassLoader
