1 16 17 package org.apache.commons.logging; 18 19 20 import java.io.File ; 21 import java.lang.reflect.Method ; 22 import java.net.URL ; 23 import java.net.URLClassLoader ; 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 28 70 71 public class Wrapper { 72 73 74 public static void main(String args[]) { 75 76 try { 77 78 List parentList = new ArrayList (); 80 List childList = new ArrayList (); 81 URL urls[] = null; 82 83 File target = new File (System.getProperty("wrapper.target")); 85 URL commonsLogging = 86 (new File (target, "commons-logging.jar")).toURL(); 87 URL commonsLoggingApi = 88 (new File (target, "commons-logging-api.jar")).toURL(); 89 URL commonsLoggingTests = 90 (new File (target, "commons-logging-tests.jar")).toURL(); 91 URL junit = 92 (new File (System.getProperty("wrapper.junit"))).toURL(); 93 URL appender = null; 94 URL log4j = null; 95 if (System.getProperty("wrapper.log4j") != null) { 96 log4j = 97 (new File (System.getProperty("wrapper.log4j"))).toURL(); 98 appender = 99 (new File (target, "commons-logging-appender.jar")).toURL(); 100 } 101 102 if ("API".equals(System.getProperty("wrapper.hierarchy"))) { 104 parentList.add(commonsLoggingApi); 105 childList.add(commonsLogging); 106 if (log4j != null) { 107 childList.add(log4j); 108 childList.add(appender); 109 } 110 } else { parentList.add(commonsLogging); 112 if (log4j != null) { 113 parentList.add(log4j); 114 childList.add(appender); 115 } 116 } 117 childList.add(commonsLoggingTests); 118 childList.add(junit); 119 120 urls = (URL []) parentList.toArray(new URL [parentList.size()]); 122 ClassLoader parent = 123 new URLClassLoader (urls, 124 ClassLoader.getSystemClassLoader()); 125 urls = (URL []) childList.toArray(new URL [childList.size()]); 126 ClassLoader child = new URLClassLoader (urls, parent); 127 128 ClassLoader old = Thread.currentThread().getContextClassLoader(); 130 Thread.currentThread().setContextClassLoader(child); 131 Class clazz = child.loadClass("junit.textui.TestRunner"); 132 String params[] = new String [1]; 133 params[0] = System.getProperty("wrapper.testcase"); 134 Method method = clazz.getMethod("main", 135 new Class [] { params.getClass() }); 136 method.invoke(null, new Object [] { params }); 137 Thread.currentThread().setContextClassLoader(old); 138 139 } catch (Exception e) { 140 141 System.out.println("Wrapper Exception Occurred: " + e); 142 e.printStackTrace(System.out); 143 System.exit(1); 144 145 } 146 147 } 148 149 150 151 } 152 | Popular Tags |