Class: Kramdown::PlantUml::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/kramdown-plantuml/executor.rb

Overview

Executes the PlantUML Java application.

Instance Method Summary collapse

Constructor Details

#initializeExecutor

Returns a new instance of Executor.

Raises:

  • (IOError)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kramdown-plantuml/executor.rb', line 12

def initialize
  @logger = LogWrapper.init

  java_location = Which.which('java')

  raise IOError, 'Java can not be found' if java_location.nil?

  @logger.debug "Java found: #{java_location}"
  @plantuml_jar_file = find_plantuml_jar_file

  raise IOError, "'#{@plantuml_jar_file}' does not exist" unless File.exist? @plantuml_jar_file

  @logger.debug "plantuml.jar found: #{@plantuml_jar_file}"
end

Instance Method Details

#execute(diagram) ⇒ Object

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/kramdown-plantuml/executor.rb', line 27

def execute(diagram)
  raise ArgumentError, 'diagram cannot be nil' if diagram.nil?
  raise ArgumentError, "diagram must be a #{PlantUmlDiagram}" unless diagram.is_a?(PlantUmlDiagram)

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

  @logger.debug "Executing '#{cmd}'."

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

  @logger.debug "PlantUML exit code '#{status.exitstatus}'."

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