mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[rubygems/rubygems] Split validations into required and optional
55b09a7aa2
This commit is contained in:
parent
455330143a
commit
e9c8066bd9
Notes:
git
2020-06-05 07:33:35 +09:00
1 changed files with 47 additions and 13 deletions
|
@ -42,6 +42,23 @@ class Gem::SpecificationPolicy
|
||||||
# messages instead.
|
# messages instead.
|
||||||
|
|
||||||
def validate(strict = false)
|
def validate(strict = false)
|
||||||
|
validate_required!
|
||||||
|
|
||||||
|
validate_optional(strict)
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Does a sanity check on the specification.
|
||||||
|
#
|
||||||
|
# Raises InvalidSpecificationException if the spec does not pass the
|
||||||
|
# checks.
|
||||||
|
#
|
||||||
|
# Only runs checks that are considered necessary for the specification to be
|
||||||
|
# functional.
|
||||||
|
|
||||||
|
def validate_required!
|
||||||
validate_nil_attributes
|
validate_nil_attributes
|
||||||
|
|
||||||
validate_rubygems_version
|
validate_rubygems_version
|
||||||
|
@ -68,12 +85,18 @@ class Gem::SpecificationPolicy
|
||||||
|
|
||||||
validate_metadata
|
validate_metadata
|
||||||
|
|
||||||
|
validate_licenses_length
|
||||||
|
|
||||||
|
validate_lazy_metadata
|
||||||
|
|
||||||
|
validate_duplicate_dependencies
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_optional(strict)
|
||||||
validate_licenses
|
validate_licenses
|
||||||
|
|
||||||
validate_permissions
|
validate_permissions
|
||||||
|
|
||||||
validate_lazy_metadata
|
|
||||||
|
|
||||||
validate_values
|
validate_values
|
||||||
|
|
||||||
validate_dependencies
|
validate_dependencies
|
||||||
|
@ -89,8 +112,6 @@ class Gem::SpecificationPolicy
|
||||||
alert_warning help_text
|
alert_warning help_text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -129,16 +150,13 @@ class Gem::SpecificationPolicy
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Checks that dependencies use requirements as we recommend. Warnings are
|
# Checks that no duplicate dependencies are specified.
|
||||||
# issued when dependencies are open-ended or overly strict for semantic
|
|
||||||
# versioning.
|
|
||||||
|
|
||||||
def validate_dependencies # :nodoc:
|
def validate_duplicate_dependencies # :nodoc:
|
||||||
# NOTE: see REFACTOR note in Gem::Dependency about types - this might be brittle
|
# NOTE: see REFACTOR note in Gem::Dependency about types - this might be brittle
|
||||||
seen = Gem::Dependency::TYPES.inject({}) { |types, type| types.merge({ type => {}}) }
|
seen = Gem::Dependency::TYPES.inject({}) { |types, type| types.merge({ type => {}}) }
|
||||||
|
|
||||||
error_messages = []
|
error_messages = []
|
||||||
warning_messages = []
|
|
||||||
@specification.dependencies.each do |dep|
|
@specification.dependencies.each do |dep|
|
||||||
if prev = seen[dep.type][dep.name]
|
if prev = seen[dep.type][dep.name]
|
||||||
error_messages << <<-MESSAGE
|
error_messages << <<-MESSAGE
|
||||||
|
@ -148,7 +166,20 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use:
|
||||||
end
|
end
|
||||||
|
|
||||||
seen[dep.type][dep.name] = dep
|
seen[dep.type][dep.name] = dep
|
||||||
|
end
|
||||||
|
if error_messages.any?
|
||||||
|
error error_messages.join
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Checks that dependencies use requirements as we recommend. Warnings are
|
||||||
|
# issued when dependencies are open-ended or overly strict for semantic
|
||||||
|
# versioning.
|
||||||
|
|
||||||
|
def validate_dependencies # :nodoc:
|
||||||
|
warning_messages = []
|
||||||
|
@specification.dependencies.each do |dep|
|
||||||
prerelease_dep = dep.requirements_list.any? do |req|
|
prerelease_dep = dep.requirements_list.any? do |req|
|
||||||
Gem::Requirement.new(req).prerelease?
|
Gem::Requirement.new(req).prerelease?
|
||||||
end
|
end
|
||||||
|
@ -183,9 +214,6 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use:
|
||||||
warning_messages << ["open-ended dependency on #{dep} is not recommended", recommendation].join("\n") + "\n"
|
warning_messages << ["open-ended dependency on #{dep} is not recommended", recommendation].join("\n") + "\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if error_messages.any?
|
|
||||||
error error_messages.join
|
|
||||||
end
|
|
||||||
if warning_messages.any?
|
if warning_messages.any?
|
||||||
warning_messages.each { |warning_message| warning warning_message }
|
warning_messages.each { |warning_message| warning warning_message }
|
||||||
end
|
end
|
||||||
|
@ -321,14 +349,20 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use:
|
||||||
error "authors may not be empty"
|
error "authors may not be empty"
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_licenses
|
def validate_licenses_length
|
||||||
licenses = @specification.licenses
|
licenses = @specification.licenses
|
||||||
|
|
||||||
licenses.each do |license|
|
licenses.each do |license|
|
||||||
if license.length > 64
|
if license.length > 64
|
||||||
error "each license must be 64 characters or less"
|
error "each license must be 64 characters or less"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_licenses
|
||||||
|
licenses = @specification.licenses
|
||||||
|
|
||||||
|
licenses.each do |license|
|
||||||
if !Gem::Licenses.match?(license)
|
if !Gem::Licenses.match?(license)
|
||||||
suggestions = Gem::Licenses.suggestions(license)
|
suggestions = Gem::Licenses.suggestions(license)
|
||||||
message = <<-WARNING
|
message = <<-WARNING
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue