line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OTRS::OPM::Maker::Command::build; |
2
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
13626
|
use strict; |
|
15
|
|
|
|
|
39
|
|
|
15
|
|
|
|
|
488
|
|
4
|
15
|
|
|
15
|
|
80
|
use warnings; |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
422
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Build OTRS packages |
7
|
|
|
|
|
|
|
|
8
|
15
|
|
|
15
|
|
6457
|
use MIME::Base64 (); |
|
15
|
|
|
|
|
8318
|
|
|
15
|
|
|
|
|
398
|
|
9
|
15
|
|
|
15
|
|
6169
|
use Sys::Hostname; |
|
15
|
|
|
|
|
13900
|
|
|
15
|
|
|
|
|
831
|
|
10
|
15
|
|
|
15
|
|
4220
|
use Path::Class (); |
|
15
|
|
|
|
|
293142
|
|
|
15
|
|
|
|
|
357
|
|
11
|
15
|
|
|
15
|
|
5191
|
use XML::LibXML; |
|
15
|
|
|
|
|
364291
|
|
|
15
|
|
|
|
|
122
|
|
12
|
|
|
|
|
|
|
|
13
|
15
|
|
|
15
|
|
4500
|
use OTRS::OPM::Maker -command; |
|
15
|
|
|
|
|
37
|
|
|
15
|
|
|
|
|
194
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.17'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub abstract { |
18
|
1
|
|
|
1
|
1
|
3655
|
return "build package files for OTRS"; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub usage_desc { |
22
|
1
|
|
|
1
|
1
|
881
|
return "opmbuild build [--version ] [--output ] "; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub opt_spec { |
26
|
|
|
|
|
|
|
return ( |
27
|
1
|
|
|
1
|
1
|
556
|
[ "output=s", "Output path for OPM file" ], |
28
|
|
|
|
|
|
|
[ "version=s", "Version to be used (override the one from the sopm file)" ], |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub validate_args { |
33
|
8
|
|
|
8
|
1
|
8424
|
my ($self, $opt, $args) = @_; |
34
|
|
|
|
|
|
|
|
35
|
8
|
100
|
100
|
|
|
160
|
$self->usage_error( 'need path to .sopm' ) if |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
36
|
|
|
|
|
|
|
!$args or |
37
|
|
|
|
|
|
|
'ARRAY' ne ref $args or |
38
|
|
|
|
|
|
|
!defined $args->[0] or |
39
|
|
|
|
|
|
|
$args->[0] !~ /\.sopm\z/ or |
40
|
|
|
|
|
|
|
!-f $args->[0]; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub execute { |
44
|
3
|
|
|
3
|
1
|
3723
|
my ($self, $opt, $args) = @_; |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
9
|
my $file = $args->[0]; |
47
|
|
|
|
|
|
|
|
48
|
3
|
|
|
|
|
16
|
my $hostname = hostname; |
49
|
3
|
|
|
|
|
228
|
my @time = localtime; |
50
|
3
|
|
|
|
|
33
|
my $timestamp = sprintf "%04d-%02d-%02d %02d:%02d:%02d", |
51
|
|
|
|
|
|
|
$time[5]+1900, $time[4]+1, $time[3], |
52
|
|
|
|
|
|
|
$time[2], $time[1], $time[0]; |
53
|
|
|
|
|
|
|
|
54
|
3
|
|
|
|
|
30
|
my $parser = XML::LibXML->new; |
55
|
3
|
|
|
|
|
91
|
my $tree = $parser->parse_file( $file ); |
56
|
|
|
|
|
|
|
|
57
|
3
|
|
|
|
|
1500
|
my $sopm_path = Path::Class::File->new( $file ); |
58
|
3
|
|
|
|
|
689
|
my $path = $sopm_path->dir; |
59
|
|
|
|
|
|
|
|
60
|
3
|
|
|
|
|
47
|
my $root_elem = $tree->getDocumentElement; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# retrieve file information |
63
|
3
|
|
|
|
|
51
|
my @files = $root_elem->findnodes( 'Filelist/File' ); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
FILE: |
66
|
3
|
|
|
|
|
238
|
for my $file ( @files ) { |
67
|
6
|
|
|
|
|
41
|
my $name = $file->findvalue( '@Location' ); |
68
|
6
|
|
|
|
|
848
|
my $file_path = Path::Class::File->new( $path, $name ); |
69
|
6
|
|
|
|
|
640
|
my $file_content = $file_path->slurp; |
70
|
6
|
|
|
|
|
2066
|
my $base64 = MIME::Base64::encode( $file_content ); |
71
|
|
|
|
|
|
|
|
72
|
6
|
|
|
|
|
37
|
$file->setAttribute( 'Encode', 'Base64' ); |
73
|
6
|
|
|
|
|
805
|
$file->appendText( $base64 ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
3
|
|
|
|
|
37
|
my $build_date = XML::LibXML::Element->new( 'BuildDate' ); |
77
|
3
|
|
|
|
|
19
|
$build_date->appendText( $timestamp ); |
78
|
|
|
|
|
|
|
|
79
|
3
|
|
|
|
|
12
|
my $build_host = XML::LibXML::Element->new( 'BuildHost' ); |
80
|
3
|
|
|
|
|
12
|
$build_host->appendText( $hostname ); |
81
|
|
|
|
|
|
|
|
82
|
3
|
|
|
|
|
32
|
$root_elem->addChild( $build_date ); |
83
|
3
|
|
|
|
|
18
|
$root_elem->addChild( $build_host ); |
84
|
|
|
|
|
|
|
|
85
|
3
|
|
|
|
|
230
|
my $version = $root_elem->find( 'Version' )->[0]; |
86
|
3
|
100
|
|
|
|
160
|
if ( $opt->{version} ) { |
87
|
1
|
|
|
|
|
8
|
$version->removeChildNodes(); |
88
|
1
|
|
|
|
|
4
|
$version->appendText( $opt->{version} ); |
89
|
|
|
|
|
|
|
} |
90
|
3
|
|
|
|
|
11
|
my $package_name = $root_elem->findvalue( 'Name' ); |
91
|
3
|
|
|
|
|
251
|
my $file_name = sprintf "%s-%s.opm", $package_name, $version->textContent; |
92
|
|
|
|
|
|
|
|
93
|
3
|
|
|
|
|
9
|
my $output_path = $opt->{output}; |
94
|
3
|
100
|
|
|
|
13
|
$output_path = $path if !$output_path; |
95
|
|
|
|
|
|
|
|
96
|
3
|
|
|
|
|
19
|
my $opm_path = Path::Class::File->new( $output_path, $file_name ); |
97
|
3
|
|
|
|
|
272
|
my $fh = $opm_path->openw; |
98
|
3
|
|
|
|
|
660
|
$fh->print( $tree->toString ); |
99
|
|
|
|
|
|
|
|
100
|
3
|
|
|
|
|
1273
|
return $opm_path->stringify; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |