torquebox-rake-support 2.0.0.beta1 → 2.0.0.beta2

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.
@@ -1,4 +1,4 @@
1
- # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
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
@@ -1,4 +1,4 @@
1
- # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
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
@@ -70,7 +70,7 @@ module TorqueBox
70
70
  end
71
71
 
72
72
  def cluster_config_file
73
- File.join(config_dir, 'torquebox', "standalone-preview-ha.xml")
73
+ "standalone-ha.xml"
74
74
  end
75
75
 
76
76
  def properties_dir
@@ -98,12 +98,12 @@ module TorqueBox
98
98
  File.join( modules_dir, 'org', 'torquebox' )
99
99
  end
100
100
 
101
- def archive_name(root=Dir.pwd)
102
- File.basename( root ) + '.knob'
101
+ def archive_name(root = Dir.pwd)
102
+ normalize_archive_name( File.basename( root || Dir.pwd ) )
103
103
  end
104
104
 
105
105
  def deployment_name(root = Dir.pwd)
106
- File.basename( root ) + '-knob.yml'
106
+ normalize_yaml_name( File.basename( root || Dir.pwd ) )
107
107
  end
108
108
 
109
109
  def check_server
@@ -148,7 +148,11 @@ module TorqueBox
148
148
  end
149
149
  end
150
150
 
151
- def create_archive(archive = archive_name, app_dir = Dir.pwd, dest_dir = Dir.pwd)
151
+ def create_archive(opts = {})
152
+
153
+ archive = normalize_archive_name( find_option( opts, 'name' ) || archive_name )
154
+ app_dir = find_option( opts, 'app_dir') || Dir.pwd
155
+ dest_dir = find_option( opts, 'dest_dir') || Dir.pwd
152
156
  skip_files = %w{ ^log$ ^tmp$ ^test$ ^spec$ \.knob$ vendor }
153
157
 
154
158
  archive_path = File.join(dest_dir, archive)
@@ -185,7 +189,7 @@ module TorqueBox
185
189
  def basic_deployment_descriptor(options = {})
186
190
  env = options[:env] || options['env']
187
191
  env ||= defined?(RACK_ENV) ? RACK_ENV : ENV['RACK_ENV']
188
- env ||= defined?(::Rails) ? ::Rails.env : ENV['RAILS_ENV']
192
+ env ||= defined?(::Rails) && Rails.respond_to?(:env) ? ::Rails.env : ENV['RAILS_ENV']
189
193
 
190
194
  root = options[:root] || options['root'] || Dir.pwd
191
195
  context_path = options[:context_path] || options['context_path']
@@ -210,7 +214,9 @@ module TorqueBox
210
214
  d
211
215
  end
212
216
 
213
- def deploy_yaml(deployment_descriptor, name = deployment_name, dest_dir = deploy_dir)
217
+ def deploy_yaml(deployment_descriptor, opts = {})
218
+ name = normalize_yaml_name( find_option( opts, 'name' ) || deployment_name(opts[:root] || opts['root']) )
219
+ dest_dir = opts[:dest_dir] || opts['dest_dir'] || deploy_dir
214
220
  deployment = File.join( dest_dir, name )
215
221
  File.open( deployment, 'w' ) do |file|
216
222
  YAML.dump( deployment_descriptor, file )
@@ -219,43 +225,30 @@ module TorqueBox
219
225
  [name, dest_dir]
220
226
  end
221
227
 
222
- def deploy_archive(archive_path = nil, dest_dir = deploy_dir)
223
- archive_path ||= File.join( Dir.pwd, archive_name )
228
+ def deploy_archive(opts = {})
229
+ name = normalize_archive_name( find_option( opts, 'name' ) || archive_name )
230
+ archive_path = find_option( opts, 'archive_path' ) || File.join( Dir.pwd, name )
231
+ dest_dir = find_option( opts, 'dest_dir' ) || deploy_dir
224
232
  FileUtils.cp( archive_path, dest_dir )
