/** * Creates a Script with a given scriptName and binding. * * @param scriptName name of the script to run * @param binding the binding to pass to the script * @return the script object * @throws ResourceException if there is a problem accessing the script * @throws ScriptException if there is a problem parsing the script */ public Script createScript(String scriptName, Binding binding) throws ResourceException, ScriptException { return InvokerHelper.createScript(loadScriptByName(scriptName), binding); }
/** * Creates a Script with a given scriptName and binding. * * @param scriptName name of the script to run * @param binding the binding to pass to the script * @return the script object * @throws ResourceException if there is a problem accessing the script * @throws ScriptException if there is a problem parsing the script */ public Script createScript(String scriptName, Binding binding) throws ResourceException, ScriptException { return InvokerHelper.createScript(loadScriptByName(scriptName), binding); }
public static Class<?> getGroovyClass(File scriptFile) throws IOException, ScriptException, ResourceException { if(!scriptFile.exists()) { return null; } GroovyScriptEngine scriptEngine = (GroovyScriptEngine) ElementsThreadLocals.getServletContext().getAttribute( BaseModule.GROOVY_SCRIPT_ENGINE); return scriptEngine.loadScriptByName(scriptFile.toURI().toString()); }
/** * Get the class of the scriptName in question, so that you can instantiate Groovy objects with caching and reloading. * * @param scriptName resource name pointing to the script * @param parentClassLoader the class loader to use when loading the script * @return the loaded scriptName as a compiled class * @throws ResourceException if there is a problem accessing the script * @throws ScriptException if there is a problem parsing the script * @deprecated */ public Class loadScriptByName(String scriptName, ClassLoader parentClassLoader) throws ResourceException, ScriptException { initGroovyLoader(parentClassLoader); return loadScriptByName(scriptName); }
public Class loadGroovyFile(FileObject fileObject) throws FileSystemException, ResourceException, ScriptException { return groovyScriptEngine.loadScriptByName(fileObject.getURL().toString()); }
@Override public Transformer<String, String> createTransformer() { Transformer<String, String> transformerFromScript = null; try { File scriptFile = scriptFactory.createScript(); URL scriptAsAClasspathResource = Resources.getResource(GROOVY_SCRIPTS_CLASSPATH + scriptFile.getName()); Class classFromScript = groovyScriptEngine.loadScriptByName(scriptAsAClasspathResource.getFile()); transformerFromScript = (Transformer<String, String>) classFromScript.newInstance(); } catch (Exception e) { LOGGER.error("Exception occurred while trying to execute Groovy script", e); } return transformerFromScript; }
/** * Get the class of the scriptName in question, so that you can instantiate Groovy objects with caching and reloading. * * @param scriptName resource name pointing to the script * @param parentClassLoader the class loader to use when loading the script * @return the loaded scriptName as a compiled class * @throws ResourceException if there is a problem accessing the script * @throws ScriptException if there is a problem parsing the script * @deprecated */ public Class loadScriptByName(String scriptName, ClassLoader parentClassLoader) throws ResourceException, ScriptException { initGroovyLoader(parentClassLoader); return loadScriptByName(scriptName); }
/** * Get the class of the scriptName in question, so that you can instantiate Groovy objects with caching and reloading. * * @param scriptName resource name pointing to the script * @param parentClassLoader the class loader to use when loading the script * @return the loaded scriptName as a compiled class * @throws ResourceException if there is a problem accessing the script * @throws ScriptException if there is a problem parsing the script * @deprecated */ public Class loadScriptByName(String scriptName, ClassLoader parentClassLoader) throws ResourceException, ScriptException { initGroovyLoader(parentClassLoader); return loadScriptByName(scriptName); }
GroovyProcessor(final boolean scriptPooling, final String scriptExprOrFile, final String... scriptArgs) { Objects.requireNonNull(scriptExprOrFile); Class<?> scriptClass = null; try { try { scriptClass = ENGINE.loadScriptByName(scriptExprOrFile); } catch (final ResourceException ex) { final Path path = Files.createTempFile("rdfpro-filter-", ".groovy"); Files.write(path, scriptExprOrFile.getBytes(Charset.forName("UTF-8"))); scriptClass = ENGINE.loadScriptByName(path.toUri().toString()); } } catch (final Throwable ex) { throw new Error("Could not compile Groovy script", ex); } this.scriptPooling = scriptPooling; this.scriptClass = scriptClass; this.scriptArgs = scriptArgs.clone(); }
protected void preloadGroovyClasses(File directory) { for(File file : directory.listFiles()) { logger.debug("visit {}", file); if(file.isDirectory()) { if(!file.equals(directory) && !file.equals(directory.getParentFile())) { preloadGroovyClasses(file); } } else { String scriptName = file.toURI().toString(); logger.debug("Preloading " + scriptName); try { groovyScriptEngine.loadScriptByName(scriptName); } catch(Throwable t) { logger.warn("Groovy class preload failed for " + scriptName, t); } } } }
@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; }
@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; }
private PortofinoRealm doEnsureDelegate() throws ScriptException, ResourceException, IllegalAccessException, InstantiationException { Class<?> scriptClass = groovyScriptEngine.loadScriptByName(scriptUrl); if(scriptClass.isInstance(security)) { //Class did not change return security; } else { logger.info("Refreshing Portofino Realm Delegate instance (Security.groovy)"); if(security != null) { logger.debug("Script class changed: from " + security.getClass() + " to " + scriptClass); } Object securityTemp = scriptClass.newInstance(); if(securityTemp instanceof PortofinoRealm) { PortofinoRealm realm = (PortofinoRealm) securityTemp; configureDelegate(realm); PortofinoRealm oldSecurity = security; security = realm; LifecycleUtils.destroy(oldSecurity); return realm; } else { throw new ClassCastException( "Security object is not an instance of " + PortofinoRealm.class + ": " + securityTemp + " (" + securityTemp.getClass().getSuperclass() + " " + Arrays.asList(securityTemp.getClass().getInterfaces()) + ")"); } } }
c = GroovyScriptEngine.getEngine().loadScriptByName(resource.toString()); } catch (ScriptException se) { throw new IOException(se);
Class c = gse.loadScriptByName(new File(scriptFile).toURI().toString());
Class c = gse.loadScriptByName(new File(path).toURI().toString());