pdk-akerl 1.9.1.1 → 1.14.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +180 -0
  3. data/README.md +43 -4
  4. data/lib/pdk.rb +4 -2
  5. data/lib/pdk/analytics.rb +44 -0
  6. data/lib/pdk/analytics/client/google_analytics.rb +141 -0
  7. data/lib/pdk/analytics/client/noop.rb +23 -0
  8. data/lib/pdk/analytics/util.rb +17 -0
  9. data/lib/pdk/answer_file.rb +4 -1
  10. data/lib/pdk/cli.rb +50 -3
  11. data/lib/pdk/cli/build.rb +10 -4
  12. data/lib/pdk/cli/bundle.rb +10 -8
  13. data/lib/pdk/cli/config.rb +20 -0
  14. data/lib/pdk/cli/config/get.rb +24 -0
  15. data/lib/pdk/cli/console.rb +148 -0
  16. data/lib/pdk/cli/convert.rb +7 -2
  17. data/lib/pdk/cli/exec.rb +22 -190
  18. data/lib/pdk/cli/exec/command.rb +238 -0
  19. data/lib/pdk/cli/exec/interactive_command.rb +114 -0
  20. data/lib/pdk/cli/exec_group.rb +6 -6
  21. data/lib/pdk/cli/module/build.rb +0 -2
  22. data/lib/pdk/cli/module/generate.rb +4 -2
  23. data/lib/pdk/cli/new.rb +2 -0
  24. data/lib/pdk/cli/new/class.rb +2 -2
  25. data/lib/pdk/cli/new/defined_type.rb +4 -2
  26. data/lib/pdk/cli/new/module.rb +5 -0
  27. data/lib/pdk/cli/new/provider.rb +4 -2
  28. data/lib/pdk/cli/new/task.rb +4 -1
  29. data/lib/pdk/cli/new/test.rb +53 -0
  30. data/lib/pdk/cli/new/transport.rb +27 -0
  31. data/lib/pdk/cli/test.rb +0 -1
  32. data/lib/pdk/cli/test/unit.rb +18 -13
  33. data/lib/pdk/cli/update.rb +25 -3
  34. data/lib/pdk/cli/util.rb +111 -14
  35. data/lib/pdk/cli/util/interview.rb +10 -2
  36. data/lib/pdk/cli/util/option_validator.rb +4 -0
  37. data/lib/pdk/cli/util/spinner.rb +13 -0
  38. data/lib/pdk/cli/validate.rb +16 -5
  39. data/lib/pdk/config.rb +121 -0
  40. data/lib/pdk/config/analytics_schema.json +26 -0
  41. data/lib/pdk/config/errors.rb +5 -0
  42. data/lib/pdk/config/json.rb +34 -0
  43. data/lib/pdk/config/json_schema_namespace.rb +143 -0
  44. data/lib/pdk/config/json_schema_setting.rb +53 -0
  45. data/lib/pdk/config/json_with_schema.rb +50 -0
  46. data/lib/pdk/config/namespace.rb +332 -0
  47. data/lib/pdk/config/setting.rb +132 -0
  48. data/lib/pdk/config/yaml.rb +43 -0
  49. data/lib/pdk/config/yaml_with_schema.rb +59 -0
  50. data/lib/pdk/generate.rb +10 -3
  51. data/lib/pdk/generate/defined_type.rb +1 -0
  52. data/lib/pdk/generate/module.rb +62 -35
  53. data/lib/pdk/generate/provider.rb +0 -5
  54. data/lib/pdk/generate/puppet_class.rb +1 -0
  55. data/lib/pdk/generate/puppet_object.rb +88 -41
  56. data/lib/pdk/generate/transport.rb +87 -0
  57. data/lib/pdk/logger.rb +21 -1
  58. data/lib/pdk/module.rb +2 -2
  59. data/lib/pdk/module/build.rb +103 -10
  60. data/lib/pdk/module/convert.rb +85 -19
  61. data/lib/pdk/module/metadata.rb +17 -12
  62. data/lib/pdk/module/templatedir.rb +108 -40
  63. data/lib/pdk/module/update.rb +27 -15
  64. data/lib/pdk/module/update_manager.rb +23 -15
  65. data/lib/pdk/report.rb +4 -3
  66. data/lib/pdk/report/event.rb +8 -6
  67. data/lib/pdk/template_file.rb +1 -1
  68. data/lib/pdk/tests/unit.rb +48 -21
  69. data/lib/pdk/util.rb +29 -63
  70. data/lib/pdk/util/bundler.rb +19 -15
  71. data/lib/pdk/util/filesystem.rb +64 -1
  72. data/lib/pdk/util/git.rb +52 -1
  73. data/lib/pdk/util/puppet_strings.rb +123 -0
  74. data/lib/pdk/util/puppet_version.rb +27 -12
  75. data/lib/pdk/util/ruby_version.rb +30 -7
  76. data/lib/pdk/util/template_uri.rb +281 -0
  77. data/lib/pdk/util/vendored_file.rb +28 -24
  78. data/lib/pdk/util/version.rb +7 -8
  79. data/lib/pdk/util/windows.rb +1 -0
  80. data/lib/pdk/util/windows/api_types.rb +0 -7
  81. data/lib/pdk/util/windows/file.rb +1 -1
  82. data/lib/pdk/util/windows/string.rb +1 -1
  83. data/lib/pdk/validate/base_validator.rb +12 -14
  84. data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -4
  85. data/lib/pdk/validate/metadata/metadata_syntax.rb +5 -3
  86. data/lib/pdk/validate/metadata_validator.rb +0 -2
  87. data/lib/pdk/validate/puppet/puppet_epp.rb +137 -0
  88. data/lib/pdk/validate/puppet/puppet_lint.rb +0 -3
  89. data/lib/pdk/validate/puppet/puppet_syntax.rb +5 -5
  90. data/lib/pdk/validate/puppet_validator.rb +2 -3
  91. data/lib/pdk/validate/ruby/rubocop.rb +1 -6
  92. data/lib/pdk/validate/ruby_validator.rb +0 -2
  93. data/lib/pdk/validate/tasks/metadata_lint.rb +9 -5
  94. data/lib/pdk/validate/tasks/name.rb +5 -3
  95. data/lib/pdk/validate/tasks_validator.rb +0 -2
  96. data/lib/pdk/validate/yaml/syntax.rb +6 -4
  97. data/lib/pdk/validate/yaml_validator.rb +0 -2
  98. data/lib/pdk/version.rb +1 -1
  99. data/locales/pdk.pot +634 -307
  100. metadata +100 -45
