From 49e248e7a055c50586bf1f4170c5404566adba23 Mon Sep 17 00:00:00 2001 From: witgo Date: Sun, 27 Apr 2014 10:44:29 +0800 Subject: [PATCH] Fix SPARK-1629: Spark should inline use of commons-lang `SystemUtils.IS_OS_WINDOWS` --- .../main/scala/org/apache/spark/util/Utils.scala | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/src/main/scala/org/apache/spark/util/Utils.scala b/core/src/main/scala/org/apache/spark/util/Utils.scala index 8351f7156a5e4..cabea5ac03e88 100644 --- a/core/src/main/scala/org/apache/spark/util/Utils.scala +++ b/core/src/main/scala/org/apache/spark/util/Utils.scala @@ -30,7 +30,6 @@ import scala.io.Source import scala.reflect.ClassTag import com.google.common.io.Files -import org.apache.commons.lang.SystemUtils import com.google.common.util.concurrent.ThreadFactoryBuilder import org.apache.hadoop.fs.{FileSystem, FileUtil, Path} import org.json4s._ @@ -49,7 +48,7 @@ private[spark] object Utils extends Logging { val random = new Random() def sparkBin(sparkHome: String, which: String): File = { - val suffix = if (SystemUtils.IS_OS_WINDOWS) ".cmd" else "" + val suffix = if (isWindows) ".cmd" else "" new File(sparkHome + File.separator + "bin", which + suffix) } @@ -609,7 +608,7 @@ private[spark] object Utils extends Logging { */ def isSymlink(file: File): Boolean = { if (file == null) throw new NullPointerException("File must not be null") - if (SystemUtils.IS_OS_WINDOWS) return false + if (isWindows) return false val fileInCanonicalDir = if (file.getParent() == null) { file } else { @@ -1013,7 +1012,7 @@ private[spark] object Utils extends Logging { throw new IOException("Destination must be relative") } var cmdSuffix = "" - val linkCmd = if (SystemUtils.IS_OS_WINDOWS) { + val linkCmd = if (isWindows) { // refer to http://technet.microsoft.com/en-us/library/cc771254.aspx cmdSuffix = " /s /e /k /h /y /i" "cmd /c xcopy " @@ -1056,4 +1055,11 @@ private[spark] object Utils extends Logging { def getHadoopFileSystem(path: String): FileSystem = { getHadoopFileSystem(new URI(path)) } + + /** + * return true if this is Windows. + */ + def isWindows = Option(System.getProperty("os.name")). + map(_.startsWith("Windows")).getOrElse(false) + }