use of groovy.lang.GroovyClassLoader in project spring-boot by spring-projects.
the class AetherGrapeEngineTests method dependencyResolutionWithCustomClassLoader.
@Test
public void dependencyResolutionWithCustomClassLoader() {
Map<String, Object> args = new HashMap<>();
GroovyClassLoader customClassLoader = new GroovyClassLoader();
args.put("classLoader", customClassLoader);
createGrapeEngine(this.springMilestones).grab(args, createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"));
assertThat(this.groovyClassLoader.getURLs().length).isEqualTo(0);
assertThat(customClassLoader.getURLs().length).isEqualTo(5);
}
use of groovy.lang.GroovyClassLoader in project groovy by apache.
the class Groovyc method loadRegisteredScriptExtensions.
private void loadRegisteredScriptExtensions() {
if (scriptExtensions.isEmpty()) {
// first extension will be the one set explicitly on <groovyc>
scriptExtensions.add(getScriptExtension().substring(2));
Path classpath = getClasspath() != null ? getClasspath() : new Path(getProject());
final String[] pe = classpath.list();
final GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader());
for (String file : pe) {
loader.addClasspath(file);
}
scriptExtensions.addAll(SourceExtensionHandler.getRegisteredExtensions(loader));
}
}
use of groovy.lang.GroovyClassLoader in project groovy by apache.
the class GroovycTask method compile.
protected void compile() {
Path path = getClasspath();
if (path != null) {
config.setClasspath(path.toString());
}
config.setTargetDirectory(destdir);
GroovyClassLoader gcl = createClassLoader();
CompilationUnit compilation = new CompilationUnit(config, null, gcl);
GlobPatternMapper mapper = new GlobPatternMapper();
mapper.setFrom("*.groovy");
mapper.setTo("*.class");
int count = 0;
String[] list = src.list();
for (int i = 0; i < list.length; i++) {
File basedir = getProject().resolveFile(list[i]);
if (!basedir.exists()) {
throw new BuildException("Source directory does not exist: " + basedir, getLocation());
}
DirectoryScanner scanner = getDirectoryScanner(basedir);
String[] includes = scanner.getIncludedFiles();
if (force) {
log.debug("Forcefully including all files from: " + basedir);
for (int j = 0; j < includes.length; j++) {
File file = new File(basedir, includes[j]);
log.debug(" " + file);
compilation.addSource(file);
count++;
}
} else {
log.debug("Including changed files from: " + basedir);
SourceFileScanner sourceScanner = new SourceFileScanner(this);
File[] files = sourceScanner.restrictAsFiles(includes, basedir, destdir, mapper);
for (int j = 0; j < files.length; j++) {
log.debug(" " + files[j]);
compilation.addSource(files[j]);
count++;
}
}
}
if (count > 0) {
log.info("Compiling " + count + " source file" + (count > 1 ? "s" : "") + " to " + destdir);
compilation.compile();
} else {
log.info("No sources found to compile");
}
}
use of groovy.lang.GroovyClassLoader in project groovy by apache.
the class JdkDynamicProxyTest method testJdkDynamicProxySameLoader.
public void testJdkDynamicProxySameLoader() throws Exception {
// Instantiate all beans.
final GroovyClassLoader loader = new GroovyClassLoader();
JdkDynamicProxyServiceBean sb1 = (JdkDynamicProxyServiceBean) JdkDynamicProxyInvocationHandler.getProxiedObject(loader.loadClass("org.codehaus.groovy.runtime.JdkDynamicProxyServiceBeanImpl1").newInstance());
JdkDynamicProxyServiceBean sb2 = (JdkDynamicProxyServiceBean) JdkDynamicProxyInvocationHandler.getProxiedObject(loader.loadClass("org.codehaus.groovy.runtime.JdkDynamicProxyServiceBeanImpl2").newInstance());
// Manually wire beans together.
sb1.setJdkDynamicProxyServiceBean(sb2);
assertEquals("SERVICE", sb1.doService());
}
use of groovy.lang.GroovyClassLoader in project groovy by apache.
the class StaticInitTest method testInitOrder.
public void testInitOrder() throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException {
final Field f = new GroovyClassLoader().loadClass("org.codehaus.groovy.runtime.X", false, false, false).getField("field");
assertTrue(!failed);
f.getInt(null);
assertTrue(failed);
}
Aggregations