-
Notifications
You must be signed in to change notification settings - Fork 49
Add a SwiftPM build plugin to generate Swift wrappers for Java classes #77
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
Conversation
Introduce the plugin `Java2SwiftPlugin`, which will invoke Java2Swift to generate Swift wrappers for the specified Java classes. Each SwiftPM target that uses this plugin must contain a file named `Java2Swift.config` that specifies options for the Java2Swift tool. This is a JSON file with a top-level dictionary that currently can contain keys for the Java class path (`classPath`) and a dictionary called `classes` whose keys are Java canonical class names (such as `java.util.Vector`) and whose values are the corresponding Swift names. For example: ```swift { "classes" : { "java.util.Vector" : "JavaVector" } } ``` will translate the class `java.util.Vector` into the Swift type `JavaVector`. The resulting Swift files will become part of the Swift module that uses this plugin. I've updated the JavaKitSampleApp to make use of this, albeit in a very narrow way that is not at all compelling. The user guide also needs updating. Fixes issue swiftlang#16
@@ -0,0 +1,5 @@ | |||
{ | |||
"classes" : { | |||
"java.util.Vector" : null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vector is a rarely used type that folks generally avoid as it predates the "proper collections framework", I'd recommend avoiding it in examples (it'll look weird to Java developers that we're using that anywhere) and using java.util.ArrayList
in examples.
double checked in docs:
As of the Java 2 platform v1.2, this class was retrofitted to implement the List interface, making it a member of the Java Collections Framework. Unlike the new collection implementations, Vector is synchronized. If a thread-safe implementation is not needed, it is recommended to use ArrayList in place of Vector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was picking something silly that we wouldn't actually end up wrapping in any of the JavaKit* modules, but yeah... Vector is extra silly. Thanks for the ArrayList suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, no harm but a bit too silly maybe :) No prob
Package.swift
Outdated
@@ -56,6 +56,11 @@ let package = Package( | |||
targets: ["JavaKit"] | |||
), | |||
|
|||
.library( | |||
name: "JavaRuntime", | |||
targets: [ "JavaRuntime"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
targets: [ "JavaRuntime"] | |
targets: ["JavaRuntime"] |
Need to enable the Swift formatting enforcement soon 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start, LGTM, minor nitpick inline
@@ -5,6 +5,7 @@ | |||
.swift-format | |||
.github/* | |||
*.md | |||
**/*.config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to fix the license checking CI job, since it checked and failed on the new file not having a license header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thank you!
20afcf3
to
8496f1a
Compare
I have improvements I'd still like to make (e.g., handling Jar files, documenting this new path), but this is a good start |
Introduce the plugin
Java2SwiftPlugin
, which will invoke Java2Swift to generate Swift wrappers for the specified Java classes. Each SwiftPM target that uses this plugin must contain a file namedJava2Swift.config
that specifies options for the Java2Swift tool. This is a JSON file with a top-level dictionary that currently can contain keys for the Java class path (classPath
) and a dictionary calledclasses
whose keys are Java canonical class names (such asjava.util.Vector
) and whose values are the corresponding Swift names. For example:will translate the class
java.util.Vector
into the Swift typeJavaVector
. The resulting Swift files will become part of the Swift module that uses this plugin.I've updated the JavaKitSampleApp to make use of this, albeit in a very narrow way that is not at all compelling. The user guide also needs updating.
Fixes issue #16