Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
require 'rails/vendor_gem_source_index'
|
|
|
|
|
|
|
|
module Gem
|
|
|
|
def self.source_index=(index)
|
|
|
|
@@source_index = index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-03-29 22:17:28 -04:00
|
|
|
module Rails
|
2009-03-13 06:20:23 -04:00
|
|
|
class GemDependency < Gem::Dependency
|
|
|
|
attr_accessor :lib, :source, :dep
|
2008-03-29 22:17:28 -04:00
|
|
|
|
|
|
|
def self.unpacked_path
|
|
|
|
@unpacked_path ||= File.join(RAILS_ROOT, 'vendor', 'gems')
|
|
|
|
end
|
|
|
|
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
@@framework_gems = {}
|
|
|
|
|
|
|
|
def self.add_frozen_gem_path
|
|
|
|
@@paths_loaded ||= begin
|
2008-10-26 02:25:52 -04:00
|
|
|
source_index = Rails::VendorGemSourceIndex.new(Gem.source_index)
|
|
|
|
Gem.clear_paths
|
|
|
|
Gem.source_index = source_index
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
# loaded before us - we can't change them, so mark them
|
|
|
|
Gem.loaded_specs.each do |name, spec|
|
|
|
|
@@framework_gems[name] = spec
|
|
|
|
end
|
2008-10-26 02:25:52 -04:00
|
|
|
true
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-04-29 01:22:54 -04:00
|
|
|
def self.from_directory_name(directory_name)
|
|
|
|
directory_name_parts = File.basename(directory_name).split('-')
|
|
|
|
name = directory_name_parts[0..-2].join('-')
|
|
|
|
version = directory_name_parts.last
|
|
|
|
self.new(name, :version => version)
|
|
|
|
rescue ArgumentError => e
|
|
|
|
raise "Unable to determine gem name and version from '#{directory_name}'"
|
|
|
|
end
|
|
|
|
|
2008-03-29 22:17:28 -04:00
|
|
|
def initialize(name, options = {})
|
2008-04-09 12:24:32 -04:00
|
|
|
require 'rubygems' unless Object.const_defined?(:Gem)
|
2008-04-11 18:25:11 -04:00
|
|
|
|
|
|
|
if options[:requirement]
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
req = options[:requirement]
|
2008-04-11 18:25:11 -04:00
|
|
|
elsif options[:version]
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
req = Gem::Requirement.create(options[:version])
|
|
|
|
else
|
|
|
|
req = Gem::Requirement.default
|
2008-03-29 22:17:28 -04:00
|
|
|
end
|
2008-04-11 18:25:11 -04:00
|
|
|
|
2008-03-29 22:17:28 -04:00
|
|
|
@lib = options[:lib]
|
|
|
|
@source = options[:source]
|
2008-04-08 00:21:32 -04:00
|
|
|
@loaded = @frozen = @load_paths_added = false
|
2009-03-13 06:20:23 -04:00
|
|
|
|
|
|
|
super(name, req)
|
2008-06-08 14:04:04 -04:00
|
|
|
end
|
|
|
|
|
2008-03-29 22:17:28 -04:00
|
|
|
def add_load_paths
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
self.class.add_frozen_gem_path
|
2008-03-29 22:17:28 -04:00
|
|
|
return if @loaded || @load_paths_added
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
if framework_gem?
|
|
|
|
@load_paths_added = @loaded = @frozen = true
|
|
|
|
return
|
2008-03-29 22:17:28 -04:00
|
|
|
end
|
2009-03-13 06:20:23 -04:00
|
|
|
gem self
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
@spec = Gem.loaded_specs[name]
|
|
|
|
@frozen = @spec.loaded_from.include?(self.class.unpacked_path) if @spec
|
2008-03-29 22:17:28 -04:00
|
|
|
@load_paths_added = true
|
|
|
|
rescue Gem::LoadError
|
|
|
|
end
|
2008-06-02 10:54:36 -04:00
|
|
|
|
2009-03-13 06:20:23 -04:00
|
|
|
def dependencies
|
|
|
|
return [] if framework_gem?
|
|
|
|
return [] unless installed?
|
|
|
|
specification.dependencies.reject do |dependency|
|
|
|
|
dependency.type == :development
|
|
|
|
end.map do |dependency|
|
2008-04-11 18:25:11 -04:00
|
|
|
GemDependency.new(dependency.name, :requirement => dependency.version_requirements)
|
|
|
|
end
|
2009-03-13 06:20:23 -04:00
|
|
|
end
|
2009-03-01 06:53:58 -05:00
|
|
|
|
2009-03-13 06:20:23 -04:00
|
|
|
def specification
|
|
|
|
# code repeated from Gem.activate. Find a matching spec, or the currently loaded version.
|
|
|
|
# error out if loaded version and requested version are incompatible.
|
|
|
|
@spec ||= begin
|
|
|
|
matches = Gem.source_index.search(self)
|
|
|
|
matches << @@framework_gems[name] if framework_gem?
|
|
|
|
if Gem.loaded_specs[name] then
|
|
|
|
# This gem is already loaded. If the currently loaded gem is not in the
|
|
|
|
# list of candidate gems, then we have a version conflict.
|
|
|
|
existing_spec = Gem.loaded_specs[name]
|
|
|
|
unless matches.any? { |spec| spec.version == existing_spec.version } then
|
|
|
|
raise Gem::Exception,
|
|
|
|
"can't activate #{@dep}, already activated #{existing_spec.full_name}"
|
|
|
|
end
|
|
|
|
# we're stuck with it, so change to match
|
|
|
|
version_requirements = Gem::Requirement.create("=#{existing_spec.version}")
|
|
|
|
existing_spec
|
|
|
|
else
|
|
|
|
# new load
|
|
|
|
matches.last
|
|
|
|
end
|
|
|
|
end
|
2008-04-11 18:25:11 -04:00
|
|
|
end
|
2008-06-02 10:54:36 -04:00
|
|
|
|
2009-03-13 06:20:23 -04:00
|
|
|
def requirement
|
|
|
|
r = version_requirements
|
|
|
|
(r == Gem::Requirement.default) ? nil : r
|
2008-04-02 13:48:30 -04:00
|
|
|
end
|
2008-03-29 22:17:28 -04:00
|
|
|
|
2009-03-13 06:20:23 -04:00
|
|
|
def built?
|
2009-04-29 01:22:54 -04:00
|
|
|
return false unless frozen?
|
|
|
|
specification.extensions.each do |ext|
|
|
|
|
makefile = File.join(unpacked_gem_directory, File.dirname(ext), 'Makefile')
|
|
|
|
return false unless File.exists?(makefile)
|
|
|
|
end
|
|
|
|
true
|
2008-10-11 13:54:21 -04:00
|
|
|
end
|
|
|
|
|
2009-03-13 06:20:23 -04:00
|
|
|
def framework_gem?
|
|
|
|
@@framework_gems.has_key?(name)
|
2008-03-29 22:17:28 -04:00
|
|
|
end
|
|
|
|
|
2009-03-13 06:20:23 -04:00
|
|
|
def frozen?
|
|
|
|
@frozen ||= vendor_rails? || vendor_gem?
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
end
|
|
|
|
|
2009-03-13 06:20:23 -04:00
|
|
|
def installed?
|
|
|
|
Gem.loaded_specs.keys.include?(name)
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
end
|
|
|
|
|
2009-03-13 06:20:23 -04:00
|
|
|
def load_paths_added?
|
|
|
|
# always try to add load paths - even if a gem is loaded, it may not
|
|
|
|
# be a compatible version (ie random_gem 0.4 is loaded and a later spec
|
|
|
|
# needs >= 0.5 - gem 'random_gem' will catch this and error out)
|
|
|
|
@load_paths_added
|
2008-04-08 00:21:32 -04:00
|
|
|
end
|
|
|
|
|
2008-03-29 22:17:28 -04:00
|
|
|
def loaded?
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
@loaded ||= begin
|
|
|
|
if vendor_rails?
|
|
|
|
true
|
2008-10-07 23:10:45 -04:00
|
|
|
elsif specification.nil?
|
|
|
|
false
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
else
|
|
|
|
# check if the gem is loaded by inspecting $"
|
|
|
|
# specification.files lists all the files contained in the gem
|
|
|
|
gem_files = specification.files
|
|
|
|
# select only the files contained in require_paths - typically in bin and lib
|
|
|
|
require_paths_regexp = Regexp.new("^(#{specification.require_paths*'|'})/")
|
|
|
|
gem_lib_files = gem_files.select { |f| require_paths_regexp.match(f) }
|
|
|
|
# chop the leading directory off - a typical file might be in
|
|
|
|
# lib/gem_name/file_name.rb, but it will be 'require'd as gem_name/file_name.rb
|
|
|
|
gem_lib_files.map! { |f| f.split('/', 2)[1] }
|
|
|
|
# if any of the files from the above list appear in $", the gem is assumed to
|
|
|
|
# have been loaded
|
|
|
|
!(gem_lib_files & $").empty?
|
|
|
|
end
|
|
|
|
end
|
2008-03-29 22:17:28 -04:00
|
|
|
end
|
|
|
|
|
2009-03-13 06:20:23 -04:00
|
|
|
def vendor_rails?
|
|
|
|
Gem.loaded_specs.has_key?(name) && Gem.loaded_specs[name].loaded_from.empty?
|
2008-03-29 22:17:28 -04:00
|
|
|
end
|
|
|
|
|
2009-03-13 06:20:23 -04:00
|
|
|
def vendor_gem?
|
|
|
|
specification && File.exists?(unpacked_gem_directory)
|
2008-03-29 22:17:28 -04:00
|
|
|
end
|
2008-06-02 10:54:36 -04:00
|
|
|
|
2009-04-29 01:22:54 -04:00
|
|
|
def build(options={})
|
2009-03-13 06:20:23 -04:00
|
|
|
require 'rails/gem_builder'
|
2009-04-29 01:22:54 -04:00
|
|
|
if options[:force] || !built?
|
2009-03-13 06:20:23 -04:00
|
|
|
return unless File.exists?(unpacked_specification_filename)
|
|
|
|
spec = YAML::load_file(unpacked_specification_filename)
|
|
|
|
Rails::GemBuilder.new(spec, unpacked_gem_directory).build_extensions
|
|
|
|
puts "Built gem: '#{unpacked_gem_directory}'"
|
2008-03-29 22:17:28 -04:00
|
|
|
end
|
2009-03-13 06:20:23 -04:00
|
|
|
dependencies.each { |dep| dep.build }
|
2008-10-11 13:54:21 -04:00
|
|
|
end
|
|
|
|
|
2009-03-13 06:20:23 -04:00
|
|
|
def install
|
|
|
|
unless installed?
|
|
|
|
cmd = "#{gem_command} #{install_command.join(' ')}"
|
|
|
|
puts cmd
|
|
|
|
puts %x(#{cmd})
|
2008-04-02 13:48:30 -04:00
|
|
|
end
|
2008-03-29 22:17:28 -04:00
|
|
|
end
|
|
|
|
|
2009-03-13 06:20:23 -04:00
|
|
|
def load
|
|
|
|
return if @loaded || @load_paths_added == false
|
|
|
|
require(@lib || name) unless @lib == false
|
|
|
|
@loaded = true
|
|
|
|
rescue LoadError
|
|
|
|
puts $!.to_s
|
|
|
|
$!.backtrace.each { |b| puts b }
|
|
|
|
end
|
|
|
|
|
|
|
|
def refresh
|
|
|
|
Rails::VendorGemSourceIndex.silence_spec_warnings = true
|
2008-10-11 13:54:21 -04:00
|
|
|
real_gems = Gem.source_index.installed_source_index
|
|
|
|
exact_dep = Gem::Dependency.new(name, "= #{specification.version}")
|
|
|
|
matches = real_gems.search(exact_dep)
|
|
|
|
installed_spec = matches.first
|
2009-03-13 06:20:23 -04:00
|
|
|
if frozen?
|
2008-10-26 02:25:52 -04:00
|
|
|
if installed_spec
|
|
|
|
# we have a real copy
|
|
|
|
# get a fresh spec - matches should only have one element
|
|
|
|
# note that there is no reliable method to check that the loaded
|
|
|
|
# spec is the same as the copy from real_gems - Gem.activate changes
|
|
|
|
# some of the fields
|
|
|
|
real_spec = Gem::Specification.load(matches.first.loaded_from)
|
2009-03-13 06:20:23 -04:00
|
|
|
write_specification(real_spec)
|
2008-10-26 02:25:52 -04:00
|
|
|
puts "Reloaded specification for #{name} from installed gems."
|
|
|
|
else
|
|
|
|
# the gem isn't installed locally - write out our current specs
|
2009-03-13 06:20:23 -04:00
|
|
|
write_specification(specification)
|
2008-10-26 02:25:52 -04:00
|
|
|
puts "Gem #{name} not loaded locally - writing out current spec."
|
|
|
|
end
|
2008-10-11 13:54:21 -04:00
|
|
|
else
|
2008-10-26 02:25:52 -04:00
|
|
|
if framework_gem?
|
|
|
|
puts "Gem directory for #{name} not found - check if it's loading before rails."
|
|
|
|
else
|
|
|
|
puts "Something bad is going on - gem directory not found for #{name}."
|
|
|
|
end
|
2008-10-11 13:54:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-03-13 06:20:23 -04:00
|
|
|
def unpack(options={})
|
|
|
|
unless frozen? || framework_gem?
|
|
|
|
FileUtils.mkdir_p unpack_base
|
|
|
|
Dir.chdir unpack_base do
|
|
|
|
Gem::GemRunner.new.run(unpack_command)
|
|
|
|
end
|
|
|
|
# Gem.activate changes the spec - get the original
|
|
|
|
real_spec = Gem::Specification.load(specification.loaded_from)
|
|
|
|
write_specification(real_spec)
|
|
|
|
end
|
|
|
|
dependencies.each { |dep| dep.unpack } if options[:recursive]
|
2008-04-11 18:25:11 -04:00
|
|
|
end
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
|
2009-03-13 06:20:23 -04:00
|
|
|
def write_specification(spec)
|
|
|
|
# copy the gem's specification into GEMDIR/.specification so that
|
|
|
|
# we can access information about the gem on deployment systems
|
|
|
|
# without having the gem installed
|
|
|
|
File.open(unpacked_specification_filename, 'w') do |file|
|
|
|
|
file.puts spec.to_yaml
|
|
|
|
end
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
end
|
2008-04-11 18:25:11 -04:00
|
|
|
|
2009-03-13 06:20:23 -04:00
|
|
|
def ==(other)
|
|
|
|
self.name == other.name && self.requirement == other.requirement
|
2008-04-11 18:25:11 -04:00
|
|
|
end
|
2009-03-13 06:20:23 -04:00
|
|
|
alias_method :"eql?", :"=="
|
2008-06-02 10:54:36 -04:00
|
|
|
|
2008-06-06 23:41:22 -04:00
|
|
|
private
|
2009-03-13 06:20:23 -04:00
|
|
|
|
2008-06-06 23:41:22 -04:00
|
|
|
def gem_command
|
2009-03-11 20:53:21 -04:00
|
|
|
case RUBY_PLATFORM
|
|
|
|
when /win32/
|
|
|
|
'gem.bat'
|
|
|
|
when /java/
|
|
|
|
'jruby -S gem'
|
|
|
|
else
|
|
|
|
'gem'
|
|
|
|
end
|
2008-06-06 23:41:22 -04:00
|
|
|
end
|
2008-04-11 18:25:11 -04:00
|
|
|
|
2008-06-06 23:41:22 -04:00
|
|
|
def install_command
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
cmd = %w(install) << name
|
|
|
|
cmd << "--version" << %("#{requirement.to_s}") if requirement
|
2008-06-06 23:41:22 -04:00
|
|
|
cmd << "--source" << @source if @source
|
|
|
|
cmd
|
|
|
|
end
|
2008-06-02 10:54:36 -04:00
|
|
|
|
2008-06-06 23:41:22 -04:00
|
|
|
def unpack_command
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
cmd = %w(unpack) << name
|
|
|
|
cmd << "--version" << "= "+specification.version.to_s if requirement
|
2008-06-06 23:41:22 -04:00
|
|
|
cmd
|
|
|
|
end
|
2009-03-13 06:20:23 -04:00
|
|
|
|
|
|
|
def unpack_base
|
|
|
|
Rails::GemDependency.unpacked_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def unpacked_gem_directory
|
|
|
|
File.join(unpack_base, specification.full_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def unpacked_specification_filename
|
|
|
|
File.join(unpacked_gem_directory, '.specification')
|
|
|
|
end
|
|
|
|
|
2008-03-29 22:17:28 -04:00
|
|
|
end
|
2008-06-02 10:54:36 -04:00
|
|
|
end
|