File Coverage

blib/lib/MavenBuilds/Tasks/BuildWebappsWithMaven.pm
Criterion Covered Total %
statement 16 18 88.8
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 22 24 91.6


line stmt bran cond sub pod time code
1             package MavenBuilds::Tasks::BuildWebappsWithMaven;
2            
3 1     1   24175 use 5.006;
  1         4  
  1         56  
4 1     1   10 use strict;
  1         3  
  1         49  
5 1     1   8 use warnings FATAL => 'all';
  1         6  
  1         66  
6            
7 1     1   7 use Exporter qw(import);
  1         3  
  1         69  
8             our @EXPORT = qw(execute setOptions setTomcatDirectory setMavenDirectory setMavenArtifactsDirectory setLocationsOfLocalDependencies setWebAppLoc setMavenSettingsFileLocation);
9            
10 1     1   7 use File::Path;
  1         2  
  1         82  
11 1     1   27355 use XML::Simple;
  0            
  0            
12             use Data::Dumper;
13             use File::Copy::Recursive qw(dircopy);
14             use Getopt::Long;
15            
16             #prefill default Locations
17             my $tomcatDir = "C:/Users/i076326/Documents/softwares/apache-tomcat-7.0.57/bin";
18             my $mavenDir = "C:/Users/i076326/Documents/softwares/apache-maven-3.0.5/bin";
19             my $mavenArtifactsDir = "C:/Users/i076326/.m2";
20             my @localDevVersions = ("C:/Users/i076326/git/sap.ui.m2m.extor.reuse");
21             my $webAppLoc = "C:/Users/i076326/git/ui.m2m.extor";
22             my $settingsFile = "settings-ui5.xml";
23            
24             =head1 NAME
25            
26             MavenBuilds::Tasks::BuildWebappsWithMaven - The great new MavenBuilds::Tasks::BuildWebappsWithMaven!
27            
28             =head1 VERSION
29            
30             Version 0.01
31            
32             =cut
33            
34             our $VERSION = '0.01';
35            
36            
37             =head1 SYNOPSIS
38            
39             Quick summary of what the module does.
40            
41             Perhaps a little code snippet.
42            
43             use MavenBuilds::Tasks::BuildWebappsWithMaven;
44            
45             my $foo = MavenBuilds::Tasks::BuildWebappsWithMaven->new();
46             $foo->execute();
47            
48             =head1 EXPORT
49            
50             A list of functions that can be exported. You can delete this section
51             if you don't export anything, such as for a purely object-oriented module.
52            
53             =head1 SUBROUTINES/METHODS
54            
55             =head2 new
56            
57             =cut
58            
59             sub new {
60            
61             my $self = {};
62             bless($self);
63             return $self;
64             }
65            
66             =head2 setOptions
67            
68             =cut
69            
70             sub setOptions{
71            
72             my $localDevVersionsStr = 0;
73            
74             GetOptions(
75             "tomcatDir=s", \$tomcatDir,
76             "mavenDir=s", \$mavenDir,
77             "mavenArtifactsDir=s", \$mavenArtifactsDir,
78             "localDevVersions=s", \$localDevVersionsStr,
79             "webAppLoc=s", \$webAppLoc,
80             "settingsFile=s", \$settingsFile
81             );
82            
83             @localDevVersions = split(",", $localDevVersionsStr, length($localDevVersionsStr));
84             }
85            
86             =head2 setTomcatDirectory
87            
88             =cut
89            
90             sub setTomcatDirectory{
91             $tomcatDir = $_[0];
92             }
93            
94             =head2 setMavenDirectory
95            
96             =cut
97            
98             sub setMavenDirectory{
99             $mavenDir = $_[0];
100             }
101            
102             =head2 setMavenArtifactsDirectory
103            
104             =cut
105            
106             sub setMavenArtifactsDirectory{
107             $mavenArtifactsDir = $_[0];
108             }
109            
110             =head2 setLocationsOfLocalDependencies
111            
112             =cut
113            
114             sub setLocationsOfLocalDependencies{
115             @localDevVersions = @_;
116             }
117            
118             =head2 setWebAppLoc
119            
120             =cut
121            
122             sub setWebAppLoc{
123             $webAppLoc = $_[0];
124             }
125            
126             =head2 setMavenSettingsFileLocation
127            
128             =cut
129            
130             sub setMavenSettingsFileLocation{
131             $settingsFile = $_[0];
132             }
133            
134             =head2 execute
135            
136             =cut
137            
138             sub execute{
139             _stopTomcat();
140             _cleanupTomcatDirectory();
141             _readAndCleanupLocalDependencies();
142             _createNewSnapshots();
143             _hostAndStart();
144             }
145            
146             =head2 _stopTomcat
147            
148             =cut
149            
150             sub _stopTomcat{
151             chdir $tomcatDir;
152             my @argsTomcatStop = ("shutdown.bat");
153             system(@argsTomcatStop);
154            
155             print "Stop Tomcat\n";
156             }
157            
158             =head2 _startTomcat
159            
160             =cut
161            
162             sub _startTomcat{
163             chdir $tomcatDir;
164             my @argsTomcatStart = ("startup.bat");
165             system(@argsTomcatStart);
166             }
167            
168             =head2 _getArtifactIdOfParent
169            
170             =cut
171            
172             sub _getArtifactIdOfParent{
173             my $fileName = $webAppLoc . "/pom.xml";
174             my $xml = new XML::Simple;
175            
176             my $data = $xml->XMLin($fileName);
177            
178             my $webappGroupId = $data->{groupId};
179             my $webappArtifactId = $data->{artifactId};
180            
181             return $webappArtifactId;
182             }
183            
184             =head2 _getWebappDirectory
185            
186             =cut
187            
188             sub _getWebappDirectory{
189             my $tomcatPathMaker = substr($tomcatDir, 0, -4);
190             $tomcatPathMaker = $tomcatPathMaker . "/webapps";
191            
192             return $tomcatPathMaker;
193             }
194            
195             =head2 _cleanupTomcatDirectory
196            
197             =cut
198            
199             sub _cleanupTomcatDirectory{
200             my $tomcatPathMaker = _getWebappDirectory();
201             my $webappArtifactId = _getArtifactIdOfParent();
202             rmtree($tomcatPathMaker . "/" . $webappArtifactId, { verbose => 1, mode => 0711 });
203             }
204            
205             =head2 _readAndCleanupLocalDependencies
206            
207             =cut
208            
209             sub _readAndCleanupLocalDependencies{
210             for my $count (@localDevVersions){
211             my $fileName = $count . "/pom.xml";
212             my $xml = new XML::Simple;
213            
214             my $data = $xml->XMLin($fileName);
215            
216             my $groupId = $data->{groupId};
217             my $artifactId = $data->{artifactId};
218            
219             my @pathFormer = split('\.', $groupId);
220             my $finalPath = $mavenArtifactsDir . "/repository";
221             for my $pathCounter (@pathFormer) {
222             $finalPath = $finalPath . "/" . $pathCounter;
223             }
224             $finalPath = $finalPath . "/" . $artifactId;
225            
226             #delete the snapshot tree under the maven directory
227             rmtree($finalPath, { verbose => 1, mode => 0711 });
228            
229             print $!;
230             }
231             }
232            
233             =head2 _createNewSnapshots
234            
235             =cut
236            
237             sub _createNewSnapshots{
238             #create new snapshots for each local dependency
239             for my $count (@localDevVersions){
240             my $dependencyName = $count;
241            
242             #assuming settings file resides in maven artifacts Dir
243             my @mvnExecutorClean = ($mavenDir . "/mvn.bat","clean","-f",$dependencyName . "/pom.xml","--settings",$mavenArtifactsDir . "/" . $settingsFile);
244             my @mvnExecutorInstall = ($mavenDir . "/mvn.bat","install","-f",$dependencyName . "/pom.xml","--settings",$mavenArtifactsDir . "/" . $settingsFile);
245            
246             system(@mvnExecutorClean);
247             system(@mvnExecutorInstall);
248             }
249            
250             #create new snapshot for webApp
251             #assuming settings file resides in maven artifacts Dir
252             my @mvnExecutorClean = ($mavenDir . "/mvn.bat","clean","-f",$webAppLoc . "/pom.xml","--settings",$mavenArtifactsDir . "/" . $settingsFile);
253             my @mvnExecutorInstall = ($mavenDir . "/mvn.bat","install","-f",$webAppLoc . "/pom.xml","--settings",$mavenArtifactsDir . "/" . $settingsFile);
254            
255             system(@mvnExecutorClean);
256             system(@mvnExecutorInstall);
257            
258             }
259            
260             =head2 _hostAndStart
261            
262             =cut
263            
264             sub _hostAndStart{
265             #hosting webApp in tomcat
266            
267             my $tomcatPathMaker = _getWebappDirectory();
268             my $webappArtifactId = _getArtifactIdOfParent();
269            
270             my @finalCmd = ("mkdir", $tomcatPathMaker . "/" . $webappArtifactId);
271             system(@finalCmd);
272             dircopy($webAppLoc . "/target/" . $webappArtifactId, $tomcatPathMaker . "/" . $webappArtifactId);
273             _startTomcat();
274             }
275             =head1 AUTHOR
276            
277             Subhobrata Dey, C<< >>
278            
279             =head1 BUGS
280            
281             Please report any bugs or feature requests to C, or through
282             the web interface at L. I will be notified, and then you'll
283             automatically be notified of progress on your bug as I make changes.
284            
285            
286            
287            
288             =head1 SUPPORT
289            
290             You can find documentation for this module with the perldoc command.
291            
292             perldoc MavenBuilds::Tasks::BuildWebappsWithMaven
293            
294            
295             You can also look for information at:
296            
297             =over 4
298            
299             =item * RT: CPAN's request tracker (report bugs here)
300            
301             L
302            
303             =item * AnnoCPAN: Annotated CPAN documentation
304            
305             L
306            
307             =item * CPAN Ratings
308            
309             L
310            
311             =item * Search CPAN
312            
313             L
314            
315             =back
316            
317            
318             =head1 ACKNOWLEDGEMENTS
319            
320            
321             =head1 LICENSE AND COPYRIGHT
322            
323             Copyright 2014 Subhobrata Dey.
324            
325             This program is free software; you can redistribute it and/or modify it
326             under the terms of the the Artistic License (2.0). You may obtain a
327             copy of the full license at:
328            
329             L
330            
331             Any use, modification, and distribution of the Standard or Modified
332             Versions is governed by this Artistic License. By using, modifying or
333             distributing the Package, you accept this license. Do not use, modify,
334             or distribute the Package, if you do not accept this license.
335            
336             If your Modified Version has been derived from a Modified Version made
337             by someone other than you, you are nevertheless required to ensure that
338             your Modified Version complies with the requirements of this license.
339            
340             This license does not grant you the right to use any trademark, service
341             mark, tradename, or logo of the Copyright Holder.
342            
343             This license includes the non-exclusive, worldwide, free-of-charge
344             patent license to make, have made, use, offer to sell, sell, import and
345             otherwise transfer the Package with respect to any patent claims
346             licensable by the Copyright Holder that are necessarily infringed by the
347             Package. If you institute patent litigation (including a cross-claim or
348             counterclaim) against any party alleging that the Package constitutes
349             direct or contributory patent infringement, then this Artistic License
350             to you shall terminate on the date that such litigation is filed.
351            
352             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
353             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
354             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
355             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
356             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
357             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
358             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
359             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
360            
361            
362             =cut
363            
364             1; # End of MavenBuilds::Tasks::BuildWebappsWithMaven