line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OTRS::OPM::Maker::Command::build; |
2
|
|
|
|
|
|
|
$OTRS::OPM::Maker::Command::build::VERSION = '0.18'; |
3
|
15
|
|
|
15
|
|
14141
|
use strict; |
|
15
|
|
|
|
|
39
|
|
|
15
|
|
|
|
|
505
|
|
4
|
15
|
|
|
15
|
|
86
|
use warnings; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
438
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Build OTRS packages |
7
|
|
|
|
|
|
|
|
8
|
15
|
|
|
15
|
|
6687
|
use MIME::Base64 (); |
|
15
|
|
|
|
|
8610
|
|
|
15
|
|
|
|
|
397
|
|
9
|
15
|
|
|
15
|
|
6485
|
use Sys::Hostname; |
|
15
|
|
|
|
|
13803
|
|
|
15
|
|
|
|
|
861
|
|
10
|
15
|
|
|
15
|
|
4324
|
use Path::Class (); |
|
15
|
|
|
|
|
282531
|
|
|
15
|
|
|
|
|
354
|
|
11
|
15
|
|
|
15
|
|
5309
|
use XML::LibXML; |
|
15
|
|
|
|
|
359250
|
|
|
15
|
|
|
|
|
123
|
|
12
|
|
|
|
|
|
|
|
13
|
15
|
|
|
15
|
|
4686
|
use OTRS::OPM::Maker -command; |
|
15
|
|
|
|
|
40
|
|
|
15
|
|
|
|
|
197
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub abstract { |
16
|
1
|
|
|
1
|
1
|
4629
|
return "build package files for OTRS"; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub usage_desc { |
20
|
1
|
|
|
1
|
1
|
946
|
return "opmbuild build [--version ] [--output ] "; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub opt_spec { |
24
|
|
|
|
|
|
|
return ( |
25
|
1
|
|
|
1
|
1
|
637
|
[ "output=s", "Output path for OPM file" ], |
26
|
|
|
|
|
|
|
[ "version=s", "Version to be used (override the one from the sopm file)" ], |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub validate_args { |
31
|
8
|
|
|
8
|
1
|
8327
|
my ($self, $opt, $args) = @_; |
32
|
|
|
|
|
|
|
|
33
|
8
|
100
|
100
|
|
|
155
|
$self->usage_error( 'need path to .sopm' ) if |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
34
|
|
|
|
|
|
|
!$args or |
35
|
|
|
|
|
|
|
'ARRAY' ne ref $args or |
36
|
|
|
|
|
|
|
!defined $args->[0] or |
37
|
|
|
|
|
|
|
$args->[0] !~ /\.sopm\z/ or |
38
|
|
|
|
|
|
|
!-f $args->[0]; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub execute { |
42
|
3
|
|
|
3
|
1
|
3880
|
my ($self, $opt, $args) = @_; |
43
|
|
|
|
|
|
|
|
44
|
3
|
|
|
|
|
10
|
my $file = $args->[0]; |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
18
|
my $hostname = hostname; |
47
|
3
|
|
|
|
|
227
|
my @time = localtime; |
48
|
3
|
|
|
|
|
31
|
my $timestamp = sprintf "%04d-%02d-%02d %02d:%02d:%02d", |
49
|
|
|
|
|
|
|
$time[5]+1900, $time[4]+1, $time[3], |
50
|
|
|
|
|
|
|
$time[2], $time[1], $time[0]; |
51
|
|
|
|
|
|
|
|
52
|
3
|
|
|
|
|
28
|
my $parser = XML::LibXML->new; |
53
|
3
|
|
|
|
|
90
|
my $tree = $parser->parse_file( $file ); |
54
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
1343
|
my $sopm_path = Path::Class::File->new( $file ); |
56
|
3
|
|
|
|
|
649
|
my $path = $sopm_path->dir; |
57
|
|
|
|
|
|
|
|
58
|
3
|
|
|
|
|
44
|
my $root_elem = $tree->getDocumentElement; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# retrieve file information |
61
|
3
|
|
|
|
|
29
|
my @files = $root_elem->findnodes( 'Filelist/File' ); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
FILE: |
64
|
3
|
|
|
|
|
253
|
for my $file ( @files ) { |
65
|
6
|
|
|
|
|
33
|
my $name = $file->findvalue( '@Location' ); |
66
|
6
|
|
|
|
|
820
|
my $file_path = Path::Class::File->new( $path, $name ); |
67
|
6
|
|
|
|
|
641
|
my $file_content = $file_path->slurp; |
68
|
6
|
|
|
|
|
2036
|
my $base64 = MIME::Base64::encode( $file_content ); |
69
|
|
|
|
|
|
|
|
70
|
6
|
|
|
|
|
38
|
$file->setAttribute( 'Encode', 'Base64' ); |
71
|
6
|
|
|
|
|
779
|
$file->appendText( $base64 ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
3
|
|
|
|
|
34
|
my $build_date = XML::LibXML::Element->new( 'BuildDate' ); |
75
|
3
|
|
|
|
|
19
|
$build_date->appendText( $timestamp ); |
76
|
|
|
|
|
|
|
|
77
|
3
|
|
|
|
|
10
|
my $build_host = XML::LibXML::Element->new( 'BuildHost' ); |
78
|
3
|
|
|
|
|
13
|
$build_host->appendText( $hostname ); |
79
|
|
|
|
|
|
|
|
80
|
3
|
|
|
|
|
35
|
$root_elem->addChild( $build_date ); |
81
|
3
|
|
|
|
|
18
|
$root_elem->addChild( $build_host ); |
82
|
|
|
|
|
|
|
|
83
|
3
|
|
|
|
|
197
|
my $version = $root_elem->find( 'Version' )->[0]; |
84
|
3
|
100
|
|
|
|
210
|
if ( $opt->{version} ) { |
85
|
1
|
|
|
|
|
10
|
$version->removeChildNodes(); |
86
|
1
|
|
|
|
|
5
|
$version->appendText( $opt->{version} ); |
87
|
|
|
|
|
|
|
} |
88
|
3
|
|
|
|
|
11
|
my $package_name = $root_elem->findvalue( 'Name' ); |
89
|
3
|
|
|
|
|
299
|
my $file_name = sprintf "%s-%s.opm", $package_name, $version->textContent; |
90
|
|
|
|
|
|
|
|
91
|
3
|
|
|
|
|
10
|
my $output_path = $opt->{output}; |
92
|
3
|
100
|
|
|
|
12
|
$output_path = $path if !$output_path; |
93
|
|
|
|
|
|
|
|
94
|
3
|
|
|
|
|
19
|
my $opm_path = Path::Class::File->new( $output_path, $file_name ); |
95
|
3
|
|
|
|
|
291
|
my $fh = $opm_path->openw; |
96
|
3
|
|
|
|
|
702
|
$fh->print( $tree->toString ); |
97
|
|
|
|
|
|
|
|
98
|
3
|
|
|
|
|
1323
|
return $opm_path->stringify; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |