Skip to content

Introduce basic compatibility with JRuby 10 #273

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: monthly
groups:
actions-deps:
patterns: [ "*" ]
- package-ecosystem: maven
directory: "/"
schedule:
interval: monthly
groups:
maven-deps:
dependency-type: "production"
maven-dev-deps:
dependency-type: "development"
- package-ecosystem: bundler
directories:
- "/"
schedule:
interval: monthly
allow:
- dependency-type: all
groups:
ruby-deps:
patterns: [ "*" ]
30 changes: 22 additions & 8 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ jobs:

strategy:
matrix:
jruby_version: [ '9.3.15.0', '9.4.12.0' ]
jruby_version: [ '9.3.15.0', '9.4.12.0', '10.0.0.0' ]
java_version: [ '8', '11', '17', '21' ]
exclude:
- jruby_version: '10.0.0.0'
java_version: '8' # JRuby 10 requires Java 21
- jruby_version: '10.0.0.0'
java_version: '11' # JRuby 10 requires Java 21
- jruby_version: '10.0.0.0'
java_version: '17' # JRuby 10 requires Java 21
fail-fast: false

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Set up JDK
uses: actions/setup-java@v4
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
with:
java-version: ${{ matrix.java_version }}
distribution: 'temurin'
Expand All @@ -32,7 +39,7 @@ jobs:

# Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
- name: Update dependency graph
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
uses: advanced-security/maven-dependency-submission-action@aeab9f885293af501bae8bdfe88c589528ea5e25 # v4.1.2
if: github.head_ref == 'refs/heads/master' && matrix.java_version == '8' && startsWith(matrix.jruby_version, '9.4')

appraisals:
Expand All @@ -42,7 +49,7 @@ jobs:

strategy:
matrix:
jruby_version: [ '9.3.15.0', '9.4.12.0' ]
jruby_version: [ '9.3.15.0', '9.4.12.0', '10.0.0.0' ]
java_version: [ '8', '11', '17', '21' ]
appraisal: [ 'rails50', 'rails52', 'rails60', 'rails61', 'rails70', 'rails71', 'rails72' ]
exclude:
Expand Down Expand Up @@ -82,26 +89,33 @@ jobs:
- jruby_version: '9.3.15.0'
java_version: '21'
appraisal: 'rails72' # Requires Ruby 3.1 compatibility, which JRuby 9.3 does not support
- jruby_version: '10.0.0.0'
java_version: '8' # JRuby 10 requires Java 21
- jruby_version: '10.0.0.0'
java_version: '11' # JRuby 10 requires Java 21
- jruby_version: '10.0.0.0'
java_version: '17' # JRuby 10 requires Java 21
fail-fast: false

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Set up JDK
uses: actions/setup-java@v4
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
with:
java-version: ${{ matrix.java_version }}
distribution: 'temurin'
cache: maven

- name: Setup JRuby
uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@ca041f971d66735f3e5ff1e21cc13e2d51e7e535 # v1.233.0
with:
ruby-version: jruby-${{ matrix.jruby_version }}
bundler: 2.3.27 # use version that is OK for JRuby 9.3

- name: Run appraisal for ${{ matrix.appraisal }}
env:
BUNDLE_GEMFILE: gemfiles/${{ matrix.appraisal }}.gemfile
JRUBY_VERSION: ${{ matrix.jruby_version }}
run: bundle install && bundle exec rake spec

2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GEM
bundler
rake
thor (>= 0.14.0)
diff-lcs (1.6.0)
diff-lcs (1.6.1)
rack (2.2.13)
rake (13.2.1)
rspec (3.13.0)
Expand Down
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 1.2.3

- Adds basic compatibility with JRuby 10.0
- update (bundled) rack to 2.2.13
- Corrects Rack 2.x compatibility when used with modern Rails, and requires Rack 2.x going forward
- forward ports all 1.1.x fixes to the 1.2.x stream which were omitted in 1.2.2 release (#262)
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ as context init parameters in web.xml or as VM-wide system properties.
sub-path of the main servlet context root.
- `gem.path`: Relative path to the bundled gem repository. Defaults to
*/WEB-INF/gems*.
- `jruby.compat.version`: Set to "1.8" or "1.9" to make JRuby run a specific
version of Ruby (same as the --1.8 / --1.9 command line flags).
- `jruby.min.runtimes`: For non-threadsafe Rails applications using a runtime
pool, specify an integer minimum number of runtimes to hold in the pool.
- `jruby.max.runtimes`: For non-threadsafe Rails applications, an integer
Expand Down
11 changes: 4 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,15 @@ end
directory 'target/classes'

desc "Compile classes"
task(:compile => 'target/classes') { sh 'mvn compile -Dmdep.skip=true' }
task(:compile => 'target/classes') do
sh "mvn compile #{ENV['JRUBY_VERSION'] ? "-Djruby.version=#{ENV['JRUBY_VERSION']}" : ""}"
end

directory 'target/test-classes'

desc "Compile test classes"
task(:test_compile => 'target/test-classes') { sh 'mvn test-compile -Dmdep.skip=true' }

desc "Copy .jar dependencies for (local) testing"
task(:test_jars) { sh 'mvn test-compile' }

task(:test_prepare => ['target/classes', 'target/test-classes']) do
sh 'mvn test-compile'
sh "mvn test-compile #{ENV['JRUBY_VERSION'] ? "-Djruby.version=#{ENV['JRUBY_VERSION']}" : ""}"
end

desc "Unpack the rack gem"
Expand Down
2 changes: 1 addition & 1 deletion examples/rails3/config/boot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</description>

<properties>
<jruby.version>9.4.12.0</jruby.version>
<jruby.version>10.0.0.0</jruby.version>
<jruby.maven.plugins.version>3.0.5</jruby.maven.plugins.version>
<gem.home>${project.build.directory}/rubygems</gem.home>
<slf4j.version>2.0.17</slf4j.version>
Expand Down Expand Up @@ -219,7 +219,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.2</version>
<version>3.5.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,6 @@ protected RubyInstanceConfig initRuntimeConfig(final RubyInstanceConfig config)
// Process arguments, namely any that might be in RUBYOPT
config.processArguments(rackConfig.getRuntimeArguments());

if ( rackConfig.getCompatVersion() != null ) {
config.setCompatVersion(rackConfig.getCompatVersion());
}

try { // try to set jruby home to jar file path
final URL resource = Ruby.class.getResource("/META-INF/jruby.home");
if ( resource != null && "jar".equals( resource.getProtocol() ) ) {
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/org/jruby/rack/DefaultRackConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jruby.CompatVersion;
import org.jruby.rack.logging.OutputStreamLogger;
import org.jruby.rack.logging.StandardOutLogger;
import org.jruby.util.SafePropertyAccessor;
import static org.jruby.rack.RackLogger.Level.*;

/**
* A base implementation of that retrieves settings from system properties.
Expand Down Expand Up @@ -77,28 +73,6 @@ public void setQuiet(boolean quiet) {
this.quiet = quiet;
}

@Override
public CompatVersion getCompatVersion() {
final String version = getProperty("jruby.compat.version");
if ( version != null ) {
// we handle 1.8, RUBY1_9, --2.0 1_9 2.1.0.dev etc :
final Pattern pattern = Pattern.compile("([123])[._]([8901234567])");
final Matcher matcher = pattern.matcher(version);
if ( matcher.find() ) {
final String name = "RUBY" +
matcher.group(1) + '_' + matcher.group(2);
try {
return Enum.valueOf(CompatVersion.class, name);
}
catch (IllegalArgumentException e) {
getLogger().log(WARN,
"could not resolve compat version from '"+ version +"' will use default", e);
}
}
}
return null;
}

@Override
public String getRackup() {
return getProperty("rackup");
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/org/jruby/rack/RackConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

package org.jruby.rack;

import org.jruby.CompatVersion;

import java.io.PrintStream;
import java.util.Map;

Expand All @@ -32,12 +30,6 @@ public interface RackConfig {
* @return <code>STDERR</code>
*/
PrintStream getErr();

/**
* Return the Ruby version that JRuby should run.
* @return <code>RUBY_VERSION</code> (e.g. 1.8, 1.9)
*/
CompatVersion getCompatVersion();

/**
* Return the rackup Ruby script to be used to launch the application.
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/org/jruby/rack/embed/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.io.PrintStream;
import java.util.Map;

import org.jruby.CompatVersion;
import org.jruby.Ruby;
import org.jruby.rack.DefaultRackConfig;
import org.jruby.rack.RackConfig;
Expand All @@ -44,7 +43,6 @@ public class Config implements RackConfig {

private RackLogger logger;
private Map<String, String> rubyENV;
private CompatVersion compatVersion;

public Config() {
delegate = new DefaultRackConfig() {
Expand All @@ -61,31 +59,11 @@ public String getProperty(String key, String defaultValue) {
};
}

/*
Config(final RackConfig config) {
delegate = new DefaultRackConfig() {

@Override
public String getProperty(String key, String defaultValue) {
String value = config.getProperty(key, null);
if ( value != null ) return value;

value = Config.this.resolveProperty(key);
return value != null ? value : super.getProperty(key, defaultValue);
}

@Override
public RackLogger defaultLogger() { return null; }

};
} */

@SuppressWarnings("unchecked")
public void doInitialize(final Ruby runtime) {
setOut( runtime.getOut() );
setErr( runtime.getErr() );
rubyENV = runtime.getENV();
compatVersion = runtime.getInstanceConfig().getCompatVersion();
}


Expand Down Expand Up @@ -119,10 +97,6 @@ public final Number getNumberProperty(String key, Number defaultValue) {
return delegate.getNumberProperty(key, defaultValue);
}

public CompatVersion getCompatVersion() {
return compatVersion;
}

public RackLogger getLogger() {
if (logger == null) {
logger = delegate.getLogger();
Expand Down
2 changes: 1 addition & 1 deletion src/main/ruby/jruby/rack/rails/extensions2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module Rescue
def render_optional_error_file(status_code) #:nodoc:
status = interpret_status(status_code)
path = "#{PUBLIC_ROOT}/#{status[0,3]}.html"
if File.exists?(path)
if File.exist?(path)
render :file => path, :status => status
else
head status
Expand Down
2 changes: 1 addition & 1 deletion src/spec/ruby/jruby/rack/error_app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def in_tmpdir_with_files(files = {})
end
yield path
ensure
FileUtils.rm_rf(path) if path && File.exists?(path)
FileUtils.rm_rf(path) if path && File.exist?(path)
end

end
Expand Down
20 changes: 0 additions & 20 deletions src/spec/ruby/jruby/rack/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@

before(:all) { require 'fileutils' }

#after(:all) { JRuby::Rack.context = nil }

describe 'rack (lambda)' do

before do
@servlet_context = org.jruby.rack.mock.RackLoggingMockServletContext.new "file://#{STUB_DIR}/rack"
@servlet_context.logger = raise_logger
# make sure we always boot runtimes in the same mode as specs :
set_compat_version @servlet_context
end

it "initializes" do
Expand Down Expand Up @@ -136,7 +132,6 @@ def base_path; "file://#{STUB_DIR}/rails30" end
before :all do
initialize_rails nil, base_path
end
after(:all) { restore_rails }

it "loaded rack ~> 1.2" do
@runtime = @rack_factory.getApplication.getRuntime
Expand Down Expand Up @@ -435,27 +430,12 @@ def initialize_rails(env = nil, servlet_context = @servlet_context)
@servlet_context ||= servlet_context
end

def restore_rails
#ENV['RACK_ENV'] = ENV_COPY['RACK_ENV'] if ENV.key?('RACK_ENV')
#ENV['RAILS_ENV'] = ENV_COPY['RAILS_ENV'] if ENV.key?('RAILS_ENV')
end

def new_servlet_context(base_path = nil)
servlet_context = org.jruby.rack.mock.RackLoggingMockServletContext.new base_path
servlet_context.logger = raise_logger
prepare_servlet_context servlet_context
servlet_context
end

def prepare_servlet_context(servlet_context)
set_compat_version servlet_context
end

def set_compat_version(servlet_context = @servlet_context); require 'jruby'
compat_version = JRuby.runtime.getInstanceConfig.getCompatVersion # RUBY1_9
servlet_context.addInitParameter("jruby.compat.version", compat_version.to_s)
end

private

GEMFILES_DIR = File.expand_path('../../../gemfiles', STUB_DIR)
Expand Down
Loading