class Jars::MavenVersion
def convert(arg, low = nil, high = nil)
def convert(arg, low = nil, high = nil) if arg.include?('~>') val = arg.sub(/~>\s*/, '') last = val.include?('.') ? val.sub(/\.[0-9]*[a-z]+.*$/, '').sub(/\.[^.]+$/, '.99999') : '99999' ["[#{snapshot_version(val)}", "#{snapshot_version(last)}]"] elsif arg.include?('>=') val = arg.sub(/>=\s*/, '') ["[#{snapshot_version(val)}", (nil || high)] elsif arg.include?('<=') val = arg.sub(/<=\s*/, '') [(nil || low), "#{snapshot_version(val)}]"] # treat '!' the same way as '>' since maven can not describe such range elsif /[!>]/.match?(arg) val = arg.sub(/[!>]\s*/, '') ["(#{snapshot_version(val)}", (nil || high)] elsif arg.include?('<') val = arg.sub(/<\s*/, '') [(nil || low), "#{snapshot_version(val)})"] elsif arg.include?('=') val = arg.sub(/=\s*/, '') # for prereleased version pick the maven version (no version range) if /[a-z]|[A-Z]/.match?(val) [val, val] else ["[#{val}", "#{val}.0.0.0.0.1)"] end else # no conversion here, i.e. assume maven version [arg, arg] end end
def new(*args)
def new(*args) if args.empty? || (args.size == 1 && args[0].nil?) nil else low, high = convert(args[0]) low, high = convert(args[1], low, high) if /[=~><]/.match?(args[1]) if low == high low else super "#{low || '[0'},#{high || ')'}" end end end
def snapshot_version(val)
def snapshot_version(val) if val.match(/[a-z]|[A-Z]/) && !val.match(/-SNAPSHOT|[${}]/) "#{val}-SNAPSHOT" else val end end