1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
# --
# Copyright (C) 2001-2021 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::Console::Command::Dev::Package::Build;
use strict;
use warnings;
use parent qw(Kernel::System::Console::BaseCommand);
our @ObjectDependencies = (
'Kernel::System::Main',
'Kernel::System::Package',
);
sub Configure {
my ( $Self, %Param ) = @_;
$Self->Description('Create an OTRS package (opm) file from an OTRS package source (sopm) file.');
$Self->AddOption(
Name => 'version',
Description => "Specify the version to be used (overrides version from sopm file).",
Required => 0,
HasValue => 1,
ValueRegex => qr/^\d{1,4}[.]\d{1,4}[.]\d{1,4}$/smx,
);
$Self->AddOption(
Name => 'module-directory',
Description =>
"Specify the directory containing the module sources (otherwise the OTRS home directory will be used).",
Required => 0,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddArgument(
Name => 'source-path',
Description => "Specify the path to an OTRS package source (sopm) file that should be built.",
Required => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddArgument(
Name => 'target-directory',
Description => "Specify the directory where the generated package should be placed.",
Required => 1,
ValueRegex => qr/.*/smx,
);
return;
}
sub PreRun {
my ( $Self, %Param ) = @_;
my $SourcePath = $Self->GetArgument('source-path');
if ( !-r $SourcePath ) {
die "File $SourcePath does not exist / cannot be read.\n";
}
my $TargetDirectory = $Self->GetArgument('target-directory');
if ( !-d $TargetDirectory ) {
die "Directory $TargetDirectory does not exist.\n";
}
my $ModuleDirectory = $Self->GetOption('module-directory');
if ( $ModuleDirectory && !-d $ModuleDirectory ) {
die "Directory $ModuleDirectory does not exist.\n";
}
return;
}
sub Run {
my ( $Self, %Param ) = @_;
$Self->Print("<yellow>Building package...</yellow>\n");
my $FileString;
my $SourcePath = $Self->GetArgument('source-path');
my $ContentRef = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
Location => $SourcePath,
Mode => 'utf8', # optional - binmode|utf8
Result => 'SCALAR', # optional - SCALAR|ARRAY
);
if ( !$ContentRef || ref $ContentRef ne 'SCALAR' ) {
$Self->PrintError("File $SourcePath is empty / could not be read.");
return $Self->ExitCodeError();
}
$FileString = ${$ContentRef};
my %Structure = $Kernel::OM->Get('Kernel::System::Package')->PackageParse(
String => $FileString,
);
# just build it if PackageIsDownloadable flag is enable
if (
defined $Structure{PackageIsDownloadable}
&& !$Structure{PackageIsDownloadable}->{Content}
)
{
$Self->PrintError("Package cannot be built.\n");
return $Self->ExitCodeError();
}
if ( $Self->GetOption('version') ) {
$Structure{Version}->{Content} = $Self->GetOption('version');
}
# build from given package directory, if any (otherwise default to OTRS home)
if ( $Self->GetOption('module-directory') ) {
$Structure{Home} = $Self->GetOption('module-directory');
}
my $Filename = $Structure{Name}->{Content} . '-' . $Structure{Version}->{Content} . '.opm';
my $Content = $Kernel::OM->Get('Kernel::System::Package')->PackageBuild(%Structure);
if ( !$Content ) {
$Self->PrintError("Package build failed.\n");
return $Self->ExitCodeError();
}
my $File = $Kernel::OM->Get('Kernel::System::Main')->FileWrite(
Location => $Self->GetArgument('target-directory') . '/' . $Filename,
Content => \$Content,
Mode => 'utf8', # binmode|utf8
Type => 'Local', # optional - Local|Attachment|MD5
Permission => '644', # unix file permissions
);
if ( !$File ) {
$Self->PrintError("File $File could not be written.\n");
return $Self->ExitCodeError();
}
$Self->Print("<green>Done.</green>\n");
return $Self->ExitCodeOk();
}
# sub PostRun {
# my ( $Self, %Param ) = @_;
#
# # This will be called after Run() (even in case of exceptions). Perform any cleanups here.
#
# return;
# }
1;
|