From 34a71dba18cd90c54acd656e591a61c0c1822f67 Mon Sep 17 00:00:00 2001 From: koloyyee Date: Mon, 4 Aug 2025 22:48:07 -0400 Subject: [PATCH 1/4] replace Java2Swift.config with swift-java.config --- .../Documentation.docc/SwiftJavaCommandLineTool.md | 2 +- Sources/SwiftJavaTool/Commands/JExtractCommand.swift | 2 +- Sources/SwiftJavaTool/Commands/WrapJavaCommand.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaCommandLineTool.md b/Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaCommandLineTool.md index f83458d4..e8a3dfed 100644 --- a/Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaCommandLineTool.md +++ b/Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaCommandLineTool.md @@ -57,7 +57,7 @@ OPTIONS: The name of the Swift module into which the resulting Swift types will be generated. --depends-on A swift-java configuration file for a given Swift module name on which this module depends, - e.g., JavaKitJar=Sources/JavaKitJar/Java2Swift.config. There should be one of these options + e.g., JavaKitJar=Sources/JavaKitJar/swift-java.config. There should be one of these options for each Swift module that this module depends on (transitively) that contains wrapped Java sources. --swift-native-implementation The names of Java classes whose declared native methods will be implemented in Swift. diff --git a/Sources/SwiftJavaTool/Commands/JExtractCommand.swift b/Sources/SwiftJavaTool/Commands/JExtractCommand.swift index 54a99708..88fbf7f3 100644 --- a/Sources/SwiftJavaTool/Commands/JExtractCommand.swift +++ b/Sources/SwiftJavaTool/Commands/JExtractCommand.swift @@ -70,7 +70,7 @@ extension SwiftJava { @Option( help: """ A swift-java configuration file for a given Swift module name on which this module depends, - e.g., Sources/JavaKitJar/Java2Swift.config. There should be one of these options + e.g., Sources/JavaKitJar/swift-java.config. There should be one of these options for each Swift module that this module depends on (transitively) that contains wrapped Java sources. """ ) diff --git a/Sources/SwiftJavaTool/Commands/WrapJavaCommand.swift b/Sources/SwiftJavaTool/Commands/WrapJavaCommand.swift index 4c5bd97b..3e4a62af 100644 --- a/Sources/SwiftJavaTool/Commands/WrapJavaCommand.swift +++ b/Sources/SwiftJavaTool/Commands/WrapJavaCommand.swift @@ -40,7 +40,7 @@ extension SwiftJava { @Option( help: """ A swift-java configuration file for a given Swift module name on which this module depends, - e.g., JavaKitJar=Sources/JavaKitJar/Java2Swift.config. There should be one of these options + e.g., JavaKitJar=Sources/JavaKitJar/swift-java.config. There should be one of these options for each Swift module that this module depends on (transitively) that contains wrapped Java sources. """ ) From fb96646403e0834f694cfb14649ac5253386111b Mon Sep 17 00:00:00 2001 From: koloyyee Date: Sat, 2 Aug 2025 15:41:55 -0400 Subject: [PATCH 2/4] doc: ResolveCommand dependency resolution functions --- .gitignore | 1 + .../Commands/ResolveCommand.swift | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 28dfbae2..bec8a5e0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .DS_Store .build .idea +.vscode Packages xcuserdata/ DerivedData/ diff --git a/Sources/SwiftJavaTool/Commands/ResolveCommand.swift b/Sources/SwiftJavaTool/Commands/ResolveCommand.swift index 3eb01fe7..063c291a 100644 --- a/Sources/SwiftJavaTool/Commands/ResolveCommand.swift +++ b/Sources/SwiftJavaTool/Commands/ResolveCommand.swift @@ -89,6 +89,16 @@ extension SwiftJava.ResolveCommand { resolvedClasspath: dependenciesClasspath) } + + /// Resolves Java dependencies from swift-java.config and returns classpath information. + /// + /// - Parameters: + /// - swiftModule: module name from --swift-module. e.g.: --swift-module MySwiftModule + /// - dependencies: parsed maven-style dependency descriptors (groupId:artifactId:version) + /// from Sources/MySwiftModule/swift-java.config "dependencies" array. + /// + /// - Throws: + /// - Returns: `ResolvedDependencyClasspath` func resolveDependencies( swiftModule: String, dependencies: [JavaDependencyDescriptor] ) async throws -> ResolvedDependencyClasspath { @@ -108,6 +118,11 @@ extension SwiftJava.ResolveCommand { return ResolvedDependencyClasspath(for: dependencies, classpath: dependenciesClasspath) } + + /// Resolves maven-style dependencies from swift-java.config under temporary project directory. + /// + /// - Parameter dependencies: maven-style dependencies to resolve + /// - Returns: Colon-separated classpath func resolveDependencies(dependencies: [JavaDependencyDescriptor]) async -> String { let workDir = URL(fileURLWithPath: FileManager.default.currentDirectoryPath) .appendingPathComponent(".build") @@ -158,6 +173,7 @@ extension SwiftJava.ResolveCommand { } } + /// Creates Gradle project files (build.gradle, settings.gradle.kts) in temporary directory. func printGradleProject(directory: URL, dependencies: [JavaDependencyDescriptor]) throws { let buildGradle = directory .appendingPathComponent("build.gradle", isDirectory: false) @@ -189,7 +205,15 @@ extension SwiftJava.ResolveCommand { """ try settingsGradleText.write(to: settingsGradle, atomically: true, encoding: .utf8) } - + + /// Creates {MySwiftModule}.swift.classpath in the --output-directory. + /// + /// - Parameters: + /// - swiftModule: Swift module name for classpath filename (--swift-module value) + /// - outputDirectory: Directory path for classpath file (--output-directory value) + /// - resolvedClasspath: Complete dependency classpath information + /// + /// - Throws: TBC mutating func writeSwiftJavaClasspathFile( swiftModule: String, outputDirectory: String, @@ -218,6 +242,7 @@ extension SwiftJava.ResolveCommand { return camelCased } + // copy gradlew & gradle.bat from root, throws error if there is no gradle setup. func copyGradlew(to resolverWorkDirectory: URL) throws { var searchDir = URL(fileURLWithPath: FileManager.default.currentDirectoryPath) From 62ce8669338c2e008593f02bb09ee4b86201f372 Mon Sep 17 00:00:00 2001 From: koloyyee Date: Sat, 9 Aug 2025 09:36:32 -0400 Subject: [PATCH 3/4] update gitgnore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 28dfbae2..b72ffed5 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ bin/ BuildLogic/out/ .index-build .build-vscode +**/.vscode # Ignore gradle build artifacts .gradle @@ -45,3 +46,4 @@ Package.resolved */**/*.swiftdeps */**/*.swiftdeps~ */**/.docc-build/ + From 0fc00aa07696722bf6f7bd71b44a31355b648b0a Mon Sep 17 00:00:00 2001 From: Konrad `ktoso` Malawski Date: Fri, 15 Aug 2025 09:53:03 +0900 Subject: [PATCH 4/4] Apply suggestions from code review --- Sources/SwiftJavaTool/Commands/ResolveCommand.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sources/SwiftJavaTool/Commands/ResolveCommand.swift b/Sources/SwiftJavaTool/Commands/ResolveCommand.swift index 063c291a..c492e788 100644 --- a/Sources/SwiftJavaTool/Commands/ResolveCommand.swift +++ b/Sources/SwiftJavaTool/Commands/ResolveCommand.swift @@ -98,7 +98,6 @@ extension SwiftJava.ResolveCommand { /// from Sources/MySwiftModule/swift-java.config "dependencies" array. /// /// - Throws: - /// - Returns: `ResolvedDependencyClasspath` func resolveDependencies( swiftModule: String, dependencies: [JavaDependencyDescriptor] ) async throws -> ResolvedDependencyClasspath { @@ -213,7 +212,6 @@ extension SwiftJava.ResolveCommand { /// - outputDirectory: Directory path for classpath file (--output-directory value) /// - resolvedClasspath: Complete dependency classpath information /// - /// - Throws: TBC mutating func writeSwiftJavaClasspathFile( swiftModule: String, outputDirectory: String,