Skip to content

Commit db51652

Browse files
joderskyMarcelo Vanzin
authored andcommitted
[SPARK-11832][CORE] Process arguments in spark-shell for Scala 2.11
Process arguments passed to the spark-shell. Fixes running the spark-shell from within a build environment. Author: Jakob Odersky <[email protected]> Closes #9824 from jodersky/shell-2.11.
1 parent 76540b6 commit db51652

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

repl/scala-2.11/src/main/scala/org/apache/spark/repl/Main.scala

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,39 @@ object Main extends Logging {
3131
val tmp = System.getProperty("java.io.tmpdir")
3232
val rootDir = conf.get("spark.repl.classdir", tmp)
3333
val outputDir = Utils.createTempDir(rootDir)
34-
val s = new Settings()
35-
s.processArguments(List("-Yrepl-class-based",
36-
"-Yrepl-outdir", s"${outputDir.getAbsolutePath}",
37-
"-classpath", getAddedJars.mkString(File.pathSeparator)), true)
3834
// the creation of SecurityManager has to be lazy so SPARK_YARN_MODE is set if needed
3935
lazy val classServer = new HttpServer(conf, outputDir, new SecurityManager(conf))
4036
var sparkContext: SparkContext = _
4137
var sqlContext: SQLContext = _
4238
var interp = new SparkILoop // this is a public var because tests reset it.
4339

40+
private var hasErrors = false
41+
42+
private def scalaOptionError(msg: String): Unit = {
43+
hasErrors = true
44+
Console.err.println(msg)
45+
}
46+
4447
def main(args: Array[String]) {
45-
if (getMaster == "yarn-client") System.setProperty("SPARK_YARN_MODE", "true")
46-
// Start the classServer and store its URI in a spark system property
47-
// (which will be passed to executors so that they can connect to it)
48-
classServer.start()
49-
interp.process(s) // Repl starts and goes in loop of R.E.P.L
50-
classServer.stop()
51-
Option(sparkContext).map(_.stop)
48+
49+
val interpArguments = List(
50+
"-Yrepl-class-based",
51+
"-Yrepl-outdir", s"${outputDir.getAbsolutePath}",
52+
"-classpath", getAddedJars.mkString(File.pathSeparator)
53+
) ++ args.toList
54+
55+
val settings = new Settings(scalaOptionError)
56+
settings.processArguments(interpArguments, true)
57+
58+
if (!hasErrors) {
59+
if (getMaster == "yarn-client") System.setProperty("SPARK_YARN_MODE", "true")
60+
// Start the classServer and store its URI in a spark system property
61+
// (which will be passed to executors so that they can connect to it)
62+
classServer.start()
63+
interp.process(settings) // Repl starts and goes in loop of R.E.P.L
64+
classServer.stop()
65+
Option(sparkContext).map(_.stop)
66+
}
5267
}
5368

5469
def getAddedJars: Array[String] = {

repl/scala-2.11/src/test/scala/org/apache/spark/repl/ReplSuite.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ class ReplSuite extends SparkFunSuite {
5454
new SparkILoop(in, new PrintWriter(out))
5555
}
5656
org.apache.spark.repl.Main.interp = interp
57-
Main.s.processArguments(List("-classpath", classpath), true)
58-
Main.main(Array()) // call main
57+
Main.main(Array("-classpath", classpath)) // call main
5958
org.apache.spark.repl.Main.interp = null
6059

6160
if (oldExecutorClasspath != null) {

0 commit comments

Comments
 (0)