Skip to content
Browse files

Added jbarnette@gmail.com's developer dependencies

git-svn-id: svn+ssh://rubyforge.org/var/svn/rubygems/trunk@1711 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information...
1 parent b861bd7 commit efd062d90585a95f59d311ca9d676a94775be120 @zenspider zenspider committed
View
2 lib/rubygems.rb
@@ -152,7 +152,7 @@ def self.activate(gem, *version_requirements)
@loaded_specs[spec.name] = spec
# Load dependent gems first
- spec.dependencies.each do |dep_gem|
+ spec.runtime_dependencies.each do |dep_gem|
activate dep_gem
end
View
3 lib/rubygems/commands/install_command.rb
@@ -62,7 +62,8 @@ def execute
:install_dir => options[:install_dir],
:security_policy => options[:security_policy],
:wrappers => options[:wrappers],
- :bin_dir => options[:bin_dir]
+ :bin_dir => options[:bin_dir],
+ :development => options[:development],
}
exit_code = 0
View
2 lib/rubygems/commands/lock_command.rb
@@ -80,7 +80,7 @@ def execute
say "gem '#{spec.name}', '= #{spec.version}'" unless locked[spec.name]
locked[spec.name] = true
- spec.dependencies.each do |dep|
+ spec.runtime_dependencies.each do |dep|
next if locked[dep.name]
candidates = Gem.source_index.search dep.name, dep.requirement_list
View
2 lib/rubygems/custom_require.rb
@@ -26,7 +26,7 @@ module Kernel
def require(path) # :nodoc:
gem_original_require path
rescue LoadError => load_error
- if load_error.message =~ /\A[Nn]o such file to load -- #{Regexp.escape path}\z/ and
+ if load_error.message =~ /#{Regexp.escape path}\z/ and
spec = Gem.searcher.find(path) then
Gem.activate(spec.name, "= #{spec.version}")
gem_original_require path
View
20 lib/rubygems/dependency.rb
@@ -9,9 +9,15 @@
##
# The Dependency class holds a Gem name and a Gem::Requirement
class Gem::Dependency
+ TYPES = [
+ :runtime,
+ :development
+ ]
attr_accessor :name
+ attr_reader :type
+
attr_writer :version_requirements
def <=>(other)
@@ -24,8 +30,15 @@ def <=>(other)
# name:: [String] name of the Gem
# version_requirements:: [String Array] version requirement (e.g. ["> 1.2"])
#
- def initialize(name, version_requirements)
+ def initialize(name, version_requirements, type=:runtime)
@name = name
+
+ unless TYPES.include? type
+ raise ArgumentError, "Valid types are #{TYPES.inspect}, not #{@type.inspect}"
+ end
+
+ @type = type
+
@version_requirements = Gem::Requirement.create version_requirements
@version_requirement = nil # Avoid warnings.
end
@@ -48,17 +61,18 @@ def normalize
end
def to_s # :nodoc:
- "#{name} (#{version_requirements})"
+ "#{name} (#{version_requirements}#{", #{type}" if type != :runtime})"
end
def ==(other) # :nodoc:
self.class === other &&
self.name == other.name &&
+ self.type == other.type &&
self.version_requirements == other.version_requirements
end
def hash
- name.hash + version_requirements.hash
+ name.hash + type.hash + version_requirements.hash
end
end
View
9 lib/rubygems/dependency_installer.rb
@@ -44,6 +44,7 @@ def initialize(options = {})
options = DEFAULT_OPTIONS.merge options
@bin_dir = options[:bin_dir]
+ @development = options[:development]
@domain = options[:domain]
@env_shebang = options[:env_shebang]
@force = options[:force]
@@ -120,7 +121,10 @@ def gather_dependencies
next if spec.nil? or seen[spec.name]
seen[spec.name] = true
- spec.dependencies.each do |dep|
+ deps = spec.runtime_dependencies
+ deps |= spec.development_dependencies if @development
+
+ deps.each do |dep|
results = find_gems_with_sources(dep).reverse # local gems first
results.each do |dep_spec, source_uri|
@@ -222,7 +226,8 @@ def install dep_or_name, version = Gem::Requirement.default
:install_dir => @install_dir,
:security_policy => @security_policy,
:wrappers => @wrappers,
- :bin_dir => @bin_dir
+ :bin_dir => @bin_dir,
+ :development => @development
spec = inst.install
View
2 lib/rubygems/dependency_list.rb
@@ -69,7 +69,7 @@ def find_name(full_name)
# Are all the dependencies in the list satisfied?
def ok?
@specs.all? do |spec|
- spec.dependencies.all? do |dep|
+ spec.runtime_dependencies.all? do |dep|
@specs.find { |s| s.satisfies_requirement? dep }
end
end
View
6 lib/rubygems/install_update_options.rb
@@ -89,6 +89,12 @@ def add_install_update_options
'foo_exec18') do |value, options|
options[:format_executable] = value
end
+
+ add_option(:"Install/Update", "--development",
+ "Install any additional development",
+ "dependencies") do |value, options|
+ options[:development] = true
+ end
end
# Default options for the gem install command.
View
6 lib/rubygems/installer.rb
@@ -76,6 +76,7 @@ def initialize(gem, options={})
@security_policy = options[:security_policy]
@wrappers = options[:wrappers]
@bin_dir = options[:bin_dir]
+ @development = options[:development]
begin
@format = Gem::Format.from_file_by_path @gem, @security_policy
@@ -119,7 +120,10 @@ def install
end
unless @ignore_dependencies then
- @spec.dependencies.each do |dep_gem|
+ deps = @spec.runtime_dependencies
+ deps |= @spec.development_dependencies if @development
+
+ deps.each do |dep_gem|
ensure_dependency @spec, dep_gem
end
end
View
1 lib/rubygems/server.rb
@@ -421,6 +421,7 @@ def run
total_file_count += spec.files.size
deps = spec.dependencies.collect { |dep|
{ "name" => dep.name,
+ "type" => dep.type,
"version" => dep.version_requirements.to_s, }
}
deps = deps.sort_by { |dep| [dep["name"].downcase, dep["version"]] }
View
58 lib/rubygems/specification.rb
@@ -335,6 +335,14 @@ def self._load(str)
read_only :dependencies
+ def runtime_dependencies
+ dependencies.select { |d| d.type == :runtime }
+ end
+
+ def development_dependencies
+ dependencies.select { |d| d.type == :development }
+ end
+
# ALIASED gemspec attributes -------------------------------------
attribute_alias_singular :executable, :executables
@@ -629,27 +637,31 @@ def method_missing(sym, *a, &b) # :nodoc:
end
end
- # Adds a dependency to this Gem. For example,
+ # Adds a development dependency to this Gem. For example,
#
- # spec.add_dependency('jabber4r', '> 0.1', '<= 0.5')
+ # spec.add_development_dependency('jabber4r', '> 0.1', '<= 0.5')
+ #
+ # Development dependencies aren't installed by default, and
+ # aren't activated when a gem is required.
#
# gem:: [String or Gem::Dependency] The Gem name/dependency.
# requirements:: [default=">= 0"] The version requirements.
+ def add_development_dependency(gem, *requirements)
+ add_dependency_with_type(gem, :development, *requirements)
+ end
+
+ # Adds a runtime dependency to this Gem. For example,
#
- def add_dependency(gem, *requirements)
- requirements = if requirements.empty? then
- Gem::Requirement.default
- else
- requirements.flatten
- end
+ # spec.add_runtime_dependency('jabber4r', '> 0.1', '<= 0.5')
+ #
+ # gem:: [String or Gem::Dependency] The Gem name/dependency.
+ # requirements:: [default=">= 0"] The version requirements.
+ def add_runtime_dependency(gem, *requirements)
+ add_dependency_with_type(gem, :runtime, *requirements)
+ end
- unless gem.respond_to?(:name) && gem.respond_to?(:version_requirements)
- gem = Dependency.new(gem, requirements)
- end
+ alias add_dependency add_runtime_dependency
- dependencies << gem
- end
-
# Returns the full name (name-version) of this Gem. Platform information
# is included (name-version-platform) if it is specified (and not the
# default Ruby platform).
@@ -820,7 +832,7 @@ def to_ruby
dependencies.each do |dep|
version_reqs_param = dep.requirements_list.inspect
- result << " s.add_dependency(%q<#{dep.name}>, #{version_reqs_param})"
+ result << " s.add_#{dep.type}_dependency(%q<#{dep.name}>, #{version_reqs_param})"
end
result << "end"
@@ -940,6 +952,22 @@ def to_s
private
+ def add_dependency_with_type(dependency, type, *requirements)
+ requirements = if requirements.empty? then
+ Gem::Requirement.default
+ else
+ requirements.flatten
+ end
+
+ unless dependency.respond_to?(:name) &&
+ dependency.respond_to?(:version_requirements)
+
+ dependency = Dependency.new(dependency, requirements, type)
+ end
+
+ dependencies << dependency
+ end
+
def find_all_satisfiers(dep)
Gem.source_index.each do |name,gem|
if(gem.satisfies_requirement?(dep)) then
View
28 test/test_gem_dependency.rb
@@ -60,6 +60,21 @@ def test_initialize_version
assert_equal Gem::Requirement.new('= 2'), dep.version_requirements
end
+ def test_initialize_with_type
+ dep = Gem::Dependency.new("pkg", [], :development)
+ assert_equal(:development, dep.type)
+ end
+
+ def test_type_is_runtime_by_default
+ assert_equal(:runtime, Gem::Dependency.new("pkg", []).type)
+ end
+
+ def test_type_is_restricted
+ assert_raise(ArgumentError) do
+ Gem::Dependency.new("pkg", [:sometimes])
+ end
+ end
+
def test_equals2
assert_equal @pkg1_0, @pkg1_0.dup
assert_equal @pkg1_0.dup, @pkg1_0
@@ -74,6 +89,13 @@ def test_equals2
assert_not_equal Object.new, @pkg1_0
end
+ def test_equals2_type
+ runtime = Gem::Dependency.new("pkg", [])
+ development = Gem::Dependency.new("pkg", [], :development)
+
+ assert_not_equal(runtime, development)
+ end
+
def test_hash
assert_equal @pkg1_0.hash, @pkg1_0.dup.hash
assert_equal @pkg1_0.dup.hash, @pkg1_0.hash
@@ -85,5 +107,11 @@ def test_hash
assert_not_equal @oth1_0.hash, @pkg1_0.hash, "names different"
end
+ def test_hash_type
+ runtime = Gem::Dependency.new("pkg", [])
+ development = Gem::Dependency.new("pkg", [], :development)
+
+ assert_not_equal(runtime.hash, development.hash)
+ end
end
View
20 test/test_gem_dependency_installer.rb
@@ -15,8 +15,12 @@ def setup
fp.puts "#!/usr/bin/ruby"
end
@a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end
+ @aa1, @aa1_gem = util_gem 'aa', '1'
- @b1, @b1_gem = util_gem 'b', '1' do |s| s.add_dependency 'a' end
+ @b1, @b1_gem = util_gem 'b', '1' do |s|
+ s.add_dependency 'a'
+ s.add_development_dependency 'aa'
+ end
@d1, @d1_gem = util_gem 'd', '1'
@d2, @d2_gem = util_gem 'd', '2'
@@ -92,6 +96,20 @@ def test_install_dependency
assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
end
+ def test_install_with_development_dependency
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv @aa1_gem, @tempdir
+ FileUtils.mv @b1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new(:development => true)
+ inst.install 'b'
+ end
+
+ assert_equal %w[a-1 aa-1 b-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
def test_install_dependency_existing
Gem::Installer.new(@a1_gem).install
FileUtils.mv @a1_gem, @tempdir
View
29 test/test_gem_specification.rb
@@ -213,6 +213,15 @@ def test__dump
assert_equal 'old_platform', same_spec.original_platform
end
+ def test_add_dependency_with_explicit_type
+ gem = quick_gem "awesome", "1.0" do |awesome|
+ awesome.add_development_dependency "monkey"
+ end
+
+ monkey = gem.dependencies.detect { |d| d.name == "monkey" }
+ assert_equal(:development, monkey.type)
+ end
+
def test_author
assert_equal 'A User', @a1.author
end
@@ -282,6 +291,20 @@ def test_dependencies
assert_equal [rake, jabber, pqa], @a1.dependencies
end
+ def test_dependencies_scoped_by_type
+ gem = quick_gem "awesome", "1.0" do |awesome|
+ awesome.add_runtime_dependency "bonobo", []
+ awesome.add_development_dependency "monkey", []
+ end
+
+ bonobo = Gem::Dependency.new("bonobo", [])
+ monkey = Gem::Dependency.new("monkey", [], :development)
+
+ assert_equal([bonobo, monkey], gem.dependencies)
+ assert_equal([bonobo], gem.runtime_dependencies)
+ assert_equal([monkey], gem.development_dependencies)
+ end
+
def test_description
assert_equal 'This is a test description', @a1.description
end
@@ -633,9 +656,9 @@ def test_to_ruby_fancy
s.summary = %q{this is a summary}
s.test_files = [\"test/suite.rb\"]
- s.add_dependency(%q<rake>, [\"> 0.4\"])
- s.add_dependency(%q<jabber4r>, [\"> 0.0.0\"])
- s.add_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
+ s.add_runtime_dependency(%q<rake>, [\"> 0.4\"])
+ s.add_runtime_dependency(%q<jabber4r>, [\"> 0.0.0\"])
+ s.add_runtime_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
end
"

0 comments on commit efd062d

Please sign in to comment.
Something went wrong with that request. Please try again.