Search in sources :

Example 1 with AbstractFile

use of scala.reflect.io.AbstractFile in project zeppelin by apache.

the class SparkDependencyResolver method updateCompilerClassPath.

private void updateCompilerClassPath(URL[] urls) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    JavaPlatform platform = (JavaPlatform) global.platform();
    MergedClassPath<AbstractFile> newClassPath = mergeUrlsIntoClassPath(platform, urls);
    Method[] methods = platform.getClass().getMethods();
    for (Method m : methods) {
        if (m.getName().endsWith("currentClassPath_$eq")) {
            m.invoke(platform, new Some(newClassPath));
            break;
        }
    }
    // NOTE: Must use reflection until this is exposed/fixed upstream in Scala
    List<String> classPaths = new LinkedList<>();
    for (URL url : urls) {
        classPaths.add(url.getPath());
    }
    // Reload all jars specified into our compiler
    global.invalidateClassPathEntries(scala.collection.JavaConversions.asScalaBuffer(classPaths).toList());
}
Also used : AbstractFile(scala.reflect.io.AbstractFile) Some(scala.Some) JavaPlatform(scala.tools.nsc.backend.JavaPlatform) Method(java.lang.reflect.Method) LinkedList(java.util.LinkedList) URL(java.net.URL)

Example 2 with AbstractFile

use of scala.reflect.io.AbstractFile in project zeppelin by apache.

the class SparkDependencyResolver method mergeUrlsIntoClassPath.

private MergedClassPath<AbstractFile> mergeUrlsIntoClassPath(JavaPlatform platform, URL[] urls) {
    IndexedSeq<ClassPath<AbstractFile>> entries = ((MergedClassPath<AbstractFile>) platform.classPath()).entries();
    List<ClassPath<AbstractFile>> cp = new LinkedList<>();
    for (int i = 0; i < entries.size(); i++) {
        cp.add(entries.apply(i));
    }
    for (URL url : urls) {
        AbstractFile file;
        if ("file".equals(url.getProtocol())) {
            File f = new File(url.getPath());
            if (f.isDirectory()) {
                file = AbstractFile.getDirectory(scala.reflect.io.File.jfile2path(f));
            } else {
                file = AbstractFile.getFile(scala.reflect.io.File.jfile2path(f));
            }
        } else {
            file = AbstractFile.getURL(url);
        }
        ClassPath<AbstractFile> newcp = platform.classPath().context().newClassPath(file);
        // distinct
        if (cp.contains(newcp) == false) {
            cp.add(newcp);
        }
    }
    return new MergedClassPath(scala.collection.JavaConversions.asScalaBuffer(cp).toIndexedSeq(), platform.classPath().context());
}
Also used : ClassPath(scala.tools.nsc.util.ClassPath) MergedClassPath(scala.tools.nsc.util.MergedClassPath) AbstractFile(scala.reflect.io.AbstractFile) MergedClassPath(scala.tools.nsc.util.MergedClassPath) AbstractFile(scala.reflect.io.AbstractFile) File(java.io.File) LinkedList(java.util.LinkedList) URL(java.net.URL)

Aggregations

URL (java.net.URL)2 LinkedList (java.util.LinkedList)2 AbstractFile (scala.reflect.io.AbstractFile)2 File (java.io.File)1 Method (java.lang.reflect.Method)1 Some (scala.Some)1 JavaPlatform (scala.tools.nsc.backend.JavaPlatform)1 ClassPath (scala.tools.nsc.util.ClassPath)1 MergedClassPath (scala.tools.nsc.util.MergedClassPath)1