Skip to content

Commit 8c0b76b

Browse files
committed
embed config inheritance (no longer) supported (... for now)
1 parent be105b7 commit 8c0b76b

File tree

8 files changed

+77
-78
lines changed

8 files changed

+77
-78
lines changed

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
/*
2-
* This source code is available under the MIT license.
3-
* See the file LICENSE.txt for details.
2+
* The MIT License
3+
*
4+
* Copyright (c) 2013-2014 Karol Bucek LTD.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
423
*/
524
package org.jruby.rack.embed;
625

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2+
* Copyright (c) 2013-2014 Karol Bucek LTD.
23
* Copyright (c) 2010-2012 Engine Yard, Inc.
34
* Copyright (c) 2007-2009 Sun Microsystems, Inc.
45
* This source code is available under the MIT license.
56
* See the file LICENSE.txt for details.
67
*/
7-
88
package org.jruby.rack.embed;
99

1010
import java.io.IOException;
@@ -27,7 +27,7 @@ public class Dispatcher extends AbstractRackDispatcher {
2727

2828
protected final IRubyObject application;
2929
private RackApplication rackApplication;
30-
30+
3131
public Dispatcher(RackContext rackContext, IRubyObject application) {
3232
super(rackContext);
3333
this.application = application;
@@ -48,7 +48,7 @@ private void initialize() {
4848
// user code should use JRuby::Rack.context instead of $servlet_context
4949
runtime.getGlobalVariables().set("$servlet_context", rubyContext);
5050
}
51-
51+
5252
@Override
5353
protected RackApplication getApplication() throws RackInitializationException {
5454
if (rackApplication == null) {
@@ -57,13 +57,13 @@ protected RackApplication getApplication() throws RackInitializationException {
5757
}
5858
return rackApplication;
5959
}
60-
60+
6161
@Override
6262
public void destroy() {
6363
if (rackApplication != null) rackApplication.destroy();
6464
rackApplication = null;
6565
}
66-
66+
6767
@Override
6868
protected void afterException(
6969
RackEnvironment env, Exception re,
@@ -77,5 +77,5 @@ protected void afterException(
7777
protected void afterProcess(RackApplication app) throws IOException {
7878
// NOOP
7979
}
80-
80+
8181
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2+
* Copyright (c) 2013-2014 Karol Bucek LTD.
23
* Copyright (c) 2010-2012 Engine Yard, Inc.
34
* Copyright (c) 2007-2009 Sun Microsystems, Inc.
45
* This source code is available under the MIT license.
56
* See the file LICENSE.txt for details.
67
*/
7-
88
package org.jruby.rack.embed;
99

1010
import javax.servlet.FilterConfig;
@@ -17,7 +17,7 @@
1717
/**
1818
* There isn't anything particularly embedded about this filter
1919
* FIXME perhaps make this one the base implementation?
20-
*
20+
*
2121
* @author nick
2222
*/
2323
public class Filter extends AbstractFilter {
@@ -44,5 +44,5 @@ protected RackDispatcher getDispatcher() {
4444
public void init(FilterConfig config) throws ServletException {
4545
// NOOP
4646
}
47-
47+
4848
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2+
* Copyright (c) 2013-2014 Karol Bucek LTD.
23
* Copyright (c) 2010-2012 Engine Yard, Inc.
34
* Copyright (c) 2007-2009 Sun Microsystems, Inc.
45
* This source code is available under the MIT license.
56
* See the file LICENSE.txt for details.
67
*/
7-
88
package org.jruby.rack.embed;
99

1010
import javax.servlet.ServletConfig;
@@ -38,5 +38,5 @@ protected RackDispatcher getDispatcher() {
3838
public void init(ServletConfig config) {
3939
// NOOP
4040
}
41-
41+
4242
}
Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
2-
require File.expand_path('spec_helper', File.dirname(__FILE__) + '/../..')
3-
require 'jruby'
1+
require File.expand_path('../../spec_helper', File.dirname(__FILE__))
42

53
describe org.jruby.rack.embed.Config do
64

@@ -9,10 +7,10 @@
97
java.lang.System.set_property "foo", "bar"
108
java.lang.System.set_property "truish", "true"
119
java.lang.System.set_property "falsish", "false"
12-
10+
1311
subject.get_property('foo').should == 'bar'
1412
subject.get_property('foo', 'BAR').should == 'bar'
15-
13+
1614
subject.get_boolean_property('truish').should == true
1715
subject.get_boolean_property('falsish', true).should == false
1816
ensure
@@ -22,47 +20,47 @@
2220
end
2321
end
2422

25-
it "honors properties from provided config if available" do
26-
foo_config = org.jruby.rack.RackConfig.impl {}
27-
def foo_config.getProperty(name, default = nil)
28-
name == 'foo' ? 'bar' : default
29-
end
30-
31-
constructor = org.jruby.rack.embed.Config.java_class.to_java.
32-
getDeclaredConstructor([ org.jruby.rack.RackConfig.java_class ].to_java :'java.lang.Class')
33-
constructor.setAccessible(true)
34-
config = constructor.newInstance(foo_config) # org.jruby.rack.embed.Config.new(foo_config)
35-
36-
begin
37-
java.lang.System.set_property "foo", "BAR"
38-
java.lang.System.set_property "bar", "FOO"
39-
40-
config.getProperty('some').should be nil
41-
42-
config.getProperty('foo').should == 'bar'
43-
config.getProperty('bar').should == 'FOO'
44-
ensure
45-
java.lang.System.clear_property "foo"
46-
java.lang.System.clear_property "bar"
47-
end
48-
end
49-
23+
# it "honors properties from provided config if available" do
24+
# foo_config = org.jruby.rack.RackConfig.impl {}
25+
# def foo_config.getProperty(name, default = nil)
26+
# name == 'foo' ? 'bar' : default
27+
# end
28+
#
29+
# constructor = org.jruby.rack.embed.Config.java_class.to_java.
30+
# getDeclaredConstructor([ org.jruby.rack.RackConfig.java_class ].to_java :'java.lang.Class')
31+
# constructor.setAccessible(true)
32+
# config = constructor.newInstance(foo_config) # org.jruby.rack.embed.Config.new(foo_config)
33+
#
34+
# begin
35+
# java.lang.System.set_property "foo", "BAR"
36+
# java.lang.System.set_property "bar", "FOO"
37+
#
38+
# config.getProperty('some').should be nil
39+
#
40+
# config.getProperty('foo').should == 'bar'
41+
# config.getProperty('bar').should == 'FOO'
42+
# ensure
43+
# java.lang.System.clear_property "foo"
44+
# java.lang.System.clear_property "bar"
45+
# end
46+
# end
47+
5048
context "initialized" do
51-
49+
5250
before(:each) do
5351
@config = org.jruby.rack.embed.Config.new
5452
@config.doInitialize JRuby.runtime
5553
end
56-
54+
5755
it "resolves properties from ENV" do
5856
begin
5957
ENV['env_foo'] = 'env_bar'
6058
ENV['env_true'] = 'true'
6159
ENV['env_false'] = 'false'
62-
60+
6361
@config.get_property('env_foo').should == 'env_bar'
6462
@config.get_property('env_true').should == 'true'
65-
63+
6664
@config.get_boolean_property('env_true').should == true
6765
@config.get_boolean_property('env_false').should == false
6866
ensure
@@ -76,38 +74,36 @@ def foo_config.getProperty(name, default = nil)
7674
begin
7775
ENV["jruby.rack.request.size.initial.bytes"] = '1024'
7876
ENV["jruby.rack.request.size.maximum.bytes"] = '4096'
79-
77+
8078
@config.getInitialMemoryBufferSize.should == 1024
8179
@config.getMaximumMemoryBufferSize.should == 4096
8280
ensure
8381
ENV.delete("jruby.rack.request.size.initial.bytes")
8482
ENV.delete("jruby.rack.request.size.treshold.bytes")
8583
end
8684
end
87-
85+
8886
it "sets compat version from runtime" do
89-
if JRuby.runtime.is1_9
90-
@config.compat_version.should == org.jruby.CompatVersion::RUBY1_9
91-
else
92-
@config.compat_version.should == org.jruby.CompatVersion::RUBY1_8
93-
end
87+
require 'jruby'
88+
compat_version = JRuby.runtime.instance_config.compat_version
89+
expect( @config.compat_version ).to eql compat_version
9490
end
95-
91+
9692
it "sets out/err streams from runtime" do
9793
out = java.io.ByteArrayOutputStream.new
9894
err = java.io.ByteArrayOutputStream.new
9995
config = org.jruby.RubyInstanceConfig.new
10096
config.output = java.io.PrintStream.new(out)
10197
config.error = java.io.PrintStream.new(err)
10298
@config.doInitialize org.jruby.Ruby.newInstance(config)
103-
99+
104100
@config.getOut.println "hello out!"
105101
@config.getErr.println "hello err!"
106-
102+
107103
out.toString.should == "hello out!\n"
108104
err.toString.should == "hello err!\n"
109105
end
110106

111107
end
112-
108+
113109
end

src/spec/ruby/rack/embed/context_spec.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
#--
2-
# Copyright (c) 2010-2012 Engine Yard, Inc.
3-
# Copyright (c) 2007-2009 Sun Microsystems, Inc.
4-
# This source code is available under the MIT license.
5-
# See the file LICENSE.txt for details.
6-
#++
7-
8-
require File.expand_path('spec_helper', File.dirname(__FILE__) + '/../..')
1+
require File.expand_path('../../spec_helper', File.dirname(__FILE__))
92

103
describe org.jruby.rack.embed.Context do
114
let(:stream) { java.io.ByteArrayOutputStream.new }
@@ -28,7 +21,7 @@
2821
context.log info, "this is logging at its best"
2922
captured.should == "INFO: this is logging at its best\n"
3023
end
31-
24+
3225
it "outputs error log messages to stderr" do
3326
my_error = begin
3427
raise java.lang.RuntimeException.new "shizzle sticks"

src/spec/ruby/rack/embed/dispatcher_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
2-
require File.expand_path('spec_helper', File.dirname(__FILE__) + '/../..')
3-
require 'jruby'
1+
require File.expand_path('../../spec_helper', File.dirname(__FILE__))
42

53
describe org.jruby.rack.embed.Dispatcher do
64

src/spec/ruby/rack/embed/filter_spec.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
#--
2-
# Copyright (c) 2010-2012 Engine Yard, Inc.
3-
# Copyright (c) 2007-2009 Sun Microsystems, Inc.
4-
# This source code is available under the MIT license.
5-
# See the file LICENSE.txt for details.
6-
#++
7-
8-
require File.expand_path('spec_helper', File.dirname(__FILE__) + '/../..')
1+
require File.expand_path('../../spec_helper', File.dirname(__FILE__))
92

103
describe org.jruby.rack.embed.Filter do
114

0 commit comments

Comments
 (0)