Class: Kramdown::PlantUml::Executor
- Defined in:
- lib/kramdown-plantuml/executor.rb
Overview
Executes the PlantUML Java application.
Instance Method Summary collapse
- #execute(diagram) ⇒ Object
-
#initialize ⇒ Executor
constructor
A new instance of Executor.
Constructor Details
#initialize ⇒ Executor
Returns a new instance of Executor.
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
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 |