warbler 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,24 @@
1
+ == 1.2.0
2
+
3
+ - Drop compatibility with earlier versions of Bundler -- Bundler has
4
+ changed a lot in a short period of time, so I'm expecting the number
5
+ of people depending on 0.8 or 0.9 to be small. Please use Warbler
6
+ 1.2.0 with applications that depend on Bundler 1.0 or higher.
7
+ - Support for Bundler groups. The 'development' and 'test' groups are
8
+ excluded by default.
9
+ - Add 'compiled' feature: With this feature added to config.features
10
+ Warbler will pre-compile all Ruby files and will not ship the
11
+ original Ruby source in your war file.
12
+ - warble.rb: Add config.bundle_without that controls Bundler groups to
13
+ be skipped, like 'Bundler.settings.without'.
14
+ - warble.rb: Add config.compiled_ruby_files to specify which Ruby
15
+ files to compile when using the "compiled" feature. Defaults to
16
+ compiling all Ruby files.
17
+ - warble.rb: Add config.gem_excludes which allows exclusion of some
18
+ gem files from the war. Default assumes no exclusions.
19
+ - Exclude 'tmp/war' directory so that people upgrading from 0.9 won't
20
+ accidentally include it in their war file.
21
+
1
22
  == 1.1.0
2
23
 
3
24
  - Add concept of "features" -- small Rake tasks that run before the
data/Manifest.txt CHANGED
@@ -13,7 +13,6 @@ lib/warbler.rb
13
13
  lib/warbler/application.rb
14
14
  lib/warbler/config.rb
15
15
  lib/warbler/gems.rb
16
- lib/warbler/runtime.rb
17
16
  lib/warbler/task.rb
18
17
  lib/warbler/version.rb
19
18
  lib/warbler/war.rb
data/README.txt CHANGED
@@ -6,8 +6,7 @@ bundle up all of your application files for deployment to a Java application
6
6
  server.
7
7
 
8
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
+ Ruby web applications to assemble and Just Work.
11
10
 
12
11
  == Getting Started
13
12
 
@@ -21,6 +20,7 @@ Warbler's +warble+ command is just a small wrapper around Rake with internally
21
20
  defined tasks.
22
21
 
23
22
  $ warble -T
23
+ warble compiled # Feature: precompile all Ruby files
24
24
  warble config # Generate a configuration file to customize your war
25
25
  warble executable # Feature: make an executable archive
26
26
  warble gemjar # Feature: package gem repository inside a jar
@@ -30,18 +30,16 @@ defined tasks.
30
30
  warble war:clean # Remove the .war file
31
31
  warble war:debug # Dump diagnostic information
32
32
 
33
- If you'd like to control Warbler from your own project's Rakefile,
34
- simply add the following code somewhere in the Rakefile:
35
-
36
- require 'warbler'
37
- Warbler::Task.new
38
-
39
- Now you should be able to invoke "rake war" to create your war file.
33
+ Type <tt>warble</tt> or <tt>warble war</tt> to create the war file.
40
34
 
41
35
  == Features
42
36
 
43
37
  Warbler "features" are small Rake tasks that run before the creation
44
- of the war file and make manipulations to the war file structure.
38
+ of the war file and make manipulations to the war file structure. For
39
+ instance, the +executable+ feature makes your war file capable of
40
+ running on its own (like a jar), without a servlet container:
41
+
42
+ warble executable war
45
43
 
46
44
  You can either add features to the warbler command line:
47
45
 
@@ -51,14 +49,17 @@ or configure them in config/warble.rb to always be used.
51
49
 
52
50
  config.features = %w(FEATURE)
53
51
 
54
- Currently, two features are available.
52
+ Currently, three features are available.
55
53
 
56
54
  * +gemjar+: This bundles all gems into a single gem file to reduce the
57
55
  number of files in the .war. This is mostly useful for Google
58
56
  AppEngine where the number of files per application has a limit.
59
57
  * +executable+: This bundles an embedded web server into the .war so
60
58
  that it can either be deployed into a traditional java web server or
61
- run as a standalone application using 'java -jar myapp.war'.
59
+ run as a standalone application using <tt>java -jar myapp.war</tt>.
60
+ * +compiled+: This uses +jrubyc+ to precompile all .rb files in your
61
+ application to .class files and includes those in the .war instead
62
+ of the Ruby sources.
62
63
 
63
64
  Features may form the basis for a third-party plugin system in the
64
65
  future if there is demand.
@@ -69,8 +70,9 @@ future if there is demand.
69
70
 
