private ExtendedGroovyClassLoader createLoader( GroovyCompilerConfiguration configuration) { ExtendedGroovyClassLoader loader = new ExtendedGroovyClassLoader( configuration.getScope()); for (URL url : getExistingUrls()) { loader.addURL(url); } for (String classpath : configuration.getClasspath()) { loader.addClasspath(classpath); } return loader; }
public ExtendedGroovyClassLoader(GroovyCompilerScope scope) { this(scope, createParentClassLoader(scope), new CompilerConfiguration()); }
private Class<?> findSharedClass(String name) { try { String path = name.replace('.', '/').concat(".class"); try (InputStream inputStream = getParent().getResourceAsStream(path)) { if (inputStream != null) { return defineClass(name, FileCopyUtils.copyToByteArray(inputStream)); } } return null; } catch (Exception ex) { return null; } }
throws CompilationFailedException, IOException { this.loader.clearCache(); List<Class<?>> classes = new ArrayList<>(); CompilerConfiguration configuration = this.loader.getConfiguration(); ClassCollector collector = this.loader.createCollector(compilationUnit, null); compilationUnit.setClassgenCallback(collector);
public void addCompilationCustomizers(CompilationCustomizer... customizers) { this.loader.getConfiguration().addCompilationCustomizers(customizers); }
@Override public ClassCollector createCollector(CompilationUnit unit, SourceUnit su) { InnerLoader loader = AccessController.doPrivileged(getInnerLoader()); return new ExtendedClassCollector(loader, unit, su); }
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { try { return super.findClass(name); } catch (ClassNotFoundException ex) { if (this.scope == GroovyCompilerScope.DEFAULT && name.startsWith(SHARED_PACKAGE)) { Class<?> sharedClass = findSharedClass(name); if (sharedClass != null) { return sharedClass; } } throw ex; } }
this.loader.getConfiguration() .addCompilationCustomizers(new CompilerAutoConfigureCustomizer()); if (configuration.isAutoconfigure()) {