[MWAR-225] Add support for customizing filtering delimiters like the resources plugin
 o Upgraded maven-filtering to 3.1.0
 o Support to customize the delimiters which will be used.


git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1739362 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index c31391d..d5e2128 100644
--- a/pom.xml
+++ b/pom.xml
@@ -61,7 +61,7 @@
 
   <properties>
     <mavenArchiverVersion>3.0.1</mavenArchiverVersion>
-    <mavenFilteringVersion>3.0.0</mavenFilteringVersion>
+    <mavenFilteringVersion>3.1.0</mavenFilteringVersion>
     <mavenVersion>3.0</mavenVersion>
   </properties>
 
diff --git a/src/it/web-resources-filtering-delimiter/parent/pom.xml b/src/it/web-resources-filtering-delimiter/parent/pom.xml
new file mode 100644
index 0000000..cee6b83
--- /dev/null
+++ b/src/it/web-resources-filtering-delimiter/parent/pom.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <name>Company Parent</name>
+  <description>Parent that handles dependencyManagement</description>
+
+  <groupId>com.edb.finance.example</groupId>
+  <artifactId>example-parent</artifactId> 
+  <version>1.0.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+  <inceptionYear>2008</inceptionYear>
+
+  <developers>
+    <developer>
+      <id>1</id>
+      <name>Valeriy Molyakov</name>
+      <email>valeriy.molyakov@infopulse.com.ua</email>
+      <organization>EDB Business Partner</organization>
+      <organizationUrl>http://www.edb.com</organizationUrl>
+      <roles>
+        <role>developer</role>
+      </roles>
+      <timezone>+2</timezone>
+    </developer>
+  </developers>
+
+  <distributionManagement>
+    <site>
+      <id>sample.website</id>
+      <url>${website.url}/${project.name}</url>
+    </site>
+  </distributionManagement>
+
+
+  <properties>
+    <jdbc.url>jdbc:oracle:thin:@localhost:1521:orcl</jdbc.url>
+    <website.url>scp://www.yourcompany.com/www/docs/project</website.url>
+  </properties>
+
+</project>
diff --git a/src/it/web-resources-filtering-delimiter/pom.xml b/src/it/web-resources-filtering-delimiter/pom.xml
new file mode 100644
index 0000000..8439116
--- /dev/null
+++ b/src/it/web-resources-filtering-delimiter/pom.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>com.edb.finance.example</groupId>
+    <artifactId>example-parent</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <relativePath>parent/pom.xml</relativePath>
+  </parent>
+
+
+  <artifactId>example</artifactId>
+  <packaging>pom</packaging>
+  
+  <name>Example Maven Multi-module project For Filtering with Delimiters</name>
+  <url>http://maven.apache.org</url>
+
+  <modules>
+    <module>parent</module>
+    <module>web</module>
+  </modules>
+
+
+</project>
diff --git a/src/it/web-resources-filtering-delimiter/verify.bsh b/src/it/web-resources-filtering-delimiter/verify.bsh
new file mode 100644
index 0000000..dd86ecd
--- /dev/null
+++ b/src/it/web-resources-filtering-delimiter/verify.bsh
@@ -0,0 +1,108 @@
+
+/*
+ * 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.
+ */
+
+import java.io.*;
+
+import org.codehaus.plexus.util.*;
+
+boolean result = true;
+
+try
+{
+    // Load and check jetty-env.xml
+
+    File target = new File( basedir, "web/target/example-web/WEB-INF" );
+    if ( !target.exists() || !target.isDirectory() )
+    {
+        System.err.println( "web/target/example-web/WEB-INF is missing or is not a directory." );
+        return false;
+    }
+
+    File jettyEnv = new File( target, "jetty-env.xml" );
+    if ( !jettyEnv.exists() || jettyEnv.isDirectory() )
+    {
+        System.err.println( "jetty-env.xml is missing or is a directory." );
+        return false;
+    }
+
+
+    FileInputStream fis = new FileInputStream ( jettyEnv );
+    String paramContent = IOUtil.toString ( fis, "UTF-8" );
+
+    System.out.println( "content='" + paramContent + "'" );
+
+
+    int indexOf = paramContent.indexOf( "Characters that should be encoded in UTF-8: åäö" );
+    if ( indexOf < 0 )
+    {
+      System.err.println( "Non-ascii characters changed encoding during filtering" );
+      return false;
+    }
+
+    indexOf = paramContent.indexOf( "<Set name=\"URL\">jdbc:oracle:thin:@localhost:1521:orcl</Set>" );
+    if ( indexOf < 0 )
+    {
+      System.err.println( "jdbc.url not filtered correctly" );
+      return false;
+    }
+
+    indexOf = paramContent.indexOf( "<Set name=\"password\">@@jdbc.password@@</Set>" );
+    if ( indexOf < 0 )
+    {
+      System.err.println( "jdbc.password has been filtered" );
+      return false;
+    }
+
+    // Load and check my.properties
+
+    target = new File( basedir, "web/target/example-web/WEB-INF/classes" );
+    if ( !target.exists() || !target.isDirectory() )
+    {
+        System.err.println( "web/target/example-web/WEB-INF/classes is missing or is not a directory." );
+        return false;
+    }
+
+    File myProperties = new File( target, "my.properties" );
+    if ( !myProperties.exists() || myProperties.isDirectory() )
+    {
+        System.err.println( "my.properties is missing or is a directory." );
+        return false;
+    }
+
+    Properties properties = new Properties();
+    FileInputStream fis = new FileInputStream( myProperties );
+    properties.load( fis );
+    fis.close();
+
+    String property = properties.get( "my.property" );
+    System.out.println( "my.property='" + property + "'" );
+    if ( !"Characters that should be encoded in ISO-8859-1: åäö".equals( property ) )
+    {
+        System.err.println( "Non-ascii characters has wrong encoding after filtering" );
+        return false;
+    }
+}
+catch( IOException e )
+{
+    e.printStackTrace();
+    result = false;
+}
+
+return result;
diff --git a/src/it/web-resources-filtering-delimiter/web/pom.xml b/src/it/web-resources-filtering-delimiter/web/pom.xml
new file mode 100644
index 0000000..531d279
--- /dev/null
+++ b/src/it/web-resources-filtering-delimiter/web/pom.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>com.edb.finance.example</groupId>
+    <artifactId>example-parent</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <relativePath>../parent/pom.xml</relativePath>
+  </parent>
+
+
+  <artifactId>example-web</artifactId>
+  <packaging>war</packaging>
+  
+  <name>example-web Maven Webapp</name>
+  <url>http://maven.apache.org</url>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <finalName>example-web</finalName>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-war-plugin</artifactId>
+        <version>@pom.version@</version>
+        <configuration>
+          <escapeString>\</escapeString>
+          <supportMultiLineFiltering>true</supportMultiLineFiltering>
+          <webResources>
+            <resource>
+              <directory>${basedir}/src/main/webresources</directory>
+              <filtering>true</filtering>
+            </resource>
+          </webResources>
+          <resourceEncoding>ISO-8859-1</resourceEncoding>
+          <delimiters>
+            <delimiter>@@*@@</delimiter>
+          </delimiters>
+          <useDefaultDelimiters>false</useDefaultDelimiters>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/web-resources-filtering-delimiter/web/src/main/webapp/WEB-INF/web.xml b/src/it/web-resources-filtering-delimiter/web/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..36c5645
--- /dev/null
+++ b/src/it/web-resources-filtering-delimiter/web/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app>
+  <display-name>Archetype Created Web Application</display-name>
+</web-app>
diff --git a/src/it/web-resources-filtering-delimiter/web/src/main/webapp/index.jsp b/src/it/web-resources-filtering-delimiter/web/src/main/webapp/index.jsp
new file mode 100755
index 0000000..1f294fe
--- /dev/null
+++ b/src/it/web-resources-filtering-delimiter/web/src/main/webapp/index.jsp
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+<html>
+<body>
+<h2>Hello World!</h2>
+</body>
+</html>
diff --git a/src/it/web-resources-filtering-delimiter/web/src/main/webresources/WEB-INF/classes/my.properties b/src/it/web-resources-filtering-delimiter/web/src/main/webresources/WEB-INF/classes/my.properties
new file mode 100644
index 0000000..d076967
--- /dev/null
+++ b/src/it/web-resources-filtering-delimiter/web/src/main/webresources/WEB-INF/classes/my.properties
@@ -0,0 +1,18 @@
+# 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.
+
+my.property=Characters that should be encoded in ISO-8859-1: åäö
\ No newline at end of file
diff --git a/src/it/web-resources-filtering-delimiter/web/src/main/webresources/WEB-INF/jetty-env.xml b/src/it/web-resources-filtering-delimiter/web/src/main/webresources/WEB-INF/jetty-env.xml
new file mode 100644
index 0000000..68ffb66
--- /dev/null
+++ b/src/it/web-resources-filtering-delimiter/web/src/main/webresources/WEB-INF/jetty-env.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
+        "http://jetty.mortbay.org/configure.dtd">
+<Configure class="org.mortbay.jetty.webapp.WebAppContext">
+  <!--
+    This file is encoded in UTF-8 and should be so after filtering, since it
+    specifies an encoding in the xml header. So the following characters should
+    remain unaltered after filtering even though the encoding for filtering is
+    set to ISO-8859-1:
+    Characters that should be encoded in UTF-8: åäö
+  -->
+  <New id="MyDS" class="org.mortbay.jetty.plus.naming.Resource">
+    <Arg>jdbc/EventdialogDS</Arg>
+    <Arg>
+      <New class="oracle.jdbc.pool.OracleConnectionPoolDataSource">
+        <Set name="URL">@@jdbc.url@@</Set>
+        <Set name="user">@@jdbc.user@@</Set>
+        <Set name="password">\@@jdbc.password@@</Set>
+      </New>
+    </Arg>
+  </New>
+</Configure>
diff --git a/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java b/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
index a5653e0..f519727 100644
--- a/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
@@ -24,6 +24,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.LinkedHashSet;
 import java.util.List;
 
 import org.apache.maven.archiver.MavenArchiveConfiguration;