70
71
  Applications that use Bundler[http://gembundler.com/], detected via
71
72
  presence of a +Gemfile+, will have the gems packaged up into the war
72
- file. The .bundle/environment.rb file will be included for you, and
73
- rewritten to use the paths to the gems inside the war.
73
+ file along with the Gemfile. The Bundler groups named +:development+
74
+ and +:test+ will be excluded by default, unless you specify with
75
+ +config.bundle_without+ in +config/warble.rb+.
74
76
 
75
77
  === Rails applications
76
78
 
@@ -90,7 +92,7 @@ dependencies are packaged.
90
92
 
91
93
  === Other Rack-based applications
92
94
 
93
- If you have a 'config.ru' file in the top directory or one of the
95
+ If you have a +config.ru+ file in the top directory or one of the
94
96
  immediate subdirectories of your application, it will be included and
95
97
  used as the rackup script for your Rack-based application. You will
96
98
  probably need to specify framework and application gems in
@@ -101,16 +103,16 @@ of how to configure Warbler to package Camping and Sinatra apps.
101
103
 
102
104
  === Configuration auto-detect notes
103
105
 
104
- * Warbler will load the "environment" Rake task in a Rails application
106
+ * Warbler will load the +environment+ Rake task in a Rails application
105
107
  to try to detect some configuration. If you don't have database
106
108
  access in the environment where you package your application, you
107
- may wish to set `Warbler.framework_detection` to false at the top of
109
+ may wish to set +Warbler.framework_detection+ to false at the top of
108
110
  config.rb. In this case you may need to specify additional details
109
111
  such as booter, gems and other settings that would normally be
110
112
  gleaned from the application configuration.
111
113
  * A more accurate way of detecting a Merb application's gems is
112
114
  needed. Until then, you will have to specify them in
113
- config/warble.rb. See below.
115
+ +config/warble.rb+. See below.
114
116
  * Is it possible to more generally detect what gems an application
115
117
  uses? Gem.loaded_specs is available, but the application needs to be
116
118
  loaded first before its contents are reliable.
@@ -155,18 +157,37 @@ customize it in any way, you have two options.
155
157
 
156
158
  For more information on configuration, see Warbler::Config.
157
159
 
158
- === Troubleshooting
160
+ == Rakefile integration
161
+
162
+ If you'd like to control Warbler from your own project's Rakefile,
163
+ simply add the following code somewhere in the Rakefile:
164
+
165
+ require 'warbler'
166
+ Warbler::Task.new
167
+
168
+ If you're using Bundler, you'll want to add Warbler to your Gemfile:
169
+
170
+ group :development do
171
+ gem "warbler"
172
+ end
173
+
174
+ Now you should be able to invoke "rake war" to create your war file.
175
+
176
+ == Troubleshooting
159
177
 
160
178
  If Warbler isn't packaging the files you were expecting, use the
161
- war:debug task to give you more insight into what's going on.
179
+ +war:debug+ task to give you more insight into what's going on.
180
+
181
+ If you think you found a bug, please file one at
182
+ http://kenai.com/jira/browse/WARBLER.
162
183
 
163
184
  == Source
164
185
 
165
186
  You can get the Warbler source using Git, in any of the following ways:
166
187
 
167
- git clone git://kenai.com/warbler~main
168
188
  git clone git://git.caldersphere.net/warbler.git
169
189
  git clone git://github.com/nicksieger/warbler.git
190
+ git clone git://kenai.com/warbler~main
170
191
 
171
192
  You can also download a tarball of Warbler source at
172
193
  http://github.com/nicksieger/warbler/tree/master.
data/Rakefile CHANGED
@@ -6,8 +6,7 @@
6
6
  #++
7
7
 
8
8
  begin
9
- require 'bundler'
10
- Bundler.setup
9
+ require 'bundler/setup'
11
10
  rescue LoadError
12
11
  puts "Please install Bundler and run 'bundle install' to ensure you have all dependencies"
13
12
  end
@@ -33,7 +32,7 @@ begin
33
32
  p.summary = "Warbler chirpily constructs .war files of your Rails applications."
34
33
  p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
35
34
  p.description = p.paragraphs_of('README.txt', 1...2).join("\n\n")
36
- p.extra_deps += [['rake', '>= 0.8.7'], ['jruby-jars', '>= 1.4.0'], ['jruby-rack', '>= 0.9.8'], ['rubyzip', '>= 0.9.4']]
35
+ p.extra_deps += [['rake', '>= 0.8.7'], ['jruby-jars', '>= 1.4.0'], ['jruby-rack', '>= 1.0.0'], ['rubyzip', '>= 0.9.4']]
37
36
  p.clean_globs += ['spec/sample/MANIFEST*', 'spec/sample/web.xml*']
38
37
  end
39
38
  hoe.spec.files = MANIFEST
data/lib/warbler.rb CHANGED
@@ -34,4 +34,3 @@ require 'warbler/config'
34
34
  require 'warbler/war'
35
35
  require 'warbler/task'
36
36
  require 'warbler/application'
37
- require 'warbler/runtime'
@@ -38,6 +38,9 @@ class Warbler::Application < Rake::Application
38
38
  desc "Feature: make an executable archive"
39
39
  task :executable => "war:executable"
40
40
 
41
+ desc "Feature: precompile all Ruby files"
42
+ task :compiled => "war:compiled"
43
+
41
44
  desc "Display version of Warbler"
42
45
  task :version => "war:version"
43
46
  end
@@ -19,6 +19,7 @@ module Warbler
19
19
  # Currently the following features are supported:
20
20
  # - gemjar: package the gem repository in a jar file in WEB-INF/lib
21
21
  # - executable: embed a web server and make the war executable
22
+ # - compiled: compile .rb files to .class files
22
23
  attr_accessor :features
23
24
 
24
25
  # Deprecated: No longer has any effect.
@@ -26,7 +27,7 @@ module Warbler
26
27
 
27
28
  # Directory where the war file will be written. Can be used to direct
28
29
  # Warbler to place your war file directly in your application server's
29
- # autodeploy directory. Defaults to the root of the Rails directory.
30
+ # autodeploy directory. Defaults to the root of the application directory.
30
31
  attr_accessor :autodeploy_dir
31
32
 
32
33
  # Top-level directories to be copied into WEB-INF. Defaults to
@@ -52,6 +53,10 @@ module Warbler
52
53
  # Whether to include dependent gems (default true)
53
54
  attr_accessor :gem_dependencies
54
55
 
56
+ # Array of regular expressions matching relative paths in gems to
57
+ # be excluded from the war. Default contains no exclusions.
58
+ attr_accessor :gem_excludes
59
+
55
60
  # Whether to exclude **/*.log files (default is true)
56
61
  attr_accessor :exclude_logs
57
62
 
@@ -77,10 +82,18 @@ module Warbler
77
82
  # Use Bundler to locate gems if Gemfile is found. Default is true.
78
83
  attr_accessor :bundler
79
84
 
85
+ # An array of Bundler groups to avoid including in the war file.
86
+ # Defaults to ["development", "test"].
87
+ attr_accessor :bundle_without
88
+
80
89
  # Path to the pre-bundled gem directory inside the war file. Default is '/WEB-INF/gems'.
81
90
  # This also sets 'gem.path' inside web.xml.
82
91
  attr_accessor :gem_path
83
92
 
93
+ # List of ruby files to compile to class files. Default is to
94
+ # compile all .rb files in the application.
95
+ attr_accessor :compiled_ruby_files
96
+
84
97
  # Extra configuration for web.xml. Controls how the dynamically-generated web.xml
85
98
  # file is generated.
86
99
  #
@@ -120,18 +133,24 @@ module Warbler
120
133
  @gems = Warbler::Gems.new
121
134
  @gem_path = DEFAULT_GEM_PATH
122
135
  @gem_dependencies = true
136
+ @gem_excludes = []
123
137
  @exclude_logs = true
124
138
  @public_html = FileList["public/**/*"]
125
139
  @pathmaps = default_pathmaps
126
140
  @webxml = default_webxml_config
127
- @rails_root = File.expand_path(defined?(RAILS_ROOT) ? RAILS_ROOT : Dir.getwd)
141
+ @rails_root = default_rails_root
128
142
  @war_name = File.basename(@rails_root)
129
143
  @bundler = true
144
+ @bundle_without = ["development", "test"]
130
145
  @webinf_files = default_webinf_files
146
+
131
147
  auto_detect_frameworks
132
148
  yield self if block_given?
133
149
  update_gem_path
134
150
  detect_bundler_gems
151
+
152
+ @compiled_ruby_files ||= FileList[*@dirs.map {|d| "#{d}/**/*.rb"}]
153
+ @excludes += ["tmp/war"] if File.directory?("tmp/war")
135
154
  @excludes += warbler_vendor_excludes(warbler_home)
136
155
  @excludes += FileList["**/*.log"] if @exclude_logs
137
156
  end
@@ -175,6 +194,10 @@ module Warbler
175
194
  c
176
195
  end
177
196
 
197
+ def default_rails_root
198
+ File.expand_path(defined?(Rails.root) ? Rails.root : (defined?(RAILS_ROOT) ? RAILS_ROOT : Dir.getwd))
199
+ end
200
+
178
201
  def default_webinf_files
179
202
  webxml = if File.exist?("config/web.xml")
180
203
  "config/web.xml"
@@ -200,26 +223,13 @@ module Warbler
200
223
  if @bundler && File.exist?("Gemfile")
201
224
  @gems.clear
202
225
  @gem_dependencies = false # Bundler takes care of these
203
- begin
204
- require 'bundler'
205
- env = Bundler::Runtime.new(Bundler.root, Bundler.definition)
206
- if bundler_env_file = Bundler.respond_to?(:env_file)
207
- class << Bundler
208
- alias orig_env_file env_file
209
- def env_file; root.join(::Warbler::Runtime::WAR_ENV); end
210
- end
211
- end
212
- env.extend Warbler::Runtime
213
- env.gem_path = @gem_path
214
- env.write_war_environment
215
- env.war_specs.each {|spec| @gems << spec }
216
- ensure
217
- if bundler_env_file
218
- class << Bundler
219
- alias env_file orig_env_file
220
- end
221
- end
222
- end
226
+ require 'bundler'
227
+ gemfile = Pathname.new("Gemfile").expand_path
228
+ root = gemfile.dirname
229
+ lockfile = root.join('Gemfile.lock')
230
+ definition = Bundler::Definition.build(gemfile, lockfile, nil)
231
+ groups = definition.groups - @bundle_without.map {|g| g.to_sym}
232
+ definition.specs_for(groups).each {|spec| @gems << spec }
223
233
  else
224
234
  @bundler = false
225
235
  end
@@ -233,16 +243,7 @@ module Warbler
233
243
 
234
244
  def auto_detect_frameworks
235
245
  return unless Warbler.framework_detection
236
- if File.exist?(".bundle/environment.rb")
237
- begin # Don't want Bundler to load from .bundle/environment
238
- mv(".bundle/environment.rb",".bundle/environment-save.rb", :verbose => false)
239
- auto_detect_rails || auto_detect_merb || auto_detect_rackup
240
- ensure
241
- mv(".bundle/environment-save.rb",".bundle/environment.rb", :verbose => false)
242
- end
243
- else
244
- auto_detect_rails || auto_detect_merb || auto_detect_rackup
245
- end
246
+ auto_detect_rails || auto_detect_merb || auto_detect_rackup
246
247
  end
247
248
 
248
249
  def auto_detect_rails
@@ -292,7 +293,7 @@ module Warbler
292
293
 
293
294
  # Helper class for holding arbitrary config.webxml values for injecting into +web.xml+.
294
295
  class WebxmlOpenStruct < OpenStruct
295
- %w(java com org javax).each {|name| undef_method name if Object.methods.include?(name) }
296
+ %w(java com org javax gem).each {|name| undef_method name if Object.methods.include?(name) }
296
297
 
297
298
  def initialize(key = 'webxml')
298
299
  @key = key
data/lib/warbler/task.rb CHANGED
@@ -59,6 +59,7 @@ module Warbler
59
59
  define_main_task
60
60
  namespace name do
61
61
  define_clean_task
62
+ define_compiled_task
62
63
  define_files_task
63
64
  define_jar_task
64
65
  define_debug_task
@@ -99,6 +100,12 @@ module Warbler
99
100
  task "clear" => "#{name}:clean"
100
101
  end
101
102
 
103
+ def define_compiled_task
104
+ task "compiled" do
105
+ war.compile(config)
106
+ end
107
+ end
108
+
102
109
  def define_files_task
103
110
  task "files" do
104
111
  war.apply(config)
@@ -6,5 +6,5 @@
6
6
  #++
7
7
 
8
8
  module Warbler
9
- VERSION = "1.1.0"
9
+ VERSION = "1.2.0"
10
10
  end
data/lib/warbler/war.rb CHANGED
@@ -17,6 +17,30 @@ module Warbler
17
17
  @files = {}
18
18
  end
19
19
 
20
+ def compile(config)
21
+ # Compiling all Ruby files we can find -- do we need to allow an
22
+ # option to configure what gets compiled?
23
+ return if config.compiled_ruby_files.nil? || config.compiled_ruby_files.empty?
24
+
25
+ run_javac(config, config.compiled_ruby_files)
26
+ replace_compiled_ruby_files(config, config.compiled_ruby_files)
27
+ end
28
+
29
+ def run_javac(config, compiled_ruby_files)
30
+ # Need to use the version of JRuby in the application to compile it
31
+ %x{java -classpath #{config.java_libs.join(File::PATH_SEPARATOR)} org.jruby.Main -S jrubyc \"#{compiled_ruby_files.join('" "')}\"}
32
+ end
33
+
34
+ def replace_compiled_ruby_files(config, compiled_ruby_files)
35
+ # Exclude the rb files and recreate them. This
36
+ # prevents the original contents being used.
37
+ config.excludes += compiled_ruby_files
38
+
39
+ compiled_ruby_files.each do |ruby_source|
40
+ files[apply_pathmaps(config, ruby_source, :application)] = StringIO.new("require __FILE__.sub(/\.rb$/, '.class')")
41
+ end
42
+ end
43
+
20
44
  # Apply the information in a Warbler::Config object in order to
21
45
  # look for files to put into this war file.
22
46
  def apply(config)
@@ -115,6 +139,7 @@ module Warbler
115
139
 
116
140
  add_with_pathmaps(config, spec.loaded_from, :gemspecs)
117
141
  spec.files.each do |f|
142
+ next if config.gem_excludes && config.gem_excludes.any? {|rx| f =~ rx }
118
143
  src = File.join(spec.full_gem_path, f)
119
144
  # some gemspecs may have incorrect file listings
120
145
  next unless File.exist?(src)
@@ -139,13 +164,12 @@ module Warbler
139
164
  @webinf_filelist.map {|f| add_with_pathmaps(config, f, :application) }
140
165
  end
141
166
 
142
- # Add Bundler Gemfile and .bundle/environment.rb to the war file.
167
+ # Add Bundler Gemfiles to the war file.
143
168
  def add_bundler_files(config)
144
169
  if config.bundler
145
170
  @files[apply_pathmaps(config, 'Gemfile', :application)] = 'Gemfile'
146
171
  if File.exist?('Gemfile.lock')
147
172
  @files[apply_pathmaps(config, 'Gemfile.lock', :application)] = 'Gemfile.lock'
148
- @files[apply_pathmaps(config, '.bundle/environment.rb', :application)] = '.bundle/war-environment.rb'
149
173
  end
150
174
  end
151
175
  end
data/lib/warbler_war.jar CHANGED
Binary file
@@ -29,7 +29,7 @@ describe Warbler::Task do
29
29
  rm_rf "log"
30
30
  rm_f FileList["config.ru", "*web.xml", "config/web.xml*", "config/warble.rb",
31
31
  "config/special.txt", "config/link.txt", "tmp/gems.jar",
32
- "file.txt", 'Gemfile', 'lib/rakelib']
32
+ "file.txt", 'Gemfile', 'lib/rakelib', '**/*.class']
33
33
  Dir.chdir(@pwd)
34
34
  end
35
35
 
@@ -82,6 +82,21 @@ describe Warbler::Task do
82
82
  Warbler::Task.new "warble", @config
83
83
  end
84
84
 
85
+ it "should compile any ruby files specified" do
86
+ @config.features << "compiled"
87
+ silence { Rake::Task["warble"].invoke }
88
+
89
+ java_class_magic_number = [0xCA,0xFE,0xBA,0xBE].map { |magic_char| magic_char.chr }.join
90
+
91
+ Zip::ZipFile.open("#{@config.war_name}.war") do |zf|
92
+ java_class_header = zf.get_input_stream('WEB-INF/app/helpers/application_helper.class') {|io| io.read }[0..3]
93
+ ruby_class_definition = zf.get_input_stream('WEB-INF/app/helpers/application_helper.rb') {|io| io.read }
94
+
95
+ java_class_header.should == java_class_magic_number
96
+ ruby_class_definition.should == %{require __FILE__.sub(/.rb$/, '.class')}
97
+ end
98
+ end
99
+
85
100
  it "should process symlinks by storing a file in the archive that has the same contents as the source" do
86
101
  File.open("config/special.txt", "wb") {|f| f << "special"}
87
102
  Dir.chdir("config") { ln_s "special.txt", "link.txt" }
@@ -19,16 +19,18 @@ describe Warbler::War do
19
19
  config.war_name = "warbler"
20
20
  config.gems = ["rake"]
21
21
  config.webxml.jruby.max.runtimes = 5
22
- end
22
+ end rescue nil
23
23
  @war = Warbler::War.new
24
+ @env_save = {}
25
+ (ENV.keys.grep(/BUNDLE/) + ["RUBYOPT", "GEM_PATH"]).each {|k| @env_save[k] = ENV[k]; ENV[k] = nil}
24
26
  end
25
27
 
26
28
  after(:each) do
27
- rm_rf "log"
28
- rm_rf ".bundle"
29
+ rm_rf FileList["log", ".bundle", "tmp/war"]
29
30
  rm_f FileList["*.war", "config.ru", "*web.xml*", "config/web.xml*",
30
- "config/warble.rb", "file.txt", 'manifest', 'Gemfile*']
31
+ "config/warble.rb", "file.txt", 'manifest', 'Gemfile*', 'MANIFEST.MF*']
31
32
  Dir.chdir(@pwd)
