Skip to content

Commit

Permalink
Merge pull request swiftlang#150 from PADL/lhoward/class-path-validate
Browse files Browse the repository at this point in the history
  • Loading branch information
ktoso authored Nov 5, 2024
2 parents cad41a5 + b08446a commit 3436f46
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Sources/JavaKit/JavaKitVM/JavaVirtualMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
//
//===----------------------------------------------------------------------===//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

typealias JavaVMPointer = UnsafeMutablePointer<JavaVM?>

public final class JavaVirtualMachine: @unchecked Sendable {
Expand Down Expand Up @@ -54,6 +60,12 @@ public final class JavaVirtualMachine: @unchecked Sendable {
// Construct the complete list of VM options.
var allVMOptions: [String] = []
if !classPath.isEmpty {
let fileManager = FileManager.default
for path in classPath {
if !fileManager.fileExists(atPath: path) {
throw JavaKitError.classPathEntryNotFound(entry: path, classPath: classPath)
}
}
let colonSeparatedClassPath = classPath.joined(separator: ":")
allVMOptions.append("-Djava.class.path=\(colonSeparatedClassPath)")
}
Expand Down Expand Up @@ -268,4 +280,8 @@ extension JavaVirtualMachine {
}
}
}

enum JavaKitError: Error {
case classPathEntryNotFound(entry: String, classPath: [String])
}
}

0 comments on commit 3436f46

Please sign in to comment.