lib/Rex/Apache/Build/rpm.pm

filter: Statementstmt 34.7% 40 / 115 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 76.4% 13 / 17 Podpod 0.0% 0 / 4 totaltotal 28.8% 53 / 184 CC 22 SCAR 36.1
CC
22
Cov
26%
find_files
72.0
new
56.0
find_dirs
56.0
CRAP 37.1
« blib/lib/Rex/Apache/Build.pm ↑ Summary lib/Rex/Apache/Deploy/JBoss.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4 # vim: set ts=2 sw=2 tw=0:
5 # vim: set expandtab:
6  
7 =head1 NAME
8  
9 Rex::Apache::Build::rpm - Build rpm packages
10  
11 =head1 DESCRIPTION
12  
13 With this module you can build RedHat packages to distribute your application.
14  
15 =head1 SYNOPSIS
16  
17 build "my-software",
18 type => "rpm",
19 version => "1.0",
20 source => "/path/to/your/software",
21 path => "/path/to/deploy/target",
22 # below this, it is all optional
23 description => "some description of your package",
24 url => "website of the package",
25 depends => [qw/httpd perl/],
26 release => 1,
27 epoch => 1,
28 vendor => "some vendor",
29 license => "your license for ex. GPL2",
30 section => "some/section",
31 conflicts => [qw/somepkg/],
32 provides => "some-package-name",
33 arch => "x86_64",
34 target => "linux / the platform",
35 post_install => "filename or script to run after installation",
36 pre_install => "filename or script to run before installation",
37 post_uninstall => "filename or script to run after uninstall",
38 pre_uninstall => "filename or script to run before uninstall",
39 exclude => [qw/file1 file2/],
40 maintainer => "your name",
41 config_files => [qw/special files for configuration mostly for etc directory/];
42  
43  
44 =cut
45  
46 package Rex::Apache::Build::rpm;
47  
48 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 ▶use attributes;
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 1 ▶use Cwd qw(getcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 ▶use Digest::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 1 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 1 ▶use Rex::Commands::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 1 ▶use Rex::Commands::Fs;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 1 ▶use Rex::Commands::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 1 ▶use Rex::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 1 ▶use Rex::Apache::Build::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 1 ▶use base qw(Rex::Apache::Build::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 0 ▶sub new {
Subroutine new: not called CC=7 SCAR=40.3
Pod undocumented
65 0 my $that = shift;
66 0 ▶ my $proto = ref($that) || $that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
67 0 my $self = $proto->SUPER::new(@_);
68  
69 0 bless($self, $proto);
70  
71 0 ▶ $self->{license} ||= "unknown";
Condition0%0/2
$self->{"license"} ||= "unknown"
l!l
00
MC/DC0%0/1
$self->{"license"} ||= "unknown"
$self->{"license"}
Truth table0%0/2
A
A= $self->{"license"}
Aresult
11
00
72 0 ▶ $self->{file_user} ||= "root";
Condition0%0/2
$self->{"file_user"} ||= "root"
l!l
00
MC/DC0%0/1
$self->{"file_user"} ||= "root"
$self->{"file_user"}
Truth table0%0/2
A
A= $self->{"file_user"}
Aresult
11
00
73 0 ▶ $self->{file_group} ||= "root";
Condition0%0/2
$self->{"file_group"} ||= "root"
l!l
00
MC/DC0%0/1
$self->{"file_group"} ||= "root"
$self->{"file_group"}
Truth table0%0/2
A
A= $self->{"file_group"}
Aresult
11
00
74 0 ▶ $self->{release} ||= 1;
Condition0%0/2
$self->{"release"} ||= 1
l!l
00
MC/DC0%0/1
$self->{"release"} ||= 1
$self->{"release"}
Truth table0%0/2
A
A= $self->{"release"}
Aresult
11
00
75 0 ▶ $self->{exclude} ||= [];
Condition0%0/2
$self->{"exclude"} ||= []
l!l
00
MC/DC0%0/1
$self->{"exclude"} ||= []
$self->{"exclude"}
Truth table0%0/2
A
A= $self->{"exclude"}
Aresult
11
00
76  
77 0 push(@{ $self->{exclude} }, qr{^Rexfile$}, qr{^Rexfile\.lock$}, qr{^\.git}, qr{^\.svn}, qr{.*~$}, qr{\.sw[a-z]$}, qr{\.rpm$});
78  
79 0 return $self;
80 }
81  
82 0 ▶sub build {
Subroutine build: not called CC=3 SCAR=24.8
Pod undocumented
83 0 my ($self, $name) = @_;
84  
85 0 ▶ $name ||= $self->name;
Condition0%0/3
$name ||= $self->name
l!l&&r!l&&!r
000
MC/DC0%0/2
$name ||= $self->name
$name $self->name
Truth table0%0/3
A ||= B
A= $nameB= $self->name
ABresult
1X1
011
000
86  
87 0 mkdir "temp-rpm-build";
88 0 mkdir "temp-rpm-build/tree";
89 0 mkdir "temp-rpm-build/tree" . $self->prefix;
90  
91 0 my @dirs = $self->find_dirs;
92 0 push(@dirs, $self->prefix);
93  
94 0 my @files = $self->find_files;
95  
96 0 file "temp-rpm-build/$name.spec",
97 content => template('@spec.template', pkg => $self, cur_dir => getcwd(), files => \@files, dirs => \@dirs);
98  
99 0 chdir "temp-rpm-build";
100  
101 0 ▶ my $rpmbuild_path = Rex::Config->get("rpmbuild") || "rpmbuild";
Condition0%0/2
'Rex::Config'->get('rpmbuild') || 'rpmbuild'
l!l
00
MC/DC0%0/1
'Rex::Config'->get('rpmbuild') || 'rpmbuild'
'Rex::Config'->get('rpmbuild')
Truth table0%0/2
A
A= 'Rex::Config'->get('rpmbuild')
Aresult
11
00
102 0 run "$rpmbuild_path --buildroot=" . getcwd() . "/tree -bb $name.spec";
103  
104 0 chdir "..";
105  
106 0 my $arch = $self->arch;
107 0 cp "temp-rpm-build/$arch/*.rpm", ".";
108  
109 0 rmdir "temp-rpm-build";
110  
111 0 my $build_file = "$name-" . $self->version . "-" . $self->release . "." . $self->arch . ".rpm";
112 0 Rex::Logger::info("Your build is now available: $build_file");
113  
114 0 return $build_file;
115 }
116  
117 0 ▶sub find_files {
Subroutine find_files: not called CC=8 SCAR=42.8
Pod undocumented
118 0 my ($self) = @_;
119  
120 0 my @ret;
121  
122 0 my @dirs = ($self->{source});
123 0 for my $dir (@dirs) {
124 0 ▶ opendir(my $dh, $dir) or die($!);
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or die $! 0 0 0
125 0 ▶ while(my $entry = readdir($dh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = readdir $dh)) 0 0 0
126 0 ▶ next if($entry eq ".");
Branch: 1 branch
BranchTrueFalseTotal
if $entry eq "." 0 0 0
127 0 ▶ next if($entry eq "..");
Branch: 1 branch
BranchTrueFalseTotal
if $entry eq ".." 0 0 0
128  
129 0 ▶ if(-d "$dir/$entry") {
Branch: 1 branch
BranchTrueFalseTotal
if (-d "$dir/$entry") 0 0 0
130 0 push(@dirs, "$dir/$entry");
131 0 next;
132 }
133  
134 0 Rex::Logger::debug("Adding file: " . getcwd() . "/$dir/$entry => $dir/$entry");
135 0 push(@ret, [getcwd() . "/$dir/$entry", "$dir/$entry"]);
136 }
137 0 closedir($dh);
138 }
139  
140 # free conffiles
141 0 for my $conf (@{ $self->config_files }) {
142 0 @ret = grep { $_->[0] !~ m/$conf/ } @ret;
143 }
144  
145 0 my $top = $self->source . "/";
146 0 map { $_->[1] =~ s/^$top// } @ret;
147  
148 0 Rex::Logger::debug("==== files ====");
149 0 Rex::Logger::debug(Dumper(\@ret));
150  
151 0 return @ret;
152 }
153  
154 0 ▶sub find_dirs {
Subroutine find_dirs: not called CC=7 SCAR=40.3
Pod undocumented
155 0 my ($self) = @_;
156  
157 0 my @ret;
158  
159 0 my @dirs = ($self->{source});
160 0 for my $dir (@dirs) {
161 0 ▶ opendir(my $dh, $dir) or die($!);
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or die $! 0 0 0
162 0 ▶ while(my $entry = readdir($dh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = readdir $dh)) 0 0 0
163 0 ▶ next if($entry eq ".");
Branch: 1 branch
BranchTrueFalseTotal
if $entry eq "." 0 0 0
164 0 ▶ next if($entry eq "..");
Branch: 1 branch
BranchTrueFalseTotal
if $entry eq ".." 0 0 0
165  
166 0 ▶ if(-d "$dir/$entry") {
Branch: 1 branch
BranchTrueFalseTotal
if (-d "$dir/$entry") 0 0 0
167 0 push(@dirs, "$dir/$entry");
168  
169 0 Rex::Logger::debug("Adding directory: $dir/$entry");
170 0 push(@ret, "$dir/$entry");
171 }
172  
173 }
174 0 closedir($dh);
175 }
176  
177 0 my $top = $self->source;
178 0 map { s/^$top//; $_ = $self->prefix . $_ } @ret;
179  
180 0 Rex::Logger::debug("==== directories ====");
181 0 Rex::Logger::debug(Dumper(\@ret));
182  
183 0 return @ret;
184 }
185  
186  
187  
188 1 1;
189  
190 __DATA__
« blib/lib/Rex/Apache/Build.pm ↑ Summary lib/Rex/Apache/Deploy/JBoss.pm »