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
@@ -6,6 +6,8 @@ module PDK
6
6
  GIT_DESCRIBE_PATTERN = %r{\A(?<base>.+?)-(?<additional_commits>\d+)-g(?<sha>.+)\Z}
7
7
 
8
8
  def run
9
+ template_uri.git_ref = new_template_version
10
+
9
11
  stage_changes!
10
12
 
11
13
  if current_version == new_version
@@ -39,7 +41,11 @@ module PDK
39
41
 
40
42
  update_manager.sync_changes!
41
43
 
42
- PDK::Util::Bundler.ensure_bundle! if needs_bundle_update?
44
+ if needs_bundle_update?
45
+ require 'pdk/util/bundler'
46
+
47
+ PDK::Util::Bundler.ensure_bundle!
48
+ end
43
49
 
44
50
  print_result 'Update completed'
45
51
  end
@@ -50,8 +56,8 @@ module PDK
50
56
  raise PDK::CLI::ExitWithError, e.message
51
57
  end
52
58
 
53
- def template_url
54
- @template_url ||= module_metadata.data['template-url']
59
+ def template_uri
60
+ @template_uri ||= PDK::Util::TemplateURI.new(module_metadata.data['template-url'])
55
61
  end
56
62
 
57
63
  def current_version
@@ -62,6 +68,16 @@ module PDK
62
68
  @new_version ||= fetch_remote_version(new_template_version)
63
69
  end
64
70
 
71
+ def new_template_version
72
+ return options[:'template-ref'] if options[:'template-ref']
73
+
74
+ if template_uri.default? && template_uri.ref_is_tag? && PDK::Util.package_install?
75
+ PDK::Util::TemplateURI.default_template_ref
76
+ else
77
+ template_uri.git_ref
78
+ end
79
+ end
80
+
65
81
  private
66
82
 
67
83
  def current_template_version
@@ -73,27 +89,23 @@ module PDK
73
89
 
74
90
  return data if data.nil?
75
91
 
76
- if data[:base].start_with?('heads/')
77
- "#{data[:base].gsub(%r{^heads/}, '')}@#{data[:sha]}"
92
+ if data[:base] =~ %r{^(?:heads|remotes)/}
93
+ "#{data[:base].gsub(%r{^(heads/|remotes/\w+?/)}, '')}@#{data[:sha]}"
78
94
  else
79
95
  data[:base]
80
96
  end
81
97
  end
82
98
 
83
- def new_template_version
84
- PDK::Util.default_template_ref
85
- end
86
-
87
- def fetch_remote_version(version)
88
- return version unless version.include?('/')
99
+ def fetch_remote_version(template_ref)
100
+ return template_ref unless current_template_version.is_a?(String)
101
+ return template_ref if template_ref == PDK::TEMPLATE_REF
89
102
 
90
- branch = version.partition('/').last
91
103
  sha_length = GIT_DESCRIBE_PATTERN.match(current_template_version)[:sha].length - 1
92
- "#{branch}@#{PDK::Util::Git.ls_remote(template_url, "refs/heads/#{branch}")[0..sha_length]}"
104
+ "#{template_ref}@#{PDK::Util::Git.ls_remote(template_uri.git_remote, template_ref)[0..sha_length]}"
93
105
  end
94
106
 
95
107
  def update_message
96
- format_string = if template_url == PDK::Util.puppetlabs_template_url
108
+ format_string = if template_uri.default?
97
109
  _('Updating %{module_name} using the default template, from %{current_version} to %{new_version}')
98
110
  else
99
111
  _('Updating %{module_name} using the template at %{template_url}, from %{current_version} to %{new_version}')
@@ -101,7 +113,7 @@ module PDK
101
113
 
102
114
  format_string % {
103
115
  module_name: module_metadata.data['name'],
104
- template_url: template_url,
116
+ template_url: template_uri.git_remote,
105
117
  current_version: current_version,
106
118
  new_version: new_version,
107
119
  }
@@ -1,16 +1,11 @@
1
- require 'diff/lcs'
2
- require 'diff/lcs/hunk'
3
- require 'English'
4
- require 'fileutils'
5
- require 'set'
6
- require 'pdk/util/filesystem'
7
-
8
1
  module PDK
9
2
  module Module
10
3
  class UpdateManager
11
4
  # Initialises a blank UpdateManager object, which is used to store and
12
5
  # process file additions/removals/modifications.
13
6
  def initialize
7
+ require 'set'
8
+
14
9
  @modified_files = Set.new
15
10
  @added_files = Set.new
16
11
  @removed_files = Set.new
@@ -45,11 +40,13 @@ module PDK
45
40
  # @raise (see #calculate_diffs)
46
41
  # @return [Hash{Symbol => Set,Hash}] the summary of the pending changes.
47
42
  def changes
43
+ require 'pdk/util/filesystem'
44
+
48
45
  calculate_diffs
49
46
 
50
47
  {
51
48
  added: @added_files,
52
- removed: @removed_files.select { |f| File.exist?(f) },
49
+ removed: @removed_files.select { |f| PDK::Util::Filesystem.exist?(f) },
53
50
  modified: @diff_cache.reject { |_, value| value.nil? },
54
51
  }
55
52
  end
@@ -73,7 +70,7 @@ module PDK
73
70
  def changed?(path)
74
71
  changes[:added].any? { |add| add[:path] == path } ||
75
72
  changes[:removed].include?(path) ||
76
- changes[:modified].keys.include?(path)
73
+ changes[:modified].key?(path)
77
74
  end
78
75
 
79
76
  # Apply any pending changes stored in the UpdateManager to the module.
@@ -106,9 +103,11 @@ module PDK
106
103
  #
107
104
  # @raise [PDK::CLI::ExitWithError] if the file could not be removed.
108
105
  def unlink_file(path)
109
- if File.file?(path)
106
+ require 'pdk/util/filesystem'
107
+
108
+ if PDK::Util::Filesystem.file?(path)
110
109
  PDK.logger.debug(_("unlinking '%{path}'") % { path: path })
111
- FileUtils.rm(path)
110
+ PDK::Util::Filesystem.rm(path)
112
111
  else
113
112
  PDK.logger.debug(_("'%{path}': already gone") % { path: path })
114
113
  end
@@ -127,14 +126,16 @@ module PDK
127
126
  # @raise [PDK::CLI::ExitWithError] if a file being modified isn't
128
127
  # readable.
129
128
  def calculate_diffs
129
+ require 'pdk/util/filesystem'
130
+
130
131
  @modified_files.each do |file|
131
132
  next if @diff_cache.key?(file[:path])
132
133
 
133
- unless File.readable?(file[:path])
134
+ unless PDK::Util::Filesystem.readable?(file[:path])
134
135
  raise PDK::CLI::ExitWithError, _("Unable to open '%{path}' for reading") % { path: file[:path] }
135
136
  end
136
137
 
137
- old_content = File.read(file[:path])
138
+ old_content = PDK::Util::Filesystem.read_file(file[:path])
138
139
  file_diff = unified_diff(file[:path], old_content, file[:content])
139
140
  @diff_cache[file[:path]] = file_diff
140
141
  end
@@ -147,7 +148,9 @@ module PDK
147
148
  #
148
149
  # @raise [PDK::CLI::ExitWithError] if the file is not writeable.
149
150
  def write_file(path, content)
150
- FileUtils.mkdir_p(File.dirname(path))
151
+ require 'pdk/util/filesystem'
152
+
153
+ PDK::Util::Filesystem.mkdir_p(File.dirname(path))
151
154
  PDK.logger.debug(_("writing '%{path}'") % { path: path })
152
155
  PDK::Util::Filesystem.write_file(path, content)
153
156
  rescue Errno::EACCES
@@ -167,6 +170,9 @@ module PDK
167
170
  #
