warbler 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,13 @@
1
+ == 1.2.1
2
+
3
+ - Add --directoryListings=false to Winstone launch by default. In some
4
+ cases (sinatra) Winstone's directory listing masks application
5
+ content. (Fletcher Nichol)
6
+ - Build and add META-INF/init.rb file into the war file. This is
7
+ recognized and loaded by JRuby-Rack 1.0.3 as a new way to do extra
8
+ environment initialization before the web framework is loaded. See
9
+ config.init_contents in Warbler::Config for details.
10
+
1
11
  == 1.2.0
2
12
 
3
13
  - Drop compatibility with earlier versions of Bundler -- Bundler has
data/Manifest.txt CHANGED
@@ -14,6 +14,10 @@ lib/warbler/application.rb
14
14
  lib/warbler/config.rb
15
15
  lib/warbler/gems.rb
16
16
  lib/warbler/task.rb
17
+ lib/warbler/templates
18
+ lib/warbler/templates/config.erb
19
+ lib/warbler/templates/rack.erb
20
+ lib/warbler/templates/rails.erb
17
21
  lib/warbler/version.rb
18
22
  lib/warbler/war.rb
19
23
  lib/warbler_war.jar
data/README.txt CHANGED
@@ -79,11 +79,13 @@ and +:test+ will be excluded by default, unless you specify with
79
79
  Rails applications are detected automatically and configured appropriately.
80
80
  The following items are set up for you:
81
81
 
82
- * The Rails gem is packaged if you haven't vendored Rails.
82
+ * Your application runs in the +production+ environment by default.
83
+ Change it in <tt>config/warble.rb</tt> (see below).
84
+ * The Rails gem is packaged if you haven't vendored Rails (Rails <= 2.x).
83
85
  * Other gems configured in Rails.configuration.gems are packaged
84
- (Rails 2.1 - 2.3)
86
+ (Rails 2.1 - 2.3)
85
87
  * Multi-thread-safe execution (as introduced in Rails 2.2) is detected
86
- and runtime pooling is disabled.
88
+ and runtime pooling is disabled.
87
89
 
88
90
  === Merb applications
89
91
 
@@ -97,6 +99,7 @@ immediate subdirectories of your application, it will be included and
97
99
  used as the rackup script for your Rack-based application. You will
98
100
  probably need to specify framework and application gems in
99
101
  config/warble.rb unless you're using Bundler to manage your gems.
102
+ <tt>ENV['RACK_ENV']</tt> will be set to +production+.
100
103
 
