Skip to content

Commit ae13d90

Browse files
authored
Merge pull request #418 from chadlwilson/minor-tidies
[chore] impove build/test reliabiliy across jruby versions
2 parents df94627 + f5c74c2 commit ae13d90

8 files changed

Lines changed: 76 additions & 31 deletions

File tree

.github/workflows/maven.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
env:
1010
# Default versions for canonical release build
1111
DEFAULT_JAVA_VERSION: '8'
12-
DEFAULT_JRUBY_VERSION: '9.4.14.0' # Should match pom.xml <jruby.version> property (AND a version inside the test matrix)
12+
DEFAULT_JRUBY_VERSION: '9.4.14.0' # Should match pom.xml <jruby.compat.version> property (AND a version inside the test matrix)
1313
DEFAULT_RACK_VERSION: '~> 2.2.0' # Should match Gemfile (AND a version inside the test matrix)
1414

1515
jobs:
@@ -42,7 +42,7 @@ jobs:
4242
cache: maven
4343

4444
- name: Build with Maven
45-
run: ./mvnw -B install -Djruby.version=${{ matrix.jruby_version }}
45+
run: ./mvnw -ntp install -Dstyle.color=always -Djruby.test.version=${{ matrix.jruby_version }}
4646
env:
4747
RACK_VERSION: ${{ matrix.rack_version }}
4848

@@ -79,7 +79,6 @@ jobs:
7979

8080
env:
8181
BUNDLE_GEMFILE: gemfiles/${{ matrix.appraisal }}.gemfile
82-
JRUBY_VERSION: ${{ matrix.jruby_version }}
8382

8483
steps:
8584
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

Rakefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ directory 'target/classes'
3838

3939
desc "Compile classes"
4040
task(:compile => 'target/classes') do
41-
sh "./mvnw compile #{ENV['JRUBY_VERSION'] ? "-Djruby.version=#{ENV['JRUBY_VERSION']}" : ""}"
41+
sh "./mvnw -ntp -Dstyle.color=always compile"
4242
end
4343

4444
directory 'target/test-classes'
4545

4646
desc "Compile test classes"
4747
task(:test_prepare => ['target/classes', 'target/test-classes']) do
48-
sh "./mvnw test-compile #{ENV['JRUBY_VERSION'] ? "-Djruby.version=#{ENV['JRUBY_VERSION']}" : ""}"
48+
sh "./mvnw -ntp -Dstyle.color=always test-compile"
4949
end
5050

5151
desc "Unpack the rack gem"
@@ -88,7 +88,7 @@ task :test_resources => ["target/test-classes"]
8888
namespace :resources do
8989
desc "Copy (and generate) resources"
9090
task :copy => :resources do
91-
sh './mvnw process-resources -Dmdep.skip=true'
91+
sh './mvnw -ntp process-resources -Dstyle.color=always -Dmdep.skip=true'
9292
end
9393
desc "Generate test resources"
9494
task :test => :test_resources
@@ -198,8 +198,7 @@ task :release_checks do
198198
" git push origin :#{GEM_VERSION}" if ok
199199
end
200200

201-
pom_version = `./mvnw help:evaluate -Dexpression=project.version`.
202-
split("\n").reject { |line| line =~ /[INFO]/ }.first.chomp
201+
pom_version = `./mvnw help:evaluate -q --non-recursive -DforceStdout -Dexpression=project.version`
203202
if pom_version =~ /dev|SNAPSHOT/
204203
fail "Can't release a dev/snapshot version.\n" +
205204
"Please update pom.xml to the final release version, run `mvn install', and commit the result."
@@ -219,7 +218,7 @@ task :release => [:release_checks, :clean] do
219218
args = ''
220219
args << "-Dgpg.keyname=#{ENV['GPG_KEYNAME']} " if ENV['GPG_KEYNAME']
221220

222-
sh "./mvnw -Prelease #{args} -DupdateReleaseInfo=true clean deploy"
221+
sh "./mvnw -ntp -Prelease #{args} -Dstyle.color=always -DupdateReleaseInfo=true clean deploy"
223222

224223
sh "git tag #{GEM_VERSION}"
225224

