pdk 1.16.0 → 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/lib/pdk.rb +25 -18
- data/lib/pdk/answer_file.rb +2 -93
- data/lib/pdk/cli.rb +1 -5
- data/lib/pdk/cli/config.rb +3 -1
- data/lib/pdk/cli/config/get.rb +3 -1
- data/lib/pdk/cli/convert.rb +1 -1
- data/lib/pdk/cli/exec/command.rb +13 -0
- data/lib/pdk/cli/exec_group.rb +78 -43
- data/lib/pdk/cli/get.rb +20 -0
- data/lib/pdk/cli/get/config.rb +24 -0
- data/lib/pdk/cli/util.rb +6 -3
- data/lib/pdk/cli/validate.rb +26 -44
- data/lib/pdk/config.rb +178 -4
- data/lib/pdk/config/ini_file.rb +183 -0
- data/lib/pdk/config/ini_file_setting.rb +39 -0
- data/lib/pdk/config/namespace.rb +25 -5
- data/lib/pdk/config/setting.rb +3 -2
- data/lib/pdk/context.rb +96 -0
- data/lib/pdk/context/control_repo.rb +60 -0
- data/lib/pdk/context/module.rb +28 -0
- data/lib/pdk/context/none.rb +22 -0
- data/lib/pdk/control_repo.rb +40 -0
- data/lib/pdk/generate/module.rb +8 -12
- data/lib/pdk/module/release.rb +2 -8
- data/lib/pdk/util.rb +35 -5
- data/lib/pdk/util/bundler.rb +1 -0
- data/lib/pdk/util/changelog_generator.rb +6 -1
- data/lib/pdk/util/template_uri.rb +4 -3
- data/lib/pdk/validate.rb +72 -25
- data/lib/pdk/validate/external_command_validator.rb +208 -0
- data/lib/pdk/validate/internal_ruby_validator.rb +100 -0
- data/lib/pdk/validate/invokable_validator.rb +216 -0
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -0
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -0
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -0
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -0
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -0
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -0
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -0
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -0
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -0
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -0
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -0
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -0
- data/lib/pdk/validate/validator.rb +111 -0
- data/lib/pdk/validate/validator_group.rb +103 -0
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -0
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -0
- data/lib/pdk/version.rb +1 -1
- data/locales/pdk.pot +161 -125
- metadata +29 -17
- data/lib/pdk/validate/base_validator.rb +0 -215
- data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -82
- data/lib/pdk/validate/metadata/metadata_syntax.rb +0 -111
- data/lib/pdk/validate/metadata_validator.rb +0 -26
- data/lib/pdk/validate/puppet/puppet_epp.rb +0 -135
- data/lib/pdk/validate/puppet/puppet_lint.rb +0 -64
- data/lib/pdk/validate/puppet/puppet_syntax.rb +0 -135
- data/lib/pdk/validate/puppet_validator.rb +0 -26
- data/lib/pdk/validate/ruby/rubocop.rb +0 -72
- data/lib/pdk/validate/ruby_validator.rb +0 -26
- data/lib/pdk/validate/tasks/metadata_lint.rb +0 -130
- data/lib/pdk/validate/tasks/name.rb +0 -90
- data/lib/pdk/validate/tasks_validator.rb +0 -29
- data/lib/pdk/validate/yaml/syntax.rb +0 -125
- data/lib/pdk/validate/yaml_validator.rb +0 -28
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -299,6 +299,8 @@ files:
|
|
299
299
|
- lib/pdk/cli/exec/command.rb
|
300
300
|
- lib/pdk/cli/exec/interactive_command.rb
|
301
301
|
- lib/pdk/cli/exec_group.rb
|
302
|
+
- lib/pdk/cli/get.rb
|
303
|
+
- lib/pdk/cli/get/config.rb
|
302
304
|
- lib/pdk/cli/module.rb
|
303
305
|
- lib/pdk/cli/module/build.rb
|
304
306
|
- lib/pdk/cli/module/generate.rb
|
@@ -326,6 +328,8 @@ files:
|
|
326
328
|
- lib/pdk/config.rb
|
327
329
|
- lib/pdk/config/analytics_schema.json
|
328
330
|
- lib/pdk/config/errors.rb
|
331
|
+
- lib/pdk/config/ini_file.rb
|
332
|
+
- lib/pdk/config/ini_file_setting.rb
|
329
333
|
- lib/pdk/config/json.rb
|
330
334
|
- lib/pdk/config/json_schema_namespace.rb
|
331
335
|
- lib/pdk/config/json_schema_setting.rb
|
@@ -335,6 +339,10 @@ files:
|
|
335
339
|
- lib/pdk/config/validator.rb
|
336
340
|
- lib/pdk/config/yaml.rb
|
337
341
|
- lib/pdk/config/yaml_with_schema.rb
|
342
|
+
- lib/pdk/context.rb
|
343
|
+
- lib/pdk/context/control_repo.rb
|
344
|
+
- lib/pdk/context/module.rb
|
345
|
+
- lib/pdk/context/none.rb
|
338
346
|
- lib/pdk/control_repo.rb
|
339
347
|
- lib/pdk/generate.rb
|
340
348
|
- lib/pdk/generate/defined_type.rb
|
@@ -379,21 +387,25 @@ files:
|
|
379
387
|
- lib/pdk/util/windows/process.rb
|
380
388
|
- lib/pdk/util/windows/string.rb
|
381
389
|
- lib/pdk/validate.rb
|
382
|
-
- lib/pdk/validate/
|
383
|
-
- lib/pdk/validate/
|
384
|
-
- lib/pdk/validate/
|
385
|
-
- lib/pdk/validate/
|
386
|
-
- lib/pdk/validate/
|
387
|
-
- lib/pdk/validate/
|
388
|
-
- lib/pdk/validate/puppet/
|
389
|
-
- lib/pdk/validate/
|
390
|
-
- lib/pdk/validate/
|
391
|
-
- lib/pdk/validate/
|
392
|
-
- lib/pdk/validate/
|
393
|
-
- lib/pdk/validate/
|
394
|
-
- lib/pdk/validate/
|
395
|
-
- lib/pdk/validate/
|
396
|
-
- lib/pdk/validate/
|
390
|
+
- lib/pdk/validate/external_command_validator.rb
|
391
|
+
- lib/pdk/validate/internal_ruby_validator.rb
|
392
|
+
- lib/pdk/validate/invokable_validator.rb
|
393
|
+
- lib/pdk/validate/metadata/metadata_json_lint_validator.rb
|
394
|
+
- lib/pdk/validate/metadata/metadata_syntax_validator.rb
|
395
|
+
- lib/pdk/validate/metadata/metadata_validator_group.rb
|
396
|
+
- lib/pdk/validate/puppet/puppet_epp_validator.rb
|
397
|
+
- lib/pdk/validate/puppet/puppet_lint_validator.rb
|
398
|
+
- lib/pdk/validate/puppet/puppet_syntax_validator.rb
|
399
|
+
- lib/pdk/validate/puppet/puppet_validator_group.rb
|
400
|
+
- lib/pdk/validate/ruby/ruby_rubocop_validator.rb
|
401
|
+
- lib/pdk/validate/ruby/ruby_validator_group.rb
|
402
|
+
- lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb
|
403
|
+
- lib/pdk/validate/tasks/tasks_name_validator.rb
|
404
|
+
- lib/pdk/validate/tasks/tasks_validator_group.rb
|
405
|
+
- lib/pdk/validate/validator.rb
|
406
|
+
- lib/pdk/validate/validator_group.rb
|
407
|
+
- lib/pdk/validate/yaml/yaml_syntax_validator.rb
|
408
|
+
- lib/pdk/validate/yaml/yaml_validator_group.rb
|
397
409
|
- lib/pdk/version.rb
|
398
410
|
- locales/config.yaml
|
399
411
|
- locales/pdk.pot
|
@@ -1,215 +0,0 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
|
3
|
-
module PDK
|
4
|
-
module Validate
|
5
|
-
class BaseValidator
|
6
|
-
# Controls how many times the validator is invoked.
|
7
|
-
#
|
8
|
-
# :once - The validator will be invoked once and passed all the
|
9
|
-
# targets.
|
10
|
-
# :per_target - The validator will be invoked for each target
|
11
|
-
# separately.
|
12
|
-
INVOKE_STYLE = :once
|
13
|
-
|
14
|
-
# Controls how the validator behaves if not passed any targets.
|
15
|
-
#
|
16
|
-
# true - PDK will not pass the globbed targets to the validator command
|
17
|
-
# and it will instead rely on the underlying tool to find its
|
18
|
-
# own default targets.
|
19
|
-
# false - PDK will pass the globbed targets to the validator command.
|
20
|
-
ALLOW_EMPTY_TARGETS = false
|
21
|
-
|
22
|
-
IGNORE_DOTFILES = true
|
23
|
-
|
24
|
-
def self.cmd_path
|
25
|
-
File.join(PDK::Util.module_root, 'bin', cmd)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Parses the target strings provided from the CLI
|
29
|
-
#
|
30
|
-
# @param options [Hash] A Hash containing the input options from the CLI.
|
31
|
-
#
|
32
|
-
# @return targets [Array] An Array of Strings containing target file paths
|
33
|
-
# for the validator to validate.
|
34
|
-
# @return skipped [Array] An Array of Strings containing targets
|
35
|
-
# that are skipped due to target not containing
|
36
|
-
# any files that can be validated by the validator.
|
37
|
-
# @return invalid [Array] An Array of Strings containing targets that do
|
38
|
-
# not exist, and will not be run by validator.
|
39
|
-
def self.parse_targets(options)
|
40
|
-
# If no targets are specified, then we will run validations from the
|
41
|
-
# base module directory.
|
42
|
-
|
43
|
-
targets = options.fetch(:targets, []).empty? ? [PDK::Util.module_root] : options[:targets]
|
44
|
-
|
45
|
-
targets.map! { |r| r.gsub(File::ALT_SEPARATOR, File::SEPARATOR) } if File::ALT_SEPARATOR
|
46
|
-
skipped = []
|
47
|
-
invalid = []
|
48
|
-
matched = targets.map { |target|
|
49
|
-
if respond_to?(:pattern)
|
50
|
-
if PDK::Util::Filesystem.directory?(target)
|
51
|
-
target_root = PDK::Util.module_root
|
52
|
-
pattern_glob = Array(pattern).map { |p| PDK::Util::Filesystem.glob(File.join(target_root, p), File::FNM_DOTMATCH) }
|
53
|
-
target_list = pattern_glob.flatten
|
54
|
-
.select { |glob| PDK::Util::Filesystem.fnmatch(File.join(PDK::Util::Filesystem.expand_path(PDK::Util.canonical_path(target)), '*'), glob, File::FNM_DOTMATCH) }
|
55
|
-
.map { |glob| Pathname.new(glob).relative_path_from(Pathname.new(PDK::Util.module_root)).to_s }
|
56
|
-
|
57
|
-
ignore_list = ignore_pathspec
|
58
|
-
target_list = target_list.reject { |file| ignore_list.match(file) }
|
59
|
-
|
60
|
-
skipped << target if target_list.flatten.empty?
|
61
|
-
target_list
|
62
|
-
elsif PDK::Util::Filesystem.file?(target)
|
63
|
-
if Array(pattern).include? target
|
64
|
-
target
|
65
|
-
elsif Array(pattern).any? { |p| PDK::Util::Filesystem.fnmatch(PDK::Util::Filesystem.expand_path(p), PDK::Util::Filesystem.expand_path(target), File::FNM_DOTMATCH) }
|
66
|
-
target
|
67
|
-
else
|
68
|
-
skipped << target
|
69
|
-
next
|
70
|
-
end
|
71
|
-
else
|
72
|
-
invalid << target
|
73
|
-
next
|
74
|
-
end
|
75
|
-
else
|
76
|
-
target
|
77
|
-
end
|
78
|
-
}.compact.flatten
|
79
|
-
[matched, skipped, invalid]
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.ignore_pathspec
|
83
|
-
require 'pdk/module'
|
84
|
-
|
85
|
-
ignore_pathspec = PDK::Module.default_ignored_pathspec(ignore_dotfiles?)
|
86
|
-
|
87
|
-
if respond_to?(:pattern_ignore)
|
88
|
-
Array(pattern_ignore).each do |pattern|
|
89
|
-
ignore_pathspec.add(pattern)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
ignore_pathspec
|
94
|
-
end
|
95
|
-
|
96
|
-
def self.ignore_dotfiles?
|
97
|
-
self::IGNORE_DOTFILES
|
98
|
-
end
|
99
|
-
|
100
|
-
def self.parse_options(_options, targets)
|
101
|
-
targets
|
102
|
-
end
|
103
|
-
|
104
|
-
def self.spinner_text(_targets = nil)
|
105
|
-
_('Invoking %{cmd}') % { cmd: cmd }
|
106
|
-
end
|
107
|
-
|
108
|
-
def self.process_skipped(report, skipped = [])
|
109
|
-
skipped.each do |skipped_target|
|
110
|
-
PDK.logger.debug(_('%{validator}: Skipped \'%{target}\'. Target does not contain any files to validate (%{pattern}).') % { validator: name, target: skipped_target, pattern: pattern })
|
111
|
-
report.add_event(
|
112
|
-
file: skipped_target,
|
113
|
-
source: name,
|
114
|
-
message: _('Target does not contain any files to validate (%{pattern}).') % { pattern: pattern },
|
115
|
-
severity: :info,
|
116
|
-
state: :skipped,
|
117
|
-
)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def self.process_invalid(report, invalid = [])
|
122
|
-
invalid.each do |invalid_target|
|
123
|
-
PDK.logger.debug(_('%{validator}: Skipped \'%{target}\'. Target file not found.') % { validator: name, target: invalid_target })
|
124
|
-
report.add_event(
|
125
|
-
file: invalid_target,
|
126
|
-
source: name,
|
127
|
-
message: _('File does not exist.'),
|
128
|
-
severity: :error,
|
129
|
-
state: :error,
|
130
|
-
)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def self.allow_empty_targets?
|
135
|
-
self::ALLOW_EMPTY_TARGETS == true
|
136
|
-
end
|
137
|
-
|
138
|
-
def self.invoke(report, options = {})
|
139
|
-
require 'pdk/cli/exec/command'
|
140
|
-
|
141
|
-
targets, skipped, invalid = parse_targets(options)
|
142
|
-
|
143
|
-
process_skipped(report, skipped)
|
144
|
-
process_invalid(report, invalid)
|
145
|
-
|
146
|
-
return 0 if targets.empty?
|
147
|
-
|
148
|
-
PDK::Util::Bundler.ensure_binstubs!(cmd)
|
149
|
-
|
150
|
-
# If invoking :per_target, split the targets array into an array of
|
151
|
-
# single element arrays (one per target). If invoking :once, wrap the
|
152
|
-
# targets array in another array. This is so we can loop through the
|
153
|
-
# invokes with the same logic, regardless of which invoke style is
|
154
|
-
# needed.
|
155
|
-
#
|
156
|
-
if self::INVOKE_STYLE == :per_target
|
157
|
-
targets = targets.combination(1).to_a
|
158
|
-
else
|
159
|
-
require 'pdk/cli/exec_group'
|
160
|
-
targets = targets.each_slice(1000).to_a
|
161
|
-
options[:split_exec] = PDK::CLI::ExecGroup.new(spinner_text(targets), parallel: false)
|
162
|
-
end
|
163
|
-
|
164
|
-
if options.fetch(:targets, []).empty? && allow_empty_targets?
|
165
|
-
targets = [[]]
|
166
|
-
end
|
167
|
-
|
168
|
-
exit_codes = []
|
169
|
-
|
170
|
-
targets.each do |invokation_targets|
|
171
|
-
cmd_argv = parse_options(options, invokation_targets).unshift(cmd_path).compact
|
172
|
-
cmd_argv.unshift(File.join(PDK::Util::RubyVersion.bin_path, 'ruby.exe'), '-W0') if Gem.win_platform?
|
173
|
-
|
174
|
-
command = PDK::CLI::Exec::Command.new(*cmd_argv).tap do |c|
|
175
|
-
c.context = :module
|
176
|
-
c.environment = { 'PUPPET_GEM_VERSION' => options[:puppet] } if options[:puppet]
|
177
|
-
unless options[:split_exec]
|
178
|
-
exec_group = options[:exec_group]
|
179
|
-
if exec_group
|
180
|
-
sub_spinner = exec_group.add_spinner(spinner_text(invokation_targets))
|
181
|
-
c.register_spinner(sub_spinner)
|
182
|
-
else
|
183
|
-
c.add_spinner(spinner_text(invokation_targets))
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
if options[:split_exec]
|
189
|
-
options[:split_exec].register do
|
190
|
-
result = command.execute!
|
191
|
-
|
192
|
-
begin
|
193
|
-
parse_output(report, result, invokation_targets.compact)
|
194
|
-
rescue PDK::Validate::ParseOutputError => e
|
195
|
-
$stderr.puts e.message
|
196
|
-
end
|
197
|
-
result[:exit_code]
|
198
|
-
end
|
199
|
-
else
|
200
|
-
result = command.execute!
|
201
|
-
exit_codes << result[:exit_code]
|
202
|
-
|
203
|
-
begin
|
204
|
-
parse_output(report, result, invokation_targets.compact)
|
205
|
-
rescue PDK::Validate::ParseOutputError => e
|
206
|
-
$stderr.puts e.message
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
options.key?(:split_exec) ? options[:split_exec].exit_code : exit_codes.max
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
|
3
|
-
module PDK
|
4
|
-
module Validate
|
5
|
-
class MetadataJSONLint < BaseValidator
|
6
|
-
# Validate each metadata file separately, as metadata-json-lint does not
|
7
|
-
# support multiple targets.
|
8
|
-
INVOKE_STYLE = :per_target
|
9
|
-
|
10
|
-
def self.name
|
11
|
-
'metadata-json-lint'
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.cmd
|
15
|
-
'metadata-json-lint'
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.spinner_text(targets = [])
|
19
|
-
_('Checking module metadata style (%{targets}).') % {
|
20
|
-
targets: PDK::Util.targets_relative_to_pwd(targets).join(' '),
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.pattern
|
25
|
-
'metadata.json'
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.parse_options(_options, targets)
|
29
|
-
cmd_options = ['--format', 'json']
|
30
|
-
cmd_options << '--strict-dependencies'
|
31
|
-
|
32
|
-
cmd_options.concat(targets)
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.parse_output(report, result, targets)
|
36
|
-
raise ArgumentError, _('More than 1 target provided to PDK::Validate::MetadataJSONLint.') if targets.count > 1
|
37
|
-
|
38
|
-
if result[:stdout].strip.empty?
|
39
|
-
# metadata-json-lint will print nothing if there are no problems with
|
40
|
-
# the file being linted. This should be handled separately to
|
41
|
-
# metadata-json-lint generating output that can not be parsed as JSON
|
42
|
-
# (unhandled exception in metadata-json-lint).
|
43
|
-
json_data = {}
|
44
|
-
else
|
45
|
-
begin
|
46
|
-
json_data = JSON.parse(result[:stdout])
|
47
|
-
rescue JSON::ParserError
|
48
|
-
raise PDK::Validate::ParseOutputError, result[:stdout]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
if json_data.empty?
|
53
|
-
report.add_event(
|
54
|
-
file: targets.first,
|
55
|
-
source: name,
|
56
|
-
state: :passed,
|
57
|
-
severity: :ok,
|
58
|
-
)
|
59
|
-
else
|
60
|
-
json_data.delete('result')
|
61
|
-
json_data.keys.each do |type|
|
62
|
-
json_data[type].each do |offense|
|
63
|
-
# metadata-json-lint groups the offenses by type, so the type ends
|
64
|
-
# up being `warnings` or `errors`. We want to convert that to the
|
65
|
-
# singular noun for the event.
|
66
|
-
event_type = type[%r{\A(.+?)s?\Z}, 1]
|
67
|
-
|
68
|
-
report.add_event(
|
69
|
-
file: targets.first,
|
70
|
-
source: name,
|
71
|
-
message: offense['msg'],
|
72
|
-
test: offense['check'],
|
73
|
-
severity: event_type,
|
74
|
-
state: :failure,
|
75
|
-
)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
|
3
|
-
module PDK
|
4
|
-
module Validate
|
5
|
-
class MetadataSyntax < BaseValidator
|
6
|
-
def self.name
|
7
|
-
'metadata-syntax'
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.pattern
|
11
|
-
['metadata.json', 'tasks/*.json']
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.spinner_text(_targets = [])
|
15
|
-
_('Checking metadata syntax (%{targets}).') % {
|
16
|
-
targets: pattern.join(' '),
|
17
|
-
}
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.create_spinner(targets = [], options = {})
|
21
|
-
require 'pdk/cli/util'
|
22
|
-
|
23
|
-
return unless PDK::CLI::Util.interactive?
|
24
|
-
|
25
|
-
options = options.merge(PDK::CLI::Util.spinner_opts_for_platform)
|
26
|
-
|
27
|
-
exec_group = options[:exec_group]
|
28
|
-
@spinner = if exec_group
|
29
|
-
exec_group.add_spinner(spinner_text(targets), options)
|
30
|
-
else
|
31
|
-
require 'pdk/cli/util/spinner'
|
32
|
-
|
33
|
-
TTY::Spinner.new("[:spinner] #{spinner_text(targets)}", options)
|
34
|
-
end
|
35
|
-
@spinner.auto_spin
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.stop_spinner(exit_code)
|
39
|
-
if exit_code.zero? && @spinner
|
40
|
-
@spinner.success
|
41
|
-
elsif @spinner
|
42
|
-
@spinner.error
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.invoke(report, options = {})
|
47
|
-
targets, skipped, invalid = parse_targets(options)
|
48
|
-
|
49
|
-
process_skipped(report, skipped)
|
50
|
-
process_invalid(report, invalid)
|
51
|
-
|
52
|
-
return 0 if targets.empty?
|
53
|
-
|
54
|
-
return_val = 0
|
55
|
-
create_spinner(targets, options)
|
56
|
-
|
57
|
-
# The pure ruby JSON parser gives much nicer parse error messages than
|
58
|
-
# the C extension at the cost of slightly slower parsing. We require it
|
59
|
-
# here and restore the C extension at the end of the method (if it was
|
60
|
-
# being used).
|
61
|
-
require 'json/pure'
|
62
|
-
JSON.parser = JSON::Pure::Parser
|
63
|
-
|
64
|
-
targets.each do |target|
|
65
|
-
unless PDK::Util::Filesystem.readable?(target)
|
66
|
-
report.add_event(
|
67
|
-
file: target,
|
68
|
-
source: name,
|
69
|
-
state: :failure,
|
70
|
-
severity: 'error',
|
71
|
-
message: _('Could not be read.'),
|
72
|
-
)
|
73
|
-
return_val = 1
|
74
|
-
next
|
75
|
-
end
|
76
|
-
|
77
|
-
begin
|
78
|
-
JSON.parse(PDK::Util::Filesystem.read_file(target))
|
79
|
-
|
80
|
-
report.add_event(
|
81
|
-
file: target,
|
82
|
-
source: name,
|
83
|
-
state: :passed,
|
84
|
-
severity: 'ok',
|
85
|
-
)
|
86
|
-
rescue JSON::ParserError => e
|
87
|
-
# Because the message contains a raw segment of the file, we use
|
88
|
-
# String#dump here to unescape any escape characters like newlines.
|
89
|
-
# We then strip out the surrounding quotes and the exclaimation
|
90
|
-
# point that json_pure likes to put in exception messages.
|
91
|
-
sane_message = e.message.dump[%r{\A"(.+?)!?"\Z}, 1]
|
92
|
-
|
93
|
-
report.add_event(
|
94
|
-
file: target,
|
95
|
-
source: name,
|
96
|
-
state: :failure,
|
97
|
-
severity: 'error',
|
98
|
-
message: sane_message,
|
99
|
-
)
|
100
|
-
return_val = 1
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
stop_spinner(return_val)
|
105
|
-
return_val
|
106
|
-
ensure
|
107
|
-
JSON.parser = JSON::Ext::Parser if defined?(JSON::Ext::Parser)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|