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

Added URI::Generic#to_java to convert to java.net.URI #4698

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jkutner
Copy link
Member

@jkutner jkutner commented Jun 29, 2017

This cleans up direct use of java.net.URI usage in Ruby code. For example, when working with a Java http_client like this:

uri = java.net.URI.new(rest_url(item))
http_client = ctx.get(HttpClient.java_class)
http_client.get(uri)

We can now use a Ruby URI like this:

uri = URI(rest_url(item))
http_client = ctx.get(HttpClient.java_class)
http_client.get(uri.to_java)

Using a Ruby URI allows for better reuse of the object throughout the code.

If there is a way to make the uri.to_java call implicit, I'll be happy to work on that too.

Unverified

This user has not yet uploaded their public signing key.
@kares
Copy link
Member

kares commented Jun 29, 2017

👍 patch however it has at least 1 problematic part :
spec/ruby is shared among Ruby impls so it should be moved elsewhere (e.g. spec/java_integration)

the other would be that stdlib files now contain JRuby specific ext - which is kind of a first but than since its an ext of a .rb library there's no other easy way to not pollute stdlib with java ext pieces (which usually live elsewhere)

@jkutner
Copy link
Member Author

jkutner commented Jun 29, 2017

@kares i don't like mucking with the stdlib this way either. Maybe the java.rb can become a "pattern" so that it's not a one-off case. Otherwise, maybe there we could add special case logic to the base implementation of to_java (which I think is in KernelJavaAddons.java) to check for a URI object.

But if everyone is ok with the java.rb I'll move the test to spec/java_integration.

@enebo
Copy link
Member

enebo commented Jun 30, 2017

we need a mechanism for adding our own definitions to the stdlib without adding them to the stdlib file itself. Unfortunately I almost feel like this would be an exercise in AOP. I can think our overrides being further up load path which would then somehow require the stdlib file. This would allow cutpoint defs before or defs after the real stdlib file is required. Without a special require in our required file we could maybe use require_relative? Bleh.

If we had a generic mechanism for this then it would be really easy to patch stdlib in cases where that code makes no sense going upstream to MRI.

@kares
Copy link
Member

kares commented Nov 10, 2017

marked as PENDING since we vaguely agreed the idea is good but the impl will cause headaches ...

@headius
Copy link
Member

headius commented Nov 22, 2017

We're going to need to cross the bridge of stdlib-sharing sooner or later, now that 2.5 is gemifying everything. People will start depending on newer versions of stdlib gems and pulling whatever's released, so they'll lose JRuby-specific bits unless we come up with an answer.

The typical way to do this, I think, is to put the impl-specific bits in separate gems, so that readline would depend on readline-mri when installing on mri and readline-jruby when installing on JRuby. But this is a complex issue, since it means readline itself would need a -java release for different dependencies on JRuby.

The other option would be for the readline gem to contain both what JRuby needs and what MRI needs. That will work for some libraries that are pure Ruby, but for libraries with exts we'll still need two separate gems.

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

Successfully merging this pull request may close these issues.

None yet

4 participants