line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Jenkins::i18n::Warnings; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
75784
|
use 5.014004; |
|
2
|
|
|
|
|
13
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
63
|
|
5
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
56
|
|
6
|
2
|
|
|
2
|
|
535
|
use Hash::Util qw(lock_keys); |
|
2
|
|
|
|
|
2986
|
|
|
2
|
|
|
|
|
11
|
|
7
|
2
|
|
|
2
|
|
161
|
use Carp qw(confess); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
73
|
|
8
|
2
|
|
|
2
|
|
10
|
use Cwd; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1574
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=pod |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Jenkins::i18n::Warnings - stores and handles translation warnings |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Jenkins::i18n::Warnings; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
C |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 EXPORT |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
None by default. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
All attributes are "private". |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 METHODS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 new |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Creates a new instance. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Expects as single parameter a boolean (0 or 1) to mark the instance as |
41
|
|
|
|
|
|
|
"silent". That means that the return values of some methods will be affected by |
42
|
|
|
|
|
|
|
this option, please check the documentation of the methods available in this |
43
|
|
|
|
|
|
|
class for more details. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub new { |
48
|
2
|
|
|
2
|
1
|
763
|
my ( $class, $silent ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
22
|
my $self = { |
51
|
|
|
|
|
|
|
types => { |
52
|
|
|
|
|
|
|
empty => 'Empty', |
53
|
|
|
|
|
|
|
unused => 'Unused', |
54
|
|
|
|
|
|
|
same => 'Same', |
55
|
|
|
|
|
|
|
non_jenkins => 'Non Jenkins', |
56
|
|
|
|
|
|
|
search_found => 'Found match on given term', |
57
|
|
|
|
|
|
|
ignored => 'Ignored due expected value' |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
silent => $silent |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
2
|
50
|
|
|
|
6
|
if ( $self->{is_add} ) { |
63
|
0
|
|
|
|
|
0
|
$self->{types}->{missing} = 'Adding'; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
2
|
|
|
|
|
6
|
$self->{types}->{missing} = 'Missing'; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
4
|
bless $self, $class; |
70
|
2
|
|
|
|
|
6
|
$self->reset; |
71
|
2
|
|
|
|
|
10
|
lock_keys( %{$self} ); |
|
2
|
|
|
|
|
8
|
|
72
|
2
|
|
|
|
|
25
|
return $self; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 add |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Adds a new warnings. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Each warning has a type, so the message must be identified. Valid types are: |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=over |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item * |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
empty: translation files with keys that have an empty value. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item * |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
unused: translation files with keys that are deprecated. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item * |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
same: translation files that have keys with unstranslated text (still in |
94
|
|
|
|
|
|
|
English). |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item * |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
non_jenkins: translation files with keys that are part of Hudson, not Jenkins. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item * |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
missing: translation files that are missing. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=back |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Expects as positional parameters: |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=over |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item 1 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
The warning type. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item 2 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
The warning message. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=back |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub add { |
123
|
6
|
|
|
6
|
1
|
5636
|
my ( $self, $type, $value ) = @_; |
124
|
6
|
100
|
|
|
|
43
|
confess "type is a required parameter" unless ($type); |
125
|
|
|
|
|
|
|
confess "'$type' is not a valid type" |
126
|
5
|
100
|
|
|
|
23
|
unless ( exists( $self->{types}->{$type} ) ); |
127
|
4
|
100
|
|
|
|
24
|
confess "value is a required parameter" unless ($value); |
128
|
3
|
|
|
|
|
6
|
push( @{ $self->{$type} }, $value ); |
|
3
|
|
|
|
|
8
|
|
129
|
3
|
|
|
|
|
10
|
return 1; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 has_unused |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Returns true (1) or false (0) if there are unused warnings; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub has_unused { |
139
|
3
|
|
|
3
|
1
|
1237
|
my $self = shift; |
140
|
3
|
|
|
|
|
5
|
my $total = scalar( @{ $self->{unused} } ); |
|
3
|
|
|
|
|
6
|
|
141
|
3
|
100
|
|
|
|
13
|
return 1 if ( $total > 0 ); |
142
|
2
|
|
|
|
|
12
|
return 0; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 reset |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Removes all captured warnings, bringing the instance to it's original state. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub reset { |
152
|
5
|
|
|
5
|
1
|
17
|
my $self = shift; |
153
|
|
|
|
|
|
|
|
154
|
5
|
|
|
|
|
9
|
foreach my $type ( keys %{ $self->{types} } ) { |
|
5
|
|
|
|
|
30
|
|
155
|
35
|
|
|
|
|
60
|
$self->{$type} = []; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
5
|
|
|
|
|
24
|
return 1; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 summary |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Returns "true" (1) or "false" (0) if there are any warnings registered for a |
164
|
|
|
|
|
|
|
single file. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Expects as parameter the translation file being processed. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
If the class instance wasn't created as "silent" prints to C all |
169
|
|
|
|
|
|
|
collected warnings so far, one per line. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Otherwise, nothing will be printed. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub summary { |
176
|
5
|
|
|
5
|
1
|
101
|
my ( $self, $file ) = @_; |
177
|
|
|
|
|
|
|
|
178
|
5
|
100
|
|
|
|
23
|
confess 'The path to the file translation file is required' |
179
|
|
|
|
|
|
|
unless ( defined($file) ); |
180
|
|
|
|
|
|
|
|
181
|
4
|
|
|
|
|
17
|
my $has_any = 0; |
182
|
|
|
|
|
|
|
|
183
|
4
|
|
|
|
|
10
|
foreach my $type ( keys( %{ $self->{types} } ) ) { |
|
4
|
|
|
|
|
16
|
|
184
|
25
|
100
|
|
|
|
39
|
if ( scalar( @{ $self->{$type} } ) > 0 ) { |
|
25
|
|
|
|
|
48
|
|
185
|
1
|
|
|
|
|
2
|
$has_any = 1; |
186
|
1
|
|
|
|
|
2
|
last; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
4
|
100
|
66
|
|
|
17
|
if ( ($has_any) and ( not $self->{silent} ) ) { |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
# required for predicable warnings order |
193
|
1
|
|
|
|
|
2
|
my @sorted_types = sort( keys( %{ $self->{types} } ) ); |
|
1
|
|
|
|
|
6
|
|
194
|
|
|
|
|
|
|
|
195
|
1
|
|
|
|
|
5
|
my $rel = $self->_relative_path($file); |
196
|
1
|
|
|
|
|
20
|
warn "Got warnings for $rel:\n"; |
197
|
|
|
|
|
|
|
|
198
|
1
|
|
|
|
|
8
|
foreach my $type (@sorted_types) { |
199
|
7
|
|
|
|
|
14
|
foreach my $item ( @{ $self->{$type} } ) { |
|
7
|
|
|
|
|
14
|
|
200
|
2
|
|
|
|
|
13
|
warn "\t$self->{types}->{$type} '$item'\n"; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
4
|
100
|
|
|
|
32
|
return ( ( $has_any > 0 ) ? 1 : 0 ); |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub _relative_path { |
210
|
1
|
|
|
1
|
|
3
|
my ( $self, $file_path ) = @_; |
211
|
1
|
|
|
|
|
15
|
my $curr_dir = getcwd; |
212
|
|
|
|
|
|
|
|
213
|
1
|
50
|
|
|
|
20
|
if ( $file_path =~ /^$curr_dir/ ) { |
214
|
0
|
|
|
|
|
0
|
$file_path =~ s#$curr_dir/##; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
1
|
|
|
|
|
5
|
return $file_path; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 has_missing |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Returns true (1) or false (0) if there are missing warnings collected. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=cut |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub has_missing { |
227
|
3
|
|
|
3
|
1
|
6
|
my $self = shift; |
228
|
3
|
|
|
|
|
7
|
my $total = scalar( @{ $self->{missing} } ); |
|
3
|
|
|
|
|
5
|
|
229
|
3
|
100
|
|
|
|
12
|
return 1 if ( $total > 0 ); |
230
|
2
|
|
|
|
|
6
|
return 0; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head2 has_found |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Returns true (1) or false (0) if there are warnings regarding terms that were |
236
|
|
|
|
|
|
|
found in the properties values. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub has_found { |
241
|
2
|
|
|
2
|
1
|
900
|
my $self = shift; |
242
|
2
|
|
|
|
|
4
|
my $total = scalar( @{ $self->{search_found} } ); |
|
2
|
|
|
|
|
3
|
|
243
|
2
|
100
|
|
|
|
9
|
return 1 if ( $total > 0 ); |
244
|
1
|
|
|
|
|
4
|
return 0; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
1; |
248
|
|
|
|
|
|
|
__END__ |