getversion 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/getversion.rb ADDED
@@ -0,0 +1,2 @@
1
+ require_relative '../lib/getversion'
2
+ puts GetVersion[ARGV[0]]
@@ -0,0 +1,13 @@
1
+ module GetVersion
2
+
3
+ namespace :apple
4
+
5
+ executable 'security' do
6
+ osx_version
7
+ end
8
+
9
+ executable 'xcodebuild' do
10
+ find_version_in_output @exe, '-version'
11
+ end
12
+
13
+ end
@@ -0,0 +1,15 @@
1
+ require 'yaml'
2
+
3
+ module GetVersion
4
+
5
+ namespace :google
6
+
7
+ executable 'appcfg.py' do
8
+ google_appengine_version @exe
9
+ end
10
+
11
+ executable 'dev_appserver.py' do
12
+ google_appengine_version @exe
13
+ end
14
+
15
+ end
@@ -0,0 +1,9 @@
1
+ module GetVersion
2
+
3
+ namespace :jetbrains
4
+
5
+ executable 'dotcover' do
6
+ find_version_in_output @exe
7
+ end
8
+
9
+ end
@@ -0,0 +1,37 @@
1
+ module GetVersion
2
+
3
+ namespace :microsoft
4
+
5
+ executable 'aspnet_compiler' do
6
+ GetVersion['msbuild']
7
+ end
8
+
9
+ executable 'installutil' do
10
+ find_version_in_output @exe
11
+ end
12
+
13
+ executable 'msbuild' do
14
+ find_version_in_output @exe, '/version'
15
+ end
16
+
17
+ executable 'msdeploy' do
18
+ find_version_in_output @exe
19
+ end
20
+
21
+ executable 'mstest' do
22
+ find_version_in_output @exe, '/help'
23
+ end
24
+
25
+ executable 'netsh' do
26
+ windows_version
27
+ end
28
+
29
+ executable 'nuget' do
30
+ find_version_in_output @exe
31
+ end
32
+
33
+ executable 'tf' do
34
+ find_version_in_output @exe
35
+ end
36
+
37
+ end
@@ -0,0 +1,17 @@
1
+ module GetVersion
2
+
3
+ namespace :rubygems
4
+
5
+ executable 'bundle' do
6
+ find_version_in_output @exe, '--version'
7
+ end
8
+
9
+ executable 'cucumber' do
10
+ find_version_in_output @exe, '--version'
11
+ end
12
+
13
+ executable 'rake' do
14
+ find_version_in_output @exe, '--version'
15
+ end
16
+
17
+ end
@@ -0,0 +1,19 @@
1
+ module GetVersion
2
+
3
+ executable 'conlinkchecker' do
4
+ find_version_in_output @exe
5
+ end
6
+
7
+ executable 'nunit' do
8
+ find_version_in_output @exe, '/help'
9
+ end
10
+
11
+ executable '7z' do
12
+ find_version_in_output @exe
13
+ end
14
+
15
+ executable '7za' do
16
+ find_version_in_output @exe
17
+ end
18
+
19
+ end
@@ -0,0 +1 @@
1
+ Dir[File.dirname(__FILE__) + '/detectors/*.rb'].each { |f| require f }
@@ -0,0 +1,25 @@
1
+ require_relative 'version'
2
+
3
+ module GetVersion
4
+
5
+ def self.find_version_in_output(executable, args=nil)
6
+ output = `"#{executable}" #{args} 2>&1`
7
+ v = Version.match output
8
+ v ? v.version : nil
9
+ end
10
+
11
+ def self.google_appengine_version(executable)
12
+ path = File.dirname executable
13
+ version_file = File.join path, 'VERSION'
14
+ YAML::load_file(version_file)['release']
15
+ end
16
+
17
+ def self.osx_version
18
+ find_version_in_output 'sw_vers', '-productVersion'
19
+ end
20
+
21
+ def self.windows_version
22
+ find_version_in_output 'ver'
23
+ end
24
+
25
+ end
@@ -0,0 +1,25 @@
1
+ class Path
2
+
3
+ attr_accessor :path, :is_windows
4
+
5
+ def initialize(*path)
6
+ path.select! { |p| p unless p == '' }
7
+ @path = File.join path
8
+ @is_windows = !ENV['WINDIR'].nil?
9
+ end
10
+
11
+ def evaluated_path
12
+ return unless @path
13
+ `echo #{normalised_path}`.strip
14
+ end
15
+
16
+ def normalised_path
17
+ return unless @path
18
+ @is_windows ? @path.gsub('/', '\\') : @path.gsub('\\', '/')
19
+ end
20
+
21
+ def to_s
22
+ evaluated_path
23
+ end
24
+
25
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'path_finders/unix_path_finder'
2
+ require_relative 'path_finders/windows_path_finder'
3
+
4
+ class PathFinder
5
+
6
+ def self.find_path(executable_name)
7
+ path_finder = is_windows? ? WindowsPathFinder.new : UnixPathFinder.new
8
+ path_finder.find_path executable_name
9
+ end
10
+
11
+ private
12
+
13
+ def self.is_windows?
14
+ !ENV['WINDIR'].nil?
15
+ end
16
+
17
+ end
@@ -0,0 +1,11 @@
1
+ class UnixPathFinder
2
+
3
+ def find_path(executable_name)
4
+ executable = `which #{executable_name}`
5
+ real_executable = `readlink #{executable}`.strip
6
+ result = real_executable == '' ? executable : real_executable
7
+ return if result.to_s == ''
8
+ File.dirname result
9
+ end
10
+
11
+ end
@@ -0,0 +1,12 @@
1
+ class WindowsPathFinder
2
+
3
+ def find_path(executable_name)
4
+ paths = ENV['PATH'].split ';'
5
+ extensions = ENV['PATHEXT'].split ';'
6
+ possibilities = paths.map { |path| extensions.map { |ext| File.join(path, executable_name + ext.downcase).gsub('/', '\\') } }.flatten
7
+ executable = possibilities.select { |exe| File.exist? exe }.first
8
+ return unless executable
9
+ File.dirname executable
10
+ end
11
+
12
+ end
@@ -0,0 +1,43 @@
1
+ class Version
2
+
3
+ VERSION_REGEX = '(?:\d+\.)+(?:\d+)'
4
+ DELIMITER = '.'
5
+
6
+ attr_accessor :version
7
+
8
+ def initialize(version)
9
+ raise "#{version} is not a valid version." unless Version.is_valid? version
10
+ @version = version
11
+ end
12
+
13
+ def compact
14
+ first 2, ''
15
+ end
16
+
17
+ def first(count, delimiter=DELIMITER)
18
+ to_a.first(count).join(delimiter)
19
+ end
20
+
21
+ def to_s
22
+ @version
23
+ end
24
+
25
+ def to_a
26
+ @version.split DELIMITER
27
+ end
28
+
29
+ def self.match(value)
30
+ exp = Regexp.new VERSION_REGEX
31
+ version = value.scan(exp)[0]
32
+ return unless version
33
+ Version.new(version)
34
+ end
35
+
36
+ private
37
+
38
+ def self.is_valid?(version)
39
+ exp = Regexp.new "^#{VERSION_REGEX}$"
40
+ version.scan(exp)[0] != nil
41
+ end
42
+
43
+ end
data/lib/getversion.rb ADDED
@@ -0,0 +1,30 @@
1
+ require_relative 'getversion/path_finder'
2
+ require_relative 'getversion/path'
3
+ require_relative 'getversion/helpers'
4
+
5
+ module GetVersion
6
+
7
+ @executables = []
8
+
9
+ def self.[](name)
10
+ executable = @executables.find { |e| e[:name] == name }
11
+ path = PathFinder.find_path name
12
+ path = nil if path == '.'
13
+ @exe = path ? Path.new(path, name).evaluated_path : name
14
+ instance_eval &executable[:block]
15
+ end
16
+
17
+ private
18
+
19
+ def self.namespace(namespace)
20
+ @namespace = namespace
21
+ yield if block_given?
22
+ end
23
+
24
+ def self.executable(name, &block)
25
+ @executables << {name: name, namespace: @namespace, block: block}
26
+ end
27
+
28
+ end
29
+
30
+ require_relative 'getversion/detectors'
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: getversion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matthew Riley
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-20 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Provides a standard interface for obtaining CLI application version numbers.
15
+ email: matthew@matthewriley.name
16
+ executables:
17
+ - getversion.rb
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/getversion/detectors/apple.rb
22
+ - lib/getversion/detectors/google.rb
23
+ - lib/getversion/detectors/jetbrains.rb
24
+ - lib/getversion/detectors/microsoft.rb
25
+ - lib/getversion/detectors/rubygems.rb
26
+ - lib/getversion/detectors/uncategorised.rb
27
+ - lib/getversion/detectors.rb
28
+ - lib/getversion/helpers.rb
29
+ - lib/getversion/path.rb
30
+ - lib/getversion/path_finder.rb
31
+ - lib/getversion/path_finders/unix_path_finder.rb
32
+ - lib/getversion/path_finders/windows_path_finder.rb
33
+ - lib/getversion/version.rb
34
+ - lib/getversion.rb
35
+ - !binary |-
36
+ YmluL2dldHZlcnNpb24ucmI=
37
+ homepage: http://rubygems.org/gems/getversion
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 1.8.15
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: Provides a standard interface for obtaining CLI application version numbers.
61
+ test_files: []