Search in sources :

Example 1 with JellyClassLoaderTearOff

use of org.kohsuke.stapler.jelly.JellyClassLoaderTearOff in project hudson-2.x by hudson.

the class JellyTestSuiteBuilder method build.

/**
     * Given a jar file or a class file directory, recursively search all the Jelly files and build a {@link TestSuite}
     * that performs static syntax checks.
     */
public static TestSuite build(File res) throws Exception {
    TestSuite ts = new JellyTestSuite();
    final JellyClassLoaderTearOff jct = new MetaClassLoader(JellyTestSuiteBuilder.class.getClassLoader()).loadTearOff(JellyClassLoaderTearOff.class);
    if (res.isDirectory()) {
        for (final File jelly : (Collection<File>) FileUtils.listFiles(res, new String[] { "jelly" }, true)) ts.addTest(new JellyCheck(jelly.toURI().toURL(), jct));
    }
    if (res.getName().endsWith(".jar")) {
        String jarUrl = res.toURI().toURL().toExternalForm();
        JarFile jf = new JarFile(res);
        Enumeration<JarEntry> e = jf.entries();
        while (e.hasMoreElements()) {
            JarEntry ent = e.nextElement();
            if (ent.getName().endsWith(".jelly"))
                ts.addTest(new JellyCheck(new URL("jar:" + jarUrl + "!/" + ent.getName()), jct));
        }
        jf.close();
    }
    return ts;
}
Also used : TestSuite(junit.framework.TestSuite) MetaClassLoader(org.kohsuke.stapler.MetaClassLoader) JellyClassLoaderTearOff(org.kohsuke.stapler.jelly.JellyClassLoaderTearOff) Collection(java.util.Collection) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL)

Aggregations

File (java.io.File)1 URL (java.net.URL)1 Collection (java.util.Collection)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 TestSuite (junit.framework.TestSuite)1 MetaClassLoader (org.kohsuke.stapler.MetaClassLoader)1 JellyClassLoaderTearOff (org.kohsuke.stapler.jelly.JellyClassLoaderTearOff)1