@@ -62,6 +62,20 @@ struct JavaToSwift: ParsableCommand {
6262 @Option ( name: . shortAndLong, help: " The directory in which to output the generated Swift files or the Java2Swift configuration file. " )
6363 var outputDirectory : String ? = nil
6464
65+
66+ @Option ( name: . shortAndLong, help: " Directory where to write cached values (e.g. swift-java.classpath files) " )
67+ var cacheDirectory : String ? = nil
68+
69+ var effectiveCacheDirectory : String ? {
70+ if let cacheDirectory {
71+ return cacheDirectory
72+ } else if let outputDirectory {
73+ return outputDirectory
74+ } else {
75+ return nil
76+ }
77+ }
78+
6579 @Option ( name: . shortAndLong, help: " How to handle an existing swift-java.config; by default 'overwrite' by can be changed to amending a configuration " )
6680 var existingConfig : ExistingConfigFileMode = . overwrite
6781 public enum ExistingConfigFileMode : String , ExpressibleByArgument , Codable {
@@ -288,10 +302,16 @@ struct JavaToSwift: ParsableCommand {
288302 environment: jvm. environment ( )
289303 )
290304
291- case . fetchDependencies/*(let config)*/ :
305+ case . fetchDependencies:
292306 guard let dependencies = config. dependencies else {
293307 fatalError ( " Configuration for fetching dependencies must have 'dependencies' defined! " )
294308 }
309+ guard let moduleName = self . moduleName else {
310+ fatalError ( " Fetching dependencies must specify module name (--module-name)! " )
311+ }
312+ guard let effectiveCacheDirectory else {
313+ fatalError ( " Fetching dependencies must effective cache directory! Specify --output-directory or --cache-directory " )
314+ }
295315
296316 let dependencyClasspath = try fetchDependencies (
297317 moduleName: moduleName,
@@ -300,7 +320,10 @@ struct JavaToSwift: ParsableCommand {
300320 environment: jvm. environment ( )
301321 )
302322
303- try writeFetchDependencies ( resolvedClasspath: dependencyClasspath)
323+ try writeFetchedDependenciesClasspath (
324+ moduleName: moduleName,
325+ cacheDir: effectiveCacheDirectory,
326+ resolvedClasspath: dependencyClasspath)
304327 }
305328 } catch {
306329 // We fail like this since throwing out of the run often ends up hiding the failure reason when it is executed as SwiftPM plugin (!)
@@ -309,7 +332,8 @@ struct JavaToSwift: ParsableCommand {
309332 fatalError ( message)
310333 }
311334
312- print ( " [info][swift-java] " + " Done: " . green + CommandLine. arguments. joined ( separator: " " ) )
335+ // Just for debugging so it is clear which command has finished
336+ print ( " [debug][swift-java] " + " Done: " . green + CommandLine. arguments. joined ( separator: " " ) . green)
313337 }
314338
315339 private func names( from javaClassNameOpt: String ) -> ( javaClassName: String , swiftName: String ) {
@@ -346,8 +370,9 @@ struct JavaToSwift: ParsableCommand {
346370 mutating func writeContents(
347371 _ contents: String ,
348372 outputDirectoryOverride: Foundation . URL ? ,
349- to filename: String , description: String ) throws {
350- guard let outputDir = actualOutputDirectory else {
373+ to filename: String ,
374+ description: String ) throws {
375+ guard let outputDir = ( outputDirectoryOverride ?? actualOutputDirectory) else {
351376 print ( " // \( filename) - \( description) " )
352377 print ( contents)
353378 return
@@ -365,9 +390,9 @@ struct JavaToSwift: ParsableCommand {
365390
366391 // Write the file:
367392 let file = outputDir. appendingPathComponent ( filename)
368- print ( " [swift-java] Writing \( description) to ' \( file. path) '... " , terminator: " " )
393+ print ( " [debug][ swift-java] Writing \( description) to ' \( file. path) '... " , terminator: " " )
369394 try contents. write ( to: file, atomically: true , encoding: . utf8)
370- print ( " done." . green)
395+ print ( " done. " . green)
371396 }
372397}
373398
0 commit comments