-
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
base: master
Are you sure you want to change the base?
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 |
src/main/java/SimpleAPI.java
Outdated
@@ -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. |
ddd6aa5
to
4a837c6
Compare
- New stringifyOptions method to help convert options object value into compatible string values: This method get a map of java objects and convert the values back to a Map of list of string values to ensure the parameters passed to the startJob method are well-formed. - _startJob and startJob now returns the job it has created and launched for external monitoring. - CommandLineJob has now a getNewMessages and a getErrors methods to help logging - the CommandLineJob getNewMessages method replaces the previous static SimpleAPI.getNewMessages method for finer per-job logging. - Fix uri-encoded result file names.
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. |