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

hboutemy pushed a commit to annotated tag maven-filtering-1.0-alpha-1
in repository https://gitbox.apache.org/repos/asf/maven-filtering.git

commit 06f6dc182063a5407a9d53b4769f4d46c7bea262
Author: Oliver Lamy <[email protected]>
AuthorDate: Tue Feb 19 00:02:39 2008 +0000

    add :
    - unit with adding token
    - test escaping windows path
    - usage page with code samples
    
    
    
    git-svn-id: 
https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@628928
 13f79535-47bb-0310-9956-ffa450edef68
---
 src/site/apt/usage.apt                             | 85 ++++++++++++++++++++++
 src/site/site.xml                                  |  1 +
 .../DefaultMavenResourcesFilteringTest.java        | 64 +++++++++++++++-
 .../maven-resources-filtering.txt                  |  3 +-
 4 files changed, 150 insertions(+), 3 deletions(-)

diff --git a/src/site/apt/usage.apt b/src/site/apt/usage.apt
new file mode 100755
index 0000000..3584ab5
--- /dev/null
+++ b/src/site/apt/usage.apt
@@ -0,0 +1,85 @@
+ ------
+ Basic Usage
+ ------
+ Olivier Lamy
+ ------
+ 2008-02-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.
+
+Maven Filtering Component Basic Usage
+
+* Filtering a List of org.apache.maven.model.Resource. 
+  
+  Lookup the component in your Mojo
+  
++-----+
+  
+    /**
+     * @component 
role="org.apache.maven.shared.filtering.MavenResourcesFiltering" 
role-hint="default"
+     * @required
+     */    
+    private MavenResourcesFiltering mavenResourcesFiltering;
+  
++-----+
+
+  Apply filtering on your resources List (see {{{../index.html}Reference}} to 
see the default FilterWrappers used).
+
++-----+
+
+encoding can be null platform default will be used
+
+nonFilteredFileExtensions : is a List of String which file extensions to not 
apply filtering (default List contains jpg,jpeg,gif,bmp,png)
+
+mavenResourcesFiltering.filterResources( resources, outputDirectory, 
mavenProject, encoding, filtersFile, nonFilteredFileExtensions );
+
++-----+
+
+* Adding new filtering Token
+
+  You must use the other methods from the MavenResourcesFiltering component 
and construct your own List of FilterWrapper.
+  The following example add the interpolation for the Token @ @ with using 
values coming from reflection with the Maven Project.
+
++-----+
+
+MavenFileFilter mavenFileFilter = (MavenFileFilter) lookup( 
MavenFileFilter.class.getName(), "default" );
+List defaultFilterWrappers = mavenFileFilter.getDefaultFilterWrappers( 
mavenProject, null, true );
+
+List filterWrappers = new ArrayList( );
+filterWrappers.addAll( defaultFilterWrappers );
+FileUtils.FilterWrapper filterWrapper = new FileUtils.FilterWrapper()
+{
+    public Reader getReader( Reader reader )
+    {
+        ReflectionProperties reflectionProperties = new ReflectionProperties( 
mavenProject, true );
+        return new InterpolationFilterReader( reader, reflectionProperties, 
"@", "@" );
+    }
+};
+filterWrappers.add( filterWrapper );
+
+here you can apply filtering on your resources.
+
+encoding can be null platform default will be used
+
+nonFilteredFileExtensions : is a List of String which file extensions to not 
apply filtering (default List contains jpg,jpeg,gif,bmp,png)
+
+mavenResourcesFiltering.filterResources( resources, outputDirectory, encoding, 
filterWrappers,
+                                         outputDirectory, 
nonFilteredFileExtensions );
+
++-----+
diff --git a/src/site/site.xml b/src/site/site.xml
index 4afb631..7033f1f 100755
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -37,6 +37,7 @@ under the License.
   <body>
     <menu name="Overview">
       <item name="Reference" href="index.html"/>
+      <item name="Usage" href="usage.html"/>
     </menu>
     <!-- TODO: Link, head, reports should be inherited -->
     <!-- TODO: use breadcrumbs more structure, links for links, and inherit 
subprojects as a menu or not at all -->
diff --git 
a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
 
b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
index 73e396f..8668ee6 100755
--- 
a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
+++ 
b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
@@ -22,15 +22,18 @@ package org.apache.maven.shared.filtering;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.Reader;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
 
 import org.apache.maven.model.Resource;
