bosh_common 1.2583.0 → 1.2596.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/common/version/bosh_version.rb +22 -0
- data/lib/common/version/release_version.rb +35 -0
- data/lib/common/version/release_version_list.rb +34 -0
- data/lib/common/version/semi_semantic_version.rb +62 -0
- data/lib/common/version/stemcell_version.rb +22 -0
- data/lib/common/version/version_list.rb +45 -0
- data/lib/common/version.rb +1 -1
- metadata +10 -5
- data/lib/common/version_number.rb +0 -37
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'common/version/semi_semantic_version'
|
2
|
+
|
3
|
+
module Bosh::Common::Version
|
4
|
+
class BoshVersion < SemiSemanticVersion
|
5
|
+
|
6
|
+
def self.parse(version)
|
7
|
+
raise ArgumentError, 'Invalid Version: nil' if version.nil?
|
8
|
+
version = version.to_s
|
9
|
+
|
10
|
+
#discard anything after a space, including the space, to support compound bosh versions
|
11
|
+
version = version.split(' ', 2)[0] if version =~ / /
|
12
|
+
|
13
|
+
self.new(SemiSemantic::Version.parse(version))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def default_post_release_segment
|
19
|
+
raise NotImplementedError, 'Bosh post-release versions unsupported'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'common/version/semi_semantic_version'
|
2
|
+
|
3
|
+
module Bosh::Common::Version
|
4
|
+
class ReleaseVersion < SemiSemanticVersion
|
5
|
+
|
6
|
+
DEFAULT_POST_RELEASE_SEGMENT = SemiSemantic::VersionSegment.parse('dev.1')
|
7
|
+
|
8
|
+
def self.parse(version)
|
9
|
+
raise ArgumentError, 'Invalid Version: nil' if version.nil?
|
10
|
+
version = version.to_s
|
11
|
+
|
12
|
+
#convert old-style dev version suffix to new dev post-release segment
|
13
|
+
matches = /\A(?<release>.*)(\.(?<dev>[0-9]+)-dev)\z/.match(version)
|
14
|
+
unless matches.nil?
|
15
|
+
version = matches[:release] + "+dev." + matches[:dev]
|
16
|
+
end
|
17
|
+
|
18
|
+
self.new(SemiSemantic::Version.parse(version))
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_old_format
|
22
|
+
matches = /\A(?<release>.*)(\+dev\.(?<dev>[0-9]+))\z/.match(to_s)
|
23
|
+
if matches.nil?
|
24
|
+
return nil
|
25
|
+
end
|
26
|
+
matches[:release] + '.' + matches[:dev] + "-dev"
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def default_post_release_segment
|
32
|
+
DEFAULT_POST_RELEASE_SEGMENT
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'semi_semantic/version'
|
2
|
+
require 'common/version/release_version'
|
3
|
+
|
4
|
+
module Bosh::Common::Version
|
5
|
+
class ReleaseVersionList < VersionList
|
6
|
+
|
7
|
+
# @param [Array<#version>] Collection of version strings
|
8
|
+
# @param [class] Version type to parse as (ex: SemiSemantic::Version, ReleaseVersion, StemcellVersion, BoshVersion)
|
9
|
+
def self.parse(versions)
|
10
|
+
self.new(VersionList.parse(versions, ReleaseVersion))
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param [#version] ReleaseVersion from which to rebase the post-release segment
|
14
|
+
def rebase(version)
|
15
|
+
raise TypeError, "Failed to Rebase - Invalid Version Type: #{version.class}" unless version.is_a?(ReleaseVersion)
|
16
|
+
|
17
|
+
# Can only rebase versions with a post-release segment
|
18
|
+
if version.version.post_release.nil?
|
19
|
+
raise ArgumentError, "Failed to Rebase - Invalid Version: #{version.inspect}"
|
20
|
+
end
|
21
|
+
|
22
|
+
latest = latest_with_pre_release(version)
|
23
|
+
if latest
|
24
|
+
if latest.version.post_release.nil?
|
25
|
+
latest.default_post_release
|
26
|
+
else
|
27
|
+
latest.increment_post_release
|
28
|
+
end
|
29
|
+
else
|
30
|
+
version.default_post_release
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'semi_semantic/version'
|
2
|
+
require 'common/version/version_list'
|
3
|
+
|
4
|
+
module Bosh::Common::Version
|
5
|
+
class UnavailableMethodError < StandardError; end
|
6
|
+
|
7
|
+
class SemiSemanticVersion
|
8
|
+
include Comparable
|
9
|
+
|
10
|
+
DEFAULT_POST_RELEASE_SEGMENT = SemiSemantic::VersionSegment.parse('build.1')
|
11
|
+
|
12
|
+
attr_reader :version
|
13
|
+
|
14
|
+
def self.parse(version)
|
15
|
+
raise ArgumentError, 'Invalid Version: nil' if version.nil?
|
16
|
+
version = version.to_s
|
17
|
+
|
18
|
+
self.new(SemiSemantic::Version.parse(version))
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.parse_list(versions)
|
22
|
+
VersionList.parse(versions, self)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.parse_and_compare(a, b)
|
26
|
+
self.parse(a) <=> self.parse(b)
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(version)
|
30
|
+
raise ArgumentError, "Invalid Version Type: #{version.class}" unless version.is_a?(SemiSemantic::Version)
|
31
|
+
@version = version
|
32
|
+
@version.freeze
|
33
|
+
end
|
34
|
+
|
35
|
+
def default_post_release
|
36
|
+
self.class.new(SemiSemantic::Version.new(@version.release, @version.pre_release, default_post_release_segment))
|
37
|
+
end
|
38
|
+
|
39
|
+
def increment_post_release
|
40
|
+
raise UnavailableMethodError, 'Failed to increment: post-release is nil' if @version.post_release.nil?
|
41
|
+
self.class.new(SemiSemantic::Version.new(@version.release, @version.pre_release, @version.post_release.increment))
|
42
|
+
end
|
43
|
+
|
44
|
+
def increment_release
|
45
|
+
self.class.new(SemiSemantic::Version.new(@version.release.increment))
|
46
|
+
end
|
47
|
+
|
48
|
+
def <=>(other)
|
49
|
+
@version <=> other.version
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
@version.to_s
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def default_post_release_segment
|
59
|
+
DEFAULT_POST_RELEASE_SEGMENT
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'common/version/semi_semantic_version'
|
2
|
+
|
3
|
+
module Bosh::Common::Version
|
4
|
+
class StemcellVersion < SemiSemanticVersion
|
5
|
+
|
6
|
+
def self.parse(version)
|
7
|
+
raise ArgumentError, 'Invalid Version: nil' if version.nil?
|
8
|
+
version = version.to_s
|
9
|
+
|
10
|
+
#replace underscores with periods to maintain reverse compatibility with stemcell versions
|
11
|
+
version = version.gsub('_', '.')
|
12
|
+
|
13
|
+
self.new(SemiSemantic::Version.parse(version))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def default_post_release_segment
|
19
|
+
raise NotImplementedError, 'Stemcell post-release versions unsupported'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'semi_semantic/version'
|
2
|
+
|
3
|
+
module Bosh::Common::Version
|
4
|
+
class VersionList
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
attr_reader :versions
|
8
|
+
|
9
|
+
alias :latest :max
|
10
|
+
|
11
|
+
# @param [Array<#version>] Collection of version strings
|
12
|
+
# @param [class] Version type to parse as (ex: SemiSemanticVersion, ReleaseVersion, StemcellVersion, BoshVersion)
|
13
|
+
def self.parse(versions, version_type)
|
14
|
+
raise TypeError, "Failed to Parse - Invalid Version Type: '#{version_type.inspect}'" unless version_type <= SemiSemanticVersion
|
15
|
+
self.new(versions.map { |v| version_type.parse(v) })
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param [Array<#version>] Collection of SemiSemanticVersion objects
|
19
|
+
def initialize(versions)
|
20
|
+
@versions = versions
|
21
|
+
end
|
22
|
+
|
23
|
+
# Gets the latest version with the same release and pre-release version as the specified version
|
24
|
+
# @param [#version] SemiSemanticVersion object
|
25
|
+
def latest_with_pre_release(version)
|
26
|
+
raise TypeError, "Invalid Version Type: #{version.class}" unless version.kind_of?(SemiSemanticVersion)
|
27
|
+
@versions.select { |v|
|
28
|
+
v.version.release == version.version.release && v.version.pre_release == version.version.pre_release
|
29
|
+
}.max
|
30
|
+
end
|
31
|
+
|
32
|
+
# Gets the latest version with the same release version as the specified version
|
33
|
+
# @param [#version] SemiSemanticVersion object
|
34
|
+
def latest_with_release(version)
|
35
|
+
raise TypeError, "Invalid Version Type: #{version.class}" unless version.kind_of?(SemiSemanticVersion)
|
36
|
+
@versions.select { |v|
|
37
|
+
v.version.release == version.version.release
|
38
|
+
}.max
|
39
|
+
end
|
40
|
+
|
41
|
+
def each(&block)
|
42
|
+
@versions.each(&block)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/common/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bosh_common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2596.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-06-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: semi_semantic
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 1.1.0
|
30
30
|
description: ! 'BOSH common
|
31
31
|
|
32
|
-
|
32
|
+
3c1470'
|
33
33
|
email: support@cloudfoundry.com
|
34
34
|
executables: []
|
35
35
|
extensions: []
|
@@ -50,7 +50,12 @@ files:
|
|
50
50
|
- lib/common/thread_formatter.rb
|
51
51
|
- lib/common/thread_pool.rb
|
52
52
|
- lib/common/version.rb
|
53
|
-
- lib/common/
|
53
|
+
- lib/common/version/bosh_version.rb
|
54
|
+
- lib/common/version/release_version.rb
|
55
|
+
- lib/common/version/release_version_list.rb
|
56
|
+
- lib/common/version/semi_semantic_version.rb
|
57
|
+
- lib/common/version/stemcell_version.rb
|
58
|
+
- lib/common/version/version_list.rb
|
54
59
|
- README
|
55
60
|
homepage: https://github.com/cloudfoundry/bosh
|
56
61
|
licenses:
|
@@ -73,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
78
|
version: '0'
|
74
79
|
segments:
|
75
80
|
- 0
|
76
|
-
hash:
|
81
|
+
hash: -2801231138931334462
|
77
82
|
requirements: []
|
78
83
|
rubyforge_project:
|
79
84
|
rubygems_version: 1.8.23.2
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'semi_semantic/version'
|
2
|
-
|
3
|
-
module Bosh::Common
|
4
|
-
class VersionNumber
|
5
|
-
DEFAULT_DEV_RELEASE_SEGMENT = SemiSemantic::VersionSegment.parse('dev.1')
|
6
|
-
|
7
|
-
def self.parse(version)
|
8
|
-
raise ArgumentError, 'Invalid Version: nil' if version.nil?
|
9
|
-
#raise ArgumentError, "Invalid Version Type: #{version.class}" if version.is_a?(String)
|
10
|
-
version = version.to_s
|
11
|
-
|
12
|
-
#discard anything after a space, including the space, to support compound bosh versions
|
13
|
-
version = version.split(' ', 2)[0] if version =~ / /
|
14
|
-
|
15
|
-
#convert old-style dev version suffix to new dev post-release segment
|
16
|
-
matches = /\A(?<release>.*)(\.(?<dev>[0-9]+)-dev)\z/.match(version)
|
17
|
-
unless matches.nil?
|
18
|
-
version = matches[:release] + "+dev." + matches[:dev]
|
19
|
-
end
|
20
|
-
|
21
|
-
#replace underscores with periods to maintain reverse compatibility with stemcell versions
|
22
|
-
version = version.gsub('_', '.')
|
23
|
-
|
24
|
-
SemiSemantic::Version.parse(version)
|
25
|
-
end
|
26
|
-
|
27
|
-
# @param [Array<#version>] Collection of version strings
|
28
|
-
def self.parse_list(versions)
|
29
|
-
versions.map { |v| self.parse(v) }
|
30
|
-
end
|
31
|
-
|
32
|
-
# @param [Array<#version>] Collection of version strings
|
33
|
-
def self.latest(versions)
|
34
|
-
versions.max
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|