File Coverage

blib/lib/App/Git/Workflow/Command/Pom.pm
Criterion Covered Total %
statement 50 86 58.1
branch 8 22 36.3
condition 3 6 50.0
subroutine 10 12 83.3
pod 5 5 100.0
total 76 131 58.0


line stmt bran cond sub pod time code
1              
2             # Created on: 2014-03-19 17:18:17
3             # Create by: Ivan Wills
4             # $Id$
5             # $Revision$, $HeadURL$, $Date$
6             # $Revision$, $Source$, $Date$
7              
8             use strict;
9 2     2   78710 use warnings;
  2         11  
  2         48  
10 2     2   9 use version;
  2         3  
  2         45  
11 2     2   336 use English qw/ -no_match_vars /;
  2         1423  
  2         11  
12 2     2   531 use App::Git::Workflow::Pom;
  2         2649  
  2         12  
13 2     2   974 use App::Git::Workflow::Command qw/get_options/;
  2         5  
  2         78  
14 2     2   428 use Path::Tiny;
  2         5  
  2         86  
15 2     2   1273  
  2         17383  
  2         1793  
16             our $VERSION = version->new(1.1.20);
17             our $workflow = App::Git::Workflow::Pom->new;
18             our ($name) = $PROGRAM_NAME =~ m{^.*/(.*?)$}mxs;
19             our %option;
20             our %p2u_extra;
21              
22             my ($self) = @_;
23             $option{fetch} = 1;
24 3     3 1 8 $option{pom} ||= $workflow->config('workflow.pom', 'pom.xml'),
25 3         9  
26 3 50 33     25 get_options(
27             \%option,
28             'pom|package|P=s',
29             'update|u!',
30             'skip|s=s',
31             'match|m=s',
32             'fetch|f!',
33             'tag|t=s',
34             'branch|b=s',
35             'local|l!',
36             ) or return;
37             my $sub_command = @ARGV ? 'do_' . shift @ARGV : "do_uniq";
38             $sub_command =~ s/-/_/g;
39 3 100       12  
40 3         7 if ( !$self->can($sub_command) ) {
41             warn "Unknown sub command '$sub_command'!\n";
42 3 50       21 App::Git::Workflow::Command::pod2usage( %p2u_extra, -verbose => 1 );
43 0         0 return 1;
44 0         0 }
45 0         0  
46             $workflow->{VERBOSE} = $option{verbose};
47             $workflow->{TEST } = $option{test};
48 3         8  
49 3         5 # make sure that git is up-to-date
50             $workflow->git->fetch if $option{fetch};
51              
52 3 50       13 $self->$sub_command($option{pom}, @ARGV);
53              
54 3         13 return;
55             }
56 3         11  
57             my (undef, $pom) = @_;
58             my $versions = $workflow->get_pom_versions($pom, $option{match}, $option{skip});
59             my $numerical = my $version = $workflow->pom_version((scalar path($pom)->slurp), $pom, 1);
60 2     2 1 4 $numerical =~ s/-SNAPSHOT$//xms;
61 2         13  
62 2         14 if ( !$versions->{$numerical} || keys %{ $versions->{$numerical} } <= 1 ) {
63 2         14 print "POM Version $version is unique\n";
64             }
65 2 100 66     28 else {
  2         11  
66 1         34 warn "Following branches are using version $numerical\n";
67             warn "\t", join "\n\t", (sort keys %{ $versions->{$numerical} }), "\n";
68             return scalar keys %{ $versions->{$numerical} };
69 1         27 }
70 1         4  
  1         14  
71 1         3 return;
  1         5  
72             }
73              
74 1         5 my (undef, $pom) = @_;
75              
76             my $version = $workflow->next_pom_version($pom);
77             print "$version\n";
78 1     1 1 2  
79             if ($option{update}) {
80 1         4 system(qw/mvn versions:set/, "–DnewVersion=$version");
81 1         22 }
82              
83 1 50       6 return;
84 0         0 }
85              
86             my (undef, $pom, $version) = @_;
87 1         2  
88             if (!$version) {
89             warn "No version supplied!\n";
90             App::Git::Workflow::Command::pod2usage( %p2u_extra, -verbose => 1 );
91 0     0 1   return 1;
92             }
93 0 0          
94 0           $version =~ s/-SNAPSHOT$//;
95 0            
96 0           my $versions = $workflow->get_pom_versions($pom, $option{match}, $option{skip});
97              
98             my $version_re = $version =~ /^\d+[.]\d+[.]\d+/ ? qr/^$version$/ : qr/$version/;
99 0           my %versions = map {%{ $versions->{$_} }} grep {/$version_re/} keys %{ $versions };
100              
101 0           print map {"$_\t$versions{$_}\n"} sort keys %versions;
102              
103 0 0         return;
104 0           }
  0            
  0            
  0            
  0            
