Class: Sprout::System::JavaUnixSystem
- Inherits:
-
UnixSystem
- Object
- UnixSystem
- Sprout::System::JavaUnixSystem
- Defined in:
- lib/flexpmd/base.rb
Overview
Extend the unix system so we can run tools with a ‘java -jar’ prefix.
Instance Method Summary collapse
-
#execute(tool, options = '') ⇒ Object
Creates a new process, executes the command and returns whatever the process wrote to stdout, or stderr.
-
#get_and_execute_process_runner(tool, options = nil) ⇒ Object
Get a process runner and execute the provided
executable
, with the providedoptions
.
Instance Method Details
#execute(tool, options = '') ⇒ Object
Creates a new process, executes the command and returns whatever the process wrote to stdout, or stderr.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/flexpmd/base.rb', line 12 def execute(tool, ='') Sprout.stdout.puts("#{tool} #{}") runner = get_and_execute_process_runner(tool, ) error = runner.read_err result = runner.read if(result.size > 0) Sprout.stdout.puts result end if(error.size > 0) # We expect the process to write to stderror so filter and print it, we don't want Rake # to stop executing. 'WARNING' is consciously supressed as I've not seen it used as a # prefix to anything meaningful. # error.each_line { |line| Sprout.stdout.puts line if line =~ /^(ERROR|INFO):/ } end result || error end |
#get_and_execute_process_runner(tool, options = nil) ⇒ Object
Get a process runner and execute the provided executable
, with the provided options
.
executable
String path to the external executable file.
options
String commandline options to send to the executable
.
41 42 43 44 45 46 |
# File 'lib/flexpmd/base.rb', line 41 def get_and_execute_process_runner tool, =nil runner = get_process_runner raise Sprout::Errors::ExecutionError.new('[ERROR] Java is required for this tool to run.') unless `which java` =~ /java$/ runner.execute_open4 'java -Xms64m -Xmx768m -jar ' + clean_path(tool), runner end |