Skip to content
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

Merged
merged 8 commits into from
Mar 25, 2020

Conversation

dmnyu
Copy link
Contributor

@dmnyu dmnyu commented Feb 26, 2020

This pull requests

  • Adds a javaprops map to Server
  • Adds a AddJavaProp function to add key-value pairs to a Servers javaprops map
  • Modifies the Start() function to check if the javaprops map is not empty, if so it formats key value pairs into system property setters to the java command.
  • Adds a test to check that kv pairs are being added to javaprops map

… Start function to check for added props, wrote test.
tika/server.go Outdated
port string
cmd *exec.Cmd
child *ChildOptions
javaprops map[string]string
Copy link
Member

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.

Suggested change
javaprops map[string]string
JavaProps map[string]string

@dmnyu
Copy link
Contributor Author

dmnyu commented Feb 26, 2020

That makes a lot of sense. I'll make the changes.

Copy link
Member

@tbpg tbpg left a 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
Copy link
Member

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)
Copy link
Member

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 {
Copy link
Member

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.


want := 1
got := len(s.javaprops)
got := len(s.Javaprops)
Copy link
Member

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])
Copy link
Member

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.)

Copy link
Member

@tbpg tbpg left a 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()...)...)
Copy link
Member

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:

Suggested change
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
JavaProps: javaProps,
JavaProps: map[string]string{},

@dmnyu
Copy link
Contributor Author

dmnyu commented Mar 23, 2020

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

dmnyu added 2 commits March 23, 2020 13:47
… Start function to check for added props, wrote test.
…avaprops

# Conflicts:
#	tika/server.go
#	tika/server_test.go
@tbpg
Copy link
Member

tbpg commented Mar 23, 2020

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()...)...)
Copy link
Member

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.

Suggested change
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...)

@tbpg
Copy link
Member

tbpg commented Mar 25, 2020

Merging and will send another PR for a few style changes.

Thank you!

@tbpg tbpg merged commit 41cad59 into google:master Mar 25, 2020
@dmnyu
Copy link
Contributor Author

dmnyu commented Mar 26, 2020

Tyler, Thanks for all the help. this was the first PR I've done for a Go project.

@tbpg
Copy link
Member

tbpg commented Mar 26, 2020

Thank you for the contribution! And welcome! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants