pdk 0.1.0 → 0.2.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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -0
  3. data/README.md +3 -9
  4. data/exe/pdk +1 -1
  5. data/lib/pdk.rb +5 -4
  6. data/lib/pdk/cli.rb +62 -59
  7. data/lib/pdk/cli/errors.rb +1 -1
  8. data/lib/pdk/cli/exec.rb +154 -29
  9. data/lib/pdk/cli/input.rb +2 -2
  10. data/lib/pdk/cli/new.rb +12 -27
  11. data/lib/pdk/cli/new/class.rb +28 -41
  12. data/lib/pdk/cli/new/module.rb +30 -41
  13. data/lib/pdk/cli/test.rb +9 -20
  14. data/lib/pdk/cli/test/unit.rb +38 -0
  15. data/lib/pdk/cli/util/option_normalizer.rb +45 -19
  16. data/lib/pdk/cli/util/option_validator.rb +24 -20
  17. data/lib/pdk/cli/validate.rb +65 -65
  18. data/lib/pdk/generate.rb +5 -0
  19. data/lib/pdk/generators/module.rb +37 -33
  20. data/lib/pdk/generators/puppet_class.rb +1 -1
  21. data/lib/pdk/generators/puppet_object.rb +19 -20
  22. data/lib/pdk/logger.rb +1 -1
  23. data/lib/pdk/module/metadata.rb +35 -18
  24. data/lib/pdk/module/templatedir.rb +40 -33
  25. data/lib/pdk/report.rb +76 -19
  26. data/lib/pdk/report/event.rb +276 -0
  27. data/lib/pdk/template_file.rb +8 -6
  28. data/lib/pdk/tests/unit.rb +8 -3
  29. data/lib/pdk/util.rb +65 -0
  30. data/lib/pdk/util/bundler.rb +167 -0
  31. data/lib/pdk/util/version.rb +34 -0
  32. data/lib/pdk/validate.rb +3 -4
  33. data/lib/pdk/validators/base_validator.rb +60 -4
  34. data/lib/pdk/validators/metadata.rb +29 -0
  35. data/lib/pdk/validators/puppet/puppet_lint.rb +47 -0
  36. data/lib/pdk/validators/puppet/puppet_parser.rb +34 -0
  37. data/lib/pdk/validators/puppet_validator.rb +30 -0
  38. data/lib/pdk/validators/ruby/rubocop.rb +59 -0
  39. data/lib/pdk/validators/ruby_validator.rb +29 -0
  40. data/lib/pdk/version.rb +1 -1
  41. data/lib/puppet/util/windows.rb +14 -0
  42. data/lib/puppet/util/windows/api_types.rb +278 -0
  43. data/lib/puppet/util/windows/file.rb +488 -0
  44. data/lib/puppet/util/windows/string.rb +16 -0
  45. data/locales/de/pdk.po +263 -78
  46. data/locales/pdk.pot +224 -65
  47. metadata +60 -8
  48. data/lib/pdk/cli/tests/unit.rb +0 -52
  49. data/lib/pdk/validators/puppet_lint.rb +0 -17
  50. data/lib/pdk/validators/puppet_parser.rb +0 -17
  51. data/lib/pdk/validators/ruby_lint.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6475b9cccfedb258b4accc3ce84b407f4f530480
4
- data.tar.gz: 29aeb6521f3b3ee7bd41e2ade024e9a75a79692d
3
+ metadata.gz: f22acd513e00856fbadcd4c5090b2787df655426
4
+ data.tar.gz: 6636287e1acef4c9ba87f52b4b853c922e4ce92b
5
5
  SHA512:
