nailgun 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,7 +19,7 @@ Install
19
19
  <code>rake nailgun</code>
20
20
 
21
21
  OR
22
- <code> sudo gem insatll nailgun </code>
22
+ <code> sudo gem install nailgun </code>
23
23
 
24
24
 
25
25
 
@@ -6,7 +6,7 @@ Nailgun::NailgunConfig.options =
6
6
  {
7
7
  :java_bin => "java",
8
8
  :server_address =>'localhost',
9
- :port_no=>'2114'
9
+ :port_no=>'2113'
10
10
  }
11
11
 
12
12
  Nailgun::NailgunServer.new(ARGV).daemonize
@@ -1,35 +1,31 @@
1
- #require 'optparse'
1
+ require 'optparse'
2
2
  require 'nailgun_config'
3
3
  require 'ng_command'
4
4
 
5
5
  module Nailgun
6
- class NailgunServer
7
- attr_accessor :args,:nailgun_options
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
- def daemonize
23
- if @args.include?('start')
24
- Nailgun::NgCommand.start_server
25
- elsif @args.include?('stop')
26
- Nailgun::NgCommand.stop_server
27
- end
28
- end
29
- end
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
-
@@ -1,15 +1,14 @@
1
1
  module Nailgun
2
- class NailgunConfig
2
+ class NailgunConfig
3
3
  # default options
4
- class << self
5
- attr_accessor :options
6
- end
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
@@ -1,62 +1,74 @@
1
- #require 'nailgun_config'
2
1
  module Nailgun
3
- class NgCommand
4
- if RUBY_PLATFORM =~ /linux/
5
- if RUBY_PLATFORM =~ /x86_64/
6
- OS_PLATFORM = 'linux64'
7
- else
8
- OS_PLATFORM = 'linux32'
9
- end
10
- elsif RUBY_PLATFORM =~ /darwin/
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
- else
13
- OS_PLATFORM = 'win32'
14
- end
15
- begin
16
- NGPATH = File.expand_path(File.join(File.dirname(__FILE__), 'java','bin',OS_PLATFORM,'ng'))
17
- rescue Exception
18
- puts "cant find os version"
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
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "nailgun"
6
- s.version = "0.0.2"
6
+ s.version = "0.0.3"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Amar Daxini"]
9
9
  s.email = ["amardaxini@gmail.com"]
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.2
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-05-10 00:00:00.000000000 Z
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: