early attempt to fix jruby

This commit is contained in:
Thomas Reynolds 2011-12-20 17:03:36 -08:00
parent d553ee653b
commit c0ba3e2946
6 changed files with 52 additions and 34 deletions

View file

@ -2,4 +2,5 @@ rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- jruby
script: "bundle exec rake test"

View file

@ -1,9 +1,14 @@
require "rbconfig"
# Setup our load paths
libdir = File.dirname(__FILE__)
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
# Top-level Middleman object
module Middleman
WINDOWS = !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i)
JRUBY = !!(RbConfig::CONFIG["RUBY_INSTALL_NAME"] =~ /^jruby/i)
# Auto-load modules on-demand
autoload :Base, "middleman/base"
autoload :Cache, "middleman/cache"
@ -225,7 +230,13 @@ module Middleman
app_class = options[:app] ||= ::Middleman.server.inst
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.start

View file

@ -1,5 +1,4 @@
require 'pathname'
require 'rbconfig'
require "sprockets"
module Middleman::CoreExtensions::Sprockets

View file

@ -6,8 +6,7 @@ require "guard/guard"
require "net/http"
# Support forking on Windows
require "rbconfig"
require "win32/process" if RbConfig::CONFIG['host_os'].downcase =~ %r{mingw}
require "win32/process" if Middleman::WINDOWS
module Middleman::Guard
def self.start(options={})
@ -42,11 +41,25 @@ module Guard
def initialize(watchers = [], options = {})
super
@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
# Start Middleman in a fork
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
is_logging = @options.has_key?(:debug) && (@options[:debug] == "true")
app = ::Middleman.server.inst do
@ -54,25 +67,25 @@ module Guard
set :logging, is_logging
end
require "thin"
::Thin::Logging.silent = !is_logging
app_rack = app.class.to_rack_app
opts = @options.dup
opts[:app] = app_rack
opts[:logging] = is_logging
puts "== The Middleman is standing watch on port #{opts[:port]||4567}"
::Middleman.start_server(opts)
end
end
# Stop the forked Middleman
def stop
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
@server_job = nil
end
end
# Simply stop, then start
def reload
@ -116,11 +129,9 @@ module Guard
uri = URI.parse("http://#{@options[:host]}:#{@options[:port]}/__middleman__")
Net::HTTP.post_form(uri, {}.merge(params))
end
end
end
# Trap the interupt signal and shut down Guard (and thus the server) smoothly
trap(:INT) do
::Guard.stop
exit
def kill_command
::Middleman::WINDOWS ? 1 : :INT
end
end
end

View file

@ -1,6 +1,4 @@
# -*- encoding: utf-8 -*-
require "rbconfig"
$:.push File.expand_path("../lib", __FILE__)
require "middleman/version"

View file

@ -1,6 +1,4 @@
# -*- encoding: utf-8 -*-
require "rbconfig"
$:.push File.expand_path("../lib", __FILE__)
require "middleman/version"