@@ -1,15 +1,11 @@
1
- require 'bundler'
2
- require 'digest'
3
- require 'fileutils'
4
- require 'pdk/util'
5
- require 'pdk/cli/exec'
6
-
7
1
  module PDK
8
2
  module Util
9
3
  module Bundler
10
4
  class BundleHelper; end
11
5
 
12
6
  def self.ensure_bundle!(gem_overrides = nil)
7
+ require 'fileutils'
8
+
13
9
  bundle = BundleHelper.new
14
10
 
15
11
  # This will default ensure_bundle! to re-resolving everything to latest
@@ -70,6 +66,8 @@ module PDK
70
66
  end
71
67
 
72
68
  def self.bundle_cache_key(gemfile, gem_overrides)
69
+ require 'digest'
70
+
73
71
  override_sig = (gem_overrides || {}).sort_by { |gem, _| gem.to_s }.to_s
74
72
  Digest::MD5.hexdigest(gemfile.to_s + override_sig)
75
73
  end
@@ -77,11 +75,12 @@ module PDK
77
75
 
78
76
  class BundleHelper
79
77
  def gemfile
78
+ require 'pdk/util'
80
79
  @gemfile ||= PDK::Util.find_upwards('Gemfile')
81
80
  end
82
81
 
83
82
  def gemfile_lock
84
- return nil if gemfile.nil?
83
+ return if gemfile.nil?
85
84
  @gemfile_lock ||= File.join(File.dirname(gemfile), 'Gemfile.lock')
86
85
  end
87
86
 
@@ -104,14 +103,14 @@ module PDK
104
103
 
105
104
  result = cmd.execute!
106
105
 
