-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparseSVN.rb
More file actions
283 lines (253 loc) · 8.41 KB
/
Copy pathparseSVN.rb
File metadata and controls
283 lines (253 loc) · 8.41 KB
1
2
3
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
require 'rexml/document'
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:host => 'localhost',
:username => 'root',
:password => 'zahdeh',
:database => 'se2')
class Revision < ActiveRecord::Base
has_many :modifications
end
class Modification < ActiveRecord::Base
belongs_to :revision
end
class StdClass
@@bug = []
@@revision = ""
@@date = ""
@@files = {}
@@developer = ""
def startMe
startedAt = Time.now
#filename = "firebird.xml"
filename = "version3.xml"
bugs = []
total_faults = 0
#files
modified = []
#added = []
#deleted = []
revisionEx = /\d/
dateEx = /\d{4}-\d{2}-\d{2}/
bugEx = /BUG=[0-9,]+/
fileEx = /.cc/
reset()
xml = File.read(filename)
data, others = REXML::Document.new(xml), []
data.elements.each('/log/*') do |ele|
#get the revision number
@@revision = ele.attributes['revision']
#@@revision = "r" + ele.attributes['revision']
#search through the elements for information
ele.each_element do |sub_element|
#get the date
#@@date = sub_element.text.scan(dateEx) if sub_element.name == "date"
#@@developer = sub_element.text if sub_element.name == "author"
#search for bugs - search for better regexp
if sub_element.name == "msg"
@@bug = sub_element.text.scan(bugEx) if sub_element.text #.to_s if bugEx.match(sub_element.text)
end
#report the revision if it is related to a bug
if sub_element.name == "paths"
#loop in the paths and add the files into the arrays according to the status of the file
sub_element.each_element do |path|
modified << path.text.to_s if path.attributes['action'].to_s == "M" && fileEx.match(path.text)
#added << path.text.to_s if path.attributes['action'].to_s == "A" && fileEx.match(path.text)
#deleted << path.text.to_s if path.attributes['action'].to_s == "D" && fileEx.match(path.text)
end
@@files = {:modified => modified} #, :added => added, :deleted => deleted}
modified = []
#added = []
#deleted = []
end
#report only if a bug is mentioned in the message
unless @@bug.empty?
#create a database record for the bug
aRevision = Revision.create(:rev => @@revision)
puts @@revision
#now get the differences in files and count the number of faults
faults = 0
#count number of changes per file using svn diff
@@files[:modified].each do |file|
#split from source since the log brings from trunk/ version number and other places
file = file.split("/src/")
# puts file.inspect
unless file[1].blank?
faults = getDiff(@@revision, file[1])
#write the filename and its count to database
#check if the file existed before and increment the count of faults
modification = Modification.find_by_filename(file[1])
if modification
modification.faults += faults
modification.save
else
aRevision.modifications.create(:filename => file[1], :faults => faults)
end
end
puts @@revision
end
#bugs << {:faults => faults, :revision => @@revision, :date => @@date.to_s,
# :bug => @@bug.join(','), :files => @@files, :developer => @@developer }
end
end
reset #reset all variables
end #/log
=begin
bugs.each do |bug|
puts bug[:revision]
#puts bug[:developer]
#puts bug[:bug]
puts "Faults: " + bug[:faults].to_s
total_faults += bug[:faults]
puts "Modified: " + bug[:files][:modified].size.to_s # + " " + bug[:files][:modified].inspect #if bug[:files][:modified]
#puts "Added: " + bug[:files][:added].size.to_s # + " " + bug[:files][:added].inspect# if bug[:files][:added]
#puts "Deleted: " + bug[:files][:deleted].size.to_s #+ " " + bug[:files][:deleted].inspect # if bug[:files][:deleted]
puts "------------"
end
=end
#puts bugs.size
#puts "faults: " + total_faults.to_s
puts startedAt
puts Time.now
end
def differences
filename = "diff2.txt"
reg = /^[+|-]/
f = File.read(filename)
current = nil
previous = nil
faults = 0
f.each_line do |line|
current = reg.match(line)
if(current == nil && (previous.to_s == '+' || previous.to_s == '-'))
faults += 1
previous = nil
current == nil
elsif((current.to_s == '+' || current.to_s == '-'))
previous = current.to_s
current = nil
end
end
puts faults
end
def reset
@@bug = []
@@revision = ""
@@date = ""
@@files = {}
@@developer = ""
end
def getDiff(revision, file)
prev = revision.to_i - 1
puts "svn diff -r r#{prev.to_s}:r#{revision.to_s} #{file}"
out = `svn diff -r r#{prev.to_s}:r#{revision.to_s} #{file}`
faults = 0
reg = /^[@]{2} [+-]\d*,\d* [+-]\d*,\d* [@]{2}$/
array = out.scan(reg)
faults += array.size
faults
end
def retrieveDB
revisions = Revision.find(:all)
revisions.each do |revision|
puts "Revision: " + revision.rev.to_s
#puts "Added: " + revision.added.to_s
#puts "Deleted: " + revision.deleted.to_s
#puts revision.modifications.faults
puts "modified: " + revision.modifications.size.to_s
puts '------------------'
end
end
def readSLOC
filename = "C_CPP_outfile.dat"
reg = /\d+/
# Total Blank | Comments | Compiler Data Exec. |Logical | File Module
# Lines Lines | Whole Embedded | Direct. Decl. Instr. | SLOC | Type Name
#------------------------------------------------------------------------------------------------------
# 957 119 | 203 0 | 21 100 307 | 428 | CODE chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
f = File.read(filename)
f.each_line do |line|
file = line.split("CODE ")
array = line.scan(reg)
#filter the data and store the metrics
total_lines = array[0].to_i
blank_lines = array[1].to_i
comments = array[2].to_i + array[3].to_i
logical_SLOC = array[7].to_i
#check if the file exists on database
aFile = Modification.find_by_filename(file[1].strip)
aFile.total_lines = total_lines
aFile.blank_lines = blank_lines
aFile.comments = comments
aFile.logical_SLOC = logical_SLOC
aFile.save
puts aFile.filename
puts "file: " + file[1].strip
puts "total_lines: " + total_lines.to_s
puts "blank_lines: " + blank_lines.to_s
puts "comments: " + comments.to_s
puts "Logical SLOC: " + logical_SLOC.to_s
puts "----------"
end
end
def compute80
modifications = Modification.find(:all, :conditions => "faults > 0", :order => "faults desc")
#get total number of faults
all_faults = Modification.sum('faults')
eighty = all_faults * 80 / 100
total = 0
files = 0
#sum up to 80%
last_fault = 0
modifications.each do |modification|
if total <= eighty
total += modification.faults.to_i
last_fault = modification.faults.to_i
files += 1
end
end
puts "all faulty files: " + modifications.size.to_s
puts "all faults: " + all_faults.to_s
puts "80%: " + eighty.to_s
puts "total: " + total.to_s
puts "Files: " + files.to_s
puts "faulty module has at least: " + last_fault.to_s + "faults"
#now mark the faulty and non faulty files. Faulty = 1, non faulty = 0
end
def sourceMonitor
#this will read the source monitor output file and dump it into the database
filename = "source_monitor/ChromeV3.xml"
#filename = "source_monitor/sourceSample.xml"
xml = File.read(filename)
data, others = REXML::Document.new(xml), []
counter = 0
data.elements.each('/sourcemonitor_metrics/project/checkpoints/checkpoint/files/*') do |ele|
#get the file into linux format
file = ele.attributes['file_name'].gsub("\\","/").gsub("src/","").to_s
if Modification.find_by_filename(file, :conditions => "faults > 0")
counter += 1
ele.each_element("metrics/*") do |sub_element|
#puts sub_element.text
puts "Lines: " + sub_element.text.to_s if sub_element.attributes['id'] == "M0"
puts "statements: " + sub_element.text.to_s if sub_element.attributes['id'] == "M1"
puts "methods/class: " + sub_element.text.to_s if sub_element.attributes['id'] == "M5"
puts "avg stmts/method: " + sub_element.text.to_s if sub_element.attributes['id'] == "M6"
puts "functions: " + sub_element.text.to_s if sub_element.attributes['id'] == "M14"
end
else
puts file + " does not exist in database"
end
end
puts "Total files: " + counter.to_s
end
end
x = StdClass.new
#x.getDiff
#x.differences
#x.startMe
#x.retrieveDB
#x.readSLOC
#x.compute80
x.sourceMonitor