in src/main/java/org/apache/openejb/tools/release/util/JarLocation.java [33:72]
public static File jarLocation(final Class clazz) {
try {
final String classFileName = clazz.getName().replace(".", "/") + ".class";
final ClassLoader loader = clazz.getClassLoader();
URL url;
if (loader != null) {
url = loader.getResource(classFileName);
} else {
url = clazz.getResource(classFileName);
}
if (url == null) {
throw new IllegalStateException("classloader.getResource(classFileName) returned a null URL");
}
if ("jar".equals(url.getProtocol())) {
final String spec = url.getFile();
int separator = spec.indexOf('!');
/*
* REMIND: we don't handle nested JAR URLs
*/
if (separator == -1) throw new MalformedURLException("no ! found in jar url spec:" + spec);
url = new URL(spec.substring(0, separator++));
return new File(decode(url.getFile()));
} else if ("file".equals(url.getProtocol())) {
return toFile(classFileName, url);
} else {
throw new IllegalArgumentException("Unsupported URL scheme: " + url.toExternalForm());
}
} catch (final RuntimeException e) {
throw e;
} catch (final Exception e) {
throw new IllegalStateException(e);
}
}