225
233
  archive = File.basename( archive_path )
226
234
  FileUtils.touch( dodeploy_file( archive ) )
227
235
  [archive, dest_dir]
228
236
  end
229
237
 
230
- def dodeploy_file( name )
238
+ def dodeploy_file(name)
231
239
  File.join( DeployUtils.deploy_dir, "#{name}" ) + ".dodeploy"
232
240
  end
233
241
 
234
- def deployed_file( name )
242
+ def deployed_file(name)
235
243
  File.join( DeployUtils.deploy_dir, "#{name}" ) + ".deployed"
236
244
  end
237
-
238
- def undeploy(name = deployment_name, from_dir = deploy_dir)
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
249
- if File.exists?( deployment )
250
- FileUtils.rm_rf( deployment )
251
- undeployed = true
252
- end
253
-
254
- if undeployed
255
- [name, from_dir]
256
- else
257
- puts "Can't undeploy #{deployment}. It does not appear to be deployed."
258
- end
245
+
246
+ def undeploy_archive(opts = {})
247
+ undeploy( normalize_archive_name( find_option( opts, 'name' ) || archive_name( opts[:root] ) ), opts )
248
+ end
249
+
250
+ def undeploy_yaml(opts = {})
251
+ undeploy( normalize_yaml_name( find_option( opts, 'name' ) || deployment_name( opts[:root] ) ), opts )
259
252
  end
260
253
 
261
254
  # TODO: This is not windows friendly
@@ -313,6 +306,45 @@ module TorqueBox
313
306
  def windows?
314
307
  Config::CONFIG['host_os'] =~ /mswin/
315
308
  end
309
+
310
+ def find_option(opt, key)
311
+ opt[key.to_sym] || opt[key] || ENV[key] || ENV[key.upcase]
312
+ end
313
+
314
+ def normalize_yaml_name(name)
315
+ name[-9..-1] == '-knob.yml' ? name : name + '-knob.yml'
316
+ end
317
+
318
+ def normalize_archive_name(name)
319
+ name[-5..-1] == '.knob' ? name : name + '.knob'
320
+ end
321
+
322
+ private
323
+
324
+ def undeploy(name, opts = {})
325
+ puts "Attempting to undeploy #{name}"
326
+ from_dir = find_option( opts, 'deploy_dir' ) || deploy_dir
327
+ deployment = File.join( from_dir, name )
328
+ undeployed = false
329
+ if File.exists?( dodeploy_file( name ) )
330
+ FileUtils.rm_rf( dodeploy_file( name ) )
331
+ undeployed = true
332
+ end
333
+ if File.exists?( deployed_file( name ) )
334
+ FileUtils.rm_rf( deployed_file( name ) )
335
+ undeployed = true
336
+ end
337
+ if File.exists?( deployment )
338
+ FileUtils.rm_rf( deployment )
339
+ undeployed = true
340
+ end
341
+
342
+ if undeployed
343
+ [name, from_dir]
344
+ else
345
+ puts "Can't undeploy #{deployment}. It does not appear to be deployed."
346
+ end
347
+ end
316
348
 
317
349
  end
318
350
  end
@@ -1,4 +1,4 @@
1
- # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
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
@@ -0,0 +1,44 @@
1
+ # Copyright 2008-2012 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
+ begin
19
+ require 'rails/generators'
20
+ require 'rails/generators/rails/app/app_generator'
21
+ rescue LoadError
22
+ # Rails isn't installed, bail out
23
+ return
24
+ end
25
+
26
+ module TorqueBox
27
+ class Rails
28
+ def self.new_app
29
+ # Assumes ARGV[0] already has the application name
30
+ ARGV << [ "-m", TorqueBox::Rails.template ]
31
+ ARGV.flatten!
32
+ ::Rails::Generators::AppGenerator.start
33
+ end
34
+
35
+ def self.apply_template( root )
36
+ generator = ::Rails::Generators::AppGenerator.new( [root], {}, :destination_root => root )
37
+ generator.apply TorqueBox::Rails.template
38
+ end
39
+
40
+ def self.template
41
+ "#{ENV['TORQUEBOX_HOME']}/share/rails/template.rb"
42
+ end
43
+ end
44
+ end
@@ -1,4 +1,4 @@
1
- # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
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
@@ -21,9 +21,8 @@ require 'torquebox/deploy_utils'
21
21
  namespace :torquebox do
