line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OPM::Maker::Command::build; |
2
|
|
|
|
|
|
|
$OPM::Maker::Command::build::VERSION = '1.17'; |
3
|
22
|
|
|
22
|
|
14757
|
use strict; |
|
22
|
|
|
|
|
58
|
|
|
22
|
|
|
|
|
616
|
|
4
|
22
|
|
|
22
|
|
101
|
use warnings; |
|
22
|
|
|
|
|
36
|
|
|
22
|
|
|
|
|
627
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Build OPM packages |
7
|
|
|
|
|
|
|
|
8
|
22
|
|
|
22
|
|
122
|
use Carp qw(croak); |
|
22
|
|
|
|
|
39
|
|
|
22
|
|
|
|
|
917
|
|
9
|
22
|
|
|
22
|
|
8286
|
use MIME::Base64 (); |
|
22
|
|
|
|
|
68922
|
|
|
22
|
|
|
|
|
503
|
|
10
|
22
|
|
|
22
|
|
7864
|
use Sys::Hostname; |
|
22
|
|
|
|
|
17831
|
|
|
22
|
|
|
|
|
1001
|
|
11
|
22
|
|
|
22
|
|
3582
|
use Path::Class (); |
|
22
|
|
|
|
|
225741
|
|
|
22
|
|
|
|
|
394
|
|
12
|
22
|
|
|
22
|
|
8660
|
use XML::LibXML; |
|
22
|
|
|
|
|
518525
|
|
|
22
|
|
|
|
|
158
|
|
13
|
|
|
|
|
|
|
|
14
|
22
|
|
|
22
|
|
6068
|
use OPM::Maker -command; |
|
22
|
|
|
|
|
60
|
|
|
22
|
|
|
|
|
171
|
|
15
|
22
|
|
|
22
|
|
87690
|
use OPM::Maker::Utils qw(reformat_size check_args_sopm); |
|
22
|
|
|
|
|
50
|
|
|
22
|
|
|
|
|
12811
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub abstract { |
18
|
1
|
|
|
1
|
1
|
3010
|
return "build package files for Znuny, OTOBO or ((OTRS)) Community Edition"; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub usage_desc { |
22
|
1
|
|
|
1
|
1
|
1437
|
return "opmbuild build [--version ] [--basedir ] [--output ] "; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub opt_spec { |
26
|
|
|
|
|
|
|
return ( |
27
|
1
|
|
|
1
|
1
|
665
|
[ "output=s", "Output path for OPM file" ], |
28
|
|
|
|
|
|
|
[ "basedir=s", "Base directory of SOPM files" ], |
29
|
|
|
|
|
|
|
[ "version=s", "Version to be used (override the one from the sopm file)" ], |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub validate_args { |
34
|
16
|
|
|
16
|
1
|
14093
|
my ($self, $opt, $args) = @_; |
35
|
|
|
|
|
|
|
|
36
|
16
|
|
|
|
|
45
|
my $sopm = check_args_sopm( $args ); |
37
|
|
|
|
|
|
|
|
38
|
16
|
100
|
|
|
|
85
|
$self->usage_error( 'need path to .sopm' ) if |
39
|
|
|
|
|
|
|
!$sopm; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub execute { |
43
|
12
|
|
|
12
|
1
|
9453
|
my ($self, $opt, $args) = @_; |
44
|
|
|
|
|
|
|
|
45
|
12
|
|
|
|
|
43
|
my $file = check_args_sopm( $args ); |
46
|
|
|
|
|
|
|
|
47
|
12
|
|
|
|
|
49
|
my $hostname = hostname; |
48
|
12
|
|
|
|
|
501
|
my @time = localtime; |
49
|
12
|
|
|
|
|
103
|
my $timestamp = sprintf "%04d-%02d-%02d %02d:%02d:%02d", |
50
|
|
|
|
|
|
|
$time[5]+1900, $time[4]+1, $time[3], |
51
|
|
|
|
|
|
|
$time[2], $time[1], $time[0]; |
52
|
|
|
|
|
|
|
|
53
|
12
|
|
|
|
|
23
|
my %opts; |
54
|
12
|
50
|
|
|
|
48
|
if ( !$ENV{OPM_UNSECURE} ) { |
55
|
12
|
|
|
|
|
42
|
%opts = ( |
56
|
|
|
|
|
|
|
no_network => 1, |
57
|
|
|
|
|
|
|
expand_entities => 0, |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
12
|
|
|
|
|
160
|
my $size = -s $file; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# if file is big, but not "too big" |
64
|
12
|
|
|
|
|
26
|
my $max_size = 31_457_280; |
65
|
12
|
100
|
|
|
|
42
|
if ( $ENV{OPM_MAX_SIZE} ) { |
66
|
7
|
|
|
|
|
22
|
$max_size = reformat_size( $ENV{OPM_MAX_SIZE} ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
12
|
100
|
|
|
|
36
|
if ( $size > $max_size ) { |
70
|
1
|
|
|
|
|
192
|
croak "$file too big (max size: $max_size bytes)"; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
11
|
50
|
|
|
|
26
|
if ( $size > 10_000_000 ) { |
74
|
0
|
|
|
|
|
0
|
$opts{huge} = 1; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
11
|
|
|
|
|
93
|
my $parser = XML::LibXML->new( %opts ); |
78
|
11
|
|
|
|
|
1019
|
my $tree = $parser->parse_file( $file ); |
79
|
|
|
|
|
|
|
|
80
|
11
|
|
|
|
|
3824
|
my $sopm_path = Path::Class::File->new( $file ); |
81
|
11
|
|
|
|
|
1535
|
my $path = $sopm_path->dir; |
82
|
|
|
|
|
|
|
|
83
|
11
|
|
|
|
|
210
|
my $root_elem = $tree->getDocumentElement; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# retrieve file information |
86
|
11
|
|
|
|
|
72
|
my @files = $root_elem->findnodes( 'Filelist/File' ); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
FILE: |
89
|
11
|
|
|
|
|
618
|
for my $file ( @files ) { |
90
|
22
|
|
|
|
|
85
|
my $name = $file->findvalue( '@Location' ); |
91
|
|
|
|
|
|
|
my $file_path = Path::Class::File->new( |
92
|
22
|
100
|
|
|
|
1893
|
$opt->{basedir} ? $opt->{basedir} : $path, $name ); |
93
|
22
|
|
|
|
|
1881
|
my $file_content = $file_path->slurp; |
94
|
22
|
|
|
|
|
4645
|
my $base64 = MIME::Base64::encode( $file_content ); |
95
|
|
|
|
|
|
|
|
96
|
22
|
|
|
|
|
97
|
$file->setAttribute( 'Encode', 'Base64' ); |
97
|
22
|
|
|
|
|
583
|
$file->appendText( $base64 ); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
11
|
|
|
|
|
81
|
my $build_date = XML::LibXML::Element->new( 'BuildDate' ); |
101
|
11
|
|
|
|
|
42
|
$build_date->appendText( $timestamp ); |
102
|
|
|
|
|
|
|
|
103
|
11
|
|
|
|
|
32
|
my $build_host = XML::LibXML::Element->new( 'BuildHost' ); |
104
|
11
|
|
|
|
|
36
|
$build_host->appendText( $hostname ); |
105
|
|
|
|
|
|
|
|
106
|
11
|
|
|
|
|
75
|
$root_elem->addChild( $build_date ); |
107
|
11
|
|
|
|
|
46
|
$root_elem->addChild( $build_host ); |
108
|
|
|
|
|
|
|
|
109
|
11
|
|
|
|
|
428
|
my $version = $root_elem->find( 'Version' )->[0]; |
110
|
11
|
100
|
|
|
|
580
|
if ( $opt->{version} ) { |
111
|
1
|
|
|
|
|
8
|
$version->removeChildNodes(); |
112
|
1
|
|
|
|
|
4
|
$version->appendText( $opt->{version} ); |
113
|
|
|
|
|
|
|
} |
114
|
11
|
|
|
|
|
34
|
my $package_name = $root_elem->findvalue( 'Name' ); |
115
|
11
|
|
|
|
|
764
|
my $file_name = sprintf "%s-%s.opm", $package_name, $version->textContent; |
116
|
|
|
|
|
|
|
|
117
|
11
|
|
|
|
|
27
|
my $output_path = $opt->{output}; |
118
|
11
|
100
|
|
|
|
31
|
$output_path = $path if !$output_path; |
119
|
|
|
|
|
|
|
|
120
|
11
|
|
|
|
|
50
|
my $opm_path = Path::Class::File->new( $output_path, $file_name ); |
121
|
11
|
|
|
|
|
753
|
my $fh = $opm_path->openw; |
122
|
11
|
|
|
|
|
2110
|
$fh->print( $tree->toString ); |
123
|
|
|
|
|
|
|
|
124
|
11
|
|
|
|
|
904
|
return $opm_path->stringify; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |