ea 0.6.160 → 0.6.161
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/lib/ea/export/xsd/class_mapping.rb +4 -4
- data/lib/ea/export/xsd/generator.rb +21 -12
- data/lib/ea/mdg/stereotype_alias_registry.rb +6 -6
- data/lib/ea/sources/xmi/constraint_builder.rb +18 -18
- data/lib/ea/sources/xmi/diagram_builder/association_class_metadata.rb +50 -12
- data/lib/ea/sources/xmi/diagram_builder/connector_metadata.rb +59 -7
- data/lib/ea/sources/xmi/diagram_builder/font_settings.rb +2 -2
- data/lib/ea/sources/xmi/diagram_builder/umldi_edges/property_roles.rb +7 -5
- data/lib/ea/sources/xmi/diagram_builder/umldi_edges.rb +16 -10
- data/lib/ea/sources/xmi/extension_types.rb +2 -2
- data/lib/ea/sources/xmi/instance_builder.rb +6 -4
- data/lib/ea/sources/xmi/note_builder.rb +1 -1
- data/lib/ea/sources/xmi/reception_builder.rb +2 -2
- data/lib/ea/sources/xmi/tag_builder.rb +2 -2
- data/lib/ea/sources/xmi/umldi_keyword_extractor.rb +2 -2
- data/lib/ea/svg/parity/checker.rb +21 -10
- data/lib/ea/svg/parity/differ.rb +4 -2
- data/lib/ea/svg/parity/suite.rb +1 -1
- data/lib/ea/version.rb +1 -1
- data/lib/ea/xmi.rb +1 -1
- data/lib/ea/xml.rb +44 -0
- data/lib/ea.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d7197145439783ffd1371d762178adb42d10fbb7bd149a35b321eb07d85bfdea
|
|
4
|
+
data.tar.gz: 2337db7f718d4237e586bb4b77bd7ab03fe2c8ca21466be720c73a0f74bd78ba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5d1728a63e4be58c217d2204e3095af3255f0e2a69ef84586ac74a3c3eb62c3ab132b8d06d31a8f139e0ab08f53160b856fa3c03f8e5a9bb5d0053b544ad9d1e
|
|
7
|
+
data.tar.gz: 9abe04e07fb696d543c4ea5fbadba8049baea8b91fbae6276ddecd3c9bfaf7b716a576adf6bacb1c9e1dd156c87044081ae28f688095ba9277c80e522d48d46a
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Export
|
|
@@ -30,12 +30,12 @@ module Ea
|
|
|
30
30
|
def self.from_path(path)
|
|
31
31
|
return new if path.nil? || !File.exist?(path)
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
from_xml(Ea::Xml.parse_file(path))
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
# @param doc [
|
|
36
|
+
# @param doc [Moxml::Wrappers::Document]
|
|
37
37
|
# @return [ClassMapping]
|
|
38
|
-
def self.
|
|
38
|
+
def self.from_xml(doc)
|
|
39
39
|
mappings = {}
|
|
40
40
|
doc.xpath("//Class").each do |node|
|
|
41
41
|
name = node["name"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Export
|
|
@@ -46,13 +46,14 @@ module Ea
|
|
|
46
46
|
private
|
|
47
47
|
|
|
48
48
|
def build_schema_doc(target_namespace, prefix)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
doc = Moxml.new.create_document
|
|
50
|
+
schema = doc.create_element("schema")
|
|
51
|
+
schema["xmlns"] = XSD_NS
|
|
52
|
+
schema["xmlns:#{prefix}"] = target_namespace
|
|
53
|
+
schema["targetNamespace"] = target_namespace
|
|
54
|
+
schema["elementFormDefault"] = "qualified"
|
|
55
|
+
doc.root = schema
|
|
56
|
+
doc
|
|
56
57
|
end
|
|
57
58
|
|
|
58
59
|
def walk_model(model, doc)
|
|
@@ -107,16 +108,16 @@ module Ea
|
|
|
107
108
|
end
|
|
108
109
|
|
|
109
110
|
def element_node(doc, name, type_name)
|
|
110
|
-
el = doc
|
|
111
|
+
el = xsd_element(doc)
|
|
111
112
|
el["name"] = name
|
|
112
113
|
el["type"] = "tns:#{type_name}"
|
|
113
114
|
el
|
|
114
115
|
end
|
|
115
116
|
|
|
116
117
|
def complex_type_node(doc, type_name, classifier)
|
|
117
|
-
ct = doc
|
|
118
|
+
ct = xsd_element(doc, "complexType")
|
|
118
119
|
ct["name"] = type_name
|
|
119
|
-
seq = doc
|
|
120
|
+
seq = xsd_element(doc, "sequence")
|
|
120
121
|
classifier.attributes.each do |attr|
|
|
121
122
|
seq.add_child(attribute_element(doc, attr))
|
|
122
123
|
end
|
|
@@ -125,12 +126,20 @@ module Ea
|
|
|
125
126
|
end
|
|
126
127
|
|
|
127
128
|
def attribute_element(doc, attr)
|
|
128
|
-
el = doc
|
|
129
|
+
el = xsd_element(doc)
|
|
129
130
|
el["name"] = attr[:name].to_s
|
|
130
131
|
el["type"] = "xs:string"
|
|
131
132
|
el["minOccurs"] = "0"
|
|
132
133
|
el
|
|
133
134
|
end
|
|
135
|
+
|
|
136
|
+
# Schema children carry the XSD namespace explicitly, matching
|
|
137
|
+
# the reference EA output.
|
|
138
|
+
def xsd_element(doc, name = "element")
|
|
139
|
+
el = doc.create_element(name)
|
|
140
|
+
el["xmlns"] = XSD_NS
|
|
141
|
+
el
|
|
142
|
+
end
|
|
134
143
|
end
|
|
135
144
|
end
|
|
136
145
|
end
|
|
@@ -32,16 +32,16 @@ module Ea
|
|
|
32
32
|
def self.from_path(path)
|
|
33
33
|
return new if path.nil? || !File.exist?(path)
|
|
34
34
|
|
|
35
|
-
require "
|
|
36
|
-
doc =
|
|
37
|
-
|
|
35
|
+
require "moxml"
|
|
36
|
+
doc = Ea::Xml.parse_file(path)
|
|
37
|
+
from_xml(doc)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
# Build from a parsed
|
|
40
|
+
# Build from a parsed XML document. Tested separately so
|
|
41
41
|
# the parser path is exercised without file IO.
|
|
42
|
-
# @param doc [
|
|
42
|
+
# @param doc [Moxml::Wrappers::Document]
|
|
43
43
|
# @return [StereotypeAliasRegistry]
|
|
44
|
-
def self.
|
|
44
|
+
def self.from_xml(doc)
|
|
45
45
|
aliases = {}
|
|
46
46
|
doc.xpath("//Stereotype").each do |stereo|
|
|
47
47
|
canonical = stereo["name"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "leptris"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Sources
|
|
@@ -32,28 +32,28 @@ module Ea
|
|
|
32
32
|
@seen_owners = {}
|
|
33
33
|
@blocks_seen = {}
|
|
34
34
|
@skip_block = false
|
|
35
|
-
File.
|
|
35
|
+
Leptris::XML::Pull.parse(File.read(xmi_path)).each { |event| visit(event) }
|
|
36
36
|
@grouped
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
def visit(
|
|
40
|
-
case
|
|
41
|
-
when
|
|
39
|
+
def visit(event)
|
|
40
|
+
case event.type
|
|
41
|
+
when :end_element
|
|
42
42
|
@owner = nil if @path.pop == "element"
|
|
43
|
-
when
|
|
44
|
-
enter(
|
|
45
|
-
@path.push(
|
|
43
|
+
when :start_element
|
|
44
|
+
enter(event)
|
|
45
|
+
@path.push(event.name)
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
def enter(
|
|
50
|
-
if
|
|
51
|
-
@owner = first_block_owner(
|
|
52
|
-
elsif
|
|
49
|
+
def enter(event)
|
|
50
|
+
if event.name == "element" && @path.last == "elements"
|
|
51
|
+
@owner = first_block_owner(event.attrs&.fetch("xmi:idref", nil))
|
|
52
|
+
elsif event.name == "constraints" && @owner && @path.last == "element"
|
|
53
53
|
@skip_block = @blocks_seen.key?(@owner)
|
|
54
54
|
@blocks_seen[@owner] = true
|
|
55
|
-
elsif
|
|
56
|
-
(@grouped[@owner] ||= []) << constraint(
|
|
55
|
+
elsif event.name == "constraint" && @owner && !@skip_block && @path.last(2) == %w[element constraints]
|
|
56
|
+
(@grouped[@owner] ||= []) << constraint(event)
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
|
|
@@ -69,10 +69,10 @@ module Ea
|
|
|
69
69
|
def constraint(node)
|
|
70
70
|
Ea::Model::Constraint.new(
|
|
71
71
|
id: IdNormalizer.synthetic_id(@owner, "constraint", @grouped[@owner].to_a.size.to_s),
|
|
72
|
-
name: node.
|
|
73
|
-
kind: node.
|
|
74
|
-
body: node.
|
|
75
|
-
status: node.
|
|
72
|
+
name: node.attrs&.fetch("name", nil).to_s,
|
|
73
|
+
kind: node.attrs&.fetch("type", nil).to_s,
|
|
74
|
+
body: node.attrs&.fetch("description", nil).to_s,
|
|
75
|
+
status: node.attrs&.fetch("status", nil).to_s
|
|
76
76
|
)
|
|
77
77
|
end
|
|
78
78
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
|
+
require "leptris"
|
|
4
5
|
|
|
5
6
|
module Ea
|
|
6
7
|
module Sources
|
|
@@ -76,21 +77,59 @@ module Ea
|
|
|
76
77
|
|
|
77
78
|
def scan_metadata
|
|
78
79
|
data = { connectors: {}, proxies: {}, classes: [] }
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
@capture = nil
|
|
81
|
+
# Single streaming pass over the XMI: reconstruct each
|
|
82
|
+
# <element>/<connector>'s outer XML from the pull stream and
|
|
83
|
+
# parse it as a subtree for the attribute lookups below.
|
|
84
|
+
Leptris::XML::Pull.parse(File.read(@xmi_path)).each do |event|
|
|
85
|
+
case event.type
|
|
86
|
+
when :start_element
|
|
87
|
+
if @capture
|
|
88
|
+
@capture[:depth] += 1
|
|
89
|
+
@capture[:xml] << write_start(event)
|
|
90
|
+
elsif %w[element connector].include?(event.name)
|
|
91
|
+
@capture = { kind: event.name, depth: 1, xml: +write_start(event) }
|
|
92
|
+
end
|
|
93
|
+
when :end_element
|
|
94
|
+
next unless @capture
|
|
95
|
+
|
|
96
|
+
@capture[:xml] << "</#{event.name}>"
|
|
97
|
+
@capture[:depth] -= 1
|
|
98
|
+
if @capture[:depth].zero?
|
|
99
|
+
subtree = Moxml.parse(scrub(@capture[:xml])).root
|
|
100
|
+
send("read_#{@capture[:kind]}", subtree, data)
|
|
101
|
+
@capture = nil
|
|
102
|
+
end
|
|
103
|
+
when :text
|
|
104
|
+
@capture[:xml] << escape_text(event.text) if @capture
|
|
105
|
+
end
|
|
81
106
|
end
|
|
82
107
|
data
|
|
83
108
|
end
|
|
84
109
|
|
|
85
|
-
|
|
86
|
-
|
|
110
|
+
# EA XMI files occasionally carry bytes outside the declared
|
|
111
|
+
# encoding; the nokogiri outer-xml path tolerated them, so scrub
|
|
112
|
+
# the reconstructed fragment the same way before parsing.
|
|
113
|
+
def scrub(buffer)
|
|
114
|
+
buffer.encode("UTF-8", invalid: :replace, undef: :replace)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def write_start(event)
|
|
118
|
+
attrs = (event.attrs || {}).map do |key, value|
|
|
119
|
+
%( #{key}="#{escape_attribute(value)}")
|
|
120
|
+
end.join
|
|
121
|
+
"<#{event.name}#{attrs}>"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def escape_attribute(value)
|
|
125
|
+
value.to_s.gsub("&", "&").gsub("<", "<").gsub('"', """)
|
|
126
|
+
end
|
|
87
127
|
|
|
88
|
-
|
|
89
|
-
|
|
128
|
+
def escape_text(text)
|
|
129
|
+
text.to_s.gsub("&", "&").gsub("<", "<").gsub(">", ">")
|
|
90
130
|
end
|
|
91
131
|
|
|
92
|
-
def read_element(
|
|
93
|
-
element = Nokogiri::XML(node.outer_xml).root
|
|
132
|
+
def read_element(element, data)
|
|
94
133
|
id = attr(element, "idref")
|
|
95
134
|
return unless id
|
|
96
135
|
|
|
@@ -99,8 +138,7 @@ module Ea
|
|
|
99
138
|
data[:proxies][id] = attr(element, "classifier") if type == "uml:ProxyConnector"
|
|
100
139
|
end
|
|
101
140
|
|
|
102
|
-
def read_connector(
|
|
103
|
-
connector = Nokogiri::XML(node.outer_xml).root
|
|
141
|
+
def read_connector(connector, data)
|
|
104
142
|
id = attr(connector, "idref")
|
|
105
143
|
return unless id
|
|
106
144
|
|
|
@@ -114,7 +152,7 @@ module Ea
|
|
|
114
152
|
end
|
|
115
153
|
|
|
116
154
|
def attr(node, name)
|
|
117
|
-
node&.
|
|
155
|
+
node&.attributes&.find { |attribute| attribute.name == name }&.value
|
|
118
156
|
end
|
|
119
157
|
|
|
120
158
|
def guid_key(subject)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
|
+
require "leptris"
|
|
4
5
|
|
|
5
6
|
module Ea
|
|
6
7
|
module Sources
|
|
@@ -50,17 +51,68 @@ module Ea
|
|
|
50
51
|
def read_role_stereotypes
|
|
51
52
|
return {} unless @xmi_path
|
|
52
53
|
|
|
53
|
-
File.
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
capture_connectors(File.read(@xmi_path)).each_with_object({}) do |connector, roles|
|
|
55
|
+
read_connector_roles(connector, roles)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Single streaming pass over the XMI: reconstruct each
|
|
60
|
+
# <connector>'s outer XML from the pull stream and parse it as a
|
|
61
|
+
# subtree for the role lookups below.
|
|
62
|
+
def capture_connectors(xml)
|
|
63
|
+
connectors = []
|
|
64
|
+
buffer = nil
|
|
65
|
+
depth = 0
|
|
56
66
|
|
|
57
|
-
|
|
67
|
+
Leptris::XML::Pull.parse(xml).each do |event|
|
|
68
|
+
case event.type
|
|
69
|
+
when :start_element
|
|
70
|
+
if buffer
|
|
71
|
+
buffer << write_start(event)
|
|
72
|
+
depth += 1
|
|
73
|
+
elsif event.name == "connector"
|
|
74
|
+
buffer = +write_start(event)
|
|
75
|
+
depth = 1
|
|
76
|
+
end
|
|
77
|
+
when :end_element
|
|
78
|
+
next unless buffer
|
|
79
|
+
|
|
80
|
+
buffer << "</#{event.name}>"
|
|
81
|
+
depth -= 1
|
|
82
|
+
if depth.zero?
|
|
83
|
+
connectors << Moxml.parse(scrub(buffer)).root
|
|
84
|
+
buffer = nil
|
|
85
|
+
end
|
|
86
|
+
when :text
|
|
87
|
+
buffer << escape_text(event.text) if buffer
|
|
58
88
|
end
|
|
59
89
|
end
|
|
90
|
+
connectors
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# EA XMI files occasionally carry bytes outside the declared
|
|
94
|
+
# encoding; the nokogiri outer-xml path tolerated them, so scrub
|
|
95
|
+
# the reconstructed fragment the same way before parsing.
|
|
96
|
+
def scrub(buffer)
|
|
97
|
+
buffer.encode("UTF-8", invalid: :replace, undef: :replace)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def write_start(event)
|
|
101
|
+
attrs = (event.attrs || {}).map do |key, value|
|
|
102
|
+
%( #{key}="#{escape_attribute(value)}")
|
|
103
|
+
end.join
|
|
104
|
+
"<#{event.name}#{attrs}>"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def escape_attribute(value)
|
|
108
|
+
value.to_s.gsub("&", "&").gsub("<", "<").gsub('"', """)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def escape_text(text)
|
|
112
|
+
text.to_s.gsub("&", "&").gsub("<", "<").gsub(">", ">")
|
|
60
113
|
end
|
|
61
114
|
|
|
62
|
-
def read_connector_roles(
|
|
63
|
-
connector = Nokogiri::XML(node.outer_xml).root
|
|
115
|
+
def read_connector_roles(connector, roles)
|
|
64
116
|
id = connector.at_xpath("@*[local-name()='idref']")&.value
|
|
65
117
|
return unless id
|
|
66
118
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Sources
|
|
@@ -52,7 +52,7 @@ module Ea
|
|
|
52
52
|
def saved_objects
|
|
53
53
|
return [] unless @xmi_path
|
|
54
54
|
|
|
55
|
-
doc =
|
|
55
|
+
doc = Ea::Xml.parse_file(@xmi_path)
|
|
56
56
|
doc.xpath("//*[local-name()='Extension']/*[local-name()='elements']/*[local-name()='element']")
|
|
57
57
|
end
|
|
58
58
|
end
|
|
@@ -21,8 +21,10 @@ module Ea
|
|
|
21
21
|
@property_roles ||= begin
|
|
22
22
|
document = @doc
|
|
23
23
|
declared = declared_properties(document)
|
|
24
|
-
document.xpath("//*[local-name()=\"Diagram\"]")
|
|
25
|
-
|
|
24
|
+
document.xpath("//*[local-name()=\"Diagram\"]")
|
|
25
|
+
.each_with_object({}) do |diagram, hash|
|
|
26
|
+
hash[diagram["id"] || diagram["xmi:id"]] =
|
|
27
|
+
diagram_property_roles(diagram, declared)
|
|
26
28
|
end
|
|
27
29
|
end
|
|
28
30
|
end
|
|
@@ -34,7 +36,7 @@ module Ea
|
|
|
34
36
|
document.xpath("//*[@association][@xmi:id]", "xmi" => "http://www.omg.org/spec/XMI/20131001")
|
|
35
37
|
.filter_map do |node|
|
|
36
38
|
pair = [node["xmi:id"], node["association"]]
|
|
37
|
-
pair if node.
|
|
39
|
+
pair if node.at_xpath("@*[local-name()='type']")&.value == "uml:Property" && members.include?(pair)
|
|
38
40
|
end.to_set
|
|
39
41
|
end
|
|
40
42
|
|
|
@@ -50,13 +52,13 @@ module Ea
|
|
|
50
52
|
|
|
51
53
|
def unique_edges(diagram)
|
|
52
54
|
diagram.xpath("./ownedElement[@modelElement]")
|
|
53
|
-
.select { |node| node.
|
|
55
|
+
.select { |node| node.at_xpath("@*[local-name()='type']")&.value.to_s.end_with?("UMLEdge") }
|
|
54
56
|
.group_by { |edge| edge["modelElement"] }
|
|
55
57
|
.select { |_, edges| edges.one? }.transform_values(&:first)
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
def role_key(label)
|
|
59
|
-
return unless label.
|
|
61
|
+
return unless label.at_xpath("@*[local-name()='type']")&.value.to_s.end_with?("UMLAssociationEndLabel")
|
|
60
62
|
|
|
61
63
|
case label["xmi:id"] || label["id"]
|
|
62
64
|
when /\AEAID_SEL/ then :source_role
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Sources
|
|
@@ -41,15 +41,20 @@ module Ea
|
|
|
41
41
|
|
|
42
42
|
private
|
|
43
43
|
|
|
44
|
+
# NodeSet#to_h is not Enumerable-backed across XML adapters —
|
|
45
|
+
# build the id-keyed maps with an explicit reduction instead.
|
|
44
46
|
def ends
|
|
45
|
-
@ends ||= doc.xpath("//*[local-name()=\"Diagram\"]")
|
|
46
|
-
|
|
47
|
+
@ends ||= doc.xpath("//*[local-name()=\"Diagram\"]")
|
|
48
|
+
.each_with_object({}) do |diagram, hash|
|
|
49
|
+
hash[diagram["id"] || diagram["xmi:id"]] = diagram_ends(diagram)
|
|
47
50
|
end
|
|
48
51
|
end
|
|
49
52
|
|
|
50
53
|
def label_bounds
|
|
51
|
-
@label_bounds ||= doc.xpath("//*[local-name()=\"Diagram\"]")
|
|
52
|
-
|
|
54
|
+
@label_bounds ||= doc.xpath("//*[local-name()=\"Diagram\"]")
|
|
55
|
+
.each_with_object({}) do |diagram, hash|
|
|
56
|
+
hash[diagram["id"] || diagram["xmi:id"]] =
|
|
57
|
+
diagram_label_bounds(diagram)
|
|
53
58
|
end
|
|
54
59
|
end
|
|
55
60
|
|
|
@@ -77,7 +82,7 @@ module Ea
|
|
|
77
82
|
end
|
|
78
83
|
|
|
79
84
|
def label_key(label)
|
|
80
|
-
type = label.
|
|
85
|
+
type = label.at_xpath("@*[local-name()='type']")&.value.to_s
|
|
81
86
|
role = (label["id"] || label["xmi:id"]).to_s
|
|
82
87
|
end_name = { "EAID_SEL" => "source", "EAID_SML" => "source",
|
|
83
88
|
"EAID_TEL" => "target", "EAID_TML" => "target" }
|
|
@@ -97,15 +102,16 @@ module Ea
|
|
|
97
102
|
# one edge of the diagram, whatever that edge carries.
|
|
98
103
|
def unique_edges(diagram)
|
|
99
104
|
diagram.xpath("./ownedElement[@modelElement]")
|
|
100
|
-
.select { |node| node.
|
|
105
|
+
.select { |node| node.at_xpath("@*[local-name()='type']")&.value.to_s.end_with?("UMLEdge") }
|
|
101
106
|
.group_by { |edge| edge["modelElement"] }
|
|
102
107
|
.select { |_, same| same.one? }
|
|
103
108
|
.transform_values(&:first)
|
|
104
109
|
end
|
|
105
110
|
|
|
106
111
|
def routes
|
|
107
|
-
@routes ||= doc.xpath("//*[local-name()=\"Diagram\"]")
|
|
108
|
-
|
|
112
|
+
@routes ||= doc.xpath("//*[local-name()=\"Diagram\"]")
|
|
113
|
+
.each_with_object({}) do |diagram, hash|
|
|
114
|
+
hash[diagram["id"] || diagram["xmi:id"]] = diagram_routes(diagram)
|
|
109
115
|
end
|
|
110
116
|
end
|
|
111
117
|
|
|
@@ -121,7 +127,7 @@ module Ea
|
|
|
121
127
|
end
|
|
122
128
|
|
|
123
129
|
def doc
|
|
124
|
-
|
|
130
|
+
Ea::Xml.parse_file(@xmi_path)
|
|
125
131
|
end
|
|
126
132
|
end
|
|
127
133
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Sources
|
|
@@ -17,7 +17,7 @@ module Ea
|
|
|
17
17
|
def self.from_path(xmi_path)
|
|
18
18
|
return empty if xmi_path.nil?
|
|
19
19
|
|
|
20
|
-
new(
|
|
20
|
+
new(Ea::Xml.parse_file(xmi_path))
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def self.empty
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Sources
|
|
@@ -88,9 +88,11 @@ module Ea
|
|
|
88
88
|
def extension_runstates
|
|
89
89
|
return {} if xmi_path.nil?
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
Ea::Xml.parse_file(xmi_path)
|
|
92
|
+
.xpath(RUNSTATE_XPATH)
|
|
93
|
+
.each_with_object({}) do |node, acc|
|
|
94
|
+
acc[node.parent["xmi:idref"]] = node["runstate"]
|
|
95
|
+
end
|
|
94
96
|
end
|
|
95
97
|
end
|
|
96
98
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Sources
|
|
@@ -15,7 +15,7 @@ module Ea
|
|
|
15
15
|
def grouped_by_owner
|
|
16
16
|
return {} unless @xmi_path
|
|
17
17
|
|
|
18
|
-
@grouped_by_owner ||= read_receptions(
|
|
18
|
+
@grouped_by_owner ||= read_receptions(Ea::Xml.parse_file(@xmi_path))
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
private
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Sources
|
|
@@ -22,7 +22,7 @@ module Ea
|
|
|
22
22
|
return {} if xmi_path.nil?
|
|
23
23
|
|
|
24
24
|
@grouped ||= begin
|
|
25
|
-
doc =
|
|
25
|
+
doc = Ea::Xml.parse_file(xmi_path)
|
|
26
26
|
# <tags><tag/></tags> lives inside per-element <element>
|
|
27
27
|
# blocks within <xmi:Extension>. The element itself is in
|
|
28
28
|
# no XML namespace; match by local-name to be safe.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Sources
|
|
@@ -59,7 +59,7 @@ module Ea
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def doc
|
|
62
|
-
@doc ||=
|
|
62
|
+
@doc ||= Ea::Xml.parse_file(xmi_path)
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def keywords_by_diagram
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Svg
|
|
@@ -34,21 +34,25 @@ module Ea
|
|
|
34
34
|
private
|
|
35
35
|
|
|
36
36
|
def our_doc
|
|
37
|
-
@our_doc ||=
|
|
37
|
+
@our_doc ||= Ea::Xml.parse(@ours)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def ref_doc
|
|
41
|
-
@ref_doc ||=
|
|
41
|
+
@ref_doc ||= Ea::Xml.parse(@reference)
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
# CSS is not reliable on moxml for namespaced documents
|
|
45
|
+
# (lutaml/moxml#582) — tag counting goes through xpath.
|
|
44
46
|
def count_diff(selector)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
xpath = "//*[local-name()=\"#{selector}\"]"
|
|
48
|
+
Diff.new(ours: our_doc.xpath(xpath).size,
|
|
49
|
+
reference: ref_doc.xpath(xpath).size)
|
|
47
50
|
end
|
|
48
51
|
|
|
49
52
|
def top_level_group_diff
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
xpath = "/*[local-name()=\"svg\"]/*[local-name()=\"g\"]"
|
|
54
|
+
Diff.new(ours: our_doc.xpath(xpath).size,
|
|
55
|
+
reference: ref_doc.xpath(xpath).size)
|
|
52
56
|
end
|
|
53
57
|
|
|
54
58
|
def font_family_match
|
|
@@ -65,7 +69,8 @@ module Ea
|
|
|
65
69
|
end
|
|
66
70
|
|
|
67
71
|
def font_style_histogram(doc, property)
|
|
68
|
-
doc.
|
|
72
|
+
doc.xpath("//*[local-name()=\"text\"]")
|
|
73
|
+
.each_with_object(Hash.new(0)) do |node, acc|
|
|
69
74
|
value = (node["style"] || "")[/#{Regexp.quote(property)}:([^;]+)/, 1]
|
|
70
75
|
acc[value] += 1 if value
|
|
71
76
|
end
|
|
@@ -76,14 +81,20 @@ module Ea
|
|
|
76
81
|
end
|
|
77
82
|
|
|
78
83
|
def text_overlap_ratio
|
|
79
|
-
our_set = our_doc
|
|
80
|
-
ref_set = ref_doc
|
|
84
|
+
our_set = text_set(our_doc)
|
|
85
|
+
ref_set = text_set(ref_doc)
|
|
81
86
|
return 1.0 if our_set.empty? && ref_set.empty?
|
|
82
87
|
return 0.0 if our_set.empty? || ref_set.empty?
|
|
83
88
|
|
|
84
89
|
(our_set & ref_set).size.to_f / (our_set | ref_set).size.to_f
|
|
85
90
|
end
|
|
86
91
|
|
|
92
|
+
def text_set(doc)
|
|
93
|
+
doc.xpath("//*[local-name()=\"text\"]").map do |node|
|
|
94
|
+
node.text.to_s.strip
|
|
95
|
+
end.to_set
|
|
96
|
+
end
|
|
97
|
+
|
|
87
98
|
Diff = Struct.new(:ours, :reference, keyword_init: true) do
|
|
88
99
|
def delta
|
|
89
100
|
ours - reference
|
data/lib/ea/svg/parity/differ.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Svg
|
|
@@ -27,7 +27,9 @@ module Ea
|
|
|
27
27
|
# Extracts the primitives consumed by both comparison reports.
|
|
28
28
|
class PrimitiveParser
|
|
29
29
|
def parse(svg)
|
|
30
|
-
|
|
30
|
+
# xpath, not css — css is unreliable on moxml for
|
|
31
|
+
# namespaced documents (lutaml/moxml#582).
|
|
32
|
+
Ea::Xml.parse(svg).xpath('//*[local-name()="g"]').flat_map do |group|
|
|
31
33
|
group.element_children.filter_map { |node| primitive(node, group["style"] || "") }
|
|
32
34
|
end
|
|
33
35
|
end
|
data/lib/ea/svg/parity/suite.rb
CHANGED
data/lib/ea/version.rb
CHANGED
data/lib/ea/xmi.rb
CHANGED
data/lib/ea/xml.rb
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
# Shared XML parse entry for the gem's direct parses. Lenient by
|
|
5
|
+
# default — nokogiri/libxml2 parity — tolerating files whose bytes
|
|
6
|
+
# do not match UTF-8 (EA exports declare windows-1252 regularly and
|
|
7
|
+
# bundle raw CP1252 bytes alongside).
|
|
8
|
+
module Xml
|
|
9
|
+
DECLARED_ENCODING = /\A\s*<\?xml[^>]*encoding=["']([^"']+)["']/
|
|
10
|
+
|
|
11
|
+
module_function
|
|
12
|
+
|
|
13
|
+
# @param path [String] file path
|
|
14
|
+
# @return [Moxml::Wrappers::Document]
|
|
15
|
+
def parse_file(path)
|
|
16
|
+
parse(File.read(path))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# @param content [String] XML text
|
|
20
|
+
# @return [Moxml::Wrappers::Document]
|
|
21
|
+
def parse(content)
|
|
22
|
+
context = Moxml.new
|
|
23
|
+
context.config.strict_parsing = false
|
|
24
|
+
context.parse(normalize_encoding(content))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# libxml2 transcoded according to the XML declaration; moxml's
|
|
28
|
+
# parse validates UTF-8 strictly regardless of the declaration.
|
|
29
|
+
# Transcode declared non-UTF-8 content to UTF-8 and rewrite the
|
|
30
|
+
# declaration so downstream sees consistent text.
|
|
31
|
+
def normalize_encoding(content)
|
|
32
|
+
declared = content[DECLARED_ENCODING, 1]
|
|
33
|
+
return content if declared.nil? || declared.casecmp?("utf-8")
|
|
34
|
+
|
|
35
|
+
text = content.dup.force_encoding(declared).encode("UTF-8")
|
|
36
|
+
text.sub!(/\A(\s*<\?xml[^>]*encoding=["'])([^"']+)/) do
|
|
37
|
+
"#{Regexp.last_match(1)}UTF-8"
|
|
38
|
+
end
|
|
39
|
+
text
|
|
40
|
+
rescue StandardError
|
|
41
|
+
content.valid_encoding? ? content : content.scrub
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
data/lib/ea.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ea
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.161
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -663,6 +663,7 @@ files:
|
|
|
663
663
|
- lib/ea/xmi/lookup_service.rb
|
|
664
664
|
- lib/ea/xmi/parser.rb
|
|
665
665
|
- lib/ea/xmi/slicer.rb
|
|
666
|
+
- lib/ea/xml.rb
|
|
666
667
|
- lib/ea/xml_escape.rb
|
|
667
668
|
- lib/ea/xref_format.rb
|
|
668
669
|
- lib/ea/xref_format/legend_definition.rb
|