107
- unless result[:exit_code].zero?
108
- PDK.logger.debug(result.values_at(:stdout, :stderr).join("\n"))
109
- end
110
-
111
106
  result[:exit_code].zero?
112
107
  end
113
108
 
114
109
  def lock!
110
+ require 'pdk/util'
111
+ require 'fileutils'
112
+ require 'pdk/util/ruby_version'
113
+
115
114
  if PDK::Util.package_install?
116
115
  # In packaged installs, use vendored Gemfile.lock as a starting point.
117
116
  # Subsequent 'bundle install' will still pick up any new dependencies.
@@ -140,7 +139,7 @@ module PDK
140
139
  result = cmd.execute!
141
140
 
142
141
  unless result[:exit_code].zero?
143
- PDK.logger.fatal(result.values_at(:stdout, :stderr).join("\n"))
142
+ PDK.logger.fatal(result.values_at(:stdout, :stderr).join("\n")) unless PDK.logger.debug?
144
143
  raise PDK::CLI::FatalError, _('Unable to resolve default Gemfile dependencies.')
145
144
  end
146
145
 
@@ -181,7 +180,7 @@ module PDK
181
180
  result = cmd.execute!
182
181
 
183
182
  unless result[:exit_code].zero?
184
- PDK.logger.fatal(result.values_at(:stdout, :stderr).join("\n"))
183
+ PDK.logger.fatal(result.values_at(:stdout, :stderr).join("\n")) unless PDK.logger.debug?
185
184
  raise PDK::CLI::FatalError, _('Unable to resolve Gemfile dependencies.')
186
185
  end
187
186
 
@@ -189,6 +188,8 @@ module PDK
189
188
  end
190
189
 
191
190
  def install!(gem_overrides = {})
191
+ require 'pdk/util/ruby_version'
192
+
192
193
  argv = ['install', "--gemfile=#{gemfile}"]
193
194
  argv << '-j4' unless Gem.win_platform? && Gem::Version.new(PDK::Util::RubyVersion.active_ruby_version) < Gem::Version.new('2.3.5')
194
195
 
@@ -200,7 +201,7 @@ module PDK
200
201
  result = cmd.execute!
201
202
 
202
203
  unless result[:exit_code].zero?
203
- PDK.logger.fatal(result.values_at(:stdout, :stderr).join("\n"))
204
+ PDK.logger.fatal(result.values_at(:stdout, :stderr).join("\n")) unless PDK.logger.debug?
204
205
  raise PDK::CLI::FatalError, _('Unable to install missing Gemfile dependencies.')
205
206
  end
206
207
 
@@ -215,7 +216,7 @@ module PDK
215
216
  result = cmd.execute!
216
217
 
217
218
  unless result[:exit_code].zero?
218
- PDK.logger.fatal(_("Failed to generate binstubs for '%{gems}':\n%{output}") % { gems: gems.join(' '), output: result.values_at(:stdout, :stderr).join("\n") })
219
+ PDK.logger.fatal(_("Failed to generate binstubs for '%{gems}':\n%{output}") % { gems: gems.join(' '), output: result.values_at(:stdout, :stderr).join("\n") }) unless PDK.logger.debug?
219
220
  raise PDK::CLI::FatalError, _('Unable to install requested binstubs.')
220
221
  end
221
222
 
@@ -243,6 +244,9 @@ module PDK
243
244
  end
244
245
 
245
246
  def bundle_command(*args)
247
+ require 'pdk/cli/exec'
248
+ require 'pdk/cli/exec/command'
249
+
246
250
  PDK::CLI::Exec::Command.new(PDK::CLI::Exec.bundle_bin, *args).tap do |c|
247
251
  c.context = :module
248
252
  end
@@ -4,9 +4,72 @@ module PDK
4
4
  def write_file(path, content)
5
5
  raise ArgumentError unless path.is_a?(String) || path.respond_to?(:to_path)
6
6
 
7
- File.open(path, 'wb') { |f| f.write(content.encode(universal_newline: true)) }
7
+ # Harmonize newlines across platforms.
8
+ content = content.encode(universal_newline: true)
9
+
10
+ # Make sure all written files have a trailing newline.
11
+ content += "\n" unless content[-1] == "\n"
12
+
13
+ File.open(path, 'wb') { |f| f.write(content) }
8
14
  end
