line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Jenkins::i18n::Warnings; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
74399
|
use 5.014004; |
|
1
|
|
|
|
|
8
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
6
|
1
|
|
|
1
|
|
505
|
use Hash::Util qw(lock_keys); |
|
1
|
|
|
|
|
2850
|
|
|
1
|
|
|
|
|
7
|
|
7
|
1
|
|
|
1
|
|
88
|
use Carp qw(confess); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
8
|
1
|
|
|
1
|
|
6
|
use Cwd; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
725
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
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
|
1
|
|
|
1
|
1
|
786
|
my ( $class, $silent ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
11
|
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
|
1
|
50
|
|
|
|
4
|
if ( $self->{is_add} ) { |
63
|
0
|
|
|
|
|
0
|
$self->{types}->{missing} = 'Adding'; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
1
|
|
|
|
|
3
|
$self->{types}->{missing} = 'Missing'; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
3
|
bless $self, $class; |
70
|
1
|
|
|
|
|
4
|
$self->reset; |
71
|
1
|
|
|
|
|
8
|
lock_keys( %{$self} ); |
|
1
|
|
|
|
|
5
|
|
72
|
1
|
|
|
|
|
19
|
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
|
5350
|
my ( $self, $type, $value ) = @_; |
124
|
6
|
100
|
|
|
|
35
|
confess "type is a required parameter" unless ($type); |
125
|
|
|
|
|
|
|
confess "'$type' is not a valid type" |
126
|
5
|
100
|
|
|
|
27
|
unless ( exists( $self->{types}->{$type} ) ); |
127
|
4
|
100
|
|
|
|
25
|
confess "value is a required parameter" unless ($value); |
128
|
3
|
|
|
|
|
6
|
push( @{ $self->{$type} }, $value ); |
|
3
|
|
|
|
|
9
|
|
129
|
3
|
|
|
|
|
11
|
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
|
1301
|
my $self = shift; |
140
|
3
|
|
|
|
|
5
|
my $total = scalar( @{ $self->{unused} } ); |
|
3
|
|
|
|
|
7
|
|
141
|
3
|
100
|
|
|
|
14
|
return 1 if ( $total > 0 ); |
142
|
2
|
|
|
|
|
11
|
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
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
153
|
|
|
|
|
|
|
|
154
|
2
|
|
|
|
|
3
|
foreach my $type ( keys %{ $self->{types} } ) { |
|
2
|
|
|
|
|
11
|
|
155
|
14
|
|
|
|
|
26
|
$self->{$type} = []; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
2
|
|
|
|
|
7
|
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
|
3
|
|
|
3
|
1
|
61
|
my ( $self, $file ) = @_; |
177
|
|
|
|
|
|
|
|
178
|
3
|
100
|
|
|
|
18
|
confess 'The path to the file translation file is required' |
179
|
|
|
|
|
|
|
unless ( defined($file) ); |
180
|
|
|
|
|
|
|
|
181
|
2
|
|
|
|
|
5
|
my $has_any = 0; |
182
|
|
|
|
|
|
|
|
183
|
2
|
|
|
|
|
4
|
foreach my $type ( keys( %{ $self->{types} } ) ) { |
|
2
|
|
|
|
|
8
|
|
184
|
8
|
100
|
|
|
|
12
|
if ( scalar( @{ $self->{$type} } ) > 0 ) { |
|
8
|
|
|
|
|
20
|
|
185
|
1
|
|
|
|
|
2
|
$has_any = 1; |
186
|
1
|
|
|
|
|
3
|
last; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
2
|
100
|
66
|
|
|
10
|
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
|
|
|
|
|
9
|
|
194
|
|
|
|
|
|
|
|
195
|
1
|
|
|
|
|
4
|
my $rel = $self->_relative_path($file); |
196
|
1
|
|
|
|
|
13
|
warn "Got warnings for $rel:\n"; |
197
|
|
|
|
|
|
|
|
198
|
1
|
|
|
|
|
10
|
foreach my $type (@sorted_types) { |
199
|
7
|
|
|
|
|
14
|
foreach my $item ( @{ $self->{$type} } ) { |
|
7
|
|
|
|
|
15
|
|
200
|
2
|
|
|
|
|
13
|
warn "\t$self->{types}->{$type} '$item'\n"; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
2
|
100
|
|
|
|
16
|
return ( ( $has_any > 0 ) ? 1 : 0 ); |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub _relative_path { |
210
|
1
|
|
|
1
|
|
2
|
my ( $self, $file_path ) = @_; |
211
|
1
|
|
|
|
|
15
|
my $curr_dir = getcwd; |
212
|
|
|
|
|
|
|
|
213
|
1
|
50
|
|
|
|
26
|
if ( $file_path =~ /^$curr_dir/ ) { |
214
|
0
|
|
|
|
|
0
|
$file_path =~ s#$curr_dir/##; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
1
|
|
|
|
|
3
|
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
|
7
|
my $self = shift; |
228
|
3
|
|
|
|
|
6
|
my $total = scalar( @{ $self->{missing} } ); |
|
3
|
|
|
|
|
7
|
|
229
|
3
|
100
|
|
|
|
11
|
return 1 if ( $total > 0 ); |
230
|
2
|
|
|
|
|
8
|
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
|
922
|
my $self = shift; |
242
|
2
|
|
|
|
|
3
|
my $total = scalar( @{ $self->{search_found} } ); |
|
2
|
|
|
|
|
5
|
|
243
|
2
|
100
|
|
|
|
11
|
return 1 if ( $total > 0 ); |
244
|
1
|
|
|
|
|
5
|
return 0; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
1; |
248
|
|
|
|
|
|
|
__END__ |