Skip to content

Commit

Permalink
This should fix it...
Browse files Browse the repository at this point in the history
The problem was that StringContext wasn't resolved with a `f` in it.
The thing being that the SBT's `scala.StringContext` class from the `sbt-launch.jar` doesn't indeed define it :-S.

Okay, but where is included this jar in the classpath when running `play run`? In the JavaPlatform (from scala jar), which its `result` will contain the user java path.
This path is actually, the only `sbt-launch.jar` when running `play run`.

This can be avoided by setting (a contrary from previous messages): settings.usejavacp.value to false.

Now need some cleanup and detect if the running mode must be detected or, `dist` will still work
  • Loading branch information
andypetrella committed Dec 27, 2014
1 parent c125168 commit ca91a88
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 46 deletions.
2 changes: 2 additions & 0 deletions modules/kernel/src/main/scala/HackSparkILoop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class HackSparkILoop(out:JPrintWriter) extends SparkILoop(None, out, None) {
if (getMaster() == "yarn-client") System.setProperty("SPARK_YARN_MODE", "true")

this.settings = settings

createInterpreter()

// sets in to some kind of reader depending on environmental cues
Expand Down Expand Up @@ -84,6 +85,7 @@ class HackSparkILoop(out:JPrintWriter) extends SparkILoop(None, out, None) {
createAsyncListener() // listens for signal to run postInitialization
}
else {
// ??? intp.getInterpreterClassLoader
intp.initializeSynchronous()
postInitialization()
}
Expand Down
104 changes: 59 additions & 45 deletions modules/kernel/src/main/scala/notebook/kernel/Repl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@
package notebook.kernel

import java.io.{StringWriter, PrintWriter, ByteArrayOutputStream}
import java.net.{URLDecoder, JarURLConnection}
import java.util.ArrayList

import collection.JavaConversions
import collection.JavaConversions._
import xml.{NodeSeq, Text}
import scala.util.control.NonFatal

import org.apache.spark.repl.{HackSparkILoop, SparkILoop, SparkJLineCompletion}

import tools.nsc.Settings
import tools.nsc.interpreter._
import tools.nsc.interpreter.Completion.{Candidates, ScalaCompleter}
import tools.jline.console.completer.{ArgumentCompleter, Completer}
import tools.nsc.interpreter.Completion.Candidates
import tools.nsc.interpreter.Results.{Incomplete => ReplIncomplete, Success => ReplSuccess, Error}
import scala.Either
import java.util.ArrayList
import collection.JavaConversions._

import tools.jline.console.completer.{ArgumentCompleter, Completer}

import play.api.Play

import notebook.front.Widget
import notebook.util.Match
import xml.{NodeSeq, Text}
import collection.JavaConversions
import java.net.{URLDecoder, JarURLConnection}
import scala.util.control.NonFatal

class Repl(val compilerOpts: List[String], val jars:List[String]=Nil) {

Expand Down Expand Up @@ -61,32 +65,6 @@ class Repl(val compilerOpts: List[String], val jars:List[String]=Nil) {

var classServerUri:Option[String] = None

def defaultClassPath: IndexedSeq[String] = {
import java.net._

def urls(cl:ClassLoader, acc:IndexedSeq[String]=IndexedSeq.empty):IndexedSeq[String] = {
if (!cl.isInstanceOf[URLClassLoader]) {
//println(" ----- ")
//println(cl.getClass.getSimpleName)
return acc
}
if (cl != null) {
val us = acc ++ (cl.asInstanceOf[URLClassLoader].getURLs map { u =>
val f = new java.io.File(u.getFile)
URLDecoder.decode(f.getAbsolutePath, "UTF8")
})
urls(cl.getParent, us)
} else {
acc
}
}
val loader = play.api.Play.current.classloader
val gurls = urls(loader)
//println(gurls)
gurls
}


val interp:org.apache.spark.repl.SparkIMain = {
val settings = new Settings

Expand All @@ -97,23 +75,59 @@ class Repl(val compilerOpts: List[String], val jars:List[String]=Nil) {
// TODO: This causes tests to fail in SBT, but work in IntelliJ
// The java CP in SBT contains only a few SBT entries (no project entries), while
// in intellij it has the full module classpath + some intellij stuff.
settings.usejavacp.value = true
settings.usejavacp.value = false


//val urls = java.lang.Thread.currentThread.getContextClassLoader match {
// case cl: java.net.URLClassLoader => cl.getURLs.toList
// case _ => error("classloader is not a URLClassLoader")
//}

val urls = java.lang.Thread.currentThread.getContextClassLoader match {
case cl: java.net.URLClassLoader => cl.getURLs.toList
case _ => error("classloader is not a URLClassLoader")
val urls: IndexedSeq[String] = {
import java.net.URLClassLoader
import java.io.File
def urls(cl:ClassLoader, acc:IndexedSeq[String]=IndexedSeq.empty):IndexedSeq[String] = {
if (!cl.isInstanceOf[URLClassLoader]) {
return acc
}
if (cl != null) {
val us = acc ++ (cl.asInstanceOf[URLClassLoader].getURLs map { u =>
val f = new File(u.getFile)
URLDecoder.decode(f.getAbsolutePath, "UTF8")
})
urls(cl.getParent, us)
} else {
acc
}
}
val loader = Play.current.classloader
val gurls = urls(loader).distinct.filter(!_.contains("sbt/"))
gurls
}
val classpath = urls map {_.toString}

// println(settings.classpath.value)

val classpath = urls// map {_.toString}
// println(classpath)

settings.classpath.value = classpath.distinct.mkString(java.io.File.pathSeparator)

/*
println(settings.classpath.value)
println(settings.bootclasspath.value)
*/

//bootclasspath → settings.classpath.isDefault = false → settings.classpath is used
settings.bootclasspath.value += scala.tools.util.PathResolver.Environment.javaBootClassPath
settings.bootclasspath.value += java.io.File.pathSeparator + settings.classpath.value

//settings.bootclasspath.value += scala.tools.util.PathResolver.Environment.javaBootClassPath
//settings.bootclasspath.value += java.io.File.pathSeparator + defaultClassPath.mkString(java.io.File.pathSeparator)
//settings.bootclasspath.value += java.io.File.pathSeparator + "_lib/scala-library-2.10.4.jar"
//settings.bootclasspath.value += java.io.File.pathSeparator + "_lib/sbt-launch.jar"
/*println(settings.bootclasspath.isDefault)
println(settings.bootclasspath.value)
println(settings.classpath.value)
*/

//println(settings.bootclasspath.value)
// LOG the classpath
settings.Ylogcp.value = true

//val i = new HackIMain(settings, stdout)
loop = new HackSparkILoop(stdout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ object BetterFork {
}
}
val loader = Play.current.classloader
val gurls = urls(loader).distinct.filter(!_.contains("sbt/"))
val gurls = urls(loader).distinct//.filter(!_.contains("sbt/"))
gurls
}

Expand Down

0 comments on commit ca91a88

Please sign in to comment.