private void updateLocalDependencyCache(GroovyCodeSource codeSource, LocalData localData) { // we put the old dependencies into local cache so createCompilationUnit // can pick it up. We put that entry under the name "." ScriptCacheEntry origEntry = scriptCache.get(codeSource.getName()); Set<String> origDep = null; if (origEntry != null) origDep = origEntry.dependencies; if (origDep != null) { Set<String> newDep = new HashSet<String>(origDep.size()); for (String depName : origDep) { ScriptCacheEntry dep = scriptCache.get(depName); try { if (origEntry == dep || GroovyScriptEngine.this.isSourceNewer(dep)) { newDep.add(depName); } } catch (ResourceException re) { } } StringSetMap cache = localData.dependencyCache; cache.put(".", newDep); } }
/** * 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 * @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 */ public Class loadScriptByName(String scriptName) throws ResourceException, ScriptException { URLConnection conn = rc.getResourceConnection(scriptName); String path = conn.getURL().toExternalForm(); ScriptCacheEntry entry = scriptCache.get(path); Class clazz = null; if (entry != null) clazz = entry.scriptClass; try { if (isSourceNewer(entry)) { try { String encoding = conn.getContentEncoding() != null ? conn.getContentEncoding() : config.getSourceEncoding(); String content = IOGroovyMethods.getText(conn.getInputStream(), encoding); clazz = groovyLoader.parseClass(content, path); } catch (IOException e) { throw new ResourceException(e); } } } finally { forceClose(conn); } return clazz; }
Class clazz = null; if (entry != null) clazz = entry.scriptClass; if (GroovyScriptEngine.this.isSourceNewer(entry)) { try { SourceUnit su = compilationUnit.addSource(url);
/** * 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 * @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 */ public Class loadScriptByName(String scriptName) throws ResourceException, ScriptException { URLConnection conn = rc.getResourceConnection(scriptName); String path = conn.getURL().toExternalForm(); ScriptCacheEntry entry = scriptCache.get(path); Class clazz = null; if (entry != null) clazz = entry.scriptClass; try { if (isSourceNewer(entry)) { try { String encoding = conn.getContentEncoding() != null ? conn.getContentEncoding() : "UTF-8"; String content = DefaultGroovyMethods.getText(conn.getInputStream(), encoding); clazz = groovyLoader.parseClass(content, path); } catch (IOException e) { throw new ResourceException(e); } } } finally { forceClose(conn); } return clazz; }
Class clazz = null; if (entry != null) clazz = entry.scriptClass; if (GroovyScriptEngine.this.isSourceNewer(entry)) { try { SourceUnit su = compilationUnit.addSource(url);