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
158 158
    end
159 159

  
160 160
    # Sets a requirement on Redmine version
161
    # Raises a PluginRequirementError exception if the requirement is not met
161
    # Raises a PluginRequirementError exception if the requirement is not met.
162
    # if the current branch is 'devel' -- that is, the user is on Redmine
163
    # trunk, print a warning instead.
162 164
    #
163 165
    # Examples
164 166
    #   # Requires Redmine 0.7.3 or higher
......
186 188
        when :version_or_higher
187 189
          raise ArgumentError.new(":version_or_higher accepts a version string only") unless req.is_a?(String)
188 190
          unless compare_versions(req, current) <= 0
189
            raise PluginRequirementError.new("#{id} plugin requires Redmine #{req} or higher but current is #{current.join('.')}")
191
            plugin_version_mismatch("#{id} plugin requires Redmine #{req} or higher but current is #{current.join('.')}")
190 192
          end
191 193
        when :version
192 194
          req = [req] if req.is_a?(String)
193 195
          if req.is_a?(Array)
194 196
            unless req.detect {|ver| compare_versions(ver, current) == 0}
195
              raise PluginRequirementError.new("#{id} plugin requires one the following Redmine versions: #{req.join(', ')} but current is #{current.join('.')}")
197
              plugin_version_mismatch("#{id} plugin requires one the following Redmine versions: #{req.join(', ')} but current is #{current.join('.')}")
196 198
            end
197 199
          elsif req.is_a?(Range)
198 200
            unless compare_versions(req.first, current) <= 0 && compare_versions(req.last, current) >= 0
199
              raise PluginRequirementError.new("#{id} plugin requires a Redmine version between #{req.first} and #{req.last} but current is #{current.join('.')}")
201
              plugin_version_mismatch("#{id} plugin requires a Redmine version between #{req.first} and #{req.last} but current is #{current.join('.')}")
200 202
            end
201 203
          else
202 204
            raise ArgumentError.new(":version option accepts a version string, an array or a range of versions")
......
206 208
      true
207 209
    end
208 210

  
211
    def plugin_version_mismatch(message)
212
      if Redmine::VERSION.to_a[3] == 'devel'
213
        warn "warning: #{message}"
214
        warn "warning: this would have caused an abort if you weren't on trunk"
215
      else
216
        raise PluginRequirementError.new(message)
217
      end
218
    end
219
    private :plugin_version_mismatch
220

  
209 221
    def compare_versions(requirement, current)
210 222
      requirement = requirement.split('.').collect(&:to_i)
211 223
      requirement <=> current.slice(0, requirement.size)
test/unit/lib/redmine/plugin_test.rb
133 133
    assert_raise Redmine::PluginRequirementError do
134 134
      plugin.requires_redmine(:version_or_higher => '2.2')
135 135
    end
136

  
137
    # Warn instead of failing if branch is 'devel'
138
    Redmine::VERSION.stubs(:to_a).returns([2, 1, 3, "devel", 10817])
139
    _, stderr = capture_io do
140
      plugin.requires_redmine(:version_or_higher => '2.2')
141
    end
142
    assert_match /requires Redmine/, stderr
136 143
  end
137 144

  
138 145
  def test_requires_redmine_plugin
    (1-1/1)