Skip to content

Commit

Permalink
updated requirements and refactored the cmd line config to a shared f…
Browse files Browse the repository at this point in the history
…ile since almost all of it was duplicated
  • Loading branch information
Jeffrey Damick committed Jul 22, 2008
1 parent 773445c commit 28370f9
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 128 deletions.
54 changes: 54 additions & 0 deletions Manifest.txt
@@ -1,3 +1,52 @@
.git/COMMIT_EDITMSG
.git/FETCH_HEAD
.git/HEAD
.git/ORIG_HEAD
.git/config
.git/description
.git/hooks/applypatch-msg
.git/hooks/commit-msg
.git/hooks/post-commit
.git/hooks/post-receive
.git/hooks/post-update
.git/hooks/pre-applypatch
.git/hooks/pre-commit
.git/hooks/pre-rebase
.git/hooks/update
.git/index
.git/info/exclude
.git/logs/HEAD
.git/logs/refs/heads/master
.git/logs/refs/heads/origin
.git/logs/refs/remotes/origin/master
.git/objects/50/487ba8c75733f0102b36306795e451119e88f0
.git/objects/77/3445ccefaef5e9cf15b1bcd10de4a8a92861bf
.git/objects/b3/779bc386170a14655093ff09d7c19a876c14dc
.git/objects/c7/671fca5b631a5f6661826de6c1ed20c338e803
.git/objects/ca/9417af66ff8effef57c3586444631a05c1e765
.git/objects/cc/bdc16ba7069c9b80363a0bda97da8215cee9c3
.git/objects/d9/be4a87fa40cc4e30079151068cb9cf47ad1524
.git/objects/de/a816e5f3c9383237642ad787b0837b613e0aef
.git/objects/df/7d3e6e264911a0bcee7dd7e607436cc9c4ad97
.git/objects/e5/3e28ad6c6ab556736f43240cd7eae0ade788b0
.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
.git/objects/ec/ffeae35b1202df4bc57c9d47c0938d52f07138
.git/objects/f5/9bc4e9c2edba364fd1a2c1cf735934c79f8850
.git/objects/f8/cb2593e1960f6c17f63096627065930dc51623
.git/objects/fa/c46c6d56eec47f4ef47e20fe88263f2e3867c8
.git/objects/pack/pack-dd95688d89b3598e233e32dd5e7a629b0c19e0bd.idx
.git/objects/pack/pack-dd95688d89b3598e233e32dd5e7a629b0c19e0bd.keep
.git/objects/pack/pack-dd95688d89b3598e233e32dd5e7a629b0c19e0bd.pack
.git/refs/heads/master
.git/refs/heads/origin
.git/refs/remotes/origin/HEAD
.git/refs/remotes/origin/master
.git/refs/tags/running_simple_rails_apps
.git/refs/tags/v0.2
.git/refs/tags/v0.3
.git/refs/tags/v0.4
.git/refs/tags/v0.5
.gitignore
History.txt
Licenses.txt
Manifest.txt
Expand All @@ -16,13 +65,16 @@ lib/jetty_rails.rb
lib/jetty_rails/adapters/abstract_adapter.rb
lib/jetty_rails/adapters/merb_adapter.rb
lib/jetty_rails/adapters/rails_adapter.rb
lib/jetty_rails/config/command_line_config.rb
lib/jetty_rails/config/rdoc_fix.rb
lib/jetty_rails/handler/delegate_on_errors_handler.rb
lib/jetty_rails/handler/public_directory_handler.rb
lib/jetty_rails/handler/web_app_handler.rb
lib/jetty_rails/jars.rb
lib/jetty_rails/runner.rb
lib/jetty_rails/server.rb
lib/jetty_rails/version.rb
lib/jetty_rails/warbler_reader.rb
lib/jruby-rack-0.9.jar
lib/servlet-api-2.5-6.1.9.jar
script/console
Expand All @@ -44,6 +96,8 @@ tasks/deployment.rake
tasks/environment.rake
tasks/rspec.rake
tasks/website.rake
test.rb
website/index.html
website/index.txt
website/javascripts/rounded_corners_lite.inc.js
website/stylesheets/screen.css
Expand Down
64 changes: 2 additions & 62 deletions bin/jetty_merb
Expand Up @@ -26,68 +26,8 @@
# BASEDIR (optional): directory to be run (default: current).

