warbler 0.9.10 → 0.9.11

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,3 +1,21 @@
1
+ == 0.9.11
2
+
3
+ * Auto-detect Rails and Merb and configure appropriately
4
+ - For Rails, set rails booter, determine max runtimes based on Rails.configuration.threadsafe!,
5
+ add Rails gem, detect Rails version, set gems to be packaged based on
6
+ Rails.configuration.gems if available
7
+ - Rails gems only added if Rails application detected
8
+ - For Merb, set merb booter automatically
9
+ * Auto-detect config.ru rackup script and pass it into config.webxml.rackup
10
+ * rails.env now commented by default in config/warble.rb and internally default
11
+ the value to 'production'
12
+ * Default directories in config.dirs to only those that are found to be present
13
+ * Allow config.gems array to contain regexps and Gem::Dependency objects as well
14
+ (assist from Jani Soila)
15
+ * Fix bug ensuring you can += and -= for config.gems
16
+ * Upgrade to JRuby 1.1.4 and JRuby-Rack 0.9.2
17
+ * add [] as a way to specify non-identifier keys, example: config.webxml['!@#$%^'] = 'haha'
18
+
1
19
  == 0.9.10
2
20
 
3
21
  * Upgraded to JRuby-Rack 0.9.1. Fixes JRUBY-2620, JRUBY-2594, JRUBY-2507.
@@ -23,7 +41,7 @@
23
41
 
24
42
  == 0.9.5
25
43
 
26
- * Fix bug in plugin warbler.rake task file that would favor loading warbler from gems before the version
44
+ * Fix bug in plugin warbler.rake task file that would favor loading warbler from gems before the version
27
45
  installed as a plugin
28
46
  * Upgrade to JRuby 1.1 final and Goldspike 1.6.1
29
47
 
@@ -9,8 +9,8 @@ generators/warble
9
9
  generators/warble/templates
10
10
  generators/warble/templates/warble.rb
11
11
  generators/warble/warble_generator.rb
12
- lib/jruby-complete-1.1.3.jar
13
- lib/jruby-rack-0.9.1.jar
12
+ lib/jruby-complete-1.1.4.jar
13
+ lib/jruby-rack-0.9.2.jar
14
14
  lib/warbler
15
15
  lib/warbler/config.rb
16
16
  lib/warbler/gems.rb
data/README.txt CHANGED
@@ -1,15 +1,18 @@
1
1
  = Warbler
2
2
 
3
- Warbler is a gem to make a .war file out of a Rails project. The intent is to provide a minimal,
4
- flexible, ruby-like way to bundle up all of your application files for deployment to a Java
5
- application server.
3
+ Warbler is a gem to make a .war file out of a Rails, Merb, or Rack-based
4
+ application. The intent is to provide a minimal, flexible, ruby-like way to
5
+ bundle up all of your application files for deployment to a Java application
6
+ server.
6
7
 
7
- Warbler provides a sane set of out-of-the box defaults that should allow most Rails applications
8
- without external gem dependencies (aside from Rails itself) to assemble and Just Work.
8
+ Warbler provides a sane set of out-of-the box defaults that should allow most
9
+ Rails applications without external gem dependencies (aside from Rails itself)
10
+ to assemble and Just Work.
9
11
 
