Skip to content

Commit

Permalink
Support bundle_without and default to excluding 'development' and 'test'
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksieger committed Jul 29, 2010
1 parent 0998de7 commit 56651b6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/warbler/config.rb
Expand Up @@ -77,6 +77,10 @@ class Config
# Use Bundler to locate gems if Gemfile is found. Default is true.
attr_accessor :bundler

# An array of Bundler groups to avoid including in the war file.
# Defaults to ["development", "test"].
attr_accessor :bundle_without

# Path to the pre-bundled gem directory inside the war file. Default is '/WEB-INF/gems'.
# This also sets 'gem.path' inside web.xml.
attr_accessor :gem_path
Expand Down Expand Up @@ -130,6 +134,7 @@ def initialize(warbler_home = WARBLER_HOME)
@rails_root = default_rails_root
@war_name = File.basename(@rails_root)
@bundler = true
@bundle_without = ["development", "test"]
@webinf_files = default_webinf_files

auto_detect_frameworks
Expand Down Expand Up @@ -215,8 +220,8 @@ def detect_bundler_gems
root = gemfile.dirname
lockfile = root.join('Gemfile.lock')
definition = Bundler::Definition.build(gemfile, lockfile, nil)
env = Bundler::Runtime.new(root, definition)
env.requested_specs.each {|spec| @gems << spec }
groups = definition.groups - @bundle_without.map {|g| g.to_sym}
definition.specs_for(groups).each {|spec| @gems << spec }
else
@bundler = false
end
Expand Down
9 changes: 9 additions & 0 deletions spec/warbler/war_spec.rb
Expand Up @@ -413,6 +413,15 @@ class << t; public :instance_variable_get; end
file_list(%r{WEB-INF/gems/specifications/warbler}).should_not be_empty
end

it "should not bundle dependencies in the test group by default when bundling" do
File.open("Gemfile", "w") {|f| f << "gem 'rake'\ngroup :test do\ngem 'rspec'\nend\n"}
@war.apply(Warbler::Config.new)
file_list(%r{WEB-INF/gems/gems/rake[^/]*/}).should_not be_empty
file_list(%r{WEB-INF/gems/gems/rspec[^/]*/}).should be_empty
file_list(%r{WEB-INF/gems/specifications/rake}).should_not be_empty
file_list(%r{WEB-INF/gems/specifications/rspec}).should be_empty
end

it "should allow adding additional WEB-INF files via config.webinf_files" do
File.open("myserver-web.xml", "w") do |f|
f << "<web-app></web-app>"
Expand Down
4 changes: 4 additions & 0 deletions warble.rb
Expand Up @@ -43,6 +43,10 @@
# functionality, uncomment here.
# config.bundler = false

# An array of Bundler groups to avoid including in the war file.
# Defaults to ["development", "test"].
# config.bundle_without = []

# Files for WEB-INF directory (next to web.xml). This contains
# web.xml by default. If there is an .erb-File it will be processed
# with webxml-config. You may want to exclude this file via
Expand Down

1 comment on commit 56651b6

@fnichol
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great addition, I've been waiting on this one for skinnier war deployments. I'll be testing that out right now :)

Please sign in to comment.