Details
-
Type:
New Feature
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6.3
-
Fix Version/s: JRuby 1.7.0.pre1
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
Currently, any changes to ENV in any runtime get reflected in the real ENV. This isn't always desirable, especially in the case of embedded runtimes. I propose a per runtime setting or System property to disable this.
I would be happy to implement this if the jruby team agrees that it would be useful.
My current approach to disable this is:
StringBuffer env_fix = new StringBuffer( "require 'java'" ); env_fix.append( "update_real_env_attr = org.jruby.RubyGlobal::StringOnlyRubyHash.java_class.declared_fields.find { |f| f.name == 'updateRealENV' }\n" ); env_fix.append( "update_real_env_attr.accessible = true\n" ); env_fix.append( "update_real_env_attr.set_value(ENV.to_java, false)\n" ); runtime.evalScriptlet( env_fix.toString() );
And god bless JRuby for making even that so flippin' easy.
Ah yes embedding. We followed MRI in how it handled setting envs, but that is not desirable in MVMs or in embedding in some cases. On the flip side of this coin, I think if jruby.native.enabled=true then it should do this by default. Otherwise native calls (e.g. Kernel.exec() won't see those new ENVs <--- only works native on windows as of 1.6.3).
A property (you cancadd it to RubyInstanceConfig) like jruby.native.env=true maybe? Then it could be disabled when you know you don't want it.
Although not part of this bug I have also wondered how granular we should make some features like native method support. It seems like we are missing a more systemic way of controlling some of these all-or-nothing features.