This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-filtering.git
The following commit(s) were added to refs/heads/master by this push:
new 7cb8933 Rewrite the custom filtering token example against the
current API
7cb8933 is described below
commit 7cb89335f8173818b8002c25cf4738af22e5e56b
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sun Nov 1 16:19:44 2026 +0000
Rewrite the custom filtering token example against the current API
---
src/site/markdown/usage.md | 33 +++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/src/site/markdown/usage.md b/src/site/markdown/usage.md
index acae7a5..c6ee08b 100644
--- a/src/site/markdown/usage.md
+++ b/src/site/markdown/usage.md
@@ -48,35 +48,32 @@ Apply filtering on your `List` of resources, see
[Introduction](./index.html) fo
## Add a new filtering token
-You must use the other methods from the `MavenResourcesFiltering` component
and construct your own `List` of `FilterWrappers`. The following example adds
interpolation for the token @ @ using values coming from reflection with the
Maven Project.
+You must use the other methods from the `MavenResourcesFiltering` component
and construct your own `List` of `FilterWrapper`s. The following example adds
interpolation for the token @ @ using values coming from reflection with the
Maven Project.
```java
// Create your FilterWrapper
- FileUtils.FilterWrapper filterWrapper = new FileUtils.FilterWrapper()
- {
- public Reader getReader( Reader reader )
- {
- Interpolator propertiesInterpolator =
- new RegexBasedInterpolator( "\\@", "(.+?)\\@" );
- ValueSource valueSource = new MavenProjectValueSource(
mavenProject,
- true );
- propertiesInterpolator.addValueSource( valueSource );
- return new InterpolatorFilterReader( reader,
- propertiesInterpolator,
- "@", "@" );
+ FilterWrapper filterWrapper = new FilterWrapper() {
+ @Override
+ public Reader getReader(Reader reader) {
+ Interpolator interpolator = new RegexBasedInterpolator("\\@",
"(.+?)\\@");
+ interpolator.addValueSource(
+ new PrefixedObjectValueSource(Arrays.asList("project",
"pom"), mavenProject, true));
+ return new InterpolatorFilterReader(reader, interpolator, "@",
"@");
}
};
// Add the new filterWrapper to your MavenResourcesExecution instance
- mavenResourcesExecution.addFilterWrapper( filterWrapper );
+ mavenResourcesExecution.addFilterWrapper(filterWrapper);
```
-There is a helper method to simplify this. Here's how you would use it to do
what we did above:
+`FilterWrapper` is `org.apache.maven.shared.filtering.FilterWrapper`; the
interpolation classes come from `org.codehaus.plexus.interpolation`.
+
+There is a helper method to simplify this. It takes literal tokens rather than
regular expressions, and an escape string (`null` for none):
```java
- mavenResourcesExecution.addFilerWrapper( new MavenProjectValueSource(
mavenProject,
-
true ),
- "\\@", "(.+?)\\@", "@", "@" );
+ mavenResourcesExecution.addFilerWrapperWithEscaping(
+ new PrefixedObjectValueSource(Arrays.asList("project", "pom"),
mavenProject, true),
+ "@", "@", null, false);
```
**Note:** If `mavenResourcesExecution.useDefaultFilterWrappers` is set to
`true`, the default `FilterWrapper`s will be added first.