summaryrefslogtreecommitdiff
path: root/lib/rubygems/specification_policy.rb
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2020-05-29 15:57:45 +0200
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-06-05 07:32:42 +0900
commite9c8066bd965634475f4273406fd0e0f6f5e5988 (patch)
tree722135430d8444a7a96683d8c972785caad250d4 /lib/rubygems/specification_policy.rb
parent455330143aed490f867cde2c1a5d0db81c2b7c76 (diff)
[rubygems/rubygems] Split validations into required and optional
https://github.com/rubygems/rubygems/commit/55b09a7aa2
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3184
Diffstat (limited to 'lib/rubygems/specification_policy.rb')
-rw-r--r--lib/rubygems/specification_policy.rb60
1 files changed, 47 insertions, 13 deletions
diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb
index f752240368..f96e95b5e1 100644
--- a/lib/rubygems/specification_policy.rb
+++ b/lib/rubygems/specification_policy.rb
@@ -42,6 +42,23 @@ class Gem::SpecificationPolicy
# messages instead.
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_rubygems_version
@@ -68,12 +85,18 @@ class Gem::SpecificationPolicy
validate_metadata
+ validate_licenses_length
+
+ validate_lazy_metadata
+
+ validate_duplicate_dependencies
+ end
+
+ def validate_optional(strict)
validate_licenses
validate_permissions
- validate_lazy_metadata
-
validate_values
validate_dependencies
@@ -89,8 +112,6 @@ class Gem::SpecificationPolicy
alert_warning help_text
end
end
-
- true
end
##
@@ -129,16 +150,13 @@ class Gem::SpecificationPolicy
end
##
- # Checks that dependencies use requirements as we recommend. Warnings are
- # issued when dependencies are open-ended or overly strict for semantic
- # versioning.
+ # Checks that no duplicate dependencies are specified.
- def validate_dependencies # :nodoc:
+ def validate_duplicate_dependencies # :nodoc:
# NOTE: see REFACTOR note in Gem::Dependency about types - this might be brittle
seen = Gem::Dependency::TYPES.inject({}) { |types, type| types.merge({ type => {}}) }
error_messages = []
- warning_messages = []
@specification.dependencies.each do |dep|
if prev = seen[dep.type][dep.name]
error_messages << <<-MESSAGE
@@ -148,7 +166,20 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use:
end
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|
Gem::Requirement.new(req).prerelease?
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"
end
end
- if error_messages.any?
- error error_messages.join
- end
if warning_messages.any?
warning_messages.each { |warning_message| warning warning_message }
end
@@ -321,14 +349,20 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use:
error "authors may not be empty"
end
- def validate_licenses
+ def validate_licenses_length
licenses = @specification.licenses
licenses.each do |license|
if license.length > 64
error "each license must be 64 characters or less"
end
+ end
+ end
+
+ def validate_licenses
+ licenses = @specification.licenses
+ licenses.each do |license|
if !Gem::Licenses.match?(license)
suggestions = Gem::Licenses.suggestions(license)
message = <<-WARNING