use of org.apache.tools.ant.AntClassLoader in project error-prone by google.
the class ErrorProneAntCompilerAdapter method execute.
@Override
public boolean execute() throws BuildException {
ClassLoader originalLoader = ErrorProneCompiler.class.getClassLoader();
URL[] urls;
if (originalLoader instanceof URLClassLoader) {
urls = ((URLClassLoader) originalLoader).getURLs();
} else if (originalLoader instanceof AntClassLoader) {
String[] pieces = ((AntClassLoader) originalLoader).getClasspath().split(":");
urls = new URL[pieces.length];
for (int i = 0; i < pieces.length; ++i) {
try {
urls[i] = Paths.get(pieces[i]).toUri().toURL();
} catch (MalformedURLException e) {
throw new BuildException(e);
}
}
} else {
throw new BuildException("Unexpected ClassLoader: " + originalLoader.getClass());
}
ClassLoader loader = NonDelegatingClassLoader.create(ImmutableSet.<String>of(Function.class.getName()), urls, originalLoader);
String[] args = setupModernJavacCommand().getArguments();
try {
Class<?> runnerClass = Class.forName(AntRunner.class.getName(), true, loader);
@SuppressWarnings("unchecked") Function<String[], Boolean> runner = (Function<String[], Boolean>) runnerClass.newInstance();
return runner.apply(args);
} catch (ReflectiveOperationException e) {
throw new LinkageError("Unable to create runner.", e);
}
}
use of org.apache.tools.ant.AntClassLoader in project groovy by apache.
the class RootLoaderRef method execute.
public void execute() throws BuildException {
if (taskClasspath == null || taskClasspath.size() == 0) {
throw new BuildException("no classpath given");
}
Project project = getProject();
AntClassLoader loader = new AntClassLoader(makeRoot(), true);
project.addReference(name, loader);
}
Aggregations