Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ private[spark] trait SparkTestUtils {
Seq(
"-classpath",
classpathUrls
.map {
_.getFile
.map { u =>
new File(u.toURI).getPath
}
.mkString(File.pathSeparator))
} else {
Expand Down Expand Up @@ -123,7 +123,8 @@ private[spark] trait SparkTestUtils {

val options = Seq("-d", classDir.getAbsolutePath) ++ (
if (classpathUrls.nonEmpty) {
Seq("-classpath", classpathUrls.map(_.getFile).mkString(File.pathSeparator))
Seq("-classpath",
classpathUrls.map(u => new File(u.toURI).getPath).mkString(File.pathSeparator))
} else Seq.empty
)

Expand Down Expand Up @@ -177,7 +178,7 @@ private[spark] trait SparkTestUtils {
// on Windows to work around CMD's command-line length limit and by some build/CI
// tools. Expand any such JARs before invoking scalac so the classpath is complete.
val expandedClasspath = classpathUrls.flatMap(expandManifestClasspath)
val cpStr = expandedClasspath.map(_.getFile).mkString(File.pathSeparator)
val cpStr = expandedClasspath.map(u => new File(u.toURI).getPath).mkString(File.pathSeparator)
val args = Array("-classpath", cpStr, "-d", classDir.getAbsolutePath) ++
sourceFiles.map(_.getAbsolutePath)

Expand Down Expand Up @@ -216,7 +217,7 @@ private[spark] trait SparkTestUtils {
* original URL unchanged.
*/
private[spark] def expandManifestClasspath(url: URL): Seq[URL] = {
val file = new File(url.getFile)
val file = new File(url.toURI)
if (!file.exists() || !file.getName.endsWith(".jar")) return Seq(url)
try {
val jarFile = new JarFile(file)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.spark.util

import org.scalatest.funsuite.AnyFunSuite // scalastyle:ignore funsuite

class SparkTestUtilsSuite extends AnyFunSuite with SparkTestUtils { // scalastyle:ignore funsuite

test("SPARK-57081: createCompiledClass with spaces in classpath") {
val dir = SparkFileUtils.createTempDir(namePrefix = "path with spaces")
val sourceFile = new JavaSourceFromString("Hello", "public class Hello {}")
val result = createCompiledClass("Hello", dir, sourceFile, Seq(dir.toURI.toURL))
assert(result.exists(), s"Compiled class file should exist at ${result.getPath}")
}
}