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