Author: olamy Date: Wed Sep 10 14:18:18 2008 New Revision: 693989 URL: http://svn.apache.org/viewvc?rev=693989&view=rev Log: [MRESOURCES-29] An escape mechanism for property interpolation is missing. this feature is off by default no default escapeString value the mojo parameter to configure is escapeString expression="${maven.resources.escapeString}"
Added: maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/ maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/pom.xml (with props) maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/src/ (props changed) - copied from r692908, maven/plugins/trunk/maven-resources-plugin/src/it/filter/src/ maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/src/test/ - copied from r692908, maven/plugins/trunk/maven-resources-plugin/src/it/filter-test-resources/src/test/ maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/verify.bsh (with props) Modified: maven/plugins/trunk/maven-resources-plugin/pom.xml maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/src/main/resources/SomeResource.txt maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/src/test/resources/SomeResource.txt maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java Modified: maven/plugins/trunk/maven-resources-plugin/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/pom.xml?rev=693989&r1=693988&r2=693989&view=diff ============================================================================== --- maven/plugins/trunk/maven-resources-plugin/pom.xml (original) +++ maven/plugins/trunk/maven-resources-plugin/pom.xml Wed Sep 10 14:18:18 2008 @@ -127,4 +127,19 @@ </build> </profile> </profiles> + + <!-- remove when plexus-interpolation 1.6 released --> + <repositories> + <repository> + <id>snapshots.codehaus</id> + <url>http://snapshots.repository.codehaus.org/</url> + <releases> + <enabled>false</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + </repositories> + </project> Added: maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/pom.xml?rev=693989&view=auto ============================================================================== --- maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/pom.xml (added) +++ maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/pom.xml Wed Sep 10 14:18:18 2008 @@ -0,0 +1,77 @@ +<?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> + + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin-it-escapeInterpolation</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + + <build> + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + </resource> + </resources> + <testResources> + <testResource> + <directory>src/test/resources</directory> + <filtering>true</filtering> + </testResource> + </testResources> + <filters> + <filter>src/main/filters/my.filter</filter> + </filters> + <pluginManagement> + <plugins> + <plugin> + <artifactId>maven-resources-plugin</artifactId> + <version>@pom.version@</version> + <configuration> + <escapeString>\</escapeString> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> + + <!-- + Look at SomeResource.txt after being processed with filtering. + Note the tokens for ${projectProperty} and ${profileProperty} for the "filter resolution" case should be resolved and evaluated + using the POM property values of the filter tokens + --> + <properties> + <projectProperty>foo-projectProperty-bar</projectProperty> + </properties> + + <profiles> + <profile> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <properties> + <profileProperty>foo-profileProperty-bar</profileProperty> + </properties> + </profile> + </profiles> +</project> Propchange: maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Propchange: maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/src/ ------------------------------------------------------------------------------ --- svn:mergeinfo (added) +++ svn:mergeinfo Wed Sep 10 14:18:18 2008 @@ -0,0 +1 @@ +/maven/plugins/branches/MRESOURCES-56/src/it/filter/src:632505-692535 Modified: maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/src/main/resources/SomeResource.txt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/src/main/resources/SomeResource.txt?rev=693989&r1=692908&r2=693989&view=diff ============================================================================== --- maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/src/main/resources/SomeResource.txt (original) +++ maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/src/main/resources/SomeResource.txt Wed Sep 10 14:18:18 2008 @@ -11,3 +11,5 @@ test:filter syspropsExecutionPropsWins=${execProps} [EMAIL PROTECTED]@ + +escapeString=\${project.artifactId} \ No newline at end of file Modified: maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/src/test/resources/SomeResource.txt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/src/test/resources/SomeResource.txt?rev=693989&r1=692908&r2=693989&view=diff ============================================================================== --- maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/src/test/resources/SomeResource.txt (original) +++ maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/src/test/resources/SomeResource.txt Wed Sep 10 14:18:18 2008 @@ -8,3 +8,4 @@ test:filter direct profileProperty=${profileProperty} test:filter resolution profileProperty=${filter.token.profileProperty} +escapeString=\${project.version} \ No newline at end of file Added: maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/verify.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/verify.bsh?rev=693989&view=auto ============================================================================== --- maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/verify.bsh (added) +++ maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/verify.bsh Wed Sep 10 14:18:18 2008 @@ -0,0 +1,199 @@ + +/* + * 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 +{ + File target = new File( basedir, "target" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "target file is missing or a directory." ); + return false; + } + + File someResource = new File( target, "/classes/SomeResource.txt" ); + if ( !someResource.exists() || someResource.isDirectory() ) + { + System.err.println( "SomeResource.txt is missing or not a file." ); + return false; + } + + FileInputStream fis = new FileInputStream ( someResource ); + String paramContent = IOUtil.toString ( fis ); + + //test:direct resolution project.version=1.0-SNAPSHOT + int indexOf = paramContent.indexOf( "test:direct resolution project.version=1.0-SNAPSHOT" ); + if ( indexOf < 0) + { + System.err.println( "/classes/SomeResource.txt not contains test:direct resolution project.version=1.0-SNAPSHOT" ); + return false; + } + + + //test:filter resolution project.version=1.0-SNAPSHOT + indexOf = paramContent.indexOf( "test:filter resolution project.version=1.0-SNAPSHOT" ); + if ( indexOf < 0) + { + System.err.println( "/classes/SomeResource.txt not contains test:filter resolution project.version=1.0-SNAPSHOT" ); + return false; + } + + //test:filter direct projectProperty=foo-projectProperty-bar + indexOf = paramContent.indexOf( "test:filter direct projectProperty=foo-projectProperty-bar" ); + if ( indexOf < 0) + { + System.err.println( "/classes/SomeResource.txt not contains test:filter direct projectProperty=foo-projectProperty-bar" ); + return false; + } + + //test:filter resolution projectProperty=foo-projectProperty-bar + indexOf = paramContent.indexOf( "test:filter resolution projectProperty=foo-projectProperty-bar" ); + if ( indexOf < 0) + { + System.err.println( "/classes/SomeResource.txt not contains test:filter resolution projectProperty=foo-projectProperty-bar" ); + return false; + } + + //test:filter direct profileProperty=foo-profileProperty-bar + indexOf = paramContent.indexOf( "test:filter direct profileProperty=foo-profileProperty-bar" ); + if ( indexOf < 0) + { + System.err.println( "/classes/SomeResource.txt not contains test:filter direct profileProperty=foo-profileProperty-bar" ); + return false; + } + + //test:filter resolution profileProperty=foo-profileProperty-bar + indexOf = paramContent.indexOf( "test:filter resolution profileProperty=foo-profileProperty-bar" ); + if ( indexOf < 0) + { + System.err.println( "/classes/SomeResource.txt not contains test:filter resolution profileProperty=foo-profileProperty-bar" ); + return false; + } + + //test:filter syspropsExecutionPropsWins=fromExecProps + indexOf = paramContent.indexOf( "test:filter syspropsExecutionPropsWins=fromExecProps" ); + if ( indexOf < 0) + { + System.err.println( "/classes/SomeResource.txt not contains test:filter syspropsExecutionPropsWins=fromExecProps" ); + return false; + } + + //newToken=foo + indexOf = paramContent.indexOf( "newToken=foo" ); + if ( indexOf < 0) + { + System.err.println( "/classes/SomeResource.txt not contains newToken=foo" ); + return false; + } + + //escapeString=${project.version} + indexOf = paramContent.indexOf( "escapeString=${project.artifactId}" ); + if ( indexOf < 0) + { + System.err.println( "/classes/SomeResource.txt not contains escapeString=${project.version}" ); + System.out.println (" content " + paramContent ); + return false; + } + + // ------------------------- + // assert on test resources + // ------------------------- + + + someResource = new File( target, "/test-classes/SomeResource.txt" ); + if ( !someResource.exists() || someResource.isDirectory() ) + { + System.err.println( "/test-classes/SomeResource.txt is missing or not a file." ); + return false; + } + + fis = new FileInputStream ( someResource ); + paramContent = IOUtil.toString ( fis ); + + //test:direct resolution project.version=1.0-SNAPSHOT + int indexOf = paramContent.indexOf( "test:direct resolution project.version=1.0-SNAPSHOT" ); + if ( indexOf < 0) + { + System.err.println( "/test-classes/SomeResource.txt not contains test:direct resolution project.version=1.0-SNAPSHOT" ); + return false; + } + + + //test:filter resolution project.version=1.0-SNAPSHOT + indexOf = paramContent.indexOf( "test:filter resolution project.version=1.0-SNAPSHOT" ); + if ( indexOf < 0) + { + System.err.println( "/test-classes/SomeResource.txt not contains test:filter resolution project.version=1.0-SNAPSHOT" ); + return false; + } + + //test:filter direct projectProperty=foo-projectProperty-bar + indexOf = paramContent.indexOf( "test:filter direct projectProperty=foo-projectProperty-bar" ); + if ( indexOf < 0) + { + System.err.println( "/test-classes/SomeResource.txt not contains test:filter direct projectProperty=foo-projectProperty-bar" ); + return false; + } + + //test:filter resolution projectProperty=foo-projectProperty-bar + indexOf = paramContent.indexOf( "test:filter resolution projectProperty=foo-projectProperty-bar" ); + if ( indexOf < 0) + { + System.err.println( "/test-classes/SomeResource.txt not contains test:filter resolution projectProperty=foo-projectProperty-bar" ); + return false; + } + + //test:filter direct profileProperty=foo-profileProperty-bar + indexOf = paramContent.indexOf( "test:filter direct profileProperty=foo-profileProperty-bar" ); + if ( indexOf < 0) + { + System.err.println( "/test-classes/SomeResource.txt not contains test:filter direct profileProperty=foo-profileProperty-bar" ); + return false; + } + + //test:filter resolution profileProperty=foo-profileProperty-bar + indexOf = paramContent.indexOf( "test:filter resolution profileProperty=foo-profileProperty-bar" ); + if ( indexOf < 0) + { + System.err.println( "/test-classes/SomeResource.txt not contains test:filter resolution profileProperty=foo-profileProperty-bar" ); + return false; + } + + //escapeString=${project.version} + indexOf = paramContent.indexOf( "escapeString=${project.version}" ); + if ( indexOf < 0) + { + System.err.println( "/test-classes/SomeResource.txt not contains escapeString=${project.version}" ); + return false; + } + +} +catch( IOException e ) +{ + e.printStackTrace(); + result = false; +} + +return result; Propchange: maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/verify.bsh ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-resources-plugin/src/it/escapeInterpolation/verify.bsh ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java?rev=693989&r1=693988&r2=693989&view=diff ============================================================================== --- maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java (original) +++ maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java Wed Sep 10 14:18:18 2008 @@ -102,6 +102,14 @@ * @required */ protected MavenSession session; + + /** + * Expression preceded with the String won't be interpolated + * \${foo} will be replaced with ${foo} + * @parameter expression="${maven.resources.escapeString}" + * @since 2.3 + */ + protected String escapeString; public void execute() throws MojoExecutionException @@ -121,6 +129,7 @@ project, encoding, filters, Collections.EMPTY_LIST, session ); + mavenResourcesExecution.setEscapeString( escapeString ); mavenResourcesFiltering.filterResources( mavenResourcesExecution ); } catch ( MavenFilteringException e )