Class: Asciidoctor::Diagram::Java::CommandServer

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor-diagram/util/java_socket.rb

Instance Method Summary collapse

Constructor Details

#initialize(java, classpath) ⇒ CommandServer

Returns a new instance of CommandServer.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/asciidoctor-diagram/util/java_socket.rb', line 16

def initialize(java, classpath)
  classpath.each do |file|
    raise "Classpath item #{file} does not exist" unless File.exist?(file)
  end

  args = []
  args << '-Djava.awt.headless=true'
  args << '-Djava.net.useSystemProxies=true'
  args << '-Dfile.encoding=UTF-8'
  args << '-cp'
  args << classpath.flatten.map { |jar| ::Asciidoctor::Diagram::Platform.host_os_path(jar).strip }.join(::Asciidoctor::Diagram::Platform.host_os_path_separator)
  args << 'org.asciidoctor.diagram.StdInOutCommandServer'

  @server = IO.popen([java, *args], 'r+b')
end

Instance Method Details

#ioObject



32
33
34
# File 'lib/asciidoctor-diagram/util/java_socket.rb', line 32

def io
  @server
end

#shutdownObject



36
37
38
39
40
# File 'lib/asciidoctor-diagram/util/java_socket.rb', line 36

def shutdown
  # KILL is a bit heavy handed, but TERM does not seem to shut down the JVM on Windows.
  Process.kill('KILL', @server.pid)
  @server.close
end