-
Notifications
You must be signed in to change notification settings - Fork 5
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
[simple-api] simplified method for JNI bridges #221
Conversation
NPavie
commented
Nov 20, 2023
- Handle URIs in options
- Return the job object for external monitoring
- Generalize withArgument to allow the use of java objects and raw types instead of string in options
- handle null arguments
- when writing result, decode the idx to avoid url-encoded file names
@NPavie I wonder why you need this. Also I'm not sure whether your change actually did what you intended: I don't see any Java objects provided to Also note that If you want to provide inputs or fetch outputs through other ways than through (string) paths,
Why do you need this? Actually I'd rather throw an
Why do you need this? The idea of
Why do you do that? In which case did you get an URL-encoded idx? If this happens, that might be an error in the Pipeline itself (and not something we need to fix in |
@@ -334,7 +358,7 @@ else if (file.list().length > 0) | |||
if (file.isDirectory()) { | |||
if (file.list().length > 0) | |||
throw new IllegalArgumentException("Directory is not empty: " + file); | |||
resultLocations.put(port, URI.create(file.toURI() + "/")); | |||
resultLocations.put(port, file.toURI()); |
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.
Why this change?
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.
If i recall, It could lead to invalid/malformed path on windows ending by "//" or "\/"
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 see. Shouldn't we instead change the
if (result.endsWith("/")) {
above to
if (result.endsWith("/") || result.endsWith("\\")) {
?
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.
Indeed, I did not treat this in the results side (only the parameters initialization side was creating issues during developement of the connection between word addin and pipeline)
Oh Ok, I might need to change the plugin code in that case, or make an alternative entrypoint.
If i recall, at first i had "unspecified" options in some scripts, and i don't remember why but in that case it would produce "null" values for the options and it was making the script crash.
URI handling in the code was incorrect in the previous code, it would raised exception on windows, especially when trying to check if path is absolute.
When i checked, the idx values are URI encoded and you create a system path in the code (not an URI path): |
So if I understand correctly you made the Perhaps the real issue we need to solve is that Pipeline should be more relaxed about which values to accept. For example, a "boolean" value should currently be either "true", "false", "1" or "0". In addition we could allow also "True", "False", "TRUE", "FALSE", etc.
I think an example would help. What kind of input is causing exceptions?
Aha I see. You're right. I think I would fix it as follows though: File dest = new File(u.resolve(r.strip().getIdx())); |
Hum i have rested the simple API from the current version and i can't reproduce the issue i had before when forwarding URIs. I realised that the URI fix and most changes i made was based on the first version of the SimpleAPI and with an older JRE so it's possible the fixes i made was only needed with that version, and/or that some fixes like the absolute check for URI path was done at the JRE level. I'll rework the PR to only provided the fixes that i think are really of use for (my) usage of the SimpleAPI through JNI :
|
35c0c97
to
8c50d09
Compare
8c50d09
to
71cd4b0
Compare
@NPavie So you prefer to use the Regarding the new public static Map<String,Iterable<String>> stringifyOptions(Map<String,Object> options) { ... } |
I still think this problem can also (at least partly) be solved by being less strict in the validation of option values. Can you show me what a typical option map coming from the Word add-in looks like? |
Yes i prefer, mainly because i have a project in house to do some batch conversions from another C# project with possibly multiple jobs running.
Oh indeed it would be a good alternative !
I'll try to make an example, but i remember i was facing 2 problems when i had the need of going with the more generic
I think the second point was the main issue that made me change the start function to accept more generic objects at the time. Anyway, i think the "stringifyOptions" approach will help ensure parameters are correctly stringified for usage of SimpleAPI Through JNI, while keeping the normal startJob behavior as targeted for command line usage. |
4a837c6
to
4228251
Compare
@bertfrees I added a bit more documentation to the SimpleAPI and did the following:
It makes the API more (And I also changed the job info messages output of the main to be on the standard output) I'm thinking of making on the side a little C or C++ version of the main just to illustrate the usage through JNI, maybe in another repo for demo. |
I think there has been a bit of a misunderstanding. Calabash indeed supports options with any type of XDM value, and the word-to-dtbook step indeed had an option that accepted maps. However Pipeline scripts are an abstraction layer on top of XProc steps, and script options are unfortunately simple strings. It is of course also possible to create JNI bindings for the XProc API, and if I remember correctly we discussed that, and at one point I had even added it to the SimpleAPI class. But I changed my mind when I realized it was not a good idea. There is a reason we have the abstraction layer, and we should not try to work around it unless we have a very good reason. |
Also prepare pipeline engine rebuild from submodule (requires the merge of a daisy/pipeline-assembly#221 for finalization)
Hi @bertfrees, I was wondering if something remained to be changed here regarding the proposal for easier interoperability with JNI ? |
I still don't like the I don't like what it does. It just feels like a hack to me:
and I don't like the reason for adding it:
|
Ok, we can remove this function then for the PR (I figured how to redo it on the jni side if need be) |
4228251
to
f65813b
Compare
@bertfrees the |
Thanks. |
Accept "True" and "False" in addition to "true", "false", "1" and "0". see daisy/pipeline-assembly#221
- Return the job object for external monitoring - The job is wrapped in a CommandLineJob object that has convenience methods for handling messages. The CommandLineJob.getNewMessages() method replaces the static method from before for per-job logging. Co-authored-by: Bert Frees <[email protected]>
in addition to file path values.
f65813b
to
262183f
Compare
I did some clean up and rebased onto master. |
Everything works with my jni-side of options' stringification, so I would say its fine for me. (I assume the version of the framework with the commit you mentioned is not yet referenced in the assembly master branch, if I remove the stringification i get a "value "False" not accepted" error) |
No, it is not included yet. Perhaps we need to test it first, just to be sure I did it right. But I'm unsure how. Shall I deploy the snapshot? |
The PR does not strictly depend on it, but if you do I can run a quick test just to be sure |
I deployed framework-bom 1.14.20-SNAPSHOT. |
I finally got the time to launch the test with the new bom, and I confirm : it works :) |
Nice. I'll merge now. |
Merged in ff701bc |