@@ -133,6 +134,38 @@
     private List<String> filters;
 
     /**
+     * <p>
+     * Set of delimiters for expressions to filter within the resources. These delimiters are specified in the form
+     * 'beginToken*endToken'. If no '*' is given, the delimiter is assumed to be the same for start and end.
+     * </p>
+     * <p>
+     * So, the default filtering delimiters might be specified as:
+     * </p>
+     * 
+     * <pre>
+     * &lt;delimiters&gt;
+     *   &lt;delimiter&gt;${*}&lt;/delimiter&gt;
+     *   &lt;delimiter&gt;@&lt;/delimiter&gt;
+     * &lt;/delimiters&gt;
+     * </pre>
+     * <p>
+     * Since the '@' delimiter is the same on both ends, we don't need to specify '@*@' (though we can).
+     * </p>
+     *
+     * @since 3.0.0
+     */
+    @Parameter
+    private LinkedHashSet<String> delimiters;
+
+    /**
+     * Use default delimiters in addition to custom delimiters, if any.
+     *
+     * @since 3.0.0
+     */
+    @Parameter( defaultValue = "true" )
+    private boolean useDefaultDelimiters;
+
+    /**
      * The path to the web.xml file to use.
      */
     @Parameter( property = "maven.war.webxml" )
@@ -422,6 +455,15 @@
             mavenResourcesExecution.setEscapeString( escapeString );
             mavenResourcesExecution.setSupportMultiLineFiltering( supportMultiLineFiltering );
             mavenResourcesExecution.setMavenProject( mavenProject );
+
+            // if these are NOT set, just use the defaults, which are '${*}' and '@'.
+            mavenResourcesExecution.setDelimiters( delimiters, useDefaultDelimiters );
+
+            if ( nonFilteredFileExtensions != null )
+            {
+                mavenResourcesExecution.setNonFilteredFileExtensions( nonFilteredFileExtensions );
+            }
+            
             if ( filters == null )
             {
                 filters = getProject().getBuild().getFilters();