line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::RunList; |
6
|
|
|
|
|
|
|
|
7
|
102
|
|
|
102
|
|
8518
|
use v5.12.5; |
|
102
|
|
|
|
|
357
|
|
8
|
102
|
|
|
102
|
|
589
|
use warnings; |
|
102
|
|
|
|
|
454
|
|
|
102
|
|
|
|
|
3089
|
|
9
|
|
|
|
|
|
|
|
10
|
102
|
|
|
102
|
|
541
|
use Rex::Logger; |
|
102
|
|
|
|
|
320
|
|
|
102
|
|
|
|
|
4286
|
|
11
|
102
|
|
|
102
|
|
8877
|
use Rex::TaskList; |
|
102
|
|
|
|
|
223
|
|
|
102
|
|
|
|
|
722
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '1.14.2.3'; # TRIAL VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $INSTANCE; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
28
|
|
|
28
|
0
|
172
|
my ( $class, %args ) = @_; |
19
|
28
|
|
|
|
|
156
|
return bless \%args, $class; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# returns a singleton |
23
|
|
|
|
|
|
|
sub instance { |
24
|
40
|
|
|
40
|
0
|
960
|
my $class = shift; |
25
|
40
|
100
|
|
|
|
239
|
return $INSTANCE if $INSTANCE; |
26
|
28
|
|
|
|
|
146
|
$INSTANCE = $class->new(@_); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub add_task { |
30
|
101
|
|
|
101
|
0
|
309
|
my ( $self, $task_name, $task_args, $task_opts ) = @_; |
31
|
101
|
|
50
|
|
|
286
|
$task_args ||= []; |
32
|
101
|
|
50
|
|
|
324
|
$task_opts ||= {}; |
33
|
101
|
|
|
|
|
268
|
my $task = $self->task_list->get_task($task_name); |
34
|
101
|
|
|
|
|
511
|
$task->set_args(@$task_args); |
35
|
101
|
|
|
|
|
675
|
$task->set_opts(%$task_opts); |
36
|
101
|
|
|
|
|
215
|
push @{ $self->{tasks} }, $task; |
|
101
|
|
|
|
|
500
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub current_index { |
40
|
5
|
|
|
5
|
0
|
18
|
my ($self) = @_; |
41
|
5
|
|
100
|
|
|
52
|
return $self->{current_index} || 0; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub increment_current_index { |
45
|
70
|
|
|
70
|
0
|
838
|
my ($self) = @_; |
46
|
70
|
|
|
|
|
1903
|
return $self->{current_index} += 1; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub current_task { |
50
|
5
|
|
|
5
|
0
|
20
|
my $self = shift; |
51
|
5
|
|
|
|
|
28
|
my $i = $self->current_index; |
52
|
5
|
|
|
|
|
46
|
$self->{tasks}->[$i]; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
39
|
50
|
|
39
|
0
|
148
|
sub tasks { @{ shift->{tasks} || [] } } |
|
39
|
|
|
|
|
235
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub task_list { |
58
|
290
|
|
|
290
|
0
|
513
|
my $self = shift; |
59
|
290
|
100
|
|
|
|
1357
|
return $self->{task_list} if $self->{task_list}; |
60
|
28
|
|
|
|
|
152
|
$self->{task_list} = Rex::TaskList->create; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub run_tasks { |
64
|
29
|
|
|
29
|
0
|
214
|
my ($self) = @_; |
65
|
|
|
|
|
|
|
|
66
|
29
|
|
|
|
|
126
|
for my $task ( $self->tasks ) { |
67
|
71
|
|
|
|
|
692
|
Rex::TaskList->run($task); |
68
|
55
|
|
|
|
|
978
|
$self->increment_current_index; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Parse @ARGV to get tasks, task args, and task opts. Use these values to |
73
|
|
|
|
|
|
|
# generate a list of tasks the user wants to run. |
74
|
|
|
|
|
|
|
sub parse_opts { |
75
|
35
|
|
|
35
|
0
|
442
|
my ( $self, @params ) = @_; |
76
|
|
|
|
|
|
|
|
77
|
35
|
100
|
|
|
|
255
|
return $self->pre_1_4_parse_opts(@params) |
78
|
|
|
|
|
|
|
unless Rex::Config->get_task_chaining_cmdline_args; |
79
|
|
|
|
|
|
|
|
80
|
11
|
|
|
|
|
111
|
while ( my $task_name = shift @params ) { |
81
|
33
|
50
|
|
|
|
114
|
$self->exit_rex($task_name) unless $self->task_list->is_task($task_name); |
82
|
|
|
|
|
|
|
|
83
|
33
|
|
|
|
|
139
|
my @args; |
84
|
|
|
|
|
|
|
my %opts; |
85
|
|
|
|
|
|
|
|
86
|
33
|
|
|
|
|
305
|
while ( my $param = shift @params ) { |
87
|
88
|
100
|
|
|
|
254
|
if ( $self->task_list->is_task($param) ) { |
88
|
22
|
|
|
|
|
128
|
unshift @params, $param; |
89
|
22
|
|
|
|
|
115
|
last; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
66
|
100
|
|
|
|
407
|
if ( $param =~ /^--/ ) { |
93
|
33
|
|
|
|
|
189
|
my ( $key, $val ) = split /=/, $param, 2; |
94
|
33
|
|
|
|
|
159
|
$key =~ s/^--//; |
95
|
|
|
|
|
|
|
|
96
|
33
|
50
|
|
|
|
269
|
$opts{$key} = defined $val ? $val : 1; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
else { |
99
|
33
|
|
|
|
|
202
|
push @args, $param; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
33
|
|
|
|
|
162
|
$self->add_task( $task_name, \@args, \%opts ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
11
|
|
|
|
|
139
|
return $self; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# this function is to parse the task parameters in a pre 1.4 fashion. |
110
|
|
|
|
|
|
|
# this is used if the feature flag 'no_task_chaining_cmdline_args' or |
111
|
|
|
|
|
|
|
# '< 1.4' is enabled. |
112
|
|
|
|
|
|
|
sub pre_1_4_parse_opts { |
113
|
24
|
|
|
24
|
0
|
106
|
my ( $self, @params ) = @_; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
#### parse task options |
116
|
24
|
|
|
|
|
94
|
my %task_opts; |
117
|
|
|
|
|
|
|
|
118
|
24
|
|
|
|
|
144
|
for my $p (@params) { |
119
|
104
|
|
|
|
|
386
|
my ( $key, $val ) = split( /=/, $p, 2 ); |
120
|
|
|
|
|
|
|
|
121
|
104
|
|
|
|
|
304
|
$key =~ s/^--//; |
122
|
|
|
|
|
|
|
|
123
|
104
|
100
|
|
|
|
230
|
if ( defined $val ) { $task_opts{$key} = $val; next; } |
|
36
|
|
|
|
|
106
|
|
|
36
|
|
|
|
|
72
|
|
124
|
68
|
|
|
|
|
186
|
$task_opts{$key} = 1; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
24
|
|
|
|
|
138
|
for my $task_name (@params) { |
128
|
104
|
100
|
66
|
|
|
734
|
next if $task_name =~ m/^\-\-/ || $task_name =~ m/=/; |
129
|
68
|
50
|
|
|
|
260
|
$self->exit_rex($task_name) unless $self->task_list->is_task($task_name); |
130
|
68
|
|
|
|
|
316
|
$self->add_task( $task_name, [], \%task_opts ); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub exit_rex { |
135
|
0
|
|
|
0
|
0
|
|
my ( $self, $task_name ) = @_; |
136
|
0
|
|
|
|
|
|
my $msg = "Task names are case sensitive "; |
137
|
0
|
|
|
|
|
|
$msg .= "and the module delimiter is a single colon."; |
138
|
0
|
|
|
|
|
|
Rex::Logger::info( "No task named '$task_name' found. $msg", 'error' ); |
139
|
0
|
|
|
|
|
|
Rex::CLI::exit_rex(1); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |