torquebox-rake-support 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,15 @@
1
1
  # Copyright 2008-2012 Red Hat, Inc, and individual contributors.
2
- #
2
+ #
3
3
  # This is free software; you can redistribute it and/or modify it
4
4
  # under the terms of the GNU Lesser General Public License as
5
5
  # published by the Free Software Foundation; either version 2.1 of
6
6
  # the License, or (at your option) any later version.
7
- #
7
+ #
8
8
  # This software is distributed in the hope that it will be useful,
9
9
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
11
  # Lesser General Public License for more details.
12
- #
12
+ #
13
13
  # You should have received a copy of the GNU Lesser General Public
14
14
  # License along with this software; if not, write to the Free
15
15
  # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
@@ -17,6 +17,7 @@
17
17
 
18
18
  require 'tmpdir'
19
19
  require 'rbconfig'
20
+ require 'tempfile'
20
21
  require 'yaml'
21
22
  require 'rake'
22
23
  require 'torquebox/server'
@@ -151,8 +152,11 @@ module TorqueBox
151
152
  # app. Otherwise, they'll end up sharing this Gemfile, which
152
153
  # is probably not what we want.
153
154
  ENV.delete('BUNDLE_GEMFILE')
155
+ # If called from rake within a rails app, bundler will try
156
+ # to init itself via RUBYOPT, which we don't want
157
+ ENV.delete('RUBYOPT')
154
158
 
155
- set_java_opts(options[:jvm_options])
159
+ set_java_opts("#{options[:jvm_options]} #{jruby_opts_properties}")
156
160
  exec_command(run_command_line(options).join(' '))
157
161
  end
158
162
  end
@@ -163,27 +167,30 @@ module TorqueBox
163
167
  app_dir = find_option( opts, 'app_dir') || Dir.pwd
164
168
  dest_dir = find_option( opts, 'dest_dir') || Dir.pwd
165
169
 
166
- default_skip_files = %w{ ^log$ ^tmp$ ^test$ ^spec$ \.knob$ vendor }
167
- opts_skip_files = (find_option(opts, 'exclude') || "").split(/,/)
170
+ default_skip_files = %w{ ^log/ ^tmp/ ^test/ ^spec/ ^[^/]*\.knob$ vendor/.*cache/.*\.gem$ }
171
+ opts_skip_files = (find_option(opts, 'exclude') || "").
172
+ split(/,/).
173
+ map { |r| "^[^/]*#{r}"}
168
174
  skip_files = default_skip_files + opts_skip_files
169
175
 
170
176
  archive_path = File.join(dest_dir, archive)
171
-
177
+
172
178
  Dir.chdir( app_dir ) do
173
179
  include_files = []
174
- Dir[ "*", ".bundle" ].each do |entry|
175
- entry = File.basename( entry )
176
- unless ( skip_files.any?{ |regex| entry.match(regex)} )
177
- include_files << entry
180
+ Dir[ "**/**", ".bundle/**/**" ].each do |entry|
181
+ unless File.directory?(entry) || skip_files.any? {|regex| entry.match(regex)}
182
+ include_files << entry
178
183
  end
179
184
  end
180
185
 
181
- Dir[ 'vendor/*' ].each do |entry|
182
- include_files << entry unless ( entry == 'vendor/cache' )
183
- end
186
+ includes = Tempfile.new("include-files")
187
+ includes.write(include_files.join("\n"))
188
+ includes.flush
189
+
190
+ cmd = "jar cvf '#{archive_path}' @#{includes.path}"
184
191
 
185
- cmd = "jar cvf #{archive_path} #{include_files.join(' ')}"
186
192
  run_command( cmd )
193
+ includes.close( true )
187
194
  end
188
195
 
189
196
  archive_path
@@ -205,7 +212,7 @@ module TorqueBox
205
212
 
206
213
  root = options[:root] || options['root'] || Dir.pwd
207
214
  context_path = options[:context_path] || options['context_path']
208
-
215
+
209
216
  d = {}
210
217
  d['application'] = {}
211
218
  d['application']['root'] = root
@@ -248,11 +255,11 @@ module TorqueBox
248
255
  def deployed_file(name)
249
256
  File.join( DeployUtils.deploy_dir, "#{name}" ) + ".deployed"
250
257
  end
251
-
258
+
252
259
  def undeploy_archive(opts = {})
253
260
  undeploy( normalize_archive_name( find_option( opts, 'name' ) || archive_name( opts[:root] ) ), opts )
