ea 0.6.187 → 0.6.188
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/README.adoc +2 -0
- data/lib/ea/cli/app.rb +22 -0
- data/lib/ea/cli/command/base.rb +20 -0
- data/lib/ea/cli/command/model_diff.rb +50 -0
- data/lib/ea/cli/command/model_lint.rb +58 -0
- data/lib/ea/cli/command.rb +2 -0
- data/lib/ea/guid_format.rb +10 -0
- data/lib/ea/model/document.rb +20 -0
- data/lib/ea/model/property.rb +2 -0
- data/lib/ea/model/relationship.rb +15 -0
- data/lib/ea/model_diff/change.rb +30 -0
- data/lib/ea/model_diff/comparator.rb +308 -0
- data/lib/ea/model_diff/report.rb +26 -0
- data/lib/ea/model_diff/text_reporter.rb +41 -0
- data/lib/ea/model_diff.rb +13 -0
- data/lib/ea/model_lint/engine.rb +31 -0
- data/lib/ea/model_lint/finding.rb +31 -0
- data/lib/ea/model_lint/report.rb +29 -0
- data/lib/ea/model_lint/rules/ambiguous_names.rb +28 -0
- data/lib/ea/model_lint/rules/duplicate_names.rb +28 -0
- data/lib/ea/model_lint/rules/missing_connector_ends.rb +46 -0
- data/lib/ea/model_lint/rules/outside_package_tree.rb +39 -0
- data/lib/ea/model_lint/rules/shared_attribute_positions.rb +30 -0
- data/lib/ea/model_lint/rules.rb +54 -0
- data/lib/ea/model_lint/text_reporter.rb +43 -0
- data/lib/ea/model_lint.rb +13 -0
- data/lib/ea/rules/attribute_order.rb +13 -0
- data/lib/ea/sources/qea/property_builder.rb +1 -0
- data/lib/ea/sources/xmi/classifier_builder.rb +1 -1
- data/lib/ea/sources/xmi/property_builder.rb +12 -0
- data/lib/ea/version.rb +1 -1
- data/lib/ea.rb +2 -0
- metadata +19 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '08ceee1ed355bec802f2f95905a3fe4fbfff8b200c3e44ccd55fc34e15b38952'
|
|
4
|
+
data.tar.gz: 261cf26d134c4ab6bd3991b79c9900d6bed6f3af101b1a05597fdc8c072928af
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bf01ef5efe1db91a20f804645dbdd62cd218f11659662b37d71db893d5c75a9a70bc1de81dd2c9830b03dcabf5737f6b9b65767569f21e342503bfa4669cb32e
|
|
7
|
+
data.tar.gz: 53b29fccb2498a89ba2eece12f8c6b11fd8eca58cabca91c60aa28f0e7b349b9812366679e24811bdb584833f49847a3893ac5e725130c04b5a2c08951d8e2f9
|
data/README.adoc
CHANGED
|
@@ -148,6 +148,8 @@ QEA file ──→ Ea::Qea::Database ──→ Ea::Transformers::QeaToXmi ─
|
|
|
148
148
|
| `ea parse FILE` | Parse QEA/XMI to a `Lutaml::Uml::Document` (requires lutaml-uml)
|
|
149
149
|
| `ea convert FILE --to xmi` | Convert QEA → Sparx XMI
|
|
150
150
|
| `ea diff OLD NEW` | Structural diff between two EA files (table/json/html)
|
|
151
|
+
| `ea model:lint FILE` | Duplicate and ambiguous names, shared attribute positions, strays, broken connectors (report/json/table)
|
|
152
|
+
| `ea model:diff OLD NEW` | Element-level diff of a project file and its export by EA id: added, removed, renamed, moved, retyped, notes, attributes, parent, connectors
|
|
151
153
|
| `ea export FILE --format xmi/json/plantuml/xsd` | Export the model
|
|
152
154
|
| `ea mdg FILE` | Inspect MDG technologies (list/show)
|
|
153
155
|
| `ea query FILE` | Filter model elements (type, package, stereotype)
|
data/lib/ea/cli/app.rb
CHANGED
|
@@ -155,6 +155,28 @@ module Ea
|
|
|
155
155
|
Command::Lint.new(file: file, **symbolize(options)).call
|
|
156
156
|
end
|
|
157
157
|
|
|
158
|
+
desc "model:lint FILE",
|
|
159
|
+
"Lint a project file or export: duplicate and ambiguous names, " \
|
|
160
|
+
"shared attribute positions, strays, broken connectors"
|
|
161
|
+
option :format, type: :string, default: "report",
|
|
162
|
+
desc: "Output format: report | json | table"
|
|
163
|
+
option :json, type: :boolean, default: false,
|
|
164
|
+
desc: "Shorthand for --format=json"
|
|
165
|
+
option :rule, type: :string, desc: "Run only the rules whose name contains this"
|
|
166
|
+
def model_lint(file)
|
|
167
|
+
Command::ModelLint.new(file: file, **symbolize(options)).call
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
desc "model:diff OLD NEW",
|
|
171
|
+
"Element-level diff of two project files or exports, joined on EA ids"
|
|
172
|
+
option :format, type: :string, default: "report",
|
|
173
|
+
desc: "Output format: report | json | table"
|
|
174
|
+
option :json, type: :boolean, default: false,
|
|
175
|
+
desc: "Shorthand for --format=json"
|
|
176
|
+
def model_diff(old, new)
|
|
177
|
+
Command::ModelDiff.new(old: old, new: new, **symbolize(options)).call
|
|
178
|
+
end
|
|
179
|
+
|
|
158
180
|
desc "query FILE", "Filter model elements by criteria"
|
|
159
181
|
option :type, type: :string, desc: "Filter by object_type (Class, etc.)"
|
|
160
182
|
option :package, type: :string, desc: "Restrict to a package name"
|
data/lib/ea/cli/command/base.rb
CHANGED
|
@@ -47,6 +47,26 @@ module Ea
|
|
|
47
47
|
raise Ea::Cli::Error, "Failed to load #{path}: #{e.message}"
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
+
# Load any EA file (QEA or Sparx XMI) into the canonical
|
|
51
|
+
# Ea::Model::Document, the model the lint and diff commands read.
|
|
52
|
+
# @return [Ea::Model::Document]
|
|
53
|
+
def load_document(path = file_path)
|
|
54
|
+
validate_file!(path)
|
|
55
|
+
case File.extname(path).downcase
|
|
56
|
+
when ".qea"
|
|
57
|
+
Ea::Sources::Qea::Adapter.from_path(path)
|
|
58
|
+
when ".xmi", ".xml"
|
|
59
|
+
Ea::Sources::Xmi::Adapter.from_path(path)
|
|
60
|
+
else
|
|
61
|
+
raise Ea::Cli::UnsupportedFormat,
|
|
62
|
+
"Unknown file format: #{File.extname(path)}"
|
|
63
|
+
end
|
|
64
|
+
rescue Ea::Cli::Error
|
|
65
|
+
raise
|
|
66
|
+
rescue Ea::Error => e
|
|
67
|
+
raise Ea::Cli::Error, "Failed to load #{path}: #{e.message}"
|
|
68
|
+
end
|
|
69
|
+
|
|
50
70
|
# Parse any EA file (QEA or Sparx XMI) to a Lutaml::Uml::Document.
|
|
51
71
|
# Lazy-loads lutaml-uml via the bridge's require guard.
|
|
52
72
|
# @return [Lutaml::Uml::Document]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module Cli
|
|
5
|
+
module Command
|
|
6
|
+
# `ea model:diff OLD NEW [--format=report|json|table] [--json]`
|
|
7
|
+
#
|
|
8
|
+
# Element-level differences between two project files or exports
|
|
9
|
+
# (a .qea beside its XMI export, or two revisions), joined on EA's
|
|
10
|
+
# element ids. Exit 1 when anything differs.
|
|
11
|
+
class ModelDiff < Base
|
|
12
|
+
COLUMNS = %i[kind element_kind element_name detail before after].freeze
|
|
13
|
+
|
|
14
|
+
def call
|
|
15
|
+
report = comparator.report(old_source: options[:old],
|
|
16
|
+
new_source: options[:new])
|
|
17
|
+
case output_format
|
|
18
|
+
when "json"
|
|
19
|
+
puts report.to_json
|
|
20
|
+
when "table"
|
|
21
|
+
formatter.render(rows_for(report), columns: COLUMNS)
|
|
22
|
+
else
|
|
23
|
+
puts Ea::ModelDiff::TextReporter.new(report).render
|
|
24
|
+
end
|
|
25
|
+
exit(1) unless report.identical?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def comparator
|
|
31
|
+
@comparator ||= Ea::ModelDiff::Comparator.new(load_document(options[:old]),
|
|
32
|
+
load_document(options[:new]))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def output_format
|
|
36
|
+
return "json" if options[:json]
|
|
37
|
+
|
|
38
|
+
options[:format].to_s
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def rows_for(report)
|
|
42
|
+
report.changes.map do |change|
|
|
43
|
+
[change.kind, change.element_kind, change.element_name,
|
|
44
|
+
change.detail, change.before, change.after]
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module Cli
|
|
5
|
+
module Command
|
|
6
|
+
# `ea model:lint FILE [--format=report|json|table] [--json] [--rule=NAME]`
|
|
7
|
+
#
|
|
8
|
+
# Reports what a lookup by name cannot answer, what a diagram will
|
|
9
|
+
# order by name, and what no tree walk or connector can reach.
|
|
10
|
+
# Exit 1 when an error-severity finding is reported.
|
|
11
|
+
class ModelLint < Base
|
|
12
|
+
COLUMNS = %i[severity rule element_name message].freeze
|
|
13
|
+
|
|
14
|
+
def call
|
|
15
|
+
report = Ea::ModelLint::Engine.new(document, rules: selected_rules)
|
|
16
|
+
.report(source: file_path)
|
|
17
|
+
case output_format
|
|
18
|
+
when "json"
|
|
19
|
+
puts report.to_json
|
|
20
|
+
when "table"
|
|
21
|
+
formatter.render(rows_for(report), columns: COLUMNS)
|
|
22
|
+
else
|
|
23
|
+
puts Ea::ModelLint::TextReporter.new(report).render
|
|
24
|
+
end
|
|
25
|
+
exit(1) if report.error_count.positive?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def document
|
|
31
|
+
@document ||= load_document(file_path)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def output_format
|
|
35
|
+
return "json" if options[:json]
|
|
36
|
+
|
|
37
|
+
options[:format].to_s
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def selected_rules
|
|
41
|
+
return unless options[:rule]
|
|
42
|
+
|
|
43
|
+
needle = options[:rule].to_s.downcase
|
|
44
|
+
Ea::ModelLint::Engine::DEFAULT_RULES.select do |rule|
|
|
45
|
+
rule.name.downcase.include?(needle)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def rows_for(report)
|
|
50
|
+
report.findings.map do |finding|
|
|
51
|
+
[finding.severity, finding.rule, finding.element_name,
|
|
52
|
+
finding.message]
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
data/lib/ea/cli/command.rb
CHANGED
|
@@ -17,6 +17,8 @@ module Ea
|
|
|
17
17
|
autoload :Mdg, "ea/cli/command/mdg"
|
|
18
18
|
autoload :Diff, "ea/cli/command/diff"
|
|
19
19
|
autoload :Lint, "ea/cli/command/lint"
|
|
20
|
+
autoload :ModelLint, "ea/cli/command/model_lint"
|
|
21
|
+
autoload :ModelDiff, "ea/cli/command/model_diff"
|
|
20
22
|
autoload :Query, "ea/cli/command/query"
|
|
21
23
|
autoload :Info, "ea/cli/command/info"
|
|
22
24
|
end
|
data/lib/ea/guid_format.rb
CHANGED
|
@@ -55,6 +55,16 @@ module Ea
|
|
|
55
55
|
ea_guid.to_s.gsub(/[{}]/, "")
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
+
# The identity behind any of EA's spellings of one element's id: an
|
|
59
|
+
# xmi:id (EAID_..., EAPK_...), a braced or a bare GUID. Two reads of
|
|
60
|
+
# one model — a project file and its export — join on this. An id
|
|
61
|
+
# that is not EA-shaped keeps its own spelling, case-insensitively.
|
|
62
|
+
# @param id [String, nil]
|
|
63
|
+
# @return [String] the GUID's hex, e.g. "ABCDEF0123456789ABCDEF0123456789"
|
|
64
|
+
def id_key(id)
|
|
65
|
+
id.to_s.sub(/\A(?:EAID|EAPK)_/i, "").gsub(/[{}\-_]/, "").upcase
|
|
66
|
+
end
|
|
67
|
+
|
|
58
68
|
# Build a member-end xmi:id for one side of a connector.
|
|
59
69
|
#
|
|
60
70
|
# Sparx EA's convention: take the connector's GUID, drop the first
|
data/lib/ea/model/document.rb
CHANGED
|
@@ -49,6 +49,26 @@ module Ea
|
|
|
49
49
|
initialize_empty: true
|
|
50
50
|
attribute :diagrams, Diagram, collection: true, initialize_empty: true
|
|
51
51
|
|
|
52
|
+
# Every package's path — its ancestors' names, outermost first —
|
|
53
|
+
# keyed by package id. A package whose parent is not in the
|
|
54
|
+
# document starts a path of its own.
|
|
55
|
+
#
|
|
56
|
+
# @return [Hash<String, String>] package id => "Outer::Inner"
|
|
57
|
+
def package_paths
|
|
58
|
+
@package_paths ||= begin
|
|
59
|
+
by_id = packages.to_h { |package| [package.id, package] }
|
|
60
|
+
packages.to_h do |package|
|
|
61
|
+
names = []
|
|
62
|
+
current = package
|
|
63
|
+
while current
|
|
64
|
+
names.unshift(current.name)
|
|
65
|
+
current = by_id[current.parent_id]
|
|
66
|
+
end
|
|
67
|
+
[package.id, names.join("::")]
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
52
72
|
# Flat lookup indexes, built lazily by consumers. Not
|
|
53
73
|
# serialized — they're derived from the element collections.
|
|
54
74
|
#
|
data/lib/ea/model/property.rb
CHANGED
|
@@ -30,6 +30,7 @@ module Ea
|
|
|
30
30
|
attribute :aggregation, :string, default: -> { "none" } # none|shared|composite
|
|
31
31
|
attribute :association_id, :string # non-nil when this property is a navigable end of an Association
|
|
32
32
|
attribute :visibility, :string # public|protected|private|package
|
|
33
|
+
attribute :position, :integer # EA's tree position (t_attribute.Pos); nil = unpositioned
|
|
33
34
|
attribute :stereotype_refs, :string, collection: true, initialize_empty: true
|
|
34
35
|
attribute :tagged_values, TaggedValue, collection: true, initialize_empty: true
|
|
35
36
|
attribute :annotations, Annotation, collection: true, initialize_empty: true
|
|
@@ -53,6 +54,7 @@ module Ea
|
|
|
53
54
|
map "aggregation", to: :aggregation, render_default: true
|
|
54
55
|
map "associationId", to: :association_id
|
|
55
56
|
map "visibility", to: :visibility
|
|
57
|
+
map "position", to: :position
|
|
56
58
|
map "stereotypeRefs", to: :stereotype_refs, render_empty: true
|
|
57
59
|
map "taggedValues", to: :tagged_values, render_empty: true
|
|
58
60
|
map "annotations", to: :annotations, render_empty: true
|
|
@@ -7,6 +7,15 @@ module Ea
|
|
|
7
7
|
# Dependency. The discriminator (`relationship_kind`) lets
|
|
8
8
|
# consumers dispatch without `is_a?` ladders.
|
|
9
9
|
class Relationship < Base
|
|
10
|
+
# The id attributes that name each kind's ends, in the model's
|
|
11
|
+
# own order: a lint, a diff or a drawing walks them the same way.
|
|
12
|
+
END_ATTRIBUTES = {
|
|
13
|
+
"association" => %i[source_id target_id],
|
|
14
|
+
"generalization" => %i[specific_id general_id],
|
|
15
|
+
"realization" => %i[realizing_id contract_id],
|
|
16
|
+
"dependency" => %i[client_id supplier_id]
|
|
17
|
+
}.freeze
|
|
18
|
+
|
|
10
19
|
attribute :qualified_name, :string
|
|
11
20
|
attribute :stereotype, :string
|
|
12
21
|
attribute :relationship_kind, :string, default: -> { "relationship" }
|
|
@@ -18,6 +27,12 @@ module Ea
|
|
|
18
27
|
map "stereotype", to: :stereotype
|
|
19
28
|
map "relationshipKind", to: :relationship_kind, render_default: true
|
|
20
29
|
end
|
|
30
|
+
|
|
31
|
+
# @return [Array<String>] the ids of the ends this kind declares
|
|
32
|
+
def end_ids
|
|
33
|
+
END_ATTRIBUTES.fetch(relationship_kind, [])
|
|
34
|
+
.filter_map { |attribute| public_send(attribute) }
|
|
35
|
+
end
|
|
21
36
|
end
|
|
22
37
|
end
|
|
23
38
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module ModelDiff
|
|
5
|
+
# One difference between two models. `kind` says what changed,
|
|
6
|
+
# `before` and `after` hold the two values when there are two.
|
|
7
|
+
class Change < Lutaml::Model::Serializable
|
|
8
|
+
KINDS = %w[added removed renamed moved retyped notes attributes
|
|
9
|
+
parent connectors].freeze
|
|
10
|
+
|
|
11
|
+
attribute :kind, :string
|
|
12
|
+
attribute :element_kind, :string
|
|
13
|
+
attribute :element_id, :string
|
|
14
|
+
attribute :element_name, :string
|
|
15
|
+
attribute :detail, :string
|
|
16
|
+
attribute :before, :string
|
|
17
|
+
attribute :after, :string
|
|
18
|
+
|
|
19
|
+
json do
|
|
20
|
+
map "kind", to: :kind
|
|
21
|
+
map "elementKind", to: :element_kind
|
|
22
|
+
map "elementId", to: :element_id
|
|
23
|
+
map "elementName", to: :element_name
|
|
24
|
+
map "detail", to: :detail
|
|
25
|
+
map "before", to: :before
|
|
26
|
+
map "after", to: :after
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module ModelDiff
|
|
5
|
+
# Joins two canonical documents on EA's element ids and describes
|
|
6
|
+
# what differs per element. A project file and its export spell one
|
|
7
|
+
# element's id differently (a bare GUID, an EAID_ xmi:id), so the
|
|
8
|
+
# join is on the GUID behind the spelling; a rename is therefore a
|
|
9
|
+
# change to one element, not a removal plus an addition.
|
|
10
|
+
class Comparator
|
|
11
|
+
PACKAGE_KIND = ->(_package) { "package" }
|
|
12
|
+
CLASSIFIER_KIND = lambda(&:model_kind)
|
|
13
|
+
INSTANCE_KIND = ->(_instance) { "instance" }
|
|
14
|
+
RELATIONSHIP_KIND = lambda(&:relationship_kind)
|
|
15
|
+
|
|
16
|
+
# @param old_document [Ea::Model::Document]
|
|
17
|
+
# @param new_document [Ea::Model::Document]
|
|
18
|
+
def initialize(old_document, new_document)
|
|
19
|
+
@old = Side.new(old_document)
|
|
20
|
+
@new = Side.new(new_document)
|
|
21
|
+
@changes = []
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# @return [Ea::ModelDiff::Report]
|
|
25
|
+
def report(old_source:, new_source:)
|
|
26
|
+
compare_packages
|
|
27
|
+
compare_classifiers
|
|
28
|
+
compare_instances
|
|
29
|
+
compare_relationships
|
|
30
|
+
Report.new(old_source: old_source, new_source: new_source,
|
|
31
|
+
changes: @changes)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
# ---- elements ---------------------------------------------------
|
|
37
|
+
|
|
38
|
+
def compare_packages
|
|
39
|
+
each_pair(@old.packages, @new.packages, PACKAGE_KIND) do |before, after|
|
|
40
|
+
renamed_change(before, after, "package")
|
|
41
|
+
moved_change(before, after, "package") do |side, package|
|
|
42
|
+
side.parent_path_of(package)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# A project file renders an instance row as a simple class as well
|
|
48
|
+
# as an instance specification; an export lists the specification
|
|
49
|
+
# only. Both name the row by the same id, so a class that is an
|
|
50
|
+
# instance on the other side is that instance, not a difference.
|
|
51
|
+
def compare_classifiers
|
|
52
|
+
each_pair(@old.classifiers - @old.instances_as_classifiers,
|
|
53
|
+
@new.classifiers - @new.instances_as_classifiers,
|
|
54
|
+
CLASSIFIER_KIND) do |before, after|
|
|
55
|
+
kind = after.model_kind
|
|
56
|
+
renamed_change(before, after, kind)
|
|
57
|
+
moved_change(before, after, kind) { |side, classifier| side.path_of(classifier) }
|
|
58
|
+
retyped_change(before, after)
|
|
59
|
+
notes_change(before, after, kind)
|
|
60
|
+
attributes_change(before, after, kind)
|
|
61
|
+
parent_change(before, after, kind)
|
|
62
|
+
connectors_change(before, after, kind)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def compare_instances
|
|
67
|
+
each_pair(@old.instance_specifications, @new.instance_specifications,
|
|
68
|
+
INSTANCE_KIND) do |before, after|
|
|
69
|
+
renamed_change(before, after, "instance")
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# A relationship that names no end belongs to no element of the
|
|
74
|
+
# model (EA emits such stubs for its diagram-level associations);
|
|
75
|
+
# there is nothing to join it by, so it is not a difference.
|
|
76
|
+
def compare_relationships
|
|
77
|
+
each_pair(@old.relationships.select { |rel| rel.end_ids.any? },
|
|
78
|
+
@new.relationships.select { |rel| rel.end_ids.any? },
|
|
79
|
+
RELATIONSHIP_KIND) do |before, after|
|
|
80
|
+
ends_change(before, after)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Records the added and removed elements, then yields each pair
|
|
85
|
+
# present on both sides. +kind+ names an element's kind: the
|
|
86
|
+
# collection being compared knows it, the element does not always.
|
|
87
|
+
def each_pair(before_elements, after_elements, kind)
|
|
88
|
+
before_by_key = before_elements.to_h { |element| [element_key(element), element] }
|
|
89
|
+
after_by_key = after_elements.to_h { |element| [element_key(element), element] }
|
|
90
|
+
(after_by_key.keys - before_by_key.keys).each do |key|
|
|
91
|
+
added(after_by_key[key], kind)
|
|
92
|
+
end
|
|
93
|
+
(before_by_key.keys - after_by_key.keys).each do |key|
|
|
94
|
+
removed(before_by_key[key], kind)
|
|
95
|
+
end
|
|
96
|
+
(before_by_key.keys & after_by_key.keys).each do |key|
|
|
97
|
+
yield before_by_key[key], after_by_key[key]
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def element_key(element)
|
|
102
|
+
Ea::GuidFormat.id_key(element.id)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def key(id)
|
|
106
|
+
Ea::GuidFormat.id_key(id)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# ---- one change each --------------------------------------------
|
|
110
|
+
|
|
111
|
+
def added(element, kind)
|
|
112
|
+
record("added", element, kind.call(element), nil, nil, nil)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def removed(element, kind)
|
|
116
|
+
record("removed", element, kind.call(element), nil, nil, nil)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def renamed_change(before, after, kind)
|
|
120
|
+
return if before.name == after.name
|
|
121
|
+
|
|
122
|
+
record("renamed", after, kind, nil, before.name, after.name)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def moved_change(before, after, kind)
|
|
126
|
+
old_place = yield @old, before
|
|
127
|
+
new_place = yield @new, after
|
|
128
|
+
return if old_place == new_place
|
|
129
|
+
|
|
130
|
+
record("moved", after, kind, nil, old_place, new_place)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def retyped_change(before, after)
|
|
134
|
+
return if before.model_kind == after.model_kind
|
|
135
|
+
|
|
136
|
+
record("retyped", after, after.model_kind, nil, before.model_kind,
|
|
137
|
+
after.model_kind)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def notes_change(before, after, kind)
|
|
141
|
+
return if notes_of(before) == notes_of(after)
|
|
142
|
+
|
|
143
|
+
record("notes", after, kind, nil, notes_of(before), notes_of(after))
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def notes_of(element)
|
|
147
|
+
element.annotations.map(&:body).compact.join("\n").strip
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Attribute differences are named by what happened to each
|
|
151
|
+
# attribute; the order of the surviving ones is a change of its own.
|
|
152
|
+
def attributes_change(before, after, kind)
|
|
153
|
+
old_rows = attribute_rows(before)
|
|
154
|
+
new_rows = attribute_rows(after)
|
|
155
|
+
return if old_rows == new_rows
|
|
156
|
+
|
|
157
|
+
record("attributes", after, kind, attribute_detail(old_rows, new_rows),
|
|
158
|
+
nil, nil)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# Navigable association ends are connectors, compared separately;
|
|
162
|
+
# the rest is ordered by EA's attribute rule, as an export may
|
|
163
|
+
# list a positioned attribute out of place.
|
|
164
|
+
def attribute_rows(classifier)
|
|
165
|
+
classifier.properties.reject(&:association_id)
|
|
166
|
+
.each_with_index
|
|
167
|
+
.sort_by { |property, index| Ea::Rules::AttributeOrder.property_key(property, index) }
|
|
168
|
+
.map do |property, _index|
|
|
169
|
+
[property.name, property.type_name,
|
|
170
|
+
property.multiplicity_lower, property.multiplicity_upper]
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def attribute_detail(old_rows, new_rows)
|
|
175
|
+
old_by_name = old_rows.to_h { |row| [row[0], row] }
|
|
176
|
+
new_by_name = new_rows.to_h { |row| [row[0], row] }
|
|
177
|
+
kept = old_rows.map(&:first) & new_rows.map(&:first)
|
|
178
|
+
parts = (new_rows.map(&:first) - kept).map { |name| "+#{name}" }
|
|
179
|
+
parts += (old_rows.map(&:first) - kept).map { |name| "-#{name}" }
|
|
180
|
+
kept.each do |name|
|
|
181
|
+
next if old_by_name[name] == new_by_name[name]
|
|
182
|
+
|
|
183
|
+
parts << "#{name}: #{format_row(old_by_name[name])} -> #{format_row(new_by_name[name])}"
|
|
184
|
+
end
|
|
185
|
+
old_order = old_rows.map(&:first) & kept
|
|
186
|
+
new_order = new_rows.map(&:first) & kept
|
|
187
|
+
parts << "order: #{old_order.join(", ")} -> #{new_order.join(", ")}" if old_order != new_order
|
|
188
|
+
parts.join("; ")
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def format_row(row)
|
|
192
|
+
bounds = [row[2], row[3]].compact.map { |bound| bound == -1 ? "*" : bound }
|
|
193
|
+
.join("..")
|
|
194
|
+
[row[1], bounds].reject { |part| part.nil? || part.empty? }.join(" ")
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# The parents of a classifier are the generals of the
|
|
198
|
+
# generalizations it is the specific end of.
|
|
199
|
+
def parent_change(before, after, kind)
|
|
200
|
+
old_parents = parents_of(@old, element_key(before))
|
|
201
|
+
new_parents = parents_of(@new, element_key(after))
|
|
202
|
+
return if old_parents == new_parents
|
|
203
|
+
|
|
204
|
+
record("parent", after, kind, nil, old_parents.join(", "),
|
|
205
|
+
new_parents.join(", "))
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def parents_of(side, classifier_key)
|
|
209
|
+
side.relationships
|
|
210
|
+
.select { |rel| rel.relationship_kind == "generalization" && key(rel.specific_id) == classifier_key }
|
|
211
|
+
.map { |rel| side.name(rel.general_id) }
|
|
212
|
+
.sort
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
# The connectors touching an element, by kind and by the element
|
|
216
|
+
# at the other end.
|
|
217
|
+
# A connector of an element is matched by the relationship's
|
|
218
|
+
# identity and its other end (both by key, as the two sides spell
|
|
219
|
+
# ids differently), so a re-pointed connector is one lost and one
|
|
220
|
+
# gained; it is described by the other end's name and the id as
|
|
221
|
+
# that side spells it.
|
|
222
|
+
def connectors_change(before, after, kind)
|
|
223
|
+
old_connectors = connectors_of(@old, element_key(before))
|
|
224
|
+
new_connectors = connectors_of(@new, element_key(after))
|
|
225
|
+
return if old_connectors.keys.sort == new_connectors.keys.sort
|
|
226
|
+
|
|
227
|
+
detail = (new_connectors.keys - old_connectors.keys)
|
|
228
|
+
.map { |connector_key| "+#{new_connectors[connector_key]}" }
|
|
229
|
+
detail += (old_connectors.keys - new_connectors.keys)
|
|
230
|
+
.map { |connector_key| "-#{old_connectors[connector_key]}" }
|
|
231
|
+
record("connectors", after, kind, detail.join("; "), nil, nil)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
# @return [Hash<String, String>] relationship key => description
|
|
235
|
+
def connectors_of(side, element_key)
|
|
236
|
+
side.relationships.filter_map do |relationship|
|
|
237
|
+
ends = relationship.end_ids
|
|
238
|
+
next unless ends.any? { |id| key(id) == element_key }
|
|
239
|
+
|
|
240
|
+
other = ends.find { |id| key(id) != element_key } || ends.first
|
|
241
|
+
["#{key(relationship.id)}|#{key(other)}",
|
|
242
|
+
"#{relationship.relationship_kind} #{side.name(other)} " \
|
|
243
|
+
"[#{relationship.id}]"]
|
|
244
|
+
end.to_h
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def ends_change(before, after)
|
|
248
|
+
old_ends = before.end_ids.map { |id| @old.name(id) }
|
|
249
|
+
new_ends = after.end_ids.map { |id| @new.name(id) }
|
|
250
|
+
return if old_ends == new_ends
|
|
251
|
+
|
|
252
|
+
record("connectors", after, after.relationship_kind, "ends changed",
|
|
253
|
+
old_ends.join(" -> "), new_ends.join(" -> "))
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def record(kind, element, element_kind, detail, before, after)
|
|
257
|
+
@changes << Change.new(
|
|
258
|
+
kind: kind, element_kind: element_kind, element_id: element.id,
|
|
259
|
+
element_name: element.name, detail: detail, before: before,
|
|
260
|
+
after: after
|
|
261
|
+
)
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
# What a comparison needs of one document: names and package
|
|
265
|
+
# paths by element key.
|
|
266
|
+
class Side
|
|
267
|
+
attr_reader :packages, :classifiers, :relationships,
|
|
268
|
+
:instance_specifications
|
|
269
|
+
|
|
270
|
+
def initialize(document)
|
|
271
|
+
@packages = document.packages
|
|
272
|
+
@classifiers = document.classifiers
|
|
273
|
+
@relationships = document.relationships
|
|
274
|
+
@instance_specifications = document.instance_specifications
|
|
275
|
+
@names = element_names
|
|
276
|
+
@paths = document.package_paths
|
|
277
|
+
.transform_keys { |id| Ea::GuidFormat.id_key(id) }
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
def name(id)
|
|
281
|
+
@names[Ea::GuidFormat.id_key(id)] || id
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
# Classifiers an adapter also lists as instance specifications.
|
|
285
|
+
def instances_as_classifiers
|
|
286
|
+
keys = instance_specifications
|
|
287
|
+
.to_h { |instance| [Ea::GuidFormat.id_key(instance.id), true] }
|
|
288
|
+
classifiers.select { |classifier| keys[Ea::GuidFormat.id_key(classifier.id)] }
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
def path_of(classifier)
|
|
292
|
+
@paths[Ea::GuidFormat.id_key(classifier.package_id)] || classifier.package_name
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
def parent_path_of(package)
|
|
296
|
+
@paths[Ea::GuidFormat.id_key(package.parent_id)] || package.parent_id
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
private
|
|
300
|
+
|
|
301
|
+
def element_names
|
|
302
|
+
(@classifiers + @packages + @instance_specifications)
|
|
303
|
+
.to_h { |element| [Ea::GuidFormat.id_key(element.id), element.name] }
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
end
|
|
308
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module ModelDiff
|
|
5
|
+
# The changes between two models; serialization is the framework's.
|
|
6
|
+
class Report < Lutaml::Model::Serializable
|
|
7
|
+
attribute :old_source, :string
|
|
8
|
+
attribute :new_source, :string
|
|
9
|
+
attribute :changes, Change, collection: true, initialize_empty: true
|
|
10
|
+
|
|
11
|
+
json do
|
|
12
|
+
map "oldSource", to: :old_source
|
|
13
|
+
map "newSource", to: :new_source
|
|
14
|
+
map "changes", to: :changes, render_empty: true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def identical?
|
|
18
|
+
changes.empty?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def changes_for(kind)
|
|
22
|
+
changes.select { |change| change.kind == kind.to_s }
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module ModelDiff
|
|
5
|
+
# Plain-text rendering of a diff: changes grouped by kind in a fixed
|
|
6
|
+
# order, then a count per kind.
|
|
7
|
+
class TextReporter
|
|
8
|
+
def initialize(report)
|
|
9
|
+
@report = report
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def render
|
|
13
|
+
return "#{@report.old_source} and #{@report.new_source} are identical\n" if @report.identical?
|
|
14
|
+
|
|
15
|
+
lines = ["#{@report.old_source} -> #{@report.new_source}: " \
|
|
16
|
+
"#{@report.changes.size} change(s)"]
|
|
17
|
+
Change::KINDS.each do |kind|
|
|
18
|
+
@report.changes_for(kind).each do |change|
|
|
19
|
+
lines << format("%<kind>-10s %<element_kind>-11s %<detail>s",
|
|
20
|
+
kind: kind, element_kind: change.element_kind,
|
|
21
|
+
detail: describe(change))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
lines << "--"
|
|
25
|
+
@report.changes.group_by(&:kind).sort.each do |kind, group|
|
|
26
|
+
lines << "#{kind}: #{group.size}"
|
|
27
|
+
end
|
|
28
|
+
lines.join("\n")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def describe(change)
|
|
34
|
+
text = "#{change.element_name} (#{change.element_id})"
|
|
35
|
+
text += " #{change.detail}" if change.detail.to_s.size.positive?
|
|
36
|
+
text += ": #{change.before.inspect} -> #{change.after.inspect}" if change.before || change.after
|
|
37
|
+
text
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
# Element-level diff between two models of the same EA project (a
|
|
5
|
+
# project file and its export, or two revisions), joined on EA's
|
|
6
|
+
# element ids.
|
|
7
|
+
module ModelDiff
|
|
8
|
+
autoload :Change, "ea/model_diff/change"
|
|
9
|
+
autoload :Report, "ea/model_diff/report"
|
|
10
|
+
autoload :Comparator, "ea/model_diff/comparator"
|
|
11
|
+
autoload :TextReporter, "ea/model_diff/text_reporter"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module ModelLint
|
|
5
|
+
# Runs every registered rule over one canonical document. A new
|
|
6
|
+
# question = a new rule class in DEFAULT_RULES; nothing else changes.
|
|
7
|
+
class Engine
|
|
8
|
+
DEFAULT_RULES = [
|
|
9
|
+
Rules::DuplicateNames,
|
|
10
|
+
Rules::AmbiguousNames,
|
|
11
|
+
Rules::SharedAttributePositions,
|
|
12
|
+
Rules::OutsidePackageTree,
|
|
13
|
+
Rules::MissingConnectorEnds
|
|
14
|
+
].freeze
|
|
15
|
+
|
|
16
|
+
# @param document [Ea::Model::Document]
|
|
17
|
+
# @param rules [Array<Class>, nil] rule classes; nil runs them all
|
|
18
|
+
def initialize(document, rules: DEFAULT_RULES)
|
|
19
|
+
@document = document
|
|
20
|
+
@rules = rules.nil? ? DEFAULT_RULES : rules
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @param source [String] the file the document was read from
|
|
24
|
+
# @return [Ea::ModelLint::Report]
|
|
25
|
+
def report(source:)
|
|
26
|
+
findings = @rules.flat_map { |rule| rule.new(@document).findings }
|
|
27
|
+
Report.new(source: source, findings: findings)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module ModelLint
|
|
5
|
+
# One thing worth a look in a model: what was found (rule), how much
|
|
6
|
+
# it matters (severity), where (element and package), and why.
|
|
7
|
+
class Finding < Lutaml::Model::Serializable
|
|
8
|
+
SEVERITIES = %w[error warning].freeze
|
|
9
|
+
|
|
10
|
+
attribute :rule, :string
|
|
11
|
+
attribute :severity, :string
|
|
12
|
+
attribute :element_id, :string
|
|
13
|
+
attribute :element_name, :string
|
|
14
|
+
attribute :package, :string
|
|
15
|
+
attribute :message, :string
|
|
16
|
+
|
|
17
|
+
json do
|
|
18
|
+
map "rule", to: :rule
|
|
19
|
+
map "severity", to: :severity
|
|
20
|
+
map "elementId", to: :element_id
|
|
21
|
+
map "elementName", to: :element_name
|
|
22
|
+
map "package", to: :package
|
|
23
|
+
map "message", to: :message
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def error?
|
|
27
|
+
severity == "error"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module ModelLint
|
|
5
|
+
# The findings for one model. Serialization is the framework's
|
|
6
|
+
# (`to_json`), so automation reads the same shape the text shows.
|
|
7
|
+
class Report < Lutaml::Model::Serializable
|
|
8
|
+
attribute :source, :string
|
|
9
|
+
attribute :findings, Finding, collection: true, initialize_empty: true
|
|
10
|
+
|
|
11
|
+
json do
|
|
12
|
+
map "source", to: :source
|
|
13
|
+
map "findings", to: :findings, render_empty: true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def error_count
|
|
17
|
+
findings.count(&:error?)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def warning_count
|
|
21
|
+
findings.size - error_count
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def findings_for(rule)
|
|
25
|
+
findings.select { |finding| finding.rule == rule.to_s }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module ModelLint
|
|
5
|
+
module Rules
|
|
6
|
+
# One (package, name) pair that names more than one element. EA's
|
|
7
|
+
# tree order decides which one a lookup offers first; the others
|
|
8
|
+
# are reachable by path only.
|
|
9
|
+
class AmbiguousNames < Base
|
|
10
|
+
RULE = "ambiguous_names"
|
|
11
|
+
|
|
12
|
+
def findings
|
|
13
|
+
classifiers.group_by { |classifier| [package_path(classifier), classifier.name] }
|
|
14
|
+
.filter_map do |(path, name), group|
|
|
15
|
+
next unless group.size > 1
|
|
16
|
+
|
|
17
|
+
first = group.first
|
|
18
|
+
finding(RULE, "warning", first,
|
|
19
|
+
"\"#{name}\" names #{group.size} elements in " \
|
|
20
|
+
"#{path.inspect}; EA's tree order offers #{first.id} " \
|
|
21
|
+
"first, then #{group.drop(1).map(&:id).join(", ")}",
|
|
22
|
+
package: path)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module ModelLint
|
|
5
|
+
module Rules
|
|
6
|
+
# A name that means more than one thing: the same classifier name
|
|
7
|
+
# under different packages. A lookup by name alone is ambiguous;
|
|
8
|
+
# the finding lists every package the name occurs in.
|
|
9
|
+
class DuplicateNames < Base
|
|
10
|
+
RULE = "duplicate_names"
|
|
11
|
+
|
|
12
|
+
def findings
|
|
13
|
+
classifiers.group_by(&:name).filter_map do |name, group|
|
|
14
|
+
paths = group.map { |classifier| package_path(classifier) }.uniq
|
|
15
|
+
next unless paths.size > 1
|
|
16
|
+
|
|
17
|
+
finding(RULE, "warning", nil,
|
|
18
|
+
"\"#{name}\" occurs in #{paths.size} packages: " \
|
|
19
|
+
"#{paths.sort.join(", ")}",
|
|
20
|
+
package: paths.min).tap do |item|
|
|
21
|
+
item.element_name = name
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module ModelLint
|
|
5
|
+
module Rules
|
|
6
|
+
# Connectors an end of which is missing from the model: the
|
|
7
|
+
# relationship survives, what it pointed at did not.
|
|
8
|
+
class MissingConnectorEnds < Base
|
|
9
|
+
RULE = "missing_connector_ends"
|
|
10
|
+
|
|
11
|
+
# A project file records an end whose row is missing as no id;
|
|
12
|
+
# an export keeps the id it cannot resolve. Both are reported. A
|
|
13
|
+
# relationship that names no end at all is one of EA's stubs
|
|
14
|
+
# (a diagram-level association), not a broken connector.
|
|
15
|
+
def findings
|
|
16
|
+
@document.relationships.reject { |relationship| relationship.end_ids.empty? }
|
|
17
|
+
.flat_map do |relationship|
|
|
18
|
+
end_attributes(relationship).flat_map do |attribute|
|
|
19
|
+
end_id = relationship.public_send(attribute)
|
|
20
|
+
next [] unless end_id.nil? || !model_ids.key?(Ea::GuidFormat.id_key(end_id))
|
|
21
|
+
|
|
22
|
+
[finding(RULE, "error", relationship,
|
|
23
|
+
"#{relationship.relationship_kind} #{relationship.id} " \
|
|
24
|
+
"has no #{attribute.to_s.delete_suffix("_id")} in the " \
|
|
25
|
+
"model#{end_id ? " (#{end_id})" : ""}")]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def end_attributes(relationship)
|
|
33
|
+
Ea::Model::Relationship::END_ATTRIBUTES
|
|
34
|
+
.fetch(relationship.relationship_kind, [])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Keyed by identity, as a reference spells a package EAID_
|
|
38
|
+
# where its own id is EAPK_.
|
|
39
|
+
def model_ids
|
|
40
|
+
@model_ids ||= (classifiers + packages + @document.instance_specifications)
|
|
41
|
+
.to_h { |element| [Ea::GuidFormat.id_key(element.id), true] }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module ModelLint
|
|
5
|
+
module Rules
|
|
6
|
+
# Elements no package tree walk reaches: a classifier whose package
|
|
7
|
+
# is not in the model, or a package whose parent is not.
|
|
8
|
+
class OutsidePackageTree < Base
|
|
9
|
+
RULE = "outside_package_tree"
|
|
10
|
+
|
|
11
|
+
def findings
|
|
12
|
+
stray_classifiers + stray_packages
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def stray_classifiers
|
|
18
|
+
classifiers.filter_map do |classifier|
|
|
19
|
+
next if package_by_id.key?(classifier.package_id)
|
|
20
|
+
|
|
21
|
+
finding(RULE, "error", classifier,
|
|
22
|
+
"\"#{classifier.name}\" sits outside the package tree " \
|
|
23
|
+
"(package #{classifier.package_id.inspect})")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def stray_packages
|
|
28
|
+
packages.filter_map do |package|
|
|
29
|
+
next if package.parent_id.nil? || package_by_id.key?(package.parent_id)
|
|
30
|
+
|
|
31
|
+
finding(RULE, "error", package,
|
|
32
|
+
"package \"#{package.name}\" has no parent " \
|
|
33
|
+
"#{package.parent_id.inspect} in the model")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module ModelLint
|
|
5
|
+
module Rules
|
|
6
|
+
# Attributes that share a tree position. EA orders such a tie by
|
|
7
|
+
# name, so a diagram's attribute order is not the row order.
|
|
8
|
+
class SharedAttributePositions < Base
|
|
9
|
+
RULE = "shared_attribute_positions"
|
|
10
|
+
|
|
11
|
+
def findings
|
|
12
|
+
classifiers.flat_map do |classifier|
|
|
13
|
+
classifier.properties.select(&:position)
|
|
14
|
+
.group_by(&:position)
|
|
15
|
+
.sort.flat_map do |position, properties|
|
|
16
|
+
next [] unless properties.size > 1
|
|
17
|
+
|
|
18
|
+
names = properties.map(&:name).sort_by(&:downcase)
|
|
19
|
+
[finding(RULE, "warning", classifier,
|
|
20
|
+
"\"#{classifier.name}\" attributes share position " \
|
|
21
|
+
"#{position}: #{names.join(", ")} (EA orders ties " \
|
|
22
|
+
"by name)",
|
|
23
|
+
package: package_path(classifier))]
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module ModelLint
|
|
5
|
+
# The rules a model is asked about. Each takes the canonical
|
|
6
|
+
# document and answers with findings; a rule never edits the model.
|
|
7
|
+
module Rules
|
|
8
|
+
autoload :DuplicateNames, "ea/model_lint/rules/duplicate_names"
|
|
9
|
+
autoload :AmbiguousNames, "ea/model_lint/rules/ambiguous_names"
|
|
10
|
+
autoload :SharedAttributePositions,
|
|
11
|
+
"ea/model_lint/rules/shared_attribute_positions"
|
|
12
|
+
autoload :OutsidePackageTree, "ea/model_lint/rules/outside_package_tree"
|
|
13
|
+
autoload :MissingConnectorEnds,
|
|
14
|
+
"ea/model_lint/rules/missing_connector_ends"
|
|
15
|
+
|
|
16
|
+
# Shared reads over the document: a rule subclasses this and
|
|
17
|
+
# implements #findings.
|
|
18
|
+
class Base
|
|
19
|
+
# @param document [Ea::Model::Document]
|
|
20
|
+
def initialize(document)
|
|
21
|
+
@document = document
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def classifiers
|
|
27
|
+
@classifiers ||= @document.classifiers
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def packages
|
|
31
|
+
@packages ||= @document.packages
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def package_by_id
|
|
35
|
+
@package_by_id ||= packages.to_h { |package| [package.id, package] }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# The package path a classifier sits in.
|
|
39
|
+
def package_path(classifier)
|
|
40
|
+
@document.package_paths[classifier.package_id] ||
|
|
41
|
+
classifier.package_name
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def finding(rule, severity, element, message, package: nil)
|
|
45
|
+
Finding.new(
|
|
46
|
+
rule: rule, severity: severity,
|
|
47
|
+
element_id: element&.id, element_name: element&.name,
|
|
48
|
+
package: package, message: message
|
|
49
|
+
)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module ModelLint
|
|
5
|
+
# Plain-text rendering of a report: one line per finding, errors
|
|
6
|
+
# before warnings and by rule, then a count per rule.
|
|
7
|
+
class TextReporter
|
|
8
|
+
def initialize(report)
|
|
9
|
+
@report = report
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def render
|
|
13
|
+
lines = ["#{@report.source}: #{@report.findings.size} finding(s)"]
|
|
14
|
+
ordered.each { |finding| lines << format_finding(finding) }
|
|
15
|
+
lines.concat(summary_lines)
|
|
16
|
+
lines.join("\n")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def ordered
|
|
22
|
+
@report.findings.sort_by do |finding|
|
|
23
|
+
[finding.error? ? 0 : 1, finding.rule, finding.element_name.to_s]
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def format_finding(finding)
|
|
28
|
+
format("%<severity>-7s %<rule>-26s %<message>s",
|
|
29
|
+
severity: finding.severity.upcase, rule: finding.rule,
|
|
30
|
+
message: finding.message)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def summary_lines
|
|
34
|
+
return [] if @report.findings.empty?
|
|
35
|
+
|
|
36
|
+
counts = @report.findings.group_by(&:rule).transform_values(&:size)
|
|
37
|
+
["--"] + counts.sort.map { |rule, count| "#{rule}: #{count}" } +
|
|
38
|
+
["errors: #{@report.error_count}, " \
|
|
39
|
+
"warnings: #{@report.warning_count}"]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
# Model lint over the canonical Ea::Model::Document: the questions a
|
|
5
|
+
# content owner asks of a project file or an export before trusting it.
|
|
6
|
+
module ModelLint
|
|
7
|
+
autoload :Finding, "ea/model_lint/finding"
|
|
8
|
+
autoload :Report, "ea/model_lint/report"
|
|
9
|
+
autoload :Engine, "ea/model_lint/engine"
|
|
10
|
+
autoload :TextReporter, "ea/model_lint/text_reporter"
|
|
11
|
+
autoload :Rules, "ea/model_lint/rules"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -12,6 +12,19 @@ module Ea
|
|
|
12
12
|
def key(attribute)
|
|
13
13
|
[attribute.pos || 0, attribute.name.to_s.downcase]
|
|
14
14
|
end
|
|
15
|
+
|
|
16
|
+
# The same rule for a canonical Ea::Model::Property, whose
|
|
17
|
+
# position is optional: an unpositioned one keeps its source
|
|
18
|
+
# order before the positioned ones.
|
|
19
|
+
#
|
|
20
|
+
# @param property [Ea::Model::Property]
|
|
21
|
+
# @param index [Integer] the property's place in its owner's list
|
|
22
|
+
# @return [Array(Integer, String, Integer)] the sort key
|
|
23
|
+
def property_key(property, index)
|
|
24
|
+
return [0, "", index] if property.position.nil?
|
|
25
|
+
|
|
26
|
+
[property.position, property.name.to_s.downcase, index]
|
|
27
|
+
end
|
|
15
28
|
end
|
|
16
29
|
end
|
|
17
30
|
end
|
|
@@ -39,6 +39,7 @@ module Ea
|
|
|
39
39
|
is_ordered: boolean(row.isordered),
|
|
40
40
|
is_unique: !boolean(row.allowduplicates),
|
|
41
41
|
visibility: visibility_from_scope(row.scope),
|
|
42
|
+
position: row.pos,
|
|
42
43
|
aggregation: "none",
|
|
43
44
|
stereotype_refs: stereotype_refs(row),
|
|
44
45
|
tagged_values: TaggedValueBuilder.new(database).for_attribute(row),
|
|
@@ -61,7 +61,7 @@ module Ea
|
|
|
61
61
|
qualified_name: qualified_name(element, containing_package, nested_parent),
|
|
62
62
|
is_abstract: boolean(element.is_abstract),
|
|
63
63
|
visibility: element.visibility,
|
|
64
|
-
properties: PropertyBuilder.new.build_all_for(element),
|
|
64
|
+
properties: PropertyBuilder.new(root.index).build_all_for(element),
|
|
65
65
|
operations: OperationBuilder.new.build_all_for(element),
|
|
66
66
|
annotations: annotations_for(element, id)
|
|
67
67
|
}
|
|
@@ -8,6 +8,12 @@ module Ea
|
|
|
8
8
|
# (LiteralInteger / LiteralUnlimitedNatural polymorphic
|
|
9
9
|
# children).
|
|
10
10
|
class PropertyBuilder
|
|
11
|
+
# @param index [Xmi::Sparx::Index, nil] the root index, through
|
|
12
|
+
# which an attribute's extension entry carries its position
|
|
13
|
+
def initialize(index = nil)
|
|
14
|
+
@index = index
|
|
15
|
+
end
|
|
16
|
+
|
|
11
17
|
def build_all_for(classifier)
|
|
12
18
|
classifier.owned_attribute.map { |attr| build_one(attr, classifier) }
|
|
13
19
|
end
|
|
@@ -32,12 +38,18 @@ module Ea
|
|
|
32
38
|
aggregation: attr.aggregation || "none",
|
|
33
39
|
association_id: IdNormalizer.from_xmi_id(attr.association),
|
|
34
40
|
visibility: attr.visibility,
|
|
41
|
+
position: position_for(attr),
|
|
35
42
|
annotations: AnnotationBuilder.from_element(attr, id)
|
|
36
43
|
)
|
|
37
44
|
end
|
|
38
45
|
|
|
39
46
|
private
|
|
40
47
|
|
|
48
|
+
def position_for(attr)
|
|
49
|
+
entry = attr.id && @index&.find_attribute(attr.id)
|
|
50
|
+
entry&.containment&.position
|
|
51
|
+
end
|
|
52
|
+
|
|
41
53
|
def type_name_for(attr)
|
|
42
54
|
# OwnedAttribute#type is the xmi:type discriminator
|
|
43
55
|
# (e.g. "uml:Property"); the actual data type reference is
|
data/lib/ea/version.rb
CHANGED
data/lib/ea.rb
CHANGED
|
@@ -28,6 +28,8 @@ module Ea
|
|
|
28
28
|
autoload :Render, "ea/render"
|
|
29
29
|
autoload :Shapescript, "ea/shapescript"
|
|
30
30
|
autoload :Lint, "ea/lint"
|
|
31
|
+
autoload :ModelLint, "ea/model_lint"
|
|
32
|
+
autoload :ModelDiff, "ea/model_diff"
|
|
31
33
|
autoload :Query, "ea/query"
|
|
32
34
|
autoload :Ocl, "ea/ocl"
|
|
33
35
|
autoload :Xml, "ea/xml"
|
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.188
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -217,6 +217,8 @@ files:
|
|
|
217
217
|
- lib/ea/cli/command/lint.rb
|
|
218
218
|
- lib/ea/cli/command/list.rb
|
|
219
219
|
- lib/ea/cli/command/mdg.rb
|
|
220
|
+
- lib/ea/cli/command/model_diff.rb
|
|
221
|
+
- lib/ea/cli/command/model_lint.rb
|
|
220
222
|
- lib/ea/cli/command/parse.rb
|
|
221
223
|
- lib/ea/cli/command/query.rb
|
|
222
224
|
- lib/ea/cli/command/render.rb
|
|
@@ -325,6 +327,22 @@ files:
|
|
|
325
327
|
- lib/ea/model/stereotype.rb
|
|
326
328
|
- lib/ea/model/tagged_value.rb
|
|
327
329
|
- lib/ea/model/waypoint.rb
|
|
330
|
+
- lib/ea/model_diff.rb
|
|
331
|
+
- lib/ea/model_diff/change.rb
|
|
332
|
+
- lib/ea/model_diff/comparator.rb
|
|
333
|
+
- lib/ea/model_diff/report.rb
|
|
334
|
+
- lib/ea/model_diff/text_reporter.rb
|
|
335
|
+
- lib/ea/model_lint.rb
|
|
336
|
+
- lib/ea/model_lint/engine.rb
|
|
337
|
+
- lib/ea/model_lint/finding.rb
|
|
338
|
+
- lib/ea/model_lint/report.rb
|
|
339
|
+
- lib/ea/model_lint/rules.rb
|
|
340
|
+
- lib/ea/model_lint/rules/ambiguous_names.rb
|
|
341
|
+
- lib/ea/model_lint/rules/duplicate_names.rb
|
|
342
|
+
- lib/ea/model_lint/rules/missing_connector_ends.rb
|
|
343
|
+
- lib/ea/model_lint/rules/outside_package_tree.rb
|
|
344
|
+
- lib/ea/model_lint/rules/shared_attribute_positions.rb
|
|
345
|
+
- lib/ea/model_lint/text_reporter.rb
|
|
328
346
|
- lib/ea/ocl.rb
|
|
329
347
|
- lib/ea/ocl/evaluator.rb
|
|
330
348
|
- lib/ea/ocl/nodes.rb
|