fluent_command_builder 0.8.18 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fluent_command_builder.rb +2 -65
- data/lib/fluent_command_builder/command_builder.rb +2 -2
- data/lib/fluent_command_builder/command_builders/appcfg_python.rb +2 -1
- data/lib/fluent_command_builder/command_builders/appcfg_python_16.rb +5 -4
- data/lib/fluent_command_builder/command_builders/appcfg_python_17.rb +5 -4
- data/lib/fluent_command_builder/command_builders/aspnet_compiler.rb +2 -1
- data/lib/fluent_command_builder/command_builders/aspnet_compiler_20.rb +5 -4
- data/lib/fluent_command_builder/command_builders/aspnet_compiler_40.rb +5 -4
- data/lib/fluent_command_builder/command_builders/bundle.rb +2 -1
- data/lib/fluent_command_builder/command_builders/bundle_11.rb +5 -4
- data/lib/fluent_command_builder/command_builders/cucumber.rb +2 -1
- data/lib/fluent_command_builder/command_builders/cucumber_11.rb +5 -4
- data/lib/fluent_command_builder/command_builders/cucumber_12.rb +5 -4
- data/lib/fluent_command_builder/command_builders/dev_appserver_python.rb +2 -1
- data/lib/fluent_command_builder/command_builders/dev_appserver_python_16.rb +5 -4
- data/lib/fluent_command_builder/command_builders/dev_appserver_python_17.rb +5 -4
- data/lib/fluent_command_builder/command_builders/dotcover.rb +2 -1
- data/lib/fluent_command_builder/command_builders/dotcover_10.rb +5 -4
- data/lib/fluent_command_builder/command_builders/dotcover_11.rb +5 -4
- data/lib/fluent_command_builder/command_builders/dotcover_12.rb +5 -4
- data/lib/fluent_command_builder/command_builders/dotcover_20.rb +5 -4
- data/lib/fluent_command_builder/command_builders/fastlinkchecker.rb +2 -1
- data/lib/fluent_command_builder/command_builders/fastlinkchecker_21.rb +5 -4
- data/lib/fluent_command_builder/command_builders/installutil.rb +2 -1
- data/lib/fluent_command_builder/command_builders/installutil_11.rb +5 -4
- data/lib/fluent_command_builder/command_builders/installutil_20.rb +5 -4
- data/lib/fluent_command_builder/command_builders/installutil_35.rb +5 -4
- data/lib/fluent_command_builder/command_builders/installutil_40.rb +5 -4
- data/lib/fluent_command_builder/command_builders/msbuild.rb +2 -1
- data/lib/fluent_command_builder/command_builders/msbuild_20.rb +5 -4
- data/lib/fluent_command_builder/command_builders/msbuild_30.rb +5 -4
- data/lib/fluent_command_builder/command_builders/msbuild_35.rb +5 -4
- data/lib/fluent_command_builder/command_builders/msbuild_40.rb +5 -4
- data/lib/fluent_command_builder/command_builders/msdeploy.rb +2 -1
- data/lib/fluent_command_builder/command_builders/msdeploy_71.rb +5 -4
- data/lib/fluent_command_builder/command_builders/mstest.rb +2 -1
- data/lib/fluent_command_builder/command_builders/mstest_100.rb +5 -4
- data/lib/fluent_command_builder/command_builders/mstest_80.rb +5 -4
- data/lib/fluent_command_builder/command_builders/mstest_90.rb +5 -4
- data/lib/fluent_command_builder/command_builders/netsh.rb +2 -1
- data/lib/fluent_command_builder/command_builders/netsh_61.rb +5 -4
- data/lib/fluent_command_builder/command_builders/nuget.rb +2 -1
- data/lib/fluent_command_builder/command_builders/nuget_20.rb +5 -4
- data/lib/fluent_command_builder/command_builders/nunit.rb +2 -1
- data/lib/fluent_command_builder/command_builders/nunit_25.rb +5 -4
- data/lib/fluent_command_builder/command_builders/nunit_26.rb +5 -4
- data/lib/fluent_command_builder/command_builders/rake.rb +2 -1
- data/lib/fluent_command_builder/command_builders/rake_09.rb +5 -4
- data/lib/fluent_command_builder/command_builders/security_osx.rb +2 -1
- data/lib/fluent_command_builder/command_builders/security_osx_107.rb +5 -4
- data/lib/fluent_command_builder/command_builders/security_osx_108.rb +5 -4
- data/lib/fluent_command_builder/command_builders/sevenzip.rb +2 -1
- data/lib/fluent_command_builder/command_builders/sevenzip_920.rb +5 -4
- data/lib/fluent_command_builder/command_builders/simian.rb +2 -1
- data/lib/fluent_command_builder/command_builders/simian_23.rb +5 -4
- data/lib/fluent_command_builder/command_builders/team_foundation.rb +2 -1
- data/lib/fluent_command_builder/command_builders/team_foundation_100.rb +5 -4
- data/lib/fluent_command_builder/command_builders/team_foundation_tee.rb +2 -1
- data/lib/fluent_command_builder/command_builders/team_foundation_tee_100.rb +5 -4
- data/lib/fluent_command_builder/command_builders/team_foundation_tee_101.rb +5 -4
- data/lib/fluent_command_builder/command_builders/xcodebuild.rb +2 -1
- data/lib/fluent_command_builder/command_builders/xcodebuild_43.rb +5 -4
- data/lib/fluent_command_builder/command_builders/xcodebuild_44.rb +5 -4
- data/lib/fluent_command_builder/command_builders/xcodebuild_45.rb +331 -0
- data/lib/fluent_command_builder/execution_context.rb +2 -4
- data/lib/fluent_command_builder/{argument_formatter.rb → internal/argument_formatter.rb} +8 -6
- data/lib/fluent_command_builder/{command_base.rb → internal/command_base.rb} +0 -0
- data/lib/fluent_command_builder/internal/command_builder_config.rb +57 -0
- data/lib/fluent_command_builder/{path_finder.rb → internal/path_finder.rb} +19 -19
- data/lib/fluent_command_builder/{path_finders → internal/path_finders}/unix_path_finder.rb +12 -12
- data/lib/fluent_command_builder/{path_finders → internal/path_finders}/windows_path_finder.rb +13 -13
- data/lib/fluent_command_builder/internal/path_validator.rb +54 -0
- data/lib/fluent_command_builder/{printer.rb → internal/printer.rb} +5 -5
- data/lib/fluent_command_builder/{underlying_builder.rb → internal/underlying_builder.rb} +12 -6
- data/lib/fluent_command_builder/{version.rb → internal/version.rb} +12 -17
- data/lib/fluent_command_builder/internal/version_detectors.rb +1 -0
- data/lib/fluent_command_builder/{version_detectors → internal/version_detectors}/appengine_python_version_detector.rb +1 -0
- data/lib/fluent_command_builder/{version_detectors → internal/version_detectors}/default_version_detector.rb +1 -0
- data/lib/fluent_command_builder/{version_detectors → internal/version_detectors}/osx_version_detector.rb +0 -0
- data/lib/fluent_command_builder/{version_detectors → internal/version_detectors}/standard_version_detector.rb +9 -6
- data/lib/fluent_command_builder/{version_detectors → internal/version_detectors}/windows_version_detector.rb +0 -0
- data/lib/fluent_command_builder/{version_validator.rb → internal/version_validator.rb} +26 -23
- data/lib/fluent_command_builder/password_formatter.rb +22 -0
- metadata +25 -24
- data/lib/fluent_command_builder/command_builder_config.rb +0 -51
- data/lib/fluent_command_builder/command_formatters/hidden_password_formatter.rb +0 -17
- data/lib/fluent_command_builder/command_formatters/null_formatter.rb +0 -9
- data/lib/fluent_command_builder/path_validator.rb +0 -27
@@ -1,15 +1,13 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/printer')
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/internal/printer')
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/command_executors/system_executor')
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/command_formatters/null_formatter')
|
4
3
|
|
5
4
|
module FluentCommandBuilder
|
6
5
|
class ExecutionContext
|
7
6
|
|
8
|
-
attr_accessor :executor, :
|
7
|
+
attr_accessor :executor, :printer, :should_print_on_execute, :should_fail_on_error
|
9
8
|
|
10
9
|
def initialize(executor)
|
11
10
|
@executor = executor
|
12
|
-
@formatter = NullFormatter.new
|
13
11
|
@should_print_on_execute = true
|
14
12
|
@should_fail_on_error = true
|
15
13
|
@printer = FluentCommandBuilder::Printer.new
|
@@ -16,6 +16,14 @@ module FluentCommandBuilder
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
def format_password(value)
|
20
|
+
password = quote_if_includes_space value.to_s
|
21
|
+
@passwords << password
|
22
|
+
password
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
19
27
|
def format_hash(hash, delimiter, key_value_separator)
|
20
28
|
hash.map { |k, v| quote_if_includes_space(k.to_s) + key_value_separator + quote_if_includes_space(v.to_s) }.join delimiter
|
21
29
|
end
|
@@ -24,12 +32,6 @@ module FluentCommandBuilder
|
|
24
32
|
array.map { |v| quote_if_includes_space v }.join delimiter
|
25
33
|
end
|
26
34
|
|
27
|
-
def format_password(value)
|
28
|
-
password = quote_if_includes_space value.to_s
|
29
|
-
@passwords << password
|
30
|
-
password
|
31
|
-
end
|
32
|
-
|
33
35
|
def quote_if_includes_space(value)
|
34
36
|
value.to_s.include?(' ') ? %Q["#{value}"] : value
|
35
37
|
end
|
File without changes
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/path_validator')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/version_validator')
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/version_detectors/default_version_detector')
|
4
|
+
|
5
|
+
module FluentCommandBuilder
|
6
|
+
class CommandBuilderConfig
|
7
|
+
|
8
|
+
attr_accessor :path, :command_name, :version, :version_detector,
|
9
|
+
:path_validation_level, :version_validation_level,
|
10
|
+
:path_validator, :version_validator,
|
11
|
+
:is_windows
|
12
|
+
|
13
|
+
def initialize(command_name, version=nil)
|
14
|
+
@path = nil
|
15
|
+
@command_name = command_name
|
16
|
+
@version = version
|
17
|
+
@version_detector = DefaultVersionDetector.new command_name
|
18
|
+
@path_validation_level = :fatal
|
19
|
+
@version_validation_level = :fatal
|
20
|
+
@path_validator = PathValidator.new self
|
21
|
+
@version_validator = VersionValidator.new self
|
22
|
+
@is_windows = !ENV['WINDIR'].nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def validate_path
|
26
|
+
@path_validator.validate
|
27
|
+
end
|
28
|
+
|
29
|
+
def validate_version
|
30
|
+
@version_validator.validate if @version
|
31
|
+
end
|
32
|
+
|
33
|
+
def executable
|
34
|
+
e = @path ? File.join(@path, @command_name) : @command_name
|
35
|
+
normalise_path e
|
36
|
+
end
|
37
|
+
|
38
|
+
def evaluated_executable
|
39
|
+
evaluate_path executable
|
40
|
+
end
|
41
|
+
|
42
|
+
def evaluated_path
|
43
|
+
evaluate_path @path if @path
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def evaluate_path(path)
|
49
|
+
`echo #{normalise_path path}`.strip
|
50
|
+
end
|
51
|
+
|
52
|
+
def normalise_path(path)
|
53
|
+
@is_windows ? path.gsub('/', '\\') : path.gsub('\\', '/')
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -1,20 +1,20 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/path_finders/unix_path_finder')
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/path_finders/windows_path_finder')
|
3
|
-
|
4
|
-
module FluentCommandBuilder
|
5
|
-
|
6
|
-
def self.path_finder
|
7
|
-
@path_finder ||= is_windows? ? WindowsPathFinder.new : UnixPathFinder.new
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.path_finder=(value)
|
11
|
-
@path_finder = value
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def self.is_windows?
|
17
|
-
!ENV['WINDIR'].nil?
|
18
|
-
end
|
19
|
-
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/path_finders/unix_path_finder')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/path_finders/windows_path_finder')
|
3
|
+
|
4
|
+
module FluentCommandBuilder
|
5
|
+
|
6
|
+
def self.path_finder
|
7
|
+
@path_finder ||= is_windows? ? WindowsPathFinder.new : UnixPathFinder.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.path_finder=(value)
|
11
|
+
@path_finder = value
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.is_windows?
|
17
|
+
!ENV['WINDIR'].nil?
|
18
|
+
end
|
19
|
+
|
20
20
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
module FluentCommandBuilder
|
2
|
-
class UnixPathFinder
|
3
|
-
|
4
|
-
def find_path(executable_name)
|
5
|
-
executable = `which #{executable_name}`
|
6
|
-
real_executable = `readlink #{executable}`.strip
|
7
|
-
result = real_executable == '' ? executable : real_executable
|
8
|
-
return unless result
|
9
|
-
File.dirname result
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
1
|
+
module FluentCommandBuilder
|
2
|
+
class UnixPathFinder
|
3
|
+
|
4
|
+
def find_path(executable_name)
|
5
|
+
executable = `which #{executable_name}`
|
6
|
+
real_executable = `readlink #{executable}`.strip
|
7
|
+
result = real_executable == '' ? executable : real_executable
|
8
|
+
return unless result
|
9
|
+
File.dirname result
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
13
|
end
|
data/lib/fluent_command_builder/{path_finders → internal/path_finders}/windows_path_finder.rb
RENAMED
@@ -1,14 +1,14 @@
|
|
1
|
-
module FluentCommandBuilder
|
2
|
-
class WindowsPathFinder
|
3
|
-
|
4
|
-
def find_path(executable_name)
|
5
|
-
paths = ENV['PATH'].split ';'
|
6
|
-
extensions = ENV['PATHEXT'].split ';'
|
7
|
-
possibilities = paths.map { |path| extensions.map { |ext| File.join(path, executable_name + ext.downcase).gsub('/', '\\') } }.flatten
|
8
|
-
executable = possibilities.select { |exe| File.exist? exe }.first
|
9
|
-
return unless executable
|
10
|
-
File.dirname executable
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
1
|
+
module FluentCommandBuilder
|
2
|
+
class WindowsPathFinder
|
3
|
+
|
4
|
+
def find_path(executable_name)
|
5
|
+
paths = ENV['PATH'].split ';'
|
6
|
+
extensions = ENV['PATHEXT'].split ';'
|
7
|
+
possibilities = paths.map { |path| extensions.map { |ext| File.join(path, executable_name + ext.downcase).gsub('/', '\\') } }.flatten
|
8
|
+
executable = possibilities.select { |exe| File.exist? exe }.first
|
9
|
+
return unless executable
|
10
|
+
File.dirname executable
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
14
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/printer')
|
2
|
+
|
3
|
+
module FluentCommandBuilder
|
4
|
+
class PathValidator
|
5
|
+
|
6
|
+
attr_accessor :path_finder, :printer, :should_abort_on_fatal
|
7
|
+
|
8
|
+
def initialize(command_builder_config)
|
9
|
+
@c = command_builder_config
|
10
|
+
@path_finder = FluentCommandBuilder.path_finder
|
11
|
+
@printer = Printer.new
|
12
|
+
@should_abort_on_fatal = true
|
13
|
+
end
|
14
|
+
|
15
|
+
def validate
|
16
|
+
validate_validation_level
|
17
|
+
return if validation_level == :off
|
18
|
+
|
19
|
+
if @c.path
|
20
|
+
path = @c.evaluated_path
|
21
|
+
return if File.exist? path
|
22
|
+
message = %Q[Path for command "#{@c.command_name}", version "#{@c.version}" does not exist. Path: #{path}]
|
23
|
+
else
|
24
|
+
return if @path_finder.find_path @c.command_name
|
25
|
+
message = %Q[Command "#{@c.command_name}" was not found on the PATH.]
|
26
|
+
end
|
27
|
+
|
28
|
+
case validation_level
|
29
|
+
when :warn
|
30
|
+
@printer.print_warning message
|
31
|
+
when :fatal
|
32
|
+
@printer.print_error message
|
33
|
+
abort if @should_abort_on_fatal
|
34
|
+
else
|
35
|
+
# do nothing
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def validation_level
|
42
|
+
@c.path_validation_level
|
43
|
+
end
|
44
|
+
|
45
|
+
def validate_validation_level
|
46
|
+
raise %Q[Validation level "#{validation_level}" is not supported.] unless validation_level_valid?
|
47
|
+
end
|
48
|
+
|
49
|
+
def validation_level_valid?
|
50
|
+
[:off, :warn, :fatal].include? validation_level
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -5,18 +5,18 @@ module FluentCommandBuilder
|
|
5
5
|
include Term::ANSIColor
|
6
6
|
|
7
7
|
def print_warning(message)
|
8
|
-
print yellow, '
|
9
|
-
|
8
|
+
$stderr.print yellow, 'Warning: ', message, reset, "\n"
|
9
|
+
$stderr.flush
|
10
10
|
end
|
11
11
|
|
12
12
|
def print_error(message)
|
13
|
-
print red, '
|
14
|
-
|
13
|
+
$stderr.print red, 'Error: ', message, reset, "\n"
|
14
|
+
$stderr.flush
|
15
15
|
end
|
16
16
|
|
17
17
|
def print_command(command)
|
18
18
|
print magenta, command, reset, "\n"
|
19
|
-
|
19
|
+
$stdout.flush
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
@@ -1,16 +1,18 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/argument_formatter')
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../execution_context')
|
3
3
|
|
4
4
|
module FluentCommandBuilder
|
5
5
|
class UnderlyingBuilder
|
6
6
|
include ArgumentFormatter
|
7
7
|
|
8
8
|
attr_reader :args, :passwords
|
9
|
+
attr_accessor :password_formatter, :execution_context
|
9
10
|
|
10
11
|
def initialize(command_builder_config)
|
11
12
|
@c = command_builder_config
|
12
13
|
@args = nil
|
13
14
|
@passwords = []
|
15
|
+
@password_formatter = FluentCommandBuilder.password_formatter
|
14
16
|
@execution_context = FluentCommandBuilder.execution_context
|
15
17
|
end
|
16
18
|
|
@@ -21,19 +23,23 @@ module FluentCommandBuilder
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def executable
|
24
|
-
@c.
|
26
|
+
@c.executable
|
25
27
|
end
|
26
28
|
|
27
29
|
def execute
|
28
|
-
@c.validate_path
|
30
|
+
@c.validate_path
|
29
31
|
@c.validate_version
|
30
|
-
visible_command = @execution_context.formatter.format self
|
31
32
|
@execution_context.execute to_s, visible_command
|
32
33
|
end
|
33
34
|
|
34
35
|
def to_s
|
35
|
-
|
36
|
-
|
36
|
+
"#{quote_if_includes_space @c.evaluated_executable} #{@args}".strip
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def visible_command
|
42
|
+
@password_formatter.format to_s, @passwords
|
37
43
|
end
|
38
44
|
|
39
45
|
end
|
@@ -2,7 +2,7 @@ module FluentCommandBuilder
|
|
2
2
|
class Version
|
3
3
|
|
4
4
|
VERSION_REGEX = '(?:\d+\.)+(?:\d+)'
|
5
|
-
|
5
|
+
DELIMITER = '.'
|
6
6
|
|
7
7
|
attr_accessor :version
|
8
8
|
|
@@ -12,20 +12,19 @@ module FluentCommandBuilder
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def compact
|
15
|
-
|
15
|
+
first 2, ''
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
18
|
+
def first(count, delimiter=DELIMITER)
|
19
|
+
to_a.first(count).join(delimiter)
|
20
|
+
end
|
21
21
|
|
22
|
-
def
|
23
|
-
@version
|
22
|
+
def to_s
|
23
|
+
@version
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
|
28
|
-
version.scan(exp)[0] != nil
|
26
|
+
def to_a
|
27
|
+
@version.split DELIMITER
|
29
28
|
end
|
30
29
|
|
31
30
|
def self.match(value)
|
@@ -35,15 +34,11 @@ module FluentCommandBuilder
|
|
35
34
|
Version.new(version)
|
36
35
|
end
|
37
36
|
|
38
|
-
def self.version_or_nil(version)
|
39
|
-
return unless version
|
40
|
-
is_valid?(version) ? Version.new(version) : nil
|
41
|
-
end
|
42
|
-
|
43
37
|
private
|
44
38
|
|
45
|
-
def
|
46
|
-
|
39
|
+
def self.is_valid?(version)
|
40
|
+
exp = Regexp.new "^#{VERSION_REGEX}$"
|
41
|
+
version.scan(exp)[0] != nil
|
47
42
|
end
|
48
43
|
|
49
44
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.expand_path(File.dirname(__FILE__) + '/version_detectors/*.rb')].each { |f| require f }
|
File without changes
|
@@ -1,5 +1,6 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../path_finder')
|
1
2
|
require File.expand_path(File.dirname(__FILE__) + '/../version')
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../command_executors/backticks_executor')
|
3
4
|
|
4
5
|
module FluentCommandBuilder
|
5
6
|
class StandardVersionDetector
|
@@ -15,11 +16,13 @@ module FluentCommandBuilder
|
|
15
16
|
def version(path=nil)
|
16
17
|
path ||= FluentCommandBuilder.path_finder.find_path @command_name
|
17
18
|
return unless path
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
return unless File.exist? path
|
20
|
+
Dir.chdir path do
|
21
|
+
command = %Q["#{@command_name}" #{@command_arg} 2>&1]
|
22
|
+
output = @backticks_executor.execute command
|
23
|
+
v = Version.match(output)
|
24
|
+
v ? v.version : nil
|
25
|
+
end
|
23
26
|
end
|
24
27
|
|
25
28
|
end
|
File without changes
|
@@ -3,15 +3,19 @@ require File.expand_path(File.dirname(__FILE__) + '/printer')
|
|
3
3
|
module FluentCommandBuilder
|
4
4
|
class VersionValidator
|
5
5
|
|
6
|
+
attr_accessor :printer, :should_abort_on_fatal
|
7
|
+
|
6
8
|
def initialize(command_builder_config)
|
7
|
-
@
|
9
|
+
@c = command_builder_config
|
8
10
|
@printer = Printer.new
|
11
|
+
@should_abort_on_fatal = true
|
9
12
|
end
|
10
13
|
|
11
|
-
def validate
|
14
|
+
def validate
|
15
|
+
validate_validation_level
|
12
16
|
return if validation_level == :off
|
13
17
|
|
14
|
-
@actual_version_string = version_detector.version(
|
18
|
+
@actual_version_string = @c.version_detector.version(@c.evaluated_path)
|
15
19
|
|
16
20
|
unless actual_version
|
17
21
|
@printer.print_warning error_message('unable to determine actual version')
|
@@ -19,52 +23,51 @@ module FluentCommandBuilder
|
|
19
23
|
end
|
20
24
|
|
21
25
|
unless is_valid?
|
22
|
-
message = error_message actual_version.
|
26
|
+
message = error_message actual_version.first(expected_version.to_a.length)
|
23
27
|
|
24
28
|
case validation_level
|
25
29
|
when :warn
|
26
30
|
@printer.print_warning message
|
27
31
|
when :fatal
|
28
32
|
@printer.print_error message
|
29
|
-
abort
|
33
|
+
abort if @should_abort_on_fatal
|
30
34
|
else
|
31
|
-
|
35
|
+
# do nothing
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
36
40
|
private
|
37
41
|
|
38
|
-
def
|
39
|
-
|
42
|
+
def validation_level
|
43
|
+
@c.version_validation_level
|
40
44
|
end
|
41
45
|
|
42
|
-
def
|
43
|
-
|
46
|
+
def validate_validation_level
|
47
|
+
raise %Q[Validation level "#{validation_level}" is not supported.] unless validation_level_valid?
|
44
48
|
end
|
45
49
|
|
46
|
-
def
|
47
|
-
|
50
|
+
def validation_level_valid?
|
51
|
+
[:off, :warn, :fatal].include? validation_level
|
48
52
|
end
|
49
53
|
|
50
|
-
def error_message(actual_version)
|
51
|
-
%Q[Version validation for command "#{command_name}" failed. Expected version #{expected_version} but was #{actual_version}.]
|
52
|
-
end
|
53
54
|
|
54
|
-
|
55
|
-
|
55
|
+
|
56
|
+
|
57
|
+
def is_valid?
|
58
|
+
actual_version.to_a.first(expected_version.to_a.length) == expected_version.to_a
|
56
59
|
end
|
57
60
|
|
58
|
-
def
|
59
|
-
@
|
61
|
+
def expected_version
|
62
|
+
@expected_version ||= Version.new(@c.version)
|
60
63
|
end
|
61
64
|
|
62
|
-
def
|
63
|
-
@
|
65
|
+
def actual_version
|
66
|
+
@actual_version ||= Version.new(@actual_version_string) if @actual_version_string
|
64
67
|
end
|
65
68
|
|
66
|
-
def
|
67
|
-
@
|
69
|
+
def error_message(actual_version)
|
70
|
+
%Q[Version validation for command "#{@c.command_name}" failed. Expected version #{expected_version} but was #{actual_version}.]
|
68
71
|
end
|
69
72
|
|
70
73
|
end
|