22
22
 
23
23
  desc "Create a nice self-contained application archive"
24
- task :archive do
25
- puts "Creating archive: #{TorqueBox::DeployUtils.archive_name}"
26
- path = TorqueBox::DeployUtils.create_archive
24
+ task :archive, :name do |t, args|
25
+ path = TorqueBox::DeployUtils.create_archive( args )
27
26
  puts "Created archive: #{path}"
28
27
  end
29
28
 
@@ -1,4 +1,4 @@
1
- # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
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
@@ -21,18 +21,20 @@ require 'torquebox/deploy_utils'
21
21
  namespace :torquebox do
22
22
 
23
23
  desc "Deploy the app in the current directory"
24
- task :deploy, [:context_path] => ['torquebox:check'] do |t, args|
24
+ task :deploy, [:context_path, :name] => ['torquebox:check'] do |t, args|
25
25
  descriptor = TorqueBox::DeployUtils.basic_deployment_descriptor( :context_path => args[:context_path] )
26
- deployment_name, deploy_dir = TorqueBox::DeployUtils.deploy_yaml( descriptor )
26
+ deployment_name, deploy_dir = TorqueBox::DeployUtils.deploy_yaml( descriptor, args )
27
27
 
28
28
  puts "Deployed: #{deployment_name}"
29
29
  puts " into: #{deploy_dir}"
30
30
  end
31
31
 
32
32
  desc "Undeploy the app in the current directory"
33
- task :undeploy=>['torquebox:check'] do
34
- deploy_name, deploy_dir = TorqueBox::DeployUtils.undeploy # try -knob.yml first
35
- deploy_name, deploy_dir = TorqueBox::DeployUtils.undeploy( TorqueBox::DeployUtils.archive_name ) unless deploy_name
33
+ task :undeploy, [:name] => ['torquebox:check'] do |t, args|
34
+ deploy_name, deploy_dir = TorqueBox::DeployUtils.undeploy_yaml( args ) # try -knob.yml first
35
+ unless deploy_name
36
+ deploy_name, deploy_dir = TorqueBox::DeployUtils.undeploy_archive( args )
37
+ end
36
38
 
37
39
  if deploy_name
38
40
  puts "Undeployed: #{deploy_name}"
@@ -44,13 +46,27 @@ namespace :torquebox do
44
46
 
45
47
  desc "Create (if needed) and deploy as application archive"
46
48
  namespace :deploy do
47
- task :archive=>[ 'torquebox:archive' ] do
48
- archive_name, deploy_dir = TorqueBox::DeployUtils.deploy_archive
49
+ task :archive, [:name] => [ 'torquebox:archive' ] do |t, args|
50
+ archive_name, deploy_dir = TorqueBox::DeployUtils.deploy_archive( args )
49
51
 
50
52
  puts "Deployed: #{archive_name}"
51
53
  puts " into: #{deploy_dir}"
52
54
  end
53
55
  end
56
+
57
+ desc "Undeploy an application archive"
58
+ namespace :undeploy do
59
+ task :archive, [:name] => [ 'torquebox:check' ] do |t, args|
60
+ deploy_name, deploy_dir = TorqueBox::DeployUtils.undeploy_archive( args )
61
+
62
+ if deploy_name
63
+ puts "Undeployed: #{deploy_name}"
64
+ puts " from: #{deploy_dir}"
65
+ else
66
+ puts "Nothing to undeploy"
67
+ end
68
+ end
69
+ end
54
70
 
55
71
  end
56
72
 
