RewritePath transform allows you to change the name and path of files without affecting their content.
type: RewritePath regex: <string> rewriteTo: <SpEL expression> matchOrFail: <boolean>
For each input file,
RewritePath attempts to match its
path by using the regular expression (regex) defined by the
regex property. If the regex matches,
RewritePath changes the
path of the file to the evaluation result of
rewriteTo is an expression that has access to the overall engine model and to variables defined by capturing groups of the regular expression. Both named capturing groups
(?<example>[a-z]*) and regular index-based capturing groups are supported.
g0 contains the whole match,
g1 contains the first capturing group, and so on.
If the regex doesn’t match, the behavior depends on the
false, which is the default, the file is left untouched.
true, an error occurs. This prevents misconfiguration if you expect all files coming in to match the regex. For more information about typical interactions between
Chain + Include, see the following section, Interaction with Chain and Include.
The default value for
regex is the following regular expression, which provides convenient access to some named capturing groups:
some/deep/nested/file.xml as an example, the preceding regular expression captures:
The default value for
rewriteTo is the expression
#folder + #filename, which doesn’t rewrite paths.
The following moves all files from
type: RewritePath regex: src/main/java/(.*) rewriteTo: "'sub-module/src/main/java' + #g1" # 'sub-module/' + #g0 works too
The following flattens all files found inside the
sub-path directory and its subdirectories, and puts them into the
type: RewritePath regex: sub-path/(.*/)*(?<filename>[^/]+) rewriteTo: "'flattened' + #filename" # 'flattened' + #g2 would work too
The following turns all paths into lowercase:
type: RewritePath rewriteTo: "#g0.toLowerCase()"
It’s common to define pipelines that perform a
Chain of transformations on a subset of files, typically selected by
- include: "**/*.java" - chain: - # do something here - # and then here
If one of the transformations in the chain is a
RewritePath operation, chances are you want the rewrite to apply to all files matched by the
Include. For those typical configurations, you can set the
matchOrFail guard to
true to ensure the
regex you provide indeed matches all files coming in.