10
- Warbler bundles JRuby and the JRuby-Rack servlet adapter for dispatching requests to your application inside
11
- the java application server, and assembles all jar files in WARBLER_HOME/lib/*.jar into
12
- your application. No external dependencies are downloaded.
12
+ Warbler bundles JRuby and the JRuby-Rack servlet adapter for dispatching
13
+ requests to your application inside the java application server, and assembles
14
+ all jar files in WARBLER_HOME/lib/*.jar into your application. No external
15
+ dependencies are downloaded.
13
16
 
14
17
  == Getting Started
15
18
 
@@ -19,9 +22,9 @@ your application. No external dependencies are downloaded.
19
22
 
20
23
  == Usage
21
24
 
22
- Warbler's +warble+ command is just a small wrapper around Rake with internally defined tasks. (Notice
23
- "rake" still prints out in the message, but you should substitute "warble" for "rake" on the command
24
- line when running this way.)
25
+ Warbler's +warble+ command is just a small wrapper around Rake with internally
26
+ defined tasks. (Notice "rake" still prints out in the message, but you should
27
+ substitute "warble" for "rake" on the command line when running this way.)
25
28
 
26
29
  $ warble -T
27
30
  rake config # Generate a configuration file to customize your war assembly
@@ -35,50 +38,108 @@ line when running this way.)
35
38
  rake war:public # Copy all public HTML files to the root of the .war
36
39
  rake war:webxml # Generate a web.xml file for the webapp
37
40
 
38
- Warble makes heavy use of Rake's file and directory tasks, so only recently updated files will be
39
- copied, making repeated assemblies much faster.
41
+ Warble makes heavy use of Rake's file and directory tasks, so only recently
42
+ updated files will be copied, making repeated assemblies much faster.
40
43
 
41
44
  == Configuration
42
45
 
43
- The default configuration puts application files (+app+, +config+, +lib+, +log+, +vendor+, +tmp+)
44
- under the .war file's WEB-INF directory, and files in +public+ in the root of the .war file. Any Java
45
- .jar files stored in lib will automatically be placed in WEB-INF/lib for placement on the web app's
46
+ === Rails applications
47
+
48
+ Rails applications are detected automatically and configured appropriately.
49
+ The following items are set up for you:
50
+
51
+ * The Rails gem is packaged if you haven't vendored Rails.
52
+ * Other gems configured in Rails.configuration.gems are packaged (Rails 2.1 or
53
+ later)
54
+ * Multi-thread-safe execution (as introduced in Rails 2.2) is detected and
55
+ runtime pooling is disabled.
56
+
57
+ === Merb applications
58
+
59
+ Merb applications are detected automatically, and the merb gem and its
60
+ dependencies are packaged.
61
+
62
+ === Other Rack-based applications
63
+
64
+ If you have a 'config.ru' file in the top directory of your application, its
65
+ contents will be used as the rackup script for your Rack-based application.
66
+ You will probably need to specify framework and application gems in
67
+ config/warble.rb.
68
+
69
+ See http://github.com/nicksieger/jruby-rack/tree/master/examples for examples
70
+ of how to configure Warbler to package Camping and Sinatra apps.
71
+
72
+ === Configuration auto-detect TODOs
73
+
74
+ * A more accurate way of detecting a Merb application's gems is needed. Until
75
+ then, you will have to specify them in config/warble.rb. See below.
76
+ * Is it possible to more generally detect what gems an application uses?
77
+ Gem.loaded_specs is available, but the application needs to be loaded first
78
+ before its contents are reliable.
79
+
80
+ === Custom configuration
81
+
82
+ The default configuration puts application files (+app+, +config+, +lib+,
83
+ +log+, +vendor+, +tmp+) under the .war file's WEB-INF directory, and files in
84
+ +public+ in the root of the .war file. Any Java .jar files stored in lib will
85
+ automatically be placed in WEB-INF/lib for placement on the web app's
46
86
  classpath.
47
87
 
48
- To customize files, libraries, and gems included in the .war file, you'll need a config/warble.rb
49
- file. There a two ways of doing this. With the gem, simply run
88
+ If the default settings are not appropriate for your application, you can
89
+ customize Warbler's behavior. To customize files, libraries, and gems included
90
+ in the .war file, you'll need a config/warble.rb file. There a two ways of
91
+ doing this. With the gem, simply run
50
92
 
51
93
  warble config
52
94
 
53
95
  If you have Warbler installed as a plugin, use the generator:
54
96
 
55
97
  script/generate warble
56
-
57
- Finally, edit the config/warble.rb to your taste. If you install the gem but later decide you'd like to have it as a plugin, use the +pluginize+ command:
98
+
99
+ Finally, edit the config/warble.rb to your taste. If you install the gem but
100
+ later decide you'd like to have it as a plugin, use the +pluginize+ command:
58
101
 
59
102
  warble pluginize
60
103
 
61
- If you wish to upgrade or switch one or more java libraries from what's bundled in the Warbler gem, simply change the jars in WARBLER_HOME/lib, or modify the +java_libs+ attribute of Warbler::Config to include the files you need.
104
+ If you wish to upgrade or switch one or more java libraries from what's
105
+ bundled in the Warbler gem, simply change the jars in WARBLER_HOME/lib, or
106
+ modify the +java_libs+ attribute of Warbler::Config to include the files you
107
+ need.
62
108
 
63
- Once Warbler is installed as a plugin, you can use +rake+ to build the war (with the same set of tasks as above).
109
+ Once Warbler is installed as a plugin, you can use +rake+ to build the war
110
+ (with the same set of tasks as above).
64
111
 
65
- === Web.xml
112
+ The generated config/warble.rb file is fully-documented with the available
113
+ options and default values.
66
114
 
67
- Java web applications are configured mainly through this file, and Warbler creates a suitable default file for you for use. However, if you need to customize it in any way, you have two options.
115
+ === Web.xml
68
116
 
69
- 1. If you just want a static web.xml file whose contents you manually control, you may copy the one generated for you in <tt>tmp/war/WEB-INF/web.xml</tt> to <tt>config/web.xml</tt>. It will be copied into the webapp for you.
70
- 2. If you want to inject some dynamic information into the file, copy the <tt>WARBLER_HOME/web.xml.erb</tt> to <tt>config/web.xml.erb</tt>. Its contents will be evaluated for you and put in the webapp. Note that you can also pass arbitrary properties to the ERb template by setting <tt>config.webxml.customkey</tt> values in your <tt>config/warble.rb</tt> file.
117
+ Java web applications are configured mainly through this file, and Warbler
118
+ creates a suitable default file for you for use. However, if you need to
119
+ customize it in any way, you have two options.
120
+
121
+ 1. If you just want a static web.xml file whose contents you manually control,
122
+ you may copy the one generated for you in <tt>tmp/war/WEB-INF/web.xml</tt>
123
+ to <tt>config/web.xml</tt> and modify as needed. It will be copied into the
124
+ webapp for you.
125
+ 2. If you want to inject some dynamic information into the file, copy the
126
+ <tt>WARBLER_HOME/web.xml.erb</tt> to <tt>config/web.xml.erb</tt>. Its
127
+ contents will be evaluated for you and put in the webapp. Note that you can
128
+ also pass arbitrary properties to the ERb template by setting
129
+ <tt>config.webxml.customkey</tt> values in your <tt>config/warble.rb</tt>
130
+ file.
71
131
 
72
132
  For more information on configuration, see Warbler::Config.
73
133
 
74
134
  === Troubleshooting
75
135
 
76
- If Warbler isn't packaging the files you were expecting, there are several debug tasks available to give you more insight into what's going on.
136
+ If Warbler isn't packaging the files you were expecting, there are several
137
+ debug tasks available to give you more insight into what's going on.
77
138
 
78
139
  * <tt>war:debug</tt> prints a YAML dump of the current configuration
79
- * <tt>war:debug:X</tt> prints a list of files that Warbler will include during that stage of
80
- assembly. Valid values of <tt>X</tt> are <tt>app, java_libs, gems, public, includes,
81
- excludes</tt>.
140
+ * <tt>war:debug:X</tt> prints a list of files that Warbler will include during
141
+ that stage of assembly. Valid values of <tt>X</tt> are <tt>app, java_libs,
142
+ gems, public, includes, excludes</tt>.
82
143
 
83
144
  == Source
84
145
 
@@ -88,7 +149,8 @@ You can get the Warbler source using Git, in any of the following ways:
88
149
  git clone http://git.caldersphere.net/warbler.git
89
150
  git clone git://github.com/nicksieger/warbler.git
90
151
 
91
- You can also download a tarball of Warbler source at http://github.com/nicksieger/warbler/tree/master.
152
+ You can also download a tarball of Warbler source at
153
+ http://github.com/nicksieger/warbler/tree/master.
92
154
 
93
155
  == License
94
156
 
@@ -96,5 +158,6 @@ Warbler is provided under the terms of the MIT license.
96
158
 
97
159
  Warbler (c) 2007-08 Sun Microsystems, Inc.
98
160
 
99
- Warbler also bundles several other pieces of software for convenience. Please read the file LICENSES.txt to ensure
100
- that you agree with the terms of all the components.
161
+ Warbler also bundles several other pieces of software for convenience. Please
162
+ read the file LICENSES.txt to ensure that you agree with the terms of all the
163
+ components.
data/bin/warble CHANGED
@@ -11,9 +11,22 @@ require 'rake'
11
11
  require 'warbler'
12
12
 
13
13
  application = Rake.application
14
+
15
+ # Load any application rakefiles to aid in autodetecting applications
16
+ Warbler.project_application = Rake::Application.new
17
+ Rake.application = Warbler.project_application
18
+ Rake::Application::DEFAULT_RAKEFILES.each do |rf|
19
+ if File.exist?(rf)
20
+ load rf
21
+ break
22
+ end
23
+ end
24
+
25
+ Rake.application = application
14
26
  application.standard_exception_handling do
15
27
  application.init
16
28
 
29
+ # Load the main warbler tasks
17
30
  Warbler::Task.new
18
31
 
19
32
  task :default => :war
@@ -21,11 +34,11 @@ application.standard_exception_handling do
21
34
  desc "Generate a configuration file to customize your war assembly"
22
35
  task :config do
23
36
  if File.exists?(Warbler::Config::FILE) && ENV["FORCE"].nil?
24
- warn "There's another bird sitting on my favorite branch"
25
- warn "(file '#{Warbler::Config::FILE}' already exists. Pass argument FORCE=1 to override)"
37
+ puts "There's another bird sitting on my favorite branch"
38
+ puts "(file '#{Warbler::Config::FILE}' already exists. Pass argument FORCE=1 to override)"
26
39
  elsif !File.directory?("config")
27
- warn "I'm confused; my favorite branch is missing"
28
- warn "(directory 'config' is missing)"
40
+ puts "I'm confused; my favorite branch is missing"
41
+ puts "(directory 'config' is missing)"
29
42
  else
30
43
  cp "#{Warbler::WARBLER_HOME}/generators/warble/templates/warble.rb", Warbler::Config::FILE
31
44
  end
@@ -34,11 +47,11 @@ application.standard_exception_handling do
34
47
  desc "Unpack warbler as a plugin in your Rails application"
35
48
  task :pluginize do
36
49
  if !Dir["vendor/plugins/warbler*"].empty?
37
- warn "I found an old nest in vendor/plugins; please trash it so I can make a new one"
38
- warn "(directory vendor/plugins/warbler* exists)"
50
+ puts "I found an old nest in vendor/plugins; please trash it so I can make a new one"
51
+ puts "(directory vendor/plugins/warbler* exists)"
39
52
  elsif !File.directory?("vendor/plugins")
40
- warn "I can't find a place to build my nest"
41
- warn "(directory 'vendor/plugins' is missing)"
53
+ puts "I can't find a place to build my nest"
54
+ puts "(directory 'vendor/plugins' is missing)"
42
55
  else
43
56
  Dir.chdir("vendor/plugins") do
44
57
  ruby "-S", "gem", "unpack", "warbler"
@@ -40,6 +40,11 @@ Warbler::Config.new do |config|
40
40
  # You can specify versions of gems by using a hash assignment:
41
41
  # config.gems["rails"] = "2.0.2"
42
42
 
43
+ # You can also use regexps or Gem::Dependency objects for flexibility or
44
+ # fine-grained control.
45
+ # config.gems << /^merb-/
46
+ # config.gems << Gem::Dependency.new("merb-core", "= 0.9.3")
47
+
43
48
  # Include gem dependencies not mentioned specifically
44
49
  config.gem_dependencies = true
45
50
 
@@ -54,8 +59,8 @@ Warbler::Config.new do |config|
54
59
  # of RAILS_ROOT
55
60
  # config.war_name = "mywar"
56
61
 
57
- # Value of RAILS_ENV for the webapp
58
- config.webxml.rails.env = 'production'
62
+ # Value of RAILS_ENV for the webapp -- default as shown below
63
+ # config.webxml.rails.env = ENV['RAILS_ENV'] || 'production'
59
64
 
60
65
  # Application booter to use, one of :rack, :rails, or :merb. (Default :rails)
61
66
  # config.webxml.booter = :rails
@@ -9,7 +9,7 @@ require 'ostruct'
9
9
  module Warbler
10
10
  # Warbler assembly configuration.
11
11
  class Config
12
- TOP_DIRS = %w(app config lib log vendor tmp)
12
+ TOP_DIRS = %w(app config lib log vendor)
13
13
  FILE = "config/warble.rb"
14
14
  BUILD_GEMS = %w(warbler rake rcov)
15
15
 
@@ -21,7 +21,7 @@ module Warbler
21
21
  # autodeploy directory. Defaults to the root of the Rails directory.
22
22
  attr_accessor :autodeploy_dir
23
23
 
24
- # Top-level directories to be copied into WEB-INF. Defaults to
24
+ # Top-level directories to be copied into WEB-INF. Defaults to
25
25
  # names in TOP_DIRS
26
26
  attr_accessor :dirs
27
27
 
@@ -88,12 +88,12 @@ module Warbler
88
88
 
89
89
  def initialize(warbler_home = WARBLER_HOME)
90
90
  @staging_dir = File.join("tmp", "war")
91
- @dirs = TOP_DIRS
91
+ @dirs = TOP_DIRS.select {|d| File.directory?(d)}
92
92
  @includes = FileList[]
93
93
  @excludes = FileList[]
94
94
  @java_libs = FileList["#{warbler_home}/lib/*.jar"]
95
95
  @java_classes = FileList[]
96
- @gems = default_gems
96
+ @gems = Warbler::Gems.new
97
97
  @gem_dependencies = true
98
98
  @exclude_logs = true
99
99
  @public_html = FileList["public/**/*"]
