public MojarraGroovyClassLoader(GroovyScriptEngine gse) { super(new URL[0], gse.getGroovyClassLoader()); this.gse = gse; }
public MojarraGroovyClassLoader(GroovyScriptEngine gse) { super(new URL[0], gse.getGroovyClassLoader()); gse.getGroovyClassLoader().setShouldRecompile(Boolean.TRUE); this.gse = gse; }
public static ClassLoader getClassLoader() { try { return getScriptEngine().getGroovyClassLoader(); } catch (Exception ex) { logger.severeException(ex.getMessage(), ex); return null; } }
@Override public Class<?> loadClass(String name) throws ClassNotFoundException { if (name == null) { throw new NullPointerException(); } Class<?> c; try { c = gse.loadScriptByName(name); } catch (Exception e) { try { c = gse.getGroovyClassLoader().loadClass(name); } catch (ClassNotFoundException cnfe) { throw new ClassNotFoundException(name, cnfe); } } if (c == null) { throw new ClassNotFoundException(name); } return c; }
@Override public Class<?> loadClass(String name) throws ClassNotFoundException { if (name == null) { throw new NullPointerException(); } Class<?> c; try { c = gse.getGroovyClassLoader().getParent().loadClass(name); } catch (ClassNotFoundException cnfe) { try { c = gse.loadScriptByName(name); } catch (Exception e) { throw new ClassNotFoundException(name, e); } } if (c == null) { throw new ClassNotFoundException(name); } return c; }
public void addURL(URL toAdd) { loader.getGroovyScriptEngine().getGroovyClassLoader().addURL(toAdd); }
public GroovyMod(File directory, String name) { Throwable ex = null; try { URL groovyURL = GroovyMod.class.getResource(""); GroovyScriptEngine scriptEngine = new GroovyScriptEngine(new URL[]{groovyURL, directory.toURI().toURL()}); CompilerConfiguration config = new CompilerConfiguration(); scriptEngine.setConfig(config); script = new GroovyRunner(directory, name, scriptEngine.getGroovyClassLoader()); } catch (Exception | AssertionError e) { ex = e; } this.exception = ex; }
@Button(list = "groovy", key = "reset.groovy.script.engine", order = 1, type = Button.TYPE_PRIMARY , icon = Button.ICON_RELOAD) public Resolution resetGroovyScriptEngine() { logger.info("Resetting Groovy script engine"); ServletContext servletContext = context.getServletContext(); GroovyScriptEngine groovyScriptEngine = ScriptingUtil.createScriptEngine(groovyClasspath, getClass().getClassLoader()); ClassLoader classLoader = groovyScriptEngine.getGroovyClassLoader(); servletContext.setAttribute(BaseModule.CLASS_LOADER, classLoader); servletContext.setAttribute(BaseModule.GROOVY_SCRIPT_ENGINE, groovyScriptEngine); SessionMessages.addInfoMessage(ElementsThreadLocals.getText("script.engine.successfully.reset")); logger.info("Clearing OGNL caches potentially holding Groovy objects"); OgnlUtils.clearCache(); logger.info("Groovy script engine reset."); return new ForwardResolution("/m/admin/groovy.jsp"); }
public static GroovyScriptEngine createScriptEngine(File classpathFile, ClassLoader parent) { CompilerConfiguration cc = new CompilerConfiguration(CompilerConfiguration.DEFAULT); String classpath = classpathFile.getAbsolutePath(); cc.setClasspath(classpath); cc.setRecompileGroovySource(true); GroovyScriptEngine scriptEngine; try { scriptEngine = new GroovyScriptEngine(new URL[] { classpathFile.toURI().toURL() }, parent); } catch (IOException e) { throw new Error(e); } scriptEngine.setConfig(cc); scriptEngine.getGroovyClassLoader().setShouldRecompile(true); return scriptEngine; } }
GroovyScriptEngine groovyScriptEngine = ScriptingUtil.createScriptEngine(groovyClasspath, getClass().getClassLoader()); ClassLoader classLoader = groovyScriptEngine.getGroovyClassLoader(); servletContext.setAttribute(BaseModule.GROOVY_CLASS_PATH, groovyClasspath); servletContext.setAttribute(BaseModule.CLASS_LOADER, classLoader);
public void resetGroovyScriptEngine() throws FileSystemException { CompilerConfiguration cc = new CompilerConfiguration(CompilerConfiguration.DEFAULT); try { String classpath = this.root.getName().getPath(); cc.setClasspath(classpath); } catch (Exception e) { logger.debug("Could not set classpath", e); } cc.setRecompileGroovySource(true); groovyScriptEngine = new GroovyScriptEngine(new URL[] { this.root.getURL() }, getClassLoader()); groovyScriptEngine.setConfig(cc); groovyScriptEngine.getGroovyClassLoader().setShouldRecompile(true); }
private static synchronized GroovyScriptEngine getScriptEngine() throws DataAccessException, IOException, CachingException { if (scriptEngine == null || !AssetCache.isLoaded()) { CodeTimer timer = new CodeTimer("Initialize script libraries", true); initializeScriptLibraries(); initializeDynamicJavaAssets(); String[] rootDirs = new String[]{getRootDir()}; if (PackageCache.getPackage(Package.MDW + ".base").getCloudClassLoader() != null) scriptEngine = new GroovyScriptEngine(rootDirs, PackageCache.getPackage(Package.MDW + ".base").getCloudClassLoader()); else scriptEngine = new GroovyScriptEngine(rootDirs); // clear the cached library versions scriptEngine.getGroovyClassLoader().clearCache(); timer.stopAndLogTiming(""); } return scriptEngine; }