summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/support/arara/chapters/concepts.tex
blob: acd96f0fe185cd9cabaab241566cf13c666848ba (plain)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
% !TeX root = ../arara-manual.tex
\chapter{Important concepts}
\label{chap:importantconcepts}

Time for our first proper contact with \arara! I must stress that is very important to understand a few concepts in which \arara\ relies before we proceed to the usage itself. Do not worry, these concepts are easy to follow, yet they are vital to the comprehension of the application and the logic behind it.

\section{Rules}
\label{sec:rule}

A \emph{rule} is a formal description of how \arara\ handles a certain task. For instance, if we want to use \rbox{pdflatex} with our tool, we should have a rule for that. Directives are mapped to rules, so a call to a non-existent rule \rbox{foo}, for instance, will indeed raise an error:

\begin{codebox}{Terminal}{teal}{\icnote}{white}
  __ _ _ __ __ _ _ __ __ _ 
 / _` | '__/ _` | '__/ _` |
| (_| | | | (_| | | | (_| |
 \__,_|_|  \__,_|_|  \__,_|

Processing 'doc1.tex' (size: 83 B, last modified: 05/03/2018
12:10:33), please wait.

I could not find a rule named 'foo' in the provided rule paths.
Perhaps a misspelled word? I was looking for a file named
'foo.yaml' in the following paths in order of priority:
(/opt/paulo/arara/rules)

Total: 0.09 seconds
\end{codebox}

Once a rule is defined, \arara\ automatically provides an access layer to that rule through directives in the source code, a concept to be formally introduced later on, in Section~\ref{sec:directives}. Observe that a directive reflects a particular instance of a rule of the same name (i.e, a \rbox{foo} directive in a certain source code is an instance of the \rbox{foo} rule).

\begin{messagebox}{A note about rules}{attentioncolour}{\icattention}{black}
For version 5.0, we kept the current YAML rule scheme. However, the names of the rules being public are marked as deprecated, as they might change in future versions.
\end{messagebox}

In short, a rule is a plain text file written in the YAML format, described in Chapter~\ref{chap:yaml}, on page~\pageref{chap:yaml}. I opted for this format because back then it was cleaner and more intuitive to use than other markup languages such as XML, besides of course being a data serialization standard for programming languages.

\begin{messagebox}{Animal jokes}{araracolour}{\icok}{white}
As a bonus, the acronym \emph{YAML} rhymes with the word \emph{camel}, so \arara\ is heavily environmentally friendly. Speaking of camels, there is the programming reference as well, since this amusing animal is usually associated with Perl and friends.
\end{messagebox}

The default rules, i.e, the rules shipped with \arara, are placed inside a special subdirectory named \abox[araracolour]{rules/} inside another special directory named \abox[araracolour]{ARARA\_HOME} (the place where our tool is installed). We will learn later on, in Section~\ref{sec:basicstructure}, on page~\pageref{sec:basicstructure}, that we can add an arbitrary number of paths for storing our own rules, in order of priority, so do not worry too much about the location of the default rules, although it is important to understand and acknowledge their existence.

The following list describes the basic structure of an \arara\ rule by presenting the proper elements (or keys, if we consider the proper YAML nomenclature). Observe that elements marked as \rbox[araracolour]{M} are mandatory (i.e, the rule \emph{has} to have them in order to work). Similarly, elements marked as \rbox[araracolour]{O} are optional, so you can safely ignore them when writing a rule for our tool. A key preceded by \rbox{context$\rightarrow$} indicates a context and should be properly defined inside it.

\begin{description}
\item[\describe{M}{!config}] This keyword is mandatory and must be the first line of any \arara\ rule. It denotes the object mapping metadata to be internally used by the tool. Actually, the tool is not too demanding on using it (in fact, you could suppress it entirely and \arara\ will not complain), but it is considered good practice to start all rules with a \abox{!config} keyword regardless.

\item[\describe{M}{identifier}] This key acts as a unique identifier for the rule (as expected). It is highly recommended to use lowercase letters without spaces, accents or punctuation symbols, as good practice (again). As a convention, if you have an identifier named \rbox{pdflatex}, the rule filename must be \rbox{pdflatex.yaml} (like our own instance). Please note that, although \rbox{yml} is known to be a valid YAML extension as well, \arara\ only considers files ending with the \rbox{yaml} extension. This is a deliberate decision.

\begin{codebox}{Example}{teal}{\icnote}{white}
identifier: pdflatex
\end{codebox}

\item[\describe{M}{name}] This key holds the name of the \emph{task} (a rule instantiated through a directive) as a plain string. When running \arara, this value will be displayed in the output enclosed in parentheses.

\begin{codebox}{Example}{teal}{\icnote}{white}
name: PDFLaTeX
\end{codebox}

\item[\describe{O}{authors}] We do love blaming people, so \arara\ features a special key to name the rule authors (if any) so you can write stern electronic communications to them! This key holds a list of strings. If the rule has just one author, add it as the first (and only) element of the list.

\begin{codebox}{Example}{teal}{\icnote}{white}
authors:
- Marco Daniel
- Paulo Cereda
\end{codebox}

\item[\describe{M}{commands}] This key denotes a potential list of commands. From the user perspective, each command is called a \emph{subtask} within a task (rule and directive) context. A task may represent only a single command (a single subtask), as well as a sequence of commands (subtasks). For instance, the \rbox{frontespizio} rule requires at least two commands. So, as a means of normalizing the representation, a task composed of a single command (single subtask) is defined as the only element of the list, as opposed to previous versions of \arara, which had a specific key to hold just one command.

In order to properly set a subtask, the keys used in this specification are defined inside the \rbox{commands$\rightarrow$} context and presented as follows.

\begin{description}
\item[\describecontext{O}{commands}{name}] This key holds the name of the subtask as a plain string. When running \arara, this value will be displayed in the output. Subtask names are displayed after the main task name. By the way, did you notice that this key is entirely optional? That means that a subtask can simply be unnamed, if you decide so. However, such practice is not recommended, as it's always good to have a visual description of what \arara\ is running at the moment, so name your subtasks properly.

\item[\describecontext{M}{commands}{command}] This key holds the action to be performed, typically a system command. The tool offers two types of returned values:

\begin{itemize}[label={--}]
\item A \rbox{Command} object: \arara\ features an approach for handling system commands based on a high level structure with explicit argument parsing named \rbox{Command} (for our curious users, it is a plain Java object). In order to use this approach, we need to rely on orb tags and use a helper method named \mtbox{getCommand} to obtain the desired result. We will detail this method later on, in Section~\ref{sec:commands}, on page~\pageref{sec:commands}. We highly recommend the adoption of this approach for rule writing instead of using plain strings.

\begin{codebox}{Example}{teal}{\icnote}{white}
command: "@{ return getCommand('ls') }"
\end{codebox}

\item A boolean value: it is also possible to exploit the expressive power of the underlying scripting language available in the rule context (see Chapter~\ref{chap:mvel}, on page~\pageref{chap:mvel}, for more details) for writing complex code. In this particular case, since the computation is being done by \arara\ itself and not the underlying operating system, there will not be a command to be executed, so simply return a boolean value -- either an explicit \rbox{true} or \rbox{false} value or a logical expression -- to indicate whether the computation was successful.

\begin{codebox}{Example}{teal}{\icnote}{white}
command: "@{ return 1 == 1 }"
\end{codebox}
\end{itemize}

It is also worth mentioning that \arara\ also supports lists of commands represented as \rbox{Command} objects, boolean values or a mix of them. This is useful if your rule has to decide whether more actions are required in order to accomplish a task. In this case, our tool will take care of the list and execute each element in the specified order.

\begin{codebox}{Example}{teal}{\icnote}{white}
command: "@{ return [ getCommand('ls'), getCommand('ls') ] }"
\end{codebox}

As an example, please refer to the official \rbox{clean} rule for a real scenario where a list of commands is successfully employed: for each provided extension, the rule creates a new cleaning command and adds it to a list of removals to be processed later.

There are at least two variables available in the \abox{command} context and are described as follows (note that MVEL variables and orb tags are discussed in Chapter~\ref{chap:mvel}). A variable will be denoted by \varbox{variable} in this list. For each rule argument (defined later on), there will be a corresponding variable in the \abox{command} context, directly accessed through its unique identifier.

\begin{description}
\item[\varbox{file}] This variable holds the file name, without any path reference, as a plain string. It is usually composed from the base name and the extension. This variable is available since the first release of \arara.

\item[\varbox{reference}] This variable holds the canonical, absolute path representation of the \varbox{file} variable as a \rbox{File} object. This is useful if it's necessary to know the hierarchical structure of a project. Since the reference is a Java object, we can use all methods available in the \rbox{File} class.
\end{description}

\begin{messagebox}{Quote handling}{araracolour}{\icinfo}{white}
\setlength{\parskip}{1em}
The YAML format disallows key values starting with \rbox{@} without proper quoting. This is the reason we had to use double quotes for the value and internally using single quotes for the command string. Also, we could use the other way around, or even using only one type and then escaping them when needed. This is excessively verbose but needed due to the format requirement. Thankfully, \arara\ offers two solutions for removing the quoting verbosity when writing commands.

The first solution is used in previous versions and it still works like a charm in modern days. We need to precede our command with a special keyword \rbox{<arara>} which will be removed afterwards. This solution works on virtually every key in the rule context, so it is a bonus. The new code will look like this:

\begin{codebox}{Example}{teal}{\icnote}{white}
command: <arara> @{ return getCommand('ls') }
\end{codebox}

The second approach is more of a YAML feature rather than a tool exclusive, although we have to do a couple of checks under the hood in order to ensure the correct execution. The idea here is to use the scalar content in folded style, as seen in Section~\ref{sec:yamlscalars}, on page~\pageref{sec:yamlscalars}. The new code will look like this:

\begin{codebox}{Example}{teal}{\icnote}{white}
command: >
  @{
    return getCommand('ls')
  }
\end{codebox}

Mind the indentation, as YAML requires it to properly identify blocks. Please keep in mind that the \rbox{<arara>} keyword is marked as deprecated in version 5.0 and will be removed in future versions of \arara, so it is highly recommended to favour this approach.
\end{messagebox}

\item[\describecontext{O}{commands}{exit}] This key holds a special purpose, as it represents a custom exit status evaluation for the corresponding command. In general, a successful execution has zero as an exit status, but sometimes we end up with tools or situations where we need to override this check for whatever reason. For this purpose, simply write a MVEL expression \emph{without orb tags} as plain string and use the special variable \varbox{value} if you need the actual exit status returned by the command, available at runtime. For example, if the command returns a non-zero value indicating a successful execution, we can write this key as:

\begin{codebox}{Example}{teal}{\icnote}{white}
exit: value > 0
\end{codebox}

If the execution should be marked as successful by \arara\ regardless of the actual exit status, you can simply write \rbox{true} as the key value and this rule will never fail, for obvious reasons.
\end{description}

For instance, consider a full example of the \abox{commands} key, defined with only one command, presented as follows. The hyphen denotes a list element, so mind the indentation for correctly specifying the component keys. Also, note that, in this case, the \abox{exit} key was completely optional, as it does the default checking, and it was included for didactic purposes.

\begin{codebox}{Example}{teal}{\icnote}{white}
commands:
- name: The PDFLaTeX engine
  command: >
    @{
      return getCommand('pdflatex', file)
    }
  exit: value == 0
\end{codebox}

\item[\describe{M}{arguments}] This key holds a list of arguments for the current rule, if any. The arguments specified in this list will be available to the user later on for potential completion through directives. Once instantiated, they will become proper variables in the \abox{command} contexts. This key is mandatory, so even if your rule does not have arguments, you need to specify a list regardless. In this case, use the empty list notation:

\begin{codebox}{Example}{teal}{\icnote}{white}
arguments: []
\end{codebox}

In order to properly set an argument, the keys used in this specification are defined inside the \rbox{arguments$\rightarrow$} context and presented as follows.

\begin{description}
\item[\describecontext{M}{arguments}{identifier}] This key acts as a unique identifier for the argument. It is highly recommended to use lowercase letters without spaces, accents or punctuation symbols, as a good practice. This key will be used later on to set the corresponding value in the directive context.

\begin{codebox}{Example}{teal}{\icnote}{white}
identifier: shell
\end{codebox}

It is important to mention that not all names are valid as argument identifiers. \arara\ has restrictions on three names, described as follows, which cannot be used.

\begin{messagebox}{Reserved names for rule arguments}{attentioncolour}{\icattention}{black}
Our tool has three names reserved for internal use: \abox{file}, \abox{files}, and \abox{reference}. Do not use them as argument identifiers!
\end{messagebox}

\item[\describecontext{O}{arguments}{flag}] This key holds a plain string and is evaluated when the corresponding argument is defined in the directive context.  After being evaluated, the result will be stored in a variable of the same name to be later accessed in the \abox{command} context. In the scenario where the argument is not defined in the directive, the variable will hold an empty string.

\begin{codebox}{Example}{teal}{\icnote}{white}
flag: >
  @{
      isTrue(parameters.shell, '--shell-escape',
             '--no-shell-escape')
  }
\end{codebox}

There are three variables available in the \abox{flag} context, described as follows. Note that are also several helper methods available in the rule context (for instance, \mtbox{isTrue} presented in the previous example) which provide interesting features for rule writing. They are detailed later on, in Chapter~\ref{chap:methods}, on page~\pageref{chap:methods}.

\begin{description}
\item[\varbox{parameters}] This variable holds a map of directive parameters available at runtime. For each argument identifier listed in the \abox{arguments} list in the rule context, there will be an entry in this variable. This is useful to get the actual values provided during execution and take proper actions. If a parameter is not set in the directive context, the reference will still exist in the map, but it will be mapped to an empty string.

\item[\varbox{file}] This variable holds the file name, without any path reference, as a plain string. It is usually composed from the base name and the extension. This variable is available since the first release of \arara.

\item[\varbox{reference}] This variable holds the canonical, absolute path representation of the \varbox{file} variable as a \rbox{File} object. This is useful if it's necessary to know the hierarchical structure of a project. Since the reference is a Java object, we can use all methods available in the \rbox{File} class.
\end{description}

In the previous example, observe that the MVEL expression defined in the \abox{flag} key checks if the user provided an affirmative value regarding shell escape, through comparing \varbox{parameters.shell} with a set of predefined affirmative values. In any case, the corresponding command flag is defined as result of such evaluation.

\item[\describecontext{O}{arguments}{default}] As default behaviour, if a parameter is not set in the directive context, the reference will be mapped to an empty string. This key exists for the exact purpose of overriding such behaviour.

\begin{codebox}{Example}{teal}{\icnote}{white}
default: ''
\end{codebox}

There are three variables available in the \abox{default} context, described as follows. Note that are also several helper methods available in the rule context (for instance, \mtbox{isTrue} presented in the previous example) which provide interesting features for rule writing. They are detailed later on, in Chapter~\ref{chap:methods}, on page~\pageref{chap:methods}.

\begin{description}
\item[\varbox{parameters}] This variable holds a map of directive parameters available at runtime. For each argument identifier listed in the \abox{arguments} list in the rule context, there will be an entry in this variable. This is useful to get the actual values provided during execution and take proper actions. If a parameter is not set in the directive context, the reference will still exist in the map, but it will be mapped to an empty string.

\item[\varbox{file}] This variable holds the file name, without any path reference, as a plain string. It is usually composed from the base name and the extension. This variable is available since the first release of \arara.

\item[\varbox{reference}] This variable holds the canonical, absolute path representation of the \varbox{file} variable as a \rbox{File} object. This is useful if it's necessary to know the hierarchical structure of a project. Since the reference is a Java object, we can use all methods available in the \rbox{File} class.
\end{description}

\item[\describecontext{O}{arguments}{required}] There might be certain scenarios in which a rule could make use of required arguments (for instance, a copy operation in which source and target must be provided). The \abox{required} key acts as a boolean switch to indicate whether the corresponding argument should be mandatory. In this case, set the key value to \rbox{true} and the argument becomes required. Later on at runtime, \arara\ will throw an error if a required parameter is missing in the directive.

\begin{codebox}{Example}{teal}{\icnote}{white}
required: false
\end{codebox}

Note that setting the \abox{required} key value to \rbox{false} corresponds to omitting the key completely in the rule context, which resorts to the default behaviour (i.e, all arguments are optional).
\end{description}

\begin{messagebox}{Note on argument keys}{attentioncolour}{\icattention}{black}
As seen previously, both \abox{flag} and \abox{default} are marked as optional, but at least one of them must occur in the argument specification, otherwise \arara\ will throw an error, as it makes no sense to have no argument handling at all. Please make sure to specify at least one of them for a consistent behaviour!
\end{messagebox}

For instance, consider a full example of the \abox{arguments} key, defined with only one argument, presented as follows. The hyphen denotes a list element, so mind the indentation for correctly specifying the component keys. Also, note that, in this case, keys \abox{required} and \abox{default} were completely optional, and they were included for didactic purposes.

\begin{codebox}{Example}{teal}{\icnote}{white}
arguments:
- identifier: shell
  flag: >
    @{
        isTrue(parameters.shell,
               '--shell-escape',
               '--no-shell-escape')
    }
  required: false
  default: ''
\end{codebox}
\end{description}

This is the rule structure in the YAML format used by \arara. Keep in mind that all subtasks in a rule are checked against their corresponding exit status. If an abnormal execution is detected, the tool will instantly halt and the rule will fail. Even \arara\ itself will return an exit code different than zero when this situation happens (detailed in Chapter~\ref{chap:commandline}, on page~\pageref{chap:commandline}).

\section{Directives}
\label{sec:directives}

A \emph{directive} is a special comment inserted in the source file in which you indicate how \arara\ should behave. You can insert as many directives as you want and in any position of the file. The tool will read the whole file and extract the directives.

There are two types of directives in \arara\ which determine the way the corresponding rules will be instantiated. They are listed as follows. Note that directives are always preceded by the \rbox{arara:} pattern.

\begin{description}
\item[empty directive] This type of directive has already been mentioned in Chapter~\ref{chap:introduction}, on page~\pageref{chap:introduction}, it has only the rule name (which refers to the \abox{identifier} key from the rule of the same name). All rule arguments are mapped to empty strings, except the ones with \abox{default} values.

\begin{codebox}{Empty directive}{teal}{\icnote}{white}
% arara: pdflatex
\end{codebox}

\item[parametrized directive] This type of directive also has the rule name (which refers to the \abox{identifier} key from the rule of the same name), and also contains a map of parameters in order to provide additional information to the corresponding rule. This map is defined in the YAML format, based on the inline style.

\begin{codebox}{Parametrized directive}{teal}{\icnote}{white}
% arara: pdflatex: { shell: yes }
\end{codebox}

Observe that \arara\ relies on named parameters, so they are mapped by their corresponding argument identifiers and not by their positions. The syntax for a parameter is described as follows. Please refer to the map definition in Section~\ref{sec:yamlcollections}, on page~\pageref{sec:yamlcollections}.

\begin{codebox}{Parameter syntax}{teal}{\icnote}{white}
key : value
\end{codebox}

Note that virtually any type of data can be used as parameter value, so lists, integers, booleans, sets and other maps are available as well. However, there must be the correct handling of such types in the rule context.
\end{description}

When handling parametrized directives, \arara\ always checks if directive parameters and rule arguments match. If we try to inject a non-existent parameter in a parametrized directive, the tool will raise an error about it:

\begin{codebox}{Terminal}{teal}{\icnote}{white}
  __ _ _ __ __ _ _ __ __ _ 
 / _` | '__/ _` | '__/ _` |
| (_| | | | (_| | | | (_| |
 \__,_|_|  \__,_|_|  \__,_|

Processing 'hello.tex' (size: 103 B, last modified:
05/03/2018 15:40:16), please wait.

I have spotted an error in rule 'pdflatex' located at
'/opt/paulo/arara/rules'. I found these unknown keys
in the directive: (foo). This should be an easy fix,
just remove them from your map.

Total: 0.21 seconds
\end{codebox}

As the message suggests, we need to remove the unknown parameter key from our directive or rewrite the rule in order to include it as an argument. The first option is, of course, easier.

Sometimes, directives can span several columns of a line, particularly the ones with several parameters. We can split a directive into multiple lines by using the \rbox{arara: {-}{-}>} mark (also known as \emph{arrow notation} during development) to each line which should compose the directive. We call it a \emph{multiline directive}. Let us see an example:

\begin{codebox}{Multiline directive}{teal}{\icnote}{white}
% arara: pdflatex: {
% arara: --> shell: yes,
% arara: --> synctex: yes
% arara: --> }
\end{codebox}

It is important to observe that there is no need of them to be in contiguous lines, i.e, provided that the syntax for parametrized directives hold for the line composition, lines can be distributed all over the code. In fact, the log file (when enabled) will contain a list of all line numbers that compose a directive. This feature is discussed later on, in Section~\ref{sec:directiveextraction}, on page~\pageref{sec:directiveextraction}.

\begin{messagebox}{Keep lines together}{araracolour}{\icinfo}{white}
Although it is possible to spread lines of a multiline directive all over the code, it is considered good practice to keep them together for easier reading and editing. In any case, you can always see which lines compose a directive by inspecting the log file.
\end{messagebox}

\arara\ provides logical expressions, written in the MVEL language, and special operators processed at runtime in order to determine whether and how a directive should be processed. This feature is named \emph{directive conditional}, or simply \emph{conditional} as an abbreviation. The following list describes all conditional operators available in the directive context.

\begin{description}
\item[\describeconditional{a priori}{if}] The associated MVEL expression is evaluated beforehand, and the directive is interpreted if, and only if, the result of such evaluation is true. This directive, when the conditional holds true, is executed at most once.

\begin{codebox}{Conditional}{teal}{\icnote}{white}
% arara: pdflatex if missing('pdf') || changed('tex')
\end{codebox}

\item[\describeconditional{a posteriori}{until}] The directive is interpreted the first time, then the associated MVEL expression evaluation is done. While the result holds false, the directive is interpreted again and again. There are no guarantees of proper halting.

\begin{codebox}{Conditional}{teal}{\icnote}{white}
% arara: pdflatex until !found('log', 'undefined references')
\end{codebox}

\item[\describeconditional{a priori}{unless}] Technically an inverted \cdbox{if} conditional, the associated MVEL expression is evaluated beforehand, and the directive is interpreted if, and only if, the result is false. This directive, when the conditional holds false, is executed at most once.

\begin{codebox}{Conditional}{teal}{\icnote}{white}
% arara: pdflatex unless unchanged('tex') && exists('pdf')
\end{codebox}

\item[\describeconditional{a priori}{while}] The associated MVEL expression is evaluated beforehand, the directive is interpreted if, and only if, the result is true, and the process is repeated while the result still holds true. There are no guarantees of proper halting.

\begin{codebox}{Conditional}{teal}{\icnote}{white}
% arara: pdflatex while missing('pdf') ||
% arara: --> found('log', 'undefined references')
\end{codebox}
\end{description}

Several methods are available in the directive context in order to ease the writing of conditionals, such as \mtbox{missing}, \mtbox{changed}, \mtbox{found}, \mtbox{unchanged}, and \mtbox{exists} featured in the previous examples. They will be properly detailed later on, in Section~\ref{sec:files}, on page~\pageref{sec:files}.

\begin{messagebox}{No infinite loops}{araracolour}{\icinfo}{white}
Although there are no conceptual guarantees for proper halting of unbounded loops, we have provided a technical solution for potentially infinite iterations: \arara\ has a predefined maximum number of loops. The default value is set to 10, but it can be overridden either in the configuration file or with a command line flag. We discuss this feature later on, in Sections~\ref{sec:options} and~\ref{sec:basicstructure}, on pages~\pageref{sec:options} and~\pageref{sec:basicstructure}, respectively.
\end{messagebox}

All directives, regardless of their type, are internally mapped with both \abox{file} and \abox{reference} parameters, discussed earlier on, in Section~\ref{sec:coreconcepts}, on page~\pageref{sec:coreconcepts}, as special variables in the rule context. When inspecting the log file, you will find all map keys and values for each extracted directive (actually, there is an entire log section devoted to detailing directives found in the code). This feature is covered in Section~\ref{sec:directivenormalization}, on page~\pageref{sec:directivenormalization}. See, for instance, the report of the directive extraction and normalization process performed by \arara\ when inspecting \rbox{doc2.tex}, available in the log file. Note that timestamps were deliberately removed in order to declutter the output, and line breaks were included in order to easily spot the log entries.

\begin{ncodebox}{Source file}{teal}{\icnote}{white}{doc2.tex}
% arara: pdflatex
% arara: pdflatex: { shell: yes }
\documentclass{article}

\begin{document}
Hello world.
\end{document}
\end{ncodebox}

\begin{codebox}{An excerpt of the log file (directive section)}{teal}{\icnote}{white}
Directive: { identifier: pdflatex, parameters:
{reference=/home/paulo/doc2.tex, file=doc2.tex},
conditional: { NONE }, lines: [1] }

Directive: { identifier: pdflatex, parameters:
{shell=yes, file=doc2.tex, reference=/home/paulo/doc2.tex},
conditional: { NONE }, lines: [2] }
\end{codebox}

The directive context also features another special parameter named \abox{files} which expects a non-empty list of file names as plain string values. For each element of this list, \arara\ will replicate the current directive and point the element being iterated as current \abox{file} and \abox{reference} values (being the latter resolved to a proper absolute, canonical path of the former). See, for instance, the report of the directive extraction and normalization process performed by \arara\ when inspecting \rbox{doc3.tex}, available in the log file.

\begin{ncodebox}{Source file}{teal}{\icnote}{white}{doc3.tex}
% arara: pdflatex: { files: [ doc1.tex, doc2.tex ] }
Hello world.
\bye
\end{ncodebox}

\begin{codebox}{An excerpt of the log file (directive section)}{teal}{\icnote}{white}
Directive: { identifier: pdflatex, parameters:
{reference=/home/paulo/doc1.tex, file=doc1.tex},
conditional: { NONE }, lines: [1] }

Directive: { identifier: pdflatex, parameters:
{reference=/home/paulo/doc2.tex, file=doc2.tex},
conditional: { NONE }, lines: [1] }
\end{codebox}

It is important to observe that, in this case, \rbox{doc3.tex} is a plain \TeX\ file, but \rbox{pdflatex} is actually being called on two \LaTeX\ documents, first \rbox{doc1.tex} and then, at last, \rbox{doc2.tex}.

Even when a directive is interpreted with a file other than the one being processed by \arara\ (through the magic of the \abox{files} parameter), it is possible to use helper methods in the rule context to get access to the original file and reference. Such methods are detailed later on, in Section~\ref{sec:files}, on page~\pageref{sec:files}.

\section{Important changes in version 5.0}
\label{sec:migrationguide}

\begin{messagebox}{A note to users}{araracolour}{\icattention}{white}
If this is your first time using \arara\ or you do not have custom rules in the old format, you can safely ignore this section. All rules shipped with our tool are already written in the new format.
\end{messagebox}

\begin{messagebox}{Removal of triggers}{araracolour}{\icattention}{white}
\arara\ previously had the concept of triggers which allowed to easily trigger events like halting \arara. As of version 5.0, support for triggers has been dropped due to the lack of use cases.

As the only pre-defined trigger has been \rbox{halt} we did not deprecate the ability to halt the application. However, the new mechanism uses the concept of session values (see \autoref{sec:others}).
\end{messagebox}

\begin{messagebox}{Removal of Velocity support}{araracolour}{\icinfo}{white}
\arara\ featured support for the Velocity Template Language. In version 5.0, this support has been removed. We decided in favour of this breaking change to achieve more independence from third-party modules and to avoid being stuck at version~1.7 for compatibility reasons.

Due to this change, \arara\ does not ship support for any templating language at the moment. If you are interested in getting a templating language on board, you are welcome to support our efforts to make the inclusion of JVM code on the user-side more pleasant.
\end{messagebox}

\begin{messagebox}{Removal of string-based commands}{araracolour}{\icinfo}{white}
Up to version 5.0 you could simply use

\begin{codebox}{Return statement}{teal}{\icnote}{white}
return "command";
\end{codebox}

\noindent in your rules. This resulted in \arara\ implicitly constructing a command object. As this does not make clear that this command is actually run, we now enforce the usage of

\vspace{1em}

\mdbox{R}{getCommand(List<String> commands)}{Command}

\vspace{1em}

\noindent in the \rbox{return} statement. Hence, the new way of doing the same is (with either single or double quote pairs):

\begin{codebox}{Return statement}{teal}{\icnote}{white}
return getCommand("command");
\end{codebox}
\end{messagebox}

\begin{messagebox}{Methods: removal and change of name}{araracolour}{\icinfo}{white}
The following previously available methods (and repective overloaded variants) have been removed:

\begin{itemize}
\item[\textcolor{warningcolour}{\faClose}] \mdbox{R}{addQuotes(String string)}{String}
\item[\textcolor{warningcolour}{\faClose}] \mdbox{R}{isAIX()}{boolean}
\item[\textcolor{warningcolour}{\faClose}] \mdbox{R}{isIrix()}{boolean}
\item[\textcolor{warningcolour}{\faClose}] \mdbox{R}{isOS2()}{boolean}
\item[\textcolor{warningcolour}{\faClose}] \mdbox{R}{isSolaris()}{boolean}
\item[\textcolor{warningcolour}{\faClose}] \mdbox{R}{getFullBasename(File file)}{String}
\item[\textcolor{warningcolour}{\faClose}] \mdbox{R}{\parbox{0.62\textwidth}{mergeVelocityTemplate(File input,\\\hspace*{1em} File output, Map<String, Object> map)}}{void}
\end{itemize}

The following methods have been renamed:
\begin{itemize}
\item[\textcolor{warningcolour}{\faClose}] \mdbox{R}{(Session.)insert(String key, Object value)}{void}

\vspace{.5em}

\hspace{2cm}\textcolor{teal}{\faArrowDown}

\item[\textcolor{okcolour}{\faCheck}]\mdbox{R}{(Session.)put(String key, Object value)}{void}

\vspace{1em}

\item[\textcolor{warningcolour}{\faClose}] \mdbox{R}{(Session.)exists(String key)}{boolean}

\vspace{.5em}

\hspace{2cm}\textcolor{teal}{\faArrowDown}

\item[\textcolor{okcolour}{\faCheck}] \mdbox{R}{(Session.)contains(String key)}{boolean}

\vspace{1em}

\item[\textcolor{warningcolour}{\faClose}] \mdbox{R}{(Session.)obtain(String key)}{Object}

\vspace{.5em}

\hspace{2cm}\textcolor{teal}{\faArrowDown}

\item[\textcolor{okcolour}{\faCheck}]\mdbox{R}{(Session.)get(String key)}{Object}
\end{itemize}
\end{messagebox}

\begin{messagebox}{Support for multiple files}{araracolour}{\icinfo}{white}
From version 5.0 on, \arara\ is able to compile multiple files at once by providing multiple files as arguments. Please note that they should reside in the same working directory. Every other kind of compilation of multiple files is restricted by the mechanisms of the running programs. See \autoref{chap:commandline} for details.
\end{messagebox}

\begin{messagebox}{Support for changing the working directory}{araracolour}{\icinfo}{white}
A common problem when compiling \TeX\ files are specialties of \TeX\ engines looking for files. Usually, you should call an engine from the directory where the target file is located. \arara\ had the same restriction in that case. Now you can instruct \arara\ to operate from another directory lifting that constraint. See \autoref{chap:commandline} for details.
\end{messagebox}

This section pretty much covered the basics of the changes to this version. Of course, it is highly advisable to make use of the new features available in \arara\ 5.0 for achieving better results. If you need any help, please do not hesitate to contact us. See Section~\ref{sec:support}, on page~\pageref{sec:support}, for more details on how to get help.