forked from bernerdschaefer/akephalos
/
akephalos
executable file
·88 lines (73 loc) · 2.59 KB
/
akephalos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env ruby
# vim:set filetype=ruby:
require "pathname"
require "optparse"
options = { :interactive => false }
parser = OptionParser.new do |opts|
opts.banner = "Usage: akephalos [--interactive, --use-htmlunit-snapshot] | [--server] <port>"
opts.on("-s", "--server", "Run in server mode (default)")
opts.on("-i", "--interactive", "Run in interactive mode") { options[:interactive] = true }
opts.on("--use-htmlunit-snapshot", "Use the snapshot of htmlunit") { options[:use_htmlunit_snapshot] = true }
opts.on_tail("-h", "--help", "Show this message") { puts opts; exit }
end
parser.parse!
root = Pathname(__FILE__).expand_path.dirname.parent
lib = root + 'lib'
src = root + 'src'
case
when options[:use_htmlunit_snapshot]
require "fileutils"
FileUtils.mkdir_p("vendor/htmlunit")
Dir["vendor/htmlunit/*.jar"].each { |jar| File.unlink(jar) }
Dir.chdir("vendor") do
$stdout.print "Downloading latest snapshot... "
$stdout.flush
%x[curl -O http://build.canoo.com/htmlunit/artifacts/htmlunit-2.9-SNAPSHOT-with-dependencies.zip &> /dev/null]
puts "done"
$stdout.print "Extracting dependencies... "
$stdout.flush
%x[unzip -j -d htmlunit htmlunit-2.9-SNAPSHOT-with-dependencies.zip htmlunit-2.9-SNAPSHOT/lib htmlunit-2.9-SNAPSHOT/lib/* &> /dev/null]
puts "done"
File.unlink "htmlunit-2.9-SNAPSHOT-with-dependencies.zip"
end
$stdout.puts "="*40
$stdout.puts "The latest HtmlUnit snapshot has been extracted to vendor/htmlunit!"
when options[:interactive]
$:.unshift('vendor', lib, src)
require 'rubygems'
require 'akephalos'
require 'akephalos/console'
Akephalos::Console.start
else
unless port = ARGV[0]
puts parser.help
exit
end
if RUBY_PLATFORM == "java"
$:.unshift("vendor", lib, src)
require 'akephalos/server'
Akephalos::Server.start!(port)
else
require 'rubygems'
require 'jruby-jars'
jruby = JRubyJars.core_jar_path
jruby_stdlib = JRubyJars.stdlib_jar_path
java_args = [
"-Xmx128M",
"-cp", [JRubyJars.core_jar_path, JRubyJars.stdlib_jar_path].join(File::PATH_SEPARATOR),
"org.jruby.Main"
]
ruby_args = [
"-Ku",
"-I", ["vendor", lib, src].join(File::PATH_SEPARATOR),
"-r", "akephalos/server",
"-e", "Akephalos::Server.start!(#{port.inspect})"
]
# Bundler sets ENV["RUBYOPT"] to automatically load bundler/setup.rb, but
# since the akephalos server doesn't have any gem dependencies and is
# always executed with the same context, we clear RUBYOPT before running
# exec.
ENV["RUBYOPT"] = ""
exec("java", *(java_args + ruby_args))
end
end