pdk 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1329 -1321
  3. data/LICENSE +201 -201
  4. data/README.md +163 -163
  5. data/exe/pdk +10 -10
  6. data/lib/pdk/analytics/client/google_analytics.rb +143 -143
  7. data/lib/pdk/analytics/client/noop.rb +25 -25
  8. data/lib/pdk/analytics/util.rb +19 -19
  9. data/lib/pdk/analytics.rb +30 -30
  10. data/lib/pdk/answer_file.rb +12 -12
  11. data/lib/pdk/bolt.rb +19 -19
  12. data/lib/pdk/cli/build.rb +82 -82
  13. data/lib/pdk/cli/bundle.rb +48 -48
  14. data/lib/pdk/cli/config/get.rb +26 -26
  15. data/lib/pdk/cli/config.rb +22 -22
  16. data/lib/pdk/cli/console.rb +148 -148
  17. data/lib/pdk/cli/convert.rb +52 -52
  18. data/lib/pdk/cli/env.rb +52 -52
  19. data/lib/pdk/cli/errors.rb +25 -25
  20. data/lib/pdk/cli/exec/command.rb +293 -293
  21. data/lib/pdk/cli/exec/interactive_command.rb +114 -114
  22. data/lib/pdk/cli/exec.rb +84 -84
  23. data/lib/pdk/cli/exec_group.rb +104 -104
  24. data/lib/pdk/cli/get/config.rb +24 -24
  25. data/lib/pdk/cli/get.rb +20 -20
  26. data/lib/pdk/cli/module/build.rb +12 -12
  27. data/lib/pdk/cli/module/generate.rb +47 -47
  28. data/lib/pdk/cli/module.rb +14 -14
  29. data/lib/pdk/cli/new/class.rb +32 -32
  30. data/lib/pdk/cli/new/defined_type.rb +32 -32
  31. data/lib/pdk/cli/new/fact.rb +29 -29
  32. data/lib/pdk/cli/new/function.rb +29 -29
  33. data/lib/pdk/cli/new/module.rb +53 -53
  34. data/lib/pdk/cli/new/provider.rb +29 -29
  35. data/lib/pdk/cli/new/task.rb +34 -34
  36. data/lib/pdk/cli/new/test.rb +52 -52
  37. data/lib/pdk/cli/new/transport.rb +27 -27
  38. data/lib/pdk/cli/new.rb +21 -21
  39. data/lib/pdk/cli/release/prep.rb +39 -39
  40. data/lib/pdk/cli/release/publish.rb +50 -50
  41. data/lib/pdk/cli/release.rb +194 -194
  42. data/lib/pdk/cli/remove/config.rb +80 -80
  43. data/lib/pdk/cli/remove.rb +20 -20
  44. data/lib/pdk/cli/set/config.rb +119 -119
  45. data/lib/pdk/cli/set.rb +20 -20
  46. data/lib/pdk/cli/test/unit.rb +90 -90
  47. data/lib/pdk/cli/test.rb +11 -11
  48. data/lib/pdk/cli/update.rb +64 -64
  49. data/lib/pdk/cli/util/command_redirector.rb +27 -27
  50. data/lib/pdk/cli/util/interview.rb +72 -72
  51. data/lib/pdk/cli/util/option_normalizer.rb +55 -55
  52. data/lib/pdk/cli/util/option_validator.rb +68 -68
  53. data/lib/pdk/cli/util/spinner.rb +13 -13
  54. data/lib/pdk/cli/util/update_manager_printer.rb +82 -82
  55. data/lib/pdk/cli/util.rb +305 -305
  56. data/lib/pdk/cli/validate.rb +116 -116
  57. data/lib/pdk/cli.rb +175 -175
  58. data/lib/pdk/config/analytics_schema.json +26 -26
  59. data/lib/pdk/config/errors.rb +5 -5
  60. data/lib/pdk/config/ini_file.rb +183 -183
  61. data/lib/pdk/config/ini_file_setting.rb +39 -39
  62. data/lib/pdk/config/json.rb +34 -34
  63. data/lib/pdk/config/json_schema_namespace.rb +142 -142
  64. data/lib/pdk/config/json_schema_setting.rb +53 -53
  65. data/lib/pdk/config/json_with_schema.rb +49 -49
  66. data/lib/pdk/config/namespace.rb +354 -354
  67. data/lib/pdk/config/setting.rb +135 -135
  68. data/lib/pdk/config/validator.rb +31 -31
  69. data/lib/pdk/config/yaml.rb +46 -46
  70. data/lib/pdk/config/yaml_with_schema.rb +59 -59
  71. data/lib/pdk/config.rb +390 -390
  72. data/lib/pdk/context/control_repo.rb +60 -60
  73. data/lib/pdk/context/module.rb +28 -28
  74. data/lib/pdk/context/none.rb +22 -22
  75. data/lib/pdk/context.rb +99 -99
  76. data/lib/pdk/control_repo.rb +90 -90
  77. data/lib/pdk/generate/defined_type.rb +43 -43
  78. data/lib/pdk/generate/fact.rb +25 -25
  79. data/lib/pdk/generate/function.rb +48 -48
  80. data/lib/pdk/generate/module.rb +352 -352
  81. data/lib/pdk/generate/provider.rb +28 -28
  82. data/lib/pdk/generate/puppet_class.rb +43 -43
  83. data/lib/pdk/generate/puppet_object.rb +232 -232
  84. data/lib/pdk/generate/task.rb +68 -68
  85. data/lib/pdk/generate/transport.rb +33 -33
  86. data/lib/pdk/generate.rb +24 -24
  87. data/lib/pdk/i18n.rb +4 -4
  88. data/lib/pdk/logger.rb +45 -45
  89. data/lib/pdk/module/build.rb +322 -322
  90. data/lib/pdk/module/convert.rb +296 -296
  91. data/lib/pdk/module/metadata.rb +202 -202
  92. data/lib/pdk/module/release.rb +260 -260
  93. data/lib/pdk/module/update.rb +131 -131
  94. data/lib/pdk/module/update_manager.rb +227 -227
  95. data/lib/pdk/module.rb +30 -30
  96. data/lib/pdk/report/event.rb +370 -370
  97. data/lib/pdk/report.rb +121 -121
  98. data/lib/pdk/template/fetcher/git.rb +85 -85
  99. data/lib/pdk/template/fetcher/local.rb +28 -28
  100. data/lib/pdk/template/fetcher.rb +98 -98
  101. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -116
  102. data/lib/pdk/template/renderer/v1/renderer.rb +132 -132
  103. data/lib/pdk/template/renderer/v1/template_file.rb +102 -102
  104. data/lib/pdk/template/renderer/v1.rb +25 -25
  105. data/lib/pdk/template/renderer.rb +96 -96
  106. data/lib/pdk/template/template_dir.rb +67 -67
  107. data/lib/pdk/template.rb +59 -59
  108. data/lib/pdk/tests/unit.rb +252 -252
  109. data/lib/pdk/util/bundler.rb +259 -259
  110. data/lib/pdk/util/changelog_generator.rb +137 -137
  111. data/lib/pdk/util/env.rb +47 -47
  112. data/lib/pdk/util/filesystem.rb +138 -138
  113. data/lib/pdk/util/git.rb +179 -179
  114. data/lib/pdk/util/json_finder.rb +85 -85
  115. data/lib/pdk/util/puppet_strings.rb +125 -125
  116. data/lib/pdk/util/puppet_version.rb +266 -266
  117. data/lib/pdk/util/ruby_version.rb +179 -179
  118. data/lib/pdk/util/template_uri.rb +295 -295
  119. data/lib/pdk/util/vendored_file.rb +93 -93
  120. data/lib/pdk/util/version.rb +43 -43
  121. data/lib/pdk/util/windows/api_types.rb +82 -82
  122. data/lib/pdk/util/windows/file.rb +36 -36
  123. data/lib/pdk/util/windows/process.rb +79 -79
  124. data/lib/pdk/util/windows/string.rb +16 -16
  125. data/lib/pdk/util/windows.rb +15 -15
  126. data/lib/pdk/util.rb +278 -277
  127. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -23
  128. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -98
  129. data/lib/pdk/validate/external_command_validator.rb +208 -208
  130. data/lib/pdk/validate/internal_ruby_validator.rb +100 -100
  131. data/lib/pdk/validate/invokable_validator.rb +228 -228
  132. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -86
  133. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -78
  134. data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -20
  135. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -133
  136. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -66
  137. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -137
  138. data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -21
  139. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -80
  140. data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -19
  141. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -88
  142. data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -50
  143. data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -20
  144. data/lib/pdk/validate/validator.rb +118 -118
  145. data/lib/pdk/validate/validator_group.rb +104 -104
  146. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -95
  147. data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -19
  148. data/lib/pdk/validate.rb +94 -94
  149. data/lib/pdk/version.rb +4 -4
  150. data/lib/pdk.rb +76 -76
  151. data/locales/config.yaml +21 -21
  152. data/locales/pdk.pot +2094 -2094
  153. metadata +5 -6
