2 |
## $Id$ |
## $Id$ |
3 |
## ---------------------------------------------------------------------- |
## ---------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.16 2004/06/21 14:15:06 jonen |
6 |
|
## handle path-modifications in a generic way now(fix for BSD) |
7 |
|
## |
8 |
|
## Revision 1.15 2004/06/16 16:37:59 joko |
9 |
|
## attempt to get things going in a generic way (Linux/FreeBSD/Win32) |
10 |
|
## |
11 |
|
## Revision 1.14 2004/05/12 14:23:31 jonen |
12 |
|
## add comment/code related to PERL5LIB var at different OS's |
13 |
|
## |
14 |
|
## Revision 1.13 2003/12/05 05:02:08 joko |
15 |
|
## + minor update: disabled some unnecessary loggers or changed to debug-level |
16 |
|
## |
17 |
|
## Revision 1.12 2003/06/24 20:59:51 jonen |
18 |
|
## added option 'detach' |
19 |
|
## |
20 |
|
## Revision 1.11 2003/06/23 17:54:32 joko |
21 |
|
## prepared execution of in-process perl-code via eval (not activated yet!) |
22 |
|
## |
23 |
|
## Revision 1.10 2003/05/13 07:56:12 joko |
24 |
|
## enhanced: *hierarchical* containers for context handling |
25 |
|
## fixes: some pre-flight checks |
26 |
|
## new: propagate "end-tag" event to e.g. close containers |
27 |
|
## |
28 |
## Revision 1.9 2003/04/04 17:23:11 joko |
## Revision 1.9 2003/04/04 17:23:11 joko |
29 |
## minor update: debugging output |
## minor update: debugging output |
30 |
## |
## |
69 |
use Hash::Merge qw( merge ); |
use Hash::Merge qw( merge ); |
70 |
use Iterate; |
use Iterate; |
71 |
|
|
72 |
use shortcuts qw( run_cmd ); |
use shortcuts qw( run_cmd RUNNING_IN_HELL RUNNING_IN_HEAVEN ); |
73 |
use Data::Mungle::Code::Ref qw( ref_slot ); |
use Data::Mungle::Code::Ref qw( ref_slot ); |
74 |
use Data::Mungle::Transform::Deep qw( expand deep_copy ); |
use Data::Mungle::Transform::Deep qw( expand deep_copy ); |
75 |
use File::Temp qw/ tempfile tempdir /; |
use File::Temp qw/ tempfile tempdir /; |
76 |
|
|
77 |
|
my $DEBUG = 0; |
78 |
|
|
79 |
sub performTarget { |
sub performTarget { |
80 |
my $self = shift; |
my $self = shift; |
86 |
my $self = shift; |
my $self = shift; |
87 |
my $targetname = shift; |
my $targetname = shift; |
88 |
|
|
89 |
|
# pre-flight checks |
90 |
|
if (!$targetname) { |
91 |
|
$self->log("Target name empty. Please try to specify (e.g.) on the command line.", 'critical'); |
92 |
|
return; |
93 |
|
} |
94 |
|
|
95 |
my $header = ("- " x 12) . " " . $targetname . " " . ("- " x 6); |
my $header = ("- " x 12) . " " . $targetname . " " . ("- " x 6); |
96 |
|
|
97 |
# V1 |
# V1 |
102 |
#$self->log($header, 'notice'); |
#$self->log($header, 'notice'); |
103 |
|
|
104 |
# V3 |
# V3 |
105 |
$self->log("- " x 20, 'info'); |
#$self->log("- " x 20, 'info'); |
106 |
$self->log("Performing Target '$targetname'.", 'notice'); |
$self->log("Performing Target '$targetname'.", 'notice'); |
107 |
|
|
108 |
#exit; |
#exit; |
115 |
|
|
116 |
$self->perform_dependencies($target); |
$self->perform_dependencies($target); |
117 |
$self->perform_details($target); |
$self->perform_details($target); |
118 |
|
|
119 |
|
return 1; |
120 |
|
|
121 |
} |
} |
122 |
|
|
149 |
my $command = $entry->{name}; |
my $command = $entry->{name}; |
150 |
my $args = $entry->{attrib}; |
my $args = $entry->{attrib}; |
151 |
my $content = $entry->{content}; |
my $content = $entry->{content}; |
152 |
$self->perform_command($command, $args, $content); |
$self->perform_command($command, $args, $content, { warn => 1 } ); |
153 |
# check recursiveness |
# check recursiveness |
154 |
if ($entry->{content} && ref $entry->{content}) { |
# new condition: don't recurse if node is flagged to have inline-args (2003-04-17) |
155 |
|
my $has_inline_args = ($entry->{attrib}->{_args} && $entry->{attrib}->{_args} eq 'inline'); |
156 |
|
if ($entry->{content} && ref $entry->{content} && !$has_inline_args) { |
157 |
$self->perform_details($entry); |
$self->perform_details($entry); |
158 |
} |
} |
159 |
|
# new of 2003-05-08 |
160 |
|
$command ||= ''; |
161 |
|
$self->perform_command($command . '_end', undef, undef, { warn => 0 } ); |
162 |
} |
} |
163 |
} |
} |
164 |
|
|
172 |
my $command = shift; |
my $command = shift; |
173 |
my $args_list = shift; |
my $args_list = shift; |
174 |
my $content = shift; |
my $content = shift; |
175 |
|
my $options = shift; |
176 |
|
|
177 |
if (!$command) { |
if (!$command) { |
178 |
$self->log("Command was empty!", 'debug'); |
$self->log("Command was empty!", 'debug') if $DEBUG; |
179 |
return; |
return; |
180 |
} |
} |
181 |
|
|
182 |
# FIXME: make '__PACKAGE__' go one level deeper properly! |
# FIXME: make '__PACKAGE__' go one level deeper properly! |
183 |
$self->log( __PACKAGE__ . "->perform_command: " . $command, 'debug'); |
$self->log( __PACKAGE__ . "->perform_command: " . $command, 'debug') if $DEBUG; |
184 |
|
|
185 |
|
|
186 |
|
# 1. make arguments from list of arguments(?) |
187 |
|
|
188 |
my $args = {}; |
my $args = {}; |
189 |
#print Dumper($args_list); |
#print Dumper($args_list); |
190 |
if ($args_list) { |
if ($args_list) { |
196 |
$args = $args_list; |
$args = $args_list; |
197 |
} |
} |
198 |
} |
} |
|
$command = '_' . $command; |
|
199 |
|
|
200 |
|
|
201 |
# determine container |
# 2. prepare command |
202 |
|
|
203 |
|
# default setting for internal rap commands |
204 |
|
my $method_prefix_default = '_'; |
205 |
|
# setting from property database |
206 |
|
my $method_prefix_setting = $self->get_property('core.method_prefix'); |
207 |
|
#print "setting: ", $method_prefix_setting, "\n"; |
208 |
|
my $prefix = $method_prefix_setting; |
209 |
|
if (not defined $prefix) { |
210 |
|
$prefix = $method_prefix_default; |
211 |
|
} |
212 |
|
$command = $prefix . $command; |
213 |
|
|
214 |
|
|
215 |
|
# 3. determine container |
216 |
my $container; # = $self->getInstance(); |
my $container; # = $self->getInstance(); |
217 |
|
#$container ||= $self->getInstance(); |
218 |
$container ||= $self; |
$container ||= $self; |
219 |
|
|
220 |
|
# 4. run method |
221 |
if ($container->can($command)) { |
if ($container->can($command)) { |
222 |
$container->$command($args, $content); |
$container->$command($args, $content); |
223 |
} else { |
} else { |
224 |
$self->log("Command '$command' not implemented.", "warning"); |
my $level = "debug"; |
225 |
|
$level = "warning" if $options->{warn}; |
226 |
|
$self->log("Command '$command' not implemented.", $level) if $DEBUG; |
227 |
} |
} |
228 |
|
|
229 |
} |
} |
287 |
|
|
288 |
$self->log("set-name: $name"); |
$self->log("set-name: $name"); |
289 |
|
|
290 |
|
#print Dumper($name, $value, '.'); |
291 |
|
|
292 |
# fill property slot with given value |
# fill property slot with given value |
293 |
if ($value) { |
# fix (2003-04-17): always do fill if value is *defined*!!! |
294 |
|
if (defined $value) { |
295 |
ref_slot($self, $name, $value, '.'); |
ref_slot($self, $name, $value, '.'); |
296 |
} |
} |
297 |
|
|
350 |
|
|
351 |
$name = '__rap.properties.' . $name; |
$name = '__rap.properties.' . $name; |
352 |
|
|
353 |
$self->log("get-name: $name"); |
$self->log("get-name: $name") if $DEBUG; |
354 |
|
|
355 |
# get property slot and return value |
# get property slot and return value |
356 |
$result = ref_slot($self, $name, undef, '.'); |
$result = ref_slot($self, $name, undef, '.'); |
381 |
|
|
382 |
delete $opts->{caption}; |
delete $opts->{caption}; |
383 |
delete $opts->{async}; |
delete $opts->{async}; |
384 |
|
delete $opts->{detach}; |
385 |
|
|
386 |
#print Dumper($meta); |
#print Dumper($meta); |
387 |
|
|
426 |
#print "command: $cmd", "\n"; |
#print "command: $cmd", "\n"; |
427 |
|
|
428 |
# start process |
# start process |
429 |
# V1: via shortcut |
# 2004-05-11 - seems like only ONE args is valid at PERL5LIB, so we use V2! |
430 |
#$ENV{PERL5LIB} = join(' ', @INC); |
# 2004-06-16 - found out delimiter required for PERL5LIB, reverting back to V1! |
431 |
|
|
432 |
# FIXME!!! what about the other slots of @INC? |
# V1: join all args |
433 |
$ENV{PERL5LIB} = $INC[0]; |
#my $delimiter = ':'; |
434 |
|
#$delimiter = ';' if RUNNING_IN_HELL(); |
435 |
|
#$ENV{PERL5LIB} = join($delimiter, @INC); |
436 |
|
# V2: insert only FIRST arg |
437 |
|
#$ENV{PERL5LIB} = $INC[0]; |
438 |
|
# WARNING: at (free)BSD our var is the SECOND, NOT FIRST!! |
439 |
|
# FIXME!! Do this in an abstract way!! |
440 |
|
#$ENV{PERL5LIB} = $INC[1]; |
441 |
|
# V3: mix V1+V2 (because V1 doesn't fit at freeBSD..) |
442 |
|
if(RUNNING_IN_HEAVEN()) { |
443 |
|
$ENV{PERL5LIB} = $INC[1]; |
444 |
|
} else { |
445 |
|
my $delimiter = ':'; |
446 |
|
$delimiter = ';' if RUNNING_IN_HELL(); |
447 |
|
$ENV{PERL5LIB} = join($delimiter, @INC); |
448 |
|
} |
449 |
|
|
450 |
#print Dumper(%ENV); |
#print Dumper(%ENV); |
451 |
|
|
457 |
# V1.b - enhanced: variable local method |
# V1.b - enhanced: variable local method |
458 |
$meta->{caption} ||= ''; |
$meta->{caption} ||= ''; |
459 |
$meta->{async} ||= 0; |
$meta->{async} ||= 0; |
460 |
my $evalstr = "run_cmd('$cmd', '$meta->{caption}', { async => $meta->{async} });"; |
$meta->{detach} ||= 0; |
461 |
|
# new of 2003-05-08: USE_PATH! |
462 |
|
$meta->{USE_PATH} ||= 0; |
463 |
|
my $evalstr = "run_cmd('$cmd', '$meta->{caption}', { async => $meta->{async}, detach => $meta->{detach}, USE_PATH => $meta->{USE_PATH} });"; |
464 |
eval($evalstr); |
eval($evalstr); |
465 |
#my $res = do "$cmd"; |
#my $res = do "$cmd"; |
466 |
#print $res, "\n" if $res; |
#print $res, "\n" if $res; |
515 |
|
|
516 |
} elsif ($args->{language} eq 'bash') { |
} elsif ($args->{language} eq 'bash') { |
517 |
$self->log("FIXME: - - - - - -- - - -- BASH - - - - - - - -- - ", 'error'); |
$self->log("FIXME: - - - - - -- - - -- BASH - - - - - - - -- - ", 'error'); |
518 |
|
|
519 |
|
} elsif ($args->{language} eq 'perl') { |
520 |
|
|
521 |
|
# reporting |
522 |
|
#$self->log("Executing some arbitrary unsigned code (probably unsafe). [language=$args->{language}]", 'info'); |
523 |
|
#$self->log("\n<code>\n$code\n</code>", 'info'); |
524 |
|
|
525 |
|
# do it |
526 |
|
#eval($code); |
527 |
|
#$self->log("\n<code>\n$code\n</code>", 'error') if $@; |
528 |
|
|
529 |
} else { |
} else { |
530 |
$self->log("FIXME: Script language '$args->{language}' not implemented.", 'error'); |
$self->log("FIXME: Script language '$args->{language}' not implemented.", 'error'); |