Skip to content

Commit 27cbe14

Browse files
committed
[fix] Remove useless processing of jruby.compat.version for JRuby 10 compatibility
This has been set to 2.1 for all supported JRubies for a long time, and the setting did nothing within JRuby. This change reduces usages, and introduce a stub to allow testing with JRuby 10; where rspec and others logic will still try and locate the class.
1 parent 1ac9a9c commit 27cbe14

14 files changed

Lines changed: 57 additions & 105 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 1.2.7 (UNRELEASED)
22

3+
- Fix compatibility with JRuby 10.0 and Rails 8.0 (#419)
34
- Fix ability to include and forward to JSPs under Rails (#370)
45
- Update (bundled) rack to 2.2.23 (#417)
56

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ For more information on Rack, visit http://rack.github.io/.
1313

1414
## Compatibility
1515

16-
| JRuby-Rack Series | Status | Rack | JRuby | Java | Rails | Target Servlet API | Notes |
17-
|----------------------------------------------------------------|---------------|-----------|-----------|------|-----------|--------------------|----------------------------------------------------------------|
18-
| [**1.2**](https://github.com/jruby/jruby-rack/tree/1.2-stable) | Maintained | 2.2 | 9.3 → 9.4 | 8+ | 5.0 → 7.2 | 3.0 (Java EE 6) |_Unofficial_: Servlet 3.1 → 4.0 also OK with most containers |
19-
| [**1.1**](https://github.com/jruby/jruby-rack/tree/1.1-stable) | EOL @ 2024-05 | 1.x → 2.2 | 1.6 → 9.4 | 6+ | 2.1 → 5.2 | 2.5 (Java EE 5) |_Unofficial_: Servlet 3.0 → 4.0 also OK with most containers |
20-
| [**1.0**](https://github.com/jruby/jruby-rack/tree/1.0.10) | EOL @ 2011-11 | 0.9 → 1.x | 1.1 → 1.9 | 5+ | 2.1 → 3.x | 2.5 (Java EE 5) | |
16+
| JRuby-Rack Series | Status | Rack | JRuby | Java | Rails | Target Servlet API | Notes |
17+
|----------------------------------------------------------------|---------------|-----------|------------|------|-----------|--------------------|----------------------------------------------------------------|
18+
| [**1.2**](https://github.com/jruby/jruby-rack/tree/1.2-stable) | Maintained | 2.2 | 9.3 → 10.0 | 8+ | 5.0 → 8.0 | 3.0 (Java EE 6) |_Unofficial_: Servlet 3.1 → 4.0 also OK with most containers |
19+
| [**1.1**](https://github.com/jruby/jruby-rack/tree/1.1-stable) | EOL @ 2024-05 | 1.x → 2.2 | 1.6 → 9.4 | 6+ | 2.1 → 5.2 | 2.5 (Java EE 5) |_Unofficial_: Servlet 3.0 → 4.0 also OK with most containers |
20+
| [**1.0**](https://github.com/jruby/jruby-rack/tree/1.0.10) | EOL @ 2011-11 | 0.9 → 1.x | 1.1 → 1.9 | 5+ | 2.1 → 3.x | 2.5 (Java EE 5) | |
2121

2222
## Getting Started
2323

@@ -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

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 & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@
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;
2523
import org.jruby.rack.logging.StandardOutLogger;
2624
import org.jruby.util.SafePropertyAccessor;
2725

28-
import static org.jruby.rack.RackLogger.Level.WARN;
29-
3026
/**
3127
* A base implementation of that retrieves settings from system properties.
3228
*
@@ -81,23 +77,6 @@ public void setQuiet(boolean quiet) {
8177

8278
@Override
8379
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-
}
10180
return null;
10281
}
10382

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/main/ruby/jruby/rack/core_ext.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Exception
1515
include JRuby::Rack::Capture::Environment if $DEBUG
1616
include JRuby::Rack::Capture::RubyGems
1717
include JRuby::Rack::Capture::Bundler
18-
include JRuby::Rack::Capture::JRubyRackConfig
18+
include JRuby::Rack::Capture::JRubyRackConfig if JRUBY_VERSION.start_with?("9.") # Workaround for JRuby 10 with missing CompatVerison class
1919
include JRuby::Rack::Capture::JavaEnvironment if $DEBUG
2020
end
2121

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.jruby;
2+
3+
/**
4+
* This was removed from JRuby Core as of 10.0; but deprecated and unused for a long time.
5+
* <p/>
6+
* While this is not actually used at runtime unless people specifically invoke the methods on Rack Config, various
7+
* tests mock RackConfig which causes tests to try and load the class. So we add back/override a minimal version here
8+
* to allow the tests to work on JRuby 10, and be able to add JRuby 10 and Rails 8.0 support to the 1.2.x line.
9+
* <p/>>
10+
* @link <a href="https://github.com/jruby/jruby/blob/jruby-9.4/core/src/main/java/org/jruby/CompatVersion.java">...</a>
11+
* @deprecated since JRuby 9.2 with no replacement; for removal with jruby-rack 1.3.0
12+
*/
13+
public enum CompatVersion {
14+
RUBY1_8, // used in specs
15+
RUBY2_1, // used as default by jruby-rack
16+
BOTH // used as the default by JRuby 9.3/9.4 at runtime
17+
}

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

0 commit comments

Comments
 (0)