| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Jenkins::i18n::ProcOpts; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
75069
|
use 5.014004; |
|
|
1
|
|
|
|
|
9
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
19
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
26
|
|
|
6
|
1
|
|
|
1
|
|
616
|
use Hash::Util qw(lock_hash unlock_value lock_value); |
|
|
1
|
|
|
|
|
2950
|
|
|
|
1
|
|
|
|
|
7
|
|
|
7
|
1
|
|
|
1
|
|
91
|
use Carp qw(confess); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
36
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use File::Spec; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
832
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=pod |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Jenkins::i18n::ProcOpts - process files definitions based on CLI options |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Jenkins::i18n::ProcOpts; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This module define how the translation files should be processed based on the |
|
25
|
|
|
|
|
|
|
collected CLI options. |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 EXPORT |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
None by default. |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 METHODS |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 new |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Creates a new instance. |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Expects as positional parameters: |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item 1 |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
A string representing the path where the files should be reviewed. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item 2 |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
A string representing the path where the processed files should be written to. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item 3 |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
A boolean (in Perl terms) if a counter is to be used. |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item 4 |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
A boolean (in Perl terms) if deprecated files should be removed. |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item 5 |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
A boolean (in Perl terms) if new files should be added. |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item 6 |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
A boolean (in Perl terms) if CLI is running in debug mode. |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item 7 |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
A string identifying the chosen language for processing. |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item 8 |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
An optional string of a regular expression to match the content of the |
|
72
|
|
|
|
|
|
|
translated properties. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=back |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub new { |
|
79
|
|
|
|
|
|
|
my ( |
|
80
|
8
|
|
|
8
|
1
|
6158
|
$class, $source_dir, $target_dir, $use_counter, $is_remove, |
|
81
|
|
|
|
|
|
|
$is_add, $is_debug, $lang, $search |
|
82
|
|
|
|
|
|
|
) = @_; |
|
83
|
8
|
|
|
|
|
65
|
my $self = { |
|
84
|
|
|
|
|
|
|
source_dir => $source_dir, |
|
85
|
|
|
|
|
|
|
target_dir => $target_dir, |
|
86
|
|
|
|
|
|
|
use_counter => $use_counter, |
|
87
|
|
|
|
|
|
|
is_remove => $is_remove, |
|
88
|
|
|
|
|
|
|
is_add => $is_add, |
|
89
|
|
|
|
|
|
|
is_debug => $is_debug, |
|
90
|
|
|
|
|
|
|
language => $lang, |
|
91
|
|
|
|
|
|
|
counter => 0, |
|
92
|
|
|
|
|
|
|
ext_sep => qr/\./ |
|
93
|
|
|
|
|
|
|
}; |
|
94
|
|
|
|
|
|
|
|
|
95
|
8
|
|
|
|
|
16
|
foreach my $attrib ( keys( %{$self} ) ) { |
|
|
8
|
|
|
|
|
30
|
|
|
96
|
|
|
|
|
|
|
confess "must receive $attrib as parameter" |
|
97
|
65
|
100
|
|
|
|
142
|
unless ( defined( $self->{$attrib} ) ); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
confess |
|
101
|
7
|
100
|
66
|
|
|
44
|
'Removing or adding translation files are excluding operations, they cannot be both true at the same time' |
|
102
|
|
|
|
|
|
|
if ( $is_remove and $is_add ); |
|
103
|
|
|
|
|
|
|
|
|
104
|
6
|
100
|
|
|
|
14
|
if ( defined($search) ) { |
|
105
|
1
|
|
|
|
|
19
|
$self->{search} = qr/$search/; |
|
106
|
1
|
|
|
|
|
3
|
$self->{has_search} = 1; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
else { |
|
109
|
5
|
|
|
|
|
11
|
$self->{has_search} = 0; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
6
|
|
|
|
|
12
|
bless $self, $class; |
|
113
|
6
|
|
|
|
|
8
|
lock_hash( %{$self} ); |
|
|
6
|
|
|
|
|
28
|
|
|
114
|
6
|
|
|
|
|
212
|
return $self; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 is_to_search |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Returns true (1) or false (0) if there is a defined term to search on the |
|
120
|
|
|
|
|
|
|
translated properties values. |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub is_to_search { |
|
125
|
2
|
|
|
2
|
1
|
1158
|
my $self = shift; |
|
126
|
2
|
|
|
|
|
10
|
return $self->{has_search}; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 search_term |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Returns the compiled regular expression that will be used to match terms in the |
|
132
|
|
|
|
|
|
|
translated properties values. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub search_term { |
|
137
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
|
138
|
1
|
50
|
|
|
|
4
|
confess 'There is no defined search term' unless ( $self->{has_search} ); |
|
139
|
1
|
|
|
|
|
5
|
return $self->{search}; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 get_language |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Returns a string identifying the chosen language for processing. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub get_language { |
|
149
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
|
150
|
1
|
|
|
|
|
5
|
return $self->{language}; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 get_source |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Returns string of the path where the translation files should be looked for. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub get_source { |
|
160
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
|
161
|
1
|
|
|
|
|
4
|
return $self->{source_dir}; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 get_target |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Returns a string of the path where the reviewed translation files should be |
|
167
|
|
|
|
|
|
|
written to. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub get_target { |
|
172
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
|
173
|
1
|
|
|
|
|
5
|
return $self->{target_dir}; |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 inc |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Increments the processed files counter. |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub inc { |
|
183
|
2
|
|
|
2
|
1
|
32
|
my $self = shift; |
|
184
|
|
|
|
|
|
|
|
|
185
|
2
|
100
|
|
|
|
8
|
if ( $self->use_counter ) { |
|
186
|
1
|
|
|
|
|
3
|
my $attrib = 'counter'; |
|
187
|
1
|
|
|
|
|
3
|
unlock_value( %{$self}, $attrib ); |
|
|
1
|
|
|
|
|
5
|
|
|
188
|
1
|
|
|
|
|
12
|
$self->{$attrib}++; |
|
189
|
1
|
|
|
|
|
2
|
lock_value( %{$self}, $attrib ); |
|
|
1
|
|
|
|
|
5
|
|
|
190
|
1
|
|
|
|
|
17
|
return 1; |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
1
|
|
|
|
|
13
|
warn "Useless invocation of inc with file counter disabled\n"; |
|
194
|
1
|
|
|
|
|
7
|
return 0; |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head2 use_counter |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Returns true (1) or false (0) if the processed counter is in use. |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=cut |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub use_counter { |
|
204
|
3
|
|
|
3
|
1
|
12
|
my $self = shift; |
|
205
|
3
|
|
|
|
|
11
|
return $self->{use_counter}; |
|
206
|
|
|
|
|
|
|
} |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 get_counter |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Returns an integer representing the number of translation files already |
|
211
|
|
|
|
|
|
|
processed. |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=cut |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub get_counter { |
|
216
|
2
|
|
|
2
|
1
|
1044
|
my $self = shift; |
|
217
|
2
|
|
|
|
|
12
|
return $self->{counter}; |
|
218
|
|
|
|
|
|
|
} |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 is_remove |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Returns true (1) or false (0) if the outdated translation files should be |
|
223
|
|
|
|
|
|
|
removed. |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=cut |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub is_remove { |
|
228
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
|
229
|
1
|
|
|
|
|
5
|
return $self->{is_remove}; |
|
230
|
|
|
|
|
|
|
} |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head2 is_add |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Returns true (1) or false (0) if the translation files should be added. |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=cut |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub is_add { |
|
239
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
|
240
|
1
|
|
|
|
|
5
|
return $self->{is_add}; |
|
241
|
|
|
|
|
|
|
} |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head2 is_debug |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Returns true (1) or false (0) if the CLI is running in debug mode. |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=cut |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub is_debug { |
|
250
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
|
251
|
1
|
|
|
|
|
5
|
return $self->{is_debug}; |
|
252
|
|
|
|
|
|
|
} |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head2 define_files |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Based on complete path to a translation file as input, defines the resulting |
|
257
|
|
|
|
|
|
|
expected translation files and their locations, even if they don't yet exist. |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
Expects as parameter the complete path to a translation file (Jelly or Java |
|
260
|
|
|
|
|
|
|
Properties). |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
Returns an array with the following elements: |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=over |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=item 1 |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
The path to the current language file location. |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=item 2 |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
The path to the English file location. |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=back |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=cut |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
sub define_files { |
|
279
|
6
|
|
|
6
|
1
|
1191
|
my ( $self, $file ) = @_; |
|
280
|
6
|
|
|
|
|
84
|
my ( $volume, $dirs, $filename ) = File::Spec->splitpath($file); |
|
281
|
6
|
|
|
|
|
35
|
my @file_parts = split( $self->{ext_sep}, $filename ); |
|
282
|
6
|
|
|
|
|
14
|
my $filename_ext = pop(@file_parts); |
|
283
|
6
|
|
|
|
|
15
|
my $filename_prefix = join( '.', @file_parts ); |
|
284
|
6
|
|
|
|
|
12
|
my ( $curr_lang_file, $english_file ); |
|
285
|
|
|
|
|
|
|
|
|
286
|
6
|
100
|
|
|
|
18
|
if ( $filename_ext eq 'jelly' ) { |
|
|
|
50
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
$curr_lang_file |
|
288
|
2
|
|
|
|
|
7
|
= $filename_prefix . '_' . $self->{language} . '.properties'; |
|
289
|
2
|
|
|
|
|
4
|
$english_file = "$filename_prefix.properties"; |
|
290
|
|
|
|
|
|
|
} |
|
291
|
|
|
|
|
|
|
elsif ( $filename_ext eq 'properties' ) { |
|
292
|
|
|
|
|
|
|
$curr_lang_file |
|
293
|
4
|
|
|
|
|
11
|
= $filename_prefix . '_' . $self->{language} . '.properties'; |
|
294
|
4
|
|
|
|
|
8
|
$english_file = $filename; |
|
295
|
|
|
|
|
|
|
} |
|
296
|
|
|
|
|
|
|
else { |
|
297
|
0
|
|
|
|
|
0
|
confess "Unexpected file extension '$filename_ext' in $file"; |
|
298
|
|
|
|
|
|
|
} |
|
299
|
|
|
|
|
|
|
|
|
300
|
6
|
|
|
|
|
44
|
my $english_file_path |
|
301
|
|
|
|
|
|
|
= File::Spec->catfile( $volume, $dirs, $english_file ); |
|
302
|
|
|
|
|
|
|
|
|
303
|
6
|
100
|
|
|
|
22
|
if ( $self->{source_dir} eq $self->{target_dir} ) { |
|
304
|
3
|
|
|
|
|
27
|
return ( File::Spec->catfile( $volume, $dirs, $curr_lang_file ), |
|
305
|
|
|
|
|
|
|
$english_file_path ); |
|
306
|
|
|
|
|
|
|
} |
|
307
|
|
|
|
|
|
|
|
|
308
|
3
|
|
|
|
|
42
|
$dirs =~ s/$self->{source_dir}/$self->{target_dir}/; |
|
309
|
|
|
|
|
|
|
|
|
310
|
3
|
|
|
|
|
29
|
return ( File::Spec->catfile( $volume, $dirs, $curr_lang_file ), |
|
311
|
|
|
|
|
|
|
$english_file_path ); |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
} |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
1; |
|
316
|
|
|
|
|
|
|
__END__ |