Class: Jing

Inherits:
Object
  • Object
show all
Defined in:
lib/tebako-runtime/adapters/jing.rb

Overview

Unpack jing.jar

Constant Summary collapse

DEFAULT_JAR =
TebakoRuntime.extract_memfs(tmp)

Instance Method Summary collapse

Constructor Details

#initialize(schema, options = nil) ⇒ Jing

Returns a new instance of Jing.



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/tebako-runtime/adapters/jing.rb', line 37

def initialize(schema, options = nil)
  original_initialize(TebakoRuntime.extract_memfs(schema, wild: true), options)
  # ruby-jing captures `:default => DEFAULT_JAR` at class-load time —
  # before this adapter replaced the constant with the extracted host
  # path. Force the extracted path per-instance (a nil option hash
  # leaves @options empty, and the builder's stale default would win).
  @options[:jar] = DEFAULT_JAR
  # The mounted openjdk toolkit payload's java wins over PATH (the
  # memfs-binary exec path; the bare "java" keeps the PATH answer).
  @options[:java] = TebakoRuntime.mounted_exe("openjdk", "java")
end

Instance Method Details

#execute(options) ⇒ Object

The spawn shape, array form (the stock execute() backticks a shell string, which the tebako spawn hook deliberately skips; the mounted java only execs through the hook from an absolute-path array spawn).



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tebako-runtime/adapters/jing.rb', line 56

def execute(options) # rubocop:disable Metrics/AbcSize
  cmd = [options[:java]]
  cmd += options[:java_opts].split if options[:java_opts]
  cmd += ["-jar", options[:jar].to_s]
  cmd << "-c" if options[:compact]
  cmd += ["-e", options[:encoding]] if options[:encoding]
  cmd << "-i" if options[:id_check]
  cmd += [options[:schema].to_s, options[:xmlfile].to_s]
  IO.popen(cmd, err: %i[child out], &:read)
rescue SystemCallError => e
  raise ExecutionError, "jing execution failed: #{e}"
end

#original_initializeObject



34
# File 'lib/tebako-runtime/adapters/jing.rb', line 34

alias original_initialize initialize

#original_validateObject



35
# File 'lib/tebako-runtime/adapters/jing.rb', line 35

alias original_validate validate

#validate(xml) ⇒ Object



49
50
51
# File 'lib/tebako-runtime/adapters/jing.rb', line 49

def validate(xml)
  original_validate(TebakoRuntime.extract_memfs(xml))
end