Class: Sprout::System::JavaUnixSystem

Inherits:
UnixSystem
  • Object
show all
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

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, options='')
  Sprout.stdout.puts("#{tool} #{options}")
  runner = get_and_execute_process_runner(tool, options)
  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.

Raises:

  • (Sprout::Errors::ExecutionError)


41
42
43
44
45
46
# File 'lib/flexpmd/base.rb', line 41

def get_and_execute_process_runner tool, options=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), options
  runner
end