torquebox-rake-support 2.0.0.beta3 → 2.0.0.cr1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -116,16 +116,25 @@ module TorqueBox
116
116
  puts "TorqueBox install OK: #{opt_torquebox}"
117
117
  end
118
118
 
119
+ def set_java_opts(options)
120
+ ENV['APPEND_JAVA_OPTS'] = options
121
+ end
122
+
119
123
  def run_command_line(opts={})
120
124
  options = ENV['JBOSS_OPTS'] || ''
121
125
  options = "#{options} --server-config=#{cluster_config_file}" if opts[:clustered]
122
126
  options = "#{options} -Dorg.torquebox.web.http.maxThreads=#{opts[:max_threads]}" if opts[:max_threads]
123
127
  options = "#{options} -b #{opts[:bind_address]}" if opts[:bind_address]
128
+ options = "#{options} -Djboss.socket.binding.port-offset=#{opts[:port_offset]}" if opts[:port_offset]
129
+ options = "#{options} -Djboss.node.name=#{opts[:node_name]}" if opts[:node_name]
130
+ options = "#{options} -Djboss.server.data.dir=#{opts[:data_directory]}" if opts[:data_directory]
131
+ options = "#{options} #{opts[:pass_through]}" if opts[:pass_through]
124
132
  if windows?
125
133
  cmd = "#{jboss_home.gsub('/', '\\')}\\bin\\standalone.bat"
126
134
  else
127
135
  cmd = "/bin/sh bin/standalone.sh"
128
136
  end
137
+ puts "#{cmd} #{options}" # Make it clear to the user what is being passed through to JBoss AS
129
138
  [cmd, options]
130
139
  end
131
140
 
@@ -134,7 +143,6 @@ module TorqueBox
134
143
  end
135
144
 
136
145
  def run_server(options={})
137
-
138
146
  puts "[WARNING] #{deployment_name} has not been deployed. Starting TorqueBox anyway." unless ( is_deployed? )
139
147
 
140
148
  Dir.chdir(jboss_home) do
@@ -144,6 +152,7 @@ module TorqueBox
144
152
  # is probably not what we want.
145
153
  ENV.delete('BUNDLE_GEMFILE')
146
154
 
155
+ set_java_opts(options[:jvm_options])
147
156
  exec_command(run_command_line(options).join(' '))
148
157
  end
149
158
  end
@@ -321,9 +330,33 @@ module TorqueBox
321
330
  def normalize_archive_name(name)
322
331
  name[-5..-1] == '.knob' ? name : name + '.knob'
323
332
  end
333
+
334
+ def deployment_descriptors
335
+ Dir.glob( "#{deploy_dir}/*-knob.yml" ).collect { |d| File.basename( d ) }
336
+ end
337
+
338
+ def deployment_status
339
+ applications = {}
340
+ deployment_descriptors.each do | descriptor |
341
+ descriptor_path = File.join( deploy_dir, descriptor )
342
+ appname = descriptor.sub( /\-knob.yml/, '' )
343
+ applications[appname] = {}
344
+ applications[appname][:descriptor] = descriptor_path
345
+ applications[appname][:status] = case
346
+ when File.exists?("#{descriptor_path}.dodeploy")
347
+ "awaiting deployment"
348
+ when File.exists?("#{descriptor_path}.deployed")
349
+ "deployed"
350
+ when File.exists?("#{descriptor_path}.failed")
351
+ "deployment failed"
352
+ else "unknown: try running `torquebox deploy #{appname}`"
353
+ end
354
+ end
355
+ applications
356
+ end
324
357
 
325
358
  private
326
-
359
+
327
360
  def undeploy(name, opts = {})
328
361
  puts "Attempting to undeploy #{name}"
329
362
  from_dir = find_option( opts, 'deploy_dir' ) || deploy_dir
@@ -15,30 +15,69 @@
15
15
  # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
16
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
17
 
18
+
18
19
  begin
19
- require 'rails/generators'
20
- require 'rails/generators/rails/app/app_generator'
20
+ require 'rails/version'
21
21
  rescue LoadError
22
- # Rails isn't installed, bail out
23
- return
24
22
  end
25
23
 
26
24
  module TorqueBox
27
25
  class Rails
26
+
28
27
  def self.new_app
28
+ print_rails_not_installed_and_exit unless rails_installed?
29
+ require_generators
29
30
  # Assumes ARGV[0] already has the application name
30
31
  ARGV << [ "-m", TorqueBox::Rails.template ]
