Daily bump.
[official-gcc.git] / libjava / gnu / gcj / runtime / HelperClassLoader.java
blob3b48da17c5cd9b56b9a5b94d2d07dfba76017fc1
1 /* Copyright (C) 2005 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7 details. */
9 package gnu.gcj.runtime;
11 import java.io.File;
12 import java.io.FilenameFilter;
13 import java.io.IOException;
14 import java.net.URL;
15 import java.net.URLClassLoader;
16 import java.util.StringTokenizer;
18 /**
19 * This is a URLClassLoader that has an extra helper method for
20 * handling things like java.ext.dirs.
22 class HelperClassLoader extends URLClassLoader
24 HelperClassLoader()
26 super(new URL[0]);
29 HelperClassLoader(ClassLoader parent)
31 super(new URL[0], parent);
34 /**
35 * This is a helper method that adds all the jar and zip files from
36 * a given list of paths to this class loader. The paths are taken
37 * from a system property whose name is provided as an argument.
39 final void addDirectoriesFromProperty(String propName)
41 StringTokenizer st
42 = new StringTokenizer (System.getProperty (propName, ""),
43 File.pathSeparator);
44 try
46 while (st.hasMoreElements ())
48 String dirname = st.nextToken ();
49 File dir = new File (dirname);
50 if (dir.exists ())
52 if (! dirname.endsWith (File.separator))
53 dirname = dirname + File.separator;
54 String files[] = dir.list (new FilenameFilter ()
56 public boolean accept (File dir, String name)
58 return name.endsWith (".jar") || name.endsWith (".zip");
60 });
61 for (int i = files.length - 1; i >= 0; i--)
62 addURL(new URL("file", "", -1, dirname + files[i]));
66 catch (java.net.MalformedURLException x)
68 // This should never happen.
69 throw new RuntimeException(x);