Skip to content

Commit 212ba5f

Browse files
committed
Remove processing of jruby.compat.version which is no longer needed for supported JRubies
This has been set to 2.1 for all supported JRubies for a long time, and the setting did nothing within JRuby. This cherry-pick avoids changing the API by bringing the class over from JRuby, allowing compatibility with JRuby 10. (cherry picked from commit abc7e0b) # Conflicts: # README.md # src/main/java/org/jruby/rack/DefaultRackConfig.java # src/main/java/org/jruby/rack/embed/Config.java # src/spec/ruby/jruby/rack/integration_spec.rb # src/spec/ruby/rack/application_spec.rb # src/spec/ruby/rack/config_spec.rb
1 parent 408870e commit 212ba5f

File tree

11 files changed

+76
-95
lines changed

11 files changed

+76
-95
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,6 @@ as context init parameters in web.xml or as VM-wide system properties.
209209
sub-path of the main servlet context root.
210210
- `gem.path`: Relative path to the bundled gem repository. Defaults to
211211
`/WEB-INF/gems`.
212-
- `jruby.compat.version`: Set to "1.8" or "1.9" to make JRuby run a specific
213-
version of Ruby (same as the --1.8 / --1.9 command line flags).
214212
- `jruby.min.runtimes`: For non-threadsafe Rails applications using a runtime
215213
pool, specify an integer minimum number of runtimes to hold in the pool.
216214
- `jruby.max.runtimes`: For non-threadsafe Rails applications, an integer
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.jruby;
2+
3+
/**
4+
* Removed from JRuby Core as of 10.0; but deprecated and unused for a long time.
5+
* <p/>
6+
* Added back to jruby-rack 1.2.x to allow JRuby 10 support without an API changed, but
7+
* will be removed in jruby-rack 1.3.0
8+
* <p/>
9+
* @link https://github.com/jruby/jruby/blob/jruby-9.3/core/src/main/java/org/jruby/CompatVersion.java
10+
* @deprecated since JRuby 9.2 with no replacement; for removal with jruby-rack 1.3.0
11+
*/
12+
@Deprecated
13+
public enum CompatVersion {
14+
15+
@Deprecated RUBY1_8,
16+
@Deprecated RUBY1_9,
17+
@Deprecated RUBY2_0,
18+
@Deprecated RUBY2_1,
19+
@Deprecated BOTH;
20+
21+
@Deprecated
22+
public boolean is1_9() {
23+
return this == RUBY1_9 || this == RUBY2_0 || this == RUBY2_1;
24+
}
25+
26+
@Deprecated
27+
public boolean is2_0() {
28+
return this == RUBY2_0 || this == RUBY2_1;
29+
}
30+
31+
@Deprecated
32+
public static CompatVersion getVersionFromString(String compatString) {
33+
if (compatString.equalsIgnoreCase("RUBY1_8")) {
34+
return CompatVersion.RUBY1_8;
35+
} else if (compatString.equalsIgnoreCase("1.8")) {
36+
return CompatVersion.RUBY1_8;
37+
} else if (compatString.equalsIgnoreCase("RUBY1_9")) {
38+
return CompatVersion.RUBY1_9;
39+
} else if (compatString.equalsIgnoreCase("1.9")) {
40+
return CompatVersion.RUBY1_9;
41+
} else if (compatString.equalsIgnoreCase("RUBY2_0")) {
42+
return CompatVersion.RUBY2_0;
43+
} else if (compatString.equalsIgnoreCase("2.0")) {
44+
return CompatVersion.RUBY2_0;
45+
} else if (compatString.equalsIgnoreCase("RUBY2_1")) {
46+
return CompatVersion.RUBY2_1;
47+
} else if (compatString.equalsIgnoreCase("2.1")) {
48+
return CompatVersion.RUBY2_1;
49+
} else {
50+
return null;
51+
}
52+
}
53+
54+
@Deprecated
55+
public static boolean shouldBindMethod(CompatVersion runtimeVersion, CompatVersion methodVersion) {
56+
if (runtimeVersion == RUBY1_8) return methodVersion == RUBY1_8 || methodVersion == BOTH;
57+
if (runtimeVersion == RUBY1_9) return methodVersion == RUBY1_9 || methodVersion == BOTH;
58+
if (runtimeVersion == RUBY2_0) return methodVersion == RUBY1_9 || methodVersion == RUBY2_0 || methodVersion == BOTH;
59+
if (runtimeVersion == RUBY2_1) return methodVersion == RUBY1_9 || methodVersion == RUBY2_0 || methodVersion == RUBY2_1 || methodVersion == BOTH;
60+
return false;
61+
}
62+
}