@@ -101,6 +101,7 @@ module Warbler
101
101
  @webxml = default_webxml_config
102
102
  @rails_root = File.expand_path(defined?(RAILS_ROOT) ? RAILS_ROOT : Dir.getwd)
103
103
  @war_name = File.basename(@rails_root)
104
+ auto_detect_frameworks
104
105
  yield self if block_given?
105
106
  @excludes += warbler_vendor_excludes(warbler_home)
106
107
  @excludes += FileList["**/*.log"] if @exclude_logs
@@ -134,26 +135,52 @@ module Warbler
134
135
 
135
136
  def default_webxml_config
136
137
  c = WebxmlOpenStruct.new
137
- c.rails.env = "production"
138
+ c.rails.env = ENV['RAILS_ENV'] || 'production'
138
139
  c.public.root = '/'
139
140
  c.jndi = nil
140
141
  c.ignored = %w(jndi booter)
141
142
  c
142
143
  end
143
144
 
144
- def default_gems
145
- gems = Warbler::Gems.new
146
- # Include all gems which are used by the web application, this only works when run as a plugin
147
- #for gem in Gem.loaded_specs.values
148
- # next if BUILD_GEMS.include?(gem.name)
149
- # gems[gem.name] = gem.version.version
150
- #end
151
- gems << "rails" unless File.directory?("vendor/rails")
152
- gems
145
+ def auto_detect_frameworks
146
+ auto_detect_rails || auto_detect_merb || auto_detect_rackup
147
+ end
148
+
149
+ def auto_detect_rails
150
+ return false unless task = Warbler.project_application.lookup("environment")
151
+ task.invoke
152
+ return false unless defined?(::Rails)
153
+ @dirs << "tmp" if File.directory?("tmp")
154
+ @webxml.booter = :rails
155
+ unless (defined?(Rails.vendor_rails?) && Rails.vendor_rails?) || File.directory?("vendor/rails")
156
+ @gems["rails"] = Rails::VERSION::STRING
157
+ end
158
+ if defined?(Rails.configuration.gems)
159
+ Rails.configuration.gems.each {|g| @gems[g.name] = g.version }
160
+ end
161
+ @webxml.jruby.max.runtimes = 1 if defined?(Rails.configuration.threadsafe!)
162
+ true
163
+ end
164
+
165
+ def auto_detect_merb
166
+ return false unless task = Warbler.project_application.lookup("merb_env")
167
+ task.invoke
168
+ return false unless defined?(::Merb)
169
+ @webxml.booter = :merb
170
+ @gems["merb"] = Merb::VERSION
171
+ true
172
+ end
173
+
174
+ def auto_detect_rackup
175
+ return false unless File.exist?("config.ru")
176
+ @webxml.booter = :rack
177
+ @webxml.rackup = File.read("config.ru")
153
178
  end
