source: ProjectBuilder/devel/lib/ProjectBuilder/Log/Item.pm@ 1498

Last change on this file since 1498 was 1498, checked in by Bruno Cornec, 12 years ago

Adding a prefix entry in Makefile.PL (Eric Anderson)

File size: 3.9 KB
Line 
1package ProjectBuilder::Log::Item;
2
3# Each PB::Log::Item represents one machine
4
5use strict;
6
7# the *matches represents strings, which a line must contain, to be recognized as a corresponding found
8# the *exludes can be used to exclude a string (if the string contains a *match and a *exclude, the line is ignored)
9# the name is by default the name of the vm (e.g. ubuntu-10.04-i386)
10sub new {
11 # contains the object name (here PBLog)
12 my $object = shift;
13 my $vmname = shift || "";
14 my $log = shift || "";
15
16 my $self = {};
17 # $ref should point to an object of type $object
18 bless($self, $object);
19
20 # array of strings, which are indicating errors or warnings (case insensitive)
21 $self->{'errormatches'} = [];
22 $self->{'warningmatches'} = [];
23 # array of strings, which are excluded from error lines (case insensitive)
24 $self->{'errorexcludes'} = [];
25 $self->{'warningexcludes'} = [];
26
27 push(@{$self->{'errormatches'}}, "error");
28 push(@{$self->{'errormatches'}}, "fehler");
29
30 push(@{$self->{'warningmatches'}}, "warning");
31 push(@{$self->{'warningmatches'}}, "warnung");
32
33 # init default values
34 $self->setName($vmname);
35 $self->setLog($log);
36
37 return($self);
38}
39
40#set's the name
41sub setName {
42 my $self = shift;
43 my $vmname = shift || "";
44
45 $self->{'vmname'} = $vmname;
46}
47
48# returns the name
49sub name {
50 my $self = shift;
51
52 return $self->{'vmname'};
53}
54
55# set's the log and calls the analyzer (parseLog())
56sub setLog {
57 my $self = shift;
58 my $log = shift || "";
59
60 $self->{'qawarnings'} = [];
61 $self->{'qaerrors'} = [];
62 $self->{'warnings'} = [];
63 $self->{'errors'} = [];
64 $self->{'log'} = $log;
65 $self->parseLog;
66}
67
68# returns the "raw" log text
69sub log {
70 my $self = shift;
71
72 return $self->{'log'};
73}
74
75# returns the number of warnings and errors reported by lintian or rpmlint
76sub numQaIssues {
77 my $self = shift;
78
79 return scalar($self->qaIssues);
80}
81
82# returns the issues itself
83sub qaIssues {
84 my $self = shift;
85 my @result = $self->qaErrors;
86
87 push(@result, $self->qaWarnings);
88 return @result;
89}
90
91#returns only the warnings
92sub qaWarnings {
93 my $self = shift;
94
95 return @{$self->{'qawarnings'}};
96}
97
98# returns only the errors
99sub qaErrors {
100 my $self = shift;
101
102 return @{$self->{'qaerrors'}};
103}
104
105# returns the number of compile errors
106# or better, all other than lintian and rpmlint
107sub numErrors {
108 my $self = shift;
109
110 return scalar($self->errors);
111}
112
113# returns the errors itself
114sub errors {
115 my $self = shift;
116
117 return @{$self->{'errors'}};
118}
119
120# same for warnings
121sub numWarnings {
122 my $self = shift;
123
124 return scalar($self->warnings);
125}
126
127# same for warnings
128sub warnings {
129 my $self = shift;
130
131 return @{$self->{'warnings'}};
132}
133
134# private part
135
136# parses the log
137sub parseLog {
138 my $self = shift;
139
140 my @lines = split("\n", $self->{'log'});
141 foreach my $line (@lines) {
142 # check for lintian or rpmlint errors
143 if ($line =~ m/^W:/) {
144 push(@{$self->{'qawarnings'}}, $line);
145 } elsif ($line =~ m/^E:/) {
146 push(@{$self->{'qaerrors'}}, $line);
147 } else {
148 # error detect
149 my $iserror = 0;
150 foreach my $errormatch (@{$self->{'errormatches'}}) {
151 if($line =~ m/$errormatch/){
152 # check wether an exclude is also true
153 my $isexcluded = 0;
154 foreach my $exclude (@{$self->{'errorexcludes'}}) {
155 if ($line =~ m/$exclude/) {
156 $isexcluded = 1;
157 last;
158 }
159 }
160 if ($isexcluded == 0) {
161 # it is an error and not excluded, so add it to array
162 push(@{$self->{'errors'}}, $line);
163 $iserror = 1;
164 last;
165 }
166 }
167 }
168
169 # warning detect
170 if ($iserror == 0) {
171 foreach my $match (@{$self->{'warningmatches'}}) {
172 if($line =~ m/$match/){
173 # check wether an exclude is also true
174 my $isexcluded = 0;
175 foreach my $exclude (@{$self->{'warningexcludes'}}) {
176 if ($line =~ m/$exclude/) {
177 $isexcluded = 1;
178 last;
179 }
180 }
181 if ($isexcluded == 0) {
182 # it is an error and not excluded, so add it to array
183 push(@{$self->{'warnings'}}, $line);
184 $iserror = 1;
185 last;
186 }
187 }
188 }
189 }
190 }
191 }
192}
193
1941;
Note: See TracBrowser for help on using the repository browser.