9
15
  module_function :write_file
16
+
17
+ def read_file(file, nil_on_error: false)
18
+ File.read(file)
19
+ rescue => e
20
+ raise e unless nil_on_error
21
+ nil
22
+ end
23
+ module_function :read_file
24
+
25
+ #:nocov:
26
+ # These methods just wrap core Ruby functionality and
27
+ # can be ignored for code coverage
28
+ def directory?(*args)
29
+ File.directory?(*args)
30
+ end
31
+ module_function :directory?
32
+
33
+ def mkdir_p(*args)
34
+ FileUtils.mkdir_p(*args)
35
+ end
36
+ module_function :mkdir_p
37
+
38
+ def file?(*args)
39
+ File.file?(*args)
40
+ end
41
+ module_function :file?
42
+
43
+ def expand_path(*args)
44
+ File.expand_path(*args)
45
+ end
46
+ module_function :expand_path
47
+
48
+ def glob(*args)
49
+ Dir.glob(*args)
50
+ end
51
+ module_function :glob
52
+
53
+ def fnmatch(*args)
54
+ File.fnmatch(*args)
55
+ end
56
+ module_function :fnmatch
57
+
58
+ def readable?(*args)
59
+ File.readable?(*args)
60
+ end
61
+ module_function :readable?
62
+
63
+ def exist?(*args)
64
+ File.exist?(*args)
65
+ end
66
+ module_function :exist?
67
+
68
+ def rm(*args)
69
+ FileUtils.rm(*args)
70
+ end
71
+ module_function :rm
72
+ #:nocov:
10
73
  end
11
74
  end
12
75
  end
data/lib/pdk/util/git.rb CHANGED
@@ -1,5 +1,21 @@
1
1
  module PDK
2
2
  module Util
3
+ class GitError < StandardError
4
+ attr_reader :stdout
5
+ attr_reader :stderr
6
+ attr_reader :exit_code
7
+ attr_reader :args
8
+
9
+ def initialze(args, result)
10
+ @args = args
11
+ @stdout = result[:stdout]
12
+ @stderr = result[:stderr]
13
+ @exit_code = result[:exit_code]
14
+
15
+ super(_('Git command failed: git %{args}' % { args: args.join(' ') }))
16
+ end
17
+ end
18
+
3
19
  module Git
4
20
  def self.git_bindir
5
21
  @git_dir ||= File.join('private', 'git', Gem.win_platform? ? 'cmd' : 'bin')
@@ -20,6 +36,8 @@ module PDK
20
36
  end
21
37
 
22
38
  def self.git_bin
39
+ require 'pdk/cli/exec'
40
+
23
41
  git_bin = Gem.win_platform? ? 'git.exe' : 'git'
24
42
  vendored_bin_path = File.join(git_bindir, git_bin)
25
43
 
@@ -27,12 +45,16 @@ module PDK
27
45
  end
28
46
 
29
47
  def self.git(*args)
48
+ require 'pdk/cli/exec'
49
+
30
50
  PDK::CLI::Exec.ensure_bin_present!(git_bin, 'git')
31
51
 
32
52
  PDK::CLI::Exec.execute(git_bin, *args)
33
53
  end
34
54
 
35
55
  def self.git_with_env(env, *args)
56
+ require 'pdk/cli/exec'
57
+
36
58
  PDK::CLI::Exec.ensure_bin_present!(git_bin, 'git')
37
59
 
38
60
  PDK::CLI::Exec.execute_with_env(env, git_bin, *args)
@@ -55,7 +77,27 @@ module PDK
55
77
  git('ls-remote', '--exit-code', maybe_repo)[:exit_code].zero?
56
78
  end
57
79
 
