diff --git a/History.md b/History.md index 7892f6911..e32485dc5 100644 --- a/History.md +++ b/History.md @@ -6,13 +6,18 @@ - Drop unnecessary `jruby.compat.version` and `RackConfig.getCompatVersion()` API - Drop JMS support - Drop deprecated `RackLogger` string (level) constants -- Drop `jruby.rack.jruby.version` and `jruby.rack.rack.release` keys from rack `env` Hhsh +- Drop `jruby.rack.jruby.version` and `jruby.rack.rack.release` keys from rack `env` Hash +- Drop deprecated `Rack::Handler::Servlet::Env` and `Rack::Handler::Servlet::LazyEnv` types (replaced by `DefaultEnv`) +- Drop undocumented and deprecated jruby-rack 1.0 backwards compat properties `jruby.runtime.timeout.sec`, `jruby.runtime.initializer.threads`, `jruby.init.serial`, `jruby.rack.request.size.threshold.bytes` +- Drop deprecated `jruby.rack.ignore.env` property, replaced long ago by `jruby.runtime.env` and optional `jruby.runtime.env.rubyopt` +- Drop deprecated `JRuby::Rack::RailsFileSystemLayout` alias for `JRuby::Rack::FileSystemLayout` +- Drop deprecated `JRuby::Rack::Errors` alias for `JRuby::Rack::ErrorApp` +- Drop deprecated `org.jruby.rack.RackInput` alias for `org.jruby.rack.ext.Input` class +- Drop/rename deprecated `RackConfig` and `ServletRackEnvironment` API methods per their earlier comments - Change context listener to throw, in case of an exception during initialization, by default - Change rails context listener to assume a thread-safe application by default -- update (bundled) rack to 2.2.17 -- Fix Rails 7.1 CSRF protection when working with `JavaServletStore` sessions -## 1.2.4 (UNRELEASED) +## 1.2.4 - update (bundled) rack to 2.2.17 - Fix Rails 7.1 CSRF protection when working with `JavaServletStore` sessions @@ -173,9 +178,9 @@ Changes from 1.1.15 apply since the previous release got yanked due a regression to handle custom lazy-bound keys but can not use a default proc (#132) - support the renew (and skip) session option with servlet store (#131) - improve ENV isolation with booted Ruby runtimes - * jruby.rack.env replaces jruby.rack.ignore.env (now deprecated) + * jruby.runtime.env replaces jruby.rack.ignore.env (now deprecated) * make sure RUBYOPT is ignored (with backwards compat) - * jruby.rack.env.rubyopt for finer RUBYOPT behavior control + * jruby.runtime.env.rubyopt for finer RUBYOPT behavior control * allow env value to be specified from config - solve the rackup "chicken - egg" problem with a plain Rack app * with a magic comment in config.ru # rack.version: ~>1.3.6 diff --git a/README.md b/README.md index 5bb322ace..fc5c787a2 100644 --- a/README.md +++ b/README.md @@ -224,10 +224,9 @@ as context init parameters in web.xml or as VM-wide system properties. - `jruby.runtime.env`: Allows to set a custom ENV hash for your Ruby environment and thus insulate the application from the environment it is running. By setting this option to en empty string (or 'false') it acts as if the ENV hash was - cleared out (similar to the now deprecated `jruby.rack.ignore.env` option). -- `jruby.runtime.env.rubyopt`: This option is used for compatibility with the - (deprecated) `jruby.rack.ignore.env` option since it cleared out the ENV after - RUBYOPT has been processed, by setting it to true ENV['RUBYOPT'] will be kept. + cleared out (similar to the now removed `jruby.rack.ignore.env` option). +- `jruby.runtime.env.rubyopt`: Set to true to cause ENV['RUBYOPT'] + to be retained even when using `jruby.runtime.env` to override environemnt (similar to how the removed `jruby.rack.ignore.env` option behaved by default). - `jruby.rack.logging`: Specify the logging device to use. Defaults to `servlet_context`. See below. - `jruby.rack.request.size.initial.bytes`: Initial size for request body memory diff --git a/Rakefile b/Rakefile index 2a30e4d90..294d47a86 100644 --- a/Rakefile +++ b/Rakefile @@ -51,22 +51,12 @@ end desc "Unpack the rack gem" task :unpack_gem => "target" do |t| target = File.expand_path(t.prerequisites.first) - spec = Gem.loaded_specs['rack'] - # JRuby <= 1.7.20 does not handle respond_to? with method_missing right - # ... issue with Bundler::StubSpecification wrapping (in bundler 1.10.x) - unless ( gem_file = spec.cache_file rescue nil ) - #if defined?(::Bundler) && ::Bundler.const_defined?(:StubSpecification) # since Bundler 1.10.1 - # spec = spec.to_spec if spec.is_a?(::Bundler::StubSpecification) - #else - # spec = spec.to_spec if spec.respond_to?(:to_spec) - #end - gem_file = File.join(spec.base_dir, 'cache', spec.file_name) - end - unless uptodate?("#{target}/vendor/rack.rb", [__FILE__, gem_file]) + rack_gemfile = Gem.loaded_specs['rack'].cache_file + unless uptodate?("#{target}/vendor/rack.rb", [__FILE__, rack_gemfile]) mkdir_p "target/vendor" require 'rubygems/installer' - rack_dir = File.basename(gem_file).sub(/\.gem$/, '') - Gem::Package.new(gem_file).extract_files("#{target}/#{rack_dir}") + rack_dir = File.basename(rack_gemfile).sub(/\.gem$/, '') + Gem::Package.new(rack_gemfile).extract_files("#{target}/#{rack_dir}") File.open("#{target}/vendor/rack.rb", "w") do |f| f << "dir = File.dirname(__FILE__)\n" f << "if dir =~ /.jar!/ && dir !~ /^file:/\n" @@ -187,9 +177,9 @@ task :gem => [target_jar, target_jruby_rack, target_jruby_rack_version] do gem.homepage = %q{http://jruby.org} gem.required_ruby_version = '>= 3.1.0' # JRuby >= 9.4 end - defined?(Gem::Builder) ? Gem::Builder.new(gemspec).build : begin - require 'rubygems/package'; Gem::Package.build(gemspec) - end + + require 'rubygems/package' + Gem::Package.build(gemspec) File.open('jruby-rack.gemspec', 'w') { |f| f << gemspec.to_ruby } mv FileList['*.gem'], '..' end diff --git a/examples/servers/Apache-Tomcat-6-0-14.txt b/examples/servers/Apache-Tomcat-6-0-14.txt index 3f11a1fe5..4dc02a432 100644 --- a/examples/servers/Apache-Tomcat-6-0-14.txt +++ b/examples/servers/Apache-Tomcat-6-0-14.txt @@ -7,7 +7,7 @@ jruby.home: file:/Users/nicksieger/Projects/java/apache-tomcat-6.0.14/webapps/si --- Context Init Parameters: ENV_HOST = Vanguard.local ENV_OUTPUT = /Users/nicksieger/Projects/ruby/jruby-rack/examples/servers -jruby.rack.ignore.env = true +jruby.runtime.env = false public.root = / rack.env = production @@ -33,8 +33,7 @@ Settings: compat_version = filter_adds_html = true filter_verifies_resource = false -ignore_environment = true -initial_runtimes = +initial_runtimes = logger = org.jruby.rack.logging.ServletContextLogger@7a14b43d logger_class_name = servlet_context logger_name = jruby.rack diff --git a/examples/servers/Apache-Tomcat-7-0-2.txt b/examples/servers/Apache-Tomcat-7-0-2.txt index 74f937722..0c9d126fc 100644 --- a/examples/servers/Apache-Tomcat-7-0-2.txt +++ b/examples/servers/Apache-Tomcat-7-0-2.txt @@ -7,7 +7,6 @@ jruby.home: file:/Users/nicksieger/Projects/java/apache-tomcat-7.0.2/webapps/sin --- Context Init Parameters: ENV_HOST = Vanguard.local ENV_OUTPUT = /Users/nicksieger/Projects/ruby/jruby-rack/examples/servers -jruby.rack.ignore.env = true public.root = / rack.env = production @@ -33,8 +32,7 @@ Settings: compat_version = filter_adds_html = true filter_verifies_resource = false -ignore_environment = true -initial_runtimes = +initial_runtimes = logger = org.jruby.rack.logging.ServletContextLogger@398a3257 logger_class_name = servlet_context logger_name = jruby.rack diff --git a/examples/servers/GlassFish-v3.txt b/examples/servers/GlassFish-v3.txt index 33d4eeb87..a5a22c65d 100644 --- a/examples/servers/GlassFish-v3.txt +++ b/examples/servers/GlassFish-v3.txt @@ -9,7 +9,7 @@ ENV_HOST = Vanguard.local ENV_OUTPUT = /Users/nicksieger/Projects/ruby/jruby-rack/examples/servers com.sun.faces.forceLoadConfiguration = true com.sun.faces.validateXml = true -jruby.rack.ignore.env = true +jruby.runtime.env = false public.root = / rack.env = production @@ -35,8 +35,7 @@ Settings: compat_version = filter_adds_html = true filter_verifies_resource = false -ignore_environment = true -initial_runtimes = +initial_runtimes = logger = org.jruby.rack.logging.ServletContextLogger@46ee45a5 logger_class_name = servlet_context logger_name = jruby.rack diff --git a/examples/servers/JBoss-Web-2-1-3-GA.txt b/examples/servers/JBoss-Web-2-1-3-GA.txt index f0b535ac9..255a408f6 100644 --- a/examples/servers/JBoss-Web-2-1-3-GA.txt +++ b/examples/servers/JBoss-Web-2-1-3-GA.txt @@ -9,7 +9,6 @@ ENV_HOST = Vanguard.local ENV_OUTPUT = /Users/nicksieger/Projects/ruby/jruby-rack/examples/servers com.sun.faces.duplicateJARPattern = ^tmp\d+(\S*\.jar) com.sun.faces.injectionProvider = org.jboss.web.jsf.integration.injection.JBossDelegatingInjectionProvider -jruby.rack.ignore.env = true public.root = / rack.env = production @@ -35,8 +34,7 @@ Settings: compat_version = filter_adds_html = true filter_verifies_resource = false -ignore_environment = true -initial_runtimes = +initial_runtimes = logger = org.jruby.rack.logging.ServletContextLogger@1a20433b logger_class_name = servlet_context logger_name = jruby.rack diff --git a/examples/servers/JBoss-Web-3-0-0-CR1.txt b/examples/servers/JBoss-Web-3-0-0-CR1.txt index 22a2c4eb8..2c9923800 100644 --- a/examples/servers/JBoss-Web-3-0-0-CR1.txt +++ b/examples/servers/JBoss-Web-3-0-0-CR1.txt @@ -7,7 +7,7 @@ jruby.home: classpath:/META-INF/jruby.home --- Context Init Parameters: ENV_HOST = Vanguard.local ENV_OUTPUT = /Users/nicksieger/Projects/ruby/jruby-rack/examples/servers -jruby.rack.ignore.env = true +jruby.runtime.env = false public.root = / rack.env = production resteasy.unwrapped.exceptions = javax.ejb.EJBException @@ -34,8 +34,7 @@ Settings: compat_version = filter_adds_html = true filter_verifies_resource = false -ignore_environment = true -initial_runtimes = +initial_runtimes = logger = org.jruby.rack.logging.ServletContextLogger@7ee18d93 logger_class_name = servlet_context logger_name = jruby.rack diff --git a/examples/servers/Resin-4-0-13.txt b/examples/servers/Resin-4-0-13.txt index 68dd49b88..6b4b9a4d4 100644 --- a/examples/servers/Resin-4-0-13.txt +++ b/examples/servers/Resin-4-0-13.txt @@ -7,7 +7,7 @@ jruby.home: file:/Users/nicksieger/Projects/java/resin-4.0.13/webapps/sinatra/WE --- Context Init Parameters: ENV_HOST = Vanguard.local ENV_OUTPUT = /Users/nicksieger/Projects/ruby/jruby-rack/examples/servers -jruby.rack.ignore.env = true +jruby.runtime.env = false public.root = / rack.env = production @@ -33,8 +33,7 @@ Settings: compat_version = filter_adds_html = true filter_verifies_resource = false -ignore_environment = true -initial_runtimes = +initial_runtimes = logger = org.jruby.rack.logging.ServletContextLogger@6c538793 logger_class_name = servlet_context logger_name = jruby.rack diff --git a/examples/servers/Winstone-Servlet-Engine-v0-9-10.txt b/examples/servers/Winstone-Servlet-Engine-v0-9-10.txt index 56e19417b..d4f39a74d 100644 --- a/examples/servers/Winstone-Servlet-Engine-v0-9-10.txt +++ b/examples/servers/Winstone-Servlet-Engine-v0-9-10.txt @@ -7,7 +7,7 @@ jruby.home: file:/private/var/folders/1j/pj33xy610ms4jxbv3g0zh9400000gn/T/winsto --- Context Init Parameters: ENV_HOST = Vanguard.local ENV_OUTPUT = /Users/nicksieger/Projects/ruby/jruby-rack/examples/servers -jruby.rack.ignore.env = true +jruby.runtime.env = false public.root = / rack.env = production @@ -34,8 +34,7 @@ Settings: compat_version = filter_adds_html = true filter_verifies_resource = false -ignore_environment = true -initial_runtimes = +initial_runtimes = logger = org.jruby.rack.logging.ServletContextLogger@397af435 logger_class_name = servlet_context logger_name = jruby.rack diff --git a/examples/servers/jetty-6-1-25.txt b/examples/servers/jetty-6-1-25.txt index 72e86d1c5..570b95fe5 100644 --- a/examples/servers/jetty-6-1-25.txt +++ b/examples/servers/jetty-6-1-25.txt @@ -7,7 +7,7 @@ jruby.home: file:/private/tmp/Jetty_0_0_0_0_8080_sinatra.war__sinatra__86inrb/we --- Context Init Parameters: ENV_HOST = Vanguard.local ENV_OUTPUT = /Users/nicksieger/Projects/ruby/jruby-rack/examples/servers -jruby.rack.ignore.env = true +jruby.runtime.env = false org.mortbay.jetty.webapp.NoTLDJarPattern = start.jar|ant-.*\.jar|dojo-.*\.jar|jetty-.*\.jar|jsp-api-.*\.jar|junit-.*\.jar|servlet-api-.*\.jar|dnsns\.jar|rt\.jar|jsse\.jar|tools\.jar|sunpkcs11\.jar|sunjce_provider\.jar|xerces.*\.jar public.root = / rack.env = production @@ -34,8 +34,7 @@ Settings: compat_version = filter_adds_html = true filter_verifies_resource = false -ignore_environment = true -initial_runtimes = +initial_runtimes = logger = org.jruby.rack.logging.ServletContextLogger@1303368e logger_class_name = servlet_context logger_name = jruby.rack diff --git a/examples/servers/jetty-7-1-6-v20100715.txt b/examples/servers/jetty-7-1-6-v20100715.txt index 6491724bf..d219a36e2 100644 --- a/examples/servers/jetty-7-1-6-v20100715.txt +++ b/examples/servers/jetty-7-1-6-v20100715.txt @@ -7,7 +7,7 @@ jruby.home: file:/private/var/folders/1j/pj33xy610ms4jxbv3g0zh9400000gn/T/Jetty_ --- Context Init Parameters: ENV_HOST = Vanguard.local ENV_OUTPUT = /Users/nicksieger/Projects/ruby/jruby-rack/examples/servers -jruby.rack.ignore.env = true +jruby.runtime.env = false public.root = / rack.env = production @@ -33,8 +33,7 @@ Settings: compat_version = filter_adds_html = true filter_verifies_resource = false -ignore_environment = true -initial_runtimes = +initial_runtimes = logger = org.jruby.rack.logging.ServletContextLogger@773fc437 logger_class_name = servlet_context logger_name = jruby.rack diff --git a/examples/sinatra/config/warble.rb b/examples/sinatra/config/warble.rb index 77846d951..46b3d7706 100644 --- a/examples/sinatra/config/warble.rb +++ b/examples/sinatra/config/warble.rb @@ -11,5 +11,5 @@ require 'socket' config.webxml.ENV_OUTPUT = File.expand_path('../../servers', __FILE__) config.webxml.ENV_HOST = Socket.gethostname - config.webxml.jruby.rack.ignore.env = true + config.webxml.jruby.runtime.env = false end diff --git a/src/main/java/org/jruby/rack/AbstractFilter.java b/src/main/java/org/jruby/rack/AbstractFilter.java index 4b8c05333..898e82ee3 100644 --- a/src/main/java/org/jruby/rack/AbstractFilter.java +++ b/src/main/java/org/jruby/rack/AbstractFilter.java @@ -62,7 +62,7 @@ public final void doFilter( // NOTE: should be moved bellow, just before getDispatcher().process(...) RackResponseEnvironment responseEnv = new ServletRackResponseEnvironment(httpResponse); - if (isDoDispatch(requestCapture, responseCapture, chain, env, responseEnv)) { + if (isDoDispatch(requestCapture, responseCapture, chain, env)) { getDispatcher().process(env, responseEnv); } @@ -99,26 +99,6 @@ protected boolean isDoDispatch( return true; } - /** - * @deprecated use {@link #isDoDispatch(RequestCapture, ResponseCapture, FilterChain, RackEnvironment)} - * @param request the request - * @param response the response - * @param chain the FilterChain - * @param env the RackEnvironent - * @param responseEnv the RackResponseEnvironment - * @return isDoDispatch - * @throws IOException if there's an IO exception - * @throws ServletException if there's a servlet exception - */ - @Deprecated - protected boolean isDoDispatch( - RequestCapture request, ResponseCapture response, - FilterChain chain, RackEnvironment env, - RackResponseEnvironment responseEnv) - throws IOException, ServletException { - return isDoDispatch(request, response, chain, env); - } - /** * Extension point if you'll need to customize {@link RequestCapture} * @param request the request diff --git a/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java b/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java index 088ced7aa..c0bcec14a 100644 --- a/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java +++ b/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java @@ -367,7 +367,7 @@ public void initRuntime(final Ruby runtime) { /** * Checks and sets the required Rack version (if specified as a magic comment). * - * e.g. # rack.version: =1.3.6 + * e.g. # rack.version: =2.2.0 * * @apiNote Internal API, only visible due tests. * diff --git a/src/main/java/org/jruby/rack/DefaultRackConfig.java b/src/main/java/org/jruby/rack/DefaultRackConfig.java index 83e51459f..afae43fde 100644 --- a/src/main/java/org/jruby/rack/DefaultRackConfig.java +++ b/src/main/java/org/jruby/rack/DefaultRackConfig.java @@ -28,7 +28,6 @@ * @see System#getProperty(String) * @see RackConfig */ -@SuppressWarnings("deprecation") public class DefaultRackConfig implements RackConfig { private RackLogger logger; @@ -85,12 +84,8 @@ public String getRackupPath() { } @Override - public Integer getRuntimeTimeoutSeconds() { - Integer timeout = getPositiveInteger("jruby.runtime.acquire.timeout"); - if (timeout == null) { // backwards compatibility with 1.0.x : - timeout = getPositiveInteger("jruby.runtime.timeout.sec"); - } - return timeout; + public Integer getRuntimeAcquireTimeout() { + return getPositiveInteger("jruby.runtime.acquire.timeout"); } @Override @@ -100,29 +95,17 @@ public String[] getRuntimeArguments() { } @Override - public Integer getNumInitializerThreads() { + public Integer getRuntimeInitThreads() { Number threads = getNumberProperty("jruby.runtime.init.threads"); - if (threads == null) { // backwards compatibility with 1.0.x : - threads = getNumberProperty("jruby.runtime.initializer.threads"); - } return threads != null ? threads.intValue() : null; } @Override public boolean isSerialInitialization() { Boolean serial = getBooleanProperty("jruby.runtime.init.serial"); - if (serial == null) { // backwards compatibility with 1.0.x : - serial = getBooleanProperty("jruby.init.serial"); - - if (serial == null) { // if initializer threads set to <= 0 - Integer threads = getNumInitializerThreads(); - if ( threads != null && threads < 0 ) { - serial = Boolean.TRUE; - } - else { - serial = Boolean.FALSE; - } - } + if (serial == null) { // if initializer threads set to <= 0 + Integer threads = getRuntimeInitThreads(); + serial = threads != null && threads < 0 ? Boolean.TRUE : Boolean.FALSE; } return serial; } @@ -157,8 +140,8 @@ protected RackLogger createLogger(final String loggerClass) { Constructor ctor = klass.getConstructor(String.class); return (RackLogger) ctor.newInstance( getLoggerName() ); } - catch (NoSuchMethodException | IllegalAccessException retry) { - return newLoggerInstance(klass, retry); + catch (NoSuchMethodException | IllegalAccessException ignore) { + return newLoggerInstance(klass); } catch (InstantiationException e) { throw new RackException("could not create logger: '" + loggerClass + "'", e); @@ -176,9 +159,9 @@ protected RackLogger createLogger(final String loggerClass) { return null; } - private static RackLogger newLoggerInstance(final Class klass, final Exception retry) { + private static RackLogger newLoggerInstance(final Class klass) { try { - return (RackLogger) klass.newInstance(); + return (RackLogger) klass.getDeclaredConstructor().newInstance(); } catch (Exception e) { // InstantiationException, IllegalAccessException throw new RackException("could not create logger: '" + klass.getName() + @@ -190,15 +173,6 @@ protected RackLogger defaultLogger() { return new StandardOutLogger(getOut()); } - @Override - public boolean isFilterAddsHtml() { - return getBooleanProperty("jruby.rack.filter.adds.html", true); - } - - @Override - public boolean isFilterVerifiesResource() { - return getBooleanProperty("jruby.rack.filter.verifies.resource", false); - } public String getLoggerName() { return getProperty("jruby.rack.logging.name", "jruby.rack"); @@ -232,40 +206,27 @@ public Integer getInitialMemoryBufferSize() { @Override public Integer getMaximumMemoryBufferSize() { - Integer max = getPositiveInteger("jruby.rack.request.size.maximum.bytes"); - if (max == null) { // backwards compatibility with 1.0.x : - max = getPositiveInteger("jruby.rack.request.size.threshold.bytes"); - } - return max; + return getPositiveInteger("jruby.rack.request.size.maximum.bytes"); } @Override public Map getRuntimeEnvironment() { String env = getProperty("jruby.runtime.env"); - if ( env == null ) env = getProperty("jruby.runtime.environment"); final Object envFlag = toStrictBoolean(env, null); if ( envFlag != null ) { // jruby.runtime.env = true keep as is (return null) // jruby.runtime.env = false clear env (return empty) return (Boolean) envFlag ? new HashMap<>(System.getenv()) : new HashMap<>(); } - if ( isIgnoreEnvironment() ) return new HashMap<>(); // TODO maybe support custom value 'servlet' to use init params ? return toStringMap(env); } - // NOTE: this is only here to be able to maintain previous behavior - // jruby.rack.ignore.env did ENV.clear but after RUBYOPT has been processed + // NOTE: this allows reinstating earlier behaviour where ENV was only cleared after RUBYOPT has been processed static boolean isIgnoreRUBYOPT(RackConfig config) { - // RUBYOPT ignored if jruby.runtime.env.rubyopt = false - Boolean rubyopt = config.getBooleanProperty("jruby.runtime.env.rubyopt"); - if ( rubyopt == null ) return ! config.isIgnoreEnvironment(); - return !rubyopt; - } - - @Override - public boolean isIgnoreEnvironment() { - return getBooleanProperty("jruby.rack.ignore.env", false); + // RUBYOPT ignored if jruby.runtime.env.rubyopt = false or unset + Boolean retainRubyopt = config.getBooleanProperty("jruby.runtime.env.rubyopt"); + return retainRubyopt == null || !retainRubyopt; } public boolean isThrowInitException() { diff --git a/src/main/java/org/jruby/rack/PoolingRackApplicationFactory.java b/src/main/java/org/jruby/rack/PoolingRackApplicationFactory.java index fdc6e4a29..d2d9466fa 100644 --- a/src/main/java/org/jruby/rack/PoolingRackApplicationFactory.java +++ b/src/main/java/org/jruby/rack/PoolingRackApplicationFactory.java @@ -113,13 +113,7 @@ public void setAcquireTimeout(Number acquireTimeout) { protected void doInit() throws Exception { super.doInit(); final RackConfig config = getConfig(); - // TODO until config.getRuntimeTimeoutSeconds returns an integer : - Number timeout = config.getNumberProperty("jruby.runtime.acquire.timeout"); - if (timeout == null) { // backwards compatibility with 1.0.x : - timeout = config.getNumberProperty("jruby.runtime.timeout.sec"); - } - setAcquireTimeout( timeout ); - + setAcquireTimeout( config.getRuntimeAcquireTimeout() ); setInitialSize( config.getInitialRuntimes() ); setMaximumSize( config.getMaximumRuntimes() ); @@ -268,27 +262,17 @@ public void fillInitialPool() throws RackInitializationException { permits = maximumSize != null ? new Semaphore(maximumSize, true) : null; if (initialSize != null) { // otherwise pool filled on demand Queue apps = createApplications(); - launchInitializerThreads(apps); + launchInitialization(apps); waitTillPoolReady(); } } - /** - * @param apps a queue of apps - * @deprecated override {@link #launchInitialization(java.util.Queue)} - */ - @Deprecated - protected void launchInitializerThreads(final Queue apps) { - launchInitialization(apps); - } - /** * Launches application initialization. * @param apps the (initial) instances (for the pool) to be initialized */ protected void launchInitialization(final Queue apps) { - @SuppressWarnings("deprecation") - Integer initThreads = getConfig().getNumInitializerThreads(); + Integer initThreads = getConfig().getRuntimeInitThreads(); if ( initThreads == null ) initThreads = 4; // quad-core baby for (int i = 0; i < initThreads; i++) { diff --git a/src/main/java/org/jruby/rack/RackApplicationFactoryDecorator.java b/src/main/java/org/jruby/rack/RackApplicationFactoryDecorator.java index 3da206028..69ceff3cc 100644 --- a/src/main/java/org/jruby/rack/RackApplicationFactoryDecorator.java +++ b/src/main/java/org/jruby/rack/RackApplicationFactoryDecorator.java @@ -58,10 +58,6 @@ public RackApplicationFactory getDelegate() { return delegate; } - @Deprecated - public RackApplicationFactory getRealFactory() { - return getDelegate(); - } public RackContext getContext() { return context; diff --git a/src/main/java/org/jruby/rack/RackConfig.java b/src/main/java/org/jruby/rack/RackConfig.java index 442e9e59c..1f946bb69 100644 --- a/src/main/java/org/jruby/rack/RackConfig.java +++ b/src/main/java/org/jruby/rack/RackConfig.java @@ -76,31 +76,20 @@ public interface RackConfig { * @return the ENV to be used in started Ruby runtimes */ Map getRuntimeEnvironment(); - - /** - * Returns true if the outer environment (variables) should not be used. - * - * @return whether to ENV.clear the Ruby runtime - * @deprecated replaced with {@link #getRuntimeEnvironment()} - */ - @Deprecated - boolean isIgnoreEnvironment(); - + /** * Return the configured amount of time before runtime acquisition times out (in seconds). * * @return the amount of time before runtimes acquisition times out */ - @Deprecated // TODO rename to Float getRuntimeAquireTimeout - Integer getRuntimeTimeoutSeconds(); - + Integer getRuntimeAcquireTimeout(); + /** * Get the number of initializer threads, or null if unspecified. * * @return the number of initializer threads or null */ - @Deprecated // TODO rename to Integer getRuntimeInitThreads - Integer getNumInitializerThreads(); + Integer getRuntimeInitThreads(); /** * Return true if runtimes should be initialized in serial @@ -141,29 +130,8 @@ public interface RackConfig { * @return a logger instance */ RackLogger getLogger(); - - /** - * Return true if passing through the filter should append '.html' - * (or 'index.html') to the path. - * - * @return true if the filter should append .html - * @deprecated configure filter with a nested init-param - * @see RackFilter - */ - @Deprecated - boolean isFilterAddsHtml(); - /** - * Return true if filter should verify the resource exists using - * ServletContext#getResource before adding .html on the request. - * - * @return true if the filter should verify the resource - * @deprecated configure filter with a nested init-param - * @see RackFilter - */ - @Deprecated - boolean isFilterVerifiesResource(); - /** + /** * General property retrieval for custom configuration values. * * @param key the key diff --git a/src/main/java/org/jruby/rack/RackInput.java b/src/main/java/org/jruby/rack/RackInput.java deleted file mode 100644 index 4f0735a1c..000000000 --- a/src/main/java/org/jruby/rack/RackInput.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * The MIT License - * - * Copyright 2013 Karol Bucek. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.jruby.rack; - -import java.io.IOException; - -import org.jruby.Ruby; -import org.jruby.RubyClass; -import org.jruby.runtime.ObjectAllocator; - -/** - * @deprecated Moved into {@link org.jruby.rack.ext.Input}. - * - * @author kares - */ -@Deprecated -public class RackInput extends org.jruby.rack.ext.Input { - - @Deprecated - public static RubyClass getClass(Ruby runtime, String name, RubyClass parent, - ObjectAllocator allocator, Class annoClass) { - return runtime.getOrCreateModule("JRuby").getClass(name); // RackInput - } - - public RackInput(Ruby runtime, RubyClass klass) { - super(runtime, klass); - } - - public RackInput(Ruby runtime, RackEnvironment env) throws IOException { - super(runtime, env); - } - -} \ No newline at end of file diff --git a/src/main/java/org/jruby/rack/RackResponseEnvironment.java b/src/main/java/org/jruby/rack/RackResponseEnvironment.java index 48da1b582..6771704bf 100644 --- a/src/main/java/org/jruby/rack/RackResponseEnvironment.java +++ b/src/main/java/org/jruby/rack/RackResponseEnvironment.java @@ -120,13 +120,4 @@ public interface RackResponseEnvironment { */ PrintWriter getWriter() throws IOException ; - /** - * @see RackResponse#respond(RackResponseEnvironment) - * @param response the response - * @throws IOException if there's an IO exception - * @deprecated (should) no longer (be) used - */ - @Deprecated - void defaultRespond(RackResponse response) throws IOException ; - } diff --git a/src/main/java/org/jruby/rack/embed/Config.java b/src/main/java/org/jruby/rack/embed/Config.java index 77f4ce45e..17c4ad83e 100644 --- a/src/main/java/org/jruby/rack/embed/Config.java +++ b/src/main/java/org/jruby/rack/embed/Config.java @@ -161,8 +161,8 @@ public String getRackupPath() { // runtime pooling in embedded ENVs not implemented : @Override - public Integer getRuntimeTimeoutSeconds() { - throw new UnsupportedOperationException("getRuntimeTimeoutSeconds()"); + public Integer getRuntimeAcquireTimeout() { + throw new UnsupportedOperationException("getRuntimeAcquireTimeout()"); } @Override @@ -181,8 +181,8 @@ public String[] getRuntimeArguments() { } @Override - public Integer getNumInitializerThreads() { - throw new UnsupportedOperationException("getNumInitializerThreads()"); + public Integer getRuntimeInitThreads() { + throw new UnsupportedOperationException("getRuntimeInitThreads()"); } @Override @@ -190,26 +190,8 @@ public boolean isSerialInitialization() { throw new UnsupportedOperationException("isSerialInitialization()"); } - @Override - public boolean isIgnoreEnvironment() { - throw new UnsupportedOperationException("isIgnoreEnvironment()"); - } - @Override public Map getRuntimeEnvironment() { throw new UnsupportedOperationException("getRuntimeEnvironment()"); } - - // RackFilter aint's used with embed : - - @Override - public boolean isFilterAddsHtml() { - throw new UnsupportedOperationException("isFilterAddsHtml()"); - } - - @Override - public boolean isFilterVerifiesResource() { - throw new UnsupportedOperationException("isFilterVerifiesResource()"); - } - } diff --git a/src/main/java/org/jruby/rack/ext/Input.java b/src/main/java/org/jruby/rack/ext/Input.java index da3431925..f50a26d8c 100644 --- a/src/main/java/org/jruby/rack/ext/Input.java +++ b/src/main/java/org/jruby/rack/ext/Input.java @@ -10,9 +10,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -27,7 +24,6 @@ import org.jruby.rack.servlet.RewindableInputStream; import org.jruby.rack.util.ExceptionUtils; import org.jruby.runtime.Block; -import org.jruby.runtime.Helpers; import org.jruby.runtime.ObjectAllocator; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; @@ -42,24 +38,6 @@ */ @SuppressWarnings("serial") public class Input extends RubyObject { - private static final MethodHandle CONCAT_WITH_CODERANGE; - - static { - // set up coderange-aware concat that works with the new catWithCodeRange as well as earlier JRuby without it. - // TODO: remove and replace with direct call once 9.3 is fully unsupported - MethodHandle catWithCR = null; - MethodHandles.Lookup lookup = MethodHandles.lookup(); - try { - catWithCR = lookup.findVirtual(RubyString.class, "catWithCodeRange", MethodType.methodType(int.class, ByteList.class, int.class)); - } catch (NoSuchMethodException | IllegalAccessException e) { - try { - catWithCR = lookup.findVirtual(RubyString.class, "cat19", MethodType.methodType(int.class, ByteList.class, int.class)); - } catch (Exception t) { - Helpers.throwException(t); - } - } - CONCAT_WITH_CODERANGE = catWithCR; - } static final ObjectAllocator ALLOCATOR = Input::new; @@ -166,12 +144,7 @@ public IRubyObject read(final ThreadContext context, final IRubyObject[] args) { if ( bytes != null ) { if ( buffer != null ) { buffer.clear(); - try { - int unused = (int) CONCAT_WITH_CODERANGE.invokeExact(buffer, new ByteList(bytes, false), StringSupport.CR_UNKNOWN); - } catch (Throwable t) { - Helpers.throwException(t); - } - + buffer.catWithCodeRange(new ByteList(bytes, false), StringSupport.CR_UNKNOWN); return buffer; } return context.runtime.newString(new ByteList(bytes, false)); diff --git a/src/main/java/org/jruby/rack/ext/RackLibrary.java b/src/main/java/org/jruby/rack/ext/RackLibrary.java index 54aa6e0b0..4ef62965f 100644 --- a/src/main/java/org/jruby/rack/ext/RackLibrary.java +++ b/src/main/java/org/jruby/rack/ext/RackLibrary.java @@ -53,7 +53,6 @@ public static void load(final Ruby runtime) { "Input", _Object, Input.ALLOCATOR ); _Input.defineAnnotatedMethods(Input.class); - _JRuby.setConstant("RackInput", _Input); // @deprecated backwards-compat // JRuby::Rack::Logger final RubyClass _Logger = _JRuby_Rack.defineClassUnder( diff --git a/src/main/java/org/jruby/rack/ext/Response.java b/src/main/java/org/jruby/rack/ext/Response.java index d65dacd46..446b098eb 100644 --- a/src/main/java/org/jruby/rack/ext/Response.java +++ b/src/main/java/org/jruby/rack/ext/Response.java @@ -365,7 +365,7 @@ public IRubyObject write_headers(final ThreadContext context, final IRubyObject private static final ByteList NEW_LINE = new ByteList(new byte[] { '\n' }, false); protected void writeHeaders(final RackResponseEnvironment response) throws IOException { - this.headers.visitAll(new RubyHash.Visitor() { // headers.each { |key, val| } + this.headers.visitAll(getRuntime().getCurrentContext(), new RubyHash.Visitor() { // headers.each { |key, val| } @Override public void visit(final IRubyObject key, final IRubyObject val) { final String name = key.toString(); @@ -424,7 +424,7 @@ else if ( val instanceof RubyTime ) { response.addHeader(name, val.toString()); } - }); + }, null); } @JRubyMethod(name = "write_body") diff --git a/src/main/java/org/jruby/rack/servlet/DefaultServletRackContext.java b/src/main/java/org/jruby/rack/servlet/DefaultServletRackContext.java index e1077566b..b100f72cf 100644 --- a/src/main/java/org/jruby/rack/servlet/DefaultServletRackContext.java +++ b/src/main/java/org/jruby/rack/servlet/DefaultServletRackContext.java @@ -148,17 +148,17 @@ public RequestDispatcher getNamedDispatcher(String name) { return context.getNamedDispatcher(name); } - @Override @Deprecated + @Override @Deprecated // Deprecated in API parent public Servlet getServlet(String name) throws ServletException { return context.getServlet(name); } - @Override @Deprecated + @Override @Deprecated // Deprecated in API parent public Enumeration getServlets() { return context.getServlets(); } - @Override @Deprecated + @Override @Deprecated // Deprecated in API parent public Enumeration getServletNames() { return context.getServletNames(); } @@ -198,7 +198,7 @@ public String getServletContextName() { return context.getServletContextName(); } - @Override @Deprecated + @Override @Deprecated // Deprecated in API parent public void log(Exception e, String msg) { logger.log(msg, e); } diff --git a/src/main/java/org/jruby/rack/servlet/ResponseCapture.java b/src/main/java/org/jruby/rack/servlet/ResponseCapture.java index 7929cd35a..c694c1860 100644 --- a/src/main/java/org/jruby/rack/servlet/ResponseCapture.java +++ b/src/main/java/org/jruby/rack/servlet/ResponseCapture.java @@ -81,9 +81,9 @@ public void setStatus(int status) { } } - @SuppressWarnings("deprecation") @Override - @Deprecated + @Deprecated // Deprecated in API parent + @SuppressWarnings("deprecation") public void setStatus(int status, String message) { if ( handleStatus(status, false) ) { super.setStatus(status, message); @@ -207,7 +207,6 @@ public boolean isError() { } /** - * @deprecated no longer to be used from outside * @see #isHandled(HttpServletRequest) * @return true if handled */ diff --git a/src/main/java/org/jruby/rack/servlet/ServletRackEnvironment.java b/src/main/java/org/jruby/rack/servlet/ServletRackEnvironment.java index 7725a80cb..c207515dc 100644 --- a/src/main/java/org/jruby/rack/servlet/ServletRackEnvironment.java +++ b/src/main/java/org/jruby/rack/servlet/ServletRackEnvironment.java @@ -15,7 +15,6 @@ import org.jruby.rack.RackContext; import org.jruby.rack.RackEnvironment; -import org.jruby.rack.ext.Input; /** * Rack environment (default) implementation based on {@link HttpServletRequest}.. @@ -146,11 +145,4 @@ public String getRequestURIWithoutQuery() { final String defaultURI = super.getRequestURI(); return requestURIWithoutQuery = defaultURI == null ? "" : defaultURI; } - - private Input io; - - @Deprecated public Input toIO() { return io; } - - @Deprecated public void setIO(Input io) { this.io = io; } - } diff --git a/src/main/java/org/jruby/rack/servlet/ServletRackResponseEnvironment.java b/src/main/java/org/jruby/rack/servlet/ServletRackResponseEnvironment.java index accad8b45..93953cac6 100644 --- a/src/main/java/org/jruby/rack/servlet/ServletRackResponseEnvironment.java +++ b/src/main/java/org/jruby/rack/servlet/ServletRackResponseEnvironment.java @@ -7,12 +7,9 @@ package org.jruby.rack.servlet; -import java.io.IOException; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; -import org.jruby.rack.DefaultErrorApplication; -import org.jruby.rack.RackResponse; import org.jruby.rack.RackResponseEnvironment; /** @@ -27,10 +24,4 @@ public ServletRackResponseEnvironment(HttpServletResponse response) { super(response); } - @Override - @Deprecated - public void defaultRespond(final RackResponse response) throws IOException { - DefaultErrorApplication.defaultRespond(response, this); - } - } diff --git a/src/main/ruby/jruby/rack/app_layout.rb b/src/main/ruby/jruby/rack/app_layout.rb index ba3ab8c21..11cc5f5d6 100644 --- a/src/main/ruby/jruby/rack/app_layout.rb +++ b/src/main/ruby/jruby/rack/app_layout.rb @@ -181,10 +181,5 @@ def expand_path(path) end end - - RailsFileSystemLayout = FileSystemLayout - # @private backwards compatibility - RailsFilesystemLayout = FileSystemLayout - end end diff --git a/src/main/ruby/jruby/rack/booter.rb b/src/main/ruby/jruby/rack/booter.rb index e319f93af..1e834e7b3 100644 --- a/src/main/ruby/jruby/rack/booter.rb +++ b/src/main/ruby/jruby/rack/booter.rb @@ -58,8 +58,6 @@ def initialize(rack_context = nil) # @return [Class] the (default) layout class to use # @see #layout_class def self.default_layout_class; WebInfLayout; end - # @deprecated use the class method - def default_layout_class; self.class.default_layout_class; end # @return [Class] the layout class to use # @see #layout @@ -188,11 +186,6 @@ def load_settings_from_init_rb end end - # @deprecated no longer used, replaced with {#run_boot_hooks} - def load_extensions - run_boot_hooks - end - def relative_url_root(init_param = 'rack.relative_url_append') relative_url_root = @rack_context.getContextPath || '' if relative_url_append = @rack_context.getInitParameter(init_param) diff --git a/src/main/ruby/jruby/rack/capture.rb b/src/main/ruby/jruby/rack/capture.rb index deee065af..c583f92c6 100644 --- a/src/main/ruby/jruby/rack/capture.rb +++ b/src/main/ruby/jruby/rack/capture.rb @@ -47,11 +47,7 @@ def capture if JRuby.runtime.instance_config.respond_to?(:trace_type) trace_type = JRuby.runtime.instance_config.trace_type # getTraceType begin - if JRUBY_VERSION < '1.7' - full_trace = trace_type.print_backtrace(self) - else - full_trace = trace_type.print_backtrace(self, false) - end + full_trace = trace_type.print_backtrace(self, false) rescue => e warn "failed to print backtrace due: #{e}" rescue nil full_trace = backtrace.join("\n") diff --git a/src/main/ruby/jruby/rack/error_app.rb b/src/main/ruby/jruby/rack/error_app.rb index 2ae0a639f..8d50de877 100644 --- a/src/main/ruby/jruby/rack/error_app.rb +++ b/src/main/ruby/jruby/rack/error_app.rb @@ -46,7 +46,7 @@ def call(env) code = response_code(env) - return respond(code) if ! root || ! accept_html?(env) + return respond(code) if !root || !accepts_html?(env) # TODO support custom JSON/XML 5xx and better HTTP_ACCEPT matching # NOTE: code == 503 ... we're try 503.html and fallback to 500.html @@ -83,9 +83,8 @@ def serve(code, path, env) DEFAULT_HEADERS.each { |field, content| headers[field] = content } ext = File.extname(path) size = File.size?(path) - mime = ::Rack::Mime.mime_type(ext, DEFAULT_MIME) if defined?(::Rack::Mime) - mime = 'text/html' if ! mime && ( ext == '.html' || ext == '.htm' ) - headers['Content-Type'] = mime if mime + mime = ::Rack::Mime.mime_type(ext, DEFAULT_MIME) + headers['Content-Type'] = mime body = env['REQUEST_METHOD'] == 'HEAD' ? [] : FileBody.new(path, size) response = [ code, headers, body ] @@ -152,41 +151,9 @@ def expand_path(path, root = self.root) end end - begin - require 'rack/utils' - Utils = ::Rack::Utils - - if ''.respond_to?(:bytesize) # Ruby >= 1.9 - def Utils.bytesize(string); string.bytesize end - else - def Utils.bytesize(string); string.size end - end unless defined? Utils.bytesize - - require 'rack/mime' - rescue LoadError; end - - if defined? Utils.best_q_match - - def accepts_html?(env) - Utils.best_q_match(env['HTTP_ACCEPT'], %w[text/html]) - rescue - http_accept?(env, 'text/html') - end - - else - - def accepts_html?(env) - http_accept?(env, 'text/html') || http_accept?(env, '*/*') - end - + def accepts_html?(env) + ::Rack::Utils.best_q_match(env['HTTP_ACCEPT'], %w[text/html]) end - alias accept_html? accepts_html? # JRuby-Rack 1.1 compatibility - - def http_accept?(env, mime) - http_accept = env['HTTP_ACCEPT'].to_s - http_accept.empty? ? nil : !! http_accept.index(mime) - end - end end end diff --git a/src/main/ruby/jruby/rack/error_app/show_status.rb b/src/main/ruby/jruby/rack/error_app/show_status.rb index 218e87bd1..605d61a24 100644 --- a/src/main/ruby/jruby/rack/error_app/show_status.rb +++ b/src/main/ruby/jruby/rack/error_app/show_status.rb @@ -15,7 +15,7 @@ def initialize(app) def call(env) status, headers, body = @app.call(env) - headers = Utils::HeaderHash.new(headers) + headers = ::Rack::Utils::HeaderHash.new(headers) empty = headers['Content-Length'].to_i <= 0 detail = env['rack.showstatus.detail'] @@ -23,7 +23,7 @@ def call(env) if (status.to_i >= 400 && empty) || detail # required erb template variables (captured with binding) : request = req = ::Rack::Request.new(env); request && req # avoid un-used warning - message = Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s + message = ::Rack::Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s detail = detail.nil? ? message : detail # false for no detail body = @template.result(binding) @@ -36,7 +36,7 @@ def call(env) # @private def h(obj) - obj.is_a?(String) ? Utils.escape_html(obj) : Utils.escape_html(obj.inspect) + obj.is_a?(String) ? ::Rack::Utils.escape_html(obj) : ::Rack::Utils.escape_html(obj.inspect) end # :stopdoc: diff --git a/src/main/ruby/jruby/rack/errors.rb b/src/main/ruby/jruby/rack/errors.rb deleted file mode 100644 index ba2ec06eb..000000000 --- a/src/main/ruby/jruby/rack/errors.rb +++ /dev/null @@ -1,15 +0,0 @@ -#-- -# Copyright (c) 2010-2012 Engine Yard, Inc. -# Copyright (c) 2007-2009 Sun Microsystems, Inc. -# This source code is available under the MIT license. -# See the file LICENSE.txt for details. -#++ - -require 'jruby/rack/error_app' - -module JRuby - module Rack - # @deprecated backwards compatibility - Errors = ErrorApp - end -end \ No newline at end of file diff --git a/src/main/ruby/jruby/rack/rack_ext.rb b/src/main/ruby/jruby/rack/rack_ext.rb index f86993570..42cc298c5 100644 --- a/src/main/ruby/jruby/rack/rack_ext.rb +++ b/src/main/ruby/jruby/rack/rack_ext.rb @@ -9,7 +9,7 @@ require 'rack' rescue LoadError require 'vendor/rack' -end unless defined?(::Rack::VERSION) +end unless defined?(::Rack::RELEASE) # Servlet API friendly extensions to Rack # Allows for forwarding the request to another servlet/JSP diff --git a/src/main/ruby/jruby/rack/rails_booter.rb b/src/main/ruby/jruby/rack/rails_booter.rb index e4ba53013..e9d05cfd8 100644 --- a/src/main/ruby/jruby/rack/rails_booter.rb +++ b/src/main/ruby/jruby/rack/rails_booter.rb @@ -52,11 +52,6 @@ def set_relative_url_root end end - # @deprecated no longer used, replaced with {#run_boot_hooks} - def load_extensions - # no-op - end - # no rack etc extensions required here (called during boot!) # require 'jruby/rack/rails/extensions' on #load_environment diff --git a/src/main/ruby/rack/handler/servlet.rb b/src/main/ruby/rack/handler/servlet.rb index d0e5f8af6..22fbef26f 100644 --- a/src/main/ruby/rack/handler/servlet.rb +++ b/src/main/ruby/rack/handler/servlet.rb @@ -47,7 +47,5 @@ def self.response=(klass) end end - # @deprecated backwards compatibility - LazyEnv = Env = Servlet::DefaultEnv end end diff --git a/src/main/ruby/rack/handler/servlet/default_env.rb b/src/main/ruby/rack/handler/servlet/default_env.rb index bf6786be4..4c196a84a 100644 --- a/src/main/ruby/rack/handler/servlet/default_env.rb +++ b/src/main/ruby/rack/handler/servlet/default_env.rb @@ -231,7 +231,7 @@ def load_variable(env, key) def load_builtin(env, key) case key - when 'rack.version' then env[key] = ::Rack::VERSION + when 'rack.version' then env[key] = ::Rack::RELEASE when 'rack.multithread' then env[key] = true when 'rack.multiprocess' then env[key] = false when 'rack.run_once' then env[key] = false diff --git a/src/main/ruby/rack/handler/servlet/servlet_env.rb b/src/main/ruby/rack/handler/servlet/servlet_env.rb index efc469d4b..4fd358054 100644 --- a/src/main/ruby/rack/handler/servlet/servlet_env.rb +++ b/src/main/ruby/rack/handler/servlet/servlet_env.rb @@ -51,12 +51,6 @@ def load_env_key(env, key) # @private POST_PARAM_METHODS = [ 'POST', 'PUT', 'DELETE' ].freeze - if defined? Rack::Utils::ParameterTypeError - ParameterTypeError = Rack::Utils::ParameterTypeError - else - ParameterTypeError = TypeError - end - # Load parameters into the (Rack) env from the Servlet API. # using javax.servlet.http.HttpServletRequest#getParameterMap def load_parameters @@ -188,8 +182,8 @@ def parse_query_string end def mark_parameter_error(msg) - raise ParameterTypeError, msg - rescue ParameterTypeError => e + raise Rack::Utils::ParameterTypeError, msg + rescue Rack::Utils::ParameterTypeError => e @parameter_error = e end diff --git a/src/spec/ruby/cgi/session/java_servlet_store_spec.rb b/src/spec/ruby/cgi/session/java_servlet_store_spec.rb index 3eede5834..281a03c88 100644 --- a/src/spec/ruby/cgi/session/java_servlet_store_spec.rb +++ b/src/spec/ruby/cgi/session/java_servlet_store_spec.rb @@ -171,6 +171,6 @@ def hmac(key, data) expect(@session).to receive(:getLastAccessedTime).and_return 123 expect(@session).to receive(:setAttribute).with("__rails_secret", "abcrandom123") expect(@dbman.generate_digest("key")).to eq(hmac("abcrandom123", "key")) - end unless JRUBY_VERSION < '1.7.0' + end end end diff --git a/src/spec/ruby/jruby/rack/app_layout_spec.rb b/src/spec/ruby/jruby/rack/app_layout_spec.rb index d77e3a505..1404a2bc6 100644 --- a/src/spec/ruby/jruby/rack/app_layout_spec.rb +++ b/src/spec/ruby/jruby/rack/app_layout_spec.rb @@ -87,7 +87,12 @@ end -shared_examples "FileSystemLayout" do +describe JRuby::Rack::FileSystemLayout do + + let(:layout) do + allow(@rack_context).to receive(:getRealPath) { |path| path } + JRuby::Rack::FileSystemLayout.new(@rack_context) + end before do @original_work_dir = Dir.pwd @@ -99,6 +104,20 @@ Dir.chdir @original_work_dir end + it "sets app uri from an app.root context param" do + FileUtils.mkdir_p 'app/current' + expect(@rack_context).to receive(:getInitParameter).with("app.root").and_return "#{Dir.pwd}/app/current" + expect(layout.app_uri).to eq File.expand_path('app/current') + expect(layout.app_path).to eq "#{Dir.pwd}/app/current" + end + + it "sets app uri from a rails.root context param" do + base = File.join File.dirname(__FILE__), '../../rails' + expect(@rack_context).to receive(:getInitParameter).with("rails.root").and_return base + expect(layout.app_uri).to eq base + expect(layout.app_path).to eq File.expand_path(base) + end + it "sets app and public uri defaults based on a typical (Rails/Rack) app" do FileUtils.mkdir('./public') expect(layout.app_uri).to eq '.' @@ -181,47 +200,3 @@ end end - -describe JRuby::Rack::FileSystemLayout do - - let(:layout) do - allow(@rack_context).to receive(:getRealPath) { |path| path } - JRuby::Rack::FileSystemLayout.new(@rack_context) - end - - it_behaves_like "FileSystemLayout" - - it "sets app uri from an app.root context param" do - FileUtils.mkdir_p 'app/current' - expect(@rack_context).to receive(:getInitParameter).with("app.root").and_return "#{Dir.pwd}/app/current" - expect(layout.app_uri).to eq File.expand_path('app/current') - expect(layout.app_path).to eq "#{Dir.pwd}/app/current" - end - - describe "deprecated-constant" do - - it "still works" do - expect(JRuby::Rack::RailsFilesystemLayout).to be JRuby::Rack::FileSystemLayout - end - - end - -end - -describe JRuby::Rack::RailsFileSystemLayout do - - let(:layout) do - allow(@rack_context).to receive(:getRealPath) { |path| path } - JRuby::Rack::RailsFileSystemLayout.new(@rack_context) - end - - it_behaves_like "FileSystemLayout" - - it "sets app uri from a rails.root context param" do - base = File.join File.dirname(__FILE__), '../../rails' - expect(@rack_context).to receive(:getInitParameter).with("rails.root").and_return base - expect(layout.app_uri).to eq base - expect(layout.app_path).to eq File.expand_path(base) - end - -end if defined? JRuby::Rack::RailsFileSystemLayout diff --git a/src/spec/ruby/jruby/rack/booter_spec.rb b/src/spec/ruby/jruby/rack/booter_spec.rb index f179d87fb..cd7cc4df0 100644 --- a/src/spec/ruby/jruby/rack/booter_spec.rb +++ b/src/spec/ruby/jruby/rack/booter_spec.rb @@ -208,12 +208,7 @@ # at RUBY.change_working_directory(classpath:/jruby/rack/booter.rb:125) # at RUBY.boot!(classpath:/jruby/rack/booter.rb:105) # at RUBY.(root)(classpath:/jruby/rack/boot/rack.rb:10) - if RUBY_VERSION > '1.9' - app_dir = File.absolute_path Dir.pwd - else - app_dir = File.expand_path Dir.pwd - end - app_dir = "#{app_dir}/sample.war!/WEB-INF" + app_dir = "#{File.absolute_path Dir.pwd}/sample.war!/WEB-INF" allow(File).to receive(:directory?).with(app_dir).and_return true allow(booter).to receive(:layout).and_return layout = double('layout') allow(layout).to receive(:app_path).and_return app_dir @@ -264,7 +259,7 @@ # Booter.boot! run : should_not_eval_as_nil "ENV['RACK_ENV']" # rack got required : - should_not_eval_as_nil "defined?(Rack::VERSION)" + should_not_eval_as_nil "defined?(Rack::RELEASE)" should_not_eval_as_nil "defined?(Rack.release)" # check if it got loaded correctly : should_not_eval_as_nil "Rack::Request.new({}) rescue nil" @@ -313,7 +308,7 @@ should_not_eval_as_nil "ENV['RAILS_ENV']" # rack not yet required (let bundler decide which rack version to load) : - should_eval_as_nil "defined?(Rack::VERSION)" + should_eval_as_nil "defined?(Rack::RELEASE)" should_eval_as_nil "defined?(Rack.release)" end diff --git a/src/spec/ruby/jruby/rack/error_app_spec.rb b/src/spec/ruby/jruby/rack/error_app_spec.rb index 65302d959..72bb5732e 100644 --- a/src/spec/ruby/jruby/rack/error_app_spec.rb +++ b/src/spec/ruby/jruby/rack/error_app_spec.rb @@ -169,13 +169,3 @@ def in_tmpdir_with_files(files = {}) end end - -describe 'JRuby::Rack::Errors' do - - before(:all) { require 'jruby/rack/errors' } - - it "still works (backward compat)" do - expect(JRuby::Rack::Errors).to be JRuby::Rack::ErrorApp - end - -end diff --git a/src/spec/ruby/jruby/rack/integration_spec.rb b/src/spec/ruby/jruby/rack/integration_spec.rb index fcfbdecee..c885a3d89 100644 --- a/src/spec/ruby/jruby/rack/integration_spec.rb +++ b/src/spec/ruby/jruby/rack/integration_spec.rb @@ -32,7 +32,7 @@ rack_factory = @servlet_context.getAttribute("rack.factory") expect(rack_factory).to be_a(RackApplicationFactory) expect(rack_factory).to be_a(SharedRackApplicationFactory) - expect(rack_factory.realFactory).to be_a(DefaultRackApplicationFactory) + expect(rack_factory.delegate).to be_a(DefaultRackApplicationFactory) expect(@servlet_context.getAttribute("rack.context")).to be_a(RackContext) expect(@servlet_context.getAttribute("rack.context")).to be_a(ServletRackContext) @@ -98,7 +98,7 @@ rack_factory = servlet_context.getAttribute("rack.factory") expect(rack_factory).to be_a(RackApplicationFactory) expect(rack_factory).to be_a(PoolingRackApplicationFactory) - expect(rack_factory.realFactory).to be_a(RailsRackApplicationFactory) + expect(rack_factory.delegate).to be_a(RailsRackApplicationFactory) expect(servlet_context.getAttribute("rack.context")).to be_a(RackContext) expect(servlet_context.getAttribute("rack.context")).to be_a(ServletRackContext) @@ -113,7 +113,7 @@ rack_factory = servlet_context.getAttribute("rack.factory") expect(rack_factory).to be_a(RackApplicationFactory) expect(rack_factory).to be_a(SharedRackApplicationFactory) - expect(rack_factory.realFactory).to be_a(RailsRackApplicationFactory) + expect(rack_factory.delegate).to be_a(RailsRackApplicationFactory) expect(rack_factory.getApplication).to be_a(DefaultRackApplication) end @@ -127,7 +127,7 @@ rack_factory = servlet_context.getAttribute("rack.factory") expect(rack_factory).to be_a(RackApplicationFactory) expect(rack_factory).to be_a(SharedRackApplicationFactory) - expect(rack_factory.realFactory).to be_a(RailsRackApplicationFactory) + expect(rack_factory.delegate).to be_a(RailsRackApplicationFactory) end end diff --git a/src/spec/ruby/rack/application_spec.rb b/src/spec/ruby/rack/application_spec.rb index 28311e4ac..30dcd43a3 100644 --- a/src/spec/ruby/rack/application_spec.rb +++ b/src/spec/ruby/rack/application_spec.rb @@ -310,11 +310,11 @@ def newRuntime() it "does not require 'rack' (until booter is called)" do @runtime = app_factory.newRuntime - should_eval_as_nil "defined?(::Rack::VERSION)" + should_eval_as_nil "defined?(::Rack::RELEASE)" end it "loads specified version of rack via bundler", :lib => :stub do - gem_install_unless_installed 'rack', '1.3.6' + gem_install_unless_installed 'rack', '2.2.0' set_config 'jruby.runtime.env', 'false' script = "# encoding: UTF-8\n" + @@ -324,7 +324,7 @@ def newRuntime() @runtime = app_factory.newRuntime file = Tempfile.new('Gemfile') - file << "source 'https://rubygems.org'\n gem 'rack', '1.3.6'" + file << "source 'https://rubygems.org'\n gem 'rack', '2.2.0'" file.flush @runtime.evalScriptlet "ENV['BUNDLE_GEMFILE'] = #{file.path.inspect}" @runtime.evalScriptlet "ENV['GEM_HOME'] = #{ENV['GEM_HOME'].inspect}" @@ -334,8 +334,8 @@ def newRuntime() @runtime.evalScriptlet "require 'rack'" should_not_eval_as_nil "defined?(Bundler)" - should_eval_as_eql_to "Rack.release if defined? Rack.release", '1.3' - should_eval_as_eql_to "Gem.loaded_specs['rack'].version.to_s", '1.3.6' + should_eval_as_eql_to "Rack.release", '2.2.0' + should_eval_as_eql_to "Gem.loaded_specs['rack'].version.to_s", '2.2.0' end it "initializes the $servlet_context global variable" do @@ -370,17 +370,6 @@ def newRuntime() should_eval_as_eql_to "ENV['RUBYOPT']", '-U' end - it "keeps RUBYOPT by default with empty ENV (backwards compat)" do - set_config 'jruby.rack.ignore.env', 'true' - - app_factory = app_factory_with_RUBYOPT '-ryaml' - @runtime = app_factory.newRuntime - should_eval_as_nil "ENV['HOME']" - should_eval_as_eql_to "ENV['RUBYOPT']", '-ryaml' # changed with jruby.runtime.env - # it was processed - feature got required : - should_eval_as_eql_to "require 'yaml'", false - end - it "does a complete ENV clean including RUBYOPT" do set_config 'jruby.runtime.env', 'false' # set_config 'jruby.runtime.env.rubyopt', 'false' diff --git a/src/spec/ruby/rack/config_spec.rb b/src/spec/ruby/rack/config_spec.rb index 45b136950..452165b51 100644 --- a/src/spec/ruby/rack/config_spec.rb +++ b/src/spec/ruby/rack/config_spec.rb @@ -145,25 +145,19 @@ it "defaults to nil (runtime should keep default from System env)" do expect(@servlet_context).to receive(:getInitParameter). - with("jruby.runtime.environment").and_return nil + with("jruby.runtime.env").and_return nil expect(config.getRuntimeEnvironment).to be nil end it "is empty when set to false" do expect(@servlet_context).to receive(:getInitParameter). - with("jruby.runtime.environment").and_return 'false' - expect_empty_env config.getRuntimeEnvironment - end - - it "setting jruby.rack.ignore.env returns empty env (backwards compat)" do - expect(@servlet_context).to receive(:getInitParameter). - with("jruby.rack.ignore.env").and_return 'true' + with("jruby.runtime.env").and_return 'false' expect_empty_env config.getRuntimeEnvironment end it "custom env hash" do expect(@servlet_context).to receive(:getInitParameter). - with("jruby.runtime.environment"). + with("jruby.runtime.env"). and_return "PATH=~/bin,HOME=/home/kares\nNAMES=Jozko, Ferko,Janko,GEM_HOME=/opt/rvm/gems\n" expect(config.getRuntimeEnvironment).to eql({ "PATH" => "~/bin", "HOME" => "/home/kares", "NAMES" => "Jozko, Ferko,Janko", "GEM_HOME" => "/opt/rvm/gems" diff --git a/src/spec/ruby/rack/handler/servlet_spec.rb b/src/spec/ruby/rack/handler/servlet_spec.rb index c05756162..186278d66 100644 --- a/src/spec/ruby/rack/handler/servlet_spec.rb +++ b/src/spec/ruby/rack/handler/servlet_spec.rb @@ -44,7 +44,7 @@ def _env it "creates a hash with the Rack variables in it" do hash = servlet.create_env(@servlet_env) - expect(hash['rack.version']).to eq Rack::VERSION + expect(hash['rack.version']).to eq Rack::RELEASE expect(hash['rack.multithread']).to eq true expect(hash['rack.multiprocess']).to eq false expect(hash['rack.run_once']).to eq false @@ -204,7 +204,7 @@ def _env end env = servlet.create_env @servlet_env - expect(env["rack.version"]).to eq Rack::VERSION + expect(env["rack.version"]).to eq Rack::RELEASE expect(env["CONTENT_TYPE"]).to eq "text/html" expect(env["HTTP_HOST"]).to eq "serverhost" expect(env["HTTP_ACCEPT"]).to eq "text/*" @@ -473,16 +473,9 @@ def getAttributeNames env = servlet.create_env(@servlet_env) rack_request = Rack::Request.new(env) - # Rack::Utils::ParameterTypeError (< TypeError) since 1.6.0 - if Rack::Utils.const_defined? :ParameterTypeError - error = Rack::Utils::ParameterTypeError - else - error = TypeError - end - - expect { rack_request.GET }.to raise_error(error, "expected Hash (got Array) for param `foo'") + expect { rack_request.GET }.to raise_error(Rack::Utils::ParameterTypeError, "expected Hash (got Array) for param `foo'") expect(rack_request.POST).to eq({}) - expect { rack_request.params }.to raise_error(error, "expected Hash (got Array) for param `foo'") + expect { rack_request.params }.to raise_error(Rack::Utils::ParameterTypeError, "expected Hash (got Array) for param `foo'") expect(rack_request.query_string).to eq 'foo[]=0&foo[bar]=1' end @@ -891,22 +884,7 @@ def servlet.create_env(servlet_env) env = servlet.create_env @servlet_env expect(env['java.servlet_context']).to_not be nil - if servlet_30? - expect(env['java.servlet_context']).to be @servlet_context - else - expect(env['java.servlet_context']).to be @rack_context - - # HACK to emulate Servlet API 3.0 MockHttpServletRequest has getServletContext : - env = Rack::Handler::Servlet::DefaultEnv.new(@servlet_request).to_hash - - expect(env['java.servlet_context']).to_not be nil - expect(env['java.servlet_context']).to be @servlet_context - begin - expect(env['java.servlet_context']).to eq @servlet_context - rescue NoMethodError - expect((env['java.servlet_context'] == @servlet_context)).to eq true - end - end + expect(env['java.servlet_context']).to be @servlet_context end it "returns the servlet request when queried with java.servlet_request" do diff --git a/src/spec/ruby/rack/input_spec.rb b/src/spec/ruby/rack/input_spec.rb index c132cbab1..8e94a32fc 100644 --- a/src/spec/ruby/rack/input_spec.rb +++ b/src/spec/ruby/rack/input_spec.rb @@ -208,9 +208,4 @@ def rewindable_input(buffer_size = nil, max_buffer_size = nil) it_should_behave_like_rack_input end - - it "is exposed as JRuby::RackInput (backwards compat)" do - expect(JRuby::RackInput).to be JRuby::Rack::Input - end - end diff --git a/src/spec/ruby/rack/servlet/response_capture_spec.rb b/src/spec/ruby/rack/servlet/response_capture_spec.rb index eef2b6b47..4bee4a700 100644 --- a/src/spec/ruby/rack/servlet/response_capture_spec.rb +++ b/src/spec/ruby/rack/servlet/response_capture_spec.rb @@ -76,8 +76,6 @@ end it "is considered handled when more than Allow header is added with OPTIONS" do - pending "need Servlet API 3.0" unless servlet_30? - servlet_request.method = 'OPTIONS' response_capture.setIntHeader "Answer", 42 @@ -87,8 +85,6 @@ end it "is considered handled when header is added" do - pending "need Servlet API 3.0" unless servlet_30? - servlet_request.method = 'OPTIONS' response_capture.addHeader "Hello", "World" diff --git a/src/spec/ruby/rack/util_spec.rb b/src/spec/ruby/rack/util_spec.rb index 778d205aa..b239cfaa8 100644 --- a/src/spec/ruby/rack/util_spec.rb +++ b/src/spec/ruby/rack/util_spec.rb @@ -31,10 +31,10 @@ it "reads magic comment 2" do code = "# encoding: UTF-8 \n" + "# comment\n" + - "# rack.version: 1.3.6 \n" + + "# rack.version: 2.2.0 \n" + "exit(0)\n'42'" string = IOHelpers.rubyMagicCommentValue(code, "rack.version:") - expect(string).to eql "1.3.6" + expect(string).to eql "2.2.0" end it "works when reading an empty/null string" do diff --git a/src/spec/ruby/spec_helper.rb b/src/spec/ruby/spec_helper.rb index 56d17736c..d8c354496 100644 --- a/src/spec/ruby/spec_helper.rb +++ b/src/spec/ruby/spec_helper.rb @@ -54,48 +54,14 @@ def silence_warnings(&block) JRuby::Rack::Helpers.silence_warnings(&block) end - @@servlet_30 = nil - - def servlet_30? - return @@servlet_30 unless @@servlet_30.nil? - @@servlet_30 = !!(Java::javax.servlet.AsyncContext rescue nil) - end - - private :servlet_30? - - def rack_release_at_least?(at_least = nil) - require 'rack'; - at_least ? Rack.release >= at_least : true - end - - private :rack_release_at_least? - def raise_logger(level = 'WARN') org.jruby.rack.logging.RaiseLogger.new(level, JRuby.runtime.out) end def gem_install_unless_installed(name, version) - found = nil - begin - if Gem::Specification.respond_to? :find_all - all = Gem::Specification.find_all - found = all.find do |spec| - spec.name == name && spec.version.to_s == version - end - elsif Gem::Specification.respond_to? :find_by_name - found = Gem::Specification.find_by_name name, version - else - raise Gem::LoadError unless Gem.available? name, version - end - rescue Gem::LoadError - found = false - end - # NOTE: won't ever be found in RubyGems >= 2.3 likely due Bundler - unless found - require 'rubygems/dependency_installer' - installer = Gem::DependencyInstaller.new - installer.install name, version - end + require 'rubygems/dependency_installer' + installer = Gem::DependencyInstaller.new + installer.install name, version end ExpectationNotMetError = RSpec::Expectations::ExpectationNotMetError