154
179
  end
155
180
 
156
181
  class WebxmlOpenStruct < OpenStruct
182
+ %w(java com org javax).each {|name| undef_method name if Object.methods.include?(name) }
183
+
157
184
  def initialize(key = 'webxml')
158
185
  @key = key
159
186
  @table = Hash.new {|h,k| h[k] = WebxmlOpenStruct.new(k) }
@@ -170,17 +197,28 @@ module Warbler
170
197
  end
171
198
  end
172
199
 
200
+ def [](key)
201
+ new_ostruct_member(key)
202
+ send(key)
203
+ end
204
+
205
+ def []=(key, value)
206
+ new_ostruct_member(key)
207
+ send("#{key}=", value)
208
+ end
209
+
173
210
  def context_params
211
+ require 'cgi'
174
212
  params = {}
175
213
  @table.each do |k,v|
176
214
  case v
177
215
  when WebxmlOpenStruct
178
216
  nested_params = v.context_params
179
217
  nested_params.each do |nk,nv|
180
- params["#{k}.#{nk}"] = nv
218
+ params["#{CGI::escapeHTML(k.to_s)}.#{nk}"] = nv
181
219
  end
182
220
  else
183
- params[k] = v.to_s
221
+ params[CGI::escapeHTML(k.to_s)] = CGI::escapeHTML(v.to_s)
184
222
  end
