torquebox-rake-support 1.1.1 → 2.0.0.beta1

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-2011 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
@@ -19,6 +19,7 @@ require 'tmpdir'
19
19
  require 'rbconfig'
20
20
  require 'yaml'
21
21
  require 'rake'
22
+ require 'torquebox/server'
22
23
 
23
24
 
24
25
  module TorqueBox
@@ -36,12 +37,14 @@ module TorqueBox
36
37
  torquebox_home = nil
37
38
  if ( ENV['TORQUEBOX_HOME'] )
38
39
  torquebox_home = File.expand_path(ENV['TORQUEBOX_HOME'])
40
+ else
41
+ torquebox_home = TorqueBox::Server.torquebox_home
39
42
  end
40
43
  torquebox_home
41
44
  end
42
45
 
43
46
  def jboss_conf
44
- ENV['TORQUEBOX_CONF'] || ENV['JBOSS_CONF'] || 'default'
47
+ ENV['TORQUEBOX_CONF'] || ENV['JBOSS_CONF'] || 'standalone'
45
48
  end
46
49
 
47
50
  # TODO: This is not windows friendly, is it?
@@ -59,15 +62,19 @@ module TorqueBox
59
62
  end
60
63
 
61
64
  def server_dir
62
- File.join("#{jboss_home}","server", "#{jboss_conf}" )
65
+ File.join("#{jboss_home}","#{jboss_conf}" )
63
66
  end
64
67
 
65
68
  def config_dir
66
- File.join("#{server_dir}","conf")
69
+ File.join("#{server_dir}","configuration")
70
+ end
71
+
72
+ def cluster_config_file
73
+ File.join(config_dir, 'torquebox', "standalone-preview-ha.xml")
67
74
  end
68
75
 
69
76
  def properties_dir
70
- File.join("#{config_dir}","props")
77
+ config_dir
71
78
  end
72
79
 
73
80
  def deploy_dir
@@ -76,11 +83,19 @@ module TorqueBox
76
83
  return d
77
84
  end
78
85
 
79
- File.join( "#{server_dir}", "deploy" )
86
+ File.join( "#{server_dir}", "deployments" )
80
87
  end
81
88
 
82
89
  def deployers_dir
83
- File.join("#{server_dir}","deployers")
90
+ raise "Deployers directory no longer relevant"
91
+ end
92
+
93
+ def modules_dir
94
+ File.join( jboss_home, 'modules' )
95
+ end
96
+
97
+ def torquebox_modules_dir
98
+ File.join( modules_dir, 'org', 'torquebox' )
84
99
  end
85
100
 
86
101
  def archive_name(root=Dir.pwd)
@@ -92,8 +107,8 @@ module TorqueBox
92
107
  end
93
108
 
94
109
  def check_server
95
- matching = Dir[ "#{deployers_dir}/torquebox*deployer*" ]
96
- raise "No TorqueBox deployer installed in #{deployers_dir}" if ( matching.empty? )
110
+ raise "#{jboss_home} doesn't appear to be a valid TorqueBox install" unless File.exist?( torquebox_modules_dir )
111
+ puts "TorqueBox installation appears OK"
97
112
  end
98
113
 
99
114
  def check_opt_torquebox
@@ -101,29 +116,38 @@ module TorqueBox
101
116
  puts "TorqueBox install OK: #{opt_torquebox}"
102
117
  end
103
118
 
104
- def run_command_line
105
- cmd = Config::CONFIG['host_os'] =~ /mswin/ ? "bin\\run" : "/bin/sh bin/run.sh"
106
- options = ENV['JBOSS_OPTS']
107
- cmd += " -b 0.0.0.0" unless /((^|\s)-b\s|(^|\s)--host=)/ =~ options
108
- "#{cmd} -c #{jboss_conf} #{options}"
119
+ def run_command_line(opts={})
120
+ options = ENV['JBOSS_OPTS'] || ''
121
+ options = "#{options} --server-config=#{cluster_config_file}" if opts[:clustered]
122
+ options = "#{options} -Dorg.torquebox.web.http.maxThreads=#{opts[:max_threads]}" if opts[:max_threads]
123
+ options = "#{options} -b #{opts[:bind_address]}" if opts[:bind_address]
124
+ if windows?
125
+ cmd = "#{jboss_home.gsub('/', '\\')}\\bin\\standalone.bat"
126
+ else
127
+ cmd = "/bin/sh bin/standalone.sh"
128
+ end
129
+ [cmd, options]
130
+ end
131
+
132
+ def is_deployed?( appname = deployment_name )
133
+ File.exists?( File.join(deploy_dir, appname) )
109
134
  end
110
135
 
111
- def run_server
136
+ def run_server(options={})
137
+
138
+ puts "[WARNING] #{deployment_name} has not been deployed. Starting TorqueBox anyway." unless ( is_deployed? )
139
+
112
140
  Dir.chdir(jboss_home) do
113
- old_trap = trap("INT") do
114
- puts "caught SIGINT, shutting down"
115
- end
116
141
  # don't send the gemfile from the current app, instead let
117
142
  # bundler suss it out itself for each deployed