80
+ def self.work_tree?(path)
81
+ return false unless File.directory?(path)
82
+
83
+ Dir.chdir(path) do
84
+ rev_parse = git('rev-parse', '--is-inside-work-tree')
85
+ rev_parse[:exit_code].zero? && rev_parse[:stdout].strip == 'true'
86
+ end
87
+ end
88
+
89
+ def self.work_dir_clean?(repo)
90
+ raise PDK::CLI::ExitWithError, _('Unable to locate git work dir "%{workdir}"') % { workdir: repo } unless File.directory?(repo)
91
+ raise PDK::CLI::ExitWithError, _('Unable to locate git dir "%{gitdir}"') % { gitdir: repo } unless File.directory?(File.join(repo, '.git'))
92
+
93
+ git('--work-tree', repo, '--git-dir', File.join(repo, '.git'), 'status', '--untracked-files=no', '--porcelain', repo)[:stdout].empty?
94
+ end
95
+
58
96
  def self.ls_remote(repo, ref)
97
+ if File.directory?(repo)
98
+ repo = 'file://' + repo
99
+ end
100
+
59
101
  output = git('ls-remote', '--refs', repo, ref)
60
102
 
61
103
  unless output[:exit_code].zero?
@@ -67,7 +109,16 @@ module PDK
67
109
  end
68
110
 
69
111
  matching_refs = output[:stdout].split("\n").map { |r| r.split("\t") }
70
- matching_refs.find { |_sha, remote_ref| remote_ref == ref }.first
112
+ matching_ref = matching_refs.find { |_sha, remote_ref| remote_ref == "refs/tags/#{ref}" || remote_ref == "refs/remotes/origin/#{ref}" || remote_ref == "refs/heads/#{ref}" }
113
+ raise PDK::CLI::ExitWithError, _('Unable to find a branch or tag named "%{ref}" in %{repo}') % { ref: ref, repo: repo } if matching_ref.nil?
114
+ matching_ref.first
115
+ end
116
+
117
+ def self.describe(path, ref = nil)
118
+ args = ['--git-dir', path, 'describe', '--all', '--long', '--always', ref].compact
119
+ result = git(*args)
120
+ raise PDK::Util::GitError, args, result unless result[:exit_code].zero?
121
+ result[:stdout].strip
71
122
  end
72
123
  end
73
124
  end