168
171
  # @return [String] The unified diff of the pending changes to the file.
169
172
  def unified_diff(path, old_content, new_content, lines_of_context = 3)
173
+ require 'diff/lcs'
174
+ require 'English'
175
+
170
176
  output = []
171
177
 
172
178
  old_lines = old_content.split($INPUT_RECORD_SEPARATOR).map(&:chomp)
@@ -174,7 +180,9 @@ module PDK
174
180
 
175
181
  diffs = Diff::LCS.diff(old_lines, new_lines)
176
182
 
177
- return nil if diffs.empty?
183
+ return if diffs.empty?
184
+
185
+ require 'diff/lcs/hunk'
178
186
 
179
187
  file_mtime = File.stat(path).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z')
180
188
  now = Time.now.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z')
data/lib/pdk/report.rb CHANGED
@@ -1,7 +1,4 @@
1
- require 'rexml/document'
2
- require 'time'
3
1
  require 'pdk/report/event'
4
- require 'socket'
5
2
 
6
3
  module PDK
7
4
  class Report
@@ -48,6 +45,10 @@ module PDK
48
45
  # @param target [#write] an IO object that the report will be written to.
49
46
  # Defaults to PDK::Report.default_target.
50
47
  def write_junit(target = self.class.default_target)
48
+ require 'rexml/document'
49
+ require 'time'
50
+ require 'socket'
51
+
51
52
  # Open a File Object for IO if target is a string containing a filename or path
52
53
  target = File.open(target, 'w') if target.is_a? String
53
54
 
@@ -1,6 +1,3 @@
1
- require 'rexml/document'
2
- require 'pathname'
3
-
4
1
  module PDK
5
2
  class Report
6
3
  class Event
@@ -132,6 +129,8 @@ module PDK
132
129
  #
133
130
  # @return [REXML::Element] The rendered event.
134
131
  def to_junit
132
+ require 'rexml/document'
133
+
135
134
  testcase = REXML::Element.new('testcase')
136
135
  testcase.attributes['classname'] = [source, test].compact.join('.')
137
136
  testcase.attributes['name'] = [file, line, column].compact.join(':')
@@ -195,6 +194,9 @@ module PDK
195
194
  raise ArgumentError, _('File must be a String.')
196
195
  end
197
196
 
197
+ require 'pathname'
198
+ require 'pdk/util'
199
+
198
200
  path = Pathname.new(value)
199
201
 
200
202
  if path.absolute?
@@ -267,7 +269,7 @@ module PDK
267
269
  # @return [Integer] the provided value, converted into an Integer if
268
270
  # necessary.
269
271
  def sanitise_line(value)
270
- return nil if value.nil?
272
+ return if value.nil?
271
273
 
272
274
  valid_types = [String, Integer]
273
275
  if RUBY_VERSION.split('.')[0..1].join('.').to_f < 2.4
@@ -292,7 +294,7 @@ module PDK
292
294
  # @return [Integer] the provided value, converted into an Integer if
293
295
  # necessary.
294
296
  def sanitise_column(value)
295
- return nil if value.nil?
297
+ return if value.nil?
296
298
 
297
299
  valid_types = [String, Integer]
298
300
  if RUBY_VERSION.split('.')[0..1].join('.').to_f < 2.4
@@ -317,7 +319,7 @@ module PDK
317
319
  #
318
320
  # @return [Array] Array of stack trace lines with less relevant lines excluded
319
321
  def sanitise_trace(value)
320
- return nil if value.nil?
322
+ return if value.nil?
321
323
 
322
324
  valid_types = [Array]
323
325
 
@@ -45,7 +45,7 @@ module PDK
45
45
  end
46
46
 
47
47
  def config_for(path)
48
- return nil unless respond_to?(:template_dir)
48
+ return unless respond_to?(:template_dir)
49
49
 
50
50
  template_dir.config_for(path)
51
51
  end
