Project

General

Profile

Defect #13189 ยป dont-abort-for-plugin-mismatch-on-trunk-13189.patch

Harry Garrood, 2013-03-11 20:26

View differences:

lib/redmine/plugin.rb
end
# Sets a requirement on Redmine version
# Raises a PluginRequirementError exception if the requirement is not met
# Raises a PluginRequirementError exception if the requirement is not met.
# if the current branch is 'devel' -- that is, the user is on Redmine
# trunk, print a warning instead.
#
# Examples
# # Requires Redmine 0.7.3 or higher
......
when :version_or_higher
raise ArgumentError.new(":version_or_higher accepts a version string only") unless req.is_a?(String)
unless compare_versions(req, current) <= 0
raise PluginRequirementError.new("#{id} plugin requires Redmine #{req} or higher but current is #{current.join('.')}")
plugin_version_mismatch("#{id} plugin requires Redmine #{req} or higher but current is #{current.join('.')}")
end
when :version
req = [req] if req.is_a?(String)
if req.is_a?(Array)
unless req.detect {|ver| compare_versions(ver, current) == 0}
raise PluginRequirementError.new("#{id} plugin requires one the following Redmine versions: #{req.join(', ')} but current is #{current.join('.')}")
plugin_version_mismatch("#{id} plugin requires one the following Redmine versions: #{req.join(', ')} but current is #{current.join('.')}")
end
elsif req.is_a?(Range)
unless compare_versions(req.first, current) <= 0 && compare_versions(req.last, current) >= 0
raise PluginRequirementError.new("#{id} plugin requires a Redmine version between #{req.first} and #{req.last} but current is #{current.join('.')}")
plugin_version_mismatch("#{id} plugin requires a Redmine version between #{req.first} and #{req.last} but current is #{current.join('.')}")
end
else
raise ArgumentError.new(":version option accepts a version string, an array or a range of versions")
......
true
end
def plugin_version_mismatch(message)
if Redmine::VERSION.to_a[3] == 'devel'
warn "warning: #{message}"
warn "warning: this would have caused an abort if you weren't on trunk"
else
raise PluginRequirementError.new(message)
end
end
private :plugin_version_mismatch
def compare_versions(requirement, current)
requirement = requirement.split('.').collect(&:to_i)
requirement <=> current.slice(0, requirement.size)
test/unit/lib/redmine/plugin_test.rb
assert_raise Redmine::PluginRequirementError do
plugin.requires_redmine(:version_or_higher => '2.2')
end
# Warn instead of failing if branch is 'devel'
Redmine::VERSION.stubs(:to_a).returns([2, 1, 3, "devel", 10817])
_, stderr = capture_io do
plugin.requires_redmine(:version_or_higher => '2.2')
end
assert_match /requires Redmine/, stderr
end
def test_requires_redmine_plugin
    (1-1/1)