6
- metadata.gz: bead00ff5d38bdf51ea0035b60a1d9a0f4ef111c982e14295dc4dbbe47a2bec0fd9d1d160c3267c98c73fde9ccd9beec9d3e95aae340b12ae9232649c3b27502
7
- data.tar.gz: ac72b4f88da4a89fdda9377e430b040f0cb3dbba59aa4d7f6cfab3879abd3005ac00bdff70ee2b4bc7ea1e307da1b94eccaa62387e8b76fab79487cd563177ba
6
+ metadata.gz: 2ce7e0faffaac9a2484c23dc1e88f9b240e0d768d63c8c793439f9a560a95cfa31a8745b510d4c84b83e410639bae7eb004f9d91732fd7740b4650581f71969a
7
+ data.tar.gz: d7a9e5bae06899f4972add88c8bc49053b257ce7aa10fb38537ea5101ea0e9ceae56e62e212bff6e07e372c558b6f38e9a9dc8ae290a6048d8fb7f72a64ddd0d
data/CHANGELOG.md ADDED
@@ -0,0 +1,50 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+
6
+ ## [v0.2.0](https://github.com/puppetlabs/pdk/tree/v0.2.0) (2017-06-21)
7
+ [Full Changelog](https://github.com/puppetlabs/pdk/compare/v0.1.0...v0.2.0)
8
+
9
+ **Implemented enhancements:**
10
+
11
+ - \(SDK-137\) Adds Puppet Parser syntax validation [\#94](https://github.com/puppetlabs/pdk/pull/94) ([bmjen](https://github.com/bmjen))
12
+ - \(SDK-274\) Adds --version option [\#90](https://github.com/puppetlabs/pdk/pull/90) ([bmjen](https://github.com/bmjen))
13
+ - \(SDK-244\) Add rubocop validation subcommand [\#75](https://github.com/puppetlabs/pdk/pull/75) ([rodjek](https://github.com/rodjek))
14
+ - \(maint\) Add hints for gem installation [\#74](https://github.com/puppetlabs/pdk/pull/74) ([DavidS](https://github.com/DavidS))
15
+ - \(SDK-240\) Adds puppet-lint validation subcommand [\#71](https://github.com/puppetlabs/pdk/pull/71) ([bmjen](https://github.com/bmjen))
16
+ - \(SDK-261\) Manage basic bundler operations for module dev [\#62](https://github.com/puppetlabs/pdk/pull/62) ([scotje](https://github.com/scotje))
17
+ - \(SDK-232\) Add operatingsystem\_support defaults [\#58](https://github.com/puppetlabs/pdk/pull/58) ([DavidS](https://github.com/DavidS))
18
+
19
+ **Fixed bugs:**
20
+
21
+ - pdk expects missing git binaries [\#61](https://github.com/puppetlabs/pdk/issues/61)
22
+ - \(maint\) avoid interfering with local ruby configs [\#86](https://github.com/puppetlabs/pdk/pull/86) ([DavidS](https://github.com/DavidS))
23
+ - \(SDK-262\) Populate default metadata to match interview defaults [\#63](https://github.com/puppetlabs/pdk/pull/63) ([rodjek](https://github.com/rodjek))
24
+ - \(maint\) nokogiri: avoid versions without ruby 2.1 support [\#60](https://github.com/puppetlabs/pdk/pull/60) ([DavidS](https://github.com/DavidS))
25
+
26
+ ## [v0.1.0](https://github.com/puppetlabs/pdk/tree/v0.1.0) (2017-06-05)
27
+ [Full Changelog](https://github.com/puppetlabs/pdk/compare/2be9329bed4715c888f273814b99f2cf37ee9341...v0.1.0)
28
+
29
+ **Implemented enhancements:**
30
+
31
+ - \(maint\) update Contributing section [\#56](https://github.com/puppetlabs/pdk/pull/56) ([DavidS](https://github.com/DavidS))
32
+ - \(SDK-197\) Add 'new class' generator command [\#48](https://github.com/puppetlabs/pdk/pull/48) ([rodjek](https://github.com/rodjek))
33
+ - \(SDK-201\) Add 'new module' generator command [\#41](https://github.com/puppetlabs/pdk/pull/41) ([rodjek](https://github.com/rodjek))
34
+ - \(maint\) make debug output optional [\#40](https://github.com/puppetlabs/pdk/pull/40) ([rodjek](https://github.com/rodjek))
35
+ - \(maint\) Print help for 'new' command if no type provided [\#35](https://github.com/puppetlabs/pdk/pull/35) ([rodjek](https://github.com/rodjek))
36
+ - \(SDK-214\) Add gettext and externalize strings [\#32](https://github.com/puppetlabs/pdk/pull/32) ([scotje](https://github.com/scotje))
37
+ - \(SDK-178\) interactive license and module name query [\#30](https://github.com/puppetlabs/pdk/pull/30) ([DavidS](https://github.com/DavidS))
38
+ - \(SDK-200\) Add user interview for `new module` info gathering [\#26](https://github.com/puppetlabs/pdk/pull/26) ([whopper](https://github.com/whopper))
39
+ - \(maint\) Replace --report-\* options with --format. [\#24](https://github.com/puppetlabs/pdk/pull/24) ([whopper](https://github.com/whopper))
40
+ - \(SDK-191\) Allow validators and targets as arguments rather than options [\#22](https://github.com/puppetlabs/pdk/pull/22) ([whopper](https://github.com/whopper))
41
+ - \(SDK-185\) Include the command in usage help output [\#19](https://github.com/puppetlabs/pdk/pull/19) ([james-stocks](https://github.com/james-stocks))
42
+
43
+ **Fixed bugs:**
44
+
45
+ - \(maint\) use correct basedir for windows execs [\#51](https://github.com/puppetlabs/pdk/pull/51) ([DavidS](https://github.com/DavidS))
46
+ - \(maint\) Update pdk.gemspec to not depend on git to assign files. [\#27](https://github.com/puppetlabs/pdk/pull/27) ([scotje](https://github.com/scotje))
47
+
48
+
49
+
50
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # pdk [![Travis Build Status](https://travis-ci.com/puppetlabs/pdk.svg?token=kFfyquZWxwxpgSetpypR&branch=master)](https://travis-ci.com/puppetlabs/pdk) [![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/x70e2fqllbaootpd?svg=true)](https://ci.appveyor.com/project/puppetlabs/pdk)
1
+ # pdk [![Build Status](https://travis-ci.org/puppetlabs/pdk.svg?branch=master)](https://travis-ci.org/puppetlabs/pdk) [![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/x70e2fqllbaootpd?svg=true)](https://ci.appveyor.com/project/puppetlabs/pdk)
2
2
 
3
3
 
4
4
  A CLI to facilitate easy, unified development workflows for Puppet modules. pdk is a key part of the Puppet Development Kit, the shortest path to better modules.
@@ -11,6 +11,8 @@ A CLI to facilitate easy, unified development workflows for Puppet modules. pdk
11
11
  $ gem install pdk
12
12
  ```
13
13
 
14
+ For default usage, you'll also need to have `git`, and `bundle` (from [bundler](http://bundler.io/)) on your system PATH.
15
+
14
16
  ## Usage
15
17
 
16
18
  ### Generate a new module
@@ -252,14 +254,6 @@ Specifies options to pass through to the actual test-runner. In the default temp
252
254
 
253
255
  ## Contributing
254
256
 
255
- To run the `pdk` tool directly from the repository, set the environment variable `PDK_USE_SYSTEM_BINARIES` to `true`. This causes it to use the system installed binaries, instead of relying on the puppet-sdk-vanagon packaging. Currently required is a ruby (2.1, or later), and git.
256
-
257
- ```
258
- PowerShell: $env:PDK_USE_SYSTEM_BINARIES = "true"
259
- cmd.exe: set PDK_USE_SYSTEM_BINARIES=true
260
- bash: export PDK_USE_SYSTEM_BINARIES=true
261
- ```
262
-
263
257
  In cases where `pdk` needs to run in a working directory outside the cloned repository, either set `BUNDLE_GEMFILE` to the pdk's Gemfile location, or install and use the [binstubs of bundler](http://bundler.io/v1.15/bundle_binstubs.html), which are small proxy binaries, that set up the environment for running the tool.
264
258
 
265
259
  ```
data/exe/pdk CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'pdk/cli'
4
4
 
5
- PDK::CLI.run(ARGV.dup)
5
+ PDK::CLI.run(ARGV)
data/lib/pdk.rb CHANGED
@@ -1,8 +1,9 @@
1
- require 'pdk/version'
2
- require 'pdk/logger'
3
- require 'pdk/i18n'
4
1
  require 'pdk/generate'
5
- require 'pdk/validate'
2
+ require 'pdk/i18n'
3
+ require 'pdk/logger'
6
4
  require 'pdk/report'
5
+ require 'pdk/template_file'
6
+ require 'pdk/validate'
7
+ require 'pdk/version'
7
8
 
8
9
  module PDK; end
data/lib/pdk/cli.rb CHANGED
@@ -1,80 +1,83 @@
1
1
  require 'cri'
2
2
 
3
3
  require 'pdk/cli/errors'
4
- require 'pdk/cli/util/option_validator'
5
4
  require 'pdk/cli/util/option_normalizer'
5
+ require 'pdk/cli/util/option_validator'
6
+ require 'pdk/generators/module'
7
+ require 'pdk/i18n'
6
8
  require 'pdk/logger'
7
9
  require 'pdk/report'
10
+ require 'pdk/util/version'
8
11
 
9
- require 'pdk/cli/new'
10
- require 'pdk/cli/validate'
11
- require 'pdk/cli/test'
12
-
13
- module PDK
14
- module CLI
15
- def self.base_command
16
- @base ||= Cri::Command.new.tap do |cmd|
17
- cmd.modify do
18
- name 'pdk'
19
- usage _("pdk command [options]")
20
- summary _("Puppet Development Kit")
21
- description _("The shortest path to better modules.")
22
-
23
- flag :h, :help, _("show help for this command") do |_, c|
24
- puts c.help
25
- exit 0
26
- end
12
+ module PDK::CLI
13
+ def self.run(args)
14
+ @base_cmd.run(args)
15
+ rescue PDK::CLI::FatalError => e
16
+ PDK.logger.fatal(e.message) if e.message
27
17
 
28
- format_desc = _(
29
- "Specify desired output format. Valid formats are '%{available_formats}'. " +
30
- "You may also specify a file to which the formatted output will be directed, " +
31
- "for example: '--format=junit:report.xml'. This option may be specified " +
32
- "multiple times as long as each option specifies a distinct target file."
33
- ) % {available_formats: PDK::Report.formats.join("', '")}
18
+ # If FatalError was raised as the result of another exception, send the
19
+ # details of that exception to the debug log. If there was no cause
20
+ # (FatalError raised on its own outside a rescue block), send the details
21
+ # of the FatalError exception to the debug log.
22
+ cause = e.cause
23
+ if cause.nil?
24
+ e.backtrace.each { |line| PDK.logger.debug(line) }
25
+ else
26
+ PDK.logger.debug("#{cause.class}: #{cause.message}")
27
+ cause.backtrace.each { |line| PDK.logger.debug(line) }
28
+ end
34
29
 
35
- option :f, :format, format_desc, { argument: :required, multiple: true } do |values|
36
- values.compact.each do |v|
37
- if v.include?(':')
38
- format = v.split(':', 2).first
30
+ exit e.exit_code
31
+ end
39
32
 
40
- PDK::CLI::Util::OptionValidator.enum(format, PDK::Report.formats)
41
- else
42
- PDK::CLI::Util::OptionValidator.enum(v, PDK::Report.formats)
43
- end
44
- end
45
- end
33
+ def self.template_url_option(dsl)
34
+ dsl.option nil, 'template-url', _('Specifies the URL to the template to use when creating new modules, and other parts.'), argument: :required, default: PDK::Generate::Module::DEFAULT_TEMPLATE
35
+ end
46
36
 
47
- flag :d, :debug, _("Enable debug output.") do |_, _|
48
- PDK.logger.enable_debug_output
49
- end
50
- end
37
+ @base_cmd = Cri::Command.define do
38
+ name 'pdk'
39
+ usage _('pdk command [options]')
40
+ summary _('Puppet Development Kit')
41
+ description _('The shortest path to better modules.')
42
+ default_subcommand 'help'
51
43
 
52
- cmd.add_command(Cri::Command.new_basic_help)
44
+ flag nil, :version, _('show version of pdk') do |_, _|
45
+ puts PDK::Util::Version.version_string
46
+ exit 0
47
+ end
53
48
 
54
- cmd.add_command(PDK::CLI::New.command)
55
- cmd.add_command(PDK::CLI::Validate.command)
56
- cmd.add_command(PDK::CLI::Test.command)
57
- end
49
+ flag :h, :help, _('show help for this command') do |_, c|
50
+ puts c.help
51
+ exit 0
58
52
  end
59
53
 
60
- def self.run(args)
61
- base_command.run(args)
62
- rescue PDK::CLI::FatalError => e
63
- PDK.logger.fatal(e.message) if e.message
54
+ format_desc = _(
55
+ "Specify desired output format. Valid formats are '%{available_formats}'. " \
56
+ 'You may also specify a file to which the formatted output will be directed, ' \
57
+ "for example: '--format=junit:report.xml'. This option may be specified " \
58
+ 'multiple times as long as each option specifies a distinct target file.',
59
+ ) % { available_formats: PDK::Report.formats.join("', '") }
64
60
 
65
- # If FatalError was raised as the result of another exception, send the
66
- # details of that exception to the debug log. If there was no cause
67
- # (FatalError raised on its own outside a rescue block), send the details
68
- # of the FatalError exception to the debug log.
69
- cause = e.cause
70
- if cause.nil?
71
- e.backtrace.each { |line| PDK.logger.debug(line) }
72
- else
73
- PDK.logger.debug("#{cause.class}: #{cause.message}")
74
- cause.backtrace.each { |line| PDK.logger.debug(line) }
61
+ option :f, :format, format_desc, argument: :required, multiple: true do |values|
62
+ values.compact.each do |v|
63
+ if v.include?(':')
64
+ format = v.split(':', 2).first
65
+
66
+ Util::OptionValidator.enum(format, PDK::Report.formats)
67
+ else
68
+ Util::OptionValidator.enum(v, PDK::Report.formats)
69
+ end
75
70
  end
71
+ end
76
72
 
77
- exit e.exit_code
73
+ flag :d, :debug, _('Enable debug output.') do |_, _|
74
+ PDK.logger.enable_debug_output
78
75
  end
79
76
  end
77
+
78
+ require 'pdk/cli/new'
79
+ require 'pdk/cli/test'
80
+ require 'pdk/cli/validate'
81
+
82
+ @base_cmd.add_command Cri::Command.new_basic_help
80
83
  end
@@ -3,7 +3,7 @@ module PDK
3
3
  class FatalError < StandardError
4
4
  attr_reader :exit_code
5
5
 
6
- def initialize(msg = _("An unexpected error has occurred, try running the command again with --debug"), exit_code=1)
6
+ def initialize(msg = _('An unexpected error has occurred, try running the command again with --debug'), exit_code = 1)
7
7
  @exit_code = exit_code
8
8
  super(msg)
9
9
  end
data/lib/pdk/cli/exec.rb CHANGED
@@ -1,50 +1,175 @@
1
+ require 'bundler'
1
2
  require 'childprocess'
2
3
  require 'tempfile'
4
+ require 'tty-spinner'
3
5
 
4
6
  module PDK
5
7
  module CLI
6
8
  module Exec
7
- # TODO: decide how to handle multiple output targets when underlying tool doesn't support that
8
- # TODO: decide what this method should return
9
- # TODO: decide how/when to connect stdin to child process for things like pry
10
9
  def self.execute(*cmd)
11
- process = ChildProcess.build(*cmd)
10
+ Command.new(*cmd).execute!
11
+ end
12
12
 
13
- process.io.stdout = Tempfile.new('stdout')
14
- process.io.stderr = Tempfile.new('stderr')
13
+ def self.pdk_basedir
14
+ @pdk_basedir ||= Gem.win_platform? ? 'C:/Program Files/Puppet Labs/DevelopmentKit' : '/opt/puppetlabs/sdk'
15
+ end
15
16
 
16
- begin
17
- # start the process
18
- process.start
17
+ def self.git_bindir
18
+ @git_dir ||= File.join(pdk_basedir, 'private', 'git', Gem.win_platform? ? 'cmd' : 'bin')
19
+ end
19
20
 
20
- # wait indefinitely for process to exit...
21
- process.wait
21
+ def self.git(*args)
22
+ git_bin = Gem.win_platform? ? 'git.exe' : 'git'
23
+ vendored_bin_path = File.join(git_bindir, git_bin)
22
24
 
23
- stdout = process.io.stdout.open.read
24
- stderr = process.io.stderr.open.read
25
- ensure
26
- process.io.stdout.close
27
- process.io.stderr.close
28
- end
25
+ execute(try_vendored_bin(vendored_bin_path, git_bin), *args)
26
+ end
27
+
28
+ def self.bundle(*args)
29
+ bundle_bin = Gem.win_platform? ? 'bundle.bat' : 'bundle'
30
+ vendored_bin_path = File.join(pdk_basedir, 'private', 'ruby', '2.1.9', 'bin', bundle_bin)
29
31
 
30
- {
31
- :exit_code => process.exit_code,
32
- :stdout => stdout,
33
- :stderr => stderr
34
- }
32
+ execute(try_vendored_bin(vendored_bin_path, bundle_bin), *args)
35
33
  end
36
34
 
37
- def self.pdk_basedir
38
- @pdk_basedir ||= Gem.win_platform? ? 'C:/Program Files/Puppet Labs/DevelopmentKit' : '/opt/puppetlabs/sdk'
35
+ def self.bundle_bin
36
+ bundle_bin = Gem.win_platform? ? 'bundle.bat' : 'bundle'
37
+ vendored_bin_path = File.join(pdk_basedir, 'private', 'ruby', '2.1.9', 'bin', bundle_bin)
38
+
39
+ try_vendored_bin(vendored_bin_path, bundle_bin)
39
40
  end
40
41
 
41
- def self.git_bindir
42
- @git_dir ||= File.join(pdk_basedir, 'private', 'git', 'bin')
42
+ def self.try_vendored_bin(vendored_bin_path, fallback)
43
+ if File.exist?(vendored_bin_path)
44
+ PDK.logger.debug(_("Using '%{vendored_bin_path}'") % { fallback: fallback, vendored_bin_path: vendored_bin_path })
45
+ vendored_bin_path
46
+ else
47
+ PDK.logger.debug(_("Trying '%{fallback}' from the system PATH, instead of '%{vendored_bin_path}'") % { fallback: fallback, vendored_bin_path: vendored_bin_path })
48
+ fallback
49
+ end
43
50
  end
44
51
 
45
- def self.git(*args)
46
- git_path = ENV['PDK_USE_SYSTEM_BINARIES'].nil? ? File.join(git_bindir, 'git') : 'git'
47
- execute(git_path, *args)
52
+ # TODO: decide how/when to connect stdin to child process for things like pry
53
+ # TODO: need a way to set callbacks on new stdout/stderr data
54
+ class Command
55
+ attr_reader :argv
56
+ attr_reader :context
57
+ attr_accessor :timeout
58
+
59
+ def initialize(*argv)
60
+ @argv = argv
61
+
62
+ @process = ChildProcess.build(*@argv)
63
+ @process.leader = true
64
+
65
+ @stdout = Tempfile.new('stdout').tap { |io| io.sync = true }
66
+ @stderr = Tempfile.new('stderr').tap { |io| io.sync = true }
67
+
68
+ @process.io.stdout = @stdout
69
+ @process.io.stderr = @stderr
70
+
71
+ # Default to running things in the system context.
72
+ @context = :system
73
+ end
74
+
75
+ def context=(new_context)
76
+ unless [:system, :module].include?(new_context)
77
+ raise ArgumentError, _("Expected execution context to be :system or :module but got '%{context}'") % { context: new_contenxt }
78
+ end
79
+
80
+ @context = new_context
81
+ end
82
+
83
+ def add_spinner(message, opts = {})
84
+ @success_message = opts.delete(:success)
85
+ @failure_message = opts.delete(:failure)
86
+
87
+ @spinner = TTY::Spinner.new("[:spinner] #{message}", opts)
88
+ end
89
+
90
+ def execute!
91
+ # Start spinning if configured.
92
+ @spinner.auto_spin if @spinner
93
+
94
+ if context == :module
95
+ # TODO: we should probably more carefully manage PATH and maybe other things too
96
+ @process.environment['GEM_HOME'] = File.join(PDK::Util.cachedir, 'bundler', 'ruby', RbConfig::CONFIG['ruby_version'])
97
+ @process.environment['GEM_PATH'] = pdk_gem_path
98
+
99
+ Dir.chdir(PDK::Util.module_root) do
100
+ ::Bundler.with_clean_env do
101
+ run_process!
102
+ end
103
+ end
104
+ else
105
+ run_process!
106
+ end
107
+
108
+ # Stop spinning when done (if configured).
109
+ if @spinner
110
+ if @process.exit_code.zero?
111
+ @spinner.success(@success_message || '')
112
+ else
113
+ @spinner.error(@failure_message || '')
114
+ end
115
+ end
116
+
117
+ @stdout.rewind
118
+ @stderr.rewind
119
+
120
+ process_data = {
121
+ stdout: @stdout.read,
122
+ stderr: @stderr.read,
123
+ exit_code: @process.exit_code,
124
+ }
125
+
126
+ return process_data
127
+ ensure
128
+ @stdout.close
129
+ @stderr.close
130
+ end
131
+
132
+ protected
133
+
134
+ def run_process!
135
+ begin
136
+ @process.start
137
+ rescue ChildProcess::LaunchError => e
138
+ msg = if @process.respond_to?(:argv)
139
+ _("Failed to execute '%{command}': %{message}") % { command: @process.argv.join(' '), message: e.message }
140
+ else
141
+ _('Failed to execute process: %{message}') % { message: e.message }
142
+ end
143
+ raise PDK::CLI::FatalError, msg
144
+ end
145
+
146
+ if timeout
147
+ begin
148
+ @process.poll_for_exit(timeout)
149
+ rescue ChildProcess::TimeoutError
150
+ @process.stop # tries increasingly harsher methods to kill the process.
151
+ end
152
+ else
153
+ # Wait indfinitely if no timeout set.
154
+ @process.wait
155
+ end
156
+ end
157
+
158
+ def pdk_gem_path
159
+ @pdk_gem_path ||= find_pdk_gem_path
160
+ end
161
+
162
+ def find_pdk_gem_path
163
+ # /opt/puppetlabs/sdk/private/ruby/2.1.9/lib/ruby/gems/2.1.0
164
+ package_gem_path = File.join(PDK::CLI::Exec.pdk_basedir, 'private', 'ruby', RUBY_VERSION, 'lib', 'ruby', 'gems', RbConfig::CONFIG['ruby_version'])
165
+
166
+ if File.directory?(package_gem_path)
167
+ package_gem_path
168
+ else
169
+ # FIXME: calculate this more reliably
170
+ File.absolute_path(File.join(`bundle show bundler`, '..', '..'))
171
+ end
172
+ end
48
173
  end
49
174
  end
50
175
  end