require "java"
$LOAD_PATH << "#{File.dirname(__FILE__)}/../lib"
require "jetty_rails"
require 'getoptlong'
require 'rdoc/usage'

# fix to work with rubygems (use current file instead of main)
def RDoc.usage_no_exit(*args)
comment = File.open(__FILE__) do |file|
find_comment(file)
end

comment = comment.gsub(/^\s*#/, '')

markup = SM::SimpleMarkup.new
flow_convertor = SM::ToFlow.new

flow = markup.convert(comment, flow_convertor)

format = "plain"

unless args.empty?
flow = extract_sections(flow, args)
end

options = RI::Options.instance
if args = ENV["RI"]
options.parse(args.split)
end
formatter = options.formatter.new(options, "")
formatter.display_flow(flow)
end

opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--context-path', '-u', GetoptLong::REQUIRED_ARGUMENT ],
[ '--port', '-p', GetoptLong::REQUIRED_ARGUMENT ],
[ '--environment', '-e', GetoptLong::REQUIRED_ARGUMENT ],
[ '--config', '-c', GetoptLong::OPTIONAL_ARGUMENT ]
)

config = {
:base => Dir.pwd,
:port => 4000,
:adapter => :merb
}

opts.each do |opt, arg|
case opt
when '--help'
RDoc::usage
when '--context-path'
config[:context_path] = arg
when '--port'
config[:port] = arg.to_i
when '--environment'
config[:environment] = arg
when '--config'
arg = "#{File.join(Dir.pwd, 'jetty_merb.yml')}" if arg.nil? || arg == ""
config.merge!(YAML.load_file(arg))
end
end

config[:base] = ARGV.shift unless ARGV.empty?

runner = JettyRails::Runner.new(config)
runner = JettyRails::Runner.new(CommandLineConfig.get_config(:merb))
runner.start
64 changes: 1 addition & 63 deletions bin/jetty_rails
Expand Up @@ -26,70 +26,8 @@
# BASEDIR (optional): directory to be run (default: current).

require "java"

$LOAD_PATH << "#{File.dirname(__FILE__)}/../lib"

require "jetty_rails"
require 'getoptlong'
require 'rdoc/usage'

# fix to work with rubygems (use current file instead of main)
def RDoc.usage_no_exit(*args)
comment = File.open(__FILE__) do |file|
find_comment(file)
end

comment = comment.gsub(/^\s*#/, '')

markup = SM::SimpleMarkup.new
flow_convertor = SM::ToFlow.new

flow = markup.convert(comment, flow_convertor)

format = "plain"

unless args.empty?
flow = extract_sections(flow, args)
end

options = RI::Options.instance
if args = ENV["RI"]
options.parse(args.split)
end
formatter = options.formatter.new(options, "")
formatter.display_flow(flow)
end

opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--context-path', '-u', GetoptLong::REQUIRED_ARGUMENT ],
[ '--port', '-p', GetoptLong::REQUIRED_ARGUMENT ],
[ '--environment', '-e', GetoptLong::REQUIRED_ARGUMENT ],
[ '--config', '-c', GetoptLong::OPTIONAL_ARGUMENT ]
)

config = {
:base => Dir.pwd,
:port => 3000,
:adapter => :rails
}

opts.each do |opt, arg|
case opt
when '--help'
RDoc::usage
when '--context-path'
config[:context_path] = arg
when '--port'
config[:port] = arg.to_i
when '--environment'
config[:environment] = arg
when '--config'
arg = "#{File.join(Dir.pwd, 'config', 'jetty_rails.yml')}" if arg.nil? || arg == ""
config.merge!(YAML.load_file(arg))
end
end

config[:base] = ARGV.shift unless ARGV.empty?
runner = JettyRails::Runner.new(config)
runner = JettyRails::Runner.new(CommandLineConfig.get_config(:rails))
runner.start
3 changes: 1 addition & 2 deletions config/hoe.rb
Expand Up @@ -8,8 +8,7 @@
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
EXTRA_DEPENDENCIES = [
['activesupport', '>= 1.3.1'],
['daemons', '>= 1.0.10']
['activesupport', '>= 1.3.1']
] # An array of rubygem dependencies [name, version]

