line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OTRS::OPM::Maker::Command::build; |
2
|
|
|
|
|
|
|
$OTRS::OPM::Maker::Command::build::VERSION = '0.19'; |
3
|
15
|
|
|
15
|
|
13763
|
use strict; |
|
15
|
|
|
|
|
34
|
|
|
15
|
|
|
|
|
497
|
|
4
|
15
|
|
|
15
|
|
86
|
use warnings; |
|
15
|
|
|
|
|
28
|
|
|
15
|
|
|
|
|
444
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Build OTRS packages |
7
|
|
|
|
|
|
|
|
8
|
15
|
|
|
15
|
|
6660
|
use MIME::Base64 (); |
|
15
|
|
|
|
|
9014
|
|
|
15
|
|
|
|
|
409
|
|
9
|
15
|
|
|
15
|
|
6201
|
use Sys::Hostname; |
|
15
|
|
|
|
|
13387
|
|
|
15
|
|
|
|
|
848
|
|
10
|
15
|
|
|
15
|
|
4379
|
use Path::Class (); |
|
15
|
|
|
|
|
285007
|
|
|
15
|
|
|
|
|
391
|
|
11
|
15
|
|
|
15
|
|
5251
|
use XML::LibXML; |
|
15
|
|
|
|
|
357692
|
|
|
15
|
|
|
|
|
123
|
|
12
|
|
|
|
|
|
|
|
13
|
15
|
|
|
15
|
|
4732
|
use OTRS::OPM::Maker -command; |
|
15
|
|
|
|
|
40
|
|
|
15
|
|
|
|
|
197
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub abstract { |
16
|
1
|
|
|
1
|
1
|
5754
|
return "build package files for OTRS"; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub usage_desc { |
20
|
1
|
|
|
1
|
1
|
1036
|
return "opmbuild build [--version ] [--output ] "; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub opt_spec { |
24
|
|
|
|
|
|
|
return ( |
25
|
1
|
|
|
1
|
1
|
673
|
[ "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
|
9644
|
my ($self, $opt, $args) = @_; |
32
|
|
|
|
|
|
|
|
33
|
8
|
100
|
100
|
|
|
159
|
$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
|
3711
|
my ($self, $opt, $args) = @_; |
43
|
|
|
|
|
|
|
|
44
|
3
|
|
|
|
|
8
|
my $file = $args->[0]; |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
18
|
my $hostname = hostname; |
47
|
3
|
|
|
|
|
230
|
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
|
|
|
|
|
93
|
my $tree = $parser->parse_file( $file ); |
54
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
1408
|
my $sopm_path = Path::Class::File->new( $file ); |
56
|
3
|
|
|
|
|
706
|
my $path = $sopm_path->dir; |
57
|
|
|
|
|
|
|
|
58
|
3
|
|
|
|
|
45
|
my $root_elem = $tree->getDocumentElement; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# retrieve file information |
61
|
3
|
|
|
|
|
33
|
my @files = $root_elem->findnodes( 'Filelist/File' ); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
FILE: |
64
|
3
|
|
|
|
|
244
|
for my $file ( @files ) { |
65
|
6
|
|
|
|
|
37
|
my $name = $file->findvalue( '@Location' ); |
66
|
6
|
|
|
|
|
855
|
my $file_path = Path::Class::File->new( $path, $name ); |
67
|
6
|
|
|
|
|
639
|
my $file_content = $file_path->slurp; |
68
|
6
|
|
|
|
|
1983
|
my $base64 = MIME::Base64::encode( $file_content ); |
69
|
|
|
|
|
|
|
|
70
|
6
|
|
|
|
|
39
|
$file->setAttribute( 'Encode', 'Base64' ); |
71
|
6
|
|
|
|
|
818
|
$file->appendText( $base64 ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
3
|
|
|
|
|
47
|
my $build_date = XML::LibXML::Element->new( 'BuildDate' ); |
75
|
3
|
|
|
|
|
19
|
$build_date->appendText( $timestamp ); |
76
|
|
|
|
|
|
|
|
77
|
3
|
|
|
|
|
12
|
my $build_host = XML::LibXML::Element->new( 'BuildHost' ); |
78
|
3
|
|
|
|
|
13
|
$build_host->appendText( $hostname ); |
79
|
|
|
|
|
|
|
|
80
|
3
|
|
|
|
|
34
|
$root_elem->addChild( $build_date ); |
81
|
3
|
|
|
|
|
20
|
$root_elem->addChild( $build_host ); |
82
|
|
|
|
|
|
|
|
83
|
3
|
|
|
|
|
215
|
my $version = $root_elem->find( 'Version' )->[0]; |
84
|
3
|
100
|
|
|
|
211
|
if ( $opt->{version} ) { |
85
|
1
|
|
|
|
|
9
|
$version->removeChildNodes(); |
86
|
1
|
|
|
|
|
5
|
$version->appendText( $opt->{version} ); |
87
|
|
|
|
|
|
|
} |
88
|
3
|
|
|
|
|
12
|
my $package_name = $root_elem->findvalue( 'Name' ); |
89
|
3
|
|
|
|
|
281
|
my $file_name = sprintf "%s-%s.opm", $package_name, $version->textContent; |
90
|
|
|
|
|
|
|
|
91
|
3
|
|
|
|
|
10
|
my $output_path = $opt->{output}; |
92
|
3
|
100
|
|
|
|
13
|
$output_path = $path if !$output_path; |
93
|
|
|
|
|
|
|
|
94
|
3
|
|
|
|
|
18
|
my $opm_path = Path::Class::File->new( $output_path, $file_name ); |
95
|
3
|
|
|
|
|
246
|
my $fh = $opm_path->openw; |
96
|
3
|
|
|
|
|
678
|
$fh->print( $tree->toString ); |
97
|
|
|
|
|
|
|
|
98
|
3
|
|
|
|
|
1272
|
return $opm_path->stringify; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |