aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/console_sandbox.rb4
-rw-r--r--railties/lib/rails/gem_dependency.rb39
-rw-r--r--railties/lib/rails/mongrel_server/commands.rb2
-rw-r--r--railties/lib/rails/vendor_gem_source_index.rb89
-rw-r--r--railties/lib/rails_generator/commands.rb1
-rw-r--r--railties/lib/rails_generator/generators/components/controller/controller_generator.rb2
-rw-r--r--railties/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb2
-rw-r--r--railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb2
-rw-r--r--railties/lib/rails_generator/generators/components/model/model_generator.rb2
-rw-r--r--railties/lib/rails_generator/generators/components/observer/observer_generator.rb2
-rw-r--r--railties/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb2
-rw-r--r--railties/lib/rails_generator/generators/components/plugin/plugin_generator.rb2
-rw-r--r--railties/lib/rails_generator/generators/components/resource/resource_generator.rb4
-rw-r--r--railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb4
-rw-r--r--railties/lib/tasks/gems.rake10
15 files changed, 128 insertions, 39 deletions
diff --git a/railties/lib/console_sandbox.rb b/railties/lib/console_sandbox.rb
index 5d57679c43..65a3d68619 100644
--- a/railties/lib/console_sandbox.rb
+++ b/railties/lib/console_sandbox.rb
@@ -1,6 +1,6 @@
-ActiveRecord::Base.send :increment_open_transactions
+ActiveRecord::Base.connection.increment_open_transactions
ActiveRecord::Base.connection.begin_db_transaction
at_exit do
ActiveRecord::Base.connection.rollback_db_transaction
- ActiveRecord::Base.send :decrement_open_transactions
+ ActiveRecord::Base.connection.decrement_open_transactions
end
diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb
index 3b2f4846a6..80481859e1 100644
--- a/railties/lib/rails/gem_dependency.rb
+++ b/railties/lib/rails/gem_dependency.rb
@@ -82,6 +82,10 @@ module Rails
File.join(base_directory, specification.full_name)
end
+ def spec_filename(base_directory)
+ File.join(gem_dir(base_directory), '.specification')
+ end
+
def load
return if @loaded || @load_paths_added == false
require(@lib || name) unless @lib == false
@@ -108,6 +112,8 @@ module Rails
@loaded ||= begin
if vendor_rails?
true
+ elsif specification.nil?
+ false
else
# check if the gem is loaded by inspecting $"
# specification.files lists all the files contained in the gem
@@ -144,17 +150,42 @@ module Rails
Gem::GemRunner.new.run(unpack_command)
end
+ # Gem.activate changes the spec - get the original
+ real_spec = Gem::Specification.load(spec.loaded_from)
+ write_spec(directory, real_spec)
+
+ end
+
+ def write_spec(directory, 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
- spec_filename = File.join(gem_dir(directory), '.specification')
- # Gem.activate changes the spec - get the original
- spec = Gem::Specification.load(specification.loaded_from)
- File.open(spec_filename, 'w') do |file|
+ File.open(spec_filename(directory), 'w') do |file|
file.puts spec.to_yaml
end
end
+ def refresh_spec(directory)
+ 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
+ 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)
+ write_spec(directory, real_spec)
+ puts "Reloaded specification for #{name} from installed gems."
+ else
+ # the gem isn't installed locally - write out our current specs
+ write_spec(directory, specification)
+ puts "Gem #{name} not loaded locally - writing out current spec."
+ end
+ end
+
def ==(other)
self.name == other.name && self.requirement == other.requirement
end
diff --git a/railties/lib/rails/mongrel_server/commands.rb b/railties/lib/rails/mongrel_server/commands.rb
index 0a92f418ad..d29b18712f 100644
--- a/railties/lib/rails/mongrel_server/commands.rb
+++ b/railties/lib/rails/mongrel_server/commands.rb
@@ -44,7 +44,7 @@ module Rails
env_location = "#{defaults[:cwd]}/config/environment"
require env_location
- ActionController::AbstractRequest.relative_url_root = defaults[:prefix]
+ ActionController::Base.relative_url_root = defaults[:prefix]
uri prefix, :handler => Rails::MongrelServer::RailsHandler.new
end
end
diff --git a/railties/lib/rails/vendor_gem_source_index.rb b/railties/lib/rails/vendor_gem_source_index.rb
index c8701101e2..dc821693ac 100644
--- a/railties/lib/rails/vendor_gem_source_index.rb
+++ b/railties/lib/rails/vendor_gem_source_index.rb
@@ -13,6 +13,16 @@ module Rails
attr_reader :installed_source_index
attr_reader :vendor_source_index
+ @@silence_spec_warnings = false
+
+ def self.silence_spec_warnings
+ @@silence_spec_warnings
+ end
+
+ def self.silence_spec_warnings=(v)
+ @@silence_spec_warnings = v
+ end
+
def initialize(installed_index, vendor_dir=Rails::GemDependency.unpacked_path)
@installed_source_index = installed_index
@vendor_dir = vendor_dir
@@ -33,38 +43,75 @@ module Rails
# load specifications from vendor/gems
Dir[File.join(Rails::GemDependency.unpacked_path, '*')].each do |d|
+ dir_name = File.basename(d)
+ dir_version = version_for_dir(dir_name)
spec = load_specification(d)
- next unless spec
- # NOTE: this is a bit of a hack - the gem system expects a different structure
- # than we have.
- # It's looking for:
- # repository
- # -> specifications
- # - gem_name.spec <= loaded_from points to this
- # -> gems
- # - gem_name <= gem files here
- # and therefore goes up one directory from loaded_from, then adds gems/gem_name
- # to the path.
- # But we have:
- # vendor
- # -> gems
- # -> gem_name <= gem files here
- # - .specification
- # so we set loaded_from to vendor/gems/.specification (not a real file) to
- # get the correct behavior.
- spec.loaded_from = File.join(Rails::GemDependency.unpacked_path, '.specification')
+ if spec
+ if spec.full_name != dir_name
+ # mismatched directory name and gem spec - produced by 2.1.0-era unpack code
+ if dir_version
+ # fix the spec version - this is not optimal (spec.files may be wrong)
+ # but it's better than breaking apps. Complain to remind users to get correct specs.
+ # use ActiveSupport::Deprecation.warn, as the logger is not set yet
+ $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems has a mismatched specification file."+
+ " Run 'rake gems:refresh_specs' to fix this.") unless @@silence_spec_warnings
+ spec.version = dir_version
+ else
+ $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems is not in a versioned directory"+
+ "(should be #{spec.full_name}).") unless @@silence_spec_warnings
+ # continue, assume everything is OK
+ end
+ end
+ else
+ # no spec - produced by early-2008 unpack code
+ # emulate old behavior, and complain.
+ $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems has no specification file."+
+ " Run 'rake gems:refresh_specs' to fix this.") unless @@silence_spec_warnings
+ if dir_version
+ spec = Gem::Specification.new
+ spec.version = dir_version
+ spec.require_paths = ['lib']
+ ext_path = File.join(d, 'ext')
+ spec.require_paths << 'ext' if File.exist?(ext_path)
+ spec.name = /^(.*)-[^-]+$/.match(dir_name)[1]
+ files = ['lib']
+ # set files to everything in lib/
+ files += Dir[File.join(d, 'lib', '*')].map { |v| v.gsub(/^#{d}\//, '') }
+ files += Dir[File.join(d, 'ext', '*')].map { |v| v.gsub(/^#{d}\//, '') } if ext_path
+ spec.files = files
+ else
+ $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems not in a versioned directory."+
+ " Giving up.") unless @silence_spec_warnings
+ next
+ end
+ end
+ spec.loaded_from = File.join(d, '.specification')
+ # finally, swap out full_gem_path
+ # it would be better to use a Gem::Specification subclass, but the YAML loads an explicit class
+ class << spec
+ def full_gem_path
+ path = File.join installation_path, full_name
+ return path if File.directory? path
+ File.join installation_path, original_name
+ end
+ end
vendor_gems[File.basename(d)] = spec
end
@vendor_source_index = Gem::SourceIndex.new(vendor_gems)
end
+ def version_for_dir(d)
+ matches = /-([^-]+)$/.match(d)
+ Gem::Version.new(matches[1]) if matches
+ end
+
def load_specification(gem_dir)
spec_file = File.join(gem_dir, '.specification')
YAML.load_file(spec_file) if File.exist?(spec_file)
end
- def find_name(gem_name, version_requirement = Gem::Requirement.default)
- search(/^#{gem_name}$/, version_requirement)
+ def find_name(*args)
+ @installed_source_index.find_name(*args) + @vendor_source_index.find_name(*args)
end
def search(*args)
diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb
index 59af7308fe..6b9a636847 100644
--- a/railties/lib/rails_generator/commands.rb
+++ b/railties/lib/rails_generator/commands.rb
@@ -169,6 +169,7 @@ HELP
# Ruby or Rails. In the future, expand to check other namespaces
# such as the rest of the user's app.
def class_collisions(*class_names)
+ path = class_names.shift
class_names.flatten.each do |class_name|
# Convert to string to allow symbol arguments.
class_name = class_name.to_s
diff --git a/railties/lib/rails_generator/generators/components/controller/controller_generator.rb b/railties/lib/rails_generator/generators/components/controller/controller_generator.rb
index c37ff45836..77b2220d57 100644
--- a/railties/lib/rails_generator/generators/components/controller/controller_generator.rb
+++ b/railties/lib/rails_generator/generators/components/controller/controller_generator.rb
@@ -2,7 +2,7 @@ class ControllerGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
# Check for class naming collisions.
- m.class_collisions class_path, "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper"
+ m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper"
# Controller, helper, views, and test directories.
m.directory File.join('app/controllers', class_path)
diff --git a/railties/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb b/railties/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb
index 90fa96938b..44323f28ca 100644
--- a/railties/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb
+++ b/railties/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb
@@ -4,7 +4,7 @@ class IntegrationTestGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
# Check for class naming collisions.
- m.class_collisions class_path, class_name, "#{class_name}Test"
+ m.class_collisions class_name, "#{class_name}Test"
# integration test directory
m.directory File.join('test/integration', class_path)
diff --git a/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb b/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb
index dc1202d7c8..ba6d60cac6 100644
--- a/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb
+++ b/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb
@@ -2,7 +2,7 @@ class MailerGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
# Check for class naming collisions.
- m.class_collisions class_path, class_name, "#{class_name}Test"
+ m.class_collisions class_name, "#{class_name}Test"
# Mailer, view, test, and fixture directories.
m.directory File.join('app/models', class_path)
diff --git a/railties/lib/rails_generator/generators/components/model/model_generator.rb b/railties/lib/rails_generator/generators/components/model/model_generator.rb
index 9be9cad8bf..582a28922f 100644
--- a/railties/lib/rails_generator/generators/components/model/model_generator.rb
+++ b/railties/lib/rails_generator/generators/components/model/model_generator.rb
@@ -4,7 +4,7 @@ class ModelGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
# Check for class naming collisions.
- m.class_collisions class_path, class_name, "#{class_name}Test"
+ m.class_collisions class_name, "#{class_name}Test"
# Model, test, and fixture directories.
m.directory File.join('app/models', class_path)
diff --git a/railties/lib/rails_generator/generators/components/observer/observer_generator.rb b/railties/lib/rails_generator/generators/components/observer/observer_generator.rb
index 18fbd32b75..3c4b330a80 100644
--- a/railties/lib/rails_generator/generators/components/observer/observer_generator.rb
+++ b/railties/lib/rails_generator/generators/components/observer/observer_generator.rb
@@ -2,7 +2,7 @@ class ObserverGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
# Check for class naming collisions.
- m.class_collisions class_path, "#{class_name}Observer", "#{class_name}ObserverTest"
+ m.class_collisions "#{class_name}Observer", "#{class_name}ObserverTest"
# Observer, and test directories.
m.directory File.join('app/models', class_path)
diff --git a/railties/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb b/railties/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb
index fbcc1cf683..83ce8ac674 100644
--- a/railties/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb
+++ b/railties/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb
@@ -4,7 +4,7 @@ class PerformanceTestGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
# Check for class naming collisions.
- m.class_collisions class_path, class_name, "#{class_name}Test"
+ m.class_collisions class_name, "#{class_name}Test"
# performance test directory
m.directory File.join('test/performance', class_path)
diff --git a/railties/lib/rails_generator/generators/components/plugin/plugin_generator.rb b/railties/lib/rails_generator/generators/components/plugin/plugin_generator.rb
index 7a619825a2..615c575e6e 100644
--- a/railties/lib/rails_generator/generators/components/plugin/plugin_generator.rb
+++ b/railties/lib/rails_generator/generators/components/plugin/plugin_generator.rb
@@ -10,7 +10,7 @@ class PluginGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
# Check for class naming collisions.
- m.class_collisions class_path, class_name
+ m.class_collisions class_name
m.directory "#{plugin_path}/lib"
m.directory "#{plugin_path}/tasks"
diff --git a/railties/lib/rails_generator/generators/components/resource/resource_generator.rb b/railties/lib/rails_generator/generators/components/resource/resource_generator.rb
index d5491ece36..ea6dd65bde 100644
--- a/railties/lib/rails_generator/generators/components/resource/resource_generator.rb
+++ b/railties/lib/rails_generator/generators/components/resource/resource_generator.rb
@@ -30,8 +30,8 @@ class ResourceGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
# Check for class naming collisions.
- m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
- m.class_collisions(class_path, "#{class_name}")
+ m.class_collisions("#{controller_class_name}Controller", "#{controller_class_name}Helper")
+ m.class_collisions(class_name)
# Controller, helper, views, and test directories.
m.directory(File.join('app/models', class_path))
diff --git a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb b/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb
index 5fecfe0167..ff0381da2a 100644
--- a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb
+++ b/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb
@@ -36,8 +36,8 @@ class ScaffoldGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
# Check for class naming collisions.
- m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
- m.class_collisions(class_path, "#{class_name}")
+ m.class_collisions("#{controller_class_name}Controller", "#{controller_class_name}Helper")
+ m.class_collisions(class_name)
# Controller, helper, views, test and stylesheets directories.
m.directory(File.join('app/models', class_path))
diff --git a/railties/lib/tasks/gems.rake b/railties/lib/tasks/gems.rake
index 9abdfc56b6..c65dfc7dd4 100644
--- a/railties/lib/tasks/gems.rake
+++ b/railties/lib/tasks/gems.rake
@@ -65,4 +65,14 @@ namespace :gems do
end
end
end
+
+ desc "Regenerate gem specifications in correct format."
+ task :refresh_specs => :base do
+ require 'rubygems'
+ require 'rubygems/gem_runner'
+ Rails.configuration.gems.each do |gem|
+ next unless gem.frozen? && (ENV['GEM'].blank? || ENV['GEM'] == gem.name)
+ gem.refresh_spec(Rails::GemDependency.unpacked_path) if gem.loaded?
+ end
+ end
end \ No newline at end of file