2007-11-10 02:48:56 -05:00
|
|
|
#--
|
|
|
|
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
|
|
|
# All rights reserved.
|
|
|
|
# See LICENSE.txt for permissions.
|
|
|
|
#++
|
|
|
|
|
|
|
|
require 'rubygems/version'
|
2008-06-17 18:04:18 -04:00
|
|
|
require 'rubygems/requirement'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/platform'
|
|
|
|
|
|
|
|
# :stopdoc:
|
2008-06-17 18:04:18 -04:00
|
|
|
class Date; end # for ruby_code if date.rb wasn't required
|
2007-11-10 02:48:56 -05:00
|
|
|
# :startdoc:
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# The Specification class contains the metadata for a Gem. Typically
|
|
|
|
# defined in a .gemspec file or a Rakefile, and looks like this:
|
|
|
|
#
|
|
|
|
# spec = Gem::Specification.new do |s|
|
2010-02-21 21:52:35 -05:00
|
|
|
# s.name = 'example'
|
2009-06-09 17:38:59 -04:00
|
|
|
# s.version = '1.0'
|
|
|
|
# s.summary = 'Example gem specification'
|
|
|
|
# ...
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# For a great way to package gems, use Hoe.
|
|
|
|
|
|
|
|
class Gem::Specification
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
2009-06-09 17:38:59 -04:00
|
|
|
# Allows deinstallation of gems with legacy platforms.
|
|
|
|
|
|
|
|
attr_accessor :original_platform # :nodoc:
|
|
|
|
|
|
|
|
##
|
|
|
|
# The the version number of a specification that does not specify one
|
|
|
|
# (i.e. RubyGems 0.7 or earlier).
|
|
|
|
|
|
|
|
NONEXISTENT_SPECIFICATION_VERSION = -1
|
|
|
|
|
|
|
|
##
|
|
|
|
# The specification version applied to any new Specification instances
|
|
|
|
# created. This should be bumped whenever something in the spec format
|
|
|
|
# changes.
|
|
|
|
#--
|
|
|
|
# When updating this number, be sure to also update #to_ruby.
|
2007-11-10 02:48:56 -05:00
|
|
|
#
|
2009-06-09 17:38:59 -04:00
|
|
|
# NOTE RubyGems < 1.2 cannot load specification versions > 2.
|
|
|
|
|
|
|
|
CURRENT_SPECIFICATION_VERSION = 3
|
|
|
|
|
|
|
|
##
|
|
|
|
# An informal list of changes to the specification. The highest-valued
|
|
|
|
# key should be equal to the CURRENT_SPECIFICATION_VERSION.
|
|
|
|
|
|
|
|
SPECIFICATION_VERSION_HISTORY = {
|
|
|
|
-1 => ['(RubyGems versions up to and including 0.7 did not have versioned specifications)'],
|
|
|
|
1 => [
|
|
|
|
'Deprecated "test_suite_file" in favor of the new, but equivalent, "test_files"',
|
|
|
|
'"test_file=x" is a shortcut for "test_files=[x]"'
|
|
|
|
],
|
|
|
|
2 => [
|
|
|
|
'Added "required_rubygems_version"',
|
|
|
|
'Now forward-compatible with future versions',
|
|
|
|
],
|
|
|
|
3 => [
|
|
|
|
'Added Fixnum validation to the specification_version'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
# :stopdoc:
|
|
|
|
MARSHAL_FIELDS = { -1 => 16, 1 => 16, 2 => 16, 3 => 17 }
|
|
|
|
|
|
|
|
now = Time.at(Time.now.to_i)
|
|
|
|
TODAY = now - ((now.to_i + now.gmt_offset) % 86400)
|
|
|
|
# :startdoc:
|
|
|
|
|
|
|
|
##
|
|
|
|
# Optional block used to gather newly defined instances.
|
|
|
|
|
|
|
|
@@gather = nil
|
|
|
|
|
|
|
|
##
|
|
|
|
# List of attribute names: [:name, :version, ...]
|
|
|
|
|
|
|
|
@@required_attributes = []
|
|
|
|
|
|
|
|
##
|
|
|
|
# List of _all_ attributes and default values:
|
2007-11-10 02:48:56 -05:00
|
|
|
#
|
2009-06-09 17:38:59 -04:00
|
|
|
# [[:name, nil],
|
|
|
|
# [:bindir, 'bin'],
|
|
|
|
# ...]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@@attributes = []
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@@nil_attributes = []
|
|
|
|
@@non_nil_attributes = [:@original_platform]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# List of array attributes
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@@array_attributes = []
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Map of attribute names to default values.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@@default_value = {}
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Names of all specification attributes
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def self.attribute_names
|
|
|
|
@@attributes.map { |name, default| name }
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Default values for specification attributes
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def self.attribute_defaults
|
|
|
|
@@attributes.dup
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# The default value for specification attribute +name+
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def self.default_value(name)
|
|
|
|
@@default_value[name]
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Required specification attributes
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def self.required_attributes
|
|
|
|
@@required_attributes.dup
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Is +name+ a required attribute?
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def self.required_attribute?(name)
|
|
|
|
@@required_attributes.include? name.to_sym
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Specification attributes that are arrays (appendable and so-forth)
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def self.array_attributes
|
|
|
|
@@array_attributes.dup
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Specifies the +name+ and +default+ for a specification attribute, and
|
|
|
|
# creates a reader and writer method like Module#attr_accessor.
|
|
|
|
#
|
|
|
|
# The reader method returns the default if the value hasn't been set.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def self.attribute(name, default=nil)
|
|
|
|
ivar_name = "@#{name}".intern
|
|
|
|
if default.nil? then
|
|
|
|
@@nil_attributes << ivar_name
|
|
|
|
else
|
|
|
|
@@non_nil_attributes << [ivar_name, default]
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@@attributes << [name, default]
|
|
|
|
@@default_value[name] = default
|
|
|
|
attr_accessor(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Same as :attribute, but ensures that values assigned to the attribute
|
|
|
|
# are array values by applying :to_a to the value.
|
|
|
|
|
|
|
|
def self.array_attribute(name)
|
|
|
|
@@non_nil_attributes << ["@#{name}".intern, []]
|
|
|
|
|
|
|
|
@@array_attributes << name
|
|
|
|
@@attributes << [name, []]
|
|
|
|
@@default_value[name] = []
|
|
|
|
code = %{
|
|
|
|
def #{name}
|
|
|
|
@#{name} ||= []
|
|
|
|
end
|
|
|
|
def #{name}=(value)
|
|
|
|
@#{name} = Array(value)
|
|
|
|
end
|
|
|
|
}
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
module_eval code, __FILE__, __LINE__ - 9
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Same as attribute above, but also records this attribute as mandatory.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def self.required_attribute(*args)
|
|
|
|
@@required_attributes << args.first
|
|
|
|
attribute(*args)
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Sometimes we don't want the world to use a setter method for a
|
|
|
|
# particular attribute.
|
|
|
|
#
|
|
|
|
# +read_only+ makes it private so we can still use it internally.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def self.read_only(*names)
|
|
|
|
names.each do |name|
|
|
|
|
private "#{name}="
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
# Shortcut for creating several attributes at once (each with a default
|
|
|
|
# value of +nil+).
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def self.attributes(*args)
|
|
|
|
args.each do |arg|
|
|
|
|
attribute(arg, nil)
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Some attributes require special behaviour when they are accessed. This
|
|
|
|
# allows for that.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def self.overwrite_accessor(name, &block)
|
|
|
|
remove_method name
|
|
|
|
define_method(name, &block)
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Defines a _singular_ version of an existing _plural_ attribute (i.e. one
|
|
|
|
# whose value is expected to be an array). This means just creating a
|
|
|
|
# helper method that takes a single value and appends it to the array.
|
|
|
|
# These are created for convenience, so that in a spec, one can write
|
|
|
|
#
|
|
|
|
# s.require_path = 'mylib'
|
|
|
|
#
|
|
|
|
# instead of:
|
|
|
|
#
|
|
|
|
# s.require_paths = ['mylib']
|
|
|
|
#
|
|
|
|
# That above convenience is available courtesy of:
|
|
|
|
#
|
|
|
|
# attribute_alias_singular :require_path, :require_paths
|
|
|
|
|
|
|
|
def self.attribute_alias_singular(singular, plural)
|
|
|
|
define_method("#{singular}=") { |val|
|
|
|
|
send("#{plural}=", [val])
|
|
|
|
}
|
|
|
|
define_method("#{singular}") {
|
|
|
|
val = send("#{plural}")
|
|
|
|
val.nil? ? nil : val.first
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Dump only crucial instance variables.
|
|
|
|
#--
|
|
|
|
# MAINTAIN ORDER!
|
|
|
|
|
|
|
|
def _dump(limit)
|
|
|
|
Marshal.dump [
|
|
|
|
@rubygems_version,
|
|
|
|
@specification_version,
|
|
|
|
@name,
|
|
|
|
@version,
|
|
|
|
(Time === @date ? @date : (require 'time'; Time.parse(@date.to_s))),
|
|
|
|
@summary,
|
|
|
|
@required_ruby_version,
|
|
|
|
@required_rubygems_version,
|
|
|
|
@original_platform,
|
|
|
|
@dependencies,
|
|
|
|
@rubyforge_project,
|
|
|
|
@email,
|
|
|
|
@authors,
|
|
|
|
@description,
|
|
|
|
@homepage,
|
|
|
|
@has_rdoc,
|
|
|
|
@new_platform,
|
|
|
|
@licenses
|
|
|
|
]
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Load custom marshal format, re-initializing defaults as needed
|
|
|
|
|
|
|
|
def self._load(str)
|
|
|
|
array = Marshal.load str
|
|
|
|
|
|
|
|
spec = Gem::Specification.new
|
|
|
|
spec.instance_variable_set :@specification_version, array[1]
|
|
|
|
|
|
|
|
current_version = CURRENT_SPECIFICATION_VERSION
|
|
|
|
|
|
|
|
field_count = if spec.specification_version > current_version then
|
|
|
|
spec.instance_variable_set :@specification_version,
|
|
|
|
current_version
|
|
|
|
MARSHAL_FIELDS[current_version]
|
|
|
|
else
|
|
|
|
MARSHAL_FIELDS[spec.specification_version]
|
|
|
|
end
|
|
|
|
|
|
|
|
if array.size < field_count then
|
|
|
|
raise TypeError, "invalid Gem::Specification format #{array.inspect}"
|
|
|
|
end
|
|
|
|
|
|
|
|
spec.instance_variable_set :@rubygems_version, array[0]
|
|
|
|
# spec version
|
|
|
|
spec.instance_variable_set :@name, array[2]
|
|
|
|
spec.instance_variable_set :@version, array[3]
|
|
|
|
spec.instance_variable_set :@date, array[4]
|
|
|
|
spec.instance_variable_set :@summary, array[5]
|
|
|
|
spec.instance_variable_set :@required_ruby_version, array[6]
|
|
|
|
spec.instance_variable_set :@required_rubygems_version, array[7]
|
|
|
|
spec.instance_variable_set :@original_platform, array[8]
|
|
|
|
spec.instance_variable_set :@dependencies, array[9]
|
|
|
|
spec.instance_variable_set :@rubyforge_project, array[10]
|
|
|
|
spec.instance_variable_set :@email, array[11]
|
|
|
|
spec.instance_variable_set :@authors, array[12]
|
|
|
|
spec.instance_variable_set :@description, array[13]
|
|
|
|
spec.instance_variable_set :@homepage, array[14]
|
|
|
|
spec.instance_variable_set :@has_rdoc, array[15]
|
|
|
|
spec.instance_variable_set :@new_platform, array[16]
|
|
|
|
spec.instance_variable_set :@platform, array[16].to_s
|
|
|
|
spec.instance_variable_set :@license, array[17]
|
|
|
|
spec.instance_variable_set :@loaded, false
|
|
|
|
|
|
|
|
spec
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# List of depedencies that will automatically be activated at runtime.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def runtime_dependencies
|
|
|
|
dependencies.select { |d| d.type == :runtime || d.type == nil }
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# List of dependencies that are used for development
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def development_dependencies
|
|
|
|
dependencies.select { |d| d.type == :development }
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def test_suite_file # :nodoc:
|
|
|
|
warn 'test_suite_file deprecated, use test_files'
|
|
|
|
test_files.first
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def test_suite_file=(val) # :nodoc:
|
|
|
|
warn 'test_suite_file= deprecated, use test_files='
|
|
|
|
@test_files = [] unless defined? @test_files
|
|
|
|
@test_files << val
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# true when this gemspec has been loaded from a specifications directory.
|
|
|
|
# This attribute is not persisted.
|
|
|
|
|
|
|
|
attr_accessor :loaded
|
|
|
|
|
|
|
|
##
|
|
|
|
# Path this gemspec was loaded from. This attribute is not persisted.
|
|
|
|
|
|
|
|
attr_accessor :loaded_from
|
|
|
|
|
|
|
|
##
|
|
|
|
# Returns an array with bindir attached to each executable in the
|
|
|
|
# executables list
|
|
|
|
|
|
|
|
def add_bindir(executables)
|
|
|
|
return nil if executables.nil?
|
|
|
|
|
|
|
|
if @bindir then
|
|
|
|
Array(executables).map { |e| File.join(@bindir, e) }
|
|
|
|
else
|
|
|
|
executables
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
rescue
|
|
|
|
return nil
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Files in the Gem under one of the require_paths
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def lib_files
|
|
|
|
@files.select do |file|
|
|
|
|
require_paths.any? do |path|
|
|
|
|
file.index(path) == 0
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# True if this gem was loaded from disk
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
alias :loaded? :loaded
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# True if this gem has files in test_files
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def has_unit_tests?
|
|
|
|
not test_files.empty?
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
# :stopdoc:
|
|
|
|
alias has_test_suite? has_unit_tests?
|
|
|
|
# :startdoc:
|
2008-06-25 22:06:00 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
2010-02-21 21:52:35 -05:00
|
|
|
# Specification constructor. Assigns the default values to the
|
|
|
|
# attributes and yields itself for further
|
|
|
|
# initialization. Optionally takes +name+ and +version+.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def initialize name = nil, version = nil
|
2009-06-09 17:38:59 -04:00
|
|
|
@new_platform = nil
|
|
|
|
assign_defaults
|
|
|
|
@loaded = false
|
|
|
|
@loaded_from = nil
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
self.name = name if name
|
|
|
|
self.version = version if version
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
yield self if block_given?
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@@gather.call(self) if @@gather
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Duplicates array_attributes from +other_spec+ so state isn't shared.
|
|
|
|
|
|
|
|
def initialize_copy(other_spec)
|
|
|
|
other_ivars = other_spec.instance_variables
|
|
|
|
other_ivars = other_ivars.map { |ivar| ivar.intern } if # for 1.9
|
|
|
|
other_ivars.any? { |ivar| String === ivar }
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
self.class.array_attributes.each do |name|
|
|
|
|
name = :"@#{name}"
|
|
|
|
next unless other_ivars.include? name
|
|
|
|
instance_variable_set name, other_spec.instance_variable_get(name).dup
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Each attribute has a default value (possibly nil). Here, we initialize
|
|
|
|
# all attributes to their default value. This is done through the
|
|
|
|
# accessor methods, so special behaviours will be honored. Furthermore,
|
|
|
|
# we take a _copy_ of the default so each specification instance has its
|
|
|
|
# own empty arrays, etc.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def assign_defaults
|
|
|
|
@@nil_attributes.each do |name|
|
|
|
|
instance_variable_set name, nil
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@@non_nil_attributes.each do |name, default|
|
|
|
|
value = case default
|
|
|
|
when Time, Numeric, Symbol, true, false, nil then default
|
|
|
|
else default.dup
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
instance_variable_set name, value
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
# HACK
|
|
|
|
instance_variable_set :@new_platform, Gem::Platform::RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Special loader for YAML files. When a Specification object is loaded
|
|
|
|
# from a YAML file, it bypasses the normal Ruby object initialization
|
|
|
|
# routine (#initialize). This method makes up for that and deals with
|
|
|
|
# gems of different ages.
|
|
|
|
#
|
|
|
|
# 'input' can be anything that YAML.load() accepts: String or IO.
|
|
|
|
|
|
|
|
def self.from_yaml(input)
|
|
|
|
input = normalize_yaml_input input
|
|
|
|
spec = YAML.load input
|
|
|
|
|
|
|
|
if spec && spec.class == FalseClass then
|
|
|
|
raise Gem::EndOfYAMLException
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
unless Gem::Specification === spec then
|
|
|
|
raise Gem::Exception, "YAML data doesn't evaluate to gem specification"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
unless (spec.instance_variables.include? '@specification_version' or
|
|
|
|
spec.instance_variables.include? :@specification_version) and
|
|
|
|
spec.instance_variable_get :@specification_version
|
|
|
|
spec.instance_variable_set :@specification_version,
|
|
|
|
NONEXISTENT_SPECIFICATION_VERSION
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
spec
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Loads ruby format gemspec from +filename+
|
|
|
|
|
|
|
|
def self.load(filename)
|
|
|
|
gemspec = nil
|
2010-02-21 21:52:35 -05:00
|
|
|
raise "NESTED Specification.load calls not allowed!" if @@gather
|
2009-06-09 17:38:59 -04:00
|
|
|
@@gather = proc { |gs| gemspec = gs }
|
2010-04-22 04:24:42 -04:00
|
|
|
data = File.read filename
|
|
|
|
eval data, nil, filename
|
2009-06-09 17:38:59 -04:00
|
|
|
gemspec
|
|
|
|
ensure
|
|
|
|
@@gather = nil
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Make sure the YAML specification is properly formatted with dashes
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def self.normalize_yaml_input(input)
|
|
|
|
result = input.respond_to?(:read) ? input.read : input
|
|
|
|
result = "--- " + result unless result =~ /^--- /
|
|
|
|
result
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Sets the rubygems_version to the current RubyGems version
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def mark_version
|
2010-04-22 04:24:42 -04:00
|
|
|
@rubygems_version = Gem::VERSION
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Ignore unknown attributes while loading
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def method_missing(sym, *a, &b) # :nodoc:
|
|
|
|
if @specification_version > CURRENT_SPECIFICATION_VERSION and
|
|
|
|
sym.to_s =~ /=$/ then
|
|
|
|
warn "ignoring #{sym} loading #{full_name}" if $DEBUG
|
|
|
|
else
|
|
|
|
super
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Adds a development dependency named +gem+ with +requirements+ to this
|
|
|
|
# Gem. For example:
|
|
|
|
#
|
|
|
|
# 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.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def add_development_dependency(gem, *requirements)
|
|
|
|
add_dependency_with_type(gem, :development, *requirements)
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Adds a runtime dependency named +gem+ with +requirements+ to this Gem.
|
|
|
|
# For example:
|
|
|
|
#
|
|
|
|
# spec.add_runtime_dependency 'jabber4r', '> 0.1', '<= 0.5'
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def add_runtime_dependency(gem, *requirements)
|
|
|
|
add_dependency_with_type(gem, :runtime, *requirements)
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Adds a runtime dependency
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
alias add_dependency add_runtime_dependency
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
def full_name
|
|
|
|
if platform == Gem::Platform::RUBY or platform.nil? then
|
|
|
|
"#{@name}-#{@version}"
|
|
|
|
else
|
|
|
|
"#{@name}-#{@version}-#{platform}"
|
|
|
|
end
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Returns the full name (name-version) of this gemspec using the original
|
|
|
|
# platform. For use with legacy gems.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def original_name # :nodoc:
|
|
|
|
if platform == Gem::Platform::RUBY or platform.nil? then
|
|
|
|
"#{@name}-#{@version}"
|
|
|
|
else
|
|
|
|
"#{@name}-#{@version}-#{@original_platform}"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# The full path to the gem (install path + full name).
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def full_gem_path
|
|
|
|
path = File.join installation_path, 'gems', full_name
|
|
|
|
return path if File.directory? path
|
|
|
|
File.join installation_path, 'gems', original_name
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
2010-02-21 21:52:35 -05:00
|
|
|
# The default (generated) file name of the gem. See also #spec_name.
|
|
|
|
#
|
|
|
|
# spec.file_name # => "example-1.0.gem"
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def file_name
|
2010-02-21 21:52:35 -05:00
|
|
|
full_name + '.gem'
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# The directory that this gem was installed into.
|
|
|
|
|
|
|
|
def installation_path
|
|
|
|
unless @loaded_from then
|
|
|
|
raise Gem::Exception, "spec #{full_name} is not from an installed gem"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
File.expand_path File.dirname(File.dirname(@loaded_from))
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Checks if this specification meets the requirement of +dependency+.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def satisfies_requirement?(dependency)
|
|
|
|
return @name == dependency.name &&
|
2010-02-21 21:52:35 -05:00
|
|
|
dependency.requirement.satisfied_by?(@version)
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Returns an object you can use to sort specifications in #sort_by.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def sort_obj
|
|
|
|
[@name, @version, @new_platform == Gem::Platform::RUBY ? -1 : 1]
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
##
|
|
|
|
# The default name of the gemspec. See also #file_name
|
|
|
|
#
|
|
|
|
# spec.spec_name # => "example-1.0.gemspec"
|
|
|
|
|
|
|
|
def spec_name
|
|
|
|
full_name + '.gemspec'
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def <=>(other) # :nodoc:
|
|
|
|
sort_obj <=> other.sort_obj
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Tests specs for equality (across all attributes).
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def ==(other) # :nodoc:
|
|
|
|
self.class === other && same_attributes?(other)
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
alias eql? == # :nodoc:
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# True if this gem has the same attributes as +other+.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def same_attributes?(other)
|
|
|
|
@@attributes.each do |name, default|
|
|
|
|
return false unless self.send(name) == other.send(name)
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
true
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
private :same_attributes?
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def hash # :nodoc:
|
|
|
|
@@attributes.inject(0) { |hash_code, (name, default_value)|
|
|
|
|
n = self.send(name).hash
|
|
|
|
hash_code + n
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
def encode_with coder # :nodoc:
|
2009-06-09 17:38:59 -04:00
|
|
|
mark_version
|
|
|
|
|
|
|
|
attributes = @@attributes.map { |name,| name.to_s }.sort
|
|
|
|
attributes = attributes - %w[name version platform]
|
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
coder.add 'name', @name
|
|
|
|
coder.add 'version', @version
|
|
|
|
platform = case @original_platform
|
|
|
|
when nil, '' then
|
|
|
|
'ruby'
|
|
|
|
when String then
|
|
|
|
@original_platform
|
|
|
|
else
|
|
|
|
@original_platform.to_s
|
|
|
|
end
|
|
|
|
coder.add 'platform', platform
|
|
|
|
|
|
|
|
attributes.each do |name|
|
|
|
|
coder.add name, instance_variable_get("@#{name}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_yaml(opts = {}) # :nodoc:
|
|
|
|
return super if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
yaml = YAML.quick_emit object_id, opts do |out|
|
|
|
|
out.map taguri, to_yaml_style do |map|
|
2010-04-22 04:24:42 -04:00
|
|
|
encode_with map
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
def init_with coder # :nodoc:
|
|
|
|
yaml_initialize coder.tag, coder.map
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def yaml_initialize(tag, vals) # :nodoc:
|
|
|
|
vals.each do |ivar, val|
|
|
|
|
instance_variable_set "@#{ivar}", val
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@original_platform = @platform # for backwards compatibility
|
|
|
|
self.platform = Gem::Platform.new @platform
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Returns a Ruby code representation of this specification, such that it
|
|
|
|
# can be eval'ed and reconstruct the same specification later. Attributes
|
|
|
|
# that still have their default values are omitted.
|
|
|
|
|
|
|
|
def to_ruby
|
|
|
|
mark_version
|
|
|
|
result = []
|
|
|
|
result << "# -*- encoding: utf-8 -*-"
|
|
|
|
result << nil
|
|
|
|
result << "Gem::Specification.new do |s|"
|
|
|
|
|
|
|
|
result << " s.name = #{ruby_code name}"
|
|
|
|
result << " s.version = #{ruby_code version}"
|
|
|
|
unless platform.nil? or platform == Gem::Platform::RUBY then
|
|
|
|
result << " s.platform = #{ruby_code original_platform}"
|
|
|
|
end
|
|
|
|
result << ""
|
|
|
|
result << " s.required_rubygems_version = #{ruby_code required_rubygems_version} if s.respond_to? :required_rubygems_version="
|
|
|
|
|
|
|
|
handled = [
|
|
|
|
:dependencies,
|
|
|
|
:name,
|
|
|
|
:platform,
|
|
|
|
:required_rubygems_version,
|
|
|
|
:specification_version,
|
|
|
|
:version,
|
|
|
|
]
|
|
|
|
|
|
|
|
attributes = @@attributes.sort_by { |attr_name,| attr_name.to_s }
|
|
|
|
|
|
|
|
attributes.each do |attr_name, default|
|
|
|
|
next if handled.include? attr_name
|
|
|
|
current_value = self.send(attr_name)
|
|
|
|
if current_value != default or
|
|
|
|
self.class.required_attribute? attr_name then
|
|
|
|
result << " s.#{attr_name} = #{ruby_code current_value}"
|
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
result << nil
|
|
|
|
result << " if s.respond_to? :specification_version then"
|
|
|
|
result << " current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION"
|
|
|
|
result << " s.specification_version = #{specification_version}"
|
|
|
|
result << nil
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
result << " if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then"
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
unless dependencies.empty? then
|
|
|
|
dependencies.each do |dep|
|
|
|
|
version_reqs_param = dep.requirements_list.inspect
|
|
|
|
dep.instance_variable_set :@type, :runtime if dep.type.nil? # HACK
|
|
|
|
result << " s.add_#{dep.type}_dependency(%q<#{dep.name}>, #{version_reqs_param})"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
result << " else"
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
unless dependencies.empty? then
|
|
|
|
dependencies.each do |dep|
|
|
|
|
version_reqs_param = dep.requirements_list.inspect
|
|
|
|
result << " s.add_dependency(%q<#{dep.name}>, #{version_reqs_param})"
|
2007-11-20 00:56:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
result << ' end'
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
result << " else"
|
|
|
|
dependencies.each do |dep|
|
|
|
|
version_reqs_param = dep.requirements_list.inspect
|
|
|
|
result << " s.add_dependency(%q<#{dep.name}>, #{version_reqs_param})"
|
|
|
|
end
|
|
|
|
result << " end"
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
result << "end"
|
|
|
|
result << nil
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
result.join "\n"
|
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Checks that the specification contains all required fields, and does a
|
|
|
|
# very basic sanity check.
|
|
|
|
#
|
|
|
|
# Raises InvalidSpecificationException if the spec does not pass the
|
|
|
|
# checks..
|
|
|
|
|
|
|
|
def validate
|
|
|
|
extend Gem::UserInteraction
|
|
|
|
normalize
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
if rubygems_version != Gem::VERSION then
|
2009-06-09 17:38:59 -04:00
|
|
|
raise Gem::InvalidSpecificationException,
|
2010-04-22 04:24:42 -04:00
|
|
|
"expected RubyGems version #{Gem::VERSION}, was #{rubygems_version}"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@@required_attributes.each do |symbol|
|
|
|
|
unless self.send symbol then
|
|
|
|
raise Gem::InvalidSpecificationException,
|
|
|
|
"missing value for attribute #{symbol}"
|
|
|
|
end
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
unless String === name then
|
|
|
|
raise Gem::InvalidSpecificationException,
|
|
|
|
"invalid value for attribute name: \"#{name.inspect}\""
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
if require_paths.empty? then
|
|
|
|
raise Gem::InvalidSpecificationException,
|
|
|
|
'specification must have at least one require_path'
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@files.delete_if do |file| File.directory? file end
|
|
|
|
@test_files.delete_if do |file| File.directory? file end
|
|
|
|
@executables.delete_if do |file|
|
|
|
|
File.directory? File.join(bindir, file)
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
@extra_rdoc_files.delete_if do |file| File.directory? file end
|
|
|
|
@extensions.delete_if do |file| File.directory? file end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
non_files = files.select do |file|
|
|
|
|
!File.file? file
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
unless non_files.empty? then
|
|
|
|
non_files = non_files.map { |file| file.inspect }
|
|
|
|
raise Gem::InvalidSpecificationException,
|
|
|
|
"[#{non_files.join ", "}] are not files"
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
unless specification_version.is_a?(Fixnum)
|
|
|
|
raise Gem::InvalidSpecificationException,
|
|
|
|
'specification_version must be a Fixnum (did you mean version?)'
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
case platform
|
|
|
|
when Gem::Platform, Gem::Platform::RUBY then # ok
|
|
|
|
else
|
|
|
|
raise Gem::InvalidSpecificationException,
|
|
|
|
"invalid platform #{platform.inspect}, see Gem::Platform"
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
unless Array === authors and
|
|
|
|
authors.all? { |author| String === author } then
|
|
|
|
raise Gem::InvalidSpecificationException,
|
|
|
|
'authors must be Array of Strings'
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
licenses.each { |license|
|
|
|
|
if license.length > 64
|
|
|
|
raise Gem::InvalidSpecificationException,
|
|
|
|
"each license must be 64 characters or less"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
}
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
# reject FIXME and TODO
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
unless authors.grep(/FIXME|TODO/).empty? then
|
|
|
|
raise Gem::InvalidSpecificationException,
|
|
|
|
'"FIXME" or "TODO" is not an author'
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2007-11-20 00:56:43 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
unless Array(email).grep(/FIXME|TODO/).empty? then
|
|
|
|
raise Gem::InvalidSpecificationException,
|
|
|
|
'"FIXME" or "TODO" is not an email address'
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
if description =~ /FIXME|TODO/ then
|
|
|
|
raise Gem::InvalidSpecificationException,
|
|
|
|
'"FIXME" or "TODO" is not a description'
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
if summary =~ /FIXME|TODO/ then
|
|
|
|
raise Gem::InvalidSpecificationException,
|
|
|
|
'"FIXME" or "TODO" is not a summary'
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
if homepage and not homepage.empty? and
|
|
|
|
homepage !~ /\A[a-z][a-z\d+.-]*:/i then
|
|
|
|
raise Gem::InvalidSpecificationException,
|
|
|
|
"\"#{homepage}\" is not a URI"
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
# Warnings
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
%w[author description email homepage rubyforge_project summary].each do |attribute|
|
|
|
|
value = self.send attribute
|
|
|
|
alert_warning "no #{attribute} specified" if value.nil? or value.empty?
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
if summary and not summary.empty? and description == summary then
|
|
|
|
alert_warning 'description and summary are identical'
|
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
alert_warning "deprecated autorequire specified" if autorequire
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
executables.each do |executable|
|
|
|
|
executable_path = File.join bindir, executable
|
|
|
|
shebang = File.read(executable_path, 2) == '#!'
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
alert_warning "#{executable_path} is missing #! line" unless shebang
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
true
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Normalize the list of files so that:
|
|
|
|
# * All file lists have redundancies removed.
|
|
|
|
# * Files referenced in the extra_rdoc_files are included in the package
|
|
|
|
# file list.
|
|
|
|
|
|
|
|
def normalize
|
|
|
|
if defined?(@extra_rdoc_files) and @extra_rdoc_files then
|
|
|
|
@extra_rdoc_files.uniq!
|
|
|
|
@files ||= []
|
|
|
|
@files.concat(@extra_rdoc_files)
|
|
|
|
end
|
|
|
|
@files.uniq! if @files
|
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Return a list of all gems that have a dependency on this gemspec. The
|
|
|
|
# list is structured with entries that conform to:
|
|
|
|
#
|
|
|
|
# [depending_gem, dependency, [list_of_gems_that_satisfy_dependency]]
|
|
|
|
|
|
|
|
def dependent_gems
|
|
|
|
out = []
|
|
|
|
Gem.source_index.each do |name,gem|
|
|
|
|
gem.dependencies.each do |dep|
|
|
|
|
if self.satisfies_requirement?(dep) then
|
|
|
|
sats = []
|
|
|
|
find_all_satisfiers(dep) do |sat|
|
|
|
|
sats << sat
|
|
|
|
end
|
|
|
|
out << [gem, dep, sats]
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
out
|
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def to_s # :nodoc:
|
|
|
|
"#<Gem::Specification name=#{@name} version=#{@version}>"
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def pretty_print(q) # :nodoc:
|
|
|
|
q.group 2, 'Gem::Specification.new do |s|', 'end' do
|
|
|
|
q.breakable
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attributes = @@attributes.sort_by { |attr_name,| attr_name.to_s }
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attributes.each do |attr_name, default|
|
|
|
|
current_value = self.send attr_name
|
|
|
|
if current_value != default or
|
|
|
|
self.class.required_attribute? attr_name then
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
q.text "s.#{attr_name} = "
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
if attr_name == :date then
|
|
|
|
current_value = current_value.utc
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
q.text "Time.utc(#{current_value.year}, #{current_value.month}, #{current_value.day})"
|
|
|
|
else
|
|
|
|
q.pp current_value
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
q.breakable
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Adds a dependency on gem +dependency+ with type +type+ that requires
|
|
|
|
# +requirements+. Valid types are currently <tt>:runtime</tt> and
|
|
|
|
# <tt>:development</tt>.
|
2007-12-20 03:39:12 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def add_dependency_with_type(dependency, type, *requirements)
|
|
|
|
requirements = if requirements.empty? then
|
|
|
|
Gem::Requirement.default
|
|
|
|
else
|
|
|
|
requirements.flatten
|
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
unless dependency.respond_to?(:name) &&
|
|
|
|
dependency.respond_to?(:version_requirements)
|
2007-12-20 03:39:12 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
dependency = Gem::Dependency.new(dependency, requirements, type)
|
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
dependencies << dependency
|
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
private :add_dependency_with_type
|
2007-12-20 03:39:12 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Finds all gems that satisfy +dep+
|
2007-12-20 03:39:12 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def find_all_satisfiers(dep)
|
|
|
|
Gem.source_index.each do |_, gem|
|
|
|
|
yield gem if gem.satisfies_requirement? dep
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
private :find_all_satisfiers
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Return a string containing a Ruby code representation of the given
|
|
|
|
# object.
|
|
|
|
|
|
|
|
def ruby_code(obj)
|
|
|
|
case obj
|
|
|
|
when String then '%q{' + obj + '}'
|
|
|
|
when Array then obj.inspect
|
|
|
|
when Gem::Version then obj.to_s.inspect
|
|
|
|
when Date then '%q{' + obj.strftime('%Y-%m-%d') + '}'
|
|
|
|
when Time then '%q{' + obj.strftime('%Y-%m-%d') + '}'
|
|
|
|
when Numeric then obj.inspect
|
|
|
|
when true, false, nil then obj.inspect
|
|
|
|
when Gem::Platform then "Gem::Platform.new(#{obj.to_a.inspect})"
|
|
|
|
when Gem::Requirement then "Gem::Requirement.new(#{obj.to_s.inspect})"
|
|
|
|
else raise Gem::Exception, "ruby_code case not handled: #{obj.class}"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
private :ruby_code
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
# :section: Required gemspec attributes
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: rubygems_version
|
|
|
|
#
|
2010-02-21 21:52:35 -05:00
|
|
|
# The version of RubyGems used to create this gem.
|
|
|
|
#
|
|
|
|
# Do not set this, it is set automatically when the gem is packaged.
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
required_attribute :rubygems_version, Gem::VERSION
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: specification_version
|
|
|
|
#
|
2010-02-21 21:52:35 -05:00
|
|
|
# The Gem::Specification version of this gemspec.
|
|
|
|
#
|
|
|
|
# Do not set this, it is set automatically when the gem is packaged.
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
required_attribute :specification_version, CURRENT_SPECIFICATION_VERSION
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: name
|
|
|
|
#
|
|
|
|
# This gem's name
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
required_attribute :name
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: version
|
|
|
|
#
|
|
|
|
# This gem's version
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
required_attribute :version
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: date
|
|
|
|
#
|
|
|
|
# The date this gem was created
|
2010-02-21 21:52:35 -05:00
|
|
|
#
|
|
|
|
# Do not set this, it is set automatically when the gem is packaged.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
required_attribute :date, TODAY
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: summary
|
|
|
|
#
|
|
|
|
# A short summary of this gem's description. Displayed in `gem list -d`.
|
2010-02-21 21:52:35 -05:00
|
|
|
#
|
|
|
|
# The description should be more detailed than the summary. For example,
|
|
|
|
# you might wish to copy the entire README into the description.
|
|
|
|
#
|
|
|
|
# As of RubyGems 1.3.2 newlines are no longer stripped.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
required_attribute :summary
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: require_paths
|
|
|
|
#
|
2010-02-21 21:52:35 -05:00
|
|
|
# Paths in the gem to add to $LOAD_PATH when this gem is activated.
|
|
|
|
#
|
|
|
|
# The default 'lib' is typically sufficient.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
required_attribute :require_paths, ['lib']
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
# :section: Optional gemspec attributes
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: email
|
|
|
|
#
|
|
|
|
# A contact email for this gem
|
2010-02-21 21:52:35 -05:00
|
|
|
#
|
|
|
|
# If you are providing multiple authors and multiple emails they should be
|
|
|
|
# in the same order such that:
|
|
|
|
#
|
|
|
|
# Hash[*spec.authors.zip(spec.emails).flatten]
|
|
|
|
#
|
|
|
|
# Gives a hash of author name to email address.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute :email
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: homepage
|
|
|
|
#
|
|
|
|
# The URL of this gem's home page
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute :homepage
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: rubyforge_project
|
|
|
|
#
|
|
|
|
# The rubyforge project this gem lives under. i.e. RubyGems'
|
|
|
|
# rubyforge_project is "rubygems".
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute :rubyforge_project
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: description
|
|
|
|
#
|
|
|
|
# A long description of this gem
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute :description
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: autorequire
|
|
|
|
#
|
|
|
|
# Autorequire was used by old RubyGems to automatically require a file.
|
|
|
|
# It no longer is supported.
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute :autorequire
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: default_executable
|
|
|
|
#
|
|
|
|
# The default executable for this gem.
|
2010-02-21 21:52:35 -05:00
|
|
|
#
|
|
|
|
# This is not used.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute :default_executable
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: bindir
|
|
|
|
#
|
|
|
|
# The path in the gem for executable scripts
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute :bindir, 'bin'
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: has_rdoc
|
|
|
|
#
|
|
|
|
# Deprecated and ignored, defaults to true.
|
|
|
|
#
|
|
|
|
# Formerly used to indicate this gem was RDoc-capable.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute :has_rdoc, true
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# True if this gem supports RDoc
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
alias :has_rdoc? :has_rdoc
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: required_ruby_version
|
|
|
|
#
|
2010-02-21 21:52:35 -05:00
|
|
|
# The version of ruby required by this gem
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute :required_ruby_version, Gem::Requirement.default
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: required_rubygems_version
|
|
|
|
#
|
|
|
|
# The RubyGems version required by this gem
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute :required_rubygems_version, Gem::Requirement.default
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: platform
|
|
|
|
#
|
|
|
|
# The platform this gem runs on. See Gem::Platform for details.
|
2010-02-21 21:52:35 -05:00
|
|
|
#
|
|
|
|
# Setting this to any value other than Gem::Platform::RUBY or
|
|
|
|
# Gem::Platform::CURRENT is probably wrong.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute :platform, Gem::Platform::RUBY
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: signing_key
|
|
|
|
#
|
|
|
|
# The key used to sign this gem. See Gem::Security for details.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute :signing_key, nil
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: cert_chain
|
|
|
|
#
|
|
|
|
# The certificate chain used to sign this gem. See Gem::Security for
|
|
|
|
# details.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute :cert_chain, []
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: post_install_message
|
|
|
|
#
|
|
|
|
# A message that gets displayed after the gem is installed
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute :post_install_message, nil
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: authors
|
|
|
|
#
|
2010-02-21 21:52:35 -05:00
|
|
|
# The list of author names who wrote this gem.
|
|
|
|
#
|
|
|
|
# If you are providing multiple authors and multiple emails they should be
|
|
|
|
# in the same order such that:
|
|
|
|
#
|
|
|
|
# Hash[*spec.authors.zip(spec.emails).flatten]
|
|
|
|
#
|
|
|
|
# Gives a hash of author name to email address.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
array_attribute :authors
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: licenses
|
|
|
|
#
|
|
|
|
# The license(s) for the library. Each license must be a short name, no
|
|
|
|
# more than 64 characters.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
array_attribute :licenses
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: files
|
|
|
|
#
|
|
|
|
# Files included in this gem. You cannot append to this accessor, you must
|
|
|
|
# assign to it.
|
|
|
|
#
|
|
|
|
# Only add files you can require to this list, not directories, etc.
|
|
|
|
#
|
|
|
|
# Directories are automatically stripped from this list when building a gem,
|
|
|
|
# other non-files cause an error.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
array_attribute :files
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: test_files
|
|
|
|
#
|
|
|
|
# Test files included in this gem. You cannot append to this accessor, you
|
|
|
|
# must assign to it.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
array_attribute :test_files
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: rdoc_options
|
|
|
|
#
|
2010-02-21 21:52:35 -05:00
|
|
|
# An ARGV style array of options to RDoc
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
array_attribute :rdoc_options
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: extra_rdoc_files
|
|
|
|
#
|
2010-02-21 21:52:35 -05:00
|
|
|
# Extra files to add to RDoc such as README or doc/examples.txt
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
array_attribute :extra_rdoc_files
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: executables
|
|
|
|
#
|
2010-02-21 21:52:35 -05:00
|
|
|
# Executables included in the gem.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
array_attribute :executables
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: extensions
|
|
|
|
#
|
|
|
|
# Extensions to build when installing the gem. See
|
|
|
|
# Gem::Installer#build_extensions for valid values.
|
|
|
|
|
|
|
|
array_attribute :extensions
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_accessor: requirements
|
|
|
|
#
|
|
|
|
# An array or things required by this gem. Not used by anything
|
|
|
|
# presently.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
array_attribute :requirements
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# :attr_reader: dependencies
|
|
|
|
#
|
|
|
|
# A list of Gem::Dependency objects this gem depends on.
|
2010-02-21 21:52:35 -05:00
|
|
|
#
|
|
|
|
# Use #add_dependency or #add_development_dependency to add dependencies to
|
|
|
|
# a gem.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
array_attribute :dependencies
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
read_only :dependencies
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
# :section: Aliased gemspec attributes
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Singular accessor for #executables
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute_alias_singular :executable, :executables
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Singular accessor for #authors
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute_alias_singular :author, :authors
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Singular accessor for #licenses
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute_alias_singular :license, :licenses
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Singular accessor for #require_paths
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute_alias_singular :require_path, :require_paths
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Singular accessor for #test_files
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
attribute_alias_singular :test_file, :test_files
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# has_rdoc is now ignored
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
overwrite_accessor :has_rdoc do
|
|
|
|
true
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# has_rdoc is now ignored
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
overwrite_accessor :has_rdoc= do |value|
|
|
|
|
@has_rdoc = true
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
overwrite_accessor :version= do |version|
|
|
|
|
@version = Gem::Version.create(version)
|
|
|
|
self.required_rubygems_version = '> 1.3.1' if @version.prerelease?
|
|
|
|
return @version
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
overwrite_accessor :platform do
|
|
|
|
@new_platform
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
overwrite_accessor :platform= do |platform|
|
|
|
|
if @original_platform.nil? or
|
|
|
|
@original_platform == Gem::Platform::RUBY then
|
|
|
|
@original_platform = platform
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
case platform
|
|
|
|
when Gem::Platform::CURRENT then
|
|
|
|
@new_platform = Gem::Platform.local
|
|
|
|
@original_platform = @new_platform.to_s
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
when Gem::Platform then
|
|
|
|
@new_platform = platform
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
# legacy constants
|
|
|
|
when nil, Gem::Platform::RUBY then
|
|
|
|
@new_platform = Gem::Platform::RUBY
|
|
|
|
when 'mswin32' then # was Gem::Platform::WIN32
|
|
|
|
@new_platform = Gem::Platform.new 'x86-mswin32'
|
|
|
|
when 'i586-linux' then # was Gem::Platform::LINUX_586
|
|
|
|
@new_platform = Gem::Platform.new 'x86-linux'
|
|
|
|
when 'powerpc-darwin' then # was Gem::Platform::DARWIN
|
|
|
|
@new_platform = Gem::Platform.new 'ppc-darwin'
|
|
|
|
else
|
|
|
|
@new_platform = Gem::Platform.new platform
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@platform = @new_platform.to_s
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@new_platform
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
overwrite_accessor :required_ruby_version= do |value|
|
|
|
|
@required_ruby_version = Gem::Requirement.create(value)
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
overwrite_accessor :required_rubygems_version= do |value|
|
|
|
|
@required_rubygems_version = Gem::Requirement.create(value)
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
overwrite_accessor :date= do |date|
|
|
|
|
# We want to end up with a Time object with one-day resolution.
|
|
|
|
# This is the cleanest, most-readable, faster-than-using-Date
|
|
|
|
# way to do it.
|
|
|
|
case date
|
|
|
|
when String then
|
|
|
|
@date = if /\A(\d{4})-(\d{2})-(\d{2})\Z/ =~ date then
|
|
|
|
Time.local($1.to_i, $2.to_i, $3.to_i)
|
|
|
|
else
|
|
|
|
require 'time'
|
|
|
|
Time.parse date
|
|
|
|
end
|
|
|
|
when Time then
|
|
|
|
@date = Time.local(date.year, date.month, date.day)
|
|
|
|
when Date then
|
|
|
|
@date = Time.local(date.year, date.month, date.day)
|
|
|
|
else
|
|
|
|
@date = TODAY
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
overwrite_accessor :date do
|
|
|
|
self.date = nil if @date.nil? # HACK Sets the default value for date
|
|
|
|
@date
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
overwrite_accessor :summary= do |str|
|
|
|
|
@summary = if str then
|
|
|
|
str.strip.
|
|
|
|
gsub(/(\w-)\n[ \t]*(\w)/, '\1\2').
|
|
|
|
gsub(/\n[ \t]*/, " ")
|
|
|
|
end
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
overwrite_accessor :description= do |str|
|
|
|
|
@description = str.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
overwrite_accessor :default_executable do
|
|
|
|
begin
|
|
|
|
if defined?(@default_executable) and @default_executable
|
|
|
|
result = @default_executable
|
|
|
|
elsif @executables and @executables.size == 1
|
|
|
|
result = Array(@executables).first
|
2008-09-25 06:13:50 -04:00
|
|
|
else
|
2009-06-09 17:38:59 -04:00
|
|
|
result = nil
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
result
|
|
|
|
rescue
|
|
|
|
nil
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
overwrite_accessor :test_files do
|
|
|
|
# Handle the possibility that we have @test_suite_file but not
|
|
|
|
# @test_files. This will happen when an old gem is loaded via
|
|
|
|
# YAML.
|
|
|
|
if defined? @test_suite_file then
|
|
|
|
@test_files = [@test_suite_file].flatten
|
|
|
|
@test_suite_file = nil
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
if defined?(@test_files) and @test_files then
|
|
|
|
@test_files
|
|
|
|
else
|
|
|
|
@test_files = []
|
|
|
|
end
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
overwrite_accessor :files do
|
2010-04-22 04:24:42 -04:00
|
|
|
# DO NOT CHANGE TO ||= ! This is not a normal accessor. (yes, it sucks)
|
|
|
|
@files = [@files,
|
|
|
|
@test_files,
|
|
|
|
add_bindir(@executables),
|
|
|
|
@extra_rdoc_files,
|
|
|
|
@extensions,
|
|
|
|
].flatten.uniq.compact
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|