Skip to content

Commit

Permalink
Resolve #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Afanasyev committed Nov 9, 2015
1 parent 5d227e8 commit ed5a457
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 14 deletions.
34 changes: 20 additions & 14 deletions lib/Serge/Engine/Plugin/run_command.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ sub init {
$self->SUPER::init(@_);

$self->merge_schema({
command => 'STRING',
command => {'' => 'LIST',
'*' => 'STRING'
},

if => {
'*' => {
then => {
command => 'STRING',
command => {'' => 'LIST',
'*' => 'STRING'
},
},
},
},
Expand Down Expand Up @@ -69,22 +73,24 @@ sub process_then_block {
my $outfile = $self->{parent}->{engine}->get_full_output_path($file, $lang);
($_, my $outpath, $_) = fileparse($outfile); # this way $outpath will include the trailing delimiter

# substitute %FILE% and target language-based macros
# with the full path to the saved file
my $command = subst_macros($block->{command}, $file, $lang);
foreach my $command (@{$block->{command}}) {
# substitute %FILE% and target language-based macros
# with the full path to the saved file
$command = subst_macros($command, $file, $lang);

# substitute %OUTFILE% macro with the full path to the saved file
$command =~ s/%OUTFILE%/$outfile/sg;
# substitute %OUTPATH% macro with the full directory path
$command =~ s/%OUTPATH%/$outpath/sg;
# substitute %OUTFILE% macro with the full path to the saved file
$command =~ s/%OUTFILE%/$outfile/sg;
# substitute %OUTPATH% macro with the full directory path
$command =~ s/%OUTPATH%/$outpath/sg;

die "After macro substitution, 'command' parameter evaluates to an empty string" if $command eq '';
die "After macro substitution, 'command' parameter evaluates to an empty string" if $command eq '';

print "RUN: $command\n";
system($command);
print "RUN: $command\n";
system($command);

my $error_code = unpack 'c', pack 'C', $? >> 8; # error code
die "Exit code: $error_code\n" if $error_code != 0;
my $error_code = unpack 'c', pack 'C', $? >> 8; # error code
die "Exit code: $error_code\n" if $error_code != 0;
}

return (shift @_)->SUPER::process_then_block(@_);
}
Expand Down
1 change: 1 addition & 0 deletions t/data/engine/run_command/02/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test for 'run_command' plugin, multiple commands
4 changes: 4 additions & 0 deletions t/data/engine/run_command/02/reference-output/database/files
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
files
{
0 1 1 test_job test_namespace strings.xml 0
}
10 changes: 10 additions & 0 deletions t/data/engine/run_command/02/reference-output/database/items
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
items
{
0 1 3 1 1 string1 NO 0
1 2 5 1 2 string2 NO 0
2 3 7 1 3 string3 NO 0
3 4 9 1 4 string4 NO 0
4 5 11 1 5 string5 NO 0
5 6 13 1 6 string6 NO 0
6 7 15 1 7 string7 NO 0
}
19 changes: 19 additions & 0 deletions t/data/engine/run_command/02/reference-output/database/properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
properties
{
0 1 source:1 d030501b7df107a2a9b9e879edfaef02
1 2 hash:1 d030501b7df107a2a9b9e879edfaef02
2 3 size:1 372
3 4 items:1 1,2,3,4,5,6,7
4 5 ts:1:test:count 7
5 6 usn:1:test 15
6 7 ts:1:test 990e8f2847b0df055dd07d06b5d20bdf
7 8 target:1:test_job:test e229a1b45afb237ab67796acc7b3b477
8 9 target:mtime:1:test_job:test 12345678
9 10 source:1:test_job:test d030501b7df107a2a9b9e879edfaef02
10 11 source:ts:1:test_job:test
990e8f2847b0df055dd07d06b5d20bdf
11 12 job-hash:test_namespace:test_job
332e756f0beb9c389a6421ee2ecbae01
12 13 job-plugin:test_namespace:test_job parse_android.
13 14 job-engine:test_namespace:test_job 1.0
}
10 changes: 10 additions & 0 deletions t/data/engine/run_command/02/reference-output/database/strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
strings
{
0 1 2 `Value 1` NO 0
1 2 4 `Value 2` NO 0
2 3 6 `Value 3` NO 0
3 4 8 `Value 4` NO 0
4 5 10 `Value 5` NO 0
5 6 12 `Value 6` NO 0
6 7 14 `Value 7` NO 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
translations
{
0 1 16 1 test `Ṽáļũē 1` NO 0 0
1 2 17 2 test `Ṽáļũē 2` NO 0 0
2 3 18 3 test `Ṽáļũē 3` NO 0 0
3 4 19 4 test `Ṽáļũē 4` NO 0 0
4 5 20 5 test `Ṽáļũē 5` NO 0 0
5 6 21 6 test `Ṽáļũē 6` NO 0 0
6 7 22 7 test `Ṽáļũē 7` NO 0 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="string1">Ṽáļũē 1</string>
<string name="string2">Ṽáļũē 2</string>
<string name="string3">Ṽáļũē 3</string>
<string name="string4">Ṽáļũē 4</string>
<string name="string5">Ṽáļũē 5</string>
<string name="string6">Ṽáļũē 6</string>
<string name="string7">Ṽáļũē 7</string>
</resources>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: test\n"
"Generated-By: Serge 1.0\n"

#. string1
#: File: strings.xml
#: ID: 52b8425aa485a7e3b7a02e1b586f9cef
msgid "Value 1"
msgstr "Ṽáļũē 1"

#. string2
#: File: strings.xml
#: ID: 3fa07f98de1fb810037bfde267c704d1
msgid "Value 2"
msgstr "Ṽáļũē 2"

#. string3
#: File: strings.xml
#: ID: 2e920fe719df0296f38564a3a624f4fa
msgid "Value 3"
msgstr "Ṽáļũē 3"

#. string4
#: File: strings.xml
#: ID: bf5a11014de06a379dcb4fda0faa156d
msgid "Value 4"
msgstr "Ṽáļũē 4"

#. string5
#: File: strings.xml
#: ID: 94ccaa970592240abdb17d60eda93e2f
msgid "Value 5"
msgstr "Ṽáļũē 5"

#. string6
#: File: strings.xml
#: ID: 033f70ded0bee8c0b721dd3a6d87129f
msgid "Value 6"
msgstr "Ṽáļũē 6"

#. string7
#: File: strings.xml
#: ID: cf87626660328addac27a006a2109e53
msgid "Value 7"
msgstr "Ṽáļũē 7"
10 changes: 10 additions & 0 deletions t/data/engine/run_command/02/resources/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="string1">Value 1</string>
<string name="string2">Value 2</string>
<string name="string3">Value 3</string>
<string name="string4">Value 4</string>
<string name="string5">Value 5</string>
<string name="string6">Value 6</string>
<string name="string7">Value 7</string>
</resources>
26 changes: 26 additions & 0 deletions t/data/engine/run_command/02/translate.serge
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
jobs
{
{
@inherit ../../common.serge#job_template
source_match \.xml$

parser
{
plugin parse_android
}

callback_plugins
{
:gzip
{
plugin run_command

data
{
command gzip <%OUTFILE% >%OUTFILE%.gz
command perl ../../cp.pl %OUTFILE%.gz %OUTFILE%.gz.copy
}
}
}
}
}

0 comments on commit ed5a457

Please sign in to comment.