@config_file = "~/.rubyforge/user-config.yml"
Expand Down
1 change: 1 addition & 0 deletions lib/jetty_rails.rb
Expand Up @@ -13,6 +13,7 @@
require "jetty_rails/handler/delegate_on_errors_handler"
require "jetty_rails/handler/public_directory_handler"
require "jetty_rails/handler/web_app_handler"
require "jetty_rails/config/command_line_config"

module JettyRails
JETTY_RAILS_HOME = File.dirname(__FILE__) + "/.." unless defined?(JETTY_RAILS_HOME)
Expand Down
59 changes: 59 additions & 0 deletions lib/jetty_rails/config/command_line_config.rb
@@ -0,0 +1,59 @@
require 'getoptlong'
require 'jetty_rails/config/rdoc_fix'


class CommandLineConfig

def self.default_config()
@config ||= {
:rails => {
:daemonize => false,
:base => Dir.pwd,
:port => 3000,
:config_file => "#{File.join(Dir.pwd, 'config', 'jetty_rails.yml')}",
:adapter => :rails
},
:merb => {
:daemonize => false,
:base => Dir.pwd,
:port => 4000,
:config_file => "#{File.join(Dir.pwd, 'jetty_merb.yml')}",
:adapter => :merb
}
}
end

def self.get_config(default_adapter = :rails)
config = default_config[default_adapter]

opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--context-path', '-u', GetoptLong::REQUIRED_ARGUMENT ],
[ '--port', '-p', GetoptLong::REQUIRED_ARGUMENT ],
[ '--environment', '-e', GetoptLong::REQUIRED_ARGUMENT ],
[ '--config', '-c', GetoptLong::OPTIONAL_ARGUMENT ]
)

opts.each do |opt, arg|
case opt
when '--help'
RDoc::usage
when '--context-path'
config[:context_path] = arg
when '--port'
config[:port] = arg.to_i
when '--environment'
config[:environment] = arg
when '--config'
config[:config_file] = arg if !arg.nil? && arg != ""
config.merge!(YAML.load_file(config[:config_file]))
end
end

config[:base] = ARGV.shift unless ARGV.empty?
config
end

end


28 changes: 28 additions & 0 deletions lib/jetty_rails/config/rdoc_fix.rb
@@ -0,0 +1,28 @@
require 'rdoc/usage'

# fix to work with rubygems (use current file instead of main)
def RDoc.usage_no_exit(*args)
comment = File.open(File.join(File.dirname(__FILE__), %w(.. .. .. bin), File.basename($0))) do |file|
find_comment(file)
end

comment = comment.gsub(/^\s*#/, '')

markup = SM::SimpleMarkup.new
flow_convertor = SM::ToFlow.new

flow = markup.convert(comment, flow_convertor)

format = "plain"

unless args.empty?
flow = extract_sections(flow, args)
end

options = RI::Options.instance
if args = ENV["RI"]
options.parse(args.split)
end
formatter = options.formatter.new(options, "")
formatter.display_flow(flow)
end
6 changes: 5 additions & 1 deletion lib/jetty_rails/runner.rb
@@ -1,4 +1,5 @@
require "jruby"
require 'daemons'

module JettyRails

Expand All @@ -8,6 +9,7 @@ class Runner
def initialize(config = {})
@servers = {}
config.symbolize_keys!
@daemonize = config[:daemonize] || false
if config[:servers].nil?
add_server(config)
else
Expand All @@ -19,7 +21,7 @@ def initialize(config = {})
end
end

read_warble_config if File.exists?("#{config[:base]}/config/warble.rb")
#read_warble_config if File.exists?("#{config[:base]}/config/warble.rb")
end

def add_server(config = {})
Expand All @@ -28,6 +30,8 @@ def add_server(config = {})
end

def start
Daemons.daemonize if @daemonize

server_threads = ThreadGroup.new
@servers.each do |base, server|
log("starting #{base}")
Expand Down

0 comments on commit 28370f9

Please sign in to comment.