185
223
  end
186
224
  params.delete_if {|k,v| ['ignored', *ignored].include?(k.to_s) }
@@ -22,6 +22,13 @@ module Warbler
22
22
  def <<(gem)
23
23
  self[gem] ||= ANY_VERSION
24
24
  end
25
-
25
+
26
+ def +(other)
27
+ other.each {|g| self[g] ||= ANY_VERSION }
28
+ end
29
+
30
+ def -(other)
31
+ other.each {|g| self.delete(g)}
32
+ end
26
33
  end
27
34
  end
@@ -8,6 +8,13 @@ require 'rake'
8
8
  require 'rake/tasklib'
9
9
 
10
10
  module Warbler
11
+ class << self
12
+ attr_writer :project_application
13
+ def project_application
14
+ @project_application || Rake.application
15
+ end
16
+ end
17
+
11
18
  # Warbler Rake task. Allows defining multiple configurations inside the same
12
19
  # Rakefile by using different task names.
13
20
  class Task < Rake::TaskLib
@@ -239,8 +246,14 @@ module Warbler
239
246
  targets
240
247
  end
241
248
 
242
- def define_single_gem_tasks(gem, targets, version = nil)
243
- matched = Gem.source_index.search(gem, version)
249
+ def define_single_gem_tasks(gem_pattern, targets, version = nil)
250
+ gem = case gem_pattern
251
+ when Gem::Dependency
252
+ gem_pattern
253
+ else
254
+ Gem::Dependency.new(gem_pattern, version)
255
+ end
256
+ matched = Gem.source_index.search(gem)
244
257
  fail "gem '#{gem}' not installed" if matched.empty?