118
143
  # app. Otherwise, they'll end up sharing this Gemfile, which
119
- # is probably not what we want.
120
- ENV.delete('BUNDLE_GEMFILE')
121
- exec_command(run_command_line)
122
- trap("INT", old_trap )
144
+ # is probably not what we want.
145
+ ENV.delete('BUNDLE_GEMFILE')
146
+
147
+ exec_command(run_command_line(options).join(' '))
123
148
  end
124
149
  end
125
150
 
126
-
127
151
  def create_archive(archive = archive_name, app_dir = Dir.pwd, dest_dir = Dir.pwd)
128
152
  skip_files = %w{ ^log$ ^tmp$ ^test$ ^spec$ \.knob$ vendor }
129
153
 
@@ -159,17 +183,18 @@ module TorqueBox
159
183
  end
160
184
 
161
185
  def basic_deployment_descriptor(options = {})
162
- env = options[:env]
186
+ env = options[:env] || options['env']
163
187
  env ||= defined?(RACK_ENV) ? RACK_ENV : ENV['RACK_ENV']
164
188
  env ||= defined?(::Rails) ? ::Rails.env : ENV['RAILS_ENV']
165
189
 
166
- root = options[:root] || Dir.pwd
167
- context_path = options[:context_path]
190
+ root = options[:root] || options['root'] || Dir.pwd
191
+ context_path = options[:context_path] || options['context_path']
168
192
 
169
193
  d = {}
170
194
  d['application'] = {}
171
195
  d['application']['root'] = root
172
- d['application']['env'] = env.to_s if env
196
+ d['environment'] = {}
197
+ d['environment']['RACK_ENV'] = env.to_s if env
173
198
 
174
199
  if !context_path &&