101
104
  See {the examples in the jruby-rack project}[http://github.com/nicksieger/jruby-rack/tree/master/examples/]
102
105
  of how to configure Warbler to package Camping and Sinatra apps.
data/ext/Main.java CHANGED
@@ -58,10 +58,11 @@ public class Main implements Runnable {
58
58
  URLClassLoader loader = new URLClassLoader(new URL[] {jar});
59
59
  Class klass = Class.forName("winstone.Launcher", true, loader);
60
60
  Method main = klass.getDeclaredMethod("main", new Class[] {String[].class});
61
- String[] newargs = new String[args.length + 2];
61
+ String[] newargs = new String[args.length + 3];
62
62
  newargs[0] = "--warfile=" + warfile;
63
63
  newargs[1] = "--webroot=" + webroot;
64
- System.arraycopy(args, 0, newargs, 2, args.length);
64
+ newargs[2] = "--directoryListings=false";
65
+ System.arraycopy(args, 0, newargs, 3, args.length);
65
66
  debug("invoking Winstone with: " + Arrays.deepToString(newargs));
66
67
  main.invoke(null, new Object[] {newargs});
67
68
  }
@@ -94,6 +94,14 @@ module Warbler
94
94
  # compile all .rb files in the application.
95
95
  attr_accessor :compiled_ruby_files
96
96
 
97
+ # Warbler writes an "init" file into the war at this location. JRuby-Rack and possibly other
98
+ # launchers may use this to initialize the Ruby environment.
99
+ attr_accessor :init_filename
100
+
101
+ # Array containing filenames or StringIO's to be concatenated together to form the init file.
102
+ # If the filename ends in .erb the file will be expanded the same way web.xml.erb is; see below.
103
+ attr_accessor :init_contents
104
+
97
105
  # Extra configuration for web.xml. Controls how the dynamically-generated web.xml
98
106
  # file is generated.
99
107
  #
@@ -124,6 +132,7 @@ module Warbler
124
132
 
125
133
  def initialize(warbler_home = WARBLER_HOME)
126
134
  @warbler_home = warbler_home
135
+ @warbler_templates = "#{WARBLER_HOME}/lib/warbler/templates"
127
136
  @features = []
128
137
  @dirs = TOP_DIRS.select {|d| File.directory?(d)}
129
138
  @includes = FileList[]
@@ -143,12 +152,16 @@ module Warbler
143
152
  @bundler = true
144
153
  @bundle_without = ["development", "test"]
145
154
  @webinf_files = default_webinf_files
155
+ @init_filename = 'META-INF/init.rb'
156
+ @init_contents = ["#{@warbler_templates}/config.erb"]
146
157
 
147
158
  auto_detect_frameworks
148
159
  yield self if block_given?
149
160
  update_gem_path
150
161
  detect_bundler_gems
151
162
 
163
+ framework_init = "#{@warbler_templates}/#{@webxml.booter}.erb"
164
+ @init_contents << framework_init if File.exist?(framework_init)
152
165
  @compiled_ruby_files ||= FileList[*@dirs.map {|d| "#{d}/**/*.rb"}]
153
166
  @excludes += ["tmp/war"] if File.directory?("tmp/war")
154
167
  @excludes += warbler_vendor_excludes(warbler_home)
@@ -230,6 +243,7 @@ module Warbler
230
243
  definition = Bundler::Definition.build(gemfile, lockfile, nil)
231
244
  groups = definition.groups - @bundle_without.map {|g| g.to_sym}
232
245
  definition.specs_for(groups).each {|spec| @gems << spec }
246
+ @init_contents << StringIO.new("ENV['BUNDLE_WITHOUT'] = '#{@bundle_without.join(':')}'\n")
233
247
  else
234
248
  @bundler = false
235
249
  end
@@ -321,7 +335,7 @@ module Warbler
321
335
  send("#{key}=", value)
322
336
  end
323
337
 
324
- def context_params
338
+ def context_params(escape = true)
325
339
  require 'cgi'
326
340
  params = {}
327
341
  @table.each do |k,v|
@@ -329,10 +343,10 @@ module Warbler
329
343
  when WebxmlOpenStruct
330
344
  nested_params = v.context_params
331
345
  nested_params.each do |nk,nv|
332
- params["#{CGI::escapeHTML(k.to_s)}.#{nk}"] = nv
346
+ params["#{escape ? CGI::escapeHTML(k.to_s) : k.to_s}.#{nk}"] = nv
333
347
  end
334
348
  else
335
- params[CGI::escapeHTML(k.to_s)] = CGI::escapeHTML(v.to_s)
349
+ params[escape ? CGI::escapeHTML(k.to_s) : k.to_s] = escape ? CGI::escapeHTML(v.to_s) : v.to_s
336
350
  end
337
351
  end
338
352
  params.delete_if {|k,v| ['ignored', *ignored].include?(k.to_s) }
@@ -0,0 +1 @@
1
+ WARBLER_CONFIG = <%= webxml.context_params(false) .inspect %>
@@ -0,0 +1 @@
1
+ ENV['RACK_ENV'] = '<%= (params = webxml.context_params; params['rack.env'] || params['rails.env']) %>'
@@ -0,0 +1 @@
1
+ ENV['RAILS_ENV'] = '<%= webxml.rails.env %>'
@@ -6,5 +6,5 @@
6
6
  #++
7
7
 
8
8
  module Warbler
9
- VERSION = "1.2.0"
9
+ VERSION = "1.2.1"
10
10
  end
data/lib/warbler/war.rb CHANGED
@@ -52,6 +52,7 @@ module Warbler
52
52
  add_webxml(config)
53
53
  add_manifest(config)
54
54
  add_bundler_files(config)
55
+ add_init_file(config)
55
56
  end
56
57
 
57
58
  # Create the war file. The single argument can either be a
@@ -73,10 +74,7 @@ module Warbler
73
74
  def add_webxml(config)
74
75
  config.webinf_files.each do |wf|
75
76
  if wf =~ /\.erb$/
76
- require 'erb'
77
- erb = ERB.new(File.open(wf) {|f| f.read })
78
- contents = StringIO.new(erb.result(erb_binding(config.webxml)))
79
- @files[apply_pathmaps(config, wf, :webinf)] = contents
77
+ @files[apply_pathmaps(config, wf, :webinf)] = expand_erb(wf, config)
80
78
  else
81
79
  @files[apply_pathmaps(config, wf, :webinf)] = wf
82
80
  end
@@ -174,11 +172,34 @@ module Warbler
174
172
  end
175
173
  end
176
174
 
175
+ # Add init.rb file to the war file.
176
+ def add_init_file(config)
177
+ if config.init_contents
178
+ contents = ''
179
+ config.init_contents.each do |file|
180
+ if file.respond_to?(:read)
181
+ contents << file.read
182
+ elsif File.extname(file) == '.erb'
183
+ contents << expand_erb(file, config).read
184
+ else
185
+ contents << File.read(file)
186
+ end
187
+ end
188
+ @files[config.init_filename] = StringIO.new(contents)
189
+ end
190
+ end
191
+
177
192
  private
178
193
  def add_with_pathmaps(config, f, map_type)
179
194
  @files[apply_pathmaps(config, f, map_type)] = f
180
195
  end
181
196
 
197
+ def expand_erb(file, config)
198
+ require 'erb'
199
+ erb = ERB.new(File.open(file) {|f| f.read })
200
+ StringIO.new(erb.result(erb_binding(config.webxml)))
201
+ end
202
+
182
203
  def erb_binding(webxml)
183
204
  binding
184
205
  end
data/lib/warbler_war.jar CHANGED
Binary file
@@ -27,8 +27,8 @@ describe Warbler::War do
27
27
 
28
28
  after(:each) do
29
29
  rm_rf FileList["log", ".bundle", "tmp/war"]
30
- rm_f FileList["*.war", "config.ru", "*web.xml*", "config/web.xml*",
31
- "config/warble.rb", "file.txt", 'manifest', 'Gemfile*', 'MANIFEST.MF*']
30
+ rm_f FileList["*.war", "config.ru", "*web.xml*", "config/web.xml*", "config/warble.rb",
31
+ "file.txt", 'manifest', 'Gemfile*', 'MANIFEST.MF*', 'init.rb*']
32
32
  Dir.chdir(@pwd)
33
33
  @env_save.keys.each {|k| ENV[k] = @env_save[k]}
34
34
  end
@@ -452,4 +452,52 @@ describe Warbler::War do
452
452
  @war.apply(@config)
453
453
  file_list(%r{WEB-INF/gems/gems/rake([^/]+)/test/test_rake.rb}).should be_empty
454
454
  end
455
+
456
+ it "should create a META-INF/init.rb file with startup config" do
457
+ @war.apply(@config)
458
+ file_list(%r{META-INF/init.rb}).should_not be_empty
459
+ end
460
+
461
+ it "should allow adjusting the init file location in the war" do
462
+ @config.init_filename = 'WEB-INF/init.rb'
463
+ @war.add_init_file(@config)
464
+ file_list(%r{WEB-INF/init.rb}).should_not be_empty
465
+ end
466
+
467
+ it "should add RAILS_ENV to init.rb for Rails apps" do
468
+ @config = Warbler::Config.new { |c| c.webxml.booter = :rails }
469
+ @war.add_init_file(@config)
470
+ contents = @war.files['META-INF/init.rb'].read
471
+ contents.should =~ /ENV\['RAILS_ENV'\]/
472
+ contents.should =~ /'production'/
473
+ end
474
+
475
+ it "should add RACK_ENV to init.rb for Rack apps" do
476
+ @config = Warbler::Config.new { |c| c.webxml.booter = :rack }
477
+ @war.add_init_file(@config)
478
+ contents = @war.files['META-INF/init.rb'].read
479
+ contents.should =~ /ENV\['RACK_ENV'\]/
480
+ contents.should =~ /'production'/
481
+ end
482
+
483
+ it "should add BUNDLE_WITHOUT to init.rb when Bundler is used" do
484
+ File.open("Gemfile", "w") {|f| f << "gem 'rake'"}
485
+ @war.add_init_file(Warbler::Config.new)
486
+ contents = @war.files['META-INF/init.rb'].read
487
+ contents.should =~ /ENV\['BUNDLE_WITHOUT'\]/
488
+ contents.should =~ /'development:test'/
489
+ end
490
+
491
+ it "should allow adding custom files' contents to init.rb" do
492
+ @config = Warbler::Config.new { |c| c.init_contents << "Rakefile" }
493
+ @war.add_init_file(@config)
494
+ contents = @war.files['META-INF/init.rb'].read
495
+ contents.should =~ /require 'rake'/
496
+ end
497
+
498
+ it "should not have escaped HTML in WARBLER_CONFIG" do
499
+ @config.webxml.dummy = '<dummy/>'
500
+ @war.apply(@config)
501
+ @war.files['META-INF/init.rb'].read.should =~ /<dummy\/>/
502
+ end
455
503
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 2
8
- - 0
9
- version: 1.2.0
8
+ - 1
9
+ version: 1.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nick Sieger
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-05 00:00:00 -05:00
17
+ date: 2010-08-13 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -123,6 +123,9 @@ files:
123
123
  - lib/warbler/config.rb
124
124
  - lib/warbler/gems.rb
125
125
  - lib/warbler/task.rb
126
+ - lib/warbler/templates/config.erb
127
+ - lib/warbler/templates/rack.erb
128
+ - lib/warbler/templates/rails.erb
126
129
  - lib/warbler/version.rb
127
130
  - lib/warbler/war.rb
128
131
  - lib/warbler_war.jar