245
258
  spec = matched.last
246
259
 
@@ -5,5 +5,5 @@
5
5
  #++
6
6
 
7
7
  module Warbler
8
- VERSION = "0.9.10"
8
+ VERSION = "0.9.11"
9
9
  end
@@ -30,4 +30,14 @@ def capture(&block)
30
30
  io = StringIO.new
31
31
  silence(io, &block)
32
32
  io.string
33
+ end
34
+
35
+ Spec::Runner.configure do |config|
36
+ config.after(:each) do
37
+ class << Object
38
+ public :remove_const
39
+ end
40
+ Object.remove_const("Rails") rescue nil
41
+ rm_rf "vendor"
42
+ end
33
43
  end
@@ -7,14 +7,10 @@
7
7
  require File.dirname(__FILE__) + '/../spec_helper'
8
8
 
9
9
  describe Warbler::Config do
10
- after(:each) do
11
- rm_rf "vendor"
12
- end
13
-
14
10
  it "should have suitable default values" do
15
11
  config = Warbler::Config.new
16
12
  config.staging_dir.should == "tmp/war"
17
- config.dirs.should include(*Warbler::Config::TOP_DIRS)
13
+ config.dirs.should include(*Warbler::Config::TOP_DIRS.select{|d| File.directory?(d)})
18
14
  config.includes.should be_empty
19
15
  config.java_libs.should_not be_empty
20
16
  config.war_name.size.should > 0
@@ -32,13 +28,13 @@ describe Warbler::Config do
32
28
  config.war_name.should == "mywar"
33
29
  end
34
30
 
35
- it "should provide Rails gems by default, unless vendor/rails is present" do
36
- config = Warbler::Config.new
37
- config.gems.should include("rails")
38
-
39
- mkdir_p "vendor/rails"
40
- config = Warbler::Config.new
41
- config.gems.should be_empty
31
+ it "should allow gems to be added/changed with =, +=, -=, <<" do
32
+ config = Warbler::Config.new do |c|
33
+ c.gems += ["activerecord-jdbc-adapter"]
34
+ c.gems -= ["rails"]
35
+ c.gems << "tzinfo"
36
+ c.gems = ["camping"]
37
+ end
42
38
  end
