/** * Evaluates the Jelly script submitted by the client. * * This is useful for system administration as well as unit testing. */ @RequirePOST public void doEval(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { checkPermission(RUN_SCRIPTS); try { MetaClass mc = WebApp.getCurrent().getMetaClass(getClass()); Script script = mc.classLoader.loadTearOff(JellyClassLoaderTearOff.class).createContext().compileScript(new InputSource(req.getReader())); new JellyRequestDispatcher(this,script).forward(req,rsp); } catch (JellyException e) { throw new ServletException(e); } }
@Override public void setClassLoader(ClassLoader classLoader) { super.setClassLoader(classLoader); jclt = MetaClassLoader.get(classLoader).loadTearOff(JellyClassLoaderTearOff.class); }
/** * 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, boolean requirePI) throws Exception { TestSuite ts = new JellyTestSuite(); final JellyClassLoaderTearOff jct = new MetaClassLoader(JellyTestSuiteBuilder.class.getClassLoader()).loadTearOff(JellyClassLoaderTearOff.class); for (Map.Entry<URL,String> entry : scan(res, "jelly").entrySet()) { ts.addTest(new JellyCheck(entry.getKey(), entry.getValue(), jct, requirePI)); } return ts; }
public MetaClassLoader(ClassLoader loader) { this.loader = loader; this.parent = get(loader.getParent()); }
public static MetaClassLoader get(ClassLoader cl) { if(cl ==null) return null; // if no parent, delegate to the debug loader if available. synchronized(classMap) { MetaClassLoader mc = classMap.get(cl); if(mc==null) { mc = new MetaClassLoader(cl); classMap.put(cl,mc); } return mc; } }
@Override public void setClassLoader(ClassLoader classLoader) { super.setClassLoader(classLoader); jclt = MetaClassLoader.get(classLoader).loadTearOff(JellyClassLoaderTearOff.class); }
/** * 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; }
public MetaClassLoader(ClassLoader loader) { this.loader = loader; this.parent = get(loader.getParent()); }
public static MetaClassLoader get(ClassLoader cl) { if(cl ==null) return null; // if no parent, delegate to the debug loader if available. synchronized(classMap) { MetaClassLoader mc = classMap.get(cl); if(mc==null) { mc = new MetaClassLoader(cl); classMap.put(cl,mc); } return mc; } }
protected AbstractTearOff(MetaClass owner, Class<CLT> cltClass) { this.owner = owner; if(owner.classLoader!=null) classLoader = owner.classLoader.loadTearOff(cltClass); else classLoader = null; }
/** * Loads a jelly tag library. * * @param t * If this is a subtype of {@link TagLibrary}, then that tag library is loaded and bound to the * {@link Namespace} object, which you can later use to call tags. * Otherwise, t has to have 'taglib' file in the resource and sibling "*.jelly" files will be treated * as tag files. */ public Namespace jelly(Class t) { String n = t.getName(); if(TagLibrary.class.isAssignableFrom(t)) { // if the given class is a tag library itself, just record it context.registerTagLibrary(n,n); } else { String path = n.replace('.', '/'); URL res = t.getClassLoader().getResource(path+"/taglib"); if(res!=null) { // this class itself is not a tag library, but it contains Jelly side files that are tag files. // (some of them might be views, but some of them are tag files, anyway. JellyContext parseContext = MetaClassLoader.get(t.getClassLoader()).loadTearOff(JellyClassLoaderTearOff.class).createContext(); context.registerTagLibrary(n, new CustomTagLibrary(parseContext, t.getClassLoader(), n, path)); } else { throw new IllegalArgumentException("Cannot find taglib from "+t); } } return new Namespace(this,n,"-"); // doesn't matter what the prefix is, since they are known to be taglibs }
/** * 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; }
public MetaClassLoader(ClassLoader loader) { this.loader = loader; this.parent = get(loader.getParent()); }
public static MetaClassLoader get(ClassLoader cl) { if(cl ==null) return null; // if no parent, delegate to the debug loader if available. synchronized(classMap) { MetaClassLoader mc = classMap.get(cl); if(mc==null) { mc = new MetaClassLoader(cl); classMap.put(cl,mc); } return mc; } }
protected AbstractTearOff(MetaClass owner, Class<CLT> cltClass) { this.owner = owner; if(owner.classLoader!=null) classLoader = owner.classLoader.loadTearOff(cltClass); else classLoader = null; }
/** * Builds an adjunct. * * @param name * Fully qualified name of the adjunct. * @param classLoader * This is where adjuncts are loaded from. */ public Adjunct(AdjunctManager manager, String name, final ClassLoader classLoader) throws IOException { this.manager = manager; this.name = name; this.slashedName = name.replace('.','/'); this.packageName = slashedName.substring(0, Math.max(0,slashedName.lastIndexOf('/'))); this.hasCss = parseOne(classLoader, slashedName+".css"); this.hasJavaScript = parseOne(classLoader,slashedName+".js"); this.inclusionFragment = parseHtml(classLoader,slashedName+".html"); URL jelly = classLoader.getResource(slashedName + ".jelly"); if (jelly!=null) { try { script = MetaClassLoader.get(classLoader).loadTearOff(JellyClassLoaderTearOff.class).createContext().compileScript(jelly); } catch (JellyException e) { throw new IOException("Failed to load "+jelly,e); } } else { script = null; } if(!hasCss && !hasJavaScript && inclusionFragment==null && script==null) throw new NoSuchAdjunctException("Neither "+ name +".css, .js, .html, nor .jelly were found"); }
/** * 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; }
public CustomTagLibrary(JellyContext master, ClassLoader classLoader, String nsUri, String basePath) { this.master = master; this.classLoader = classLoader; this.nsUri = nsUri; this.basePath = basePath; this.metaClassLoader = MetaClassLoader.get(classLoader); this.loaders = JellyTagFileLoader.discover(classLoader); }
protected AbstractTearOff(MetaClass owner, Class<CLT> cltClass) { this.owner = owner; if(owner.classLoader!=null) classLoader = owner.classLoader.loadTearOff(cltClass); else classLoader = null; }
/** * Builds an adjunct. * * @param name * Fully qualified name of the adjunct. * @param classLoader * This is where adjuncts are loaded from. */ public Adjunct(AdjunctManager manager, String name, final ClassLoader classLoader) throws IOException { this.manager = manager; this.name = name; this.slashedName = name.replace('.','/'); this.packageName = slashedName.substring(0, Math.max(0,slashedName.lastIndexOf('/'))); this.hasCss = parseOne(classLoader, slashedName+".css"); this.hasJavaScript = parseOne(classLoader,slashedName+".js"); this.inclusionFragment = parseHtml(classLoader,slashedName+".html"); URL jelly = classLoader.getResource(slashedName + ".jelly"); if (jelly!=null) { try { script = MetaClassLoader.get(classLoader).loadTearOff(JellyClassLoaderTearOff.class).createContext().compileScript(jelly); } catch (JellyException e) { throw new IOException2("Failed to load "+jelly,e); } } else { script = null; } if(!hasCss && !hasJavaScript && inclusionFragment==null && script==null) throw new NoSuchAdjunctException("Neither "+ name +".css, .js, .html, nor .jelly were found"); }