@@ -1,34 +1,51 @@
1
- require 'pdk'
2
- require 'pdk/cli/exec'
3
- require 'pdk/util/bundler'
4
- require 'json'
5
-
6
1
  module PDK
7
2
  module Test
8
3
  class Unit
9
4
  def self.cmd(tests, opts = {})
10
- rake_args = opts.key?(:parallel) ? 'parallel_spec_standalone' : 'spec_standalone'
11
- rake_args += "[#{tests}]" unless tests.nil?
5
+ rake_args = opts[:parallel] ? 'parallel_spec_standalone' : 'spec_standalone'
6
+ rake_args += "[#{tests}]" unless tests.nil? || tests.empty?
12
7
  rake_args
13
8
  end
14
9
 
15
10
  def self.rake_bin
11
+ require 'pdk/util'
12
+
16
13
  @rake ||= File.join(PDK::Util.module_root, 'bin', 'rake')
17
14
  end
18
15
 
19
- def self.rake(task, spinner_text, environment = {})
16
+ def self.cmd_with_args(task)
17
+ require 'pdk/util/ruby_version'
18
+
20
19
  argv = [rake_bin, task]
21
20
  argv.unshift(File.join(PDK::Util::RubyVersion.bin_path, 'ruby.exe')) if Gem.win_platform?
21
+ argv
22
+ end
22
23
 
23
- command = PDK::CLI::Exec::Command.new(*argv).tap do |c|
24
+ def self.rake(task, spinner_text, environment = {})
25
+ require 'pdk/cli/exec/command'
26
+
27
+ command = PDK::CLI::Exec::Command.new(*cmd_with_args(task)).tap do |c|
24
28
  c.context = :module
25
- c.add_spinner(spinner_text)
29
+ c.add_spinner(spinner_text) if spinner_text
26
30
  c.environment = environment
27
31
  end
28
32
 
29
33
  command.execute!
30
34
  end
31
35
 
36
+ def self.interactive_rake(task, environment)
37
+ require 'pdk/cli/exec/interactive_command'
38
+
39
+ command = PDK::CLI::Exec::InteractiveCommand.new(*cmd_with_args(task)).tap do |c|
40
+ c.context = :module
41
+ c.environment = environment.reject do |key, _|
42
+ key == 'CI_SPEC_OPTIONS'
43
+ end
44
+ end
45
+
46
+ command.execute!
47
+ end
48
+
32
49
  def self.parallel_with_no_tests?(ran_in_parallel, json_result, result)
33
50
  ran_in_parallel && json_result.empty? &&
