Skip to content

Commit 48d2b35

Browse files
committed
Correct how we find JavaStdlib/ in swiftpm plugin for wrap-java
1 parent d682e85 commit 48d2b35

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

Plugins/PluginsShared/SwiftJavaPluginProtocol.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ extension SwiftJavaPluginProtocol {
2323
func log(_ message: @autoclosure () -> String, terminator: String = "\n") {
2424
print("[\(pluginName)] \(message())", terminator: terminator)
2525
}
26+
27+
func warn(_ message: @autoclosure () -> String, terminator: String = "\n") {
28+
print("[\(pluginName)][warning] \(message())", terminator: terminator)
29+
}
2630
}

Plugins/SwiftJavaPlugin/SwiftJavaPlugin.swift

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -242,30 +242,34 @@ extension SwiftJavaBuildToolPlugin {
242242
func outputFilePath(context: PluginContext, generated: Bool, filename: String) -> URL {
243243
outputDirectory(context: context, generated: generated).appending(path: filename)
244244
}
245-
}
246-
247-
func getExtractedJavaStdlibModules() -> [String] {
248-
let fileManager = FileManager.default
249-
let sourcesPath = URL(fileURLWithPath: #filePath)
250-
.deletingLastPathComponent()
251-
.deletingLastPathComponent()
252-
.appendingPathComponent("Sources")
253-
.appendingPathComponent("JavaStdlib")
254-
255-
guard let stdlibDirContents = try? fileManager.contentsOfDirectory(
256-
at: sourcesPath,
257-
includingPropertiesForKeys: [.isDirectoryKey],
258-
options: [.skipsHiddenFiles]
259-
) else {
260-
return []
261-
}
262245

263-
return stdlibDirContents.compactMap { url in
264-
guard let resourceValues = try? url.resourceValues(forKeys: [.isDirectoryKey]),
265-
let isDirectory = resourceValues.isDirectory,
266-
isDirectory else {
267-
return nil
246+
func getExtractedJavaStdlibModules() -> [String] {
247+
let fileManager = FileManager.default
248+
log("Search for JavaStdlib inside: \(#filePath)")
249+
let sourcesPath = URL(fileURLWithPath: #filePath)
250+
.deletingLastPathComponent()
251+
.deletingLastPathComponent()
252+
.deletingLastPathComponent()
253+
.appendingPathComponent("Sources")
254+
.appendingPathComponent("JavaStdlib")
255+
256+
guard let stdlibDirContents = try? fileManager.contentsOfDirectory(
257+
at: sourcesPath,
258+
includingPropertiesForKeys: [.isDirectoryKey],
259+
options: [.skipsHiddenFiles]
260+
) else {
261+
warn("Unable to find Java standard library Swift wrappers! Expected \(sourcesPath) to exist." +
262+
"May be unable to wrap-java types involving Java standard library types.")
263+
return []
268264
}
269-
return url.lastPathComponent
270-
}.sorted()
265+
266+
return stdlibDirContents.compactMap { url in
267+
guard let resourceValues = try? url.resourceValues(forKeys: [.isDirectoryKey]),
268+
let isDirectory = resourceValues.isDirectory,
269+
isDirectory else {
270+
return nil
271+
}
272+
return url.lastPathComponent
273+
}.sorted()
274+
}
271275
}

0 commit comments

Comments
 (0)