line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# Created on: 2014-08-06 19:04:05 |
3
|
|
|
|
|
|
|
# Create by: Ivan Wills |
4
|
|
|
|
|
|
|
# $Id$ |
5
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
6
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use strict; |
9
|
6
|
|
|
6
|
|
97453
|
use warnings; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
140
|
|
10
|
6
|
|
|
6
|
|
25
|
use version; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
116
|
|
11
|
6
|
|
|
6
|
|
677
|
use Carp qw/carp croak cluck confess longmess/; |
|
6
|
|
|
|
|
3257
|
|
|
6
|
|
|
|
|
55
|
|
12
|
6
|
|
|
6
|
|
360
|
use Data::Dumper qw/Dumper/; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
356
|
|
13
|
6
|
|
|
6
|
|
1958
|
use English qw/ -no_match_vars /; |
|
6
|
|
|
|
|
21247
|
|
|
6
|
|
|
|
|
306
|
|
14
|
6
|
|
|
6
|
|
951
|
use XML::Tiny; |
|
6
|
|
|
|
|
4501
|
|
|
6
|
|
|
|
|
25
|
|
15
|
6
|
|
|
6
|
|
3878
|
use App::Git::Workflow::Repository qw//; |
|
6
|
|
|
|
|
7719
|
|
|
6
|
|
|
|
|
259
|
|
16
|
6
|
|
|
6
|
|
1897
|
use App::Git::Workflow; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
137
|
|
17
|
6
|
|
|
6
|
|
2036
|
use base qw/App::Git::Workflow/; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
251
|
|
18
|
6
|
|
|
6
|
|
37
|
|
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
6234
|
|
19
|
|
|
|
|
|
|
our $VERSION = version->new(1.1.20); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $class = shift; |
22
|
|
|
|
|
|
|
my $self = App::Git::Workflow->new(@_); |
23
|
20
|
|
|
20
|
1
|
58
|
bless $self, $class; |
24
|
20
|
|
|
|
|
107
|
|
25
|
20
|
|
|
|
|
50
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
20
|
|
|
|
|
46
|
|
28
|
|
|
|
|
|
|
my $A = $a; |
29
|
|
|
|
|
|
|
$A =~ s/(\d+)/sprintf "%014i", $1/egxms; |
30
|
|
|
|
|
|
|
my $B = $b; |
31
|
2
|
|
|
2
|
|
28
|
$B =~ s/(\d+)/sprintf "%014i", $1/egxms; |
32
|
2
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
29
|
|
33
|
2
|
|
|
|
|
5
|
return $A cmp $B; |
34
|
2
|
|
|
|
|
7
|
} |
|
6
|
|
|
|
|
18
|
|
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
8
|
my ($self) = @_; |
37
|
|
|
|
|
|
|
return $self->{MAX_AGE} ||= 60 * 60 * 24 * ( |
38
|
|
|
|
|
|
|
$ENV{GIT_WORKFLOW_MAX_AGE} |
39
|
|
|
|
|
|
|
|| $self->git->config('workflow.max-age') |
40
|
4
|
|
|
4
|
|
9
|
|| 120 |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
4
|
|
50
|
|
|
31
|
|
|
|
|
33
|
|
|
|
|
44
|
|
|
|
|
|
|
my ($self, $pom, $match, $skip) = @_; |
45
|
|
|
|
|
|
|
my @branches = $self->branches('both'); |
46
|
|
|
|
|
|
|
my $settings = $self->settings(); |
47
|
|
|
|
|
|
|
my %versions; |
48
|
|
|
|
|
|
|
my $count = 0; |
49
|
4
|
|
|
4
|
1
|
19
|
my $max_age = $self->_max_age; |
50
|
4
|
|
|
|
|
25
|
my $run = !$settings->{max_age} || $settings->{max_age} == $max_age ? 0 : 1; |
51
|
4
|
|
|
|
|
21
|
|
52
|
4
|
|
|
|
|
6
|
while (!%versions && $run < 10) { |
53
|
4
|
|
|
|
|
8
|
BRANCH: |
54
|
4
|
|
|
|
|
14
|
for my $branch (sort @branches) { |
55
|
4
|
50
|
33
|
|
|
17
|
$settings->{pom_versions}{$branch} ||= {}; |
56
|
|
|
|
|
|
|
my $saved = $settings->{pom_versions}{$branch}; |
57
|
4
|
|
66
|
|
|
27
|
|
58
|
|
|
|
|
|
|
# skip branches marked as OLD |
59
|
4
|
|
|
|
|
17
|
next BRANCH if !$run && $saved->{old}; |
60
|
11
|
|
100
|
|
|
527
|
next BRANCH if $match && $branch !~ /$match/; |
61
|
11
|
|
|
|
|
23
|
next BRANCH if $skip && $skip =~ /$skip/; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $current = eval { $self->commit_details($branch) } or next; |
64
|
11
|
50
|
33
|
|
|
38
|
|
65
|
11
|
50
|
33
|
|
|
27
|
# Skip any branches that are over $MAX_AGE old |
66
|
11
|
50
|
33
|
|
|
20
|
if ( $current->{time} < time - $max_age ) { |
67
|
|
|
|
|
|
|
$saved->{old} = 1; |
68
|
11
|
100
|
|
|
|
15
|
$self->save_settings() if $count++ % 20 == 0; |
|
11
|
|
|
|
|
45
|
|
69
|
|
|
|
|
|
|
next BRANCH; |
70
|
|
|
|
|
|
|
} |
71
|
8
|
50
|
|
|
|
31
|
|
72
|
0
|
|
|
|
|
0
|
delete $saved->{old}; |
73
|
0
|
0
|
|
|
|
0
|
|
74
|
0
|
|
|
|
|
0
|
# used saved version if it exists. |
75
|
|
|
|
|
|
|
if ( $saved && $saved->{time} && $saved->{time} == $current->{time} ) { |
76
|
|
|
|
|
|
|
$versions{$saved->{numerical}}{$branch} = $saved->{version}; |
77
|
8
|
|
|
|
|
13
|
next BRANCH; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
8
|
100
|
66
|
|
|
35
|
my $xml = eval { $self->git->show("$branch:$pom"); }; |
|
|
|
66
|
|
|
|
|
81
|
2
|
|
|
|
|
7
|
|
82
|
2
|
|
|
|
|
6
|
next BRANCH if !$xml; |
83
|
|
|
|
|
|
|
chomp $xml; |
84
|
|
|
|
|
|
|
next BRANCH if !$xml; |
85
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
15
|
|
86
|
|
|
|
|
|
|
$branch =~ s{^origin/}{}xms; |
87
|
6
|
50
|
|
|
|
16
|
|
88
|
6
|
|
|
|
|
11
|
my $numerical = my $version = eval { $self->pom_version($xml, $pom) }; |
89
|
6
|
50
|
|
|
|
10
|
|
90
|
|
|
|
|
|
|
# make sure we get a valid version |
91
|
6
|
|
|
|
|
14
|
if ( $@ || !defined $numerical ) { |
92
|
|
|
|
|
|
|
next BRANCH; |
93
|
6
|
|
|
|
|
7
|
} |
|
6
|
|
|
|
|
18
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# remove snapshots from the end |
96
|
6
|
50
|
33
|
|
|
39
|
$numerical =~ s/-SNAPSHOT$//xms; |
97
|
0
|
|
|
|
|
0
|
# remove any extranious text from the front |
98
|
|
|
|
|
|
|
$numerical =~ s/^\D+//xms; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$versions{$numerical}{$branch} = $version; |
101
|
6
|
|
|
|
|
25
|
$settings->{pom_versions}{$branch} = { |
102
|
|
|
|
|
|
|
numerical => $numerical, |
103
|
6
|
|
|
|
|
15
|
version => $version, |
104
|
|
|
|
|
|
|
time => $current->{time}, |
105
|
6
|
|
|
|
|
14
|
}; |
106
|
|
|
|
|
|
|
$self->save_settings() if $count++ % 50 == 0; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
$run++; |
109
|
|
|
|
|
|
|
} |
110
|
6
|
|
|
|
|
26
|
|
111
|
6
|
100
|
|
|
|
37
|
$self->save_settings(); |
112
|
|
|
|
|
|
|
|
113
|
4
|
|
|
|
|
599
|
return \%versions; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
4
|
|
|
|
|
15
|
my ($self, $xml, $pom) = @_; |
117
|
|
|
|
|
|
|
|
118
|
4
|
|
|
|
|
67
|
if ( $pom && $pom =~ /[.]json$/ ) { |
119
|
|
|
|
|
|
|
require JSON; |
120
|
|
|
|
|
|
|
my $json = eval { JSON::decode_json($xml) } |
121
|
|
|
|
|
|
|
or do { warn "Could not read $xml as json : $@\n"; }; |
122
|
12
|
|
|
12
|
1
|
1621
|
return $json->{version}; |
123
|
|
|
|
|
|
|
} |
124
|
12
|
50
|
66
|
|
|
77
|
if ( $pom && $pom =~ /[.]ya?ml$/ ) { |
125
|
0
|
|
|
|
|
0
|
require YAML; |
126
|
0
|
|
|
|
|
0
|
my $json = YAML::Load($xml); |
127
|
0
|
0
|
|
|
|
0
|
return $json->{version}; |
|
0
|
|
|
|
|
0
|
|
128
|
0
|
|
|
|
|
0
|
} |
129
|
|
|
|
|
|
|
|
130
|
12
|
50
|
66
|
|
|
41
|
my $doc = XML::Tiny::parsefile( $xml !~ /\n/ && -f $xml ? $xml : '_TINY_XML_STRING_' . $xml); |
131
|
0
|
|
|
|
|
0
|
|
132
|
0
|
|
|
|
|
0
|
for my $elem (@{ $doc->[0]{content} }) { |
133
|
0
|
|
|
|
|
0
|
next if $elem->{name} ne 'version'; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
return $elem->{content}[0]{content}; |
136
|
12
|
100
|
100
|
|
|
159
|
} |
137
|
|
|
|
|
|
|
|
138
|
12
|
|
|
|
|
6439
|
return; |
|
12
|
|
|
|
|
33
|
|
139
|
20
|
100
|
|
|
|
376
|
} |
140
|
|
|
|
|
|
|
|
141
|
11
|
|
|
|
|
60
|
my ($self, $pom, $versions) = @_; |
142
|
|
|
|
|
|
|
$versions ||= $self->get_pom_versions($pom); |
143
|
|
|
|
|
|
|
|
144
|
1
|
|
|
|
|
12
|
# sanity check |
145
|
|
|
|
|
|
|
die "No POM versions found!" if !%$versions; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my ($max) = reverse sort _alphanum_sort keys %{$versions}; |
148
|
3
|
|
|
3
|
1
|
9
|
my ($primary, $secondary) = split /[.]/, $max; |
149
|
3
|
|
66
|
|
|
10
|
$secondary++; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
return "$primary.$secondary.0-SNAPSHOT"; |
152
|
3
|
50
|
|
|
|
7
|
} |
153
|
|
|
|
|
|
|
|
154
|
3
|
|
|
|
|
6
|
1; |
|
3
|
|
|
|
|
17
|
|
155
|
3
|
|
|
|
|
12
|
|
156
|
3
|
|
|
|
|
7
|
|
157
|
|
|
|
|
|
|
=head1 NAME |
158
|
3
|
|
|
|
|
18
|
|
159
|
|
|
|
|
|
|
App::Git::Workflow::Pom - Tools for maven POM files with git |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 VERSION |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
This documentation refers to App::Git::Workflow::Pom version 1.1.20 |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SYNOPSIS |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
use App::Git::Workflow::Pom qw/get_pom_versions pom_version next_pom_version/; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# get all branch POM versions |
170
|
|
|
|
|
|
|
my $versions = $pom->get_pom_versions("pom.xml"); |
171
|
|
|
|
|
|
|
# { |
172
|
|
|
|
|
|
|
# 1.0 => { "some_branch" => "1.0.0-SNAPSHOT" }, |
173
|
|
|
|
|
|
|
# ... |
174
|
|
|
|
|
|
|
# } |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# extract the version from the POM |
177
|
|
|
|
|
|
|
my $version = $pom->pom_version("pom.xml"); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# find the next unused POM version. |
180
|
|
|
|
|
|
|
my $next = $pom->next_pom_version("pom.xml"); |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 DESCRIPTION |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
This library provides tools for looking at POM files in different branches. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=over 4 |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item C<new (%params)> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Create a new C<App::Git::Workflow::Pom> object |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item C<get_pom_versions ($pom_file)> |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Find all POM versions used in all branches. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item C<pom_version ($xml_text_or_file)> |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Extract the version number from C$xml_text_or_file> |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item C<next_pom_version ($pom, $versions)> |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Find the next available POM version number. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=back |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
There are no known bugs in this module. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Patches are welcome. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 AUTHOR |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Copyright (c) 2014 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). |
231
|
|
|
|
|
|
|
All rights reserved. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
234
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
235
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
236
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
237
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=cut |