Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ object CommandUtils extends Logging {
def buildJavaOpts(command: Command, memory: Int, sparkHome: String): Seq[String] = {
val memoryOpts = Seq(s"-Xms${memory}M", s"-Xmx${memory}M")
// Note, this will coalesce multiple options into a single command component
val extraOpts = command.extraJavaOptions.toSeq
val extraOpts = command.extraJavaOptions match {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to you, but could be written a bit more consicely

val extraOpts = command.extraJavaOptions.map(Utils.splitCommandString).getOrElse(Seq())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, val extraOpts = command.extraJavaOptions.map(Utils.splitCommandString).getOrElse(Seq()) is better

case Some(opts) =>
opts.split("\\s+").toSeq
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Utils.splitCommandString instead of this, in case people pass in stuff with quotes.

case _ =>
Seq()
}

val libraryOpts =
if (command.libraryPathEntries.size > 0) {
val joined = command.libraryPathEntries.mkString(File.pathSeparator)
Expand All @@ -62,10 +68,10 @@ object CommandUtils extends Logging {
val classPath = Utils.executeAndGetOutput(
Seq(sparkHome + "/bin/compute-classpath" + ext),
extraEnvironment=command.environment)
val userClassPath = command.classPathEntries.mkString(File.pathSeparator)
val classPathWithUser = classPath + File.pathSeparator + userClassPath
val userClassPath = command.classPathEntries ++ Seq(classPath)

Seq("-cp", classPathWithUser) ++ libraryOpts ++ extraOpts ++ memoryOpts
Seq("-cp", userClassPath.filterNot(_.isEmpty).mkString(File.pathSeparator)) ++
libraryOpts ++ extraOpts ++ memoryOpts
}

/** Spawn a thread that will redirect a given stream to a file */
Expand Down