43
39
 
44
40
  it "should exclude log files by default" do
@@ -67,18 +63,22 @@ describe Warbler::Config do
67
63
  it "should generate context parameters from the webxml openstruct" do
68
64
  config = Warbler::Config.new
69
65
  config.webxml.a.b.c = "123"
66
+ config.webxml.com.example.config = "blah"
70
67
  config.webxml.rails.env = 'staging'
71
68
  config.webxml.jruby.min.runtimes = 2
72
69
  config.webxml.jruby.max.runtimes = 4
70
+ config.webxml['org']['jruby']['rack'] = "rails"
73
71
  params = config.webxml.context_params
74
72
  params.should have_key('a.b.c')
75
73
  params.should have_key('rails.env')
76
74
  params.should have_key('jruby.min.runtimes')
77
75
  params.should have_key('jruby.max.runtimes')
78
76
  params['a.b.c'].should == "123"
77
+ params['com.example.config'].should == "blah"
79
78
  params['rails.env'].should == "staging"
80
79
  params['jruby.min.runtimes'].should == "2"
81
80
  params['jruby.max.runtimes'].should == "4"
81
+ params['org.jruby.rack'].should == "rails"
82
82
  end
83
83
 
84
84
  it "should determine the context listener from the webxml.booter parameter" do
@@ -102,6 +102,12 @@ describe Warbler::Config do
102
102
  Warbler::Config.new.webxml.missing_key.to_s.should =~ /No value for 'missing_key' found/
103
103
  end
104
104
 
105
+ it "should HTML-escape all webxml keys and values" do
106
+ config = Warbler::Config.new
107
+ config.webxml.a["b&"].c = "123<hi>456"
108
+ config.webxml.context_params['a.b&amp;.c'].should == "123&lt;hi&gt;456"
109
+ end
110
+
105
111
  #it "should automatically gems used by the web application" do
106
112
  # gem "actionpack"
107
113
  # config = Warbler::Config.new
@@ -31,6 +31,7 @@ describe Warbler::Task do
31
31
  rm_rf "public"
32
32
  rm_rf "config"
33
33
  rm_rf "log"
34
+ rm_f "config.ru"
34
35
  end
35
36
 
36
37
  def define_tasks(*tasks)
@@ -65,6 +66,7 @@ describe Warbler::Task do
65
66
  end
66
67
 
67
68
  it "should define a gems task for unpacking gems" do
69
+ @config.gems << "rails"
68
70
  define_tasks "gems"
69
71
  Rake::Task["warble:gems"].invoke
70
72
  file_list(%r{WEB-INF/gems/gems/rake.*/lib/rake.rb}).should_not be_empty
@@ -254,18 +256,123 @@ describe Warbler::Task do
254
256
  spec.stub!(:original_platform).and_return "java"
255
257
  spec.stub!(:loaded_from).and_return "hpricot.gemspec"
256
258
  spec.stub!(:dependencies).and_return []
257
- Gem.source_index.should_receive(:search).with("hpricot", nil).and_return [spec]
259
+ Gem.source_index.should_receive(:search).and_return do |gem|
260
+ gem.name.should == "hpricot"
261
+ [spec]
262
+ end
258
263
  File.should_receive(:exist?).with(File.join(Gem.dir, 'cache', "hpricot-0.6.157-java.gem")).and_return true
259
264
  @config.gems = ["hpricot"]
260
265
  define_tasks "gems"
261
266
  end
262
267
 
268
+ it "should allow specification of dependency by Gem::Dependency" do
269
+ spec = mock "gem spec"
270
+ spec.stub!(:name).and_return "hpricot"
271
+ spec.stub!(:version).and_return "0.6.157"
272
+ spec.stub!(:platform).and_return "java"
273
+ spec.stub!(:original_platform).and_return "java"
274
+ spec.stub!(:loaded_from).and_return "hpricot.gemspec"
275
+ spec.stub!(:dependencies).and_return []
276
+ Gem.source_index.should_receive(:search).and_return do |gem|
277
+ gem.name.should == "hpricot"
278
+ [spec]
279
+ end
280
+ File.should_receive(:exist?).with(File.join(Gem.dir, 'cache', "hpricot-0.6.157-java.gem")).and_return true
281
+ @config.gems = [Gem::Dependency.new("hpricot", "> 0.6")]
282
+ define_tasks "gems"
283
+ end
284
+
263
285
  it "should define a java_classes task for copying loose java classes" do