@@ -1,137 +1,137 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Util
5
- module ChangelogGenerator
6
- # Taken from the version regex in https://forgeapi.puppet.com/schemas/module.json
7
- VERSION_REGEX = %r{^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$}
8
- GEM = 'github_changelog_generator'.freeze
9
-
10
- # Raises if the github_changelog_generator is not available
11
- def self.github_changelog_generator_available!
12
- check_command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, 'show', 'github_changelog_generator')
13
- check_command.context = :module
14
-
15
- result = check_command.execute!
16
-
17
- return if result[:exit_code].zero?
18
-
19
- raise PDK::CLI::ExitWithError, _(
20
- 'Unable to generate the changelog as the %{gem} gem is not included in this module\'s Gemfile',
21
- ) % { gem: GEM }
22
- end
23
-
24
- # Runs the Changelog Generator gem (in the module's context) to automatically create a CHANGLELOG.MD file
25
- #
26
- # @returns [String] The content of the new Changelog
27
- def self.generate_changelog
28
- github_changelog_generator_available!
29
-
30
- changelog_command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, 'exec', 'rake', 'changelog')
31
- changelog_command.context = :module
32
-
33
- result = changelog_command.execute!
34
- raise PDK::CLI::ExitWithError, _('Error generating changelog: %{stdout}' % { stdout: result[:stdout] }) unless result[:exit_code].zero?
35
-
36
- output = changelog_content
37
-
38
- raise PDK::CLI::ExitWithError, _('The generated changelog contains uncategorized Pull Requests. Please label them and try again. See %{changelog_file} for more details' % { changelog_file: changelog_file }) if output =~ %r{UNCATEGORIZED PRS; GO LABEL THEM} # rubocop:disable Metrics/LineLength
39
- output
40
- end
41
-
42
- # Computes the next version, based on the content of a changelog
43
- #
44
- # @param current_version [String, Gem::Version] The current version of the module
45
- # @return [String] The new version. May be the same as the current version if there are no notable changes
46
- def self.compute_next_version(current_version)
47
- raise PDK::CLI::ExitWithError, _('Invalid version string %{version}' % { version: current_version }) unless current_version =~ VERSION_REGEX
48
- version = Gem::Version.create(current_version).segments
49
- PDK.logger.info _('Determing the target version from \'%{file}\'') % { file: changelog_file }
50
-
51
- # Grab all lines that start with ## between from the latest changes
52
- # For example given the changelog below
53
-
54
- # ```
55
- # # Change log
56
- #
57
- # All notable changes to this project will be documented in this file.
58
- #
59
- # ## [v4.0.0](https://github.com/puppetlabs/puppetlabs-inifile/tree/v4.
60
- #
61
- # [Full Changelog](https://github.com/puppetlabs/puppetlabs-inifile/com --+
62
- # |
63
- # ### Changed |
64
- # |
65
- # - pdksync - FM-8499 - remove ubuntu14 support [\#363](https://github. | It's this piece of text we are interested in
66
- # |
67
- # ### Added |
68
- # |
69
- # - FM-8402 add debian 10 support [\#352](https://github.com/puppetlabs |
70
- # |
71
- # ## [v3.1.0](https://github.com/puppetlabs/puppetlabs-inifile/tree/v3. |
72
- # --+
73
- # [Full Changelog](https://github.com/puppetlabs/puppetlabs-inifile/com
74
- #
75
- # ### Added
76
- #
77
- # - FM-8222 - Port Module inifile to Litmus [\#344](https://github.com/
78
- # - \(FM-8154\) Add Windows Server 2019 support [\#340](https://github.
79
- # - \(FM-8041\) Add RedHat 8 support [\#339](https://github.com/puppetl
80
- # ````
81
- data = ''
82
- in_changelog_entry = false
83
- changelog_content.each_line do |line|
84
- line.strip!
85
- if line.start_with?('[')
86
- # We're leaving the latest changes so we can break
87
- break if in_changelog_entry
88
- in_changelog_entry = true
89
- end
90
- if in_changelog_entry && line.start_with?('##')
91
- data += line
92
- end
93
- end
94
-
95
- # Check for meta headers in first two header line matches
96
- if data =~ %r{^### Changed}
97
- # Major Version bump
98
- version[0] += 1
99
- version[1] = 0
100
- version[2] = 0
101
- elsif data =~ %r{^### Added}
102
- # Minor Version bump
103
- version[1] += 1
104
- version[2] = 0
105
- elsif data =~ %r{^### Fixed}
106
- # Patch Version bump
107
- version[2] += 1
108
- end
109
-
110
- version.join('.')
111
- end
112
-
113
- # Returns the top most version from the CHANGELOG file
114
- def self.latest_version
115
- latest = nil
116
- changelog_content.each_line do |line|
117
- line.strip!
118
- if line.start_with?('## [')
119
- latest = line[line.index('[') + 1..line.index(']') - 1].delete('v')
120
- break # stops after the top version is extracted
121
- end
122
- end
123
- latest
124
- end
125
-
126
- def self.changelog_file
127
- # Default Changelog file is CHANGELOG.md, but also search for the .MD prefix as well.
128
- @changelog_file ||= ['CHANGELOG.md', 'CHANGELOG.MD'].map { |file| PDK::Util::Filesystem.expand_path(file) }.find { |path| PDK::Util::Filesystem.file?(path) }
129
- end
130
-
131
- def self.changelog_content
132
- return '' if changelog_file.nil?
133
- PDK::Util::Filesystem.read_file(changelog_file, open_args: 'rb:utf-8')
134
- end
135
- end
136
- end
137
- end
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Util
5
+ module ChangelogGenerator
6
+ # Taken from the version regex in https://forgeapi.puppet.com/schemas/module.json
7
+ VERSION_REGEX = %r{^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$}
8
+ GEM = 'github_changelog_generator'.freeze
9
+
10
+ # Raises if the github_changelog_generator is not available
11
+ def self.github_changelog_generator_available!
12
+ check_command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, 'show', 'github_changelog_generator')
13
+ check_command.context = :module
14
+
15
+ result = check_command.execute!
16
+
17
+ return if result[:exit_code].zero?
18
+
19
+ raise PDK::CLI::ExitWithError, _(
20
+ 'Unable to generate the changelog as the %{gem} gem is not included in this module\'s Gemfile',
21
+ ) % { gem: GEM }
22
+ end
23
+
24
+ # Runs the Changelog Generator gem (in the module's context) to automatically create a CHANGLELOG.MD file
25
+ #
26
+ # @returns [String] The content of the new Changelog
27
+ def self.generate_changelog
28
+ github_changelog_generator_available!
29
+
30
+ changelog_command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, 'exec', 'rake', 'changelog')
31
+ changelog_command.context = :module
32
+
33
+ result = changelog_command.execute!
34
+ raise PDK::CLI::ExitWithError, _('Error generating changelog: %{stdout}' % { stdout: result[:stdout] }) unless result[:exit_code].zero?
35
+
36
+ output = changelog_content
37
+
38
+ raise PDK::CLI::ExitWithError, _('The generated changelog contains uncategorized Pull Requests. Please label them and try again. See %{changelog_file} for more details' % { changelog_file: changelog_file }) if output =~ %r{UNCATEGORIZED PRS; GO LABEL THEM} # rubocop:disable Metrics/LineLength
39
+ output
40
+ end
41
+
42
+ # Computes the next version, based on the content of a changelog
43
+ #
44
+ # @param current_version [String, Gem::Version] The current version of the module
45
+ # @return [String] The new version. May be the same as the current version if there are no notable changes
46
+ def self.compute_next_version(current_version)
47
+ raise PDK::CLI::ExitWithError, _('Invalid version string %{version}' % { version: current_version }) unless current_version =~ VERSION_REGEX
48
+ version = Gem::Version.create(current_version).segments
49
+ PDK.logger.info _('Determing the target version from \'%{file}\'') % { file: changelog_file }
50
+
51
+ # Grab all lines that start with ## between from the latest changes
52
+ # For example given the changelog below
53
+
54
+ # ```
55
+ # # Change log
56
+ #
57
+ # All notable changes to this project will be documented in this file.
58
+ #
59
+ # ## [v4.0.0](https://github.com/puppetlabs/puppetlabs-inifile/tree/v4.
60
+ #
61
+ # [Full Changelog](https://github.com/puppetlabs/puppetlabs-inifile/com --+
62
+ # |
63
+ # ### Changed |
64
+ # |
65
+ # - pdksync - FM-8499 - remove ubuntu14 support [\#363](https://github. | It's this piece of text we are interested in
66
+ # |
67
+ # ### Added |
68
+ # |
69
+ # - FM-8402 add debian 10 support [\#352](https://github.com/puppetlabs |
70
+ # |
71
+ # ## [v3.1.0](https://github.com/puppetlabs/puppetlabs-inifile/tree/v3. |
72
+ # --+
73
+ # [Full Changelog](https://github.com/puppetlabs/puppetlabs-inifile/com
74
+ #
75
+ # ### Added
76
+ #
77
+ # - FM-8222 - Port Module inifile to Litmus [\#344](https://github.com/
78
+ # - \(FM-8154\) Add Windows Server 2019 support [\#340](https://github.
79
+ # - \(FM-8041\) Add RedHat 8 support [\#339](https://github.com/puppetl
80
+ # ````
81
+ data = ''
82
+ in_changelog_entry = false
83
+ changelog_content.each_line do |line|
84
+ line.strip!
85
+ if line.start_with?('[')
86
+ # We're leaving the latest changes so we can break
87
+ break if in_changelog_entry
88
+ in_changelog_entry = true
89
+ end
90
+ if in_changelog_entry && line.start_with?('##')
91
+ data += line
92
+ end
93
+ end
94
+
95
+ # Check for meta headers in first two header line matches
96
+ if data =~ %r{^### Changed}
97
+ # Major Version bump
98
+ version[0] += 1
99
+ version[1] = 0
100
+ version[2] = 0
101
+ elsif data =~ %r{^### Added}
102
+ # Minor Version bump
103
+ version[1] += 1
104
+ version[2] = 0
105
+ elsif data =~ %r{^### Fixed}
106
+ # Patch Version bump
107
+ version[2] += 1
108
+ end
109
+
110
+ version.join('.')
111
+ end
112
+
113
+ # Returns the top most version from the CHANGELOG file
114
+ def self.latest_version
115
+ latest = nil
116
+ changelog_content.each_line do |line|
117
+ line.strip!
118
+ if line.start_with?('## [')
119
+ latest = line[line.index('[') + 1..line.index(']') - 1].delete('v')
120
+ break # stops after the top version is extracted
121
+ end
122
+ end
123
+ latest
124
+ end
125
+
126
+ def self.changelog_file
127
+ # Default Changelog file is CHANGELOG.md, but also search for the .MD prefix as well.
128
+ @changelog_file ||= ['CHANGELOG.md', 'CHANGELOG.MD'].map { |file| PDK::Util::Filesystem.expand_path(file) }.find { |path| PDK::Util::Filesystem.file?(path) }
129
+ end
130
+
131
+ def self.changelog_content
132
+ return '' if changelog_file.nil?
133
+ PDK::Util::Filesystem.read_file(changelog_file, open_args: 'rb:utf-8')
134
+ end
135
+ end
136
+ end
137
+ end
data/lib/pdk/util/env.rb CHANGED
@@ -1,47 +1,47 @@
1
- require 'pdk'
2
- require 'forwardable'
3
-
4
- module PDK
5
- module Util
6
- class Env
7
- class WindowsEnv
8
- extend Forwardable
9
-
10
- # Note, these delegators may not have case insensitive keys
11
- def_delegators :env_hash, :fetch, :select, :reject
12
-
13
- def []=(key, value)
14
- PDK::Util::Windows::Process.set_environment_variable(key, value)
15
- end
16
-
17
- def key?(key)
18
- !env_hash.keys.find { |item| key.casecmp(item).zero? }.nil?
19
- end
20
-
21
- def [](key)
22
- env_hash.each do |item, value|
23
- next unless key.casecmp(item).zero?
24
- return value
25
- end
26
- nil
27
- end
28
-
29
- private
30
-
31
- def env_hash
32
- PDK::Util::Windows::Process.environment_hash
33
- end
34
- end
35
-
36
- class << self
37
- extend Forwardable
38
-
39
- def_delegators :implementation, :key?, :[], :[]=, :fetch, :select, :reject
40
-
41
- def implementation
42
- @implementation ||= Gem.win_platform? ? WindowsEnv.new : ENV
43
- end
44
- end
45
- end
46
- end
47
- end
1
+ require 'pdk'
2
+ require 'forwardable'
3
+
4
+ module PDK
5
+ module Util
6
+ class Env
7
+ class WindowsEnv
8
+ extend Forwardable
9
+
10
+ # Note, these delegators may not have case insensitive keys
11
+ def_delegators :env_hash, :fetch, :select, :reject
12
+
13
+ def []=(key, value)
14
+ PDK::Util::Windows::Process.set_environment_variable(key, value)
15
+ end
16
+
17
+ def key?(key)
18
+ !env_hash.keys.find { |item| key.casecmp(item).zero? }.nil?
19
+ end
20
+
21
+ def [](key)
22
+ env_hash.each do |item, value|
23
+ next unless key.casecmp(item).zero?
24
+ return value
25
+ end
26
+ nil
27
+ end
28
+
29
+ private
30
+
31
+ def env_hash
32
+ PDK::Util::Windows::Process.environment_hash
33
+ end
34
+ end
35
+
36
+ class << self
37
+ extend Forwardable
38
+
39
+ def_delegators :implementation, :key?, :[], :[]=, :fetch, :select, :reject
40
+
41
+ def implementation
42
+ @implementation ||= Gem.win_platform? ? WindowsEnv.new : ENV
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,138 +1,138 @@
1
- require 'pdk'
2
- autoload :FileUtils, 'fileutils'
3
-
4
- module PDK
5
- module Util
6
- module Filesystem
7
- def write_file(path, content)
8
- raise ArgumentError, _('content must be a String') unless content.is_a?(String)
9
- raise ArgumentError, _('path must be a String or Pathname') unless path.is_a?(String) || path.respond_to?(:to_path)
10
-
11
- # Harmonize newlines across platforms.
12
- content = content.encode(universal_newline: true)
13
-
14
- # Make sure all written files have a trailing newline.
15
- content += "\n" unless content[-1] == "\n"
16
-
17
- File.open(path, 'wb') { |f| f.write(content) }
18
- end
19
- module_function :write_file
20
-
21
- def read_file(file, nil_on_error: false, open_args: 'r')
22
- File.read(file, open_args: Array(open_args))
23
- rescue => e
24
- raise e unless nil_on_error
25
- nil
26
- end
27
- module_function :read_file
28
-
29
- #:nocov:
30
- # These methods just wrap core Ruby functionality and
31
- # can be ignored for code coverage
32
- def directory?(*args)
33
- File.directory?(*args)
34
- end
35
- module_function :directory?
36
-
37
- def mkdir_p(*args)
38
- FileUtils.mkdir_p(*args)
39
- end
40
- module_function :mkdir_p
41
-
42
- def file?(*args)
43
- File.file?(*args)
44
- end
45
- module_function :file?
46
-
47
- def expand_path(*args)
48
- File.expand_path(*args)
49
- end
50
- module_function :expand_path
51
-
52
- def glob(*args)
53
- Dir.glob(*args)
54
- end
55
- module_function :glob
56
-
57
- def fnmatch(*args)
58
- File.fnmatch(*args)
59
- end
60
- module_function :fnmatch
61
-
62
- def fnmatch?(*args)
63
- File.fnmatch?(*args)
64
- end
65
- module_function :fnmatch?
66
-
67
- def readable?(*args)
68
- File.readable?(*args)
69
- end
70
- module_function :readable?
71
-
72
- def exist?(*args)
73
- File.exist?(*args)
74
- end
75
- module_function :exist?
76
-
77
- def rm(*args)
78
- FileUtils.rm(*args)
79
- end
80
- module_function :rm
81
-
82
- def rm_f(*args)
83
- FileUtils.rm_f(*args)
84
- end
85
- module_function :rm_f
86
-
87
- def rm_rf(*args)
88
- FileUtils.rm_rf(*args)
89
- end
90
- module_function :rm_rf
91
-
92
- def remove_entry_secure(*args)
93
- FileUtils.remove_entry_secure(*args)
94
- end
95
- module_function :remove_entry_secure
96
-
97
- def zero?(*args)
98
- File.zero?(*args)
99
- end
100
- module_function :zero?
101
-
102
- def stat(*args)
103
- File.stat(*args)
104
- end
105
- module_function :stat
106
-
107
- def symlink?(*args)
108
- File.symlink?(*args)
109
- end
110
- module_function :symlink?
111
-
112
- def cp(*args)
113
- FileUtils.cp(*args)
114
- end
115
- module_function :cp
116
-
117
- def mv(*args)
118
- FileUtils.mv(*args)
119
- rescue Errno::ENOENT
120
- # PDK-1169 - FileUtils.mv raises Errno::ENOENT when moving files inside
121
- # VMWare shared folders on Windows. So we need to catch this
122
- # case, check if the file exists to see if the exception is
123
- # legit and "move" the file with cp & rm.
124
- src, dest, opts = args
125
- raise unless File.exist?(src)
126
-
127
- FileUtils.cp(src, dest, preserve: true)
128
- if (opts ||= {})[:secure]
129
- FileUtils.remove_entry_secure(src, opts[:force])
130
- else
131
- FileUtils.remove_entry(src, opts[:force])
132
- end
133
- end
134
- module_function :mv
135
- #:nocov:
136
- end
137
- end
138
- end
1
+ require 'pdk'
2
+ autoload :FileUtils, 'fileutils'
3
+
4
+ module PDK
5
+ module Util
6
+ module Filesystem
7
+ def write_file(path, content)
8
+ raise ArgumentError, _('content must be a String') unless content.is_a?(String)
9
+ raise ArgumentError, _('path must be a String or Pathname') unless path.is_a?(String) || path.respond_to?(:to_path)
10
+
11
+ # Harmonize newlines across platforms.
12
+ content = content.encode(universal_newline: true)
13
+
14
+ # Make sure all written files have a trailing newline.
15
+ content += "\n" unless content[-1] == "\n"
16
+
17
+ File.open(path, 'wb') { |f| f.write(content) }
18
+ end
19
+ module_function :write_file
20
+
21
+ def read_file(file, nil_on_error: false, open_args: 'r')
22
+ File.read(file, open_args: Array(open_args))
23
+ rescue => e
24
+ raise e unless nil_on_error
25
+ nil
26
+ end
27
+ module_function :read_file
28
+
29
+ #:nocov:
30
+ # These methods just wrap core Ruby functionality and
31
+ # can be ignored for code coverage
32
+ def directory?(*args)
33
+ File.directory?(*args)
34
+ end
35
+ module_function :directory?
36
+
37
+ def mkdir_p(*args)
38
+ FileUtils.mkdir_p(*args)
39
+ end
40
+ module_function :mkdir_p
41
+
42
+ def file?(*args)
43
+ File.file?(*args)
44
+ end
45
+ module_function :file?
46
+
47
+ def expand_path(*args)
48
+ File.expand_path(*args)
49
+ end
50
+ module_function :expand_path
51
+
52
+ def glob(*args)
53
+ Dir.glob(*args)
54
+ end
55
+ module_function :glob
56
+
57
+ def fnmatch(*args)
58
+ File.fnmatch(*args)
59
+ end
60
+ module_function :fnmatch
61
+
62
+ def fnmatch?(*args)
63
+ File.fnmatch?(*args)
64
+ end
65
+ module_function :fnmatch?
66
+
67
+ def readable?(*args)
68
+ File.readable?(*args)
69
+ end
70
+ module_function :readable?
71
+
72
+ def exist?(*args)
73
+ File.exist?(*args)
74
+ end
75
+ module_function :exist?
76
+
77
+ def rm(*args)
78
+ FileUtils.rm(*args)
79
+ end
80
+ module_function :rm
81
+
82
+ def rm_f(*args)
83
+ FileUtils.rm_f(*args)
84
+ end
85
+ module_function :rm_f
86
+
87
+ def rm_rf(*args)
88
+ FileUtils.rm_rf(*args)
89
+ end
90
+ module_function :rm_rf
91
+
92
+ def remove_entry_secure(*args)
93
+ FileUtils.remove_entry_secure(*args)
94
+ end
95
+ module_function :remove_entry_secure
96
+
97
+ def zero?(*args)
98
+ File.zero?(*args)
99
+ end
100
+ module_function :zero?
101
+
102
+ def stat(*args)
103
+ File.stat(*args)
104
+ end
105
+ module_function :stat
106
+
107
+ def symlink?(*args)
108
+ File.symlink?(*args)
109
+ end
110
+ module_function :symlink?
111
+
112
+ def cp(*args)
113
+ FileUtils.cp(*args)
114
+ end
115
+ module_function :cp
116
+
117
+ def mv(*args)
118
+ FileUtils.mv(*args)
119
+ rescue Errno::ENOENT
120
+ # PDK-1169 - FileUtils.mv raises Errno::ENOENT when moving files inside
121
+ # VMWare shared folders on Windows. So we need to catch this
122
+ # case, check if the file exists to see if the exception is
123
+ # legit and "move" the file with cp & rm.
124
+ src, dest, opts = args
125
+ raise unless File.exist?(src)
126
+
127
+ FileUtils.cp(src, dest, preserve: true)
128
+ if (opts ||= {})[:secure]
129
+ FileUtils.remove_entry_secure(src, opts[:force])
130
+ else
131
+ FileUtils.remove_entry(src, opts[:force])
132
+ end
133
+ end
134
+ module_function :mv
135
+ #:nocov:
136
+ end
137
+ end
138
+ end