4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
# File 'lib/overrides_tracker/comparer.rb', line 4
def self.compare_builds(unified_methods_collections, all_methods_collections, working_directories, bundle_directories)
same_source_count = 0
errored_source_count = 0
method_not_available_count = 0
method_not_override_count = 0
source_changed_count = 0
methods_count = 0
classes_count = 0
results = []
added_method_results = []
numbers = {}
numbers[:overrides] = {}
numbers[:overrides][:source_changed_count] = 0
numbers[:overrides][:override_changed_count] = 0
numbers[:overrides][:method_not_available_count] = 0
numbers[:overrides][:method_not_override_count] = 0
numbers[:overrides][:total] = 0
numbers[:added_methods] = {}
numbers[:added_methods][:source_changed_count] = 0
numbers[:added_methods][:override_changed_count] = 0
numbers[:added_methods][:method_not_available_count] = 0
numbers[:added_methods][:method_not_override_count] = 0
numbers[:added_methods][:total] = 0
numbers[:total] = {}
unified_methods_collections.each do |unified_class_name, unified_class_hash|
if unified_class_hash['instance_methods']&.any? || unified_class_hash['singleton_methods']&.any?
['instance_methods', 'singleton_methods'].each do |method_type|
unified_class_hash[method_type]&.each do |unified_method_name, unified_method_hash|
same_source_every_where = true
all_methods_collections.each do |build_id, all_methods_hash|
if all_methods_hash[unified_class_name].nil? ||
all_methods_hash[unified_class_name][method_type].nil? ||
all_methods_hash[unified_class_name][method_type][unified_method_name].nil? ||
all_methods_hash[unified_class_name][method_type][unified_method_name]['sha'] != unified_method_hash['sha'] ||
all_methods_hash[unified_class_name][method_type][unified_method_name]['overriding_sha'] != unified_method_hash['overriding_sha']
same_source_every_where = false
end
end
method_result_hash = {class_name: unified_class_name, method_name: unified_method_name, builds: {}, method_type: method_type, changes_detected: false}
if same_source_every_where
results << method_result_hash
else
method_result_hash[:changes_detected] = true
method_result_hash[:builds] ||= {}
is_source_changed_flag = false
is_override_changed_flag = false
all_methods_collections.each do |build_id, all_methods_hash|
method_result_hash[:builds][build_id] ||= {}
if all_methods_hash[unified_class_name].nil?
method_result_hash[:builds][build_id] = {result: 'method_not_available'}
numbers[:overrides][:method_not_available_count] +=1
elsif all_methods_hash[unified_class_name][method_type].nil?
if all_methods_hash[unified_class_name]["added_#{method_type}"]
if all_methods_hash[unified_class_name]["added_#{method_type}"][unified_method_name]
method_result_hash[:builds][build_id] = {result: 'method_not_override', data: all_methods_hash[unified_class_name]["added_#{method_type}"][unified_method_name]}
numbers[:overrides][:method_not_override_count] +=1
end
end
elsif !all_methods_hash[unified_class_name][method_type][unified_method_name].nil?
if all_methods_hash[unified_class_name][method_type][unified_method_name]['sha'] != unified_method_hash['sha']
method_result_hash[:builds][build_id] = {result: 'source_has_changed'}
method_result_hash[:builds][build_id][:original_body] = all_methods_hash[unified_class_name][method_type][unified_method_name]['body']
method_result_hash[:builds][build_id][:original_sha] = all_methods_hash[unified_class_name][method_type][unified_method_name]['sha']
method_result_hash[:builds][build_id][:original_location] = all_methods_hash[unified_class_name][method_type][unified_method_name]['location']
method_result_hash[:builds][build_id][:overriding_body] = all_methods_hash[unified_class_name][method_type][unified_method_name]['overriding_body']
method_result_hash[:builds][build_id][:overriding_location] = all_methods_hash[unified_class_name][method_type][unified_method_name]['overriding_location']
method_result_hash[:builds][build_id][:overriding_sha] = all_methods_hash[unified_class_name][method_type][unified_method_name]['overriding_sha']
method_result_hash[:builds][build_id][:is_part_of_app] = all_methods_hash[unified_class_name][method_type][unified_method_name]['is_part_of_app'] || all_methods_hash[unified_class_name][method_type][unified_method_name]['overriding_is_part_of_app']
numbers[:overrides][:source_changed_count] += 1
is_source_changed_flag = true
is_override_changed_flag = false
else
method_result_hash[:builds][build_id] = {result: 'override_has_changed'}
method_result_hash[:builds][build_id][:original_body] = all_methods_hash[unified_class_name][method_type][unified_method_name]['body']
method_result_hash[:builds][build_id][:original_sha] = all_methods_hash[unified_class_name][method_type][unified_method_name]['sha']
method_result_hash[:builds][build_id][:original_location] = all_methods_hash[unified_class_name][method_type][unified_method_name]['location']
method_result_hash[:builds][build_id][:overriding_body] = all_methods_hash[unified_class_name][method_type][unified_method_name]['overriding_body']
method_result_hash[:builds][build_id][:overriding_location] = all_methods_hash[unified_class_name][method_type][unified_method_name]['overriding_location']
method_result_hash[:builds][build_id][:overriding_sha] = all_methods_hash[unified_class_name][method_type][unified_method_name]['overriding_sha']
method_result_hash[:builds][build_id][:is_part_of_app] = all_methods_hash[unified_class_name][method_type][unified_method_name]['is_part_of_app'] || all_methods_hash[unified_class_name][method_type][unified_method_name]['overriding_is_part_of_app']
numbers[:overrides][:override_changed_count] += 1
is_override_changed_flag = true
end
else
method_result_hash[:builds][build_id] = {result: 'method_not_available'}
numbers[:overrides][:method_not_available_count] +=1
end
end
if is_source_changed_flag
line_differerence_array = []
all_methods_collections.each do |build_id, all_methods_hash|
begin
line_differerence_array << method_result_hash[:builds][build_id][:original_body].split(/\n/)
rescue
end
if method_result_hash[:builds][build_id][:result] == 'override_has_changed'
numbers[:overrides][:override_changed_count] -= 1
numbers[:overrides][:source_changed_count] += 1
end
method_result_hash[:builds][build_id][:result] = 'source_has_changed'
end
max_length = line_differerence_array.map(&:length).max
transposed_array = line_differerence_array.map{|e| e.values_at(0...max_length)}.transpose
method_result_hash[:mark_lines] = transposed_array.map.with_index{|val, index| val.uniq.size > 1 ? index : nil}.compact
is_override_changed_flag = false
end
if is_override_changed_flag
line_differerence_array = []
begin
begin
all_methods_collections.each do |build_id, all_methods_hash|
line_differerence_array << method_result_hash[:builds][build_id][:overriding_body].split(/\n/)
end
rescue
end
max_length = line_differerence_array.map(&:length).max
transposed_array = line_differerence_array.map{|e| e.values_at(0...max_length)}.transpose
method_result_hash[:overriding_mark_lines] = transposed_array.map.with_index{|val, index| val.uniq.size > 1 ? index : nil}.compact
rescue => exception
end
end
method_result_hash[:is_part_of_app] = method_result_hash[:builds].select{|bu, bu_val| bu_val[:is_part_of_app] }.any?
results << method_result_hash
end
end
end
end
if unified_class_hash['added_instance_methods']&.any? || unified_class_hash['added_singleton_methods']&.any?
['added_instance_methods', 'added_singleton_methods'].each do |method_type|
unified_class_hash[method_type]&.each do |unified_method_name, unified_method_hash|
same_source_every_where = true
is_added_source_has_changed_flag = false
all_methods_collections.each do |build_id, all_methods_hash|
unless (all_methods_hash[unified_class_name] != nil) && (all_methods_hash[unified_class_name][method_type] != nil) && (all_methods_hash[unified_class_name][method_type][unified_method_name] != nil ) && (all_methods_hash[unified_class_name][method_type][unified_method_name]['sha'] == unified_method_hash['sha'])
same_source_every_where = false
end
end
method_result_hash = {class_name: unified_class_name, method_name: unified_method_name, builds: {}, method_type: method_type, changes_detected: false}
if same_source_every_where
added_method_results << method_result_hash
else
method_result_hash[:changes_detected] = true
method_result_hash[:builds] ||= {}
all_methods_collections.each do |build_id, all_methods_hash|
method_result_hash[:builds][build_id] ||= {}
if all_methods_hash[unified_class_name].nil?
method_result_hash[:builds][build_id] = {result: 'added_method_not_available'}
numbers[:added_methods][:method_not_available_count] +=1
elsif all_methods_hash[unified_class_name][method_type].nil?
method_result_hash[:builds][build_id] = {result: 'added_method_not_available'}
numbers[:added_methods][:method_not_available_count] +=1
elsif !all_methods_hash[unified_class_name][method_type][unified_method_name].nil?
method_result_hash[:builds][build_id] = {result: 'added_source_has_changed'}
method_result_hash[:builds][build_id][:original_body] = all_methods_hash[unified_class_name][method_type][unified_method_name]['body']
method_result_hash[:builds][build_id][:original_location] = all_methods_hash[unified_class_name][method_type][unified_method_name]['location']
method_result_hash[:builds][build_id][:is_part_of_app] = all_methods_hash[unified_class_name][method_type][unified_method_name]['is_part_of_app'] || all_methods_hash[unified_class_name][method_type][unified_method_name]['overriding_is_part_of_app']
numbers[:added_methods][:source_changed_count] += 1
is_added_source_has_changed_flag = true
elsif all_methods_hash[unified_class_name][method_type][unified_method_name].nil?
method_result_hash[:builds][build_id] = {result: 'added_method_not_available'}
numbers[:added_methods][:method_not_available_count] +=1
else
method_result_hash[:builds][build_id] = {result: 'error'}
end
end
if is_added_source_has_changed_flag
begin
line_differerence_array = []
all_methods_collections.each do |build_id, all_methods_hash|
line_differerence_array << method_result_hash[:builds][build_id][:original_body].split(/\n/)
end
max_length = line_differerence_array.map(&:length).max
transposed_array = line_differerence_array.map{|e| e.values_at(0...max_length)}.transpose
method_result_hash[:mark_added_method_lines] = transposed_array.map.with_index{|val, index| val.uniq.size > 1 ? index : nil}.compact
rescue
end
end
method_result_hash[:is_part_of_app] = method_result_hash[:builds].select{|bu, bu_val| bu_val[:is_part_of_app] }.any?
added_method_results << method_result_hash
end
end
end
end
end
numbers[:overrides][:total] = numbers[:overrides][:method_not_override_count] + numbers[:overrides][:method_not_available_count] + numbers[:overrides][:source_changed_count] + numbers[:overrides][:override_changed_count]
numbers[:added_methods][:total] = numbers[:added_methods][:method_not_available_count] + numbers[:added_methods][:source_changed_count]
numbers[:total] = numbers[:overrides][:total] + numbers[:added_methods][:total]
{results: {override_results: results, added_method_results: added_method_results}, numbers: numbers}
end
|