Search in sources :

Example 11 with AntClassLoader

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);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) AntClassLoader(org.apache.tools.ant.AntClassLoader) URL(java.net.URL) Function(com.google.common.base.Function) URLClassLoader(java.net.URLClassLoader) NonDelegatingClassLoader(com.google.errorprone.internal.NonDelegatingClassLoader) URLClassLoader(java.net.URLClassLoader) AntClassLoader(org.apache.tools.ant.AntClassLoader) BuildException(org.apache.tools.ant.BuildException)

Example 12 with AntClassLoader

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);
}
Also used : Project(org.apache.tools.ant.Project) AntClassLoader(org.apache.tools.ant.AntClassLoader) BuildException(org.apache.tools.ant.BuildException)

Aggregations

AntClassLoader (org.apache.tools.ant.AntClassLoader)12 BuildException (org.apache.tools.ant.BuildException)8 URL (java.net.URL)6 URLClassLoader (java.net.URLClassLoader)5 File (java.io.File)4 IOException (java.io.IOException)4 MalformedURLException (java.net.MalformedURLException)3 ArrayList (java.util.ArrayList)3 Project (org.apache.tools.ant.Project)3 Function (com.google.common.base.Function)2 GroovyClassLoader (groovy.lang.GroovyClassLoader)2 GroovyResourceLoader (groovy.lang.GroovyResourceLoader)2 WebAppClassLoader (org.eclipse.jetty.webapp.WebAppClassLoader)2 SuiteHint (com.carrotsearch.ant.tasks.junit4.balancers.SuiteHint)1 AggregatedQuitEvent (com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedQuitEvent)1 AggregatedStartEvent (com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedStartEvent)1 AggregatedEventListener (com.carrotsearch.ant.tasks.junit4.listeners.AggregatedEventListener)1 FilterExpressionParser (com.carrotsearch.randomizedtesting.FilterExpressionParser)1 Node (com.carrotsearch.randomizedtesting.FilterExpressionParser.Node)1 EventBus (com.google.common.eventbus.EventBus)1