Search in sources :

Example 6 with ClasspathManager

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;
}
Also used : ClasspathManager(org.eclipse.osgi.internal.loader.classpath.ClasspathManager) ModuleClassLoader(org.eclipse.osgi.internal.loader.ModuleClassLoader) ArrayList(java.util.ArrayList) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) BundleEntry(org.eclipse.osgi.storage.bundlefile.BundleEntry) URL(java.net.URL)

Aggregations

ClasspathManager (org.eclipse.osgi.internal.loader.classpath.ClasspathManager)6 ModuleClassLoader (org.eclipse.osgi.internal.loader.ModuleClassLoader)4 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 File (java.io.File)2 JarFile (java.util.jar.JarFile)2 Module (org.eclipse.osgi.container.Module)2 URLClassLoader (java.net.URLClassLoader)1 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)1 ClasspathEntry (org.eclipse.osgi.internal.loader.classpath.ClasspathEntry)1 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)1 BundleEntry (org.eclipse.osgi.storage.bundlefile.BundleEntry)1 BundleFile (org.eclipse.osgi.storage.bundlefile.BundleFile)1 Bundle (org.osgi.framework.Bundle)1 BundleException (org.osgi.framework.BundleException)1