+import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.InterpolationFilterReader;
 
 /**
  * @author <a href="mailto:[email protected]";>olamy</a>
@@ -56,12 +59,15 @@ public class DefaultMavenResourcesFilteringTest
         outputDirectory.mkdirs();
     }
     
+   
     public void testSimpleFiltering()
         throws Exception
     {
-        StubMavenProject mavenProject = new StubMavenProject( new File( 
getBasedir() ) );
+        File baseDir = new File( "c:\\foo\\bar" );
+        StubMavenProject mavenProject = new StubMavenProject( baseDir );
         mavenProject.setVersion( "1.0" );
         mavenProject.setGroupId( "org.apache" );
+        mavenProject.setName( "test project" );
 
         Properties projectProperties = new Properties();
         projectProperties.put( "foo", "bar" );
@@ -97,18 +103,72 @@ public class DefaultMavenResourcesFilteringTest
         assertEquals("bar", result.get( "foo" ));
         // FIXME this can fail with a windows path
         String base = result.getProperty( "base" );
-        assertEquals(getBasedir(), base);
         
         assertEquals( "@@", result.getProperty( "emptyexpression" ) );
         assertEquals( "${}", result.getProperty( "emptyexpression2" ) );
         assertEquals( "zloug", result.getProperty( "javaVersion" ) );
         
+        assertEquals( baseDir.toString(), result.get( "base" ) );
+        
         File imageFile = new File(outputDirectory, "happy_duke.gif");
         assertTrue( imageFile.exists() );
         //assertEquals( initialImageFile.length(), imageFile.length() );
         assertTrue(filesAreIdentical( initialImageFile, imageFile ));
     }
     
+    public void testaddingTokens()
+        throws Exception
+    {
+        File baseDir = new File( "c:\\foo\\bar" );
+        final StubMavenProject mavenProject = new StubMavenProject( baseDir );
+        mavenProject.setVersion( "1.0" );
+        mavenProject.setGroupId( "org.apache" );
+        mavenProject.setName( "test project" );
+
+        Properties projectProperties = new Properties();
+        projectProperties.put( "foo", "bar" );
+        projectProperties.put( "java.version", "zloug" );
+        mavenProject.setProperties( projectProperties );
+        MavenResourcesFiltering mavenResourcesFiltering = 
(MavenResourcesFiltering) lookup( MavenResourcesFiltering.class
+            .getName() );
+
+        String unitFilesDir = getBasedir() + 
"/src/test/units-files/maven-resources-filtering";
+        File initialImageFile = new File( unitFilesDir, "happy_duke.gif" );
+
+        Resource resource = new Resource();
+        List resources = new ArrayList();
+        resources.add( resource );
+        resource.setDirectory( unitFilesDir );
+        resource.setFiltering( true );
+
+        List filtersFile = new ArrayList();
+        filtersFile.add( getBasedir()
+            + 
"/src/test/units-files/maven-resources-filtering/empty-maven-resources-filtering.txt"
 );
+
+        List nonFilteredFileExtensions = Collections.singletonList( "gif" );
+        
+        MavenFileFilter mavenFileFilter = (MavenFileFilter) lookup( 
MavenFileFilter.class.getName(), "default" );
+        List defaultFilterWrappers = mavenFileFilter.getDefaultFilterWrappers( 
mavenProject, null, true );
+
+        List filterWrappers = new ArrayList( );
+        filterWrappers.addAll( defaultFilterWrappers );
+        FileUtils.FilterWrapper filterWrapper = new FileUtils.FilterWrapper()
+        {
+            public Reader getReader( Reader reader )
+            {
+                ReflectionProperties reflectionProperties = new 
ReflectionProperties( mavenProject, true );
+                return new InterpolationFilterReader( reader, 
reflectionProperties, "@", "@" );
+            }
+        };
+        filterWrappers.add( filterWrapper );
+        mavenResourcesFiltering.filterResources( resources, outputDirectory, 
null, filterWrappers,
+                                                 new File( getBasedir() ), 
nonFilteredFileExtensions );
+        
+        Properties result = PropertyUtils.loadPropertyFile( new 
File(outputDirectory, "maven-resources-filtering.txt"), null );
+        assertFalse( result.isEmpty() );
+        assertEquals( mavenProject.getName(), result.get( "pomName" ) );
+    }
+    
     public void testNoFiltering()
         throws Exception
     {
diff --git 
a/src/test/units-files/maven-resources-filtering/maven-resources-filtering.txt 
b/src/test/units-files/maven-resources-filtering/maven-resources-filtering.txt
index 47eaa4e..9065b59 100755
--- 
a/src/test/units-files/maven-resources-filtering/maven-resources-filtering.txt
+++ 
b/src/test/units-files/maven-resources-filtering/maven-resources-filtering.txt
@@ -23,4 +23,5 @@ none=none filtered
 base=${pom.basedir}
 emptyexpression=@@
 emptyexpression2=${}
-javaVersion=${java.version}
\ No newline at end of file
+javaVersion=${java.version}
[email protected]@
\ No newline at end of file

Reply via email to