Permalink
Browse files

Get code working and specs clean with Bundler 1.0 RC

  • Loading branch information...
1 parent b3ea35b commit 2d038269ff756070370981b5db5e752bee23a8ba @nicksieger committed Jul 27, 2010
Showing with 50 additions and 172 deletions.
  1. +0 −1 .gitignore
  2. +33 −65 Gemfile.lock
  3. +0 −1 Manifest.txt
  4. +1 −2 Rakefile
  5. +0 −1 lib/warbler.rb
  6. +9 −31 lib/warbler/config.rb
  7. +0 −44 lib/warbler/runtime.rb
  8. +7 −27 spec/warbler/war_spec.rb
View
@@ -1,5 +1,4 @@
coverage*
pkg
doc
-spec/sample
.bundle
View
@@ -1,65 +1,33 @@
----
-dependencies:
- diff-lcs:
- group:
- - :default
- version: ">= 0"
- jruby-rack:
- group:
- - :default
- version: ">= 0"
- rake:
- group:
- - :default
- version: ">= 0.8.7"
- rspec:
- group:
- - :default
- version: ">= 0"
- jruby-jars:
- group:
- - :default
- version: ">= 0"
- rcov:
- group:
- - :default
- version: ">= 0.9.8"
- hoe:
- group:
- - :default
- version: ">= 2.3.2"
- rubyzip:
- group:
- - :default
- version: ">= 0"
- rdoc:
- group:
- - :default
- version: ">= 0"
-specs:
-- rake:
- version: 0.8.7
-- diff-lcs:
- version: 1.1.2
-- json_pure:
- version: 1.4.3
-- rubyforge:
- version: 2.0.4
-- hoe:
- version: 2.6.0
-- jruby-jars:
- version: 1.5.0
-- jruby-rack:
- version: 0.9.7
-- rcov:
- version: 0.9.8
-- rdoc:
- version: 2.5.8
-- rspec:
- version: 1.3.0
-- rubyzip:
- version: 0.9.4
-hash: 8f82c6b60dddd0684b4c02af386b7461f1ba8973
-sources:
-- Rubygems:
- uri: http://rubygems.org/
+GEM
+ remote: http://rubygems.org/
+ specs:
+ diff-lcs (1.1.2)
+ hoe (2.6.1)
+ rake (>= 0.8.7)
+ rubyforge (>= 2.0.4)
+ jruby-jars (1.5.1)
+ jruby-rack (1.0.1)
+ json_pure (1.4.3)
+ rake (0.8.7)
+ rcov (0.9.8-java)
+ rcov (0.9.8)
+ rdoc (2.5.9)
+ rspec (1.3.0)
+ rubyforge (2.0.4)
+ json_pure (>= 1.1.7)
+ rubyzip (0.9.4)
+
+PLATFORMS
+ java
+ ruby
+
+DEPENDENCIES
+ diff-lcs
+ hoe (>= 2.3.2)
+ jruby-jars
+ jruby-rack
+ rake (>= 0.8.7)
+ rcov (>= 0.9.8)
+ rdoc
+ rspec
+ rubyzip
View
@@ -13,7 +13,6 @@ lib/warbler.rb
lib/warbler/application.rb
lib/warbler/config.rb
lib/warbler/gems.rb
-lib/warbler/runtime.rb
lib/warbler/task.rb
lib/warbler/version.rb
lib/warbler/war.rb
View
@@ -6,8 +6,7 @@
#++
begin
- require 'bundler'
- Bundler.setup
+ require 'bundler/setup'
rescue LoadError
puts "Please install Bundler and run 'bundle install' to ensure you have all dependencies"
end
View
@@ -34,4 +34,3 @@ def self.project_application
require 'warbler/war'
require 'warbler/task'
require 'warbler/application'
-require 'warbler/runtime'
View
@@ -204,26 +204,13 @@ def detect_bundler_gems
if @bundler && File.exist?("Gemfile")
@gems.clear
@gem_dependencies = false # Bundler takes care of these
- begin
- require 'bundler'
- env = Bundler::Runtime.new(Bundler.root, Bundler.definition)
- if bundler_env_file = Bundler.respond_to?(:env_file)
- class << Bundler
- alias orig_env_file env_file
- def env_file; root.join(::Warbler::Runtime::WAR_ENV); end
- end
- end
- env.extend Warbler::Runtime
- env.gem_path = @gem_path
- env.write_war_environment
- env.war_specs.each {|spec| @gems << spec }
- ensure
- if bundler_env_file
- class << Bundler
- alias env_file orig_env_file
- end
- end
- end
+ require 'bundler'
+ gemfile = Pathname.new("Gemfile").expand_path
+ 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 }
else
@bundler = false
end
@@ -237,16 +224,7 @@ def default_jar_files
def auto_detect_frameworks
return unless Warbler.framework_detection
- if File.exist?(".bundle/environment.rb")
- begin # Don't want Bundler to load from .bundle/environment
- mv(".bundle/environment.rb",".bundle/environment-save.rb", :verbose => false)
- auto_detect_rails || auto_detect_merb || auto_detect_rackup
- ensure
- mv(".bundle/environment-save.rb",".bundle/environment.rb", :verbose => false)
- end
- else
- auto_detect_rails || auto_detect_merb || auto_detect_rackup
- end
+ auto_detect_rails || auto_detect_merb || auto_detect_rackup
end
def auto_detect_rails
@@ -296,7 +274,7 @@ def auto_detect_rackup
# Helper class for holding arbitrary config.webxml values for injecting into +web.xml+.
class WebxmlOpenStruct < OpenStruct
- %w(java com org javax).each {|name| undef_method name if Object.methods.include?(name) }
+ %w(java com org javax gem).each {|name| undef_method name if Object.methods.include?(name) }
def initialize(key = 'webxml')
@key = key
@@ -1,44 +0,0 @@
-module Warbler
- # Extension module for a Bundler::Runtime instance, to add methods
- # to create a Bundler environment file specific to war packaging.
- module Runtime
- WAR_ENV = ".bundle/war-environment.rb"
-
- attr_writer :gem_path
- def gem_path
- @gem_path || Config::DEFAULT_GEM_PATH
- end
-
- class Spec
- def initialize(spec, gem_path)
- location = spec[:loaded_from][%r{(.*)/specifications}, 1]
- spec = spec.dup
- spec[:loaded_from] = spec[:loaded_from].sub(location, gem_path)
- spec[:load_paths] = spec[:load_paths].map {|p| p.sub(location, gem_path)}
- @spec = spec
- end
-
- def inspect
- str = @spec.inspect
- str.gsub(%r'"/WEB-INF(/[^"]*)"', 'File.expand_path("../..\1", __FILE__)')
- end
- end
-
- # deprecated; compatibility with Bundler <= 0.9.14
- def rb_lock_file #:nocov:
- root.join(WAR_ENV) #:nocov:
- end #:nocov:
-
- def specs_for_lock_file
- super.map {|s| Spec.new(s, gem_path)}
- end
-
- def write_war_environment
- write_rb_lock
- end
-
- def war_specs
- respond_to?(:requested_specs) ? requested_specs : specs_for
- end
- end
-end
@@ -365,7 +365,10 @@ class << t; public :instance_variable_get; end
end
it "should write gems to location specified by gem_path" do
- @config = Warbler::Config.new {|c| c.gem_path = "/WEB-INF/jewels"; c.gems << 'rake' }
+ @config = Warbler::Config.new do |c|
+ c.gem_path = "/WEB-INF/jewels"
+ c.gems << 'rake'
+ end
elements = expand_webxml
file_list(%r{WEB-INF/jewels}).should_not be_empty
elements.to_a(
@@ -379,47 +382,24 @@ class << t; public :instance_variable_get; end
it "should detect a Bundler Gemfile and process only its gems" do
File.open("Gemfile", "w") {|f| f << "gem 'rspec'"}
- @war.apply(Warbler::Config.new {|c| c.gems << "rake"})
+ @war.apply(conf = Warbler::Config.new {|c| c.gems << "rake"})
file_list(%r{WEB-INF/Gemfile}).should_not be_empty
file_list(%r{WEB-INF/gems/specifications/rspec}).should_not be_empty
file_list(%r{WEB-INF/gems/specifications/rake}).should be_empty
end
- it "should write a Bundler environment file into the war" do
+ it "should copy Bundler gemfiles into the war" do
File.open("Gemfile", "w") {|f| f << "gem 'rspec'"}
+ File.open("Gemfile.lock", "w") {|f| f << "GEM"}
@war.apply(Warbler::Config.new)
file_list(%r{WEB-INF/Gemfile}).should_not be_empty
- file_list(%r{WEB-INF/Gemfile.lock}).should be_empty
- file_list(%r{WEB-INF/\.bundle/environment\.rb}).should be_empty
- end
-
- it "should only include Bundler lockfiles if Gemfile.lock exists" do
- File.open("Gemfile", "w") {|f| f << "gem 'rspec'"}
- `ruby -S bundle lock`
- @war.apply(Warbler::Config.new)
file_list(%r{WEB-INF/Gemfile.lock}).should_not be_empty
- file_list(%r{WEB-INF/\.bundle/environment\.rb}).should_not be_empty
end
it "should allow overriding of the gem path when using Bundler" do
File.open("Gemfile", "w") {|f| f << "gem 'rspec'"}
@war.apply(Warbler::Config.new {|c| c.gem_path = '/WEB-INF/jewels' })
file_list(%r{WEB-INF/jewels/specifications/rspec}).should_not be_empty
- IO.readlines(".bundle/war-environment.rb").grep(/rspec/).last.should =~ %r{jewels/specifications}m
- end
-
- it "should not let the framework load Bundler from the locked environment" do
- task :environment do
- File.exist?('.bundle/environment.rb').should_not be_true
- mock_rails_module
- end
-
- File.open("Gemfile", "w") {|f| f << "gem 'rspec'"}
- `ruby -S bundle lock`
- File.exist?('.bundle/environment.rb').should be_true
- @war.apply(Warbler::Config.new)
- hash = eval("[" + IO.readlines(".bundle/environment.rb").grep(/rspec/).last + "]").first
- hash[:load_paths].each {|p| File.exist?(p).should be_true }
end
it "should allow adding additional WEB-INF files via config.webinf_files" do

0 comments on commit 2d03826

Please sign in to comment.