34
51
  ((!result[:exit_code].zero? && result[:stderr].strip =~ %r{Pass files or folders to run$}) ||
@@ -64,31 +81,40 @@ module PDK
64
81
  end
65
82
 
66
83
  def self.invoke(report, options = {})
84
+ require 'pdk/util'
85
+ require 'pdk/util/bundler'
86
+
67
87
  PDK::Util::Bundler.ensure_binstubs!('rake', 'rspec-core')
68
88
 
69
89
  setup
70
90
 
71
- tests = options.fetch(:tests)
91
+ tests = options[:tests]
72
92
 
73
93
  environment = { 'CI_SPEC_OPTIONS' => '--format j' }
74
94
  environment['PUPPET_GEM_VERSION'] = options[:puppet] if options[:puppet]
75
- spinner_msg = options.key?(:parallel) ? _('Running unit tests in parallel.') : _('Running unit tests.')
95
+ spinner_msg = options[:parallel] ? _('Running unit tests in parallel.') : _('Running unit tests.')
96
+
97
+ if options[:interactive]
98
+ result = interactive_rake(cmd(tests, options), environment)
99
+ return result[:exit_code]
100
+ end
101
+
76
102
  result = rake(cmd(tests, options), spinner_msg, environment)
77
103
 
78
- json_result = if options.key?(:parallel)
104
+ json_result = if options[:parallel]
79
105
  PDK::Util.find_all_json_in(result[:stdout])
80
106
  else
81
107
  PDK::Util.find_first_json_in(result[:stdout])
82
108
  end
83
109
 
84
- if parallel_with_no_tests?(options.key?(:parallel), json_result, result)
110
+ if parallel_with_no_tests?(options[:parallel], json_result, result)
85
111
  json_result = [{ 'messages' => ['No examples found.'] }]
86
112
  result[:exit_code] = 0
87
113
  end
88
114
 
89
115
  raise PDK::CLI::FatalError, _('Unit test output did not contain a valid JSON result: %{output}') % { output: result[:stdout] } if json_result.nil? || json_result.empty?
90
116
 
91
- json_result = merge_json_results(json_result) if options.key?(:parallel)
117
+ json_result = merge_json_results(json_result) if options[:parallel]
92
118
 
93
119
  parse_output(report, json_result, result[:duration])
94
120
 
@@ -183,15 +209,16 @@ module PDK
183
209
  end
184
210
 
185
211
  # @return array of { :id, :full_description }
186
- def self.list
212
+ def self.list(options = {})
213
+ require 'pdk/util'
214
+ require 'pdk/util/bundler'
215
+
187
216
  PDK::Util::Bundler.ensure_binstubs!('rake')
188
217
 
189
- command_argv = [File.join(PDK::Util.module_root, 'bin', 'rake'), 'spec_list_json']
190
- command_argv.unshift(File.join(PDK::Util::RubyVersion.bin_path, 'ruby.exe')) if Gem.win_platform?
218
+ environment = {}
219
+ environment['PUPPET_GEM_VERSION'] = options[:puppet] if options[:puppet]
191
220
 
192
- list_command = PDK::CLI::Exec::Command.new(*command_argv)
193
- list_command.context = :module
194
- output = list_command.execute!
221
+ output = rake('spec_list_json', _('Finding unit tests.'), environment)
195
222
 
196
223
  rspec_json = PDK::Util.find_first_json_in(output[:stdout])
197
224
  raise PDK::CLI::FatalError, _('Failed to find valid JSON in output from rspec: %{output}' % { output: output[:stdout] }) unless rspec_json
data/lib/pdk/util.rb CHANGED
@@ -1,10 +1,7 @@
1
- require 'tmpdir'
2
- require 'tempfile'
3
-
4
- require 'pdk/util/version'
1
+ # PDK::Util::Windows can not be lazy loaded because it conditionally requires
2
+ # other files on Windows only. This can probably be fixed up with a later
3
+ # refactoring.
5
4
  require 'pdk/util/windows'
6
- require 'pdk/util/vendored_file'
7
- require 'pdk/util/filesystem'
8
5
 
9
6
  module PDK
10
7
  module Util
@@ -43,6 +40,8 @@ module PDK
43
40
  #
44
41
  # @return [String] The temporary directory path.
45
42
  def make_tmpdir_name(base)
43
+ require 'tmpdir'
44
+
46
45
  t = Time.now.strftime('%Y%m%d')
47
46
  name = "#{base}#{t}-#{Process.pid}-#{rand(0x100000000).to_s(36)}"
48
47
  File.join(Dir.tmpdir, name)
@@ -67,11 +66,15 @@ module PDK
67
66
  module_function :canonical_path
68
67
 
69
68
  def package_install?
69
+ require 'pdk/util/version'
70
+
70
71
  !PDK::Util::Version.version_file.nil?
71
72
  end
72
73
  module_function :package_install?
73
74
 
74
75
  def development_mode?
76
+ require 'pdk/util/version'
77
+
75
78
  (!PDK::Util::Version.git_ref.nil? || PDK::VERSION.end_with?('.pre'))
76
79
  end
77
80
  module_function :development_mode?
@@ -83,6 +86,7 @@ module PDK
83
86
 
84
87
  def pdk_package_basedir
85
88
  raise PDK::CLI::FatalError, _('Package basedir requested for non-package install.') unless package_install?
89
+ require 'pdk/util/version'
86
90
 
87
91
  File.dirname(PDK::Util::Version.version_file)
88
92
  end
@@ -105,6 +109,15 @@ module PDK
105
109
  end
106
110
  module_function :cachedir
107
111
 
112
+ def configdir
113
+ if Gem.win_platform?
114
+ File.join(ENV['LOCALAPPDATA'], 'PDK')
115
+ else
116
+ File.join(ENV.fetch('XDG_CONFIG_HOME', File.join(Dir.home, '.config')), 'pdk')
117
+ end
118
+ end
119
+ module_function :configdir
120
+
108
121
  # Returns path to the root of the module being worked on.
109
122
  #
110
123
  # @return [String, nil] Fully qualified base path to module, or nil if
@@ -121,6 +134,14 @@ module PDK
121
134
  end
122
135
  module_function :module_root
123
136
 
137
+ # The module's fixtures directory for spec testing
138
+ # @return [String] - the path to the module's fixtures directory
139
+ def module_fixtures_dir
140
+ dir = module_root
141
+ File.join(module_root, 'spec', 'fixtures') unless dir.nil?
142
+ end
143
+ module_function :module_fixtures_dir
144
+
124
145
  # Returns true or false depending on if any of the common directories in a module
125
146
  # are found in the current directory
126
147
  #
@@ -197,65 +218,10 @@ module PDK
197
218
  end
198
219
  module_function :targets_relative_to_pwd
199
220
 
200
- def default_template_url
201
- answer_file_url = PDK.answers['template-url']
202
-
203
- return puppetlabs_template_url if answer_file_url.nil?
204
-
205
- # Ignore answer file template-url if the value is the old or new default.
206
- return puppetlabs_template_url if answer_file_url == 'https://github.com/puppetlabs/pdk-module-template'
207
- return puppetlabs_template_url if answer_file_url == puppetlabs_template_url
208
-
209
- if File.directory?(answer_file_url)
210
- # Instantiating a new TemplateDir object pointing to the directory
211
- # will cause the directory contents to be validated, raising
212
- # ArgumentError if it does not appear to be a valid template.
213
- PDK::Module::TemplateDir.new(answer_file_url) {}
214
- return answer_file_url
215
- end
216
-
217
- raise ArgumentError unless PDK::Util::Git.repo?(answer_file_url)
218
-
219
- answer_file_url
220
- rescue ArgumentError
221
- PDK.logger.warn(
222
- _("Unable to access the previously used template '%{template}', using the default template instead.") % {
223
- template: answer_file_url,
224
- },
225
- )
226
- PDK.answers.update!('template-url' => nil)
227
- return puppetlabs_template_url
228
- end
229
- module_function :default_template_url
230
-
231
- def puppetlabs_template_url
232
- if package_install?
233
- 'file://' + File.join(package_cachedir, 'pdk-templates.git')
234
- else
235
- 'https://github.com/puppetlabs/pdk-templates'
236
- end
237
- end
238
- module_function :puppetlabs_template_url
239
-
240
- def default_template_ref
241
- # TODO: This should respect a --template-ref option if we add that
242
- return 'origin/master' if default_template_url != puppetlabs_template_url
243
-
244
- puppetlabs_template_ref
245
- end
246
- module_function :default_template_ref
247
-
248
- def puppetlabs_template_ref
249
- if PDK::Util.development_mode?
250
- 'origin/master'
251
- else
252
- PDK::TEMPLATE_REF
253
- end
254
- end
255
- module_function :puppetlabs_template_ref
256
-
257
221
  # TO-DO: Refactor replacement of lib/pdk/module/build.rb:metadata to use this function instead
258
222
  def module_metadata
223
+ require 'pdk/module/metadata'
224
+
259
225
  PDK::Module::Metadata.from_file(File.join(module_root, 'metadata.json')).data
260
226
  end
261
227
  module_function :module_metadata