105              
106 0           my (undef, $pom) = @_;
  0            
107              
108 0           my @branches = $workflow->branches('both');
109             my $max_age = $workflow->_max_age;
110              
111             BRANCH:
112 0     0 1   for my $branch (sort @branches) {
113             my $current = $workflow->commit_details($branch);
114 0            
115 0           # Skip any branches that are over $MAX_AGE old
116             if ( $current->{time} < time - $max_age ) {
117             next BRANCH;
118 0           }
119 0            
120             my $xml = $workflow->git->show("$branch:$pom");
121             chomp $xml;
122 0 0         next if !$xml;
123 0            
124             $branch =~ s{^origin/}{}xms;
125              
126 0           my $version = eval { $workflow->pom_version($xml) };
127 0            
128 0 0         # make sure we get a valid version
129             if ( $@ ) {
130 0           warn "$branch is bad!\n";
131             }
132 0           }
  0            
133              
134             return;
135 0 0         }
136 0            
137             1;
138              
139              
140 0           =head1 NAME
141              
142             git-pom - Manage pom.xml (or package.json) file versions
143              
144             =head1 VERSION
145              
146             This documentation refers to git-pom version 1.1.20
147              
148             =head1 SYNOPSIS
149              
150             git-pom [uniq] [option]
151             git-pom next [--update|-u]
152             git-pom whos version [option]
153              
154             SUB-COMMAND:
155             uniq Confirm that the current branch is the only branch using its version
156             next Calculates the next available version number
157             whos Which branch uses the pom version "version"
158              
159             OPTIONS:
160             -P --pom[=]file
161             Specify the pom file location (Default pom.xml)
162             -u --update Update to next version (used with next)
163             -t --tag[=]str
164             Specify a tag that any branch with newer commits must contain
165             -b --branch[=]str
166             Similarly a branch that other branches with newer commits must
167             contain (Default origin/master)
168             -l --local Shorthand for --branch '^master$'
169              
170             -v --verbose Show more detailed option
171             --version Prints the version information
172             --help Prints this help information
173             --man Prints the full documentation for git-pom
174              
175             =head1 DESCRIPTION
176              
177             The C<git-pom> tool helps working with Maven POM files by looking at all branches to see
178             what versions are set. The sub commands allow different kinds of checking to be done.
179              
180             =over 4
181              
182             =item uniq
183              
184             Check that the current branch's POM version is unique across all branches.
185              
186             =item next
187              
188             Finds the next available POM version number buy finding the current nighest
189             POM version and incrementing the second number. If C<--update> is used then
190             the POM version is updated to that number.
191              
192             =item whos
193              
194             Find which branch or branches use a POM version number.
195              
196             =back
197              
198             =head1 SUBROUTINES/METHODS
199              
200             =head2 C<run ()>
201              
202             Executes the git workflow command
203              
204             =head2 C<do_whos ()>
205              
206             =head2 C<do_next ()>
207              
208             =head2 C<do_uniq ()>
209              
210             =head2 C<do_bad_branches ($pom)>
211              
212             Show branches with pom.xml files that don't pass
213              
214             =head1 DIAGNOSTICS
215              
216             =head1 CONFIGURATION AND ENVIRONMENT
217              
218             Defaults for this script can be set through C<git config>
219              
220             workflow.prod Sets how a prod release is determined
221             eg the default equivalent is branch=^origin/master$
222             workflow.pom The default location for the pom.xml file (used by C<--new-pom>
223             when updating pom.xml for the new branch)
224              
225             You can set these values either by editing the repository local C<.git/config>
226             file or C<~/.gitconfig> or use the C<git config> command
227              
228             # eg Setting the global value
229             git config --global workflow.prod 'branch=^origin/master$'
230              
231             # or set a repository's local value
232             git config workflow.prod 'tag=^release_\d{4}_\d{2}\d{2}$'
233              
234             # or set pom.xml location to a sub directory
235             git config workflow.pom 'somedir/pom.xml'
236              
237             =head1 DEPENDENCIES
238              
239             =head1 INCOMPATIBILITIES
240              
241             =head1 BUGS AND LIMITATIONS
242              
243             There are no known bugs in this module.
244              
245             Please report problems to Ivan Wills (ivan.wills@gmail.com).
246              
247             Patches are welcome.
248              
249             =head1 AUTHOR
250              
251             Ivan Wills - (ivan.wills@gmail.com)
252              
253             =head1 LICENSE AND COPYRIGHT
254              
255             Copyright (c) 2014 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
256             All rights reserved.
257              
258             This module is free software; you can redistribute it and/or modify it under
259             the same terms as Perl itself. See L<perlartistic>. This program is
260             distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
261             without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
262             PARTICULAR PURPOSE.
263              
264             =cut