line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Jenkins::i18n::Warnings; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
74680
|
use 5.014004; |
|
2
|
|
|
|
|
12
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
62
|
|
5
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
55
|
|
6
|
2
|
|
|
2
|
|
591
|
use Hash::Util qw(lock_keys); |
|
2
|
|
|
|
|
2992
|
|
|
2
|
|
|
|
|
9
|
|
7
|
2
|
|
|
2
|
|
153
|
use Carp qw(confess); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
72
|
|
8
|
2
|
|
|
2
|
|
11
|
use Cwd; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1548
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
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
|
1162
|
my ( $class, $silent ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
16
|
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
|
|
|
|
9
|
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
|
|
|
|
|
6
|
bless $self, $class; |
70
|
2
|
|
|
|
|
8
|
$self->reset; |
71
|
2
|
|
|
|
|
26
|
lock_keys( %{$self} ); |
|
2
|
|
|
|
|
11
|
|
72
|
2
|
|
|
|
|
32
|
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
|
6616
|
my ( $self, $type, $value ) = @_; |
124
|
6
|
100
|
|
|
|
33
|
confess "type is a required parameter" unless ($type); |
125
|
|
|
|
|
|
|
confess "'$type' is not a valid type" |
126
|
5
|
100
|
|
|
|
36
|
unless ( exists( $self->{types}->{$type} ) ); |
127
|
4
|
100
|
|
|
|
26
|
confess "value is a required parameter" unless ($value); |
128
|
3
|
|
|
|
|
6
|
push( @{ $self->{$type} }, $value ); |
|
3
|
|
|
|
|
8
|
|
129
|
3
|
|
|
|
|
12
|
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
|
1514
|
my $self = shift; |
140
|
3
|
|
|
|
|
6
|
my $total = scalar( @{ $self->{unused} } ); |
|
3
|
|
|
|
|
7
|
|
141
|
3
|
100
|
|
|
|
11
|
return 1 if ( $total > 0 ); |
142
|
2
|
|
|
|
|
9
|
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
|
21
|
my $self = shift; |
153
|
|
|
|
|
|
|
|
154
|
5
|
|
|
|
|
7
|
foreach my $type ( keys %{ $self->{types} } ) { |
|
5
|
|
|
|
|
26
|
|
155
|
35
|
|
|
|
|
61
|
$self->{$type} = []; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
5
|
|
|
|
|
21
|
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
|
117
|
my ( $self, $file ) = @_; |
177
|
|
|
|
|
|
|
|
178
|
5
|
100
|
|
|
|
22
|
confess 'The path to the file translation file is required' |
179
|
|
|
|
|
|
|
unless ( defined($file) ); |
180
|
|
|
|
|
|
|
|
181
|
4
|
|
|
|
|
10
|
my $has_any = 0; |
182
|
|
|
|
|
|
|
|
183
|
4
|
|
|
|
|
5
|
foreach my $type ( keys( %{ $self->{types} } ) ) { |
|
4
|
|
|
|
|
17
|
|
184
|
23
|
100
|
|
|
|
30
|
if ( scalar( @{ $self->{$type} } ) > 0 ) { |
|
23
|
|
|
|
|
51
|
|
185
|
1
|
|
|
|
|
2
|
$has_any = 1; |
186
|
1
|
|
|
|
|
2
|
last; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
4
|
100
|
66
|
|
|
24
|
if ( ($has_any) and ( not $self->{silent} ) ) { |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
# required for predicable warnings order |
193
|
1
|
|
|
|
|
3
|
my @sorted_types = sort( keys( %{ $self->{types} } ) ); |
|
1
|
|
|
|
|
8
|
|
194
|
|
|
|
|
|
|
|
195
|
1
|
|
|
|
|
6
|
my $rel = $self->_relative_path($file); |
196
|
1
|
|
|
|
|
12
|
warn "Got warnings for $rel:\n"; |
197
|
|
|
|
|
|
|
|
198
|
1
|
|
|
|
|
7
|
foreach my $type (@sorted_types) { |
199
|
7
|
|
|
|
|
13
|
foreach my $item ( @{ $self->{$type} } ) { |
|
7
|
|
|
|
|
13
|
|
200
|
2
|
|
|
|
|
12
|
warn "\t$self->{types}->{$type} '$item'\n"; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
4
|
100
|
|
|
|
21
|
return ( ( $has_any > 0 ) ? 1 : 0 ); |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub _relative_path { |
210
|
1
|
|
|
1
|
|
3
|
my ( $self, $file_path ) = @_; |
211
|
1
|
|
|
|
|
12
|
my $curr_dir = getcwd; |
212
|
|
|
|
|
|
|
|
213
|
1
|
50
|
|
|
|
21
|
if ( $file_path =~ /^$curr_dir/ ) { |
214
|
0
|
|
|
|
|
0
|
$file_path =~ s#$curr_dir/##; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
1
|
|
|
|
|
4
|
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
|
|
|
|
|
8
|
|
229
|
3
|
100
|
|
|
|
11
|
return 1 if ( $total > 0 ); |
230
|
2
|
|
|
|
|
9
|
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
|
1182
|
my $self = shift; |
242
|
2
|
|
|
|
|
5
|
my $total = scalar( @{ $self->{search_found} } ); |
|
2
|
|
|
|
|
3
|
|
243
|
2
|
100
|
|
|
|
10
|
return 1 if ( $total > 0 ); |
244
|
1
|
|
|
|
|
5
|
return 0; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
1; |
248
|
|
|
|
|
|
|
__END__ |