import java.net.URLClassLoader;
import java.net.URL;
import java.net.MalformedURLException;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
*/
protected void testNewBuild() {
try {
- ClassLoader loader = new URLClassLoader(new URL[] {
- new URL("file:build/fop.jar")
- });
+ ClassLoader loader = new URLClassLoader(
+ createUrls("build/fop.jar"));
Map diff = runConverter(loader, "areatree",
"reference/output/");
if (diff != null && !diff.isEmpty()) {
// return;
// } else {
try {
- ClassLoader loader = new URLClassLoader(new URL[] {
- new URL("file:" + referenceJar)
- });
+ ClassLoader loader = new URLClassLoader(createUrls(referenceJar));
boolean failed = false;
try {
- Class cla = Class.forName("org.apache.fop.apps.Options",
- true, loader);
- /*Object opts =*/ cla.newInstance();
- cla = Class.forName("org.apache.fop.apps.Version", true,
+ Class cla = Class.forName("org.apache.fop.apps.Version", true,
loader);
Method get = cla.getMethod("getVersion", new Class[]{});
if (!get.invoke(null, new Object[]{}).equals(refVersion)) {
failed = true;
} catch (ClassNotFoundException are) {
failed = true;
- } catch (InstantiationException are) {
- failed = true;
} catch (NoSuchMethodException are) {
failed = true;
}
return diff;
}
+ /**
+ * Return a list of URL's with the specified URL first and followed
+ * by all the jar files from lib/.
+ * @return a list of urls to the runtime jar files.
+ */
+ private URL[] createUrls(String mainJar) throws MalformedURLException {
+ ArrayList urls = new ArrayList();
+ urls.add(new File(mainJar).toURL());
+ File[] libFiles = new File("lib").listFiles();
+ for (int i = 0; i < libFiles.length; i++) {
+ if (libFiles[i].getPath().endsWith(".jar")) {
+ urls.add(libFiles[i].toURL());
+ }
+ }
+ return (URL[]) urls.toArray(new URL[urls.size()]);
+ }
}