31
32
  ARGV.flatten!
32
- ::Rails::Generators::AppGenerator.start
33
+ if using_rails3?
34
+ ::Rails::Generators::AppGenerator.start
35
+ else
36
+ ::Rails::Generator::Base.use_application_sources!
37
+ ::Rails::Generator::Scripts::Generate.new.run(ARGV, :generator => 'app')
38
+ end
33
39
  end
34
40
 
35
41
  def self.apply_template( root )
36
- generator = ::Rails::Generators::AppGenerator.new( [root], {}, :destination_root => root )
37
- generator.apply TorqueBox::Rails.template
42
+ print_rails_not_installed_and_exit unless rails_installed?
43
+ require_generators
44
+ if using_rails3?
45
+ generator = ::Rails::Generators::AppGenerator.new( [root], {}, :destination_root => root )
46
+ generator.apply TorqueBox::Rails.template
47
+ else
48
+ ::Rails::TemplateRunner.new( TorqueBox::Rails.template )
49
+ end
38
50
  end
39
51
 
52
+
40
53
  def self.template
41
54
  "#{ENV['TORQUEBOX_HOME']}/share/rails/template.rb"
42
55
  end
56
+
57
+ def self.rails_installed?
58
+ defined? ::Rails::VERSION
59
+ end
60
+
61
+ def self.print_rails_not_installed_and_exit
62
+ $stderr.puts "Rails not installed. Unable to load generators"
63
+ exit 1
64
+ end
65
+
66
+ def self.using_rails3?
67
+ ::Rails::VERSION::MAJOR == 3
68
+ end
69
+
70
+ def self.require_generators
71
+ if using_rails3?
72
+ require 'rails/generators'
73
+ require 'rails/generators/rails/app/app_generator'
74
+ else
75
+ require 'rails_generator'
76
+ require 'rails_generator/generators/applications/app/app_generator'
77
+ require 'rails_generator/generators/applications/app/template_runner'
78
+ require 'rails_generator/scripts/generate'
79
+ end
80
+ end
43
81
  end
44
82
  end
83
+
@@ -23,7 +23,6 @@ module TorqueBox
23
23
 
24
24
  def self.torquebox_home
25
25
  if ((gem_version <=> Gem::Version.new('1.8.9')) < 0)
26
- puts "[WARNING] Found rubygems version #{Gem::VERSION}. This probably means you are on JRuby 1.6.4. While JRuby 1.6.4 should work, TorqueBox is tested on and ships with JRuby 1.6.5."
27
26
  home = Gem.searcher.find( 'torquebox-server' )
28
27
  else
29
28
  home = Gem::Specification.find_by_name( 'torquebox-server' )
@@ -223,7 +223,7 @@ describe TorqueBox::DeployUtils do
223
223
  begin
224
224
  @util.check_server
225
225
  rescue Exception => e