254
- end
255
-
261
+ end
262
+
256
263
  def undeploy_yaml(opts = {})
257
264
  undeploy( normalize_yaml_name( find_option( opts, 'name' ) || deployment_name( opts[:root] ) ), opts )
258
265
  end
@@ -282,18 +289,22 @@ module TorqueBox
282
289
  success
283
290
  end
284
291
 
292
+ def run_command(cmd)
293
+ puts `#{cmd} 2>&1`
294
+ end
295
+
285
296
  # Used when we want to effectively replace this process with the
286
297
  # given command. On Windows this does call Kernel#exec but on
287
- # everything else we just delegate to run_command.
298
+ # everything else we just delegate to fake_exec.
288
299
  #
289
300
  # This is mainly so CTRL+C, STDIN, STDOUT, and STDERR work as
290
301
  # expected across all operating systems.
291
302
  def exec_command(cmd)
292
- windows? ? exec(cmd) : run_command(cmd)
303
+ windows? ? exec(cmd) : fake_exec(cmd)
293
304
  end
294
305
 
295
306
  # Used to run a command as a subprocess
296
- def run_command(cmd)
307
+ def fake_exec(cmd)
297
308
  exiting = false
298
309
  IO.popen4(cmd) do |pid, stdin, stdout, stderr|
299
310
  stdout.sync = true