33
+ @env_save.keys.each {|k| ENV[k] = @env_save[k]}
32
34
  end
33
35
 
34
36
  def file_list(regex)
@@ -364,8 +366,20 @@ describe Warbler::War do
364
366
  file_list(%r{WEB-INF/notexist}).should be_empty
365
367
  end
366
368
 
369
+ it "should exclude Warbler's old tmp/war directory by default" do
370
+ mkdir_p "tmp/war"
371
+ touch "tmp/war/index.html"
372
+ @config = Warbler::Config.new
373
+ @config.dirs += ["tmp"]
374
+ @war.apply(@config)
375
+ file_list(%r{WEB-INF/tmp/war/index\.html}).should be_empty
376
+ end
377
+
367
378
  it "should write gems to location specified by gem_path" do
368
- @config = Warbler::Config.new {|c| c.gem_path = "/WEB-INF/jewels"; c.gems << 'rake' }
379
+ @config = Warbler::Config.new do |c|
380
+ c.gem_path = "/WEB-INF/jewels"
381
+ c.gems << 'rake'
382
+ end
369
383
  elements = expand_webxml
370
384
  file_list(%r{WEB-INF/jewels}).should_not be_empty
371
385
  elements.to_a(
@@ -379,47 +393,41 @@ describe Warbler::War do
379
393
 
380
394
  it "should detect a Bundler Gemfile and process only its gems" do
381
395
  File.open("Gemfile", "w") {|f| f << "gem 'rspec'"}
382
- @war.apply(Warbler::Config.new {|c| c.gems << "rake"})
396
+ @war.apply(conf = Warbler::Config.new {|c| c.gems << "rake"})
383
397
  file_list(%r{WEB-INF/Gemfile}).should_not be_empty
384
398
  file_list(%r{WEB-INF/gems/specifications/rspec}).should_not be_empty
385
399
  file_list(%r{WEB-INF/gems/specifications/rake}).should be_empty
386
400
  end
387
401
 
388
- it "should write a Bundler environment file into the war" do
402
+ it "should copy Bundler gemfiles into the war" do
389
403
  File.open("Gemfile", "w") {|f| f << "gem 'rspec'"}
404
+ File.open("Gemfile.lock", "w") {|f| f << "GEM"}
390
405
  @war.apply(Warbler::Config.new)
391
406
  file_list(%r{WEB-INF/Gemfile}).should_not be_empty
392
- file_list(%r{WEB-INF/Gemfile.lock}).should be_empty
393
- file_list(%r{WEB-INF/\.bundle/environment\.rb}).should be_empty
394
- end
395
-
396
- it "should only include Bundler lockfiles if Gemfile.lock exists" do
397
- File.open("Gemfile", "w") {|f| f << "gem 'rspec'"}
398
- `ruby -S bundle lock`
399
- @war.apply(Warbler::Config.new)
400
407
  file_list(%r{WEB-INF/Gemfile.lock}).should_not be_empty
401
- file_list(%r{WEB-INF/\.bundle/environment\.rb}).should_not be_empty
402
408
  end
403
409
 
404
410
  it "should allow overriding of the gem path when using Bundler" do
405
411
  File.open("Gemfile", "w") {|f| f << "gem 'rspec'"}
406
412
  @war.apply(Warbler::Config.new {|c| c.gem_path = '/WEB-INF/jewels' })
407
413
  file_list(%r{WEB-INF/jewels/specifications/rspec}).should_not be_empty
408
- IO.readlines(".bundle/war-environment.rb").grep(/rspec/).last.should =~ %r{jewels/specifications}m
409
414
  end
410
415
 
411
- it "should not let the framework load Bundler from the locked environment" do
412
- task :environment do
413
- File.exist?('.bundle/environment.rb').should_not be_true
414
- mock_rails_module
415
- end
416
+ it "should work with :git entries in Bundler Gemfiles" do
417
+ File.open("Gemfile", "w") {|f| f << "gem 'warbler', :git => '#{Warbler::WARBLER_HOME}'\n"}
418
+ silence { ruby "-S", "bundle", "install", "--local" }
419
+ @war.apply(Warbler::Config.new)
420
+ file_list(%r{WEB-INF/gems/gems/warbler[^/]*/lib/warbler/version\.rb}).should_not be_empty
421
+ file_list(%r{WEB-INF/gems/specifications/warbler}).should_not be_empty
422
+ end
416
423
 
417
- File.open("Gemfile", "w") {|f| f << "gem 'rspec'"}
418
- `ruby -S bundle lock`
419
- File.exist?('.bundle/environment.rb').should be_true
424
+ it "should not bundle dependencies in the test group by default when bundling" do
425
+ File.open("Gemfile", "w") {|f| f << "gem 'rake'\ngroup :test do\ngem 'rspec'\nend\n"}
420
426
  @war.apply(Warbler::Config.new)
421
- hash = eval("[" + IO.readlines(".bundle/environment.rb").grep(/rspec/).last + "]").first
422
- hash[:load_paths].each {|p| File.exist?(p).should be_true }
427
+ file_list(%r{WEB-INF/gems/gems/rake[^/]*/}).should_not be_empty
428
+ file_list(%r{WEB-INF/gems/gems/rspec[^/]*/}).should be_empty
429
+ file_list(%r{WEB-INF/gems/specifications/rake}).should_not be_empty
430
+ file_list(%r{WEB-INF/gems/specifications/rspec}).should be_empty
423
431
  end
424
432
 
425
433
  it "should allow adding additional WEB-INF files via config.webinf_files" do
@@ -438,4 +446,10 @@ describe Warbler::War do
438
446
  file_list(%r{WEB-INF/myserver-web.xml}).should_not be_empty
439
447
  @war.files['WEB-INF/myserver-web.xml'].read.should =~ /web-app.*production/
440
448
  end
449
+
450
+ it "should exclude test files in gems according to config.gem_excludes" do
451
+ @config.gem_excludes += [/^(test|spec)\//]
452
+ @war.apply(@config)
453
+ file_list(%r{WEB-INF/gems/gems/rake([^/]+)/test/test_rake.rb}).should be_empty
454
+ end
441
455
  end
data/warble.rb CHANGED
@@ -43,6 +43,10 @@ Warbler::Config.new do |config|
43
43
  # functionality, uncomment here.
44
44
  # config.bundler = false
45
45
 
46
+ # An array of Bundler groups to avoid including in the war file.
47
+ # Defaults to ["development", "test"].
48
+ # config.bundle_without = []
49
+
46
50
  # Files for WEB-INF directory (next to web.xml). This contains
47
51
  # web.xml by default. If there is an .erb-File it will be processed
48
52
  # with webxml-config. You may want to exclude this file via
@@ -69,10 +73,15 @@ Warbler::Config.new do |config|
69
73
  # config.gems << /^merb-/
70
74
  # config.gems << Gem::Dependency.new("merb-core", "= 0.9.3")
71
75
 
72
- # Include gem dependencies not mentioned specifically. Default is true, uncomment
73
- # to turn off.
76
+ # Include gem dependencies not mentioned specifically. Default is
77
+ # true, uncomment to turn off.
74
78
  # config.gem_dependencies = false
75
79
 
80
+ # Array of regular expressions matching relative paths in gems to be
81
+ # excluded from the war. Defaults to empty, but you can set it like
82
+ # below, which excludes test files.
83
+ # config.gem_excludes = [/^(test|spec)\//]
84
+
76
85
  # Files to be included in the root of the webapp. Note that files in public
77
86
  # will have the leading 'public/' part of the path stripped during staging.
78
87
  # config.public_html = FileList["public/**/*", "doc/**/*"]
@@ -87,10 +96,15 @@ Warbler::Config.new do |config|
87
96
  # of RAILS_ROOT
88
97
  # config.war_name = "mywar"
89
98
 
90
- # Name of the MANIFEST.MF template for the war file. Defaults to the
91
- # MANIFEST.MF normally generated by `jar cf`.
99
+ # Name of the MANIFEST.MF template for the war file. Defaults to a simple
100
+ # MANIFEST.MF that contains the version of Warbler used to create the war file.
92
101
  # config.manifest_file = "config/MANIFEST.MF"
93
102
 
103
+ # When using the 'compiled' feature and specified, only these Ruby
104
+ # files will be compiled. Default is to compile all \.rb files in
105
+ # the application.
106
+ # config.compiled_ruby_files = FileList['app/**/*.rb']
107
+
94
108
  # Value of RAILS_ENV for the webapp -- default as shown below
95
109
  # config.webxml.rails.env = ENV['RAILS_ENV'] || 'production'
96
110
 
metadata CHANGED
@@ -3,90 +3,95 @@ name: warbler
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 1
7
- - 1
8
- - 0
9
- version: 1.1.0
6
+ - 1
7
+ - 2
8
+ - 0
9
+ version: 1.2.0
10
10
  platform: ruby
11
11
  authors:
12
- - Nick Sieger
12
+ - Nick Sieger
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-13 00:00:00 -05:00
17
+ date: 2010-08-05 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
- - !ruby/object:Gem::Dependency
21
- requirement: &id001 !ruby/object:Gem::Requirement
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- segments:
26
- - 0
27
- - 8
28
- - 7
29
- version: 0.8.7
30
- prerelease: false
31
- type: :runtime
32
- name: rake
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- segments:
40
- - 1
41
- - 4
42
- - 0
43
- version: 1.4.0
44
- prerelease: false
45
- type: :runtime
46
- name: jruby-jars
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- requirement: &id003 !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- segments:
54
- - 0
55
- - 9
56
- - 8
57
- version: 0.9.8
58
- prerelease: false
59
- type: :runtime
60
- name: jruby-rack
61
- version_requirements: *id003
62
- - !ruby/object:Gem::Dependency
63
- requirement: &id004 !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- segments:
68
- - 0
69
- - 9
70
- - 4
71
- version: 0.9.4
72
- prerelease: false
73
- type: :runtime
74
- name: rubyzip
75
- version_requirements: *id004
76
- - !ruby/object:Gem::Dependency
77
- requirement: &id005 !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- segments:
82
- - 2
83
- - 0
84
- - 4
85
- version: 2.0.4
86
- prerelease: false
87
- type: :development
88
- name: rubyforge
89
- version_requirements: *id005
20
+ - !ruby/object:Gem::Dependency
21
+ name: rake
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 8
30
+ - 7
31
+ version: 0.8.7
32
+ requirement: *id001
33
+ prerelease: false
34
+ type: :runtime
35
+ - !ruby/object:Gem::Dependency
36
+ name: jruby-jars
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 4
45
+ - 0
46
+ version: 1.4.0
47
+ requirement: *id002
48
+ prerelease: false
49
+ type: :runtime
50
+ - !ruby/object:Gem::Dependency
51
+ name: jruby-rack
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 1
59
+ - 0
60
+ - 0
61
+ version: 1.0.0
62
+ requirement: *id003
63
+ prerelease: false
64
+ type: :runtime
65
+ - !ruby/object:Gem::Dependency
66
+ name: rubyzip
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ - 9
75
+ - 4
76
+ version: 0.9.4
77
+ requirement: *id004
78
+ prerelease: false
79
+ type: :runtime
80
+ - !ruby/object:Gem::Dependency
81
+ name: rubyforge
82
+ version_requirements: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 2
89
+ - 0
90
+ - 4
91
+ version: 2.0.4
92
+ requirement: *id005
93
+ prerelease: false
94
+ type: :development
90
95
  description: |-
91
96
  Warbler is a gem to make a .war file out of a Rails, Merb, or Rack-based
92
97
  application. The intent is to provide a minimal, flexible, ruby-like way to
@@ -94,92 +99,94 @@ description: |-
94
99
  server.
95
100
  email: nick@nicksieger.com
96
101
  executables:
97
- - warble
102
+ - warble
98
103
  extensions: []
99
104
 
100
105
  extra_rdoc_files:
101
- - History.txt
102
- - LICENSE.txt
103
- - Manifest.txt
104
- - README.txt
106
+ - History.txt
107
+ - LICENSE.txt
108
+ - Manifest.txt
109
+ - README.txt
105
110
  files:
106
- - Gemfile
107
- - History.txt
108
- - LICENSE.txt
109
- - Manifest.txt
110
- - README.txt
111
- - Rakefile
112
- - bin/warble
113
- - ext/Main.java
114
- - ext/WarblerWar.java
115
- - ext/WarblerWarService.java
116
- - lib/warbler.rb
117
- - lib/warbler/application.rb
118
- - lib/warbler/config.rb
119
- - lib/warbler/gems.rb
120
- - lib/warbler/runtime.rb
121
- - lib/warbler/task.rb
122
- - lib/warbler/version.rb
123
- - lib/warbler/war.rb
124
- - lib/warbler_war.jar
125
- - spec/sample/app/controllers/application.rb
126
- - spec/sample/app/helpers/application_helper.rb
127
- - spec/sample/config/boot.rb
128
- - spec/sample/config/database.yml
129
- - spec/sample/config/environment.rb
130
- - spec/sample/config/environments/development.rb
131
- - spec/sample/config/environments/production.rb
132
- - spec/sample/config/environments/test.rb
133
- - spec/sample/config/initializers/inflections.rb
134
- - spec/sample/config/initializers/mime_types.rb
135
- - spec/sample/config/initializers/new_rails_defaults.rb
136
- - spec/sample/config/routes.rb
137
- - spec/sample/lib/tasks/utils.rake
138
- - spec/sample/public/404.html
139
- - spec/sample/public/422.html
140
- - spec/sample/public/500.html
141
- - spec/sample/public/favicon.ico
142
- - spec/sample/public/index.html
143
- - spec/sample/public/robots.txt
144
- - spec/spec_helper.rb
145
- - spec/warbler/application_spec.rb
146
- - spec/warbler/config_spec.rb
147
- - spec/warbler/gems_spec.rb
148
- - spec/warbler/task_spec.rb
149
- - spec/warbler/war_spec.rb
150
- - warble.rb
151
- - web.xml.erb
111
+ - Gemfile
112
+ - History.txt
113
+ - LICENSE.txt
114
+ - Manifest.txt
115
+ - README.txt
116
+ - Rakefile
117
+ - bin/warble
118
+ - ext/Main.java
119
+ - ext/WarblerWar.java
120
+ - ext/WarblerWarService.java
121
+ - lib/warbler.rb
122
+ - lib/warbler/application.rb
123
+ - lib/warbler/config.rb
124
+ - lib/warbler/gems.rb
125
+ - lib/warbler/task.rb
126
+ - lib/warbler/version.rb
127
+ - lib/warbler/war.rb
128
+ - lib/warbler_war.jar
129
+ - spec/sample/app/controllers/application.rb
130
+ - spec/sample/app/helpers/application_helper.rb
131
+ - spec/sample/config/boot.rb
132
+ - spec/sample/config/database.yml
133
+ - spec/sample/config/environment.rb
134
+ - spec/sample/config/environments/development.rb
135
+ - spec/sample/config/environments/production.rb
136
+ - spec/sample/config/environments/test.rb
137
+ - spec/sample/config/initializers/inflections.rb
138
+ - spec/sample/config/initializers/mime_types.rb
139
+ - spec/sample/config/initializers/new_rails_defaults.rb
140
+ - spec/sample/config/routes.rb
141
+ - spec/sample/lib/tasks/utils.rake
142
+ - spec/sample/public/404.html
143
+ - spec/sample/public/422.html
144
+ - spec/sample/public/500.html
145
+ - spec/sample/public/favicon.ico
146
+ - spec/sample/public/index.html
147
+ - spec/sample/public/robots.txt
148
+ - spec/spec_helper.rb
149
+ - spec/warbler/application_spec.rb
150
+ - spec/warbler/config_spec.rb
151
+ - spec/warbler/gems_spec.rb
152
+ - spec/warbler/task_spec.rb
153
+ - spec/warbler/war_spec.rb
154
+ - warble.rb
155
+ - web.xml.erb
152
156
  has_rdoc: true
153
157
  homepage: http://caldersphere.rubyforge.org/warbler
154
158
  licenses: []
155
159
 
156
160
  post_install_message:
157
161
  rdoc_options:
158
- - --main
159
- - README.txt
160
- - -SHN
161
- - -f
162
- - darkfish
162
+ - --main
163
+ - README.txt
164
+ - -SHN
165
+ - -f
166
+ - darkfish
163
167
  require_paths:
164
- - lib
168
+ - lib
165
169
  required_ruby_version: !ruby/object:Gem::Requirement
170
+ none: false
166
171
  requirements:
167
- - - ">="
168
- - !ruby/object:Gem::Version
169
- segments:
170
- - 0
171
- version: "0"
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ hash: 2
175
+ segments:
176
+ - 0
177
+ version: "0"
172
178
  required_rubygems_version: !ruby/object:Gem::Requirement
179
+ none: false
173
180
  requirements:
174
- - - ">="
175
- - !ruby/object:Gem::Version
176
- segments:
177
- - 0
178
- version: "0"
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ segments:
184
+ - 0
185
+ version: "0"
179
186
  requirements: []
180
187
 
181
188
  rubyforge_project: caldersphere
182
- rubygems_version: 1.3.6
189
+ rubygems_version: 1.3.7
183
190
  signing_key:
184
191
  specification_version: 3
185
192
  summary: Warbler chirpily constructs .war files of your Rails applications.
@@ -1,44 +0,0 @@
1
- module Warbler
2
- # Extension module for a Bundler::Runtime instance, to add methods
3
- # to create a Bundler environment file specific to war packaging.
4
- module Runtime
5
- WAR_ENV = ".bundle/war-environment.rb"
6
-
7
- attr_writer :gem_path
8
- def gem_path
9
- @gem_path || Config::DEFAULT_GEM_PATH
10
- end
11
-
12
- class Spec
13
- def initialize(spec, gem_path)
14
- location = spec[:loaded_from][%r{(.*)/specifications}, 1]
15
- spec = spec.dup
16
- spec[:loaded_from] = spec[:loaded_from].sub(location, gem_path)
17
- spec[:load_paths] = spec[:load_paths].map {|p| p.sub(location, gem_path)}
18
- @spec = spec
19
- end
20
-
21
- def inspect
22
- str = @spec.inspect
23
- str.gsub(%r'"/WEB-INF(/[^"]*)"', 'File.expand_path("../..\1", __FILE__)')
24
- end
25
- end
26
-
27
- # deprecated; compatibility with Bundler <= 0.9.14
28
- def rb_lock_file #:nocov:
29
- root.join(WAR_ENV) #:nocov:
30
- end #:nocov:
31
-
32
- def specs_for_lock_file
33
- super.map {|s| Spec.new(s, gem_path)}
34
- end
35
-
36
- def write_war_environment
37
- write_rb_lock
38
- end
39
-
40
- def war_specs
41
- respond_to?(:requested_specs) ? requested_specs : specs_for
42
- end
43
- end
44
- end