Move version detection to Version class
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
parent
956c1d653a
commit
5fe7fdf153
@ -161,90 +161,10 @@ class Pathname
|
|||||||
out<<`/usr/bin/du -hd0 #{to_s} | cut -d"\t" -f1`.strip
|
out<<`/usr/bin/du -hd0 #{to_s} | cut -d"\t" -f1`.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
# attempts to retrieve the version component of this path, so generally
|
|
||||||
# you'll call it on tarballs or extracted tarball directories, if you add
|
|
||||||
# to this please provide amend the unittest
|
|
||||||
def version
|
def version
|
||||||
if directory?
|
require 'version'
|
||||||
# directories don't have extnames
|
version = Version.parse(self)
|
||||||
stem=basename.to_s
|
version.to_s unless version.nil?
|
||||||
else
|
|
||||||
# sourceforge /download
|
|
||||||
if %r[((?:sourceforge.net|sf.net)/.*)/download$].match to_s
|
|
||||||
stem=Pathname.new(dirname).stem
|
|
||||||
else
|
|
||||||
stem=self.stem
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# github tarballs, like v1.2.3
|
|
||||||
%r[github.com/.*/(zip|tar)ball/v?((\d+\.)+\d+)$].match to_s
|
|
||||||
return $2 if $2
|
|
||||||
|
|
||||||
# eg. https://github.com/sam-github/libnet/tarball/libnet-1.1.4
|
|
||||||
%r[github.com/.*/(zip|tar)ball/.*-((\d+\.)+\d+)$].match to_s
|
|
||||||
return $2 if $2
|
|
||||||
|
|
||||||
# dashed version
|
|
||||||
# eg. github.com/isaacs/npm/tarball/v0.2.5-1
|
|
||||||
%r[github.com/.*/(zip|tar)ball/v?((\d+\.)+\d+-(\d+))$].match to_s
|
|
||||||
return $2 if $2
|
|
||||||
|
|
||||||
# underscore version
|
|
||||||
# eg. github.com/petdance/ack/tarball/1.93_02
|
|
||||||
%r[github.com/.*/(zip|tar)ball/v?((\d+\.)+\d+_(\d+))$].match to_s
|
|
||||||
return $2 if $2
|
|
||||||
|
|
||||||
# eg. boost_1_39_0
|
|
||||||
/((\d+_)+\d+)$/.match stem
|
|
||||||
return $1.gsub('_', '.') if $1
|
|
||||||
|
|
||||||
# eg. foobar-4.5.1-1
|
|
||||||
# eg. ruby-1.9.1-p243
|
|
||||||
/-((\d+\.)*\d\.\d+-(p|rc|RC)?\d+)$/.match stem
|
|
||||||
return $1 if $1
|
|
||||||
|
|
||||||
# eg. lame-398-1
|
|
||||||
/-((\d)+-\d)/.match stem
|
|
||||||
return $1 if $1
|
|
||||||
|
|
||||||
# eg. foobar-4.5.1
|
|
||||||
/-((\d+\.)*\d+)$/.match stem
|
|
||||||
return $1 if $1
|
|
||||||
|
|
||||||
# eg. foobar-4.5.1b
|
|
||||||
/-((\d+\.)*\d+([abc]|rc|RC)\d*)$/.match stem
|
|
||||||
return $1 if $1
|
|
||||||
|
|
||||||
# eg foobar-4.5.0-beta1, or foobar-4.50-beta
|
|
||||||
/-((\d+\.)*\d+-beta(\d+)?)$/.match stem
|
|
||||||
return $1 if $1
|
|
||||||
|
|
||||||
# eg. foobar4.5.1
|
|
||||||
unless /^erlang-/.match basename
|
|
||||||
/((\d+\.)*\d+)$/.match stem
|
|
||||||
return $1 if $1
|
|
||||||
end
|
|
||||||
|
|
||||||
# eg foobar-4.5.0-bin
|
|
||||||
/-((\d+\.)+\d+[abc]?)[-._](bin|dist|stable|src|sources?)$/.match stem
|
|
||||||
return $1 if $1
|
|
||||||
|
|
||||||
# Debian style eg dash_0.5.5.1.orig.tar.gz
|
|
||||||
/_((\d+\.)+\d+[abc]?)[.]orig$/.match stem
|
|
||||||
return $1 if $1
|
|
||||||
|
|
||||||
# eg. otp_src_R13B (this is erlang's style)
|
|
||||||
# eg. astyle_1.23_macosx.tar.gz
|
|
||||||
stem.scan(/_([^_]+)/) do |match|
|
|
||||||
return match.first if /\d/.match $1
|
|
||||||
end
|
|
||||||
|
|
||||||
# old erlang bottle style e.g. erlang-R14B03-bottle.tar.gz
|
|
||||||
/-([^-]+)/.match stem
|
|
||||||
return $1 if $1
|
|
||||||
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def compression_type
|
def compression_type
|
||||||
|
@ -5,7 +5,7 @@ require 'version'
|
|||||||
|
|
||||||
module VersionAssertions
|
module VersionAssertions
|
||||||
def assert_version url, version
|
def assert_version url, version
|
||||||
assert_equal version, Version.parse(url)
|
assert_equal version, Version.parse(url).to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_version_nil url
|
def assert_version_nil url
|
||||||
|
@ -3,7 +3,7 @@ class Version
|
|||||||
|
|
||||||
def initialize val
|
def initialize val
|
||||||
return val if val.is_a? Version or val.nil?
|
return val if val.is_a? Version or val.nil?
|
||||||
@version = val.to_s.strip
|
@version = val.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def head?
|
def head?
|
||||||
@ -38,6 +38,86 @@ class Version
|
|||||||
alias_method :to_str, :to_s
|
alias_method :to_str, :to_s
|
||||||
|
|
||||||
def self.parse spec
|
def self.parse spec
|
||||||
Pathname.new(spec.to_s).version
|
version = _parse(spec)
|
||||||
|
Version.new(version) unless version.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def self._parse spec
|
||||||
|
spec = Pathname.new(spec) unless spec.is_a? Pathname
|
||||||
|
|
||||||
|
stem = if spec.directory?
|
||||||
|
spec.basename.to_s
|
||||||
|
elsif %r[((?:sourceforge.net|sf.net)/.*)/download$].match(spec.to_s)
|
||||||
|
Pathname.new(spec.dirname).stem
|
||||||
|
else
|
||||||
|
spec.stem
|
||||||
|
end
|
||||||
|
|
||||||
|
# GitHub tarballs, e.g. v1.2.3
|
||||||
|
m = %r[github.com/.+/(?:zip|tar)ball/v?((\d+\.)+\d+)$].match(spec.to_s)
|
||||||
|
return m.captures.first unless m.nil?
|
||||||
|
|
||||||
|
# e.g. https://github.com/sam-github/libnet/tarball/libnet-1.1.4
|
||||||
|
m = %r[github.com/.+/(?:zip|tar)ball/.*-((\d+\.)+\d+)$].match(spec.to_s)
|
||||||
|
return m.captures.first unless m.nil?
|
||||||
|
|
||||||
|
# e.g. https://github.com/isaacs/npm/tarball/v0.2.5-1
|
||||||
|
m = %r[github.com/.+/(?:zip|tar)ball/v?((\d+\.)+\d+-(\d+))$].match(spec.to_s)
|
||||||
|
return m.captures.first unless m.nil?
|
||||||
|
|
||||||
|
# e.g. https://github.com/petdance/ack/tarball/1.93_02
|
||||||
|
m = %r[github.com/.+/(?:zip|tar)ball/v?((\d+\.)+\d+_(\d+))$].match(spec.to_s)
|
||||||
|
return m.captures.first unless m.nil?
|
||||||
|
|
||||||
|
# e.g. boost_1_39_0
|
||||||
|
m = /((\d+_)+\d+)$/.match(stem)
|
||||||
|
return m.captures.first.gsub('_', '.') unless m.nil?
|
||||||
|
|
||||||
|
# e.g. foobar-4.5.1-1
|
||||||
|
# e.g. ruby-1.9.1-p243
|
||||||
|
m = /-((\d+\.)*\d\.\d+-(p|rc|RC)?\d+)$/.match(stem)
|
||||||
|
return m.captures.first unless m.nil?
|
||||||
|
|
||||||
|
# e.g. lame-398-1
|
||||||
|
m = /-((\d)+-\d)/.match(stem)
|
||||||
|
return m.captures.first unless m.nil?
|
||||||
|
|
||||||
|
# e.g. foobar-4.5.1
|
||||||
|
m = /-((\d+\.)*\d+)$/.match(stem)
|
||||||
|
return m.captures.first unless m.nil?
|
||||||
|
|
||||||
|
# e.g. foobar-4.5.1b
|
||||||
|
m = /-((\d+\.)*\d+([abc]|rc|RC)\d*)$/.match(stem)
|
||||||
|
return m.captures.first unless m.nil?
|
||||||
|
|
||||||
|
# e.g. foobar-4.5.0-beta1, or foobar-4.50-beta
|
||||||
|
m = /-((\d+\.)*\d+-beta(\d+)?)$/.match(stem)
|
||||||
|
return m.captures.first unless m.nil?
|
||||||
|
|
||||||
|
# e.g. foobar4.5.1
|
||||||
|
m = /((\d+\.)*\d+)$/.match(stem)
|
||||||
|
return m.captures.first unless m.nil?
|
||||||
|
|
||||||
|
# e.g. foobar-4.5.0-bin
|
||||||
|
m = /-((\d+\.)+\d+[abc]?)[-._](bin|dist|stable|src|sources?)$/.match(stem)
|
||||||
|
return m.captures.first unless m.nil?
|
||||||
|
|
||||||
|
# e.g. dash_0.5.5.1.orig.tar.gz (Debian style)
|
||||||
|
m = /_((\d+\.)+\d+[abc]?)[.]orig$/.match(stem)
|
||||||
|
return m.captures.first unless m.nil?
|
||||||
|
|
||||||
|
# e.g. erlang-R14B03-bottle.tar.gz (old erlang bottle style)
|
||||||
|
m = /-([^-]+)/.match(stem)
|
||||||
|
return m.captures.first unless m.nil?
|
||||||
|
|
||||||
|
# e.g. opt_src_R13B (erlang)
|
||||||
|
m = /otp_src_(.+)/.match(stem)
|
||||||
|
return m.captures.first unless m.nil?
|
||||||
|
|
||||||
|
# e.g. astyle_1.23_macosx.tar.gz
|
||||||
|
m = /_([^_]+)/.match(stem)
|
||||||
|
return m.captures.first unless m.nil?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user