xmimerge 0.0.1

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.
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+
3
+ require File.join(File.dirname(__FILE__), 'merge.rb')
4
+ require File.join(File.dirname(__FILE__), 'merge_stereotypes.rb')
5
+ require File.join(File.dirname(__FILE__), 'merge_tagged_values.rb')
6
+ require File.join(File.dirname(__FILE__), 'merge_multiplicity.rb')
7
+
8
+ class MergeAssociationEnd < Merge
9
+
10
+ def initialize(name, from_association_end, to_association_end)
11
+ super()
12
+ @name = name
13
+ @from_association_end = from_association_end
14
+ @to_association_end = to_association_end
15
+ end
16
+
17
+ def verify
18
+
19
+ # Visibility
20
+ check_change_propertie("visibility", @from_association_end, @to_association_end, "AssociationVisibility")
21
+
22
+ # IsNavegable
23
+ check_change_propertie("is_navigable", @from_association_end, @to_association_end, "AssociationIsNavegable")
24
+
25
+ # Initial Value
26
+ check_change_propertie("is_specification", @from_association_end, @to_association_end, "AssociationIsSpecification")
27
+
28
+ # Ordering
29
+ check_change_propertie("ordering", @from_association_end, @to_association_end, "AssociationOrdering")
30
+
31
+ # Aggregation
32
+ check_change_propertie("aggregation", @from_association_end, @to_association_end, "AssociationAggregation")
33
+
34
+ # Initial Value
35
+ check_change_propertie("target_scope", @from_association_end, @to_association_end, "AssociationTargetScope")
36
+
37
+ # Changeability
38
+ check_change_propertie("changeability", @from_association_end, @to_association_end, "AssociationChangeability")
39
+
40
+ # Multiplicity
41
+ merge = MergeMultiplicity.new("Attribute", @from_association_end, @to_association_end)
42
+ @only_check ? merge.check : merge.merge
43
+
44
+ # Stereotypes
45
+ merge = MergeStereotypes.new("Association", @from_association_end, @to_association_end)
46
+ @only_check ? merge.check : merge.merge
47
+
48
+ # TaggedValues
49
+ t = MergeTaggedValues.new("Association", @from_association_end, @to_association_end)
50
+ @only_check ? t.check : t.merge
51
+
52
+ # TODO
53
+
54
+ # Type Modifier
55
+ # Scope
56
+ # Documentation
57
+ end
58
+
59
+ end
@@ -0,0 +1,125 @@
1
+ require File.join(File.dirname(__FILE__), 'merge.rb')
2
+ require File.join(File.dirname(__FILE__), 'util.rb')
3
+ require File.join(File.dirname(__FILE__), 'merge_stereotypes.rb')
4
+ require File.join(File.dirname(__FILE__), 'merge_tagged_values.rb')
5
+ require File.join(File.dirname(__FILE__), 'merge_multiplicity.rb')
6
+
7
+ class MergeAttribute < Merge
8
+
9
+ def initialize(from_class, to_class)
10
+ super()
11
+ @from_class = from_class
12
+ @to_class = to_class
13
+ end
14
+
15
+ def verify
16
+
17
+ initial_buffer_size = @commands.buffer_size
18
+
19
+ @from_class.attributes.each do |from_attribute|
20
+ check_changes(from_attribute)
21
+ end
22
+
23
+ check_removed
24
+
25
+ @commands.buffer_size != initial_buffer_size
26
+ end
27
+
28
+ def check_changes(from_attribute)
29
+
30
+ @log.debug("Checking attribute: #{@from_class.full_name}::#{from_attribute.name}") if @only_check
31
+
32
+ # Localiza o atributo no modelo destino pelo nome
33
+ to_attribute = @to_class.attribute_by_name(from_attribute.name)
34
+ if to_attribute.nil?
35
+ # Se não encontrou é poque é um novo atributo
36
+ new_attribute from_attribute
37
+ else
38
+ # Atributo já existe, verifica se houve alterações
39
+ check_existing_attribute(from_attribute, to_attribute)
40
+ end
41
+ end
42
+
43
+ def check_removed
44
+ @to_class.attributes.each do |to_attribute|
45
+
46
+ ok = false
47
+ @from_class.attributes.each do |from_attribute|
48
+
49
+ if from_attribute.name == to_attribute.name
50
+ ok = true
51
+ break
52
+ end
53
+ end
54
+ if !ok
55
+ command = "\t- Attribute #{@from_class.full_name}::#{to_attribute.name}"
56
+ @commands.add_command_to_buffer(command)
57
+ unless @only_check
58
+ if @commands.has_command?(command)
59
+ @log.info "[OK] #{command}"
60
+ else
61
+ #@log.warn "[NOT] #{command}"
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ def new_attribute(from_attribute)
69
+ @log.debug("New Attribute") if @only_check
70
+
71
+ command = "\t+ Attribute #{@from_class.full_name}::#{from_attribute.name}"
72
+ @commands.add_command_to_buffer(command)
73
+
74
+ unless @only_check
75
+ if @commands.has_command?(command)
76
+ @to_class.add_xml_attribute(from_attribute.xml.to_xml)
77
+ @log.info "[OK] #{command}"
78
+ else
79
+ #@log.warn "[NOT] #{command}"
80
+ end
81
+ end
82
+ end
83
+
84
+ def check_existing_attribute(from_attribute, to_attribute)
85
+
86
+ from_full_attribute_name = "#{@from_class.full_name}::#{from_attribute.name}"
87
+
88
+ # Name
89
+ #changes = Util.check_change_by_method("name", from_attribute, to_attribute)
90
+ #check_change_propertie(changes, "AttributeName", from_attribute.full_name)
91
+
92
+ # Visibility
93
+ check_change_propertie("visibility", from_attribute, to_attribute, "AttributeVisibility")
94
+
95
+ # Type
96
+ check_change_propertie("type", from_attribute, to_attribute, "AttributeType")
97
+
98
+ # Initial Value
99
+ check_change_propertie("initial_value", from_attribute, to_attribute, "AttributeInitialValue")
100
+
101
+
102
+ # Multiplicity
103
+ merge = MergeMultiplicity.new("Attribute", from_attribute, to_attribute)
104
+ @only_check ? merge.check : merge.merge
105
+
106
+ # Stereotypes
107
+ merge = MergeStereotypes.new("Attribute", from_attribute, to_attribute)
108
+ @only_check ? merge.check : merge.merge
109
+
110
+ # TaggedValues
111
+ t = MergeTaggedValues.new("Attribute", from_attribute, to_attribute)
112
+ @only_check ? t.check : t.merge
113
+
114
+ # TODO
115
+
116
+ # Type Modifier
117
+ # Changeability
118
+ # Ordering
119
+ # Scope
120
+ # Documentation
121
+
122
+
123
+ end
124
+
125
+ end
@@ -0,0 +1,39 @@
1
+
2
+ class MergeCallEvents < Merge
3
+
4
+ def initialize(from_use_case, to_use_case)
5
+ super()
6
+ @from_use_case = from_use_case
7
+ @to_use_case = to_use_case
8
+ end
9
+
10
+ def verify
11
+ @from_use_case.call_events.each do |from_call_event|
12
+ check_changes(from_call_event)
13
+ end
14
+
15
+ check_removed
16
+ end
17
+
18
+ def check_changes(from_call_event)
19
+ @log.debug("Checking Call Event #{from_call_event.name}")
20
+
21
+ # Encontra a operação no modelo de origem pelo id
22
+ from_xmi_content = @from_use_case.document.at_xpath("./XMI/XMI.content")
23
+ from_operation = XmiHelper.operation_by_id(from_xmi_content, from_call_event.operation)
24
+
25
+ # Encontra a operação no modelo destino pelo nome
26
+ to_operation = XmiHelper.operation_by_id(to_xmi_content, from_call_event.operation)
27
+
28
+ to_call_event = @to_use_case.call_event_by_operation_id(from_call_event.name)
29
+
30
+ if to_call_event.nil?
31
+ new_obj from_call_event
32
+ else
33
+ check_existing(from_call_event, to_call_event)
34
+ end
35
+ end
36
+
37
+ def check_removed
38
+ end
39
+ end
@@ -0,0 +1,122 @@
1
+ require File.join(File.dirname(__FILE__), 'merge.rb')
2
+ require File.join(File.dirname(__FILE__), 'merge_attributes.rb')
3
+ require File.join(File.dirname(__FILE__), 'merge_operations.rb')
4
+ require File.join(File.dirname(__FILE__), 'merge_stereotypes.rb')
5
+ require File.join(File.dirname(__FILE__), 'merge_tagged_values.rb')
6
+ require File.join(File.dirname(__FILE__), 'merge_associations.rb')
7
+
8
+ class MergeClasses < Merge
9
+
10
+ def initialize(from_package, to_package)
11
+ super()
12
+ @from_package = from_package
13
+ @to_package = to_package
14
+ end
15
+
16
+ def verify
17
+
18
+ @from_package.classes.each do |from_class|
19
+ check_changes(from_class)
20
+ end
21
+
22
+ check_removed
23
+
24
+ end
25
+
26
+ def check_changes(from_class)
27
+
28
+ to_class = @to_package.class_by_name(from_class.name)
29
+
30
+ @log.info("Checking Class #{from_class.full_name}") if @only_check
31
+
32
+ if to_class.nil?
33
+ new_class from_class
34
+ else
35
+ check_existing_class(from_class, to_class)
36
+ end
37
+ end
38
+
39
+ def check_removed
40
+
41
+ @log.debug("Checking Removed Classes on package #{@to_package.full_name}...") if @only_check
42
+
43
+ @to_package.classes.each do |to_class|
44
+
45
+ ok = false
46
+ @from_package.classes.each do |from_class|
47
+
48
+ if from_class.full_name == to_class.full_name
49
+ ok = true
50
+ break
51
+ end
52
+ end
53
+ if !ok
54
+ @log.info("Class Removed: #{to_class.full_name}") if @only_check
55
+ command = "- Class #{to_class.full_name}"
56
+ @commands.add_command_to_buffer(command)
57
+ unless @only_check
58
+ if @commands.has_command?(command)
59
+ @log.info "[OK] #{command}"
60
+ else
61
+ #@log.info "[NOT] #{command}"
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ def new_class(from_class)
69
+ @log.debug("New class") if @only_check
70
+ command = "+ Class #{from_class.full_name}"
71
+ @commands.add_command_to_buffer(command)
72
+
73
+ unless @only_check
74
+ if @commands.has_command?(command)
75
+ @to_package.add_xml_class(from_class.xml.to_xml)
76
+ @log.info "[OK] #{command}"
77
+ else
78
+ @log.debug "[NOT] #{command}"
79
+ end
80
+ end
81
+
82
+ from_class.attributes.each do |from_attribute|
83
+ command = "\t+ Attribute #{from_class.full_name}::#{from_attribute.name}"
84
+ @commands.add_command_to_buffer(command)
85
+ end
86
+ end
87
+
88
+ def check_existing_class(from_class, to_class)
89
+
90
+ @log.debug("Checking Existing Class: #{from_class.full_name}") if @only_check
91
+
92
+ command = "* Class #{from_class.full_name}"
93
+ @commands.add_command_to_buffer(command)
94
+
95
+ # Attributes
96
+ merge = MergeAttribute.new(from_class, to_class)
97
+ @only_check ? merge.check : merge.merge
98
+
99
+ # Stereotypes
100
+ merge = MergeStereotypes.new("Class", from_class, to_class)
101
+ @only_check ? merge.check : merge.merge
102
+
103
+ # TaggedValues
104
+ merge = MergeTaggedValues.new("Class", from_class, to_class)
105
+ @only_check ? merge.check : merge.merge
106
+
107
+ # TODO
108
+
109
+ # Generalization
110
+
111
+ # Associations
112
+ merge = MergeAssociations.new(from_class, to_class)
113
+ @only_check ? merge.check : merge.merge
114
+
115
+ # Operations
116
+ merge = MergeOperations.new(from_class, to_class)
117
+ @only_check ? merge.check : merge.merge
118
+
119
+ @commands.remove_if_is_last_command(command)
120
+ end
121
+
122
+ end
@@ -0,0 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), 'merge_states.rb')
2
+
3
+ class MergeFinalStates < MergeStates
4
+
5
+ def initialize(from_activity_graph, to_activity_graph)
6
+ super("FinalState", "final_states", from_activity_graph, to_activity_graph)
7
+ end
8
+
9
+ end
@@ -0,0 +1,35 @@
1
+ require File.join(File.dirname(__FILE__), 'merge.rb')
2
+
3
+ class MergeMultiplicity < Merge
4
+
5
+ def initialize(name, from_tag, to_tag)
6
+ super()
7
+ @name = name
8
+ @from_tag = from_tag
9
+ @to_tag = to_tag
10
+ end
11
+
12
+ def verify
13
+
14
+ from_value = @from_tag.multiplicity_range
15
+ to_value = @to_tag.multiplicity_range
16
+
17
+ if !from_value.nil? && to_value.nil?
18
+
19
+ command = "+ #{@name}Multiplicity #{@from_tag.full_name} '#{from_value}'"
20
+ @commands.add_command_to_buffer(command)
21
+
22
+ elsif from_value.nil? && !to_value.nil?
23
+
24
+ command = "- #{@name}Multiplicity #{@from_tag.full_name} '#{to_value}'"
25
+ @commands.add_command_to_buffer(command)
26
+
27
+ elsif (!from_value.nil? && !to_value.nil?) && to_value != from_value
28
+
29
+ command = "* #{@name}Multiplicity #{@from_tag.full_name} '#{to_value}' --> '#{from_value}'"
30
+ @commands.add_command_to_buffer(command)
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,83 @@
1
+ require File.join(File.dirname(__FILE__), 'merge.rb')
2
+
3
+ class MergeOperations < Merge
4
+
5
+ def initialize(from_class, to_class)
6
+ super()
7
+ @from_class = from_class
8
+ @to_class = to_class
9
+ end
10
+
11
+ def verify
12
+ @from_class.operations.each do |from_operation|
13
+ check_changes(from_operation)
14
+ end
15
+
16
+ check_removed
17
+ end
18
+
19
+ def check_changes(from_operation)
20
+
21
+ @log.debug("Checking operation: #{@from_class.full_name}::#{from_operation.name}")
22
+
23
+ to_operation = @to_class.operation_by_name(from_operation.name)
24
+ if to_operation.nil?
25
+ new_operation from_operation
26
+ else
27
+ check_existing(from_operation, to_operation)
28
+ end
29
+ end
30
+
31
+ def check_removed
32
+ to_operations = @to_class.operations.each do |to_operation|
33
+
34
+ ok = false
35
+ @from_class.operations.each do |from_operation|
36
+
37
+ if from_operation.name == to_operation.name
38
+ ok = true
39
+ break
40
+ end
41
+ end
42
+ if !ok
43
+ command = "\t- Operation #{@from_class.full_name}::#{to_operation.name}"
44
+ @commands.add_command_to_buffer(command)
45
+ unless @only_check
46
+ if @commands.has_command?(command)
47
+ @log.info "[OK] #{command}"
48
+ else
49
+ #@log.info "[NOT] #{command}"
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ def new_operation(from_operation)
57
+ @log.debug("New operation")
58
+
59
+ command = "\t+ Operation #{@from_class.full_name}::#{from_operation.name}"
60
+ @commands.add_command_to_buffer(command)
61
+
62
+ unless @only_check
63
+ if @commands.has_command?(command)
64
+ @log.info "[OK] #{command}"
65
+ else
66
+ @log.info "[NOT] #{command}"
67
+ end
68
+ end
69
+ end
70
+
71
+ def check_existing(from_operation, to_operation)
72
+
73
+ from_full_operation_name = "#{@from_class.full_name}::#{from_operation.name}"
74
+
75
+ # Visibility
76
+ check_change_propertie("visibility", from_operation, to_operation, "OperationVisibility")
77
+
78
+ # Parameters
79
+ merge = MergeParameters.new("Operation", from_operation, to_operation)
80
+ @only_check ? merge.check : merge.merge
81
+ end
82
+
83
+ end