class Kramdown::PlantUml::Executor

Executes the PlantUML Java application.

Public Class Methods

new() click to toggle source
# File lib/kramdown-plantuml/executor.rb, line 12
def initialize
  @logger = Logger.init
  @plantuml_jar_file = find_plantuml_jar_file

  raise IOError, 'Java can not be found' unless Which.which('java')
  raise IOError, "No 'plantuml.jar' file could be found" if @plantuml_jar_file.nil?
  raise IOError, "'#{@plantuml_jar_file}' does not exist" unless File.exist? @plantuml_jar_file
end

Public Instance Methods

execute(diagram) click to toggle source
# File lib/kramdown-plantuml/executor.rb, line 21
def execute(diagram)
  raise ArgumentError, 'diagram cannot be nil' if diagram.nil?
  raise ArgumentError, "diagram must be a #{Diagram}" unless diagram.is_a?(Diagram)

  cmd = "java -Djava.awt.headless=true -jar #{@plantuml_jar_file} -tsvg -failfast -pipe #{debug_args}"

  @logger.debug " kramdown-plantuml: Executing '#{cmd}'."

  stdout, stderr, status = Open3.capture3 cmd, stdin_data: diagram.plantuml

  @logger.debug " kramdown-plantuml: PlantUML exit code '#{status.exitstatus}'."

  PlantUmlResult.new(diagram, stdout, stderr, status.exitstatus)
end

Private Instance Methods

debug_args() click to toggle source
# File lib/kramdown-plantuml/executor.rb, line 45
def debug_args
  return ' -verbose' if @logger.debug?

  ' -nometadata'
end
find_plantuml_jar_file() click to toggle source
# File lib/kramdown-plantuml/executor.rb, line 38
def find_plantuml_jar_file
  dir = File.dirname __dir__
  jar_glob = File.join dir, '../bin/**/plantuml*.jar'
  first_jar = Dir[jar_glob].first
  File.expand_path first_jar unless first_jar.nil?
end