src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,6 @@ protected RubyInstanceConfig initRuntimeConfig(final RubyInstanceConfig config)
302302
// Process arguments, namely any that might be in RUBYOPT
303303
config.processArguments(rackConfig.getRuntimeArguments());
304304

305-
if ( rackConfig.getCompatVersion() != null ) {
306-
config.setCompatVersion(rackConfig.getCompatVersion());
307-
}
308-
309305
try { // try to set jruby home to jar file path
310306
final URL resource = Ruby.class.getResource("/META-INF/jruby.home");
311307
if ( resource != null && "jar".equals( resource.getProtocol() ) ) {

src/main/java/org/jruby/rack/DefaultRackConfig.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import java.util.HashMap;
1818
import java.util.LinkedHashMap;
1919
import java.util.Map;
20-
import java.util.regex.Matcher;
21-
import java.util.regex.Pattern;
2220

2321
import org.jruby.CompatVersion;
2422
import org.jruby.rack.logging.OutputStreamLogger;
@@ -81,23 +79,6 @@ public void setQuiet(boolean quiet) {
8179

8280
@Override
8381
public CompatVersion getCompatVersion() {
84-
final String version = getProperty("jruby.compat.version");
85-
if ( version != null ) {
86-
// we handle 1.8, RUBY1_9, --2.0 1_9 2.1.0.dev etc :
87-
final Pattern pattern = Pattern.compile("([123])[._]([8901234567])");
88-
final Matcher matcher = pattern.matcher(version);
89-
if ( matcher.find() ) {
90-
final String name = "RUBY" +
91-
matcher.group(1) + '_' + matcher.group(2);
92-
try {
93-
return Enum.valueOf(CompatVersion.class, name);
94-
}
95-
catch (IllegalArgumentException e) {
96-
getLogger().log(WARN,
97-
"could not resolve compat version from '"+ version +"' will use default", e);
98-
}
99-
}
100-
}
10182
return null;
10283
}
10384

src/main/java/org/jruby/rack/RackConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public interface RackConfig {
3636
/**
3737
* Return the Ruby version that JRuby should run.
3838
* @return <code>RUBY_VERSION</code> (e.g. 1.8, 1.9)
39+
*
40+
* @deprecated Since jruby-rack 1.2 (and JRuby 9.2), for removal in 1.3.0
3941
*/
42+
@Deprecated
4043
CompatVersion getCompatVersion();
4144

4245
/**

src/main/java/org/jruby/rack/embed/Config.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public class Config implements RackConfig {
4444

4545
private RackLogger logger;
4646
private Map<String, String> rubyENV;
47-
private CompatVersion compatVersion;
4847

4948
public Config() {
5049
delegate = new DefaultRackConfig() {
@@ -66,7 +65,6 @@ public void doInitialize(final Ruby runtime) {
6665
setOut( runtime.getOut() );
6766
setErr( runtime.getErr() );
6867
rubyENV = runtime.getENV();
69-
compatVersion = runtime.getInstanceConfig().getCompatVersion();
7068
}
7169

7270

@@ -106,9 +104,15 @@ public final Number getNumberProperty(String key, Number defaultValue) {
106104
return delegate.getNumberProperty(key, defaultValue);
107105
}
108106

107+
/**
108+
* @return Always CompatVersion.RUBY2_1, consistent with JRuby 9.3+
109+
*
110+
* @deprecated Since jruby-rack 1.2 (and JRuby 9.2), for removal in 1.3.0
111+
*/
112+
@Deprecated
109113
@Override
110114
public CompatVersion getCompatVersion() {
111-
return compatVersion;
115+
return CompatVersion.RUBY2_1;
112116
}
113117

114118
@Override

src/spec/ruby/jruby/rack/error_app_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def in_tmpdir_with_files(files = {})
165165
end
166166
yield path
167167
ensure
168-
FileUtils.rm_rf(path) if path && File.exists?(path)
168+
FileUtils.rm_rf(path) if path && File.exist?(path)
169169
end
170170

171171
end

src/spec/ruby/jruby/rack/integration_spec.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
before do
2020
@servlet_context = org.jruby.rack.mock.RackLoggingMockServletContext.new "file://#{STUB_DIR}/rack"
2121
@servlet_context.logger = raise_logger
22-
# make sure we always boot runtimes in the same mode as specs :
23-
set_compat_version @servlet_context
2422
end
2523

2624
it "initializes" do
@@ -260,16 +258,10 @@ def new_servlet_context(base_path = nil)
260258
end
261259

262260
def prepare_servlet_context(servlet_context, base_path)
263-
set_compat_version servlet_context
264261
servlet_context.addInitParameter('rails.root', base_path)
265262
servlet_context.addInitParameter('jruby.rack.layout_class', 'FileSystemLayout')
266263
end
267264

268-
def set_compat_version(servlet_context = @servlet_context); require 'jruby'
269-
compat_version = JRuby.runtime.getInstanceConfig.getCompatVersion # RUBY1_9
270-
servlet_context.addInitParameter("jruby.compat.version", compat_version.to_s)
271-
end
272-
273265
GEMFILES_DIR = File.expand_path('../../../gemfiles', STUB_DIR)
274266

275267
def copy_gemfile

src/spec/ruby/rack/application_spec.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,6 @@ def newRuntime()
393393
should_eval_as_eql_to "require 'yaml'", true # -ryaml not processed
394394
end
395395

396-
it "handles jruby.compat.version == '1.9' and starts in 1.9 mode" do
397-
set_config 'jruby.compat.version', '1.9'
398-
#@rack_config.stub(:getCompatVersion).and_return org.jruby.CompatVersion::RUBY1_9
399-
@runtime = app_factory.new_runtime
400-
expect(@runtime.is1_9).to be_truthy
401-
end
402-
403396
it "handles jruby.runtime.arguments == '-X+O -Ke' and start with object space enabled and KCode EUC" do
404397
set_config 'jruby.runtime.arguments', '-X+O -Ke'
405398
# allow(@rack_config).to receive(:getRuntimeArguments).and_return ['-X+O', '-Ke'].to_java(:String)

src/spec/ruby/rack/config_spec.rb

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -184,56 +184,10 @@ def expect_empty_env(env)
184184

185185
end
186186

187-
it "sets compat version from init parameter" do
188-
expect(@servlet_context).to receive(:getInitParameter).with("jruby.compat.version").
189-
and_return "RUBY1_9"
190-
expect( config.getCompatVersion ).to be org.jruby.CompatVersion::RUBY1_9
191-
end
192-
193-
it "sets compat version from init parameter (dot syntax)" do
194-
expect(@servlet_context).to receive(:getInitParameter).with("jruby.compat.version").
195-
and_return "1.8"
196-
expect( config.getCompatVersion ).to be org.jruby.CompatVersion::RUBY1_8
197-
end
198-
199-
it "leaves compat version nil if not specified" do
200-
expect(@servlet_context).to receive(:getInitParameter).with("jruby.compat.version").
201-
and_return nil
187+
it "always returns nil compat version (backwards compat)" do
202188
expect( config.getCompatVersion ).to be nil
203189
end
204190

205-
it "leaves compat version nil if invalid value specified" do
206-
expect(@servlet_context).to receive(:getInitParameter).with("jruby.compat.version").
207-
and_return "4.2"
208-
expect( config.getCompatVersion ).to be nil
209-
end
210-
211-
it "sets compat version from init parameter (head-syntax)" do
212-
expect(@servlet_context).to receive(:getInitParameter).with("jruby.compat.version").
213-
and_return "1.9.3-SNAPSHOT"
214-
expect( config.getCompatVersion ).to be org.jruby.CompatVersion::RUBY1_9
215-
end
216-
217-
if JRUBY_VERSION >= '1.7.0'
218-
it "sets compat version 2.0 from init parameter" do
219-
expect(@servlet_context).to receive(:getInitParameter).with("jruby.compat.version").
220-
and_return "RUBY2_0"
221-
expect( config.getCompatVersion ).to be org.jruby.CompatVersion::RUBY2_0
222-
end
223-
224-
it "sets compat version 2.0 from init parameter (dot syntax)" do
225-
expect(@servlet_context).to receive(:getInitParameter).with("jruby.compat.version").
226-
and_return "2_0"
227-
expect( config.getCompatVersion ).to be org.jruby.CompatVersion::RUBY2_0
228-
end
229-
230-
it "sets compat version 2.0 from init parameter (head-syntax)" do
231-
expect(@servlet_context).to receive(:getInitParameter).with("jruby.compat.version").
232-
and_return "2.0.0.dev"
233-
expect( config.getCompatVersion ).to be org.jruby.CompatVersion::RUBY2_0
234-
end
235-
end
236-
237191
describe "custom-properties" do
238192

239193
it "parser an int property" do

0 commit comments

Comments
 (0)