/** * 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); } }
protected AbstractTearOff(MetaClass owner, Class<CLT> cltClass) { this.owner = owner; if(owner.classLoader!=null) classLoader = owner.classLoader.loadTearOff(cltClass); else classLoader = null; }
protected AbstractTearOff(MetaClass owner, Class<CLT> cltClass) { this.owner = owner; if(owner.classLoader!=null) classLoader = owner.classLoader.loadTearOff(cltClass); else classLoader = null; }
protected AbstractTearOff(MetaClass owner, Class<CLT> cltClass) { this.owner = owner; if(owner.classLoader!=null) classLoader = owner.classLoader.loadTearOff(cltClass); else classLoader = null; }
public Script load(CustomTagLibrary taglib, String name, ClassLoader classLoader) throws JellyException { URL res = classLoader.getResource(taglib.basePath + '/' + name + ".groovy"); if(res==null) return null; try { GroovyClassLoaderTearOff gcl = taglib.metaClassLoader.loadTearOff(GroovyClassLoaderTearOff.class); return gcl.parse(res); } catch (IOException e) { throw new JellyException(e); } } }
@Override public void setClassLoader(ClassLoader classLoader) { super.setClassLoader(classLoader); jclt = MetaClassLoader.get(classLoader).loadTearOff(JellyClassLoaderTearOff.class); }
@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; }
/** * 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; }
/** * 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; }
/** * 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 TagLibrary apply(String nsUri) { if(owner.parent!=null) { // parent first TagLibrary tl = owner.parent.loadTearOff(JellyClassLoaderTearOff.class).getTagLibrary(nsUri); if(tl!=null) return tl; } String taglibBasePath = trimHeadSlash(nsUri); try { URL res = owner.loader.getResource(taglibBasePath +"/taglib"); if(res!=null) return new CustomTagLibrary(createContext(),owner.loader,nsUri,taglibBasePath); } catch (IllegalArgumentException e) { // if taglibBasePath doesn't even look like an URL, getResource throws IllegalArgumentException. // see http://old.nabble.com/bug-1.331-to26145963.html } return NO_SUCH_TAGLIBRARY; // "not found" is also cached. } });
/** * 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 }
public TagLibrary load(String nsUri) { if(owner.parent!=null) { // parent first TagLibrary tl = owner.parent.loadTearOff(JellyClassLoaderTearOff.class).getTagLibrary(nsUri); if(tl!=null) return tl; } String taglibBasePath = trimHeadSlash(nsUri); try { URL res = owner.loader.getResource(taglibBasePath +"/taglib"); if(res!=null) return new CustomTagLibrary(createContext(),owner.loader,nsUri,taglibBasePath); } catch (IllegalArgumentException e) { // if taglibBasePath doesn't even look like an URL, getResource throws IllegalArgumentException. // see http://old.nabble.com/bug-1.331-to26145963.html } // support URIs like "this:it" or "this:instance". Note that "this" URI itself is registered elsewhere if (nsUri.startsWith("this:")) try { return new ThisTagLibrary(EXPRESSION_FACTORY.createExpression(nsUri.substring(5))); } catch (JellyException e) { throw new IllegalArgumentException("Illegal expression in the URI: "+nsUri,e); } if (nsUri.equals("jelly:stapler")) return new StaplerTagLibrary(); return NO_SUCH_TAGLIBRARY; // "not found" is also cached. } });
/** * 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); } }
/** * 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"); }
/** * Evaluates the Jelly script submitted by the client. * * This is useful for system administration as well as unit testing. */ public void doEval(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { checkPermission(ADMINISTER); requirePOST(); 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); } }
/** * Evaluates the Jelly script submitted by the client. * * This is useful for system administration as well as unit testing. */ public void doEval(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { checkPermission(ADMINISTER); requirePOST(); 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); } }
/** * Evaluates the Jelly script submitted by the client. * * This is useful for system administration as well as unit testing. */ public void doEval(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { checkPermission(ADMINISTER); requirePOST(); 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); } }
/** * Evaluates the Jelly script submitted by the client. * * This is useful for system administration as well as unit testing. */ public void doEval(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { checkPermission(ADMINISTER); requirePOST(); 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); } }