Skip to content
Merged
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
8 changes: 8 additions & 0 deletions PCL.Mac.Core/Managers/JavaManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ public final class JavaManager {
private init() {
do {
self.javaRuntimes = try JavaSearcher.search()
log("Java 搜索完成,共 \(javaRuntimes.count) 个:")
for javaRuntime in javaRuntimes {
let type: String = .init(describing: javaRuntime.type).padding(toLength: 4, withPad: " ", startingAt: 0)
let version: String = .init(describing: javaRuntime.version).padding(toLength: 10, withPad: " ", startingAt: 0)
let arch: String = .init(describing: javaRuntime.architecture).padding(toLength: 8, withPad: " ", startingAt: 0)
let impl: String = javaRuntime.implementor.padding(toLength: 24, withPad: " ", startingAt: 0)
log("\(type) \(version)\t\(arch)\t\(impl)\t\(javaRuntime.executableURL.path)")
}
} catch {
err("搜索 Java 失败:\(error.localizedDescription)")
self.javaRuntimes = []
Expand Down
9 changes: 8 additions & 1 deletion PCL.Mac.Core/Models/JavaRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ public struct JavaRuntime {
/// `java` 可执行文件 URL。
public let executableURL: URL

public enum JavaType {
public enum JavaType: CustomStringConvertible {
case jdk, jre

public var description: String {
switch self {
case .jdk: "JDK"
case .jre: "JRE"
}
}
}
}
17 changes: 12 additions & 5 deletions PCL.Mac.Core/Services/JavaSearcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,21 @@ public enum JavaSearcher {
private static func findJavaBundles() throws -> [URL] {
var bundleDirectories: [URL] = []

for directory in javaDirectories {
for directory in javaDirectories where FileManager.default.fileExists(atPath: directory.path) {
bundleDirectories.append(contentsOf: try FileManager.default.contentsOfDirectory(at: directory, includingPropertiesForKeys: nil))
}
// Homebrew
let homebrewDirectories: [URL] = try FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: "/opt/homebrew/opt"), includingPropertiesForKeys: nil)
.filter { $0.lastPathComponent.starts(with: "openjdk@") }
for directory in homebrewDirectories {
bundleDirectories.append(directory.appending(path: "libexec").appending(path: "openjdk.jdk"))
let homebrewRoot: URL = .init(fileURLWithPath: "/opt/homebrew/opt")
if FileManager.default.fileExists(atPath: homebrewRoot.path) {
do {
let homebrewDirectories: [URL] = try FileManager.default.contentsOfDirectory(at: homebrewRoot, includingPropertiesForKeys: nil)
.filter { $0.lastPathComponent.starts(with: "openjdk@") }
for directory in homebrewDirectories {
bundleDirectories.append(directory.appending(path: "libexec").appending(path: "openjdk.jdk"))
}
} catch {
err("搜索 Homebrew 目录失败:\(error.localizedDescription)")
}
}
return bundleDirectories.filter { FileManager.default.fileExists(atPath: $0.appending(path: "Contents/Home/release").path) }
}
Expand Down
1 change: 1 addition & 0 deletions PCL.Mac/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
try SwiftScaffolding.Logger.enableLogging(url: URLConstants.logsDirectoryURL.appending(path: "swift-scaffolding.log"))
}
_ = LauncherConfig.shared
_ = JavaManager.shared
executeTask("清理临时文件") {
for url in try FileManager.default.contentsOfDirectory(at: URLConstants.tempURL, includingPropertiesForKeys: nil) {
try FileManager.default.removeItem(at: url)
Expand Down