@@ -0,0 +1,123 @@
1
+ module PDK
2
+ module Util
3
+ module PuppetStrings
4
+ class NoObjectError < StandardError; end
5
+ class RunError < StandardError; end
6
+ class NoGeneratorError < StandardError; end
7
+
8
+ # Runs Puppet for the purposes of generating puppet-strings output.
9
+ #
10
+ # @param *args [String] additional parameters to pass to puppet.
11
+ #
12
+ # @return [Hash{Symbol=>Object}] the result of the command execution.
13
+ def self.puppet(*args)
14
+ require 'pdk/cli/exec/command'
15
+
16
+ PDK::Util::Bundler.ensure_binstubs!('puppet')
17
+
18
+ argv = [File.join(PDK::Util.module_root, 'bin', 'puppet')] + args
19
+ argv.unshift(File.join(PDK::Util::RubyVersion.bin_path, 'ruby.exe')) if Gem.win_platform?
20
+
21
+ command = PDK::CLI::Exec::Command.new(*argv).tap do |c|
22
+ c.context = :module
23
+ c.add_spinner(_('Examining module contents'))
24
+ end
25
+
26
+ command.execute!
27
+ end
28
+
29
+ # Generates and parses the JSON output from puppet-strings.
30
+ #
31
+ # @returns [Hash{String=>Object}] the parsed puppet-strings output.
32
+ #
33
+ # @raises [PDK::Util::PuppetStrings::RunError] if the puppet-strings
34
+ # command exits non-zero.
35
+ # @raises [PDK::Util::PuppetStrings::RunError] if the puppet-strings
36
+ # command outputs invalid JSON.
37
+ def self.generate_hash
38
+ result = puppet('strings', 'generate', '--format', 'json')
39
+
40
+ raise RunError, result[:stderr] unless result[:exit_code].zero?
41
+
42
+ JSON.parse(result[:stdout])
43
+ rescue JSON::ParserError => e
44
+ PDK.logger.debug(e)
45
+ raise RunError, _('Unable to parse puppet-strings output')
46
+ end
47
+
48
+ # Searches the puppet-strings result to find the definition of the named
49
+ # object.
50
+ #
51
+ # @param name [String] the name of the object definition to search for.
52
+ # If the object name is not prepended with the module name,
53
+ # "#{module_name}::#{object_name}" will also be search for.
54
+ #
55
+ # @returns [Array[PDK::Generate::PuppetObject, Hash{String=>Object}]] the
56
+ # appropriate generator class for the object as the first element and
57
+ # the puppet-strings description hash for the definition.
58
+ #
59
+ # @raises [PDK::Util::PuppetStrings::NoObjectError] if the named object
60
+ # can not be found in the puppet-strings output.
61
+ # @raises [PDK::Util::PuppetStrings::NoGeneratorError] if the named
62
+ # object does not have a corresponding PDK generator class.
63
+ def self.find_object(name)
64
+ module_name = PDK::Util.module_metadata['name'].rpartition('-').last
65
+
66
+ object_names = [name]
67
+ object_names << "#{module_name}::#{name}" unless name.start_with?("#{module_name}::")
68
+
69
+ known_objects = generate_hash
70
+ object_type = known_objects.keys.find do |obj_type|
71
+ known_objects[obj_type].any? { |obj| object_names.include?(obj['name']) }
72
+ end
73
+
74
+ raise NoObjectError if object_type.nil?
75
+
76
+ generator = find_generator(object_type)
77
+
78
+ raise NoGeneratorError, object_type if generator.nil?
79
+
80
+ [generator, known_objects[object_type].find { |obj| object_names.include?(obj['name']) }]
81
+ end
82
+
83
+ # Generate a list of all objects that PDK has a generator for.
84
+ #
85
+ # @returns [Array[Array[PDK::Generate::PuppetObject,
86
+ # Array[Hash{String=>Object}]]]] an associative array where the first
87
+ # element of each pair is the generator class and the second element of
88
+ # each pair is an array of description hashes from puppet-strings.
89
+ def self.all_objects
90
+ require 'pdk/generate'
91
+
92
+ generators = PDK::Generate::GENERATORS.select do |gen|
93
+ gen.respond_to?(:puppet_strings_type) && !gen.puppet_strings_type.nil?
94
+ end
95
+
96
+ known_objects = generate_hash
97
+
98
+ generators.map { |gen| [gen, known_objects[gen.puppet_strings_type]] }.reject do |_, obj|
99
+ obj.nil? || obj.empty?
100
+ end
101
+ end
102
+
103
+ # Evaluates the mapping of puppet-strings object type to PDK generator
104
+ # class.
105
+ #
106
+ # @param type [String] the object type as returned from puppet-strings.
107
+ #
108
+ # @returns [PDK:Generate::PuppetObject,nil] a child of
109
+ # PDK::Generate::PuppetObject or nil a suitable generator is not found.
110
+ #
111
+ # @example
112
+ # PDK::Util::PuppetStrings.find_generator('puppet_classes')
113
+ # => PDK::Generate::PuppetClass
114
+ def self.find_generator(type)
115
+ require 'pdk/generate'
116
+
117
+ PDK::Generate::GENERATORS.find do |gen|
118
+ gen.respond_to?(:puppet_strings_type) && gen.puppet_strings_type == type
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -1,6 +1,3 @@
1
- require 'pdk/util'
2
- require 'pdk/util/git'
3
-
4
1
  module PDK
5
2
  module Util
6
3
  class PuppetVersion
@@ -21,6 +18,8 @@ module PDK
21
18
  DEFAULT_PUPPET_DEV_BRANCH = 'master'.freeze
22
19
 
23
20
  def puppet_dev_env