226
- e.message.should =~ %r{doesn't appear to be a valid TorqueBox install}
226
+ e.message.should =~ /doesn't appear to be a valid TorqueBox install/
227
227
  end
228
228
  end
229
229
  end
@@ -249,6 +249,11 @@ describe TorqueBox::DeployUtils do
249
249
  @util.should_receive(:is_deployed?).and_return( true )
250
250
  @util.run_server
251
251
  end
252
+
253
+ it 'should set java options' do
254
+ @util.should_receive(:set_java_opts).with('java options')
255
+ @util.run_server(:jvm_options => 'java options')
256
+ end
252
257
  end
253
258
 
254
259
  describe '.is_deployed?' do
@@ -305,6 +310,42 @@ describe TorqueBox::DeployUtils do
305
310
  command, options = @util.run_command_line(:bind_address => '0.0.0.0')
306
311
  options.should include('-b 0.0.0.0')
307
312
  end
313
+
314
+ it 'should not set port offset by default' do
315
+ command, options = @util.run_command_line
316
+ options.should_not include('-Djboss.socket.binding.port-offset')
317
+ end
318
+
319
+ it 'should set port offset when given' do
320
+ command, options = @util.run_command_line(:port_offset => '100')
321
+ options.should include('-Djboss.socket.binding.port-offset=100')
322
+ end
323
+
324
+ it 'should not set node name by default' do
325
+ command, options = @util.run_command_line
326
+ options.should_not include('-Djboss.node.name')
327
+ end
328
+
329
+ it 'should set node name when given' do
330
+ command, options = @util.run_command_line(:node_name => 'mynode')
331
+ options.should include('-Djboss.node.name=mynode')
332
+ end
333
+
334
+ it 'should not set data directory by default' do
335
+ command, options = @util.run_command_line
336
+ options.should_not include('-Djboss.server.data.dir')
337
+ end
338
+
339
+ it 'should set data directory when given' do
340
+ command, options = @util.run_command_line(:data_directory => '/tmp/mynode')
341
+ options.should include('-Djboss.server.data.dir=/tmp/mynode')
342
+ end
343
+
344
+ it 'should allow extra parameters to be passed through to JBoss AS' do
345
+ command, options = @util.run_command_line(:pass_through => '--help')
346
+ options.should include('--help')
347
+ end
348
+
308
349
  end
309
350
 
310
351
  describe '.create_archive' do
@@ -355,4 +396,45 @@ describe TorqueBox::DeployUtils do
355
396
  path.should == "/tmp/simpleapp.knob"
356
397
  end
357
398
  end
399
+
400
+ describe '.deployment_status' do
401
+ before( :each ) do
402
+ ENV['TORQUEBOX_HOME'] = '/torquebox'
403
+ ENV['JBOSS_HOME'] = ENV['TORQUEBOX_HOME'] + '/jboss'
404
+ @myapp = @util.deployment_name( 'my-app' )
405
+ @appname = @myapp.sub /\-knob.yml/, ''
406
+ File.stub('exists?').with(File.join(@util.torquebox_home, 'apps')).and_return false
407
+ File.stub('exists?').with(File.join(@util.deploy_dir, @myapp)).and_return true
408
+ File.stub('exists?').with(File.join(@util.deploy_dir, "#{@myapp}.dodeploy")).and_return false
409
+ File.stub('exists?').with(File.join(@util.deploy_dir, "#{@myapp}.deployed")).and_return false
410
+ File.stub('exists?').with(File.join(@util.deploy_dir, "#{@myapp}.failed")).and_return false
411
+ Dir.stub('glob').with( "#{@util.deploy_dir}/*-knob.yml" ).and_return [ File.join( @util.deploy_dir, @myapp ) ]
412
+ end
413
+
414
+ it 'should return a hash of deployment info keyed by application name' do
415
+ @util.deployment_status[@appname].should_not be_nil
416
+ end
417
+
418
+ it 'should provide the deployment descriptor path' do
419
+ @util.deployment_status[@appname][:descriptor].should_not be_nil
420
+ end
421
+
422
+ it 'should provide a deployment status if awaiting deployment' do
423
+ dodeploy_file = File.join(@util.deploy_dir, "#{@myapp}.dodeploy")
424
+ File.stub('exists?').with(dodeploy_file).and_return true
425
+ @util.deployment_status[@appname][:status].should == 'awaiting deployment'
426
+ end
427
+
428
+ it 'should provide a deployment status if deployed' do
429
+ deployed_file = File.join(@util.deploy_dir, "#{@myapp}.deployed")
430
+ File.stub('exists?').with(deployed_file).and_return true
431
+ @util.deployment_status[@appname][:status].should == 'deployed'
432
+ end
433
+
434
+ it 'should provide a deployment status if failed' do
435
+ failed_file = File.join(@util.deploy_dir, "#{@myapp}.failed")
436
+ File.stub('exists?').with(failed_file).and_return true
437
+ @util.deployment_status[@appname][:status].should == 'deployment failed'
438
+ end
439
+ end
358
440
  end
@@ -0,0 +1,82 @@
1
+ require 'torquebox/rails'
2
+
3
+ describe TorqueBox::Rails do
4
+
5
+ context "Rails not installed" do
6
+ before(:each) do
7
+ TorqueBox::Rails.stub!(:rails_installed?).and_return(false)
8
+ end
9
+
10
+ describe "new_app" do
11
+ it "should print a warning" do
12
+ $stderr.should_receive(:puts)
13
+ lambda {
14
+ TorqueBox::Rails.new_app
15
+ }.should raise_error SystemExit
16
+ end
17
+ end
18
+
19
+ describe "apply_template" do
20
+ it "should print a warning" do
21
+ $stderr.should_receive(:puts)
22
+ lambda {
23
+ TorqueBox::Rails.apply_template("root")
24
+ }.should raise_error SystemExit
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ context "Rails 3" do
31
+ before(:each) do
32
+ TorqueBox::Rails.stub!(:rails_installed?).and_return(true)
33
+ TorqueBox::Rails.stub(:using_rails3?).and_return(true)
34
+ TorqueBox::Rails.stub(:require_generators)
35
+ module ::Rails; module Generators; class AppGenerator; end; end; end
36
+ end
37
+
38
+ describe "new_app" do
39
+ it "should generate" do
40
+ ::Rails::Generators::AppGenerator.should_receive(:start)
41
+ TorqueBox::Rails.new_app
42
+ end
43
+ end
44
+
45
+ describe "apply_template" do
46
+ it "should apply" do
47
+ generator = mock('generator')
48
+ ::Rails::Generators::AppGenerator.stub(:new).and_return(generator)
49
+ generator.should_receive(:apply).with(TorqueBox::Rails.template)
50
+ TorqueBox::Rails.apply_template('root')
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ context "Rails 2" do
57
+ before(:each) do
58
+ TorqueBox::Rails.stub!(:rails_installed?).and_return(true)
59
+ TorqueBox::Rails.stub(:using_rails3?).and_return(false)
60
+ TorqueBox::Rails.stub(:require_generators)
61
+ module ::Rails; module Generator; class Base; end; end; end
62
+ module ::Rails; module Generator; module Scripts; class Generate; end; end; end; end
63
+ module ::Rails; class TemplateRunner; end; end
64
+ ::Rails::Generator::Base.stub(:use_application_sources!)
65
+ end
66
+
67
+ describe "new_app" do
68
+ it "should generate" do
69
+ ::Rails::Generator::Scripts::Generate.any_instance.should_receive(:run)
70
+ TorqueBox::Rails.new_app
71
+ end
72
+ end
73
+
74
+ describe "apply_template" do
75
+ it "should apply" do
76
+ ::Rails::TemplateRunner.should_receive(:new).with(TorqueBox::Rails.template)
77
+ TorqueBox::Rails.apply_template('root')
78
+ end
79
+ end
80
+ end
81
+
82
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: torquebox-rake-support
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 2.0.0.beta3
5
+ version: 2.0.0.cr1
6
6
  platform: ruby
7
7
  authors:
8
8
  - The TorqueBox Team
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-01-24 00:00:00 Z
13
+ date: 2012-03-02 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -48,26 +48,27 @@ extra_rdoc_files: []
48
48
 
49
49
  files:
50
50
  - licenses/lgpl-2.1.txt
51
- - lib/org.torquebox.rake-support.rb
52
51
  - lib/torquebox-rake-support.rb
53
- - lib/torquebox/deploy_utils.rb
54
- - lib/torquebox/launchd.rb
52
+ - lib/org.torquebox.rake-support.rb
55
53
  - lib/torquebox/rails.rb
56
- - lib/torquebox/server.rb
54
+ - lib/torquebox/deploy_utils.rb
57
55
  - lib/torquebox/upstart.rb
56
+ - lib/torquebox/server.rb
57
+ - lib/torquebox/launchd.rb
58
58
  - lib/torquebox/rake/tasks.rb
59
59
  - lib/torquebox/rake/tasks/archive.rb
60
60
  - lib/torquebox/rake/tasks/deployment.rb
61
61
  - lib/torquebox/rake/tasks/server.rb
62
- - generators/USAGE
63
62
  - generators/torquebox_queue_generator.rb
63
+ - generators/USAGE
64
64
  - generators/templates/queue.rb
65
+ - spec/upstart_spec.rb
66
+ - spec/rails_spec.rb
65
67
  - spec/deploy_utils_spec.rb
66
- - spec/server_spec.rb
67
68
  - spec/spec_helper.rb
68
- - spec/upstart_spec.rb
69
- - spec/fixtures/simpleapp/config.ru
69
+ - spec/server_spec.rb
70
70
  - spec/fixtures/simpleapp/simpleapp.box
71
+ - spec/fixtures/simpleapp/config.ru
71
72
  homepage: http://www.torquebox.org/torquebox-gems-parent/torquebox-rake-support/
72
73
  licenses:
73
74
  - lgpl
@@ -91,11 +92,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
92
  requirements: []
92
93
 
93
94
  rubyforge_project:
94
- rubygems_version: 1.8.9
95
+ rubygems_version: 1.8.15
95
96
  signing_key:
96
97
  specification_version: 3
97
98
  summary: TorqueBox Rake Support
98
99
  test_files:
100
+ - spec/upstart_spec.rb
101
+ - spec/rails_spec.rb
99
102
  - spec/deploy_utils_spec.rb
100
103
  - spec/server_spec.rb
101
- - spec/upstart_spec.rb