asciidoctor-diagram 1.5.1 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +12 -0
- data/README.adoc +4 -1
- data/lib/asciidoctor-diagram.rb +1 -0
- data/lib/asciidoctor-diagram/blockdiag/extension.rb +5 -4
- data/lib/asciidoctor-diagram/erd.rb +7 -0
- data/lib/asciidoctor-diagram/erd/extension.rb +43 -0
- data/lib/asciidoctor-diagram/extensions.rb +9 -5
- data/lib/asciidoctor-diagram/graphviz/extension.rb +2 -1
- data/lib/asciidoctor-diagram/meme/extension.rb +4 -4
- data/lib/asciidoctor-diagram/mermaid/extension.rb +4 -2
- data/lib/asciidoctor-diagram/plantuml/extension.rb +1 -1
- data/lib/asciidoctor-diagram/shaape/extension.rb +2 -1
- data/lib/asciidoctor-diagram/util/cli.rb +19 -0
- data/lib/asciidoctor-diagram/util/cli_generator.rb +5 -15
- data/lib/asciidoctor-diagram/util/java.rb +1 -1
- data/lib/asciidoctor-diagram/util/java_socket.rb +96 -28
- data/lib/asciidoctor-diagram/util/platform.rb +35 -14
- data/lib/asciidoctor-diagram/version.rb +1 -1
- data/lib/asciidoctor-diagram/wavedrom/extension.rb +3 -2
- data/spec/blockdiag_spec.rb +15 -15
- data/spec/ditaa_spec.rb +14 -14
- data/spec/erd_spec.rb +289 -0
- data/spec/graphviz_spec.rb +12 -12
- data/spec/meme_spec.rb +6 -6
- data/spec/mermaid_spec.rb +22 -22
- data/spec/plantuml_spec.rb +78 -42
- data/spec/shaape_spec.rb +15 -15
- data/spec/test_helper.rb +8 -3
- data/spec/wavedrom_spec.rb +18 -18
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7c8a0442a43c4f2b062c9a2875db9bfe487ebfe
|
4
|
+
data.tar.gz: e5ed8001a95d21ff5461ab9adf71b679dcdeb8c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9261c02e0ce34b5b532352d5c8816f682c4cea2e352e90c7a8ac51909ed1295da58f4b337e41a852a63469bf9280596b8d11e321d8a7587f2a8e77e38274967e
|
7
|
+
data.tar.gz: 3540b311b595776f6bac442827a077fcfeefbd24e50ee8fbe58d9a756633213bd4a02336847fcda91647dd6feb2c113d701506859ec6c61dc3660b3e073d4762
|
data/CHANGELOG.adoc
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
== Development
|
4
4
|
|
5
|
+
== 1.5.2
|
6
|
+
|
7
|
+
Enhancements::
|
8
|
+
|
9
|
+
* Apply anti-aliasing to blockdiag generated images
|
10
|
+
* Issue #118: Add support for Erd.
|
11
|
+
|
12
|
+
Bug Fixes::
|
13
|
+
|
14
|
+
* Issue #125: Use correct path separator when running under Cygwin.
|
15
|
+
* Issue #127: Resolved Ruby warnings when running in verbose mode.
|
16
|
+
|
5
17
|
== 1.5.1
|
6
18
|
|
7
19
|
Bug Fixes::
|
data/README.adoc
CHANGED
@@ -19,6 +19,7 @@ ifndef::env-site[:status:]
|
|
19
19
|
:uri-blockdiag: http://blockdiag.com
|
20
20
|
:uri-ditaa: http://ditaa.sourceforge.net/
|
21
21
|
:uri-dot: http://www.graphviz.org/content/dot-language
|
22
|
+
:uri-erd: https://github.com/BurntSushi/erd
|
22
23
|
:uri-graphviz: http://www.graphviz.org
|
23
24
|
:uri-imagemagick: http://www.imagemagick.org
|
24
25
|
:uri-java: http://java.sun.com
|
@@ -108,6 +109,7 @@ The following diagram types and output formats are available:
|
|
108
109
|
|{uri-actdiag}[actdiag] | |{check}|{check}|
|
109
110
|
|{uri-blockdiag}[blockdiag] | |{check}|{check}|
|
110
111
|
|{uri-ditaa}[ditaa] | |{check}| |
|
112
|
+
|{uri-erd}[erd] | |{check}|{check}|
|
111
113
|
|{uri-dot}[graphviz] | |{check}|{check}|
|
112
114
|
|<<meme,meme>> |{check}|{check}| |
|
113
115
|
|{uri-mermaid}[mermaid] | |{check}|{check}|
|
@@ -229,7 +231,7 @@ or load and register each extension individually.
|
|
229
231
|
require 'asciidoctor-diagram/<extension_name>'
|
230
232
|
----
|
231
233
|
|
232
|
-
`<extension_name>` can be one of `blockdiag`, `ditaa`, `graphviz`, `meme`, `mermaid`, `plantuml`, `shaape`, or `wavedrom`.
|
234
|
+
`<extension_name>` can be one of `blockdiag`, `ditaa`, `erd`, `graphviz`, `meme`, `mermaid`, `plantuml`, `shaape`, or `wavedrom`.
|
233
235
|
|
234
236
|
Requiring one or more of these files will automatically register the extensions for all processed documents.
|
235
237
|
|
@@ -275,6 +277,7 @@ The following table lists the tools that are required for each diagram type, the
|
|
275
277
|
|actdiag |{uri-actdiag}[ActDiag] |`actdiag`
|
276
278
|
|blockdiag |{uri-blockdiag}[BlockDiag] |`blockdiag`
|
277
279
|
|ditaa |{uri-java}[Java] |`java`
|
280
|
+
|erd |{uri-erd}[Erd] |`erd`
|
278
281
|
|graphviz |{uri-graphviz}[GraphViz] |`dot` or `graphvizdot`
|
279
282
|
|meme |{uri-imagemagick}[ImageMagick] |`convert` and `identify`
|
280
283
|
|mermaid |{uri-mermaid}[Mermaid] |`mermaid`
|
data/lib/asciidoctor-diagram.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'asciidoctor-diagram/blockdiag'
|
2
2
|
require_relative 'asciidoctor-diagram/ditaa'
|
3
|
+
require_relative 'asciidoctor-diagram/erd'
|
3
4
|
require_relative 'asciidoctor-diagram/graphviz'
|
4
5
|
require_relative 'asciidoctor-diagram/meme'
|
5
6
|
require_relative 'asciidoctor-diagram/mermaid'
|
@@ -85,17 +85,18 @@ module Asciidoctor
|
|
85
85
|
end
|
86
86
|
|
87
87
|
block = Class.new(Extensions::DiagramBlockProcessor) do
|
88
|
-
self.instance_eval
|
88
|
+
self.instance_eval(&init)
|
89
89
|
end
|
90
90
|
::Asciidoctor::Diagram.const_set("#{name}BlockProcessor", block)
|
91
91
|
|
92
92
|
block_macro = Class.new(Extensions::DiagramBlockMacroProcessor) do
|
93
|
-
self.instance_eval
|
93
|
+
self.instance_eval(&init)
|
94
94
|
end
|
95
95
|
|
96
96
|
::Asciidoctor::Diagram.const_set("#{name}BlockMacroProcessor", block_macro)
|
97
97
|
end
|
98
98
|
|
99
|
+
include CliGenerator
|
99
100
|
include Which
|
100
101
|
|
101
102
|
def blockdiag(tool, parent, source, format)
|
@@ -105,8 +106,8 @@ module Asciidoctor
|
|
105
106
|
# a '3' suffix.
|
106
107
|
alt_cmd_name = "#{tool.downcase}3"
|
107
108
|
|
108
|
-
|
109
|
-
[tool_path, '-o', Platform.native_path(output_path), "-T#{format.to_s}", '-']
|
109
|
+
generate_stdin(which(parent, cmd_name, :alt_cmds => [alt_cmd_name]), format.to_s, source.to_s) do |tool_path, output_path|
|
110
|
+
[tool_path, '-a', '-o', Platform.native_path(output_path), "-T#{format.to_s}", '-']
|
110
111
|
end
|
111
112
|
end
|
112
113
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative '../extensions'
|
2
|
+
require_relative '../util/cli_generator'
|
3
|
+
require_relative '../util/platform'
|
4
|
+
require_relative '../util/which'
|
5
|
+
|
6
|
+
module Asciidoctor
|
7
|
+
module Diagram
|
8
|
+
# @private
|
9
|
+
module Erd
|
10
|
+
include CliGenerator
|
11
|
+
include Which
|
12
|
+
|
13
|
+
def self.included(mod)
|
14
|
+
[:png, :svg].each do |f|
|
15
|
+
mod.register_format(f, :image) do |parent, source|
|
16
|
+
erd(parent, source, f)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def erd(parent, source, format)
|
22
|
+
erd_path = which(parent, 'erd')
|
23
|
+
dot_path = which(parent, 'dot', :alt_attrs => ['graphvizdot'])
|
24
|
+
|
25
|
+
dot_code = generate_stdin(erd_path, format.to_s, source.to_s) do |tool_path, output_path|
|
26
|
+
[tool_path, '-o', Platform.native_path(output_path), '-f', 'dot']
|
27
|
+
end
|
28
|
+
|
29
|
+
generate_stdin(dot_path, format.to_s, dot_code) do |tool_path, output_path|
|
30
|
+
[tool_path, "-o#{Platform.native_path(output_path)}", "-T#{format.to_s}"]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class ErdBlockProcessor < Extensions::DiagramBlockProcessor
|
36
|
+
include Erd
|
37
|
+
end
|
38
|
+
|
39
|
+
class ErdBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
|
40
|
+
include Erd
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -32,7 +32,7 @@ module Asciidoctor
|
|
32
32
|
def register_format(format, type, &block)
|
33
33
|
raise "Unsupported output type: #{type}" unless type == :image || type == :literal
|
34
34
|
|
35
|
-
unless @default_format
|
35
|
+
unless defined?(@default_format)
|
36
36
|
@default_format = format
|
37
37
|
end
|
38
38
|
|
@@ -40,7 +40,7 @@ module Asciidoctor
|
|
40
40
|
:type => type,
|
41
41
|
:generator => block
|
42
42
|
}
|
43
|
-
|
43
|
+
end
|
44
44
|
|
45
45
|
# Returns the registered formats
|
46
46
|
#
|
@@ -115,7 +115,11 @@ module Asciidoctor
|
|
115
115
|
raise e
|
116
116
|
else
|
117
117
|
text = "Failed to generate image: #{e.message}"
|
118
|
-
|
118
|
+
warn_msg = text.dup
|
119
|
+
if $VERBOSE
|
120
|
+
warn_msg << "\n" << e.backtrace.join("\n")
|
121
|
+
end
|
122
|
+
warn %(asciidoctor-diagram: ERROR: #{warn_msg})
|
119
123
|
text << "\n"
|
120
124
|
text << source.code
|
121
125
|
Asciidoctor::Block.new parent, :listing, :source => text, :attributes => attributes
|
@@ -149,7 +153,7 @@ module Asciidoctor
|
|
149
153
|
image_file = parent.normalize_system_path image_name, image_dir
|
150
154
|
metadata_file = parent.normalize_system_path "#{image_name}.cache", cache_dir
|
151
155
|
|
152
|
-
if File.
|
156
|
+
if File.exist? metadata_file
|
153
157
|
metadata = File.open(metadata_file, 'r') { |f| JSON.load f }
|
154
158
|
else
|
155
159
|
metadata = {}
|
@@ -157,7 +161,7 @@ module Asciidoctor
|
|
157
161
|
|
158
162
|
image_attributes = source.attributes
|
159
163
|
|
160
|
-
if !File.
|
164
|
+
if !File.exist?(image_file) || source.should_process?(image_file, metadata)
|
161
165
|
params = IMAGE_PARAMS[format]
|
162
166
|
|
163
167
|
result = instance_exec(parent, source, &generator_info[:generator])
|
@@ -7,6 +7,7 @@ module Asciidoctor
|
|
7
7
|
module Diagram
|
8
8
|
# @private
|
9
9
|
module Graphviz
|
10
|
+
include CliGenerator
|
10
11
|
include Which
|
11
12
|
|
12
13
|
def self.included(mod)
|
@@ -18,7 +19,7 @@ module Asciidoctor
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def graphviz(parent, source, format)
|
21
|
-
|
22
|
+
generate_stdin(which(parent, 'dot', :alt_attrs => ['graphvizdot']), format.to_s, source.to_s) do |tool_path, output_path|
|
22
23
|
args = [tool_path, "-o#{Platform.native_path(output_path)}", "-T#{format.to_s}"]
|
23
24
|
|
24
25
|
layout = source.attr('layout')
|
@@ -36,7 +36,7 @@ module Asciidoctor
|
|
36
36
|
options = c.attr('options', '').split(',')
|
37
37
|
noupcase = options.include?('noupcase')
|
38
38
|
|
39
|
-
dimensions =
|
39
|
+
dimensions = Cli.run(identify, '-format', '%w %h', bg_img).match(/(?<w>\d+) (?<h>\d+)/)
|
40
40
|
bg_width = dimensions['w'].to_i
|
41
41
|
bg_height = dimensions['h'].to_i
|
42
42
|
label_width = bg_width
|
@@ -44,7 +44,7 @@ module Asciidoctor
|
|
44
44
|
|
45
45
|
if top_label
|
46
46
|
top_img = Tempfile.new(['meme', '.png'])
|
47
|
-
|
47
|
+
Cli.run(
|
48
48
|
convert,
|
49
49
|
'-background', 'none',
|
50
50
|
'-fill', fill_color,
|
@@ -62,7 +62,7 @@ module Asciidoctor
|
|
62
62
|
|
63
63
|
if bottom_label
|
64
64
|
bottom_img = Tempfile.new(['meme', '.png'])
|
65
|
-
|
65
|
+
Cli.run(
|
66
66
|
convert,
|
67
67
|
'-background', 'none',
|
68
68
|
'-fill', fill_color,
|
@@ -91,7 +91,7 @@ module Asciidoctor
|
|
91
91
|
|
92
92
|
args << final_img.path
|
93
93
|
|
94
|
-
|
94
|
+
Cli.run(*args)
|
95
95
|
|
96
96
|
File.binread(final_img)
|
97
97
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative '../extensions'
|
2
|
+
require_relative '../util/cli'
|
2
3
|
require_relative '../util/cli_generator'
|
3
4
|
require_relative '../util/platform'
|
4
5
|
require_relative '../util/which'
|
@@ -7,6 +8,7 @@ module Asciidoctor
|
|
7
8
|
module Diagram
|
8
9
|
# @private
|
9
10
|
module Mermaid
|
11
|
+
include CliGenerator
|
10
12
|
include Which
|
11
13
|
|
12
14
|
def self.included(mod)
|
@@ -19,7 +21,7 @@ module Asciidoctor
|
|
19
21
|
|
20
22
|
def mermaid(parent, source, format)
|
21
23
|
mermaid = which(parent, 'mermaid')
|
22
|
-
@is_mermaid_v6 ||=
|
24
|
+
@is_mermaid_v6 ||= ::Asciidoctor::Diagram::Cli.run(mermaid, '--version').split('.')[0].to_i >= 6
|
23
25
|
# Mermaid >= 6.0.0 requires PhantomJS 2.1; older version required 1.9
|
24
26
|
phantomjs = which(parent, 'phantomjs', :alt_attrs => [@is_mermaid_v6 ? 'phantomjs_2' : 'phantomjs_19'])
|
25
27
|
|
@@ -30,7 +32,7 @@ module Asciidoctor
|
|
30
32
|
|
31
33
|
width = source.attr('width')
|
32
34
|
|
33
|
-
|
35
|
+
generate_file(mermaid, 'mmd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
|
34
36
|
output_dir = File.dirname(output_path)
|
35
37
|
output_file = File.expand_path(File.basename(input_path) + ".#{format.to_s}", output_dir)
|
36
38
|
|
@@ -7,6 +7,7 @@ module Asciidoctor
|
|
7
7
|
module Diagram
|
8
8
|
# @private
|
9
9
|
module Shaape
|
10
|
+
include CliGenerator
|
10
11
|
include Which
|
11
12
|
|
12
13
|
def self.included(mod)
|
@@ -18,7 +19,7 @@ module Asciidoctor
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def shaape(parent, source, format)
|
21
|
-
|
22
|
+
generate_stdin(which(parent, 'shaape'), format.to_s, source.to_s) do |tool_path, output_path|
|
22
23
|
[tool_path, '-o', Platform.native_path(output_path), '-t', format.to_s, '-']
|
23
24
|
end
|
24
25
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
module Asciidoctor
|
5
|
+
module Diagram
|
6
|
+
# @private
|
7
|
+
module Cli
|
8
|
+
def self.run(*args)
|
9
|
+
stdout, stderr, status = Open3.capture3(*args)
|
10
|
+
|
11
|
+
if status != 0
|
12
|
+
raise "#{File.basename(args[0])} failed: #{stdout.empty? ? stderr : stdout}"
|
13
|
+
end
|
14
|
+
|
15
|
+
stdout.empty? ? stderr : stdout
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'tempfile'
|
2
|
-
|
2
|
+
require_relative 'cli'
|
3
3
|
|
4
4
|
module Asciidoctor
|
5
5
|
module Diagram
|
6
6
|
# @private
|
7
7
|
module CliGenerator
|
8
|
-
def
|
8
|
+
def generate_stdin(tool, format, code)
|
9
9
|
tool_name = File.basename(tool)
|
10
10
|
|
11
11
|
target_file = Tempfile.new([tool_name, ".#{format}"])
|
@@ -20,7 +20,7 @@ module Asciidoctor
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def generate_file(tool, input_ext, output_ext, code)
|
24
24
|
tool_name = File.basename(tool)
|
25
25
|
|
26
26
|
source_file = Tempfile.new([tool_name, ".#{input_ext}"])
|
@@ -42,7 +42,7 @@ module Asciidoctor
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
45
|
+
def generate(opts, target_file, open3_opts = {})
|
46
46
|
case opts
|
47
47
|
when Array
|
48
48
|
args = opts
|
@@ -54,7 +54,7 @@ module Asciidoctor
|
|
54
54
|
raise "Block passed to generate_file should return an Array or a Hash"
|
55
55
|
end
|
56
56
|
|
57
|
-
output =
|
57
|
+
output = ::Asciidoctor::Diagram::Cli.run(*args, open3_opts)
|
58
58
|
|
59
59
|
raise "#{args[0]} failed: #{output}" unless File.exist?(out_file || target_file.path)
|
60
60
|
|
@@ -64,16 +64,6 @@ module Asciidoctor
|
|
64
64
|
|
65
65
|
File.binread(target_file.path)
|
66
66
|
end
|
67
|
-
|
68
|
-
def self.run_cli(*args)
|
69
|
-
stdout, stderr, status = Open3.capture3(*args)
|
70
|
-
|
71
|
-
if status != 0
|
72
|
-
raise "#{File.basename(args[0])} failed: #{stdout.empty? ? stderr : stdout}"
|
73
|
-
end
|
74
|
-
|
75
|
-
stdout.empty? ? stderr : stdout
|
76
|
-
end
|
77
67
|
end
|
78
68
|
end
|
79
69
|
end
|
@@ -78,7 +78,7 @@ module Asciidoctor
|
|
78
78
|
if content_type.start_with? 'application/json'
|
79
79
|
json = JSON.parse(response[:body].force_encoding(Encoding::UTF_8))
|
80
80
|
ruby_bt = Kernel.caller(2)
|
81
|
-
java_bt = json['stk'].map { |java_line| "#{java_line[0]}:#{java_line[3]}: in
|
81
|
+
java_bt = json['stk'].map { |java_line| "#{java_line[0]}:#{java_line[3]}: in '#{java_line[2]}'" }
|
82
82
|
error = RuntimeError.new("#{prefix_msg}: #{json['msg']}")
|
83
83
|
error.set_backtrace java_bt + ruby_bt
|
84
84
|
raise error
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'socket'
|
2
|
-
require 'rbconfig'
|
3
2
|
|
3
|
+
require_relative 'cli'
|
4
|
+
require_relative 'platform'
|
4
5
|
require_relative 'which'
|
5
6
|
|
6
7
|
module Asciidoctor
|
@@ -15,10 +16,10 @@ module Asciidoctor
|
|
15
16
|
args << '-Djava.awt.headless=true'
|
16
17
|
args << '-cp'
|
17
18
|
# special case for cygwin, it requires path translation for java to work
|
18
|
-
if
|
19
|
+
if ::Asciidoctor::Diagram::Platform.os_variant == :cygwin
|
19
20
|
cygpath = ::Asciidoctor::Diagram::Which.which('cygpath')
|
20
|
-
if
|
21
|
-
args << classpath.flatten.map { |jar|
|
21
|
+
if cygpath != nil
|
22
|
+
args << classpath.flatten.map { |jar| ::Asciidoctor::Diagram::Cli.run(cygpath, '-w', jar).strip }.join(";")
|
22
23
|
else
|
23
24
|
puts 'cygwin warning: cygpath not found'
|
24
25
|
args << classpath.flatten.join(File::PATH_SEPARATOR)
|
@@ -44,7 +45,7 @@ module Asciidoctor
|
|
44
45
|
end
|
45
46
|
|
46
47
|
def self.load
|
47
|
-
if @loaded
|
48
|
+
if defined?(@loaded) && @loaded
|
48
49
|
return
|
49
50
|
end
|
50
51
|
|
@@ -56,7 +57,7 @@ module Asciidoctor
|
|
56
57
|
@java_exe ||= find_java
|
57
58
|
raise "Could not find Java executable" unless @java_exe
|
58
59
|
|
59
|
-
unless @command_server
|
60
|
+
unless defined?(@command_server) && @command_server
|
60
61
|
server = CommandServer.new(@java_exe, classpath)
|
61
62
|
@command_server = server
|
62
63
|
at_exit do
|
@@ -77,15 +78,13 @@ module Asciidoctor
|
|
77
78
|
|
78
79
|
private
|
79
80
|
def self.find_java
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
# Other unix-like system
|
88
|
-
path_to(ENV['JAVA_HOME'], 'bin/java') || ::Asciidoctor::Diagram::Which.which('java')
|
81
|
+
case ::Asciidoctor::Diagram::Platform.os
|
82
|
+
when :windows
|
83
|
+
path_to(ENV['JAVA_HOME'], 'bin/java.exe') || registry_lookup || ::Asciidoctor::Diagram::Which.which('java')
|
84
|
+
when :macosx
|
85
|
+
path_to(ENV['JAVA_HOME'], 'bin/java') || path_to(::Asciidoctor::Diagram::Cli.run('/usr/libexec/java_home').strip, 'bin/java') || ::Asciidoctor::Diagram::Which.which('java')
|
86
|
+
else
|
87
|
+
path_to(ENV['JAVA_HOME'], 'bin/java') || ::Asciidoctor::Diagram::Which.which('java')
|
89
88
|
end
|
90
89
|
end
|
91
90
|
|
@@ -98,21 +97,90 @@ module Asciidoctor
|
|
98
97
|
end
|
99
98
|
end
|
100
99
|
|
100
|
+
JDK_KEY = 'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit'
|
101
|
+
JRE_KEY = 'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment'
|
102
|
+
|
101
103
|
def self.registry_lookup
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
104
|
+
registry_current(JRE_KEY) || registry_current(JDK_KEY) || registry_any()
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.registry_current(key)
|
108
|
+
current_version = registry_query(key, 'CurrentVersion')
|
109
|
+
if current_version
|
110
|
+
java_home = registry_query("#{key}\\#{current_version}", 'JavaHome')
|
111
|
+
java_exe(java_home)
|
112
|
+
else
|
113
|
+
nil
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.registry_any()
|
118
|
+
java_homes = registry_query('HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft', 'JavaHome', :recursive => true).values
|
119
|
+
java_homes.map { |path| java_exe(path) }.find { |exe| !exe.nil? }
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.java_exe(java_home)
|
123
|
+
java = File.expand_path('bin/java.exe', java_home)
|
124
|
+
|
125
|
+
if File.executable?(java)
|
126
|
+
java
|
127
|
+
else
|
128
|
+
nil
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def self.registry_query(key, value = nil, opts = {})
|
133
|
+
args = ['reg', 'query']
|
134
|
+
args << key
|
135
|
+
args << '/v' << value unless value.nil?
|
136
|
+
args << '/s' if opts[:recursive]
|
137
|
+
|
138
|
+
begin
|
139
|
+
lines = ::Asciidoctor::Diagram::Cli.run(*args).lines.reject { |l| l.strip.empty? }.each
|
140
|
+
rescue
|
141
|
+
lines = [].each
|
142
|
+
end
|
143
|
+
|
144
|
+
result = {}
|
145
|
+
|
146
|
+
while true
|
147
|
+
begin
|
148
|
+
begin
|
149
|
+
k = lines.next
|
150
|
+
rescue StopIteration
|
151
|
+
break
|
152
|
+
end
|
153
|
+
|
154
|
+
unless k.start_with? key
|
155
|
+
next
|
156
|
+
end
|
157
|
+
|
158
|
+
v = nil
|
159
|
+
begin
|
160
|
+
v = lines.next.strip if lines.peek.start_with?(' ')
|
161
|
+
rescue StopIteration
|
162
|
+
break
|
163
|
+
end
|
164
|
+
|
165
|
+
if !k.valid_encoding? || (v && !v.valid_encoding?)
|
166
|
+
next
|
167
|
+
end
|
168
|
+
|
169
|
+
if v && (md = /([^\s]+)\s+(REG_[^\s]+)\s+(.+)/.match(v))
|
170
|
+
v_name = md[1]
|
171
|
+
v_value = md[3]
|
172
|
+
result["#{k}\\#{v_name}"] = v_value
|
173
|
+
else
|
174
|
+
result[k] = v
|
175
|
+
end
|
112
176
|
end
|
113
|
-
end
|
114
|
-
|
115
|
-
|
177
|
+
end
|
178
|
+
|
179
|
+
if value && !opts[:recursive]
|
180
|
+
result.values[0]
|
181
|
+
else
|
182
|
+
result
|
183
|
+
end
|
116
184
|
end
|
117
185
|
end
|
118
186
|
end
|