264
286
  @config.java_classes = FileList["Rakefile"]
265
287
  define_tasks "java_classes"
266
288
  Rake::Task["warble:java_classes"].invoke
267
289
  file_list(%r{WEB-INF/classes/Rakefile$}).should_not be_empty
268
290
  end
291
+
292
+ def mock_rails_module
293
+ rails = Module.new
294
+ Object.const_set("Rails", rails)
295
+ version = Module.new
296
+ rails.const_set("VERSION", version)
297
+ version.const_set("STRING", "2.1.0")
298
+ rails
299
+ end
300
+
301
+ it "should auto-detect a Rails application" do
302
+ task :environment do
303
+ mock_rails_module
304
+ end
305
+ @config = Warbler::Config.new
306
+ @config.webxml.booter.should == :rails
307
+ @config.gems["rails"].should == "2.1.0"
308
+ end
309
+
310
+ it "should provide Rails gems by default, unless vendor/rails is present" do
311
+ rails = nil
312
+ task :environment do
313
+ rails = mock_rails_module
314
+ end
315
+
316
+ config = Warbler::Config.new
317
+ config.gems.should include("rails")
318
+
319
+ mkdir_p "vendor/rails"
320
+ config = Warbler::Config.new
321
+ config.gems.should be_empty
322
+
323
+ rm_rf "vendor/rails"
324
+ rails.stub!(:vendor_rails?).and_return true
325
+ config = Warbler::Config.new
326
+ config.gems.should be_empty
327
+ end
328
+
329
+ it "should auto-detect a Merb application" do
330
+ task :merb_env do
331
+ merb = Module.new
332
+ Object.const_set("Merb", merb)
333
+ merb.const_set("VERSION", "0.9.3")
334
+ end
335
+ @config = Warbler::Config.new
336
+ @config.webxml.booter.should == :merb
337
+ @config.gems["merb"].should == "0.9.3"
338
+ @config.gems.keys.should_not include("rails")
339
+ end
340
+
341
+ it "should auto-detect a Rack application with a config.ru file" do
342
+ rackup = "run Proc.new {|env| [200, {}, ['Hello World']]}"
343
+ File.open("config.ru", "w") {|f| f << rackup }
344
+ @config = Warbler::Config.new
345
+ @config.webxml.booter.should == :rack
346
+ @config.webxml.rackup.should == rackup
347
+ end
348
+
349
+ it "should automatically add Rails.configuration.gems to the list of gems" do
350
+ task :environment do
351
+ rails = mock_rails_module
352
+ config = mock "config"
353
+ rails.stub!(:configuration).and_return(config)
354
+ gem = mock "gem"
355
+ gem.stub!(:name).and_return "hpricot"
356
+ gem.stub!(:version).and_return "=0.6"
357
+ config.stub!(:gems).and_return [gem]
358
+ end
359
+
360
+ @config = Warbler::Config.new
361
+ @config.webxml.booter.should == :rails
362
+ @config.gems["hpricot"].should == "=0.6"
363
+ end
364
+
365
+ it "should set the jruby max runtimes to 1 when MT Rails is detected" do
366
+ task :environment do
367
+ rails = mock_rails_module
368
+ config = mock "config"
369
+ rails.stub!(:configuration).and_return(config)
370
+ config.stub!(:threadsafe!)
371
+ end
372
+ @config = Warbler::Config.new
373
+ @config.webxml.booter.should == :rails
374
+ @config.webxml.jruby.max.runtimes.should == 1
375
+ end
269
376
  end
270
377
 
271
378
  describe "The warbler.rake file" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warbler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.10
4
+ version: 0.9.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sieger
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-26 00:00:00 -05:00
12
+ date: 2008-09-04 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -45,8 +45,8 @@ files:
45
45
  - generators/warble/templates
46
46
  - generators/warble/templates/warble.rb
47
47
  - generators/warble/warble_generator.rb
48
- - lib/jruby-complete-1.1.3.jar
49
- - lib/jruby-rack-0.9.1.jar
48
+ - lib/jruby-complete-1.1.4.jar
49
+ - lib/jruby-rack-0.9.2.jar
50
50
  - lib/warbler
51
51
  - lib/warbler/config.rb
52
52
  - lib/warbler/gems.rb