You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2024/06/17 17:53:31 UTC

(jackrabbit-filevault-package-maven-plugin) 01/01: JCRVLT-757 Introduce filtering extension SPI

This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch feature/support-interpolation-processors
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault-package-maven-plugin.git

commit 06fc4ddeecc9ec6a5bc06a3471e5eebbfc23076e
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Mon Jun 17 19:53:20 2024 +0200

    JCRVLT-757 Introduce filtering extension SPI
    
    Add filtering feature for escaping FileVault DocView XML Attribute
    values
---
 pom.xml                                            |   2 +-
 .../maven/packaging/InterpolationProcessor.java    |  29 ++
 .../maven/packaging/impl/DefaultFilterWrapper.java | 314 +++++++++++++++++++++
 .../DocviewEscapingInterpolationProcessor.java     |  65 +++++
 .../filevault/maven/packaging/mojo/VaultMojo.java  |  27 +-
 src/site/markdown/filtering.md                     |  21 ++
 .../DocviewEscapingInterpolationProcessorTest.java |  40 +++
 .../filevault/maven/packaging/it/FilteringIT.java  |  32 ++-
 .../simple-filter/expected-files.txt               |  24 --
 .../jcr_root/apps/bar/escaping/.content.xml        |   4 +
 10 files changed, 517 insertions(+), 41 deletions(-)

diff --git a/pom.xml b/pom.xml
index 049ee12..dc30f38 100644
--- a/pom.xml
+++ b/pom.xml
@@ -32,7 +32,7 @@
     <!-- ====================================================================== -->
     <groupId>org.apache.jackrabbit</groupId>
     <artifactId>filevault-package-maven-plugin</artifactId>
-    <version>1.3.7-SNAPSHOT</version>
+    <version>1.4.0-SNAPSHOT</version>
     <packaging>maven-plugin</packaging>
 
     <name>Apache Jackrabbit FileVault - Package Maven Plugin</name>