21
+ require 'pdk/util/ruby_version'
22
+
24
23
  {
25
24
  gem_version: 'file://%{path}' % { path: puppet_dev_path },
26
25
  ruby_version: PDK::Util::RubyVersion.latest_ruby_version,
@@ -28,6 +27,8 @@ module PDK
28
27
  end
29
28
 
30
29
  def puppet_dev_path
30
+ require 'pdk/util'
31
+
31
32
  File.join(PDK::Util.cachedir, 'src', 'puppet')
32
33
  end
33
34
 
@@ -42,6 +43,9 @@ module PDK
42
43
  end
43
44
 
44
45
  def fetch_puppet_dev
46
+ require 'pdk/util/git'
47
+ require 'fileutils'
48
+
45
49
  # Check if the source is cloned and is a readable git repo
46
50
  unless PDK::Util::Git.remote_repo? puppet_dev_path
47
51
  # Check if the path has something in it already. Delete it and prepare for clone if so.
@@ -56,7 +60,7 @@ module PDK
56
60
 
57
61
  PDK.logger.error clone_result[:stdout]
58
62
  PDK.logger.error clone_result[:stderr]
59
- raise PDK::CLI::FatalError, _("Unable to clone git repository at '%{repo}'.") % { repo: DEFAULT_PUPPET_DEV_URL }
63
+ raise PDK::CLI::FatalError, _("Unable to clone git repository from '%{repo}'.") % { repo: DEFAULT_PUPPET_DEV_URL }
60
64
  end
61
65
 
62
66
  # Fetch Updates from remote repository
@@ -133,12 +137,15 @@ module PDK
133
137
  end
134
138
 
135
139
  def from_module_metadata(metadata = nil)
140
+ require 'pdk/module/metadata'
141
+ require 'pdk/util'
142
+
136
143
  if metadata.nil?
137
144
  metadata_file = PDK::Util.find_upwards('metadata.json')
138
145
 
139
146
  unless metadata_file
140
147
  PDK.logger.warn _('Unable to determine Puppet version for module: no metadata.json present in module.')
141
- return nil
148
+ return
142
149
  end
143
150
 
144
151
  metadata = PDK::Module::Metadata.from_file(metadata_file)
@@ -191,6 +198,8 @@ module PDK
191
198
  end
192
199
 
193
200
  def fetch_pe_version_map
201
+ require 'pdk/util/vendored_file'
202
+
194
203
  map = PDK::Util::VendoredFile.new('pe_versions.json', PE_VERSIONS_URL).read
195
204
 
196
205
  JSON.parse(map)
@@ -205,17 +214,19 @@ module PDK
205
214
  end
206
215
 
207
216
  def rubygems_puppet_versions
208
- return @rubygems_puppet_versions unless @rubygems_puppet_versions.nil?
209
-
210
- fetcher = Gem::SpecFetcher.fetcher
211
- puppet_tuples = fetcher.detect(:released) do |spec_tuple|
212
- spec_tuple.name == 'puppet' && Gem::Platform.match(spec_tuple.platform)
217
+ @rubygems_puppet_versions ||= begin
218
+ fetcher = Gem::SpecFetcher.fetcher
219
+ puppet_tuples = fetcher.detect(:released) do |spec_tuple|
220
+ spec_tuple.name == 'puppet' && Gem::Platform.match(spec_tuple.platform)
221
+ end
222
+ puppet_versions = puppet_tuples.map { |name, _| name.version }.uniq
223
+ puppet_versions.sort { |a, b| b <=> a }
213
224
  end
214
- puppet_versions = puppet_tuples.map { |name, _| name.version }.uniq
215
- @rubygems_puppet_versions = puppet_versions.sort { |a, b| b <=> a }
216
225
  end
217
226
 
218
227
  def find_gem(requirement)
228
+ require 'pdk/util'
229
+
219
230
  if PDK::Util.package_install?
220
231
  find_in_package_cache(requirement)
221
232
  else
@@ -224,11 +235,15 @@ module PDK
224
235
  end
225
236
 
226
237
  def find_in_rubygems(requirement)
238
+ require 'pdk/util/ruby_version'
239
+
227
240
  version = rubygems_puppet_versions.find { |r| requirement.satisfied_by?(r) }
228
241
  version.nil? ? nil : { gem_version: version, ruby_version: PDK::Util::RubyVersion.default_ruby_version }
229
242
  end
230
243
 
231
244
  def find_in_package_cache(requirement)
245
+ require 'pdk/util/ruby_version'
246
+
232
247
  PDK::Util::RubyVersion.versions.each do |ruby_version, _|
233
248
  PDK::Util::RubyVersion.use(ruby_version)
234
249
  version = PDK::Util::RubyVersion.available_puppet_versions.find { |r| requirement.satisfied_by?(r) }