pom.xml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
<properties>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323

24-
<jruby.version>9.4.14.0</jruby.version>
24+
<!-- Version to target at compile time -->
25+
<jruby.compat.version>9.4.14.0</jruby.compat.version>
26+
<!-- Version to execute tests with -->
27+
<jruby.test.version>${jruby.compat.version}</jruby.test.version>
28+
2529
<jruby.maven.plugins.version>3.0.6</jruby.maven.plugins.version>
2630
<gem.home>${project.build.directory}/rubygems</gem.home>
2731
<slf4j.version>2.0.17</slf4j.version>
@@ -76,8 +80,10 @@
7680
<dependencies>
7781
<dependency>
7882
<groupId>org.jruby</groupId>
79-
<artifactId>jruby</artifactId>
80-
<version>${jruby.version}</version>
83+
<!-- This has to be jruby-complete, as bundler-maven-plugin has special logic to exclude jruby-complete - otherwise
84+
it conflicts with the bootclasspath if using different "target compile version" to "runtime version" -->
85+
<artifactId>jruby-complete</artifactId>
86+
<version>${jruby.compat.version}</version>
8187
<scope>provided</scope>
8288
</dependency>
8389
<dependency>
@@ -241,7 +247,7 @@
241247
<phase>test</phase>
242248
<goals><goal>install</goal></goals>
243249
<configuration>
244-
<jrubyVersion>${jruby.version}</jrubyVersion>
250+
<jrubyVersion>${jruby.test.version}</jrubyVersion>
245251
<local>false</local>
246252
<quiet>false</quiet>
247253
</configuration>
@@ -253,7 +259,7 @@
253259
<artifactId>rake-maven-plugin</artifactId>
254260
<version>${jruby.maven.plugins.version}</version>
255261
<configuration>
256-
<jrubyVersion>${jruby.version}</jrubyVersion>
262+
<jrubyVersion>${jruby.test.version}</jrubyVersion>
257263
</configuration>
258264
<executions>
259265
<execution>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ private void captureMessage(final RaiseException re) {
439439
rubyException.callMethod(context, "capture");
440440
rubyException.callMethod(context, "store");
441441
}
442-
catch (Exception e) {
442+
catch (Throwable e) {
443443
rackContext.log(INFO, "failed to capture exception message", e);
444444
// won't be able to capture anything
445445
}

src/spec/ruby/rack/application_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,40 @@ def reset_config
476476
expect(e.message).to eql 'something went wrong'
477477
end
478478
end
479+
480+
it "swallows and logs errors during exception detail capturing" do
481+
expect(@rack_config).to receive(:getRackup).and_return("raise 'something went wrong'")
482+
expect_any_instance_of(Exception).to receive(:capture).and_raise java.lang.NoClassDefFoundError.new("missing class during exception capture")
483+
484+
app_factory = mocked_runtime_application_factory
485+
app_factory.init @rack_context
486+
app_object = app_factory.newApplication
487+
488+
raise_info_logged = 0
489+
raise_error_logged = 0
490+
allow(@rack_context).to receive(:log) do |level, msg, e|
491+
if level.to_s == 'INFO'
492+
expect(msg).to eql 'failed to capture exception message'
493+
expect(e).to be_a java.lang.NoClassDefFoundError
494+
raise_info_logged += 1
495+
elsif level.to_s == 'ERROR'
496+
expect(msg).to eql 'unable to initialize application'
497+
expect(e).to be_a org.jruby.exceptions.RaiseException
498+
raise_error_logged += 1
499+
else
500+
true
501+
end
502+
end
503+
504+
begin
505+
app_object.init
506+
fail "expected to raise"
507+
rescue => e
508+
expect(e.message).to eql 'something went wrong'
509+
end
510+
511+
expect(raise_info_logged).to eql 1 # logs info message for exception capture
512+
end
479513
end
480514

481515
describe "getApplication" do

src/spec/ruby/rack/capture_spec.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,26 @@
1313
before :each do
1414
JRuby::Rack.context = nil
1515
$servlet_context = @servlet_context
16-
allow(@servlet_context).to receive(:init_parameter_names).and_return []
16+
allow(@servlet_context).to receive(:config).and_return Java::OrgJrubyRackEmbed::Config.new
1717
end
1818

1919
it "captures environment information" do
2020
expect(@servlet_context).to receive(:log)
21-
error = StandardError.new
21+
error = StandardError.new "simulated rack start-up failed"
2222
error.capture
2323
error.store
2424
expect(error.output).to be_a StringIO
25+
expect(error.output.string).to include "An exception happened during JRuby-Rack startup"
26+
expect(error.output.string).to include "simulated rack start-up failed"
27+
expect(error.output.string).to include "--- System"
28+
expect(error.output.string).to include "jruby #{JRUBY_VERSION}"
29+
expect(error.output.string).to include "--- Context Init Parameters:"
30+
expect(error.output.string).to include "--- RubyGems"
31+
expect(error.output.string).to include "Gem.path:"
32+
expect(error.output.string).to include "--- Bundler"
33+
expect(error.output.string).to include "Gemfile:"
34+
expect(error.output.string).to include "--- JRuby-Rack Config"
35+
expect(error.output.string).to include "logger_class_name"
2536
end
2637

2738
it "captures exception backtrace" do
@@ -34,4 +45,5 @@
3445
end
3546
end
3647

48+
3749
end

src/spec/ruby/rack/config_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require File.expand_path('spec_helper', File.dirname(__FILE__) + '/..')
22

3-
describe org.jruby.rack.DefaultRackConfig do
3+
describe 'org.jruby.rack.DefaultRackConfig' do
44

55
let(:config) do
66
config = org.jruby.rack.DefaultRackConfig.new
@@ -23,7 +23,7 @@
2323

2424
end
2525

26-
describe org.jruby.rack.servlet.ServletRackConfig do
26+
describe 'org.jruby.rack.servlet.ServletRackConfig' do
2727

2828
let(:config) do
2929
config = org.jruby.rack.servlet.ServletRackConfig.new(@servlet_context)

src/spec/ruby/spec_helper.rb

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,21 @@
2222

2323
module SharedHelpers
2424

25-
java_import 'org.jruby.rack.RackContext'
26-
java_import 'org.jruby.rack.RackConfig'
27-
java_import 'org.jruby.rack.servlet.ServletRackContext'
28-
java_import 'javax.servlet.ServletContext'
29-
java_import 'javax.servlet.ServletConfig'
30-
3125
def mock_servlet_context
32-
@servlet_context = ServletContext.impl {}
33-
@rack_config ||= RackConfig.impl {}
34-
@rack_context ||= ServletRackContext.impl {}
26+
@servlet_context = Java::JavaxServlet::ServletContext.impl {}
27+
@rack_config ||= Java::OrgJrubyRack::RackConfig.impl {}
28+
@rack_context ||= Java::OrgJrubyRackServlet::ServletRackContext.impl {}
3529
[@rack_context, @servlet_context].each do |context|
3630
allow(context).to receive(:log)
3731
allow(context).to receive(:isEnabled).and_return nil
3832
allow(context).to receive(:getInitParameter).and_return nil
3933
allow(context).to receive(:getRealPath).and_return "/"
4034
allow(context).to receive(:getResource).and_return nil
4135
allow(context).to receive(:getContextPath).and_return "/"
36+
allow(context).to receive(:init_parameter_names).and_return []
4237
end
4338
allow(@rack_context).to receive(:getConfig).and_return @rack_config
44-
@servlet_config ||= ServletConfig.impl {}
39+
@servlet_config ||= Java::JavaxServlet::ServletConfig.impl {}
4540
allow(@servlet_config).to receive(:getServletName).and_return "a Servlet"
4641
allow(@servlet_config).to receive(:getServletContext).and_return @servlet_context
4742
@servlet_context
@@ -151,8 +146,8 @@ def should_eval_as_not_nil(code)
151146

152147
config.backtrace_exclusion_patterns = [
153148
/bin\//,
154-
#/gems/,
155-
/spec\/spec_helper\.rb/,
149+
# /gems/,
150+
# /spec\/spec_helper\.rb/,
156151
]
157152

158153
end

0 commit comments

Comments
 (0)