diff --git a/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/InterpolationProcessor.java b/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/InterpolationProcessor.java
new file mode 100644
index 0000000..98da66e
--- /dev/null
+++ b/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/InterpolationProcessor.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.maven.packaging;
+
+import org.codehaus.plexus.interpolation.InterpolationPostProcessor;
+import org.codehaus.plexus.interpolation.Interpolator;
+import org.codehaus.plexus.interpolation.ValueSource;
+
+/**
+ * Allows to customize the {@link Interpolator} used for <a href="https://jackrabbit.apache.org/filevault-package-maven-plugin/filtering.html">resource filtering purposes</a>.
+ * Just aggregates both {@link ValueSource} and {@link InterpolationPostProcessor}
+ */
+public interface InterpolationProcessor extends ValueSource, InterpolationPostProcessor {
+
+}
diff --git a/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/impl/DefaultFilterWrapper.java b/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/impl/DefaultFilterWrapper.java
new file mode 100644
index 0000000..7e9d91a
--- /dev/null
+++ b/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/impl/DefaultFilterWrapper.java
@@ -0,0 +1,314 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.maven.packaging.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.jackrabbit.filevault.maven.packaging.InterpolationProcessor;
+import org.apache.jackrabbit.filevault.maven.packaging.impl.extensions.DocviewEscapingInterpolationProcessor;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.shared.filtering.AbstractMavenFilteringRequest;
+import org.apache.maven.shared.filtering.DefaultMavenFileFilter;
+import org.apache.maven.shared.filtering.FilterWrapper;
+import org.apache.maven.shared.filtering.FilteringUtils;
+import org.apache.maven.shared.filtering.MavenFilteringException;
+import org.apache.maven.shared.filtering.MultiDelimiterInterpolatorFilterReaderLineEnding;
+import org.apache.maven.shared.filtering.PropertyUtils;
+import org.codehaus.plexus.interpolation.Interpolator;
+import org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor;
+import org.codehaus.plexus.interpolation.PrefixedObjectValueSource;
+import org.codehaus.plexus.interpolation.PropertiesBasedValueSource;
+import org.codehaus.plexus.interpolation.RecursionInterceptor;
+import org.codehaus.plexus.interpolation.SimpleRecursionInterceptor;
+import org.codehaus.plexus.interpolation.SingleResponseValueSource;
+import org.codehaus.plexus.interpolation.ValueSource;
+import org.codehaus.plexus.interpolation.multi.MultiDelimiterStringSearchInterpolator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** 
+ * Mostly a copy from
+ * <a href="https://github.com/apache/maven-filtering/blob/9d528d0871d93e317ae21a4b6922cd795502364c/src/main/java/org/apache/maven/shared/filtering/BaseFilter.java#L46">BaseFilter</a>.
+ * Necessary due to <a href="https://issues.apache.org/jira/browse/MSHARED-1412">MSHARED-1412</a> 
+ * Allows to customize the underlying {@link Interpolator}, otherwise identical to the default filtering returned from {@link DefaultMavenFileFilter#getDefaultFilterWrappers(AbstractMavenFilteringRequest)}
+ */
+public class DefaultFilterWrapper extends FilterWrapper {
+
+    private static final Logger logger = LoggerFactory.getLogger(DefaultFilterWrapper.class);
+
+    public static FilterWrapper createDefaultFilterWrapperWithInterpolationProcessors(final AbstractMavenFilteringRequest request, Set<InterpolationProcessor> interpolationProcessors) throws MavenFilteringException {
+        // copy of
+        // https://github.com/apache/maven-filtering/blob/9d528d0871d93e317ae21a4b6922cd795502364c/src/main/java/org/apache/maven/shared/filtering/BaseFilter.java#L74C56-L74C100
+        // backup values
+        boolean supportMultiLineFiltering = request.isSupportMultiLineFiltering();
+
+        request.setSupportMultiLineFiltering(supportMultiLineFiltering);
+
+        // Here we build some properties which will be used to read some properties files
+        // to interpolate the expression ${ } in this properties file
+
+        // Take a copy of filterProperties to ensure that evaluated filterTokens are not propagated
+        // to subsequent filter files. Note: this replicates current behaviour and seems to make sense.
+
+        final Properties baseProps = new Properties();
+
+        // Project properties
+        if (request.getMavenProject() != null) {
+            baseProps.putAll(
+                    request.getMavenProject().getProperties() == null
+                            ? Collections.emptyMap()
+                            : request.getMavenProject().getProperties());
+        }
+        // TODO this is NPE free but do we consider this as normal
+        // or do we have to throw an MavenFilteringException with mavenSession cannot be null
+        //
+        // khmarbaise: 2016-05-21:
+        // If we throw an MavenFilteringException tests will fail which is
+        // caused by for example:
+        // void copyFile( File from, final File to, boolean filtering, List<FileUtils.FilterWrapper> filterWrappers,
+        // String encoding )
+        // in MavenFileFilter interface where no MavenSession is given.
+        // So changing here to throw a MavenFilteringException would make
+        // it necessary to change the interface or we need to find a better solution.
+        //
+        if (request.getMavenSession() != null) {
+            // User properties have precedence over system properties
+            putAll(baseProps, request.getMavenSession().getSystemProperties());
+            putAll(baseProps, request.getMavenSession().getUserProperties());
+        }
+
+        // now we build properties to use for resources interpolation
+
+        final Properties filterProperties = new Properties();
+
+        File basedir = request.getMavenProject() != null ? request.getMavenProject().getBasedir() : new File(".");
+
+        loadProperties(filterProperties, basedir, request.getFileFilters(), baseProps);
+        if (filterProperties.isEmpty()) {
+            putAll(filterProperties, baseProps);
+        }
+
+        if (request.getMavenProject() != null) {
+            if (request.isInjectProjectBuildFilters()) {
+                List<String> buildFilters = new ArrayList<>(request.getMavenProject().getBuild().getFilters());
+
+                // JDK-8015656: (coll) unexpected NPE from removeAll
+                if (request.getFileFilters() != null) {
+                    buildFilters.removeAll(request.getFileFilters());
+                }
+
+                loadProperties(filterProperties, basedir, buildFilters, baseProps);
+            }
+
+            // Project properties
+            filterProperties.putAll(
+                    request.getMavenProject().getProperties() == null
+                            ? Collections.emptyMap()
+                            : request.getMavenProject().getProperties());
+        }
+        if (request.getMavenSession() != null) {
+            // User properties have precedence over system properties
+            putAll(filterProperties, request.getMavenSession().getSystemProperties());
+            putAll(filterProperties, request.getMavenSession().getUserProperties());
+        }
+
+        if (request.getAdditionalProperties() != null) {
+            // additional properties wins
+            putAll(filterProperties, request.getAdditionalProperties());
+        }
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("properties used:");
+            for (String s : new TreeSet<>(filterProperties.stringPropertyNames())) {
+                logger.debug(s + ": " + filterProperties.getProperty(s));
+            }
+        }
+
+        final ValueSource propertiesValueSource = new PropertiesBasedValueSource(filterProperties);
+
+        FilterWrapper wrapper = new DefaultFilterWrapper(
+                request.getDelimiters(),
+                request.getMavenProject(),
+                request.getMavenSession(),
+                propertiesValueSource,
+                request.getProjectStartExpressions(),
+                request.getEscapeString(),
+                request.isEscapeWindowsPaths(),
+                request.isSupportMultiLineFiltering(),
+                interpolationProcessors);
+
+        return wrapper;
+    }
+
+    private static void putAll(Properties filterProperties, Properties request) {
+        synchronized (request) {
+            filterProperties.putAll(request);
+        }
+    }
+
+    /** default visibility only for testing reason ! */
+    private static void loadProperties(
+            Properties filterProperties, File basedir, List<String> propertiesFilePaths, Properties baseProps)
+            throws MavenFilteringException {
+        if (propertiesFilePaths != null) {
+            Properties workProperties = new Properties();
+            putAll(workProperties, baseProps);
+
+            for (String filterFile : propertiesFilePaths) {
+                if (filterFile == null || filterFile.trim().isEmpty()) {
+                    // skip empty file name
+                    continue;
+                }
+                try {
+                    File propFile = FilteringUtils.resolveFile(basedir, filterFile);
+                    Properties properties = PropertyUtils.loadPropertyFile(propFile, workProperties, logger);
+                    putAll(filterProperties, properties);
+                    putAll(workProperties, properties);
+                } catch (IOException e) {
+                    throw new MavenFilteringException("Error loading property file '" + filterFile + "'", e);
+                }
+            }
+        }
+    }
+
+    private LinkedHashSet<String> delimiters;
+
+    private MavenProject project;
+
+    private ValueSource propertiesValueSource;
+
+    private List<String> projectStartExpressions;
+
+    private String escapeString;
+
+    private boolean escapeWindowsPaths;
+
+    private final MavenSession mavenSession;
+
+    private boolean supportMultiLineFiltering;
+
+    private final Set<InterpolationProcessor> interpolationProcessors;
+
+    DefaultFilterWrapper(
+            LinkedHashSet<String> delimiters,
+            MavenProject project,
+            MavenSession mavenSession,
+            ValueSource propertiesValueSource,
+            List<String> projectStartExpressions,
+            String escapeString,
+            boolean escapeWindowsPaths,
+            boolean supportMultiLineFiltering, Set<InterpolationProcessor> interpolationProcessors) {
+        super();
+        this.delimiters = delimiters;
+        this.project = project;
+        this.mavenSession = mavenSession;
+        this.propertiesValueSource = propertiesValueSource;
+        this.projectStartExpressions = projectStartExpressions;
+        this.escapeString = escapeString;
+        this.escapeWindowsPaths = escapeWindowsPaths;
+        this.supportMultiLineFiltering = supportMultiLineFiltering;
+        this.interpolationProcessors = new HashSet<>(interpolationProcessors);
+    }
+
+    @Override
+    public Reader getReader(Reader reader) {
+        Interpolator interpolator = createInterpolator(
+                delimiters,
+                projectStartExpressions,
+                propertiesValueSource,
+                project,
+                mavenSession,
+                escapeString,
+                escapeWindowsPaths);
+
+        customizeInterpolator(interpolator);
+
+        MultiDelimiterInterpolatorFilterReaderLineEnding filterReader = new MultiDelimiterInterpolatorFilterReaderLineEnding(
+                reader, interpolator, supportMultiLineFiltering);
+
+        final RecursionInterceptor ri;
+        if (projectStartExpressions != null && !projectStartExpressions.isEmpty()) {
+            ri = new PrefixAwareRecursionInterceptor(projectStartExpressions, true);
+        } else {
+            ri = new SimpleRecursionInterceptor();
+        }
+
+        filterReader.setRecursionInterceptor(ri);
+        filterReader.setDelimiterSpecs(delimiters);
+
+        filterReader.setInterpolateWithPrefixPattern(false);
+        filterReader.setEscapeString(escapeString);
+
+        return filterReader;
+    }
+
+    private void customizeInterpolator(Interpolator interpolator) {
+        interpolationProcessors.forEach(p -> {
+            interpolator.addPostProcessor(p);
+            interpolator.addValueSource(p);
+        });
+    }
+
+    private Interpolator createInterpolator(
+            LinkedHashSet<String> delimiters,
+            List<String> projectStartExpressions,
+            ValueSource propertiesValueSource,
+            MavenProject project,
+            MavenSession mavenSession,
+            String escapeString,
+            boolean escapeWindowsPaths) {
+        MultiDelimiterStringSearchInterpolator interpolator = new MultiDelimiterStringSearchInterpolator();
+        interpolator.setDelimiterSpecs(delimiters);
+
+        interpolator.addValueSource(propertiesValueSource);
+
+        if (project != null) {
+            interpolator.addValueSource(new PrefixedObjectValueSource(projectStartExpressions, project, true));
+        }
+
+        if (mavenSession != null) {
+            interpolator.addValueSource(new PrefixedObjectValueSource("session", mavenSession));
+
+            final Settings settings = mavenSession.getSettings();
+            if (settings != null) {
+                interpolator.addValueSource(new PrefixedObjectValueSource("settings", settings));
+                interpolator.addValueSource(
+                        new SingleResponseValueSource("localRepository", settings.getLocalRepository()));
+            }
+        }
+
+        interpolator.setEscapeString(escapeString);
+
+        if (escapeWindowsPaths) {
+            interpolator.addPostProcessor(
+                    (expression, value) -> (value instanceof String) ? FilteringUtils.escapeWindowsPath((String) value) : value);
+        }
+        return interpolator;
+    }
+}
diff --git a/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/impl/extensions/DocviewEscapingInterpolationProcessor.java b/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/impl/extensions/DocviewEscapingInterpolationProcessor.java
new file mode 100644
index 0000000..a45abf3
--- /dev/null
+++ b/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/impl/extensions/DocviewEscapingInterpolationProcessor.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.maven.packaging.impl.extensions;
+
+import javax.inject.Named;
+
+import org.apache.jackrabbit.filevault.maven.packaging.InterpolationProcessor;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.util.Text;
+import org.apache.jackrabbit.vault.util.DocViewProperty2;
+import org.codehaus.plexus.interpolation.AbstractValueSource;
+import org.codehaus.plexus.interpolation.StringSearchInterpolator;
+
+/** Enhances the regular filtering with handling {@code vltdocviewattributeescape.} which will automatically escape the interpolated value of
+ * the suffix according to <a href="https://jackrabbit.apache.org/filevault/docview.html#Escaping">FileVault DocView Escaping Rules</a> for using it inside
+ * XML attribute values. */
+@Named()
+public class DocviewEscapingInterpolationProcessor extends AbstractValueSource implements InterpolationProcessor {
+
+    public DocviewEscapingInterpolationProcessor() {
+        super(false);
+    }
+
+    public static final String EXPRESSION_PREFIX = "vltdocviewattributeescape.";
+
+    private static final Name DEFAULT_NAME = NameConstants.JCR_TITLE;
+
+    @Override
+    public Object getValue(String expression) {
+        if (expression.startsWith(EXPRESSION_PREFIX)) {
+            // FIXME: currently the delimiter is hardcoded (https://github.com/codehaus-plexus/plexus-interpolation/issues/76)
+            return StringSearchInterpolator.DEFAULT_START_EXPR + expression.substring(EXPRESSION_PREFIX.length()) +  StringSearchInterpolator.DEFAULT_END_EXPR;
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public Object execute(String expression, Object value) {
+        if (expression.startsWith(EXPRESSION_PREFIX)) {
+            String escapedValue;
+            // use hardcoded name as it doesn't matter here
+            escapedValue = new DocViewProperty2(DEFAULT_NAME, value.toString()).formatValue();
+            // now escape for usage inside XML attributes
+            return Text.encodeIllegalXMLCharacters(escapedValue);
+        }
+        return null;
+    }
+
+}
diff --git a/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/mojo/VaultMojo.java b/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/mojo/VaultMojo.java
index 5f0b657..fdc0ac8 100644
--- a/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/mojo/VaultMojo.java
+++ b/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/mojo/VaultMojo.java
@@ -32,11 +32,16 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Set;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import javax.inject.Inject;
+
 import org.apache.jackrabbit.filevault.maven.packaging.Filters;
+import org.apache.jackrabbit.filevault.maven.packaging.InterpolationProcessor;
 import org.apache.jackrabbit.filevault.maven.packaging.impl.ContentPackageArchiver;
+import org.apache.jackrabbit.filevault.maven.packaging.impl.DefaultFilterWrapper;
 import org.apache.jackrabbit.filevault.maven.packaging.impl.PlexusIoNonExistingDirectoryResource;
 import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
 import org.apache.jackrabbit.vault.fs.config.ConfigurationException;
@@ -57,6 +62,8 @@ import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.ResolutionScope;
 import org.apache.maven.project.MavenProjectHelper;
+import org.apache.maven.shared.filtering.AbstractMavenFilteringRequest;
+import org.apache.maven.shared.filtering.FilterWrapper;
 import org.apache.maven.shared.filtering.MavenFilteringException;
 import org.apache.maven.shared.filtering.MavenResourcesExecution;
 import org.apache.maven.shared.filtering.MavenResourcesFiltering;
@@ -220,6 +227,15 @@ public class VaultMojo extends AbstractSourceAndMetadataPackageMojo {
     @Component(role = MavenResourcesFiltering.class, hint = "default") 
     MavenResourcesFiltering mavenResourcesFiltering;
 
+    /**
+     * {@link Component} annotation does not support <a href="https://github.com/google/guice/wiki/Multibindings#multibinding">multi-binding</a>
+     * therefore using standard JSR330 injection pattern.
+     * 
+     * @see <a href="https://lists.apache.org/thread/xfy3wlfxskqw3kmmyj9zxpcj548ft7k8">Mailing List Issue</a>
+     */
+    @Inject
+    Set<InterpolationProcessor> interpolationProcessors;
+
     @Component
     private MavenProjectHelper projectHelper;
 
@@ -420,11 +436,9 @@ public class VaultMojo extends AbstractSourceAndMetadataPackageMojo {
         return overwrittenFiles;
     }
 
-    protected MavenResourcesExecution setupMavenResourcesExecution() {
+    protected MavenResourcesExecution setupMavenResourcesExecution() throws MavenFilteringException {
         MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
         mavenResourcesExecution.setEncoding(resourceEncoding);
-        mavenResourcesExecution.setEscapeString(escapeString);
-        mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering);
         mavenResourcesExecution.setMavenProject(project);
 
         // if these are NOT set, just use the defaults, which are '${*}' and '@'.
@@ -444,7 +458,10 @@ public class VaultMojo extends AbstractSourceAndMetadataPackageMojo {
         mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering);
         mavenResourcesExecution.setAddDefaultExcludes(addDefaultExcludes);
         mavenResourcesExecution.setOverwrite(true);
-        mavenResourcesExecution.setUseDefaultFilterWrappers(true);
+        // cannot use default filter wrappers due to https://issues.apache.org/jira/browse/MSHARED-1412
+        mavenResourcesExecution.setUseDefaultFilterWrappers(false);
+        // rather use a custom wrapper which allows to customize the interpolator
+        mavenResourcesExecution.addFilterWrapper(DefaultFilterWrapper.createDefaultFilterWrapperWithInterpolationProcessors(mavenResourcesExecution, interpolationProcessors));
         return mavenResourcesExecution;
     }
 
@@ -453,8 +470,8 @@ public class VaultMojo extends AbstractSourceAndMetadataPackageMojo {
     public void execute() throws MojoExecutionException, MojoFailureException {
         final File finalFile = getZipFile(outputDirectory, finalName, classifier);
 
-        MavenResourcesExecution mavenResourcesExecution = setupMavenResourcesExecution();
         try {
+            MavenResourcesExecution mavenResourcesExecution = setupMavenResourcesExecution();
             ContentPackageArchiver contentPackageArchiver = new ContentPackageArchiver();
             contentPackageArchiver.setEncoding(resourceEncoding);
 
diff --git a/src/site/markdown/filtering.md b/src/site/markdown/filtering.md
index 78dea9b..f27a9fe 100644
--- a/src/site/markdown/filtering.md
+++ b/src/site/markdown/filtering.md
@@ -59,3 +59,24 @@ An example configuration which enables filtering on all `.content.xml` files in
 </plugin>
 ```
 
+Filtering Extensions
+-----
+
+Extensions allow to improve the simple placeholder replacement offered by Maven with domain specific features (useful for content packages). All features are opt-in and need to be explicitly enabled with a dedicated expression(-prefix).
+
+### Standard Extensions
+
+The following extensions ship with the ${project.artifactId}
+
+Extension | Description | Expression | Usage Example
+--- | --- | --- | ---
+FileVault DocView XML Attribute Escaping | Escape the interpolated value of the suffix according to [FileVault DocView Escaping Rules](https://jackrabbit.apache.org/filevault/docview.html#Escaping) for using it inside XML attribute values. | `vltdocviewattributeescape.` | test
+
+### Custom Extensions
+
+The filtering may be extended through JSR330 components implementing the interface `org.apache.jackrabbit.filevault.maven.packaging.InterpolationProcessor` which aggregates [`org.codehaus.plexus.interpolation.ValueSource`][codehaus-valuesource] and [`org.codehaus.plexus.interpolatio.InterpolationPostProcessor`][codehaus-interpolationpostprocessor]
+
+They need to be loaded as [plugin dependencies](https://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_.3Cdependencies.3E_Tag).
+
+[codehaus-valuesource]: https://codehaus-plexus.github.io/plexus-interpolation/apidocs/org/codehaus/plexus/interpolation/ValueSource.html
+[codehaus-interpolationpostprocessor]: https://codehaus-plexus.github.io/plexus-interpolation/apidocs/org/codehaus/plexus/interpolation/InterpolationPostProcessor.html
diff --git a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/impl/extensions/DocviewEscapingInterpolationProcessorTest.java b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/impl/extensions/DocviewEscapingInterpolationProcessorTest.java
new file mode 100644
index 0000000..1ba3a11
--- /dev/null
+++ b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/impl/extensions/DocviewEscapingInterpolationProcessorTest.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.maven.packaging.impl.extensions;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.junit.jupiter.api.Test;
+
+class DocviewEscapingInterpolationProcessorTest {
+
+    private static final String NO_ESCAPE_EXPRESSION = "some.expression";
+    private static final String ESCAPE_EXPRESSION = "vltdocviewattributeescape.some.expression";
+
+    @Test
+    void testEscaping() {
+        DocviewEscapingInterpolationProcessor processor = new DocviewEscapingInterpolationProcessor();
+        assertEquals("&lt;&gt;&amp;\\\\", processor.execute(ESCAPE_EXPRESSION, "<>&\\"));
+    }
+
+    @Test
+    void testNoEscapingWithoutPrefix() {
+        DocviewEscapingInterpolationProcessor processor = new DocviewEscapingInterpolationProcessor();
+        assertNull(processor.execute(NO_ESCAPE_EXPRESSION, "<>/"));
+    }
+}
diff --git a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/FilteringIT.java b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/FilteringIT.java
index ccaec9e..82e6ca1 100644
--- a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/FilteringIT.java
+++ b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/FilteringIT.java
@@ -17,10 +17,12 @@
 package org.apache.jackrabbit.filevault.maven.packaging.it;
 
 import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
 
 import org.apache.commons.lang3.StringUtils;
-import org.apache.jackrabbit.filevault.maven.packaging.it.util.ProjectBuilderExtension;
 import org.apache.jackrabbit.filevault.maven.packaging.it.util.ProjectBuilder;
+import org.apache.jackrabbit.filevault.maven.packaging.it.util.ProjectBuilderExtension;
 import org.apache.maven.it.VerificationException;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
@@ -31,23 +33,24 @@ import org.junit.jupiter.api.extension.ExtendWith;
 @ExtendWith(ProjectBuilderExtension.class)
 class FilteringIT {
 
-    private static void verify(ProjectBuilder projectBuilder, String projectName, boolean enableJcrRootFiltering, boolean enableMetaInfFiltering, String filteredFilePatterns, String ... goals) throws VerificationException, IOException {
+    private static void verify(ProjectBuilder projectBuilder, String projectName, boolean enableJcrRootFiltering, boolean enableMetaInfFiltering, String filteredFilePatterns, Map<String,String> properties) throws VerificationException, IOException {
         projectBuilder
                 .setTestProjectDir("filtering-tests/" + projectName)
-                .setTestGoals(goals)
                 .setProperty("vault.enableMetaInfFiltering", Boolean.toString(enableMetaInfFiltering))
                 .setProperty("vault.enableJcrRootFiltering", Boolean.toString(enableJcrRootFiltering));
         if (StringUtils.isNotBlank(filteredFilePatterns)) {
             projectBuilder.setProperty("vault.filteredFilePatterns", filteredFilePatterns);
         }
+        if (properties != null) {
+            properties.entrySet().stream().forEach(e -> projectBuilder.setProperty(e.getKey(), e.getValue()));
+        }
         projectBuilder
-                .build()
-                .verifyExpectedFiles();
+                .build();
     }
 
     @Test
     void test_simple_filter_with_filtering_enabled(ProjectBuilder projectBuilder) throws Exception {
-        verify(projectBuilder, "simple-filter", true, true, null);
+        verify(projectBuilder, "simple-filter", true, true, null, null);
             // cannot check checksum of properties.xml as that one has platform dependent new lines!
             //.verifyExpectedFileChecksum("META-INF/vault/properties.xml", "295fb69e")
         projectBuilder.verifyExpectedFileChecksum("jcr_root/apps/bar/test1.properties", "10791371")
@@ -55,9 +58,16 @@ class FilteringIT {
             .verifyExpectedFileChecksum("jcr_root/apps/foo/child/.content.xml", "d9b1ad2");
     }
 
+    @Test
+    void test_simple_filter_with_filtering_enabled_and_complex_values(ProjectBuilder projectBuilder) throws Exception {
+        verify(projectBuilder, "simple-filter", true, true, null, Collections.singletonMap("customKey1", "<>&test"));
+        // check for correct escaping
+        projectBuilder.verifyExpectedFileChecksum("jcr_root/apps/bar/escaping/.content.xml", "7022c3d3");
+    }
+
     @Test
     void test_simple_filter_with_filtering_disabled(ProjectBuilder projectBuilder) throws Exception {
-        verify(projectBuilder, "simple-filter", false, false, null);
+        verify(projectBuilder, "simple-filter", false, false, null, null);
             // cannot check checksum of properties.xml as that one has platform dependent new lines!
             //.verifyExpectedFileChecksum("META-INF/vault/properties.xml", "5953911b")
         projectBuilder.verifyExpectedFileChecksum("jcr_root/apps/bar/test1.properties", "34e5a01d")
@@ -67,7 +77,7 @@ class FilteringIT {
 
     @Test
     void test_simple_filter_with_filtering_enabled_on_jcrroot(ProjectBuilder projectBuilder) throws Exception {
-        verify(projectBuilder, "simple-filter", true, false, null);
+        verify(projectBuilder, "simple-filter", true, false, null, null);
             // cannot check checksum of properties.xml as that one has platform dependent new lines!
             //.verifyExpectedFileChecksum("META-INF/vault/properties.xml", "5953911b")
         projectBuilder.verifyExpectedFileChecksum("jcr_root/apps/bar/test1.properties", "10791371")
@@ -77,17 +87,17 @@ class FilteringIT {
 
     @Test
     void test_simple_filter_with_filtering_enabled_on_metainf(ProjectBuilder projectBuilder) throws Exception {
-        verify(projectBuilder, "simple-filter", false, true, null);
+        verify(projectBuilder, "simple-filter", false, true, null, null);
             // cannot check checksum of properties.xml as that one has platform dependent new lines!
             //.verifyExpectedFileChecksum("META-INF/vault/properties.xml", "295fb69e")
         projectBuilder.verifyExpectedFileChecksum("jcr_root/apps/bar/test1.properties", "34e5a01d")
             .verifyExpectedFileChecksum("jcr_root/apps/foo/test2.properties", "a41ae6f8")
             .verifyExpectedFileChecksum("jcr_root/apps/foo/child/.content.xml", "f8aee8df");
     }
-    
+
     @Test
     void test_simple_filter_with_filtering_partially_enabled_on_jcrroot(ProjectBuilder projectBuilder) throws Exception {
-        verify(projectBuilder, "simple-filter", true, false, "**/child/*.xml");
+        verify(projectBuilder, "simple-filter", true, false, "**/child/*.xml", null);
             // cannot check checksum of properties.xml as that one has platform dependent new lines!
             //.verifyExpectedFileChecksum("META-INF/vault/properties.xml", "5953911b")
         projectBuilder.verifyExpectedFileChecksum("jcr_root/apps/bar/test1.properties", "34e5a01d")
diff --git a/src/test/resources/test-projects/filtering-tests/simple-filter/expected-files.txt b/src/test/resources/test-projects/filtering-tests/simple-filter/expected-files.txt
deleted file mode 100644
index 289c133..0000000
--- a/src/test/resources/test-projects/filtering-tests/simple-filter/expected-files.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-META-INF/
-META-INF/MANIFEST.MF
-META-INF/maven/
-META-INF/maven/org.apache.jackrabbit.filevault/
-META-INF/maven/org.apache.jackrabbit.filevault/package-plugin-test-pkg/
-META-INF/maven/org.apache.jackrabbit.filevault/package-plugin-test-pkg/pom.properties
-META-INF/maven/org.apache.jackrabbit.filevault/package-plugin-test-pkg/pom.xml
-META-INF/vault/
-META-INF/vault/config.xml
-META-INF/vault/definition/
-META-INF/vault/definition/.content.xml
-META-INF/vault/filter.xml
-META-INF/vault/properties.xml
-META-INF/vault/settings.xml
-jcr_root/
-jcr_root/apps/
-jcr_root/apps/bar/
-jcr_root/apps/bar/test1.properties
-jcr_root/apps/bar/.content.xml
-jcr_root/apps/foo/
-jcr_root/apps/foo/.content.xml
-jcr_root/apps/foo/test2.properties
-jcr_root/apps/foo/child/
-jcr_root/apps/foo/child/.content.xml
\ No newline at end of file
diff --git a/src/test/resources/test-projects/filtering-tests/simple-filter/jcr_root/apps/bar/escaping/.content.xml b/src/test/resources/test-projects/filtering-tests/simple-filter/jcr_root/apps/bar/escaping/.content.xml
new file mode 100644
index 0000000..c2bc500
--- /dev/null
+++ b/src/test/resources/test-projects/filtering-tests/simple-filter/jcr_root/apps/bar/escaping/.content.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+jcr:primaryType="nt:unstructured"
+escapedCustomKey="${vltdocviewattributeescape.customKey1}" />
\ No newline at end of file