Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Calculate proper path the Gemfile instead of just hoping 'Gemfile' works

Fixes #37.
  • Loading branch information...
commit 404b9bada186e0579fd326783bc35d3f86931175 1 parent e822271
@nicksieger authored
View
1  Manifest.txt
@@ -15,6 +15,7 @@ lib/warbler/application.rb
lib/warbler/config.rb
lib/warbler/gems.rb
lib/warbler/jar.rb
+lib/warbler/pathmap_helper.rb
lib/warbler/rake_helper.rb
lib/warbler/task.rb
lib/warbler/templates
View
1  lib/warbler.rb
@@ -30,5 +30,6 @@ def self.project_application
require 'warbler/version'
require 'warbler/rake_helper'
+require 'warbler/pathmap_helper'
require 'warbler/task'
require 'warbler/application'
View
10 lib/warbler/jar.rb
@@ -17,6 +17,7 @@ module Warbler
# * Any object responding to +read+ representing an in-memory blob
# * A String filename pointing to a file on disk
class Jar
+ include PathmapHelper
include RakeHelper
DEFAULT_MANIFEST = %{Manifest-Version: 1.0\nCreated-By: Warbler #{Warbler::VERSION}\n\n}
@@ -196,15 +197,6 @@ def erb_binding(config)
binding
end
- def apply_pathmaps(config, file, pathmaps)
- file = file[2..-1] if file =~ /^\.\//
- pathmaps = config.pathmaps.send(pathmaps)
- pathmaps.each do |p|
- file = file.pathmap(p)
- end if pathmaps
- file
- end
-
def ensure_directory_entries
files.select {|k,v| !v.nil? }.each do |k,v|
dir = File.dirname(k)
View
13 lib/warbler/pathmap_helper.rb
@@ -0,0 +1,13 @@
+module Warbler
+ module PathmapHelper
+ def apply_pathmaps(config, file, pathmaps)
+ file = file.to_s
+ file = file[2..-1] if file =~ /^\.\//
+ pathmaps = config.pathmaps.send(pathmaps)
+ pathmaps.each do |p|
+ file = file.pathmap(p)
+ end if pathmaps
+ file
+ end
+ end
+end
View
2  lib/warbler/templates/bundler.erb
@@ -1,3 +1,3 @@
ENV['BUNDLE_WITHOUT'] = '<%= config.bundle_without.join(':') %>'
-ENV['BUNDLE_GEMFILE'] = '<%= config.bundler[:gemfile].basename %>'
+ENV['BUNDLE_GEMFILE'] = File.expand_path('../../<%= config.bundler[:gemfile_path] %>', __FILE__)
<% if config.bundler[:frozen] %>ENV['BUNDLE_FROZEN'] = '1'<% end %>
View
17 lib/warbler/traits/bundler.rb
@@ -11,6 +11,7 @@ module Traits
# be added to the project.
class Bundler
include Trait
+ include PathmapHelper
def self.detect?
File.exist?(ENV['BUNDLE_GEMFILE'] || "Gemfile")
@@ -58,6 +59,7 @@ def add_bundler_gems
end
end
config.bundler[:gemfile] = ::Bundler.default_gemfile
+ config.bundler[:gemfile_path] = apply_pathmaps(config, relative_from_pwd(::Bundler.default_gemfile), :application)
config.bundler[:lockfile] = ::Bundler.default_lockfile
config.bundler[:frozen] = ::Bundler.settings[:frozen]
path = ::Bundler.settings[:path]
@@ -71,12 +73,11 @@ def update_archive(jar)
# Add Bundler Gemfiles and git repositories to the archive.
def add_bundler_files(jar)
- pwd = Pathname.new(Dir.pwd)
- gemfile = config.bundler[:gemfile].relative_path_from(pwd).to_s
- lockfile = config.bundler[:lockfile].relative_path_from(pwd).to_s
- jar.files[jar.apply_pathmaps(config, gemfile, :application)] = config.bundler[:gemfile].to_s
+ gemfile = relative_from_pwd(config.bundler[:gemfile])
+ lockfile = relative_from_pwd(config.bundler[:lockfile])
+ jar.files[apply_pathmaps(config, gemfile, :application)] = config.bundler[:gemfile].to_s
if File.exist?(lockfile)
- jar.files[jar.apply_pathmaps(config, lockfile, :application)] = config.bundler[:lockfile].to_s
+ jar.files[apply_pathmaps(config, lockfile, :application)] = config.bundler[:lockfile].to_s
end
if config.bundler[:git_specs]
pathmap = "#{config.relative_gem_path}/bundler/gems/%p"
@@ -92,12 +93,16 @@ def add_bundler_files(jar)
FileList[pattern].each do |src|
f = Pathname.new(src).relative_path_from(full_gem_path).to_s
next if config.gem_excludes && config.gem_excludes.any? {|rx| f =~ rx }
- jar.files[jar.apply_pathmaps(config, File.join(full_gem_path.basename, f), :git)] = src
+ jar.files[apply_pathmaps(config, File.join(full_gem_path.basename, f), :git)] = src
end
end
end
end
+ def relative_from_pwd(path)
+ path.relative_path_from(Pathname.new(Dir.pwd)).to_s
+ end
+
private
def bundler_specs
View
7 lib/warbler/traits/gemspec.rb
@@ -11,6 +11,7 @@ module Traits
# executables, require paths, and dependencies for a project.
class Gemspec
include Trait
+ include PathmapHelper
def self.detect?
!Dir['*.gemspec'].empty?
@@ -33,14 +34,14 @@ def after_configure
def update_archive(jar)
(Dir['**/*'] - config.compiled_ruby_files).each do |f|
- jar.files[jar.apply_pathmaps(config, f, :application)] = f
+ jar.files[apply_pathmaps(config, f, :application)] = f
end
config.compiled_ruby_files.each do |f|
f = f.sub(/\.rb$/, '.class')
next unless File.exist?(f)
- jar.files[jar.apply_pathmaps(config, f, :application)] = f
+ jar.files[apply_pathmaps(config, f, :application)] = f
end
- bin_path = jar.apply_pathmaps(config, default_executable, :application)
+ bin_path = apply_pathmaps(config, default_executable, :application)
add_main_rb(jar, bin_path)
end
View
3  lib/warbler/traits/nogemspec.rb
@@ -12,6 +12,7 @@ module Traits
# +lib+ directories.
class NoGemspec
include Trait
+ include PathmapHelper
def self.detect?
Jar.detect? && !Gemspec.detect?
@@ -28,7 +29,7 @@ def after_configure
end
def update_archive(jar)
- add_main_rb(jar, jar.apply_pathmaps(config, default_executable, :application))
+ add_main_rb(jar, apply_pathmaps(config, default_executable, :application))
end
def default_executable
View
7 lib/warbler/traits/war.rb
@@ -11,8 +11,9 @@ module Warbler
module Traits
# The War trait sets up the layout and generates web.xml for the war project.
class War
- include RakeHelper
include Trait
+ include RakeHelper
+ include PathmapHelper
DEFAULT_GEM_PATH = '/WEB-INF/gems'
@@ -90,9 +91,9 @@ def add_public_files(jar)
def add_webxml(jar)
config.webinf_files.each do |wf|
if wf =~ /\.erb$/
- jar.files[jar.apply_pathmaps(config, wf, :webinf)] = jar.expand_erb(wf, config)
+ jar.files[apply_pathmaps(config, wf, :webinf)] = jar.expand_erb(wf, config)
else
- jar.files[jar.apply_pathmaps(config, wf, :webinf)] = wf
+ jar.files[apply_pathmaps(config, wf, :webinf)] = wf
end
end
end
View
2  lib/warbler/version.rb
@@ -6,5 +6,5 @@
#++
module Warbler
- VERSION = "1.3.2"
+ VERSION = "1.3.3"
end
View
BIN  lib/warbler_jar.jar
Binary file not shown
View
9 spec/warbler/bundler_spec.rb
@@ -101,6 +101,12 @@ def use_config(&block)
contents.should =~ /'development:test'/
end
+ it "adds BUNDLE_GEMFILE to init.rb" do
+ jar.add_init_file(config)
+ contents = jar.contents('META-INF/init.rb')
+ contents.should =~ /ENV\['BUNDLE_GEMFILE'\] = File.expand_path(.*, __FILE__)/
+ end
+
it "uses ENV['BUNDLE_GEMFILE'] if set" do
mv "Gemfile", "Special-Gemfile"
ENV['BUNDLE_GEMFILE'] = "Special-Gemfile"
@@ -118,6 +124,9 @@ def use_config(&block)
jar.apply(config)
file_list(%r{^bundler/gems/warbler[^/]*/lib/warbler/version\.rb}).should_not be_empty
file_list(%r{^bundler/gems/warbler[^/]*/warbler.gemspec}).should_not be_empty
+ jar.add_init_file(config)
+ contents = jar.contents('META-INF/init.rb')
+ contents.should =~ /ENV\['BUNDLE_GEMFILE'\] = File.expand_path(.*, __FILE__)/
end
end
View
6 warbler.gemspec
@@ -2,11 +2,11 @@
Gem::Specification.new do |s|
s.name = %q{warbler}
- s.version = "1.3.2"
+ s.version = "1.3.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Nick Sieger"]
- s.date = %q{2011-08-16}
+ s.date = %q{2011-08-17}
s.default_executable = %q{warble}
s.description = %q{Warbler is a gem to make a Java jar or war file out of any Ruby,
Rails, Merb, or Rack application. Warbler provides a minimal,
@@ -15,7 +15,7 @@ deployment to a Java environment.}
s.email = %q{nick@nicksieger.com}
s.executables = ["warble"]
s.extra_rdoc_files = ["History.txt", "LICENSE.txt", "Manifest.txt", "README.txt"]
- s.files = ["Gemfile", "History.txt", "LICENSE.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/warble", "ext/JarMain.java", "ext/WarMain.java", "ext/WarblerJar.java", "ext/WarblerJarService.java", "lib/warbler.rb", "lib/warbler/application.rb", "lib/warbler/config.rb", "lib/warbler/gems.rb", "lib/warbler/jar.rb", "lib/warbler/rake_helper.rb", "lib/warbler/task.rb", "lib/warbler/templates/bundler.erb", "lib/warbler/templates/config.erb", "lib/warbler/templates/jar.erb", "lib/warbler/templates/rack.erb", "lib/warbler/templates/rails.erb", "lib/warbler/templates/war.erb", "lib/warbler/traits.rb", "lib/warbler/traits/bundler.rb", "lib/warbler/traits/gemspec.rb", "lib/warbler/traits/jar.rb", "lib/warbler/traits/merb.rb", "lib/warbler/traits/nogemspec.rb", "lib/warbler/traits/rack.rb", "lib/warbler/traits/rails.rb", "lib/warbler/traits/war.rb", "lib/warbler/version.rb", "lib/warbler/war.rb", "lib/warbler_jar.jar", "spec/drb_helper.rb", "spec/sample_bundler/Gemfile.lock", "spec/sample_bundler/config.ru", "spec/sample_bundler/vendor/bundle/jruby/1.8/cache/rake-0.8.7.gem", "spec/sample_bundler/vendor/bundle/jruby/1.8/gems/rake-0.8.7/lib/rake.rb", "spec/sample_bundler/vendor/bundle/jruby/1.8/specifications/rake-0.8.7.gemspec", "spec/sample_bundler/vendor/bundle/ruby/1.8/cache/rake-0.8.7.gem", "spec/sample_bundler/vendor/bundle/ruby/1.8/gems/rake-0.8.7/lib/rake.rb", "spec/sample_bundler/vendor/bundle/ruby/1.8/specifications/rake-0.8.7.gemspec", "spec/sample_bundler/vendor/bundle/ruby/1.9.1/cache/rake-0.8.7.gem", "spec/sample_bundler/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb", "spec/sample_bundler/vendor/bundle/ruby/1.9.1/specifications/rake-0.8.7.gemspec", "spec/sample_jar/History.txt", "spec/sample_jar/Manifest.txt", "spec/sample_jar/README.txt", "spec/sample_jar/lib/sample_jar.rb", "spec/sample_jar/sample_jar.gemspec", "spec/sample_jar/test/test_sample_jar.rb", "spec/sample_war/app/controllers/application.rb", "spec/sample_war/app/helpers/application_helper.rb", "spec/sample_war/config/boot.rb", "spec/sample_war/config/database.yml", "spec/sample_war/config/environment.rb", "spec/sample_war/config/environments/development.rb", "spec/sample_war/config/environments/production.rb", "spec/sample_war/config/environments/test.rb", "spec/sample_war/config/initializers/inflections.rb", "spec/sample_war/config/initializers/mime_types.rb", "spec/sample_war/config/initializers/new_rails_defaults.rb", "spec/sample_war/config/routes.rb", "spec/sample_war/lib/tasks/utils.rake", "spec/sample_war/public/404.html", "spec/sample_war/public/422.html", "spec/sample_war/public/500.html", "spec/sample_war/public/favicon.ico", "spec/sample_war/public/index.html", "spec/sample_war/public/robots.txt", "spec/spec_helper.rb", "spec/warbler/application_spec.rb", "spec/warbler/bundler_spec.rb", "spec/warbler/config_spec.rb", "spec/warbler/gems_spec.rb", "spec/warbler/jar_spec.rb", "spec/warbler/task_spec.rb", "spec/warbler/traits_spec.rb", "spec/warbler/war_spec.rb", "warble.rb", "web.xml.erb"]
+ s.files = ["Gemfile", "History.txt", "LICENSE.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/warble", "ext/JarMain.java", "ext/WarMain.java", "ext/WarblerJar.java", "ext/WarblerJarService.java", "lib/warbler.rb", "lib/warbler/application.rb", "lib/warbler/config.rb", "lib/warbler/gems.rb", "lib/warbler/jar.rb", "lib/warbler/pathmap_helper.rb", "lib/warbler/rake_helper.rb", "lib/warbler/task.rb", "lib/warbler/templates/bundler.erb", "lib/warbler/templates/config.erb", "lib/warbler/templates/jar.erb", "lib/warbler/templates/rack.erb", "lib/warbler/templates/rails.erb", "lib/warbler/templates/war.erb", "lib/warbler/traits.rb", "lib/warbler/traits/bundler.rb", "lib/warbler/traits/gemspec.rb", "lib/warbler/traits/jar.rb", "lib/warbler/traits/merb.rb", "lib/warbler/traits/nogemspec.rb", "lib/warbler/traits/rack.rb", "lib/warbler/traits/rails.rb", "lib/warbler/traits/war.rb", "lib/warbler/version.rb", "lib/warbler/war.rb", "lib/warbler_jar.jar", "spec/drb_helper.rb", "spec/sample_bundler/Gemfile.lock", "spec/sample_bundler/config.ru", "spec/sample_bundler/vendor/bundle/jruby/1.8/cache/rake-0.8.7.gem", "spec/sample_bundler/vendor/bundle/jruby/1.8/gems/rake-0.8.7/lib/rake.rb", "spec/sample_bundler/vendor/bundle/jruby/1.8/specifications/rake-0.8.7.gemspec", "spec/sample_bundler/vendor/bundle/ruby/1.8/cache/rake-0.8.7.gem", "spec/sample_bundler/vendor/bundle/ruby/1.8/gems/rake-0.8.7/lib/rake.rb", "spec/sample_bundler/vendor/bundle/ruby/1.8/specifications/rake-0.8.7.gemspec", "spec/sample_bundler/vendor/bundle/ruby/1.9.1/cache/rake-0.8.7.gem", "spec/sample_bundler/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb", "spec/sample_bundler/vendor/bundle/ruby/1.9.1/specifications/rake-0.8.7.gemspec", "spec/sample_jar/History.txt", "spec/sample_jar/Manifest.txt", "spec/sample_jar/README.txt", "spec/sample_jar/lib/sample_jar.rb", "spec/sample_jar/sample_jar.gemspec", "spec/sample_jar/test/test_sample_jar.rb", "spec/sample_war/app/controllers/application.rb", "spec/sample_war/app/helpers/application_helper.rb", "spec/sample_war/config/boot.rb", "spec/sample_war/config/database.yml", "spec/sample_war/config/environment.rb", "spec/sample_war/config/environments/development.rb", "spec/sample_war/config/environments/production.rb", "spec/sample_war/config/environments/test.rb", "spec/sample_war/config/initializers/inflections.rb", "spec/sample_war/config/initializers/mime_types.rb", "spec/sample_war/config/initializers/new_rails_defaults.rb", "spec/sample_war/config/routes.rb", "spec/sample_war/lib/tasks/utils.rake", "spec/sample_war/public/404.html", "spec/sample_war/public/422.html", "spec/sample_war/public/500.html", "spec/sample_war/public/favicon.ico", "spec/sample_war/public/index.html", "spec/sample_war/public/robots.txt", "spec/spec_helper.rb", "spec/warbler/application_spec.rb", "spec/warbler/bundler_spec.rb", "spec/warbler/config_spec.rb", "spec/warbler/gems_spec.rb", "spec/warbler/jar_spec.rb", "spec/warbler/task_spec.rb", "spec/warbler/traits_spec.rb", "spec/warbler/war_spec.rb", "warble.rb", "web.xml.erb"]
s.homepage = %q{http://caldersphere.rubyforge.org/warbler}
s.rdoc_options = ["--main", "README.txt", "-SHN", "-f", "darkfish"]
s.require_paths = ["lib"]
Please sign in to comment.
Something went wrong with that request. Please try again.