@@ -310,7 +321,7 @@ module TorqueBox
310
321
  Thread.new(stdin) { |stdin_io|
311
322
  begin
312
323
  until exiting
313
- stdin_io.write(STDIN.readpartial(1024))
324
+ stdin_io.write(readpartial(STDIN))
314
325
  stdin_io.flush
315
326
  end
316
327
  rescue Errno::EBADF, IOError
@@ -322,7 +333,7 @@ module TorqueBox
322
333
  [ Thread.new(stdout) { |stdout_io|
323
334
  begin
324
335
  while true
325
- STDOUT.write(stdout_io.readpartial(1024))
336
+ STDOUT.write(readpartial(stdout_io))
326
337
  end
327
338
  rescue EOFError
328
339
  end
@@ -331,7 +342,7 @@ module TorqueBox
331
342
  Thread.new(stderr) { |stderr_io|
332
343
  begin
333
344
  while true
334
- STDERR.write(stderr_io.readpartial(1024))
345
+ STDERR.write(readpartial(stderr_io))
335
346
  end
336
347
  rescue EOFError
337
348
  end
@@ -341,18 +352,22 @@ module TorqueBox
341
352
 
342
353
  end
343
354
 
355
+ def readpartial(stream)
356
+ windows? ? stream.read(1) : stream.readpartial(1024)
357
+ end
358
+
344
359
  def windows?
345
- Config::CONFIG['host_os'] =~ /mswin/
360
+ RbConfig::CONFIG['host_os'] =~ /mswin/
346
361
  end
347
-
362
+
348
363
  def find_option(opt, key)
349
364
  opt[key.to_sym] || opt[key] || ENV[key] || ENV[key.upcase]
350
365
  end
351
-
366
+
352
367
  def normalize_yaml_name(name)
353
368
  name[-9..-1] == '-knob.yml' ? name : name + '-knob.yml'
354
369
  end
355
-
370
+
356
371
  def normalize_archive_name(name)
357
372
  name[-5..-1] == '.knob' ? name : name + '.knob'
358
373
  end
@@ -365,10 +380,10 @@ module TorqueBox
365
380
  applications = {}
366
381
  deployment_descriptors.each do | descriptor |
367
382
  descriptor_path = File.join( deploy_dir, descriptor )
368
- appname = descriptor.sub( /\-knob.yml/, '' )
383
+ appname = descriptor.sub( /\-knob.yml/, '' )
369
384
  applications[appname] = {}
370
385
  applications[appname][:descriptor] = descriptor_path
371
- applications[appname][:status] = case
386
+ applications[appname][:status] = case
372
387
  when File.exists?("#{descriptor_path}.dodeploy")
373
388
  "awaiting deployment"
374
389
  when File.exists?("#{descriptor_path}.deployed")
@@ -380,8 +395,8 @@ module TorqueBox
380
395
  end
381
396
  applications
382
397
  end
383
-
384
- private
398
+
399
+ private
385
400
 
386
401
  def undeploy(name, opts = {})
387
402
  puts "Attempting to undeploy #{name}"
@@ -408,6 +423,14 @@ module TorqueBox
408
423
  end
409
424
  end
410
425
 
426
+ def jruby_opts_properties
427
+ jruby_opts = ENV['JRUBY_OPTS']
428
+ return "" if jruby_opts.nil?
429
+ # Only convert -Xa.b, -Xa.b.c, -Xa.b.c.d style options to properties
430
+ properties = jruby_opts.scan(/-X(\w+\..+?)\s/)
431
+ properties.map { |matches| "-Djruby.#{matches.first}" }.join(' ')
432
+ end
433
+
411
434
  end
412
435
  end
413
436
  end
@@ -43,6 +43,7 @@ module TorqueBox
43
43
  require_generators
44
44
  if using_rails3?
45
45
  generator = ::Rails::Generators::AppGenerator.new( [root], {}, :destination_root => root )
46
+ Dir.chdir(root)
46
47
  generator.apply TorqueBox::Rails.template
47
48
  else
48
49
  ::Rails::TemplateRunner.new( TorqueBox::Rails.template )
@@ -210,11 +210,11 @@ describe TorqueBox::DeployUtils do
210
210
  end
211
211
 
212
212
  describe '.check_server' do
213
- context "when it can't find the modules" do
213
+ context "when it can't find the modules" do
214
214
  before(:each) do
215
215
  File.stub(:exist?).and_return(false)
216
216
  end
217
-
217
+
218
218
  it "should raise if it can't find the torquebox modules" do
219
219
  lambda { @util.check_server }.should raise_error
220
220
  end
@@ -251,7 +251,19 @@ describe TorqueBox::DeployUtils do
251
251
  end
252
252
 
253
253
  it 'should set java options' do
254
- @util.should_receive(:set_java_opts).with('java options')
254
+ @util.should_receive(:set_java_opts).with('java options ')
255
+ @util.run_server(:jvm_options => 'java options')
256
+ end
257
+
258
+ it 'should pass JRUBY_OPTS properties' do
259
+ ENV['JRUBY_OPTS'] = '--1.9 -Xjit.logging=true -Xthread.pool.enabled=true -X+C'
260
+ @util.should_receive(:set_java_opts).with(' -Djruby.jit.logging=true -Djruby.thread.pool.enabled=true')
261
+ @util.run_server
262
+ end
263
+
264
+ it 'should set java options and pass JRUBY_OPTS properties' do
265
+ ENV['JRUBY_OPTS'] = '-X-C -Xjit.logging=true --ng'
266
+ @util.should_receive(:set_java_opts).with('java options -Djruby.jit.logging=true')
255
267
  @util.run_server(:jvm_options => 'java options')
256
268
  end
257
269
  end
@@ -349,12 +361,25 @@ describe TorqueBox::DeployUtils do
349
361
  end
350
362
 
351
363
  describe '.create_archive' do
352
- it 'should not include excluded dirs and files' do
364
+
365
+ ALL_EXPECTED_FILES = %w{config.ru
366
+ app/app.rb
367
+ app/puppet-master.rb
368
+ app/app.box
369
+ app/a-non-cached.gem
370
+ vendor/vendor.rb
371
+ puppet/puppet.rb
372
+ simpleapp.box}
373
+
374
+ def mock_run_command(expected_includes)
353
375
  @util.should_receive(:run_command) do |arg|
354
- ["config.ru", "app"].permutation.map {|p|
355
- "jar cvf /tmp/simpleapp.knob #{p.join(" ")}"
356
- }.should include(arg)
376
+ included_files = arg =~ /@(.*)/ ? File.new($1).readlines.map(&:strip) : []
377
+ expected_includes.permutation.to_a.should include(included_files)
357
378
  end
379
+ end
380
+
381
+ it 'should not include excluded dirs and files' do
382
+ mock_run_command(ALL_EXPECTED_FILES - %w{puppet/puppet.rb simpleapp.box})
358
383
 
359
384
  path = @util.create_archive(
360
385
  :name => "simpleapp",
@@ -366,11 +391,7 @@ describe TorqueBox::DeployUtils do
366
391
  end
367
392
 
368
393
  it 'should exclude based on patterns' do
369
- @util.should_receive(:run_command) do |arg|
370
- ["puppet", "config.ru", "app"].permutation.map {|p|
371
- "jar cvf /tmp/simpleapp.knob #{p.join(" ")}"
372
- }.should include(arg)
373
- end
394
+ mock_run_command(ALL_EXPECTED_FILES - %w{simpleapp.box})
374
395
 
375
396
  path = @util.create_archive(
376
397
  :name => "simpleapp",
@@ -382,12 +403,8 @@ describe TorqueBox::DeployUtils do
382
403
  end
383
404
 
384
405
  it 'should include all dirs and files except default' do
385
- @util.should_receive(:run_command) do |arg|
386
- ["config.ru", "app", "puppet", "simpleapp.box"].permutation.map {|p|
387
- "jar cvf /tmp/simpleapp.knob #{p.join(" ")}"
388
- }.should include(arg)
389
- end
390
-
406
+ mock_run_command ALL_EXPECTED_FILES
407
+
391
408
  path = @util.create_archive(
392
409
  :name => "simpleapp",
393
410
  :app_dir => File.join(File.dirname(__FILE__), 'fixtures/simpleapp'),
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/spec/rails_spec.rb CHANGED
@@ -47,7 +47,7 @@ describe TorqueBox::Rails do
47
47
  generator = mock('generator')
48
48
  ::Rails::Generators::AppGenerator.stub(:new).and_return(generator)
49
49
  generator.should_receive(:apply).with(TorqueBox::Rails.template)
50
- TorqueBox::Rails.apply_template('root')
50
+ TorqueBox::Rails.apply_template(File.expand_path("../fixtures/simpleapp", __FILE__))
51
51
  end
52
52
  end
53
53
 
data/spec/server_spec.rb CHANGED
@@ -8,7 +8,19 @@ describe TorqueBox::Server do
8
8
  end
9
9
 
10
10
  it "should return nil if torquebox-server is not installed" do
11
+ # if you have torquebox-server installed, this will actually return a
12
+ # value instead of nil. so reseting gem paths.
13
+ old_gem_home = ENV['GEM_HOME']
14
+ old_gem_path = ENV['GEM_PATH']
15
+ ENV['GEM_PATH'] = ""
16
+ ENV['GEM_HOME'] = ""
17
+ Gem.clear_paths
18
+
11
19
  TorqueBox::Server.torquebox_home.should == nil
20
+
21
+ Gem.clear_paths
22
+ ENV['GEM_HOME'] = old_gem_home
23
+ ENV['GEM_PATH'] = old_gem_path
12
24
  end
13
25
 
14
26
  describe ".setup_environment" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: torquebox-rake-support
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.0.3
5
+ version: 2.1.0
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-05-04 00:00:00 Z
13
+ date: 2012-07-26 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -48,12 +48,12 @@ 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/upstart.rb
54
- - lib/torquebox/deploy_utils.rb
52
+ - lib/org.torquebox.rake-support.rb
55
53
  - lib/torquebox/launchd.rb
54
+ - lib/torquebox/upstart.rb
56
55
  - lib/torquebox/rails.rb
56
+ - lib/torquebox/deploy_utils.rb
57
57
  - lib/torquebox/server.rb
58
58
  - lib/torquebox/rake/tasks.rb
59
59
  - lib/torquebox/rake/tasks/deployment.rb
@@ -63,12 +63,18 @@ files:
63
63
  - generators/torquebox_queue_generator.rb
64
64
  - generators/templates/queue.rb
65
65
  - spec/rails_spec.rb
66
+ - spec/server_spec.rb
66
67
  - spec/spec_helper.rb
67
68
  - spec/upstart_spec.rb
68
69
  - spec/deploy_utils_spec.rb
69
- - spec/server_spec.rb
70
70
  - spec/fixtures/simpleapp/config.ru
71
71
  - spec/fixtures/simpleapp/simpleapp.box
72
+ - spec/fixtures/simpleapp/vendor/vendor.rb
73
+ - spec/fixtures/simpleapp/app/puppet-master.rb
74
+ - spec/fixtures/simpleapp/app/app.rb
75
+ - spec/fixtures/simpleapp/app/a-non-cached.gem
76
+ - spec/fixtures/simpleapp/app/app.box
77
+ - spec/fixtures/simpleapp/puppet/puppet.rb
72
78
  homepage: http://torquebox.org/
73
79
  licenses:
74
80
  - lgpl
@@ -98,6 +104,6 @@ specification_version: 3
98
104
  summary: TorqueBox Rake Support
99
105
  test_files:
100
106
  - spec/rails_spec.rb
107
+ - spec/server_spec.rb
101
108
  - spec/upstart_spec.rb
102
109
  - spec/deploy_utils_spec.rb
103
- - spec/server_spec.rb