()
| 203 | /** Returns the URLs in the system class path. */ |
| 204 | // TODO(user): Use a common API once that's available. |
| 205 | public static URL[] getClassPathUrls() { |
| 206 | if (Asserts.class.getClassLoader() instanceof URLClassLoader) { |
| 207 | return ((URLClassLoader) Asserts.class.getClassLoader()).getURLs(); |
| 208 | } |
| 209 | ImmutableList.Builder<URL> urls = ImmutableList.builder(); |
| 210 | for (String entry : Splitter.on(PATH_SEPARATOR.value()).split(JAVA_CLASS_PATH.value())) { |
| 211 | try { |
| 212 | try { |
| 213 | urls.add(new File(entry).toURI().toURL()); |
| 214 | } catch (SecurityException e) { // File.toURI checks to see if the file is a directory |
| 215 | urls.add(new URL("file", null, new File(entry).getAbsolutePath())); |
| 216 | } |
| 217 | } catch (MalformedURLException e) { |
| 218 | AssertionError error = new AssertionError("malformed class path entry: " + entry); |
| 219 | error.initCause(e); |
| 220 | throw error; |
| 221 | } |
| 222 | } |
| 223 | return urls.build().toArray(new URL[0]); |
| 224 | } |
| 225 | } |
no test coverage detected