Class: PmdTester::Cmd
- Inherits:
-
Object
- Object
- PmdTester::Cmd
- Extended by:
- PmdTester
- Defined in:
- lib/pmdtester/cmd.rb
Overview
Containing the common method for executing shell command
Constant Summary
Constants included from PmdTester
BASE, PATCH, PR_NUM_ENV_VAR, VERSION
Class Method Summary collapse
-
.execute(cmd, debug_log_stdout: true) ⇒ Object
Executes the given command and returns the process status, stdout and stderr.
-
.execute_save_output(cmd, path) ⇒ Object
Executes the given command and returns the process status.
- .execute_successfully(cmd, extra_java_home = nil, debug_log_stdout: true) ⇒ Object
- .stderr_of(cmd) ⇒ Object
Methods included from PmdTester
Class Method Details
.execute(cmd, debug_log_stdout: true) ⇒ Object
Executes the given command and returns the process status, stdout and stderr.
14 15 16 17 |
# File 'lib/pmdtester/cmd.rb', line 14 def self.execute(cmd, debug_log_stdout: true) stdout, stderr, status = internal_execute(cmd, nil, debug_log_stdout) [status, stdout, stderr] end |
.execute_save_output(cmd, path) ⇒ Object
Executes the given command and returns the process status. stdout and stderr are written to the files “stdout.txt” and “stderr.txt” in path.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pmdtester/cmd.rb', line 24 def self.execute_save_output(cmd, path) stdout, stderr, status = internal_execute(cmd, nil, true) file = File.new("#{path}/stdout.txt", 'w') file.puts stdout file.close file = File.new("#{path}/stderr.txt", 'w') file.puts stderr file.close status end |
.execute_successfully(cmd, extra_java_home = nil, debug_log_stdout: true) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pmdtester/cmd.rb', line 38 def self.execute_successfully(cmd, extra_java_home = nil, debug_log_stdout: true) stdout, stderr, status = internal_execute(cmd, extra_java_home, debug_log_stdout) unless status.success? logger.error "Command failed: #{cmd}" logger.error stdout logger.error stderr raise CmdException.new(cmd, stdout, stderr, status) end stdout end |
.stderr_of(cmd) ⇒ Object
51 52 53 54 |
# File 'lib/pmdtester/cmd.rb', line 51 def self.stderr_of(cmd) _stdout, stderr, _status = internal_execute(cmd, nil, true) stderr end |