nailgun 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -1
- data/lib/generator/nailgun_binary +1 -1
- data/lib/nailgun.rb +24 -28
- data/lib/nailgun_config.rb +5 -6
- data/lib/ng_command.rb +70 -58
- data/nailgun.gemspec +1 -1
- metadata +2 -2
data/README.markdown
CHANGED
data/lib/nailgun.rb
CHANGED
@@ -1,35 +1,31 @@
|
|
1
|
-
|
1
|
+
require 'optparse'
|
2
2
|
require 'nailgun_config'
|
3
3
|
require 'ng_command'
|
4
4
|
|
5
5
|
module Nailgun
|
6
|
-
|
7
|
-
|
8
|
-
def initialize(args)
|
9
|
-
raise ArgumentError,"please specify start|stop|-h" if args.empty?
|
10
|
-
opts = OptionParser.new do |opts|
|
11
|
-
opts.banner = "Usage: #{File.basename($0)} start|stop"
|
12
|
-
opts.on('-h', '--help', 'Show this message') do
|
13
|
-
puts "Use: start to start server"
|
14
|
-
puts "Use: stop to stop server"
|
15
|
-
puts opts
|
16
|
-
exit 1
|
17
|
-
end
|
18
|
-
end
|
19
|
-
@args = opts.parse!(args)
|
20
|
-
end
|
6
|
+
class NailgunServer
|
7
|
+
attr_accessor :args, :nailgun_options
|
21
8
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
9
|
+
def initialize(args)
|
10
|
+
raise ArgumentError, "please specify start|stop|-h" if args.empty?
|
11
|
+
opts = OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: #{File.basename($0)} start|stop"
|
13
|
+
opts.on('-h', '--help', 'Show this message') do
|
14
|
+
puts "Use: start to start server"
|
15
|
+
puts "Use: stop to stop server"
|
16
|
+
puts opts
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
@args = opts.parse! args
|
21
|
+
end
|
30
22
|
|
23
|
+
def daemonize
|
24
|
+
if @args.include? 'start'
|
25
|
+
Nailgun::NgCommand.start_server
|
26
|
+
elsif @args.include? 'stop'
|
27
|
+
Nailgun::NgCommand.stop_server
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
31
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
data/lib/nailgun_config.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
module Nailgun
|
2
|
-
|
2
|
+
class NailgunConfig
|
3
3
|
# default options
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
class << self
|
5
|
+
attr_accessor :options
|
6
|
+
end
|
7
7
|
NailgunConfig.options= {
|
8
8
|
:java_bin => "java",
|
9
9
|
:server_address => 'localhost',
|
10
10
|
:port_no=>'2113',
|
11
11
|
:run_mode => :once
|
12
12
|
}
|
13
|
-
|
14
|
-
end
|
13
|
+
end
|
15
14
|
end
|
data/lib/ng_command.rb
CHANGED
@@ -1,62 +1,74 @@
|
|
1
|
-
#require 'nailgun_config'
|
2
1
|
module Nailgun
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
|
3
|
+
class NgCommand
|
4
|
+
|
5
|
+
case RUBY_PLATFORM
|
6
|
+
when /linux.*x86_64|x86_64.*linux/
|
7
|
+
OS_PLATFORM = 'linux64'
|
8
|
+
when /linux/
|
9
|
+
OS_PLATFORM = 'linux32'
|
10
|
+
when /darwin/
|
11
11
|
OS_PLATFORM = 'darwin'
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
else
|
13
|
+
OS_PLATFORM = 'win32'
|
14
|
+
end
|
15
|
+
|
16
|
+
begin
|
17
|
+
NGPATH = File.expand_path(File.join(File.dirname(__FILE__), 'java', 'bin', OS_PLATFORM, 'ng'))
|
18
|
+
rescue NameError
|
19
|
+
raise "OS cannot be identified"
|
20
|
+
end
|
21
|
+
|
22
|
+
JAVAPATH = Nailgun::NailgunConfig.options[:java_bin]
|
23
|
+
NGJAR = File.expand_path(File.join(File.dirname(__FILE__), 'java','jar','nailgun-0.7.1.jar'))
|
24
|
+
|
25
|
+
def self.start_server(config={})
|
26
|
+
execute_command config do |p, s|
|
27
|
+
"nohup #{JAVAPATH} -jar #{NGJAR} #{s}:#{p} > /dev/null 2>&1 &"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.stop_server(config={})
|
32
|
+
execute_command config do |p, s|
|
33
|
+
"#{NGPATH} --nailgun-port #{p} --nailgun-server #{s} ng-stop"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.add_cps(paths, config={})
|
38
|
+
paths.each { |path| ng_cp path, config }
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.ng_cp(absolute_jar_path="", config={})
|
42
|
+
execute_command config do |p, s|
|
43
|
+
"#{NGPATH} --nailgun-port #{p} --nailgun-server #{s} ng-cp #{absolute_jar_path}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.ng_alias(alias_name, class_name, config={})
|
48
|
+
execute_command config do |p, s|
|
49
|
+
"#{NGPATH} --nailgun-port #{p} --nailgun-server #{s} ng-alias #{alias_name} #{class_name}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.ng_version
|
54
|
+
system "#{NGPATH} --nailgun-version"
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
##
|
60
|
+
# Abtracts command execution plumbing
|
61
|
+
#
|
62
|
+
# &block is expected to return a nailgun command that can be executed in a
|
63
|
+
# system subcall.
|
64
|
+
|
65
|
+
def self.execute_command(config={}, &block)
|
66
|
+
server_address = Nailgun::NailgunConfig.options[:server_address] if config[:server_address].nil?
|
67
|
+
port_no = Nailgun::NailgunConfig.options[:port_no] if config[:port_no].nil?
|
68
|
+
|
69
|
+
command = yield port_no, server_address
|
70
|
+
system(command)
|
71
|
+
end
|
72
|
+
|
19
73
|
end
|
20
|
-
JAVAPATH = Nailgun::NailgunConfig.options[:java_bin]
|
21
|
-
NGJAR = File.expand_path(File.join(File.dirname(__FILE__), 'java','jar','nailgun-0.7.1.jar'))
|
22
|
-
|
23
|
-
def self.start_server(port_no="",server_address="")
|
24
|
-
server_address = Nailgun::NailgunConfig.options[:server_address] if server_address.empty?
|
25
|
-
port_no = Nailgun::NailgunConfig.options[:port_no] if port_no.empty?
|
26
|
-
arguments = "#{server_address}:#{port_no}"
|
27
|
-
command= "nohup #{JAVAPATH} -jar #{NGJAR} #{arguments} > /dev/null 2>&1 &"
|
28
|
-
# puts command
|
29
|
-
system(command)
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.stop_server(port_no="",server_address="")
|
33
|
-
server_address = Nailgun::NailgunConfig.options[:server_address] if server_address.empty?
|
34
|
-
port_no = Nailgun::NailgunConfig.options[:port_no] if port_no.empty?
|
35
|
-
command ="#{NGPATH} --nailgun-port #{port_no} --nailgun-server #{server_address} ng-stop"
|
36
|
-
# puts command
|
37
|
-
system(command)
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.ng_cp(absolute_jar_path,port_no="",server_address="")
|
41
|
-
server_address = Nailgun::NailgunConfig.options[:server_address] if server_address.empty?
|
42
|
-
port_no = Nailgun::NailgunConfig.options[:port_no] if port_no.empty?
|
43
|
-
command ="#{NGPATH} --nailgun-port #{port_no} --nailgun-server #{server_address} ng-cp #{absolute_jar_path}"
|
44
|
-
# puts command
|
45
|
-
system(command)
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.ng_alias(alias_name,class_name,port_no="",server_address="")
|
49
|
-
server_address = Nailgun::NailgunConfig.options[:server_address] if server_address.empty?
|
50
|
-
port_no = Nailgun::NailgunConfig.options[:port_no] if port_no.empty?
|
51
|
-
command = "#{NGPATH} --nailgun-port #{port_no} --nailgun-server #{server_address} ng-alias #{alias_name} #{class_name}"
|
52
|
-
#puts command
|
53
|
-
system(command)
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.ng_version
|
57
|
-
command = "#{NGPATH} --nailgun-version"
|
58
|
-
# puts command
|
59
|
-
system(command)
|
60
|
-
end
|
61
|
-
end
|
62
74
|
end
|
data/nailgun.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nailgun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: XHTML to PDF using Flying Saucer java library
|
15
15
|
email:
|