@@ -1,4 +1,4 @@
1
- # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
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
@@ -1,4 +1,4 @@
1
- # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
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
@@ -1,4 +1,4 @@
1
- # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
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
@@ -45,6 +45,15 @@ module TorqueBox
45
45
  def self.gem_version
46
46
  Gem::Version.new( Gem::VERSION )
47
47
  end
48
+
49
+ def self.setup_environment
50
+ ENV['TORQUEBOX_HOME'] ||= torquebox_home
51
+ ENV['JBOSS_HOME'] ||= "#{ENV['TORQUEBOX_HOME']}/jboss"
52
+ ENV['JRUBY_HOME'] ||= jruby_home
53
+ ENV['JBOSS_OPTS'] ||= "-Djruby.home=#{jruby_home}"
54
+ %w(TORQUEBOX_HOME JBOSS_HOME JRUBY_HOME).each { |key| puts "[ERROR] #{key} is not set. Install torquebox-server gem or manually set #{key}" unless ENV[key] }
55
+ end
56
+
48
57
  end
49
58
 
50
59
  end
@@ -1,4 +1,4 @@
1
- # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
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
@@ -1,4 +1,4 @@
1
- # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
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
@@ -70,7 +70,7 @@ describe TorqueBox::DeployUtils do
70
70
 
71
71
  describe '.jboss_conf' do
72
72
  extend PathHelper
73
- it 'should defafult to "standalone"' do
73
+ it 'should default to "standalone"' do
74
74
  @util.jboss_conf.should == 'standalone'
75
75
  end
76
76
 
@@ -148,10 +148,6 @@ describe TorqueBox::DeployUtils do
148
148
  it 'should be ENV["JBOSS_HOME"]/standalone/configuration' do
149
149
  @util.config_dir.downcase.should == "#{absolute_prefix}#{ENV['JBOSS_HOME']}/standalone/configuration".downcase
150
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
151
  end
156
152
 
157
153
 
data/spec/server_spec.rb CHANGED
@@ -10,6 +10,15 @@ describe TorqueBox::Server do
10
10
  it "should return nil if torquebox-server is not installed" do
11
11
  TorqueBox::Server.torquebox_home.should == nil
12
12
  end
13
+
14
+ describe ".setup_environment" do
15
+ it "should use TORQUEBOX_HOME to determine JBOSS_HOME" do
16
+ ENV["JBOSS_HOME"] = nil
17
+ ENV["TORQUEBOX_HOME"] = "/path/to/torquebox"
18
+ TorqueBox::Server.setup_environment
19
+ ENV["JBOSS_HOME"].should == "/path/to/torquebox/jboss"
20
+ end
21
+ end
13
22
 
14
23
  describe "under jruby-1.6.5" do
15
24
  it "should use torquebox-server gem's installed path" do
data/spec/spec_helper.rb CHANGED
@@ -27,14 +27,6 @@ module PathHelper
27
27
  def self.extended(cls)
28
28
  cls.class_eval do
29
29
 
30
- def pwd()
31
- self.class.pwd
32
- end
33
-
34
- def self.pwd()
35
- ::Dir.pwd
36
- end
37
-
38
30
  def absolute_prefix
39
31
  self.class.absolute_prefix
40
32
  end
@@ -44,19 +36,6 @@ module PathHelper
44
36
  'C:'
45
37
  end
46
38
 
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
39
  end
61
40
 
62
41
  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.beta1
5
+ version: 2.0.0.beta2
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: 2011-12-02 00:00:00 Z
13
+ date: 2012-01-05 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -52,6 +52,7 @@ files:
52
52
  - lib/torquebox-rake-support.rb
53
53
  - lib/torquebox/deploy_utils.rb
54
54
  - lib/torquebox/launchd.rb
55
+ - lib/torquebox/rails.rb
55
56
  - lib/torquebox/server.rb
56
57
  - lib/torquebox/upstart.rb
57
58
  - lib/torquebox/rake/tasks.rb