use of org.codehaus.groovy.tools.RootLoader in project groovy by apache.
the class Groovyc method buildClassLoaderFor.
protected GroovyClassLoader buildClassLoaderFor() {
// GROOVY-5044
if (!fork && !getIncludeantruntime()) {
throw new IllegalArgumentException("The includeAntRuntime=false option is not compatible with fork=false");
}
ClassLoader parent = getIncludeantruntime() ? getClass().getClassLoader() : new AntClassLoader(new RootLoader(EMPTY_URL_ARRAY, null), getProject(), getClasspath());
if (parent instanceof AntClassLoader) {
AntClassLoader antLoader = (AntClassLoader) parent;
String[] pathElm = antLoader.getClasspath().split(File.pathSeparator);
List<String> classpath = configuration.getClasspath();
/*
* Iterate over the classpath provided to groovyc, and add any missing path
* entries to the AntClassLoader. This is a workaround, since for some reason
* 'directory' classpath entries were not added to the AntClassLoader' classpath.
*/
for (String cpEntry : classpath) {
boolean found = false;
for (String path : pathElm) {
if (cpEntry.equals(path)) {
found = true;
break;
}
}
/*
* fix for GROOVY-2284
* seems like AntClassLoader doesn't check if the file
* may not exist in the classpath yet
*/
if (!found && new File(cpEntry).exists()) {
try {
antLoader.addPathElement(cpEntry);
} catch (BuildException e) {
log.warn("The classpath entry " + cpEntry + " is not a valid Java resource");
}
}
}
}
GroovyClassLoader loader = new GroovyClassLoader(parent, configuration);
if (!forceLookupUnnamedFiles) {
// in normal case we don't need to do script lookups
loader.setResourceLoader(new GroovyResourceLoader() {
public URL loadGroovySource(String filename) throws MalformedURLException {
return null;
}
});
}
return loader;
}
use of org.codehaus.groovy.tools.RootLoader in project groovy by apache.
the class RootLoaderRef method makeRoot.
private RootLoader makeRoot() {
String[] list = taskClasspath.list();
LoaderConfiguration lc = new LoaderConfiguration();
for (int i = 0; i < list.length; i++) {
if (list[i].matches(".*ant-[^/]*jar$")) {
continue;
}
if (list[i].matches(".*commons-logging-[^/]*jar$")) {
continue;
}
if (list[i].matches(".*xerces-[^/]*jar$")) {
continue;
}
lc.addFile(list[i]);
}
return new RootLoader(lc);
}
use of org.codehaus.groovy.tools.RootLoader in project groovy-core by groovy.
the class Groovyc method buildClassLoaderFor.
protected GroovyClassLoader buildClassLoaderFor() {
// GROOVY-5044
if (!fork && !getIncludeantruntime()) {
throw new IllegalArgumentException("The includeAntRuntime=false option is not compatible with fork=false");
}
ClassLoader parent = getIncludeantruntime() ? getClass().getClassLoader() : new AntClassLoader(new RootLoader(EMPTY_URL_ARRAY, null), getProject(), getClasspath());
if (parent instanceof AntClassLoader) {
AntClassLoader antLoader = (AntClassLoader) parent;
String[] pathElm = antLoader.getClasspath().split(File.pathSeparator);
List<String> classpath = configuration.getClasspath();
/*
* Iterate over the classpath provided to groovyc, and add any missing path
* entries to the AntClassLoader. This is a workaround, since for some reason
* 'directory' classpath entries were not added to the AntClassLoader' classpath.
*/
for (String cpEntry : classpath) {
boolean found = false;
for (String path : pathElm) {
if (cpEntry.equals(path)) {
found = true;
break;
}
}
/*
* fix for GROOVY-2284
* seems like AntClassLoader doesn't check if the file
* may not exist in the classpath yet
*/
if (!found && new File(cpEntry).exists()) {
try {
antLoader.addPathElement(cpEntry);
} catch (BuildException e) {
log.warn("The classpath entry " + cpEntry + " is not a valid Java resource");
}
}
}
}
GroovyClassLoader loader = new GroovyClassLoader(parent, configuration);
if (!forceLookupUnnamedFiles) {
// in normal case we don't need to do script lookups
loader.setResourceLoader(new GroovyResourceLoader() {
public URL loadGroovySource(String filename) throws MalformedURLException {
return null;
}
});
}
return loader;
}
use of org.codehaus.groovy.tools.RootLoader in project groovy-core by groovy.
the class RootLoaderRef method makeRoot.
private RootLoader makeRoot() {
String[] list = taskClasspath.list();
LoaderConfiguration lc = new LoaderConfiguration();
for (int i = 0; i < list.length; i++) {
if (list[i].matches(".*ant-[^/]*jar$")) {
continue;
}
if (list[i].matches(".*commons-logging-[^/]*jar$")) {
continue;
}
if (list[i].matches(".*xerces-[^/]*jar$")) {
continue;
}
lc.addFile(list[i]);
}
return new RootLoader(lc);
}
Aggregations