use of org.eclipse.osgi.internal.loader.classpath.ClasspathManager in project knime-core by knime.
the class AbstractTestcaseCollector method getUnittestsClassNames.
/**
* Returns a list with class names that contain JUnit test methods or are old-style (JUnit3) testcases.
*
* @return a list with class names
* @throws IOException if an I/O error occurs while collecting the classes
*/
public List<String> getUnittestsClassNames() throws IOException {
ModuleClassLoader cl = (ModuleClassLoader) getClass().getClassLoader();
ClasspathManager cpm = cl.getClasspathManager();
String classPath = this.getClass().getName().replace(".", "/") + ".class";
BundleEntry be = cpm.findLocalEntry(classPath);
URL localUrl = be.getLocalURL();
List<String> classNames = new ArrayList<String>();
if ("file".equals(localUrl.getProtocol())) {
String path = localUrl.getPath();
path = path.replaceFirst(Pattern.quote(classPath) + "$", "");
collectInDirectory(new File(path), "", classNames);
} else if ("jar".equals(localUrl.getProtocol())) {
String path = localUrl.getPath().replaceFirst("^file:", "").replaceFirst("\\!.+$", "");
collectInJar(new JarFile(path), classNames);
} else {
throw new IllegalStateException("Cannot read from protocol '" + localUrl.getProtocol() + "'");
}
classNames.remove(this.getClass().getName());
filterClasses(classNames);
return classNames;
}
Aggregations