-
Notifications
You must be signed in to change notification settings - Fork 40
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
Adding support for setting java system properties (go-tika #15) #16
Conversation
… Start function to check for added props, wrote test.
tika/server.go
Outdated
port string | ||
cmd *exec.Cmd | ||
child *ChildOptions | ||
javaprops map[string]string |
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.
Can we export this variable and have people set it directly? Then we won't need the AddJavaProp
function, which will be nicer when setting multiple properties.
javaprops map[string]string | |
JavaProps map[string]string |
That makes a lot of sense. I'll make the changes. |
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.
Thanks, again, for doing this!
Heads up, I'll be slow to respond until March 16.
tika/server.go
Outdated
@@ -41,7 +41,7 @@ type Server struct { | |||
port string | |||
cmd *exec.Cmd | |||
child *ChildOptions | |||
javaprops map[string]string | |||
Javaprops map[string]string |
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.
Probably JavaProps
? Also, please add a documentation comment for this field. What is it for, how is it passed to the server, etc.
tika/server.go
Outdated
s.url = u.String() | ||
|
||
s.Javaprops = make(map[string]string) |
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.
Mind moving this above to the declaration of s
? Does it need to be pre-initialized?
tika/server.go
Outdated
if len(s.javaprops) > 0 { | ||
for i := range s.javaprops { | ||
props = fmt.Sprintf("-D%s=%s ", i, s.javaprops[i]) | ||
if len(s.Javaprops) > 0 { |
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.
range
works well on an empty map. So, we can skip this check.
tika/server_test.go
Outdated
|
||
want := 1 | ||
got := len(s.javaprops) | ||
got := len(s.Javaprops) |
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.
Is there a way we can test that the arguments are correctly added to the java
command? Would hopefully catch the overwriting props
every time bug.
tika/server.go
Outdated
props = fmt.Sprintf("-D%s=%s ", i, s.javaprops[i]) | ||
if len(s.Javaprops) > 0 { | ||
for i := range s.Javaprops { | ||
props = fmt.Sprintf("-D%s=%s ", i, s.Javaprops[i]) |
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 overwrites props on every iteration. Perhaps something like this?
props := []string{}
for k, v := range s.JavaProps {
props = append(props, fmt.Sprintf("-D%s=%s", k, v))
}
propsArgs := strings.Join(props, " ")
(Also gets the key and value from the range
, rather than just the key.)
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.
Sorry for the slow review (just getting back from OOO). Thanks for working on this. :)
tika/server.go
Outdated
|
||
cmd := command("java", append([]string{props, "-jar", s.jar, "-p", s.port}, s.child.args()...)...) | ||
cmd := command("java", append([]string{propsArgs, "-jar", s.jar, "-p", s.port}, s.child.args()...)...) |
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 think all of the props should be passed as separate args? Probably need another append
:
cmd := command("java", append([]string{propsArgs, "-jar", s.jar, "-p", s.port}, s.child.args()...)...) | |
cmd := command("java", append(append(props, []string{propsArgs, "-jar", s.jar, "-p", s.port}, s.child.args()...)...)...) |
port: port, | ||
jar: jar, | ||
port: port, | ||
JavaProps: javaProps, |
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.
JavaProps: javaProps, | |
JavaProps: map[string]string{}, |
Thanks Tyler, I made all of the changes in my local repo and just need to update the comments and documentation. It probably goes without saying how crazy things are atm. Don |
… Start function to check for added props, wrote test.
…avaprops # Conflicts: # tika/server.go # tika/server_test.go
Sounds good -- totally understand. No rush. |
tika/server.go
Outdated
|
||
cmd := command("java", append([]string{propsArgs, "-jar", s.jar, "-p", s.port}, s.child.args()...)...) | ||
cmd := command("java", append([]string{strings.Join(props, " "), "-jar", s.jar, "-p", s.port}, s.child.args()...)...) |
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.
Sorry, I probably wasn't clear. I don't think we should have spaces in the argument. Each argument should be a different element of this args slice.
Something like this, but we could do it all in one line. A little odd to have an append
with different values on the right and left.
cmd := command("java", append([]string{strings.Join(props, " "), "-jar", s.jar, "-p", s.port}, s.child.args()...)...) | |
args := append(props, "-jar", s.jar, "-p", s.port) | |
args = append(args, s.child.args()... | |
cmd := command("java", args...) |
Merging and will send another PR for a few style changes. Thank you! |
Tyler, Thanks for all the help. this was the first PR I've done for a Go project. |
Thank you for the contribution! And welcome! 🎉 |
This pull requests