175
200
  !(File.exists?( File.join( root, "torquebox.yml" )) ||
@@ -190,46 +215,49 @@ module TorqueBox
190
215
  File.open( deployment, 'w' ) do |file|
191
216
  YAML.dump( deployment_descriptor, file )
192
217
  end
218
+ FileUtils.touch( dodeploy_file( name ) )
193
219
  [name, dest_dir]
194
220
  end
195
221
 
196
222
  def deploy_archive(archive_path = nil, dest_dir = deploy_dir)
197
223
  archive_path ||= File.join( Dir.pwd, archive_name )
198
224
  FileUtils.cp( archive_path, dest_dir )
199
- [File.basename( archive_path ), dest_dir]
225
+ archive = File.basename( archive_path )
226
+ FileUtils.touch( dodeploy_file( archive ) )
227
+ [archive, dest_dir]
228
+ end
229
+
230
+ def dodeploy_file( name )
231
+ File.join( DeployUtils.deploy_dir, "#{name}" ) + ".dodeploy"
232
+ end
233
+
234
+ def deployed_file( name )
235
+ File.join( DeployUtils.deploy_dir, "#{name}" ) + ".deployed"
200
236
  end
201
237
 
202
238
  def undeploy(name = deployment_name, from_dir = deploy_dir)
203
239
  deployment = File.join( from_dir, name )
240
+ undeployed = false
241
+ if File.exists?( dodeploy_file( name ) )
242
+ FileUtils.rm_rf( dodeploy_file( name ) )
243
+ undeployed = true
244
+ end
245
+ if File.exists?( deployed_file( name ) )
246
+ FileUtils.rm_rf( deployed_file( name ) )
247
+ undeployed = true
248
+ end
204
249
  if File.exists?( deployment )
205
250
  FileUtils.rm_rf( deployment )
251
+ undeployed = true
252
+ end
253
+
254
+ if undeployed
206
255
  [name, from_dir]
207
256
  else
208
- nil
257
+ puts "Can't undeploy #{deployment}. It does not appear to be deployed."
209
258
  end
210
259
  end
211
260
 
212
- def write_credentials(user_data)
213
- properties_file = "#{properties_dir}/torquebox-users.properties"
214
- users = File.readlines( properties_file ).inject( {} ) do |accum, line|
215
- user, pass = line.split( '=' )
216
- accum[user] = pass
217
- accum
218
- end
219
-
220
- users = user_data.inject( users ) do |accum, user|
221
- accum[user[0]] = user[1]
222
- accum
223
- end
224
-
225
- File.open( properties_file, 'w' ) do |file|
226
- users.each do |user, pass|
227
- file.puts( "#{user}=#{pass}" )
228
- end
229
- end
230
- properties_file
231
- end
232
-
233
261
  # TODO: This is not windows friendly
234
262
  def create_symlink
235
263
  unless File.exist? opt_dir
@@ -257,6 +285,10 @@ module TorqueBox
257
285
 
258
286
  def exec_command(cmd)
259
287
  IO.popen4( cmd ) do |pid, stdin, stdout, stderr|
288
+ trap("INT") do
289
+ puts "caught SIGINT, shutting down"
290
+ `taskkill /F /T /PID #{pid}` if windows?
291
+ end
260
292
  stdin.close
261
293
  [
262
294
  Thread.new(stdout) {|stdout_io|
@@ -278,7 +310,11 @@ module TorqueBox
278
310
 
279
311
  end
280
312
 
313
+ def windows?
314
+ Config::CONFIG['host_os'] =~ /mswin/
315
+ end
281
316
 
282
317
  end
283
318
  end
284
319
  end
320
+
@@ -1,4 +1,4 @@
1
- # Copyright 2011 Red Hat, Inc, and individual contributors.
1
+ # Copyright 2008-2011 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
@@ -15,8 +15,7 @@
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
-
19
- # Helpers for upstart rake tasks
18
+ # Helpers for launchd rake tasks
20
19
 
21
20
  require 'torquebox/deploy_utils'
22
21
 
@@ -24,18 +23,63 @@ module TorqueBox
24
23
  module Launchd
25
24
  class << self
26
25
 
26
+ def log_dir
27
+ File.join( TorqueBox::DeployUtils.jboss_home, 'standalone', 'logs' )
28
+ end
29
+
30
+ def plist_template
31
+ File.join( plist_dir, 'TorqueBoxAgent.plist.template' )
32
+ end
33
+
34
+ def plist_file
35
+ File.join( plist_dir, 'TorqueBoxAgent.plist' )
36
+ end
37
+
27
38
  def plist_dir
28
- # TODO
39
+ File.join( TorqueBox::DeployUtils.torquebox_home, 'share', 'init' )
29
40
  end
30
41
 
31
42
  def check_install
32
- TorqueBox::DeployUtils.check_opt_torquebox
33
- # raise "#{init_torquebox} not installed in #{init_dir}" unless ( File.exist?( init_torquebox ) )
34
- # puts "TorqueBox init scripts OK: #{init_torquebox}"
43
+ raise "#{plist_file} not installed in #{plist_dir}" unless ( File.exist?( plist_file ) )
44
+ puts "TorqueBox plist scripts OK: #{plist_file}."
45
+
46
+ launchctl_found = false; IO.popen( 'launchctl list | grep torquebox' ) do |output|
47
+ output.each do |line|
48
+ if line =~ /torquebox/
49
+ puts "TorqueBox launchd script OK: #{line}"
50
+ launchctl_found = true
51
+ break
52
+ end
53
+ end
54
+ end
55
+
56
+ raise "TorqueBox launchd script not found in launchctl." unless launchctl_found
57
+
35
58
  end
36
-
59
+
60
+ def install
61
+ unless File.writable?( plist_dir )
62
+ raise "Cannot write launchd configuration to #{plist_dir}. You'll need to copy #{plist_file} to #{plist_dir} yourself."
63
+ end
64
+
65
+ File.delete( plist_file ) if File.exists? plist_file
66
+ lines = File.open( plist_template, 'r' ) { |f| f.readlines }
67
+ File.open( plist_file, 'w' ) do |file|
68
+ lines.each do |line|
69
+ if line =~ /\$\{TORQUEBOX_HOME\}/
70
+ file.puts( line.sub( /\$\{TORQUEBOX_HOME\}/, TorqueBox::DeployUtils.torquebox_home ) )
71
+ else
72
+ file.puts line
73
+ end
74
+ end
75
+ end
76
+ puts "Created launchd plist #{plist_file}, loading now."
77
+ TorqueBox::DeployUtils.exec_command "launchctl load #{plist_file}"
78
+ check_install
79
+ FileUtils.mkdir_p log_dir, :mode => 0755 unless File.exists? log_dir
80
+ end
81
+
37
82
  end
38
83
  end
39
84
  end
40
85
 
41
-
@@ -35,31 +35,31 @@ namespace :torquebox do
35
35
  end
36
36
 
37
37
  namespace :launchd do
38
- # desc "Check if TorqueBox is installed as a launchd daemon"
38
+
39
+ desc "Check if TorqueBox is installed as a launchd daemon"
39
40
  task :check=>[ 'torquebox:check' ] do
40
41
  TorqueBox::Launchd.check_install
41
- puts "Launchd tasks not done yet. Try again with a later build."
42
42
  end
43
43
 
44
- # desc "Install TorqueBox as an launchd daemon"
44
+ desc "Install TorqueBox as an launchd daemon"
45
45
  task :install=>[ 'torquebox:check' ] do
46
- TorqueBox::DeployUtils.create_symlink
47
- puts "Launchd tasks not done yet. Try again with a later build."
46
+ TorqueBox::Launchd.install
48
47
  end
49
48
 
50
- # desc "Start TorqueBox when running as a launchd daemon"
49
+ desc "Start TorqueBox when running as a launchd daemon"
51
50
  task :start=>[ :check ] do
52
- puts "Launchd tasks not done yet. Try again with a later build."
51
+ TorqueBox::DeployUtils.exec_command( 'launchctl start org.torquebox.TorqueBox' )
53
52
  end
54
53
 
55
- # desc "Stop TorqueBox when running as an launchd daemon"
54
+ desc "Stop TorqueBox when running as an launchd daemon"
56
55
  task :stop=>[ :check ] do
57
- puts "Launchd tasks not done yet. Try again with a later build."
56
+ TorqueBox::DeployUtils.exec_command( 'launchctl stop org.torquebox.TorqueBox' )
58
57
  end
59
58
 
60
- # desc "Restart TorqueBox when running as an launchd daemon"
59
+ desc "Restart TorqueBox when running as an launchd daemon"
61
60
  task :restart=>[ :check ] do
62
- puts "Launchd tasks not done yet. Try again with a later build."
61
+ TorqueBox::DeployUtils.exec_command( 'launchctl stop org.torquebox.TorqueBox' )
62
+ TorqueBox::DeployUtils.exec_command( 'launchctl start org.torquebox.TorqueBox' )
63
63
  end
64
64
 
65
65
  end
@@ -68,7 +68,7 @@ namespace :torquebox do
68
68
  desc "Check if TorqueBox is installed as an upstart service"
69
69
  task :check=>[ 'torquebox:check' ] do
70
70
  TorqueBox::Upstart.check_install
71
- puts "TorqueBox is installed as an upstart service at #{TorqueBox::Upstart.opt_torquebox}"
71
+ puts "TorqueBox is installed as an upstart service at #{TorqueBox::DeployUtils.opt_torquebox}"
72
72
  end
73
73
 
74
74
  desc "Install TorqueBox as an upstart service"
@@ -19,4 +19,3 @@ require 'torquebox/deploy_utils'
19
19
  require 'torquebox/rake/tasks/server'
20
20
  require 'torquebox/rake/tasks/deployment'
21
21
  require 'torquebox/rake/tasks/archive'
22
- require 'torquebox/rake/tasks/auth'
@@ -0,0 +1,50 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ require 'java'
19
+ require 'rubygems'
20
+
21
+ module TorqueBox
22
+ class Server
23
+
24
+ def self.torquebox_home
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
+ home = Gem.searcher.find( 'torquebox-server' )
28
+ else
29
+ home = Gem::Specification.find_by_name( 'torquebox-server' )
30
+ end
31
+ home.full_gem_path if home
32
+ rescue Exception => e
33
+ puts "Cannot find torquebox-server: #{e}"
34
+ nil
35
+ end
36
+
37
+ def self.jboss_home
38
+ File.join(torquebox_home, 'jboss') if torquebox_home
39
+ end
40
+
41
+ def self.jruby_home
42
+ File.expand_path(java.lang.System.getProperty('jruby.home'))
43
+ end
44
+
45
+ def self.gem_version
46
+ Gem::Version.new( Gem::VERSION )
47
+ end
48
+ end
49
+
50
+ end
@@ -1,4 +1,4 @@
1
- # Copyright 2011 Red Hat, Inc, and individual contributors.
1
+ # Copyright 2008-2011 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
@@ -15,7 +15,6 @@
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
-
19
18
  # Helpers for upstart rake tasks
20
19
 
21
20
  require 'torquebox/deploy_utils'
@@ -1,5 +1,5 @@
1
- GNU LESSER GENERAL PUBLIC LICENSE
2
- Version 2.1, February 1999
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 2.1, February 1999
3
3
 
4
4
  Copyright (C) 1991, 1999 Free Software Foundation, Inc.
5
5
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -10,7 +10,7 @@
10
10
  as the successor of the GNU Library Public License, version 2, hence
11
11
  the version number 2.1.]
12
12
 
13
- Preamble
13
+ Preamble
14
14
 
15
15
  The licenses for most software are designed to take away your
16
16
  freedom to share and change it. By contrast, the GNU General Public
@@ -112,7 +112,7 @@ modification follow. Pay close attention to the difference between a
112
112
  former contains code derived from the library, whereas the latter must
113
113
  be combined with the library in order to run.
114
114
 
115
- GNU LESSER GENERAL PUBLIC LICENSE
115
+ GNU LESSER GENERAL PUBLIC LICENSE
116
116
  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
117
117
 
118
118
  0. This License Agreement applies to any software library or other
@@ -146,7 +146,7 @@ such a program is covered only if its contents constitute a work based
146
146
  on the Library (independent of the use of the Library in a tool for
147
147
  writing it). Whether that is true depends on what the Library does
148
148
  and what the program that uses the Library does.
149
-
149
+
150
150
  1. You may copy and distribute verbatim copies of the Library's
151
151
  complete source code as you receive it, in any medium, provided that
152
152
  you conspicuously and appropriately publish on each copy an
@@ -432,7 +432,7 @@ decision will be guided by the two goals of preserving the free status
432
432
  of all derivatives of our free software and of promoting the sharing
433
433
  and reuse of software generally.
434
434
 
435
- NO WARRANTY
435
+ NO WARRANTY
436
436
 
437
437
  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
438
438
  WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
@@ -455,7 +455,7 @@ FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
455
455
  SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
456
456
  DAMAGES.
457
457
 
458
- END OF TERMS AND CONDITIONS
458
+ END OF TERMS AND CONDITIONS
459
459
 
460
460
  How to Apply These Terms to Your New Libraries
461
461
 
@@ -500,5 +500,3 @@ necessary. Here is a sample; alter the names:
500
500
  Ty Coon, President of Vice
501
501
 
502
502
  That's all there is to it!
503
-
504
-
@@ -0,0 +1,313 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ describe TorqueBox::DeployUtils do
20
+ before(:each) do
21
+ @util = TorqueBox::DeployUtils
22
+ end
23
+
24
+ describe '.jboss_home' do
25
+ extend PathHelper
26
+
27
+ before( :each ) do
28
+ ENV['TORQUEBOX_HOME'] = '/torquebox'
29
+ ENV['JBOSS_HOME'] = ENV['TORQUEBOX_HOME'] + '/jboss'
30
+ end
31
+
32
+ it 'should use JBOSS_HOME environment if it is set' do
33
+ @util.jboss_home.downcase.should == "#{absolute_prefix}/torquebox/jboss".downcase
34
+ end
35
+
36
+ it 'should use TORQUEBOX_HOME environment if JBOSS_HOME is not set' do
37
+ ENV['JBOSS_HOME'] = nil
38
+ @util.jboss_home.downcase.should == "#{absolute_prefix}/torquebox/jboss".downcase
39
+ end
40
+
41
+ it 'should raise an error if neither JBOSS_HOME or TORQUEBOX_HOME is set' do
42
+ ENV['JBOSS_HOME'] = nil
43
+ ENV['TORQUEBOX_HOME'] = nil
44
+ lambda { @util.jboss_home }.should raise_error
45
+ end
46
+
47
+ end
48
+
49
+ describe '.torquebox_home' do
50
+ extend PathHelper
51
+
52
+ it 'should return nil if TORQUEBOX_HOME is not set and torquebox-server is not installed' do
53
+ ENV['TORQUEBOX_HOME'] = nil
54
+ TorqueBox::Server.should_receive( :torquebox_home ).and_return( nil )
55
+ @util.torquebox_home.should == nil
56
+ end
57
+
58
+ it 'should use torquebox-server if TORQUEBOX_HOME is not set and torquebox-server is installed' do
59
+ ENV['TORQUEBOX_HOME'] = nil
60
+ TorqueBox::Server.should_receive( :torquebox_home ).and_return( 'torquebox-server-install-path' )
61
+ @util.torquebox_home.should == 'torquebox-server-install-path'
62
+ end
63
+
64
+ it 'should use TORQUEBOX_HOME environment variable' do
65
+ ENV['TORQUEBOX_HOME'] = '/torquebox'
66
+ @util.torquebox_home.downcase.should == "#{absolute_prefix}/torquebox".downcase
67
+ end
68
+
69
+ end
70
+
71
+ describe '.jboss_conf' do
72
+ extend PathHelper
73
+ it 'should defafult to "standalone"' do
74
+ @util.jboss_conf.should == 'standalone'
75
+ end
76
+
77
+ it 'should use ENV["JBOSS_CONF"] if it exists' do
78
+ ENV['JBOSS_CONF'] = 'domain'
79
+ @util.jboss_conf.should == ENV['JBOSS_CONF']
80
+ end
81
+
82
+ it 'should use ENV["TORQUEBOX_CONF"] if it exists' do
83
+ ENV['TORQUEBOX_CONF'] = 'foobar'
84
+ @util.jboss_conf.should == ENV['TORQUEBOX_CONF']
85
+ end
86
+
87
+ it 'should prefer ENV["TORQUEBOX_CONF"] if it exists over ENV["JBOSS_CONF"]' do
88
+ ENV['JBOSS_CONF'] = 'domain'
89
+ ENV['TORQUEBOX_CONF'] = 'foobar'
90
+ @util.jboss_conf.should == ENV['TORQUEBOX_CONF']
91
+ end
92
+ end
93
+
94
+ describe '.sys_root' do
95
+ extend PathHelper
96
+ it 'should be /' do
97
+ @util.sys_root.should == '/'
98
+ end
99
+ end
100
+
101
+ describe '.opt_dir' do
102
+ extend PathHelper
103
+ it 'should be /opt' do
104
+ @util.opt_dir.should == '/opt'
105
+ end
106
+ end
107
+
108
+ describe '.opt_torquebox' do
109
+ extend PathHelper
110
+ it 'should be /opt' do
111
+ @util.opt_torquebox.should == '/opt/torquebox'
112
+ end
113
+ end
114
+
115
+ describe '.server_dir' do
116
+ extend PathHelper
117
+ it 'should default to ENV["JBOSS_HOME"]/standalone' do
118
+ ENV['JBOSS_HOME'] = '/opt/torquebox/jboss'
119
+ ENV['JBOSS_CONF'] = nil
120
+ ENV['TORQUEBOX_CONF'] = nil
121
+ @util.server_dir.downcase.should == "#{absolute_prefix}/opt/torquebox/jboss/standalone".downcase
122
+ end
123
+
124
+ it 'should use ENV["JBOSS_HOME"]/ENV["JBOSS_CONF"] if JBOSS_CONF is available' do
125
+ ENV['JBOSS_HOME'] = '/opt/torquebox/jboss'
126
+ ENV['JBOSS_CONF'] = 'foobar'
127
+ ENV['TORQUEBOX_CONF'] = nil
128
+ @util.server_dir.downcase.should == "#{absolute_prefix}/opt/torquebox/jboss/foobar".downcase
129
+ end
130
+
131
+ it 'should use ENV["JBOSS_HOME"]/ENV["TORQUEBOX_CONF"] if TORQUEBOX_CONF is available' do
132
+ ENV['JBOSS_HOME'] = '/opt/torquebox/jboss'
133
+ ENV['JBOSS_CONF'] = 'foobar'
134
+ ENV['TORQUEBOX_CONF'] = 'boofar'
135
+ @util.server_dir.downcase.should == "#{absolute_prefix}/opt/torquebox/jboss/boofar".downcase
136
+ end
137
+ end
138
+
139
+ describe '.config_dir' do
140
+ extend PathHelper
141
+ before( :each ) do
142
+ ENV['TORQUEBOX_HOME'] = '/opt/torquebox'
143
+ ENV['JBOSS_HOME'] = '/opt/torquebox/jboss'
144
+ ENV['JBOSS_CONF'] = nil
145
+ ENV['TORQUEBOX_CONF'] = nil
146
+ end
147
+
148
+ it 'should be ENV["JBOSS_HOME"]/standalone/configuration' do
149
+ @util.config_dir.downcase.should == "#{absolute_prefix}#{ENV['JBOSS_HOME']}/standalone/configuration".downcase
150
+ end
151
+
152
+ it 'should be ENV["JBOSS_HOME"]/standalone/configuration/torquebox/standalone-preview-ha.xml' do
153
+ @util.cluster_config_file.downcase.should == "#{absolute_prefix}#{ENV['JBOSS_HOME']}/standalone/configuration/torquebox/standalone-preview-ha.xml".downcase
154
+ end
155
+ end
156
+
157
+
158
+ describe '.properties_dir' do
159
+ extend PathHelper
160
+ before( :each ) do
161
+ ENV['TORQUEBOX_HOME'] = '/opt/torquebox'
162
+ ENV['JBOSS_HOME'] = '/opt/torquebox/jboss'
163
+ ENV['JBOSS_CONF'] = nil
164
+ ENV['TORQUEBOX_CONF'] = nil
165
+ end
166
+
167
+ it 'should be ENV["JBOSS_HOME"]/standalone/configuration' do
168
+ @util.properties_dir.downcase.should == "#{absolute_prefix}#{ENV['JBOSS_HOME']}/standalone/configuration".downcase
169
+ end
170
+
171
+ it 'should be the same as @util.config_dir' do
172
+ @util.properties_dir.downcase.should == @util.config_dir.downcase
173
+ end
174
+ end
175
+
176
+ describe '.deploy_dir' do
177
+ extend PathHelper
178
+ before( :each ) do
179
+ ENV['JBOSS_HOME'] = '/opt/torquebox/jboss'
180
+ ENV['JBOSS_CONF'] = nil
181
+ ENV['TORQUEBOX_CONF'] = nil
182
+ end
183
+ it 'should point to JBOSS_HOME/JBOSS_CONF/deployments' do
184
+ @util.deploy_dir.downcase.should == "#{absolute_prefix}#{ENV['JBOSS_HOME']}/standalone/deployments".downcase
185
+ end
186
+ end
187
+
188
+ describe '.modules_dir' do
189
+ extend PathHelper
190
+
191
+ before( :each ) do
192
+ ENV['TORQUEBOX_HOME'] = '/torquebox'
193
+ ENV['JBOSS_HOME'] = ENV['TORQUEBOX_HOME'] + '/jboss'
194
+ end
195
+
196
+ it 'should be where I expect it to be' do
197
+ @util.modules_dir.downcase.should == "#{absolute_prefix}/torquebox/jboss/modules".downcase
198
+ end
199
+
200
+ end
201
+
202
+ describe '.torquebox_modules_dir' do
203
+ extend PathHelper
204
+
205
+ before( :each ) do
206
+ ENV['TORQUEBOX_HOME'] = '/torquebox'
207
+ ENV['JBOSS_HOME'] = ENV['TORQUEBOX_HOME'] + '/jboss'
208
+ end
209
+
210
+ it 'should be where I expect it to be' do
211
+ @util.torquebox_modules_dir.downcase.should == "#{absolute_prefix}/torquebox/jboss/modules/org/torquebox".downcase
212
+ end
213
+
214
+ end
215
+
216
+ describe '.check_server' do
217
+ context "when it can't find the modules" do
218
+ before(:each) do
219
+ File.stub(:exist?).and_return(false)
220
+ end
221
+
222
+ it "should raise if it can't find the torquebox modules" do
223
+ lambda { @util.check_server }.should raise_error
224
+ end
225
+
226
+ it "should give a helpful error message" do
227
+ begin
228
+ @util.check_server
229
+ rescue Exception => e
230
+ e.message.should =~ %r{doesn't appear to be a valid TorqueBox install}
231
+ end
232
+ end
233
+ end
234
+ end
235
+
236
+ describe '.run_server' do
237
+ before( :each ) do
238
+ ENV['TORQUEBOX_HOME'] = '/torquebox'
239
+ ENV['JBOSS_HOME'] = ENV['TORQUEBOX_HOME'] + '/jboss'
240
+ Dir.stub!(:chdir).and_yield
241
+ Kernel.stub!(:exec)
242
+ @util.stub!(:exec)
243
+ @util.stub!(:exec_command)
244
+ end
245
+
246
+ it 'should pass options to run_command_line' do
247
+ options = { :clustered => true, :max_threads => 25 }
248
+ @util.should_receive(:run_command_line).with(options).and_return([])
249
+ @util.run_server(options)
250
+ end
251
+
252
+ it 'should check if the current directory is deployed' do
253
+ @util.should_receive(:is_deployed?).and_return( true )
254
+ @util.run_server
255
+ end
256
+ end
257
+
258
+ describe '.is_deployed?' do
259
+ before( :each ) do
260
+ ENV['TORQUEBOX_HOME'] = '/torquebox'
261
+ ENV['JBOSS_HOME'] = ENV['TORQUEBOX_HOME'] + '/jboss'
262
+ @myapp = @util.deployment_name( 'my-app' )
263
+ end
264
+
265
+ it 'should be false if the app is not deployed' do
266
+ @util.is_deployed?( @myapp ).should be_false
267
+ end
268
+
269
+ it 'should be true if the app has been deployed' do
270
+ File.stub('exists?').with(File.join(@util.torquebox_home, 'apps')).and_return false
271
+ File.stub('exists?').with(File.join(@util.deploy_dir, @myapp)).and_return true
272
+ @util.is_deployed?( @myapp ).should be_true
273
+ end
274
+
275
+ it 'should default to the default deployment_name' do
276
+ @util.should_receive(:deployment_name).and_return @myapp
277
+ @util.is_deployed?
278
+ end
279
+
280
+ end
281
+
282
+ describe '.run_command_line' do
283
+ it 'should not add --server-config when not clustered' do
284
+ command, options = @util.run_command_line(:clustered => false)
285
+ options.should_not include('--server-config=')
286
+ end
287
+
288
+ it 'should add --server-config when clustered' do
289
+ command, options = @util.run_command_line(:clustered => true)
290
+ options.should include('--server-config=')
291
+ end
292
+
293
+ it 'should not set max threads by default' do
294
+ command, options = @util.run_command_line
295
+ options.should_not include('-Dorg.torquebox.web.http.maxThreads=')
296
+ end
297
+
298
+ it 'should set max threads when given' do
299
+ command, options = @util.run_command_line(:max_threads => 5)
300
+ options.should include('-Dorg.torquebox.web.http.maxThreads=5')
301
+ end
302
+
303
+ it 'should not set bind address by default' do
304
+ command, options = @util.run_command_line
305
+ options.should_not include('-b ')
306
+ end
307
+
308
+ it 'should set bind address when given' do
309
+ command, options = @util.run_command_line(:bind_address => '0.0.0.0')
310
+ options.should include('-b 0.0.0.0')
311
+ end
312
+ end
313
+ end
@@ -0,0 +1,39 @@
1
+ require 'torquebox/server'
2
+
3
+ describe TorqueBox::Server do
4
+
5
+ it "should expand relative paths" do
6
+ java.lang.System.setProperty('jruby.home', '.')
7
+ TorqueBox::Server.jruby_home.should == Dir.pwd
8
+ end
9
+
10
+ it "should return nil if torquebox-server is not installed" do
11
+ TorqueBox::Server.torquebox_home.should == nil
12
+ end
13
+
14
+ describe "under jruby-1.6.5" do
15
+ it "should use torquebox-server gem's installed path" do
16
+ server_gem = mock('server-gem')
17
+ Gem::Specification.should_receive(:find_by_name).with('torquebox-server').and_return(server_gem)
18
+ server_gem.stub('full_gem_path').and_return('torquebox-server-install-path')
19
+ TorqueBox::Server.torquebox_home.should == 'torquebox-server-install-path'
20
+ end
21
+ end
22
+
23
+ describe "under jruby-1.6.4" do
24
+ it "should use Gem.searcher to find the torquebox-server install path" do
25
+ # make rubygems lie to us
26
+ old_gems = Gem::Version.new( '1.5.1' )
27
+ TorqueBox::Server.stub!( :gem_version ).and_return( old_gems )
28
+
29
+ # mocks for rubygems
30
+ server_gem = mock('server-gem')
31
+ searcher = mock('searcher')
32
+ Gem.stub!(:searcher).and_return(searcher)
33
+ searcher.stub!('find').and_return(server_gem)
34
+ server_gem.stub('full_gem_path').and_return('torquebox-server-install-path')
35
+
36
+ TorqueBox::Server.torquebox_home.should == 'torquebox-server-install-path'
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,64 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+
18
+ require 'java'
19
+
20
+ $: << File.dirname(__FILE__) + '/../lib'
21
+
22
+ require 'torquebox-rake-support'
23
+
24
+ TESTING_ON_WINDOWS = ( java.lang::System.getProperty( "os.name" ) =~ /windows/i )
25
+
26
+ module PathHelper
27
+ def self.extended(cls)
28
+ cls.class_eval do
29
+
30
+ def pwd()
31
+ self.class.pwd
32
+ end
33
+
34
+ def self.pwd()
35
+ ::Dir.pwd
36
+ end
37
+
38
+ def absolute_prefix
39
+ self.class.absolute_prefix
40
+ end
41
+
42
+ def self.absolute_prefix
43
+ return '' unless ( TESTING_ON_WINDOWS )
44
+ 'C:'
45
+ end
46
+
47
+ def vfs_path(path)
48
+ self.class.vfs_path( path )
49
+ end
50
+
51
+ def self.vfs_path(path)
52
+ return path if ( path[0,4] == 'vfs:' )
53
+ return "vfs:#{path}" if ( path[0,1] == '/' )
54
+ return "vfs:#{path}" if ( path[0,1] == '\\' )
55
+ return vfs_path( "/#{path}" ) if ( path =~ %r(^[a-zA-Z]:) )
56
+ return vfs_path( File.join( pwd, path ) )
57
+ end
58
+
59
+
60
+ end
61
+
62
+ end
63
+ end
64
+
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torquebox-rake-support
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.1.1
4
+ prerelease: 6
5
+ version: 2.0.0.beta1
6
6
  platform: ruby
7
7
  authors:
8
8
  - The TorqueBox Team
@@ -10,10 +10,33 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-08-09 00:00:00 -04:00
14
- default_executable:
15
- dependencies: []
16
-
13
+ date: 2011-12-02 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.8.7
24
+ - - <
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ type: :runtime
28
+ version_requirements: *id001
29
+ - !ruby/object:Gem::Dependency
30
+ name: rspec
31
+ prerelease: false
32
+ requirement: &id002 !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - "="
36
+ - !ruby/object:Gem::Version
37
+ version: 2.7.0
38
+ type: :development
39
+ version_requirements: *id002
17
40
  description: ""
18
41
  email:
19
42
  - torquebox-dev@torquebox.org
@@ -29,17 +52,19 @@ files:
29
52
  - lib/torquebox-rake-support.rb
30
53
  - lib/torquebox/deploy_utils.rb
31
54
  - lib/torquebox/launchd.rb
55
+ - lib/torquebox/server.rb
32
56
  - lib/torquebox/upstart.rb
33
57
  - lib/torquebox/rake/tasks.rb
34
58
  - lib/torquebox/rake/tasks/archive.rb
35
- - lib/torquebox/rake/tasks/auth.rb
36
59
  - lib/torquebox/rake/tasks/deployment.rb
37
60
  - lib/torquebox/rake/tasks/server.rb
38
61
  - generators/USAGE
39
62
  - generators/torquebox_queue_generator.rb
40
63
  - generators/templates/queue.rb
41
- has_rdoc: true
42
- homepage: http://www.torquebox.org/torquebox-rake-support/
64
+ - spec/deploy_utils_spec.rb
65
+ - spec/server_spec.rb
66
+ - spec/spec_helper.rb
67
+ homepage: http://www.torquebox.org/torquebox-gems-parent/torquebox-rake-support/
43
68
  licenses:
44
69
  - lgpl
45
70
  post_install_message:
@@ -56,15 +81,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
81
  required_rubygems_version: !ruby/object:Gem::Requirement
57
82
  none: false
58
83
  requirements:
59
- - - ">="
84
+ - - ">"
60
85
  - !ruby/object:Gem::Version
61
- version: "0"
86
+ version: 1.3.1
62
87
  requirements: []
63
88
 
64
89
  rubyforge_project:
65
- rubygems_version: 1.5.1
90
+ rubygems_version: 1.8.9
66
91
  signing_key:
67
92
  specification_version: 3
68
93
  summary: TorqueBox Rake Support
69
- test_files: []
70
-
94
+ test_files:
95
+ - spec/deploy_utils_spec.rb
96
+ - spec/server_spec.rb
@@ -1,32 +0,0 @@
1
- # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
- #
3
- # This is free software; you can redistribute it and/or modify it
4
- # under the terms of the GNU Lesser General Public License as
5
- # published by the Free Software Foundation; either version 2.1 of
6
- # the License, or (at your option) any later version.
7
- #
8
- # This software is distributed in the hope that it will be useful,
9
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
- # Lesser General Public License for more details.
12
- #
13
- # You should have received a copy of the GNU Lesser General Public
14
- # License along with this software; if not, write to the Free
15
- # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
- # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
-
18
- require 'rake'
19
- require 'torquebox/deploy_utils'
20
-
21
- namespace :torquebox do
22
-
23
- namespace :auth do
24
- desc "Add a username and password to the torquebox-auth security realm with CREDENTIALS=user:pass"
25
- task :adduser do
26
- abort "Provide credentials as rake torquebox:auth:adduser CREDENTIALS=user:pass" unless ENV['CREDENTIALS']
27
- properties_file = TorqueBox::DeployUtils.write_credentials( [ENV['CREDENTIALS'].split( ':' )] )
28
- puts "Credentials written to #{properties_file}"
29
- end
30
- end
31
- end
32
-