early attempt to fix jruby
This commit is contained in:
parent
d553ee653b
commit
c0ba3e2946
|
@ -2,4 +2,5 @@ rvm:
|
||||||
- 1.8.7
|
- 1.8.7
|
||||||
- 1.9.2
|
- 1.9.2
|
||||||
- 1.9.3
|
- 1.9.3
|
||||||
|
- jruby
|
||||||
script: "bundle exec rake test"
|
script: "bundle exec rake test"
|
|
@ -1,9 +1,14 @@
|
||||||
|
require "rbconfig"
|
||||||
|
|
||||||
# Setup our load paths
|
# Setup our load paths
|
||||||
libdir = File.dirname(__FILE__)
|
libdir = File.dirname(__FILE__)
|
||||||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||||
|
|
||||||
# Top-level Middleman object
|
# Top-level Middleman object
|
||||||
module Middleman
|
module Middleman
|
||||||
|
WINDOWS = !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i)
|
||||||
|
JRUBY = !!(RbConfig::CONFIG["RUBY_INSTALL_NAME"] =~ /^jruby/i)
|
||||||
|
|
||||||
# Auto-load modules on-demand
|
# Auto-load modules on-demand
|
||||||
autoload :Base, "middleman/base"
|
autoload :Base, "middleman/base"
|
||||||
autoload :Cache, "middleman/cache"
|
autoload :Cache, "middleman/cache"
|
||||||
|
@ -225,7 +230,13 @@ module Middleman
|
||||||
|
|
||||||
app_class = options[:app] ||= ::Middleman.server.inst
|
app_class = options[:app] ||= ::Middleman.server.inst
|
||||||
opts[:app] = app_class
|
opts[:app] = app_class
|
||||||
opts[:server] = 'thin'
|
opts[:server] = if ::Middleman::JRUBY
|
||||||
|
'webrick' # Maybe Kirk?
|
||||||
|
else
|
||||||
|
require "thin"
|
||||||
|
::Thin::Logging.silent = !options[:is_logging]
|
||||||
|
'thin'
|
||||||
|
end
|
||||||
|
|
||||||
server = ::Rack::Server.new(opts)
|
server = ::Rack::Server.new(opts)
|
||||||
server.start
|
server.start
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
require 'rbconfig'
|
|
||||||
require "sprockets"
|
require "sprockets"
|
||||||
|
|
||||||
module Middleman::CoreExtensions::Sprockets
|
module Middleman::CoreExtensions::Sprockets
|
||||||
|
|
|
@ -6,8 +6,7 @@ require "guard/guard"
|
||||||
require "net/http"
|
require "net/http"
|
||||||
|
|
||||||
# Support forking on Windows
|
# Support forking on Windows
|
||||||
require "rbconfig"
|
require "win32/process" if Middleman::WINDOWS
|
||||||
require "win32/process" if RbConfig::CONFIG['host_os'].downcase =~ %r{mingw}
|
|
||||||
|
|
||||||
module Middleman::Guard
|
module Middleman::Guard
|
||||||
def self.start(options={})
|
def self.start(options={})
|
||||||
|
@ -42,11 +41,25 @@ module Guard
|
||||||
def initialize(watchers = [], options = {})
|
def initialize(watchers = [], options = {})
|
||||||
super
|
super
|
||||||
@options = options
|
@options = options
|
||||||
|
|
||||||
|
# Trap the interupt signal and shut down Guard (and thus the server) smoothly
|
||||||
|
trap(kill_command) do
|
||||||
|
::Guard.stop
|
||||||
|
exit!(0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Start Middleman in a fork
|
# Start Middleman in a fork
|
||||||
def start
|
def start
|
||||||
@server_job = fork do
|
if ::Middleman::JRUBY
|
||||||
|
thread = Thread.new { bootup }
|
||||||
|
thread.join
|
||||||
|
else
|
||||||
|
@server_job = fork { bootup }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def bootup
|
||||||
env = (@options[:environment] || "development").to_sym
|
env = (@options[:environment] || "development").to_sym
|
||||||
is_logging = @options.has_key?(:debug) && (@options[:debug] == "true")
|
is_logging = @options.has_key?(:debug) && (@options[:debug] == "true")
|
||||||
app = ::Middleman.server.inst do
|
app = ::Middleman.server.inst do
|
||||||
|
@ -54,25 +67,25 @@ module Guard
|
||||||
set :logging, is_logging
|
set :logging, is_logging
|
||||||
end
|
end
|
||||||
|
|
||||||
require "thin"
|
|
||||||
::Thin::Logging.silent = !is_logging
|
|
||||||
|
|
||||||
app_rack = app.class.to_rack_app
|
app_rack = app.class.to_rack_app
|
||||||
|
|
||||||
opts = @options.dup
|
opts = @options.dup
|
||||||
opts[:app] = app_rack
|
opts[:app] = app_rack
|
||||||
|
opts[:logging] = is_logging
|
||||||
puts "== The Middleman is standing watch on port #{opts[:port]||4567}"
|
puts "== The Middleman is standing watch on port #{opts[:port]||4567}"
|
||||||
::Middleman.start_server(opts)
|
::Middleman.start_server(opts)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Stop the forked Middleman
|
# Stop the forked Middleman
|
||||||
def stop
|
def stop
|
||||||
puts "== The Middleman is shutting down"
|
puts "== The Middleman is shutting down"
|
||||||
Process.kill("KILL", @server_job)
|
if ::Middleman::JRUBY
|
||||||
|
else
|
||||||
|
Process.kill(kill_command, @server_job)
|
||||||
Process.wait @server_job
|
Process.wait @server_job
|
||||||
@server_job = nil
|
@server_job = nil
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Simply stop, then start
|
# Simply stop, then start
|
||||||
def reload
|
def reload
|
||||||
|
@ -116,11 +129,9 @@ module Guard
|
||||||
uri = URI.parse("http://#{@options[:host]}:#{@options[:port]}/__middleman__")
|
uri = URI.parse("http://#{@options[:host]}:#{@options[:port]}/__middleman__")
|
||||||
Net::HTTP.post_form(uri, {}.merge(params))
|
Net::HTTP.post_form(uri, {}.merge(params))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def kill_command
|
||||||
|
::Middleman::WINDOWS ? 1 : :INT
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Trap the interupt signal and shut down Guard (and thus the server) smoothly
|
|
||||||
trap(:INT) do
|
|
||||||
::Guard.stop
|
|
||||||
exit
|
|
||||||
end
|
|
|
@ -1,6 +1,4 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
require "rbconfig"
|
|
||||||
|
|
||||||
$:.push File.expand_path("../lib", __FILE__)
|
$:.push File.expand_path("../lib", __FILE__)
|
||||||
require "middleman/version"
|
require "middleman/version"
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
require "rbconfig"
|
|
||||||
|
|
||||||
$:.push File.expand_path("../lib", __FILE__)
|
$:.push File.expand_path("../lib", __FILE__)
|
||||||
require "middleman/version"
|
require "middleman/version"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue