Skip to content

wrap-java: add option to match java package style directory nesting #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025
Merged
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
10 changes: 9 additions & 1 deletion Sources/SwiftJavaTool/Commands/WrapJavaCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ extension SwiftJava {
@Option(help: "Cache directory for intermediate results and other outputs between runs")
var cacheDirectory: String?

@Option(help: "Match java package directory structure with generated Swift files")
var swiftMatchPackageDirectoryStructure: Bool = false

@Argument(help: "Path to .jar file whose Java classes should be wrapped using Swift bindings")
var input: String
}
Expand Down Expand Up @@ -229,11 +232,16 @@ extension SwiftJava.WrapJavaCommand {

"""

var generatedFileOutputDir = self.actualOutputDirectory
if self.swiftMatchPackageDirectoryStructure {
generatedFileOutputDir?.append(path: javaClass.getPackageName().replacing(".", with: "/"))
}

let swiftFileName = try! translator.getSwiftTypeName(javaClass, preferValueTypes: false)
.swiftName.replacing(".", with: "+") + ".swift"
try writeContents(
swiftFileText,
outputDirectory: self.actualOutputDirectory,
outputDirectory: generatedFileOutputDir,
to: swiftFileName,
description: "Java class '\(javaClass.getName())' translation"
)
Expand Down
Loading