[maven-filtering] annotated tag maven-filtering-1.0-alpha-1 created (now a610e07)

classic Classic list List threaded Threaded
45 messages Options
123
Reply | Threaded
Open this post in threaded view
|

[maven-filtering] annotated tag maven-filtering-1.0-alpha-1 created (now a610e07)

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

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


      at a610e07  (tag)
 tagging 220573947fc7aae6efb2f1bbcdfece391e0d0233 (commit)
      by Oliver Lamy
      on Tue Jul 29 22:18:17 2008 +0000

- Log -----------------------------------------------------------------
maven-filtering-1.0-alpha-1
-----------------------------------------------------------------------

This annotated tag includes the following new commits:

     new 3816102  [MNG-3374] Create a common component for files filtering start some jobs for this issue
     new cdb2715  remove eclipse files
     new eb5690f  ignore eclipse files
     new 790d3a2  add a plexus component which aplly filtering on List of org.apache.maven.model.Resource
     new 559b83b  add project filter files in the value interpolation Map add a hack for interpolation on file for windows
     new 73709fa  remove a printStackTrace
     new ab64b03  add unit on PropertyUtils
     new 8e289c9  remove french character
     new 76bc417  if the resource contains empty expressions (${} or @@) the component filtered with a complex object toString or could failed to getSystemProperty
     new d01b93a  fix some checkstyle errors
     new b711d73  fix license header add junit
     new 1607cfb  fix javadoc
     new 0ff416e  add a method which allow users to have their own list of FilterWrappers
     new 4d2cb14  start a simple documentation
     new 358ec19  add a parameter to pass a list of file extensions to not filtering
     new 93a7ba9  add a predefined list (jpg,jpeg,gif,bmp,png) of known extensions which doesn't support filtering force the extension in lowerCase when testing if the file need filtering
     new b1eca6c  move a method from private to public
     new 9447d00  update documentation merge duplicate code
     new 06f6dc1  add : - unit with adding token - test escaping windows path - usage page with code samples
     new 09751f3  fix documentation
     new 6d9b56e  change the Properties loading order now System Properties wins
     new 60725be  replace using System.getProperties() with mavenSession.getExecutionProperties()
     new 7f8192a  update documentation add missing file
     new c283383  fix documentation
     new 0e49f4c  fix documentation add mavenSession parameter
     new 983c911  fix documentation add missing mavenSession parameter
     new 9371ad3  add a bean to configure a filtering execution request this will prevent having methods with dozens of parameters
     new 6b38f46  add some logging and a null check
     new 7465c47  add filterWrappers coming from the execution configuration bean update documentation
     new 0758f94  add units on exclude/include
     new 313cde1  fix scm info
     new 98f60d8  skip empty file name
     new a18a589  [MRESOURCES-62] changed message from "default encoding" to "platform encoding (xxx actually)" to be more explicit
     new 835f17d  o archiva and continuum are now TLP
     new 2a0196d  use last parent
     new acaf645  remove unused imports and checkstyle error
     new 47ed5a1  use plexus-interpolation in the maven-filtering component
     new e0ed77d  use last plexus-utils version
     new 4c8b07c  use released version
     new a8cec41  fix checstyle errors
     new 9bd05a3  add link in the documentation
     new dba4186  remove unused repository
     new 0de28ba  remove inherited links lock site plugin version
     new 2205739  [maven-release-plugin]  copy for tag maven-filtering-1.0-alpha-1

The 44 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 01/44: [MNG-3374] Create a common component for files filtering start some jobs for this issue

hboutemy
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 38161027604e0f886cb273e210424c2b2990122f
Author: Oliver Lamy <[hidden email]>
AuthorDate: Thu Jan 24 00:28:33 2008 +0000

    [MNG-3374] Create a common component for files filtering
    start some jobs for this issue
   
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@614750 13f79535-47bb-0310-9956-ffa450edef68
---
 .classpath                                         |  21 +++
 .project                                           |  13 ++
 .settings/org.eclipse.jdt.core.prefs               |   5 +
 pom.xml                                            |  76 ++++++++
 .../maven/shared/filtering/CompositeMap.java       | 140 +++++++++++++++
 .../shared/filtering/DefaultMavenFileFilter.java   | 153 ++++++++++++++++
 .../maven/shared/filtering/MavenFileFilter.java    |  79 ++++++++
 .../shared/filtering/MavenFilteringException.java  |  63 +++++++
 .../maven/shared/filtering/PropertyUtils.java      | 199 +++++++++++++++++++++
 .../shared/filtering/ReflectionProperties.java     |  87 +++++++++
 .../shared/filtering/TestReflectionProperties.java | 121 +++++++++++++
 src/test/resources/pom.xml                         |  72 ++++++++
 src/test/units-files/reflection-test.properties    |  22 +++
 13 files changed, 1051 insertions(+)

diff --git a/.classpath b/.classpath
new file mode 100755
index 0000000..c10b3b7
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,21 @@
+<classpath>
+  <classpathentry kind="src" path="src/main/java"/>
+  <classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
+  <classpathentry kind="src" path="src/test/resources" output="target/test-classes" excluding="**/*.java"/>
+  <classpathentry kind="src" path="target/maven-shared-archive-resources" excluding="**/*.java"/>
+  <classpathentry kind="output" path="target/classes"/>
+  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-project/2.0.6/maven-project-2.0.6.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-settings/2.0.6/maven-settings-2.0.6.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-model/2.0.6/maven-model-2.0.6.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/codehaus/plexus/plexus-utils/1.4.9/plexus-utils-1.4.9.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/codehaus/plexus/plexus-container-default/1.0-alpha-9-stable-1/plexus-container-default-1.0-alpha-9-stable-1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
+  <classpathentry kind="var" path="M2_REPO/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-profile/2.0.6/maven-profile-2.0.6.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-artifact-manager/2.0.6/maven-artifact-manager-2.0.6.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-repository-metadata/2.0.6/maven-repository-metadata-2.0.6.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-artifact/2.0.6/maven-artifact-2.0.6.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/maven/wagon/wagon-provider-api/1.0-beta-2/wagon-provider-api-1.0-beta-2.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-plugin-registry/2.0.6/maven-plugin-registry-2.0.6.jar"/>
+</classpath>
\ No newline at end of file
diff --git a/.project b/.project
new file mode 100755
index 0000000..26aa53c
--- /dev/null
+++ b/.project
@@ -0,0 +1,13 @@
+<projectDescription>
+  <name>maven-filtering</name>
+  <comment>Maven shared components</comment>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+  </natures>
+</projectDescription>
\ No newline at end of file
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100755
index 0000000..4f8e077
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+#Sun Jan 20 22:27:40 CET 2008
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.4
+org.eclipse.jdt.core.compiler.compliance=1.4
diff --git a/pom.xml b/pom.xml
new file mode 100755
index 0000000..a5eff30
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,76 @@
+<?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">
+
+  <parent>
+    <groupId>org.apache.maven.shared</groupId>
+    <artifactId>maven-shared-components</artifactId>
+    <version>8</version>
+  </parent>
+
+  <prerequisites>
+    <maven>2.0.6</maven>
+  </prerequisites>
+  
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.shared</groupId>
+  <artifactId>maven-filtering</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0-alpha-1-SNAPSHOT</version>
+
+  <name>Maven Files Filtering</name>
+
+  <scm>
+    <connection>scm:svn:https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-interpolation</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-interpolation</developerConnection>
+    <url>http://svn.apache.org/viewcvs.cgi/maven/sandbox/trunk/shared/maven-interpolation</url>
+  </scm>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.plexus</groupId>
+        <artifactId>plexus-maven-plugin</artifactId>
+        <version>1.3.4</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>descriptor</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0.6</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+      <version>1.4.9</version>
+    </dependency>
+  </dependencies>
+
+</project>
diff --git a/src/main/java/org/apache/maven/shared/filtering/CompositeMap.java b/src/main/java/org/apache/maven/shared/filtering/CompositeMap.java
new file mode 100755
index 0000000..c29a86c
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/filtering/CompositeMap.java
@@ -0,0 +1,140 @@
+package org.apache.maven.shared.filtering;
+
+/*
+ * 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.IOException;
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A Map composed with some others (optional adding SystemProperties and envvar)
+ * The get Method look in the Map list to return the corresponding value
+ * @author <a href="mailto:[hidden email]">olamy</a>
+ * @since 15 janv. 08
+ * @version $Id$
+ */
+public class CompositeMap
+    extends AbstractMap
+{
+    
+    private List /*Map*/maps;
+
+    private boolean systemPropertiesFirst;
+
+    /**
+     * Ca
+     * @param maps
+     * @throws IOException if getting envvars failed
+     */
+    public CompositeMap( List /* Map */maps )
+    {
+        this( maps, false, false );
+    }
+
+    /**
+     * @param maps an orderer {@link List} of {@link Map}
+     * @param useSystemProperties using or not the System Properties
+     * @param systemPropertiesFirst if with get( key ) the systemProperties must wins (the internal ordered {@link List}
+     *        will have in first the System Properties)
+     */
+    public CompositeMap( List /*Map*/maps, boolean useSystemProperties, boolean systemPropertiesFirst )
+    {
+        this.systemPropertiesFirst = systemPropertiesFirst;
+        if ( systemPropertiesFirst && !useSystemProperties )
+        {
+            throw new IllegalArgumentException( "systemPropertiesFirst can't be true if useSystemProperties is false" );
+        }
+        this.maps = new ArrayList();
+        if ( useSystemProperties && !systemPropertiesFirst )
+        {
+            if ( maps != null )
+            {
+                this.maps.addAll( maps );
+            }
+            this.maps.add( System.getProperties() );
+        }
+        else if ( useSystemProperties && systemPropertiesFirst )
+        {
+            this.maps.add( System.getProperties() );
+            if ( maps != null )
+            {
+                this.maps.addAll( maps );
+            }
+        }
+        else
+        {
+            if ( maps != null )
+            {
+                this.maps.addAll( maps );
+            }
+        }
+    }
+
+    public Object get( Object key )
+    {
+        if ( this.maps != null )
+        {
+            for ( Iterator iterator = this.maps.iterator(); iterator.hasNext(); )
+            {
+                Map map = (Map) iterator.next();
+                Object value = map.get( key );
+                if ( value != null )
+                {
+                    return value;
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * @see java.util.AbstractMap#entrySet()
+     */
+    public Set entrySet()
+    {
+        throw new UnsupportedOperationException( "Cannot enumerate properties in a composite map" );
+    }
+
+    public List getMaps()
+    {
+        return maps;
+    }
+
+    public void addMap( Map map )
+    {
+        // see constructors internal Map can't be null
+        this.maps.add( map );
+    }
+
+    public boolean isSystemPropertiesFirst()
+    {
+        return systemPropertiesFirst;
+    }
+
+    public void setSystemPropertiesFirst( boolean systemPropertiesFirst )
+    {
+        this.systemPropertiesFirst = systemPropertiesFirst;
+    }
+
+}
diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
new file mode 100755
index 0000000..b6551dc
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
@@ -0,0 +1,153 @@
+/*
+ * 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.maven.shared.filtering;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.InterpolationFilterReader;
+
+/**
+ * @author <a href="mailto:[hidden email]">olamy</a>
+ * @since 22 janv. 08
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.shared.filtering.MavenFileFilter" role-hint="default"
+ */
+public class DefaultMavenFileFilter
+    implements MavenFileFilter
+{
+
+    /**
+     * @see org.apache.maven.shared.filtering.MavenFileFilter#copyFile(java.io.File, java.io.File, boolean, org.apache.maven.project.MavenProject, java.util.List)
+     */
+    public void copyFile( File from, File to, boolean filtering, MavenProject mavenProject, List filters,
+                          boolean escapedBackslashesInFilePath, String encoding )
+        throws MavenFilteringException
+    {
+        List filterWrappers = getDefaultFilterWrappers( mavenProject, filters, escapedBackslashesInFilePath );
+        copyFile( from, to, filtering, filterWrappers, encoding );
+    }
+
+    /**
+     * @see org.apache.maven.shared.filtering.MavenFileFilter#copyFile(java.io.File, java.io.File, boolean, java.util.List)
+     */
+    public void copyFile( File from, File to, boolean filtering, List filterWrappers, String encoding )
+        throws MavenFilteringException
+    {
+
+        try
+        {
+            if ( filtering )
+            {
+                FileUtils.FilterWrapper[] wrappers = (FileUtils.FilterWrapper[]) filterWrappers
+                    .toArray( new FileUtils.FilterWrapper[filterWrappers.size()] );
+                FileUtils.copyFile( from, to, encoding, wrappers );
+            }
+            else
+            {
+                FileUtils.copyFile( from, to, encoding, new FileUtils.FilterWrapper[0] );
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new MavenFilteringException( e.getMessage(), e );
+        }
+
+    }
+
+    /**
+     * @see org.apache.maven.shared.filtering.MavenFileFilter#getDefaultFilterWrappers(org.apache.maven.project.MavenProject, java.util.List)
+     */
+    public List getDefaultFilterWrappers( final MavenProject mavenProject, List filters, final boolean escapedBackslashesInFilePath )
+        throws MavenFilteringException
+    {
+        
+        final Properties filterProperties = new Properties();
+
+        // System properties
+        filterProperties.putAll( System.getProperties() );
+
+        // Project properties
+        filterProperties.putAll( mavenProject.getProperties() );
+
+        // Take a copy of filterProperties to ensure that evaluated filterTokens are not propagated
+        // to subsequent filter files. NB this replicates current behaviour and seems to make sense.
+        final Properties baseProps = new Properties();
+        baseProps.putAll( filterProperties );
+
+        if ( filters != null )
+        {
+            for ( Iterator i = filters.iterator(); i.hasNext(); )
+            {
+                String filtersfile = (String) i.next();
+                try
+                {
+
+                    Properties properties = PropertyUtils.loadPropertyFile( new File( filtersfile ), baseProps );
+                    filterProperties.putAll( properties );
+                }
+                catch ( IOException e )
+                {
+                    throw new MavenFilteringException( "Error loading property file '" + filtersfile + "'", e );
+                }
+            }
+        }
+        
+        List defaultFilterWrappers = new ArrayList(3);
+        
+        // support ${token}
+        FileUtils.FilterWrapper one = new FileUtils.FilterWrapper() {
+            public Reader getReader(Reader reader) {
+                return new InterpolationFilterReader(reader, filterProperties, "${", "}");
+            }
+        };
+        defaultFilterWrappers.add( one );
+        
+        // support @token@
+        FileUtils.FilterWrapper second = new FileUtils.FilterWrapper() {
+            public Reader getReader(Reader reader) {
+                return new InterpolationFilterReader(reader, filterProperties, "@", "@");
+            }
+        };
+        defaultFilterWrappers.add( second );
+        // support ${token} with mavenProject reflection
+        FileUtils.FilterWrapper third = new FileUtils.FilterWrapper()
+        {
+            public Reader getReader( Reader reader )
+            {
+                ReflectionProperties reflectionProperties = new ReflectionProperties( mavenProject,
+                                                                                      escapedBackslashesInFilePath );
+                return new InterpolationFilterReader( reader, reflectionProperties, "${", "}" );
+            }
+        };
+        defaultFilterWrappers.add( third );
+        
+        
+        return defaultFilterWrappers;
+    }
+
+}
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
new file mode 100755
index 0000000..e8f32ff
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
@@ -0,0 +1,79 @@
+/*
+ * 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.maven.shared.filtering;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.maven.project.MavenProject;
+
+/**
+ * @author <a href="mailto:[hidden email]">olamy</a>
+ * @since 22 janv. 08
+ * @version $Id$
+ */
+public interface MavenFileFilter
+{
+    
+    /**
+     * Will copy a file with some filtering using defaultFilterWrappers
+     * @see #getDefaultFilterWrappers(MavenProject, List)
+     *
+     * @param from file to copy/filter
+     * @param to destination file
+     * @param filtering enable or not filering
+     * @param mavenProject the mavenproject
+     * @param filters {@link List} of properties file
+     * @throws IOException
+     */
+    public void copyFile( File from, final File to, boolean filtering, MavenProject mavenProject,
+                          List/* File */filters, boolean escapedBackslashesInFilePath, String encoding )
+        throws MavenFilteringException;
+
+    /**
+     * @param from
+     * @param to
+     * @param filtering
+     * @param filterWrappers
+     * @throws MavenFilteringException
+     */
+    public void copyFile( File from, final File to, boolean filtering, List /*FileUtils.FilterWrapper*/filterWrappers, String encoding )
+        throws MavenFilteringException;
+
+    /**
+     *
+     * Will return the default FileUtils.FilterWrappers
+     *
+     * <ul>
+     *   <li>interpolation with token ${ } and values from System.getProperties, project.getProperties and from filters.</li>
+     *   <li>interpolation with token @ @ and values from System.getProperties, project.getProperties and from filters.</li>
+     *   <li>interpolation with token ${ } and values from mavenProject interpolation.</li>
+     * </ul>
+     *
+     * @param mavenProject
+     * @param filters {@link List} of properties file
+     *
+     * @return {@link List} of FileUtils.FilterWrapper
+     *
+     */
+    public List/*FileUtils.FilterWrapper*/getDefaultFilterWrappers( MavenProject mavenProject, List/* File */filters,
+                                                                     boolean escapedBackslashesInFilePath )
+        throws MavenFilteringException;
+}
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenFilteringException.java b/src/main/java/org/apache/maven/shared/filtering/MavenFilteringException.java
new file mode 100755
index 0000000..25cb808
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenFilteringException.java
@@ -0,0 +1,63 @@
+/*
+ * 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.maven.shared.filtering;
+
+/**
+ * @author <a href="mailto:[hidden email]">olamy</a>
+ * @since 22 janv. 08
+ * @version $Id$
+ */
+public class MavenFilteringException
+    extends Exception
+{
+
+    /**
+     *
+     */
+    public MavenFilteringException()
+    {
+        // nothing
+    }
+
+    /**
+     * @param message
+     */
+    public MavenFilteringException( String message )
+    {
+        super( message );
+    }
+
+    /**
+     * @param cause
+     */
+    public MavenFilteringException( Throwable cause )
+    {
+        super( cause );
+    }
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public MavenFilteringException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+}
diff --git a/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java b/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
new file mode 100755
index 0000000..424d689
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
@@ -0,0 +1,199 @@
+package org.apache.maven.shared.filtering;
+
+/*
+ * 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 org.codehaus.plexus.util.IOUtil;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Properties;
+
+
+/**
+ * @author <a href="mailto:[hidden email]">Kenney Westerhof</a>
+ * @author William Ferguson
+ * @version $Id$
+ */
+public final class PropertyUtils
+{
+    private PropertyUtils()
+    {
+        // prevent instantiation
+    }
+
+    /**
+     * Reads a property file, resolving all internal variables, using the supplied base properties.
+     * <p>
+     * The properties are resolved iteratively, so if the value of property A refers to property B, then after resolution
+     * the value of property B will contain the value of property B.
+     * </p>
+     *
+     * @param propFile The property file to load.
+     * @param baseProps Properties containing the initial values to subsitute into the properties file.
+     * @return Properties object containing the properties in the file with their values fully resolved.
+     * @throws IOException if profile does not exist, or cannot be read.
+     */
+    public static Properties loadPropertyFile( File propFile, Properties baseProps )
+        throws IOException
+    {
+        if ( !propFile.exists() )
+        {
+            throw new FileNotFoundException( propFile.toString() );
+        }
+
+        final Properties fileProps = new Properties();
+        final FileInputStream inStream = new FileInputStream( propFile );
+        try
+        {
+            fileProps.load( inStream );
+        }
+        finally
+        {
+            IOUtil.close( inStream );
+        }
+
+        final Properties combinedProps = new Properties();
+        combinedProps.putAll( baseProps );
+        combinedProps.putAll( fileProps );
+
+        // The algorithm iterates only over the fileProps which is all that is required to resolve
+        // the properties defined within the file. This is slighlty different to current, however
+        // I suspect that this was the actual original intent.
+        //
+        // The difference is that #loadPropertyFile(File, boolean, boolean) also resolves System properties
+        // whose values contain expressions. I believe this is unexpected and is not validated by the test cases,
+        // as can be verified by replacing the implementation of #loadPropertyFile(File, boolean, boolean)
+        // with the commented variant I have provided that reuses this method.
+
+        for ( Iterator iter = fileProps.keySet().iterator(); iter.hasNext(); )
+        {
+            final String k = (String) iter.next();
+            final String propValue = getPropertyValue( k, combinedProps );
+            fileProps.setProperty( k, propValue );
+        }
+
+        return fileProps;
+    }
+
+    /**
+     * Reads a property file, resolving all internal variables.
+     *
+     * @param propfile The property file to load
+     * @param fail wheter to throw an exception when the file cannot be loaded or to return null
+     * @param useSystemProps wheter to incorporate System.getProperties settings into the returned Properties object.
+     * @return the loaded and fully resolved Properties object
+     */
+    public static Properties loadPropertyFile( File propfile, boolean fail, boolean useSystemProps )
+        throws IOException
+    {
+        
+        final Properties baseProps = new Properties();
+
+        if (useSystemProps)
+        {
+            baseProps.putAll(System.getProperties());
+        }
+
+        final Properties resolvedProps = new Properties();
+        try
+        {
+            resolvedProps.putAll(loadPropertyFile(propfile, baseProps));
+        } catch (FileNotFoundException e)
+        {
+            if (fail)
+            {
+                throw new FileNotFoundException(propfile.toString());
+            }
+        }
+
+        if (useSystemProps)
+        {
+            resolvedProps.putAll(baseProps);
+        }
+
+        return resolvedProps;
+    }
+
+
+    /**
+     * Retrieves a property value, replacing values like ${token}
+     * using the Properties to look them up.
+     *
+     * It will leave unresolved properties alone, trying for System
+     * properties, and implements reparsing (in the case that
+     * the value of a property contains a key), and will
+     * not loop endlessly on a pair like
+     * test = ${test}.
+     */
+    private static String getPropertyValue( String k, Properties p )
+    {
+        // This can also be done using InterpolationFilterReader,
+        // but it requires reparsing the file over and over until
+        // it doesn't change.
+
+        String v = p.getProperty( k );
+        String ret = "";
+        int idx, idx2;
+
+        while ( ( idx = v.indexOf( "${" ) ) >= 0 )
+        {
+            // append prefix to result
+            ret += v.substring( 0, idx );
+
+            // strip prefix from original
+            v = v.substring( idx + 2 );
+
+            // if no matching } then bail
+            if ( ( idx2 = v.indexOf( '}' ) ) < 0 )
+            {
+                break;
+            }
+
+            // strip out the key and resolve it
+            // resolve the key/value for the ${statement}
+            String nk = v.substring( 0, idx2 );
+            v = v.substring( idx2 + 1 );
+            String nv = p.getProperty( nk );
+
+            // try global environment..
+            if ( nv == null )
+            {
+                nv = System.getProperty( nk );
+            }
+
+            // if the key cannot be resolved,
+            // leave it alone ( and don't parse again )
+            // else prefix the original string with the
+            // resolved property ( so it can be parsed further )
+            // taking recursion into account.
+            if ( nv == null || nv.equals( k ) )
+            {
+                ret += "${" + nk + "}";
+            }
+            else
+            {
+                v = nv + v;
+            }
+        }
+        return ret + v;
+    }
+}
diff --git a/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java b/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java
new file mode 100755
index 0000000..a6d9ef9
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java
@@ -0,0 +1,87 @@
+package org.apache.maven.shared.filtering;
+
+/*
+ * 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.util.AbstractMap;
+import java.util.Set;
+
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
+
+
+/**
+ * @author Andreas Hoheneder (ahoh_at_inode.at)
+ * @version $Id$
+ */
+public class ReflectionProperties
+    extends AbstractMap
+{
+
+    private MavenProject project;
+
+    boolean escapedBackslashesInFilePath;
+
+    public ReflectionProperties( MavenProject mavenProject  )
+    {
+       this(mavenProject, false);
+    }    
+    
+    public ReflectionProperties( MavenProject mavenProject, boolean escapedBackslashesInFilePath )
+    {
+       super();
+
+       project = mavenProject;
+
+       this.escapedBackslashesInFilePath = escapedBackslashesInFilePath;
+    }
+    
+    public Object get( Object key )
+    {
+        Object value = null;
+        try
+        {
+            value = ReflectionValueExtractor.evaluate( "" + key , project );
+
+            if ( escapedBackslashesInFilePath && value != null &&
+                "java.lang.String".equals( value.getClass().getName() ) )
+            {
+                String val = (String) value;
+
+                // Check if it's a windows path
+                if ( val.indexOf( ":\\" ) == 1 )
+                {
+                    value = StringUtils.replace( (String)value, "\\", "\\\\" );
+                    value = StringUtils.replace( (String)value, ":", "\\:" );
+                }
+            }
+        }
+        catch ( Exception e )
+        {
+            //TODO: remove the try-catch block when ReflectionValueExtractor.evaluate() throws no more exceptions
+        }
+        return value;
+    }
+    
+    public Set entrySet()
+    {
+        throw new UnsupportedOperationException( "Cannot enumerate properties in a project" );
+    }    
+}
diff --git a/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java b/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java
new file mode 100755
index 0000000..e0a7077
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java
@@ -0,0 +1,121 @@
+/*
+ * 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.maven.shared.filtering;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Properties;
+
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.PlexusTestCase;
+
+/**
+ * @author <a href="mailto:[hidden email]">olamy</a>
+ * @since 22 janv. 08
+ * @version $Id$
+ */
+public class TestReflectionProperties
+    extends PlexusTestCase
+{
+
+    public void testSimpleFiltering()
+        throws Exception
+    {
+        Properties allProperties = System.getProperties();
+        FileInputStream readFileInputStream = null;
+        try
+        {
+            MavenProject mavenProject = new MavenProject();
+            mavenProject.setVersion( "1.0" );
+            mavenProject.setGroupId( "org.apache" );
+            System.setProperty( "foo", "bar" );
+            MavenFileFilter mavenFileFilter = (MavenFileFilter) lookup( MavenFileFilter.class.getName(), "default" );
+
+            File from = new File( getBasedir() + "/src/test/units-files/reflection-test.properties" );
+            File to = new File( getBasedir() + "/target/reflection-test.properties" );
+
+            if (to.exists())
+            {
+                to.delete();
+            }            
+            
+            mavenFileFilter.copyFile( from, to, true, mavenProject, null, false, null );
+
+            Properties reading = new Properties();
+            readFileInputStream = new FileInputStream( to );
+            reading.load( readFileInputStream );
+            assertEquals( "1.0", reading.get( "version" ) );
+            assertEquals( "org.apache", reading.get( "groupId" ) );
+            assertEquals( "bar", reading.get( "foo" ) );
+            assertEquals( "none filtered", reading.get( "none" ) );
+        }
+        finally
+        {
+            if ( readFileInputStream != null )
+            {
+                readFileInputStream.close();
+            }
+            System.setProperties( allProperties );
+        }
+
+    }
+
+    public void testSimpleNonFiltering()
+        throws Exception
+    {
+        Properties allProperties = System.getProperties();
+        FileInputStream readFileInputStream = null;
+        try
+        {
+            MavenProject mavenProject = new MavenProject();
+            mavenProject.setVersion( "1.0" );
+            mavenProject.setGroupId( "org.apache" );
+            System.setProperty( "foo", "bar" );
+            MavenFileFilter mavenFileFilter = (MavenFileFilter) lookup( MavenFileFilter.class.getName(), "default" );
+
+            File from = new File( getBasedir() + "/src/test/units-files/reflection-test.properties" );
+            File to = new File( getBasedir() + "/target/reflection-test.properties" );
+
+            if (to.exists())
+            {
+                to.delete();
+            }
+            
+            mavenFileFilter.copyFile( from, to, false, mavenProject, null, false, null );
+
+            Properties reading = new Properties();
+            readFileInputStream = new FileInputStream( to );
+            reading.load( readFileInputStream );
+            assertEquals( "${pom.version}", reading.get( "version" ) );
+            assertEquals( "${pom.groupId}", reading.get( "groupId" ) );
+            assertEquals( "${foo}", reading.get( "foo" ) );
+            assertEquals( "none filtered", reading.get( "none" ) );
+        }
+        finally
+        {
+            if ( readFileInputStream != null )
+            {
+                readFileInputStream.close();
+            }
+            System.setProperties( allProperties );
+        }
+
+    }    
+    
+}
diff --git a/src/test/resources/pom.xml b/src/test/resources/pom.xml
new file mode 100755
index 0000000..12f0265
--- /dev/null
+++ b/src/test/resources/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">
+
+  <parent>
+    <groupId>org.apache.maven.shared</groupId>
+    <artifactId>maven-shared-components</artifactId>
+    <version>8</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.shared</groupId>
+  <artifactId>maven-filtering</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0-alpha-1-SNAPSHOT</version>
+
+  <name>Maven Files Filtering</name>
+
+  <scm>
+    <connection>scm:svn:https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-interpolation</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-interpolation</developerConnection>
+    <url>http://svn.apache.org/viewcvs.cgi/maven/sandbox/trunk/shared/maven-interpolation</url>
+  </scm>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.plexus</groupId>
+        <artifactId>plexus-maven-plugin</artifactId>
+        <version>1.3.4</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>descriptor</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0.6</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+      <version>1.4.9</version>
+    </dependency>
+  </dependencies>
+
+</project>
diff --git a/src/test/units-files/reflection-test.properties b/src/test/units-files/reflection-test.properties
new file mode 100755
index 0000000..022a0a0
--- /dev/null
+++ b/src/test/units-files/reflection-test.properties
@@ -0,0 +1,22 @@
+#/*
+# * 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.
+# */
+version=${pom.version}
+groupId=${pom.groupId}
+foo=${foo}
+none=none filtered
\ No newline at end of file

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 02/44: remove eclipse files

hboutemy
In reply to this post by hboutemy
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 cdb27153a584ed911829d0e98884fc8a3901a552
Author: Oliver Lamy <[hidden email]>
AuthorDate: Thu Jan 24 00:29:44 2008 +0000

    remove eclipse files
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@614752 13f79535-47bb-0310-9956-ffa450edef68
---
 .classpath                           | 21 ---------------------
 .project                             | 13 -------------
 .settings/org.eclipse.jdt.core.prefs |  5 -----
 3 files changed, 39 deletions(-)

diff --git a/.classpath b/.classpath
deleted file mode 100755
index c10b3b7..0000000
--- a/.classpath
+++ /dev/null
@@ -1,21 +0,0 @@
-<classpath>
-  <classpathentry kind="src" path="src/main/java"/>
-  <classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
-  <classpathentry kind="src" path="src/test/resources" output="target/test-classes" excluding="**/*.java"/>
-  <classpathentry kind="src" path="target/maven-shared-archive-resources" excluding="**/*.java"/>
-  <classpathentry kind="output" path="target/classes"/>
-  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-project/2.0.6/maven-project-2.0.6.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-settings/2.0.6/maven-settings-2.0.6.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-model/2.0.6/maven-model-2.0.6.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/codehaus/plexus/plexus-utils/1.4.9/plexus-utils-1.4.9.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/codehaus/plexus/plexus-container-default/1.0-alpha-9-stable-1/plexus-container-default-1.0-alpha-9-stable-1.jar"/>
-  <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-profile/2.0.6/maven-profile-2.0.6.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-artifact-manager/2.0.6/maven-artifact-manager-2.0.6.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-repository-metadata/2.0.6/maven-repository-metadata-2.0.6.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-artifact/2.0.6/maven-artifact-2.0.6.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/maven/wagon/wagon-provider-api/1.0-beta-2/wagon-provider-api-1.0-beta-2.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-plugin-registry/2.0.6/maven-plugin-registry-2.0.6.jar"/>
-</classpath>
\ No newline at end of file
diff --git a/.project b/.project
deleted file mode 100755
index 26aa53c..0000000
--- a/.project
+++ /dev/null
@@ -1,13 +0,0 @@
-<projectDescription>
-  <name>maven-filtering</name>
-  <comment>Maven shared components</comment>
-  <projects/>
-  <buildSpec>
-    <buildCommand>
-      <name>org.eclipse.jdt.core.javabuilder</name>
-    </buildCommand>
-  </buildSpec>
-  <natures>
-    <nature>org.eclipse.jdt.core.javanature</nature>
-  </natures>
-</projectDescription>
\ No newline at end of file
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100755
index 4f8e077..0000000
--- a/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,5 +0,0 @@
-#Sun Jan 20 22:27:40 CET 2008
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.source=1.4
-org.eclipse.jdt.core.compiler.compliance=1.4

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 03/44: ignore eclipse files

hboutemy
In reply to this post by hboutemy
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 eb5690f583f161cb30b3a547ace72b148dca7870
Author: Oliver Lamy <[hidden email]>
AuthorDate: Thu Jan 24 00:32:14 2008 +0000

    ignore eclipse files
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@614755 13f79535-47bb-0310-9956-ffa450edef68

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 04/44: add a plexus component which aplly filtering on List of org.apache.maven.model.Resource

hboutemy
In reply to this post by hboutemy
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 790d3a224209599cc76694127a391039cac0c6e3
Author: Oliver Lamy <[hidden email]>
AuthorDate: Mon Jan 28 23:21:03 2008 +0000

    add a plexus component which aplly filtering on List of org.apache.maven.model.Resource
   
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@616103 13f79535-47bb-0310-9956-ffa450edef68
---
 .../shared/filtering/DefaultMavenFileFilter.java   |  38 +++---
 .../filtering/DefaultMavenResourcesFiltering.java  | 133 +++++++++++++++++++++
 .../maven/shared/filtering/MavenFileFilter.java    |  11 +-
 .../shared/filtering/MavenResourcesFiltering.java  |  49 ++++++++
 .../maven/shared/filtering/PropertyUtils.java      |   4 +-
 .../DefaultMavenResourcesFilteringTest.java        | 116 ++++++++++++++++++
 .../maven/shared/filtering/StubMavenProject.java   |  46 +++++++
 .../empty-maven-resources-filtering.txt            |  18 +++
 .../maven-resources-filtering.txt                  |  22 ++++
 9 files changed, 413 insertions(+), 24 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
index b6551dc..fe58371 100755
--- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
@@ -22,6 +22,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.Reader;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
@@ -35,7 +36,8 @@ import org.codehaus.plexus.util.InterpolationFilterReader;
  * @since 22 janv. 08
  * @version $Id$
  *
- * @plexus.component role="org.apache.maven.shared.filtering.MavenFileFilter" role-hint="default"
+ * @plexus.component role="org.apache.maven.shared.filtering.MavenFileFilter"
+ *                   role-hint="default"
  */
 public class DefaultMavenFileFilter
     implements MavenFileFilter
@@ -82,17 +84,18 @@ public class DefaultMavenFileFilter
     /**
      * @see org.apache.maven.shared.filtering.MavenFileFilter#getDefaultFilterWrappers(org.apache.maven.project.MavenProject, java.util.List)
      */
-    public List getDefaultFilterWrappers( final MavenProject mavenProject, List filters, final boolean escapedBackslashesInFilePath )
+    public List getDefaultFilterWrappers( final MavenProject mavenProject, List filters,
+                                          final boolean escapedBackslashesInFilePath )
         throws MavenFilteringException
     {
-        
+
         final Properties filterProperties = new Properties();
 
         // System properties
         filterProperties.putAll( System.getProperties() );
 
         // Project properties
-        filterProperties.putAll( mavenProject.getProperties() );
+        filterProperties.putAll( mavenProject.getProperties() == null ? Collections.EMPTY_MAP : mavenProject.getProperties() );
 
         // Take a copy of filterProperties to ensure that evaluated filterTokens are not propagated
         // to subsequent filter files. NB this replicates current behaviour and seems to make sense.
@@ -116,21 +119,25 @@ public class DefaultMavenFileFilter
                 }
             }
         }
-        
-        List defaultFilterWrappers = new ArrayList(3);
-        
+
+        List defaultFilterWrappers = new ArrayList( 3 );
+
         // support ${token}
-        FileUtils.FilterWrapper one = new FileUtils.FilterWrapper() {
-            public Reader getReader(Reader reader) {
-                return new InterpolationFilterReader(reader, filterProperties, "${", "}");
+        FileUtils.FilterWrapper one = new FileUtils.FilterWrapper()
+        {
+            public Reader getReader( Reader reader )
+            {
+                return new InterpolationFilterReader( reader, filterProperties, "${", "}" );
             }
         };
         defaultFilterWrappers.add( one );
-        
+
         // support @token@
-        FileUtils.FilterWrapper second = new FileUtils.FilterWrapper() {
-            public Reader getReader(Reader reader) {
-                return new InterpolationFilterReader(reader, filterProperties, "@", "@");
+        FileUtils.FilterWrapper second = new FileUtils.FilterWrapper()
+        {
+            public Reader getReader( Reader reader )
+            {
+                return new InterpolationFilterReader( reader, filterProperties, "@", "@" );
             }
         };
         defaultFilterWrappers.add( second );
@@ -145,8 +152,7 @@ public class DefaultMavenFileFilter
             }
         };
         defaultFilterWrappers.add( third );
-        
-        
+
         return defaultFilterWrappers;
     }
 
diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
new file mode 100755
index 0000000..be4e863
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
@@ -0,0 +1,133 @@
+/*
+ * 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.maven.shared.filtering;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.maven.model.Resource;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.DirectoryScanner;
+
+/**
+ * @author <a href="mailto:[hidden email]">olamy</a>
+ * @since 28 janv. 08
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.shared.filtering.MavenResourcesFiltering"
+ *                   role-hint="default"
+ */
+public class DefaultMavenResourcesFiltering
+    implements MavenResourcesFiltering
+{
+
+    private static final String[] EMPTY_STRING_ARRAY = {};
+
+    private static final String[] DEFAULT_INCLUDES = {"**/**"};
+    
+    /**
+     * @plexus.requirement
+     *  role-hint="default"
+     */
+    private MavenFileFilter mavenFileFilter;
+    
+    public void filterResources( List resources, File outputDirectory, MavenProject mavenProject, String encoding,
+                                 List fileFilters )
+        throws MavenFilteringException
+    {
+        for ( Iterator i = resources.iterator(); i.hasNext(); )
+        {
+            Resource resource = (Resource) i.next();
+
+            String targetPath = resource.getTargetPath();
+
+            File resourceDirectory = new File( resource.getDirectory() );
+            if ( !resourceDirectory.isAbsolute() )
+            {
+                resourceDirectory = new File( mavenProject.getBasedir(), resourceDirectory.getPath() );
+            }
+
+            if ( !resourceDirectory.exists() )
+            {
+                // TODO how to log here ?
+                continue;
+            }
+
+            // this part is required in case the user specified "../something" as destination
+            // see MNG-1345
+            if ( !outputDirectory.exists() )
+            {
+                if ( !outputDirectory.mkdirs() )
+                {
+                    throw new MavenFilteringException( "Cannot create resource output directory: " + outputDirectory );
+                }
+            }
+
+            DirectoryScanner scanner = new DirectoryScanner();
+
+            scanner.setBasedir( resourceDirectory );
+            if ( resource.getIncludes() != null && !resource.getIncludes().isEmpty() )
+            {
+                scanner.setIncludes( (String[]) resource.getIncludes().toArray( EMPTY_STRING_ARRAY ) );
+            }
+            else
+            {
+                scanner.setIncludes( DEFAULT_INCLUDES );
+            }
+
+            if ( resource.getExcludes() != null && !resource.getExcludes().isEmpty() )
+            {
+                scanner.setExcludes( (String[]) resource.getExcludes().toArray( EMPTY_STRING_ARRAY ) );
+            }
+
+            scanner.addDefaultExcludes();
+            scanner.scan();
+
+            List includedFiles = Arrays.asList( scanner.getIncludedFiles() );
+
+            List filterWrappers = mavenFileFilter.getDefaultFilterWrappers( mavenProject, fileFilters, true );            
+            
+            for ( Iterator j = includedFiles.iterator(); j.hasNext(); )
+            {
+                String name = (String) j.next();
+
+                String destination = name;
+
+                if ( targetPath != null )
+                {
+                    destination = targetPath + "/" + name;
+                }
+
+                File source = new File( resourceDirectory, name );
+
+                File destinationFile = new File( outputDirectory, destination );
+
+                if ( !destinationFile.getParentFile().exists() )
+                {
+                    destinationFile.getParentFile().mkdirs();
+                }
+                mavenFileFilter.copyFile( source, destinationFile, resource.isFiltering(), filterWrappers, encoding );
+            }
+        }
+
+    }
+
+}
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
index e8f32ff..a0c29ac 100755
--- a/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
@@ -43,18 +43,18 @@ public interface MavenFileFilter
      * @param filters {@link List} of properties file
      * @throws IOException
      */
-    public void copyFile( File from, final File to, boolean filtering, MavenProject mavenProject,
-                          List/* File */filters, boolean escapedBackslashesInFilePath, String encoding )
+    public void copyFile( File from, final File to, boolean filtering, MavenProject mavenProject, List filters,
+                          boolean escapedBackslashesInFilePath, String encoding )
         throws MavenFilteringException;
 
     /**
      * @param from
      * @param to
      * @param filtering
-     * @param filterWrappers
+     * @param filterWrappers {@link List} of FileUtils.FilterWrapper
      * @throws MavenFilteringException
      */
-    public void copyFile( File from, final File to, boolean filtering, List /*FileUtils.FilterWrapper*/filterWrappers, String encoding )
+    public void copyFile( File from, final File to, boolean filtering, List filterWrappers, String encoding )
         throws MavenFilteringException;
 
     /**
@@ -73,7 +73,6 @@ public interface MavenFileFilter
      * @return {@link List} of FileUtils.FilterWrapper
      *
      */
-    public List/*FileUtils.FilterWrapper*/getDefaultFilterWrappers( MavenProject mavenProject, List/* File */filters,
-                                                                     boolean escapedBackslashesInFilePath )
+    public List getDefaultFilterWrappers( MavenProject mavenProject, List filters, boolean escapedBackslashesInFilePath )
         throws MavenFilteringException;
 }
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
new file mode 100755
index 0000000..bae9373
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
@@ -0,0 +1,49 @@
+/*
+ * 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.maven.shared.filtering;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.maven.model.Resource;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * @author <a href="mailto:[hidden email]">olamy</a>
+ * @since 28 janv. 08
+ * @version $Id$
+ */
+public interface MavenResourcesFiltering
+{
+
+    /**
+     * @param resources {@link List} of {@link Resource}
+     * @param outputDirectory parent destination directory
+     * @param mavenProject
+     * @param encoding
+     * @param fileFilters {@link List} of Properties file
+     * @throws MavenFilteringException
+     * @throws IOException
+     */
+    public void filterResources( List resources, File outputDirectory, MavenProject mavenProject, String encoding,
+                                 List fileFilters )
+        throws MavenFilteringException;
+
+}
diff --git a/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java b/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
index 424d689..3f1e1c9 100755
--- a/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
+++ b/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
@@ -72,7 +72,7 @@ public final class PropertyUtils
         }
 
         final Properties combinedProps = new Properties();
-        combinedProps.putAll( baseProps );
+        combinedProps.putAll( baseProps == null ? new Properties() : baseProps );
         combinedProps.putAll( fileProps );
 
         // The algorithm iterates only over the fileProps which is all that is required to resolve
@@ -185,7 +185,7 @@ public final class PropertyUtils
             // else prefix the original string with the
             // resolved property ( so it can be parsed further )
             // taking recursion into account.
-            if ( nv == null || nv.equals( k ) )
+            if ( nv == null || nv.equals( k ) || k.equals( nk ) )
             {
                 ret += "${" + nk + "}";
             }
diff --git a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
new file mode 100755
index 0000000..aacc834
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
@@ -0,0 +1,116 @@
+/*
+ * 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.maven.shared.filtering;
+
+import java.io.File;
+import java.util.ArrayList;
+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;
+
+/**
+ * @author <a href="mailto:[hidden email]">olamy</a>
+ * @since 28 janv. 08
+ * @version $Id$
+ */
+public class DefaultMavenResourcesFilteringTest
+    extends PlexusTestCase
+{
+
+    File outputDirectory = new File(getBasedir(), "target/DefaultMavenResourcesFilteringTest");
+    
+
+    
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        if ( outputDirectory.exists() )
+        {
+            FileUtils.forceDelete( outputDirectory );
+        }
+        outputDirectory.mkdirs();
+    }
+    
+    public void testSimpleFiltering()
+        throws Exception
+    {
+        StubMavenProject mavenProject = new StubMavenProject();
+        mavenProject.setVersion( "1.0" );
+        mavenProject.setGroupId( "org.apache" );
+
+        Properties projectProperties = new Properties();
+        projectProperties.put( "foo", "bar" );        
+        mavenProject.setProperties( projectProperties );
+        MavenResourcesFiltering mavenResourcesFiltering = (MavenResourcesFiltering) lookup( MavenResourcesFiltering.class
+            .getName() );
+
+        Resource resource = new Resource();
+        List resources = new ArrayList();
+        resources.add( resource );
+        resource.setDirectory( getBasedir() + "/src/test/units-files/maven-resources-filtering" );
+        resource.setFiltering( true );
+        mavenResourcesFiltering.filterResources( resources, outputDirectory, mavenProject, null, null );
+      
+        assertEquals( 2, outputDirectory.listFiles().length );
+        Properties result = PropertyUtils.loadPropertyFile( new File(outputDirectory, "empty-maven-resources-filtering.txt"), null );
+        assertTrue (result.isEmpty());
+        
+        result = PropertyUtils.loadPropertyFile( new File(outputDirectory, "maven-resources-filtering.txt"), null );
+        assertFalse( result.isEmpty() );
+        
+        assertEquals("1.0", result.get( "version" ));
+        assertEquals("org.apache", result.get( "groupId" ));
+        assertEquals("bar", result.get( "foo" ));
+    }
+    
+    public void testNoFiltering()
+        throws Exception
+    {
+        StubMavenProject mavenProject = new StubMavenProject();
+        mavenProject.setVersion( "1.0" );
+        mavenProject.setGroupId( "org.apache" );
+
+        MavenResourcesFiltering mavenResourcesFiltering = (MavenResourcesFiltering) lookup( MavenResourcesFiltering.class
+            .getName() );
+
+        Resource resource = new Resource();
+        List resources = new ArrayList();
+        resources.add( resource );
+        resource.setDirectory( getBasedir() + "/src/test/units-files/maven-resources-filtering" );
+        resource.setFiltering( false );
+        mavenResourcesFiltering.filterResources( resources, outputDirectory, mavenProject, null, null );
+
+        assertEquals( 2, outputDirectory.listFiles().length );
+        Properties result = PropertyUtils.loadPropertyFile( new File( outputDirectory,
+                                                                      "empty-maven-resources-filtering.txt" ), null );
+        assertTrue( result.isEmpty() );
+
+        result = PropertyUtils.loadPropertyFile( new File( outputDirectory, "maven-resources-filtering.txt" ), null );
+        assertFalse( result.isEmpty() );
+
+        assertEquals( "${pom.version}", result.get( "version" ) );
+        assertEquals( "${pom.groupId}", result.get( "groupId" ) );
+        assertEquals( "${foo}", result.get( "foo" ) );
+    }    
+}
diff --git a/src/test/java/org/apache/maven/shared/filtering/StubMavenProject.java b/src/test/java/org/apache/maven/shared/filtering/StubMavenProject.java
new file mode 100755
index 0000000..b7ce5ab
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/filtering/StubMavenProject.java
@@ -0,0 +1,46 @@
+/*
+ * 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.maven.shared.filtering;
+
+import java.util.Properties;
+
+import org.apache.maven.project.MavenProject;
+
+/**
+ * @author <a href="mailto:[hidden email]">olamy</a>
+ * @since 28 janv. 08
+ * @version $Id$
+ */
+public class StubMavenProject
+    extends MavenProject
+{
+    private Properties properties;
+
+    public Properties getProperties()
+    {
+        return this.properties;
+    }
+
+    public void setProperties( Properties properties )
+    {
+        this.properties = properties;
+    }
+
+
+}
diff --git a/src/test/units-files/maven-resources-filtering/empty-maven-resources-filtering.txt b/src/test/units-files/maven-resources-filtering/empty-maven-resources-filtering.txt
new file mode 100755
index 0000000..eb3e59f
--- /dev/null
+++ b/src/test/units-files/maven-resources-filtering/empty-maven-resources-filtering.txt
@@ -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.
+# */
\ No newline at end of file
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
new file mode 100755
index 0000000..022a0a0
--- /dev/null
+++ b/src/test/units-files/maven-resources-filtering/maven-resources-filtering.txt
@@ -0,0 +1,22 @@
+#/*
+# * 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.
+# */
+version=${pom.version}
+groupId=${pom.groupId}
+foo=${foo}
+none=none filtered
\ No newline at end of file

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 05/44: add project filter files in the value interpolation Map add a hack for interpolation on file for windows

hboutemy
In reply to this post by hboutemy
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 559b83be720b9b0bed6f404f94890ce1aa06cbe6
Author: Oliver Lamy <[hidden email]>
AuthorDate: Thu Jan 31 23:48:31 2008 +0000

    add project filter files in the value interpolation Map
    add a hack for interpolation on file for windows
   
   
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@617299 13f79535-47bb-0310-9956-ffa450edef68
---
 .../shared/filtering/DefaultMavenFileFilter.java   | 42 +++++++++++++++++++++-
 .../maven/shared/filtering/MavenFileFilter.java    |  4 +--
 .../shared/filtering/ReflectionProperties.java     | 24 ++++++++++---
 .../DefaultMavenResourcesFilteringTest.java        | 10 +++---
 .../maven/shared/filtering/StubMavenProject.java   | 13 +++++++
 .../maven-resources-filtering.txt                  |  3 +-
 6 files changed, 83 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
index fe58371..0437f11 100755
--- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
@@ -42,7 +42,7 @@ import org.codehaus.plexus.util.InterpolationFilterReader;
 public class DefaultMavenFileFilter
     implements MavenFileFilter
 {
-
+    
     /**
      * @see org.apache.maven.shared.filtering.MavenFileFilter#copyFile(java.io.File, java.io.File, boolean, org.apache.maven.project.MavenProject, java.util.List)
      */
@@ -119,7 +119,46 @@ public class DefaultMavenFileFilter
                 }
             }
         }
+        
+        List buildFilters = mavenProject.getFilters();
+        if (buildFilters != null)
+        {
+            for (Iterator iterator = buildFilters.iterator();iterator.hasNext();)
+            {
+                String filterFile = (String) iterator.next();
+                try
+                {
+
+                    Properties properties = PropertyUtils.loadPropertyFile( new File( filterFile ), baseProps );
+                    filterProperties.putAll( properties );
+                }
+                catch ( IOException e )
+                {
+                    throw new MavenFilteringException( "Error loading property file '" + filterFile + "'", e );
+                }
+            }
+        }        
+        
+        buildFilters = mavenProject.getBuild().getFilters();
+        if (buildFilters != null)
+        {
+            for (Iterator iterator = buildFilters.iterator();iterator.hasNext();)
+            {
+                String filterFile = (String) iterator.next();
+                try
+                {
+
+                    Properties properties = PropertyUtils.loadPropertyFile( new File( filterFile ), baseProps );
+                    filterProperties.putAll( properties );
+                }
+                catch ( IOException e )
+                {
+                    throw new MavenFilteringException( "Error loading property file '" + filterFile + "'", e );
+                }
+            }
+        }
 
+      
         List defaultFilterWrappers = new ArrayList( 3 );
 
         // support ${token}
@@ -151,6 +190,7 @@ public class DefaultMavenFileFilter
                 return new InterpolationFilterReader( reader, reflectionProperties, "${", "}" );
             }
         };
+        
         defaultFilterWrappers.add( third );
 
         return defaultFilterWrappers;
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
index a0c29ac..ea8a452 100755
--- a/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
@@ -62,8 +62,8 @@ public interface MavenFileFilter
      * Will return the default FileUtils.FilterWrappers
      *
      * <ul>
-     *   <li>interpolation with token ${ } and values from System.getProperties, project.getProperties and from filters.</li>
-     *   <li>interpolation with token @ @ and values from System.getProperties, project.getProperties and from filters.</li>
+     *   <li>interpolation with token ${ } and values from System.getProperties, project.getProperties, from filters and project filters.</li>
+     *   <li>interpolation with token @ @ and values from System.getProperties, project.getProperties, from filters and project filters.</li>
      *   <li>interpolation with token ${ } and values from mavenProject interpolation.</li>
      * </ul>
      *
diff --git a/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java b/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java
index a6d9ef9..f398658 100755
--- a/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java
+++ b/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java
@@ -19,6 +19,7 @@ package org.apache.maven.shared.filtering;
  * under the License.
  */
 
+import java.io.File;
 import java.util.AbstractMap;
 import java.util.Set;
 
@@ -58,24 +59,37 @@ public class ReflectionProperties
         Object value = null;
         try
         {
-            value = ReflectionValueExtractor.evaluate( "" + key , project );
+            value = ReflectionValueExtractor.evaluate( "" + key, project );
 
-            if ( escapedBackslashesInFilePath && value != null &&
-                "java.lang.String".equals( value.getClass().getName() ) )
+            if ( escapedBackslashesInFilePath && value != null
+                && "java.lang.String".equals( value.getClass().getName() ) )
             {
                 String val = (String) value;
 
                 // Check if it's a windows path
                 if ( val.indexOf( ":\\" ) == 1 )
                 {
-                    value = StringUtils.replace( (String)value, "\\", "\\\\" );
-                    value = StringUtils.replace( (String)value, ":", "\\:" );
+                    value = StringUtils.replace( (String) value, "\\", "\\\\" );
+                    value = StringUtils.replace( (String) value, ":", "\\:" );
                 }
             }
+            else if ( escapedBackslashesInFilePath && value != null
+                && File.class.getName().equals( value.getClass().getName() ) )
+            {
+                String val = ( (File) value ).getPath();
+                // Check if it's a windows path
+                if ( val.indexOf( ":\\" ) == 1 )
+                {
+                    value = StringUtils.replace( (String) val, "\\", "\\\\" );
+                    value = StringUtils.replace( (String) value, ":", "\\:" );
+                }
+            }
+            
         }
         catch ( Exception e )
         {
             //TODO: remove the try-catch block when ReflectionValueExtractor.evaluate() throws no more exceptions
+            e.printStackTrace();
         }
         return value;
     }
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 aacc834..10741e9 100755
--- a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
+++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
@@ -24,7 +24,6 @@ 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;
 
@@ -55,12 +54,12 @@ public class DefaultMavenResourcesFilteringTest
     public void testSimpleFiltering()
         throws Exception
     {
-        StubMavenProject mavenProject = new StubMavenProject();
+        StubMavenProject mavenProject = new StubMavenProject( new File( getBasedir() ) );
         mavenProject.setVersion( "1.0" );
         mavenProject.setGroupId( "org.apache" );
 
         Properties projectProperties = new Properties();
-        projectProperties.put( "foo", "bar" );        
+        projectProperties.put( "foo", "bar" );    
         mavenProject.setProperties( projectProperties );
         MavenResourcesFiltering mavenResourcesFiltering = (MavenResourcesFiltering) lookup( MavenResourcesFiltering.class
             .getName() );
@@ -82,12 +81,15 @@ public class DefaultMavenResourcesFilteringTest
         assertEquals("1.0", result.get( "version" ));
         assertEquals("org.apache", result.get( "groupId" ));
         assertEquals("bar", result.get( "foo" ));
+        // FIXME this can fail with a windows path
+        String base = result.getProperty( "base" );
+        assertEquals(getBasedir(), base);
     }
     
     public void testNoFiltering()
         throws Exception
     {
-        StubMavenProject mavenProject = new StubMavenProject();
+        StubMavenProject mavenProject = new StubMavenProject( new File( getBasedir() ) );
         mavenProject.setVersion( "1.0" );
         mavenProject.setGroupId( "org.apache" );
 
diff --git a/src/test/java/org/apache/maven/shared/filtering/StubMavenProject.java b/src/test/java/org/apache/maven/shared/filtering/StubMavenProject.java
index b7ce5ab..2e3262c 100755
--- a/src/test/java/org/apache/maven/shared/filtering/StubMavenProject.java
+++ b/src/test/java/org/apache/maven/shared/filtering/StubMavenProject.java
@@ -18,6 +18,7 @@
  */
 package org.apache.maven.shared.filtering;
 
+import java.io.File;
 import java.util.Properties;
 
 import org.apache.maven.project.MavenProject;
@@ -31,7 +32,14 @@ public class StubMavenProject
     extends MavenProject
 {
     private Properties properties;
+    
+    private File basedir;
 
+    protected StubMavenProject (File basedir)
+    {
+        this.basedir = basedir;
+    }
+    
     public Properties getProperties()
     {
         return this.properties;
@@ -42,5 +50,10 @@ public class StubMavenProject
         this.properties = properties;
     }
 
+    public File getBasedir()
+    {
+        return basedir;
+    }
+
 
 }
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 022a0a0..d5b56d1 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
@@ -19,4 +19,5 @@
 version=${pom.version}
 groupId=${pom.groupId}
 foo=${foo}
-none=none filtered
\ No newline at end of file
+none=none filtered
+base=${pom.basedir}
\ No newline at end of file

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 06/44: remove a printStackTrace

hboutemy
In reply to this post by hboutemy
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 73709fa83328b8372ab2b19e114c3724c65a018d
Author: Oliver Lamy <[hidden email]>
AuthorDate: Thu Jan 31 23:51:07 2008 +0000

    remove a printStackTrace
   
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@617304 13f79535-47bb-0310-9956-ffa450edef68
---
 .../java/org/apache/maven/shared/filtering/ReflectionProperties.java     | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java b/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java
index f398658..b0ed590 100755
--- a/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java
+++ b/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java
@@ -89,7 +89,6 @@ public class ReflectionProperties
         catch ( Exception e )
         {
             //TODO: remove the try-catch block when ReflectionValueExtractor.evaluate() throws no more exceptions
-            e.printStackTrace();
         }
         return value;
     }

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 07/44: add unit on PropertyUtils

hboutemy
In reply to this post by hboutemy
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 ab64b03234d71115c2f8458128c6d6ad579a3b9c
Author: Oliver Lamy <[hidden email]>
AuthorDate: Mon Feb 4 21:22:15 2008 +0000

    add unit on PropertyUtils
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@618443 13f79535-47bb-0310-9956-ffa450edef68
---
 .../maven/shared/filtering/PropertyUtilsTest.java  | 101 +++++++++++++++++++++
 1 file changed, 101 insertions(+)

diff --git a/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java
new file mode 100755
index 0000000..70d3fe0
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.maven.shared.filtering;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.util.Properties;
+
+import org.codehaus.plexus.PlexusTestCase;
+
+/**
+ * @author <a href="mailto:[hidden email]">olamy</a>
+ * @since 4 f�vr. 08
+ * @version $Id$
+ */
+public class PropertyUtilsTest
+    extends PlexusTestCase
+{
+    private static File testDirectory = new File( getBasedir(), "target/test-classes/" );
+    
+    
+
+    public void testBasic()
+        throws Exception
+    {
+        File basicProp = new File( testDirectory, "basic.properties" );
+
+        if ( basicProp.exists() )
+        {
+            basicProp.delete();
+        }
+
+        basicProp.createNewFile();
+        FileWriter writer = new FileWriter( basicProp );
+
+        writer.write( "ghost=${non_existent}\n" );
+        writer.write( "key=${untat_na_damgo}\n" );
+        writer.write( "untat_na_damgo=gani_man\n" );
+        writer.flush();
+        writer.close();
+
+        Properties prop = PropertyUtils.loadPropertyFile( basicProp, false, false );
+        assertTrue( prop.getProperty( "key" ).equals( "gani_man" ) );
+        assertTrue( prop.getProperty( "ghost" ).equals( "${non_existent}" ) );
+    }
+
+    public void testSystemProperties()
+        throws Exception
+    {
+        File systemProp = new File( testDirectory, "system.properties" );
+
+        if ( systemProp.exists() )
+        {
+            systemProp.delete();
+        }
+
+        systemProp.createNewFile();
+        FileWriter writer = new FileWriter( systemProp );
+
+        writer.write( "key=${user.dir}" );
+        writer.flush();
+        writer.close();
+
+        Properties prop = PropertyUtils.loadPropertyFile( systemProp, false, true );
+        assertTrue( prop.getProperty( "key" ).equals( System.getProperty( "user.dir" ) ) );
+    }
+
+    public void testException()
+        throws Exception
+    {
+        File nonExistent = new File( testDirectory, "not_existent_file" );
+
+        assertFalse( "property file exist: " + nonExistent.toString(), nonExistent.exists() );
+
+        try
+        {
+            PropertyUtils.loadPropertyFile( nonExistent, true, false );
+            assertTrue( "Exception failed", false );
+        }
+        catch ( Exception ex )
+        {
+            // exception ok
+        }
+    }
+}

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 08/44: remove french character

hboutemy
In reply to this post by hboutemy
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 8e289c9e7840aa6d1b9f243ec569d296d3c9d9c9
Author: Oliver Lamy <[hidden email]>
AuthorDate: Mon Feb 4 21:24:15 2008 +0000

    remove french character
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@618444 13f79535-47bb-0310-9956-ffa450edef68
---
 src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java
index 70d3fe0..2a75b98 100755
--- a/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java
@@ -26,7 +26,7 @@ import org.codehaus.plexus.PlexusTestCase;
 
 /**
  * @author <a href="mailto:[hidden email]">olamy</a>
- * @since 4 f�vr. 08
+ * @since 4 feb 08
  * @version $Id$
  */
 public class PropertyUtilsTest

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 09/44: if the resource contains empty expressions (${} or @@) the component filtered with a complex object toString or could failed to getSystemProperty

hboutemy
In reply to this post by hboutemy
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 76bc4172bee64fafd0d9b0110070b4f5573b3eb6
Author: Oliver Lamy <[hidden email]>
AuthorDate: Wed Feb 6 21:42:23 2008 +0000

    if the resource contains empty expressions (${} or @@) the component filtered with a complex object toString or could failed to getSystemProperty
   
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@619165 13f79535-47bb-0310-9956-ffa450edef68
---
 src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java   | 3 ++-
 .../java/org/apache/maven/shared/filtering/ReflectionProperties.java | 5 +++++
 .../maven/shared/filtering/DefaultMavenResourcesFilteringTest.java   | 5 +++++
 .../maven-resources-filtering/maven-resources-filtering.txt          | 4 +++-
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java b/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
index 3f1e1c9..df94eda 100755
--- a/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
+++ b/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
@@ -19,6 +19,7 @@ package org.apache.maven.shared.filtering;
  * under the License.
  */
 import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -175,7 +176,7 @@ public final class PropertyUtils
             String nv = p.getProperty( nk );
 
             // try global environment..
-            if ( nv == null )
+            if ( nv == null && !StringUtils.isEmpty( nk ) )
             {
                 nv = System.getProperty( nk );
             }
diff --git a/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java b/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java
index b0ed590..2663eac 100755
--- a/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java
+++ b/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java
@@ -56,6 +56,11 @@ public class ReflectionProperties
     
     public Object get( Object key )
     {
+        if (key == null || StringUtils.isEmpty( key.toString() ))
+        {
+            return null;
+        }
+        
         Object value = null;
         try
         {
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 10741e9..0fe15c4 100755
--- a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
+++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
@@ -84,6 +84,9 @@ public class DefaultMavenResourcesFilteringTest
         // FIXME this can fail with a windows path
         String base = result.getProperty( "base" );
         assertEquals(getBasedir(), base);
+        
+        assertEquals( "@@", result.getProperty( "emptyexpression" ) );
+        assertEquals( "${}", result.getProperty( "emptyexpression2" ) );
     }
     
     public void testNoFiltering()
@@ -114,5 +117,7 @@ public class DefaultMavenResourcesFilteringTest
         assertEquals( "${pom.version}", result.get( "version" ) );
         assertEquals( "${pom.groupId}", result.get( "groupId" ) );
         assertEquals( "${foo}", result.get( "foo" ) );
+        assertEquals( "@@", result.getProperty( "emptyexpression" ) );
+        assertEquals( "${}", result.getProperty( "emptyexpression2" ) );
     }    
 }
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 d5b56d1..3826b6f 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
@@ -20,4 +20,6 @@ version=${pom.version}
 groupId=${pom.groupId}
 foo=${foo}
 none=none filtered
-base=${pom.basedir}
\ No newline at end of file
+base=${pom.basedir}
+emptyexpression=@@
+emptyexpression2=${}
\ No newline at end of file

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 10/44: fix some checkstyle errors

hboutemy
In reply to this post by hboutemy
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 d01b93a372d6e57908934951815050f55cdeb755
Author: Oliver Lamy <[hidden email]>
AuthorDate: Thu Feb 7 22:14:13 2008 +0000

    fix some checkstyle errors
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@619666 13f79535-47bb-0310-9956-ffa450edef68
---
 .../shared/filtering/DefaultMavenFileFilter.java   | 26 ++++++++-------------
 .../filtering/DefaultMavenResourcesFiltering.java  |  3 ++-
 .../maven/shared/filtering/MavenFileFilter.java    | 15 ++++++------
 .../shared/filtering/MavenFilteringException.java  |  3 ++-
 .../shared/filtering/MavenResourcesFiltering.java  |  8 +++----
 .../maven/shared/filtering/PropertyUtils.java      | 27 +++++++++++++---------
 .../shared/filtering/ReflectionProperties.java     |  6 ++---
 7 files changed, 43 insertions(+), 45 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
index 0437f11..1467c36 100755
--- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
@@ -1,3 +1,5 @@
+package org.apache.maven.shared.filtering;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -16,7 +18,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.maven.shared.filtering;
 
 import java.io.File;
 import java.io.IOException;
@@ -42,10 +43,7 @@ import org.codehaus.plexus.util.InterpolationFilterReader;
 public class DefaultMavenFileFilter
     implements MavenFileFilter
 {
-    
-    /**
-     * @see org.apache.maven.shared.filtering.MavenFileFilter#copyFile(java.io.File, java.io.File, boolean, org.apache.maven.project.MavenProject, java.util.List)
-     */
+
     public void copyFile( File from, File to, boolean filtering, MavenProject mavenProject, List filters,
                           boolean escapedBackslashesInFilePath, String encoding )
         throws MavenFilteringException
@@ -54,9 +52,6 @@ public class DefaultMavenFileFilter
         copyFile( from, to, filtering, filterWrappers, encoding );
     }
 
-    /**
-     * @see org.apache.maven.shared.filtering.MavenFileFilter#copyFile(java.io.File, java.io.File, boolean, java.util.List)
-     */
     public void copyFile( File from, File to, boolean filtering, List filterWrappers, String encoding )
         throws MavenFilteringException
     {
@@ -81,9 +76,6 @@ public class DefaultMavenFileFilter
 
     }
 
-    /**
-     * @see org.apache.maven.shared.filtering.MavenFileFilter#getDefaultFilterWrappers(org.apache.maven.project.MavenProject, java.util.List)
-     */
     public List getDefaultFilterWrappers( final MavenProject mavenProject, List filters,
                                           final boolean escapedBackslashesInFilePath )
         throws MavenFilteringException
@@ -121,9 +113,9 @@ public class DefaultMavenFileFilter
         }
         
         List buildFilters = mavenProject.getFilters();
-        if (buildFilters != null)
+        if ( buildFilters != null )
         {
-            for (Iterator iterator = buildFilters.iterator();iterator.hasNext();)
+            for ( Iterator iterator = buildFilters.iterator(); iterator.hasNext(); )
             {
                 String filterFile = (String) iterator.next();
                 try
@@ -137,12 +129,12 @@ public class DefaultMavenFileFilter
                     throw new MavenFilteringException( "Error loading property file '" + filterFile + "'", e );
                 }
             }
-        }        
-        
+        }
+
         buildFilters = mavenProject.getBuild().getFilters();
-        if (buildFilters != null)
+        if ( buildFilters != null )
         {
-            for (Iterator iterator = buildFilters.iterator();iterator.hasNext();)
+            for ( Iterator iterator = buildFilters.iterator(); iterator.hasNext(); )
             {
                 String filterFile = (String) iterator.next();
                 try
diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
index be4e863..d02f4ec 100755
--- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
@@ -1,3 +1,5 @@
+package org.apache.maven.shared.filtering;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -16,7 +18,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.maven.shared.filtering;
 
 import java.io.File;
 import java.util.Arrays;
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
index ea8a452..8fc4a59 100755
--- a/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
@@ -1,3 +1,5 @@
+package org.apache.maven.shared.filtering;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -16,7 +18,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.maven.shared.filtering;
 
 import java.io.File;
 import java.io.IOException;
@@ -34,7 +35,7 @@ public interface MavenFileFilter
     
     /**
      * Will copy a file with some filtering using defaultFilterWrappers
-     * @see #getDefaultFilterWrappers(MavenProject, List)
+     * @see #getDefaultFilterWrappers(MavenProject, List, boolean)
      *
      * @param from file to copy/filter
      * @param to destination file
@@ -43,7 +44,7 @@ public interface MavenFileFilter
      * @param filters {@link List} of properties file
      * @throws IOException
      */
-    public void copyFile( File from, final File to, boolean filtering, MavenProject mavenProject, List filters,
+    void copyFile( File from, final File to, boolean filtering, MavenProject mavenProject, List filters,
                           boolean escapedBackslashesInFilePath, String encoding )
         throws MavenFilteringException;
 
@@ -54,7 +55,7 @@ public interface MavenFileFilter
      * @param filterWrappers {@link List} of FileUtils.FilterWrapper
      * @throws MavenFilteringException
      */
-    public void copyFile( File from, final File to, boolean filtering, List filterWrappers, String encoding )
+    void copyFile( File from, final File to, boolean filtering, List filterWrappers, String encoding )
         throws MavenFilteringException;
 
     /**
@@ -62,8 +63,8 @@ public interface MavenFileFilter
      * Will return the default FileUtils.FilterWrappers
      *
      * <ul>
-     *   <li>interpolation with token ${ } and values from System.getProperties, project.getProperties, from filters and project filters.</li>
-     *   <li>interpolation with token @ @ and values from System.getProperties, project.getProperties, from filters and project filters.</li>
+     *   <li>interpolation with token ${ } and values from SystemProps, project.properties, from filters and project filters.</li>
+     *   <li>interpolation with token @ @ and values from SystemProps, project.properties, from filters and project filters.</li>
      *   <li>interpolation with token ${ } and values from mavenProject interpolation.</li>
      * </ul>
      *
@@ -73,6 +74,6 @@ public interface MavenFileFilter
      * @return {@link List} of FileUtils.FilterWrapper
      *
      */
-    public List getDefaultFilterWrappers( MavenProject mavenProject, List filters, boolean escapedBackslashesInFilePath )
+    List getDefaultFilterWrappers( MavenProject mavenProject, List filters, boolean escapedBackslashesInFilePath )
         throws MavenFilteringException;
 }
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenFilteringException.java b/src/main/java/org/apache/maven/shared/filtering/MavenFilteringException.java
index 25cb808..0a72f99 100755
--- a/src/main/java/org/apache/maven/shared/filtering/MavenFilteringException.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenFilteringException.java
@@ -1,3 +1,5 @@
+package org.apache.maven.shared.filtering;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -16,7 +18,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.maven.shared.filtering;
 
 /**
  * @author <a href="mailto:[hidden email]">olamy</a>
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
index bae9373..5acba81 100755
--- a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
@@ -1,3 +1,5 @@
+package org.apache.maven.shared.filtering;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -16,13 +18,10 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.maven.shared.filtering;
 
 import java.io.File;
-import java.io.IOException;
 import java.util.List;
 
-import org.apache.maven.model.Resource;
 import org.apache.maven.project.MavenProject;
 
 /**
@@ -40,9 +39,8 @@ public interface MavenResourcesFiltering
      * @param encoding
      * @param fileFilters {@link List} of Properties file
      * @throws MavenFilteringException
-     * @throws IOException
      */
-    public void filterResources( List resources, File outputDirectory, MavenProject mavenProject, String encoding,
+    void filterResources( List resources, File outputDirectory, MavenProject mavenProject, String encoding,
                                  List fileFilters )
         throws MavenFilteringException;
 
diff --git a/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java b/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
index df94eda..8e7ada0 100755
--- a/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
+++ b/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
@@ -18,6 +18,7 @@ package org.apache.maven.shared.filtering;
  * specific language governing permissions and limitations
  * under the License.
  */
+
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
 
@@ -36,6 +37,9 @@ import java.util.Properties;
  */
 public final class PropertyUtils
 {
+    /**
+     * private empty constructor to prevent instantiation
+     */
     private PropertyUtils()
     {
         // prevent instantiation
@@ -44,8 +48,8 @@ public final class PropertyUtils
     /**
      * Reads a property file, resolving all internal variables, using the supplied base properties.
      * <p>
-     * The properties are resolved iteratively, so if the value of property A refers to property B, then after resolution
-     * the value of property B will contain the value of property B.
+     * The properties are resolved iteratively, so if the value of property A refers to property B,
+     * then after resolution the value of property B will contain the value of property B.
      * </p>
      *
      * @param propFile The property file to load.
@@ -109,26 +113,27 @@ public final class PropertyUtils
         
         final Properties baseProps = new Properties();
 
-        if (useSystemProps)
+        if ( useSystemProps )
         {
-            baseProps.putAll(System.getProperties());
+            baseProps.putAll( System.getProperties() );
         }
 
         final Properties resolvedProps = new Properties();
-        try
+        try
         {
-            resolvedProps.putAll(loadPropertyFile(propfile, baseProps));
-        } catch (FileNotFoundException e)
+            resolvedProps.putAll( loadPropertyFile( propfile, baseProps ) );
+        }
+        catch ( FileNotFoundException e )
         {
-            if (fail)
+            if ( fail )
             {
-                throw new FileNotFoundException(propfile.toString());
+                throw new FileNotFoundException( propfile.toString() );
             }
         }
 
-        if (useSystemProps)
+        if ( useSystemProps )
         {
-            resolvedProps.putAll(baseProps);
+            resolvedProps.putAll( baseProps );
         }
 
         return resolvedProps;
diff --git a/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java b/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java
index 2663eac..dd35a46 100755
--- a/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java
+++ b/src/main/java/org/apache/maven/shared/filtering/ReflectionProperties.java
@@ -38,11 +38,11 @@ public class ReflectionProperties
 
     private MavenProject project;
 
-    boolean escapedBackslashesInFilePath;
+    private boolean escapedBackslashesInFilePath;
 
     public ReflectionProperties( MavenProject mavenProject  )
     {
-       this(mavenProject, false);
+       this( mavenProject, false );
     }    
     
     public ReflectionProperties( MavenProject mavenProject, boolean escapedBackslashesInFilePath )
@@ -56,7 +56,7 @@ public class ReflectionProperties
     
     public Object get( Object key )
     {
-        if (key == null || StringUtils.isEmpty( key.toString() ))
+        if ( key == null || StringUtils.isEmpty( key.toString() ) )
         {
             return null;
         }

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 11/44: fix license header add junit

hboutemy
In reply to this post by hboutemy
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 b711d73ab55ce045e1e8d4daca43adb2bb64c81f
Author: Oliver Lamy <[hidden email]>
AuthorDate: Fri Feb 8 22:49:37 2008 +0000

    fix license header
    add junit
   
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@620020 13f79535-47bb-0310-9956-ffa450edef68
---
 .../DefaultMavenResourcesFilteringTest.java        |  3 ++-
 .../maven/shared/filtering/PropertyUtilsTest.java  | 17 +++++++++++++++-
 .../maven/shared/filtering/StubMavenProject.java   |  3 ++-
 .../shared/filtering/TestReflectionProperties.java |  3 ++-
 src/test/units-files/propertyutils-test.properties | 23 ++++++++++++++++++++++
 5 files changed, 45 insertions(+), 4 deletions(-)

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 0fe15c4..b8d3fce 100755
--- a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
+++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
@@ -1,3 +1,5 @@
+package org.apache.maven.shared.filtering;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -16,7 +18,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.maven.shared.filtering;
 
 import java.io.File;
 import java.util.ArrayList;
diff --git a/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java
index 2a75b98..12bd282 100755
--- a/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java
@@ -1,3 +1,5 @@
+package org.apache.maven.shared.filtering;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -16,7 +18,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.maven.shared.filtering;
 
 import java.io.File;
 import java.io.FileWriter;
@@ -98,4 +99,18 @@ public class PropertyUtilsTest
             // exception ok
         }
     }
+    
+    public void testloadpropertiesFile()
+        throws Exception
+    {
+        File propertyFile = new File( getBasedir() + "/src/test/units-files/propertyutils-test.properties" );
+        Properties baseProps = new Properties();
+        baseProps.put( "pom.version", "realVersion" );
+
+        Properties interpolated = PropertyUtils.loadPropertyFile( propertyFile, baseProps );
+        assertEquals( "realVersion", interpolated.get( "version" ) );
+        assertEquals( "${foo}", interpolated.get( "foo" ) );
+        assertEquals( "realVersion", interpolated.get( "bar" ) );
+        assertEquals( "none filtered", interpolated.get( "none" ) );
+    }    
 }
diff --git a/src/test/java/org/apache/maven/shared/filtering/StubMavenProject.java b/src/test/java/org/apache/maven/shared/filtering/StubMavenProject.java
index 2e3262c..9fb5cab 100755
--- a/src/test/java/org/apache/maven/shared/filtering/StubMavenProject.java
+++ b/src/test/java/org/apache/maven/shared/filtering/StubMavenProject.java
@@ -1,3 +1,5 @@
+package org.apache.maven.shared.filtering;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -16,7 +18,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.maven.shared.filtering;
 
 import java.io.File;
 import java.util.Properties;
diff --git a/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java b/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java
index e0a7077..4784f6e 100755
--- a/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java
+++ b/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java
@@ -1,3 +1,5 @@
+package org.apache.maven.shared.filtering;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -16,7 +18,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.maven.shared.filtering;
 
 import java.io.File;
 import java.io.FileInputStream;
diff --git a/src/test/units-files/propertyutils-test.properties b/src/test/units-files/propertyutils-test.properties
new file mode 100755
index 0000000..aac8e87
--- /dev/null
+++ b/src/test/units-files/propertyutils-test.properties
@@ -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.
+# */
+version=${pom.version}
+groupId=${pom.groupId}
+foo=${foo}
+none=none filtered
+bar=${version}
\ No newline at end of file

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 12/44: fix javadoc

hboutemy
In reply to this post by hboutemy
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 1607cfb1008c5395ee2bd236dcf68a5323097971
Author: Oliver Lamy <[hidden email]>
AuthorDate: Sat Feb 9 22:29:52 2008 +0000

    fix javadoc
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@620208 13f79535-47bb-0310-9956-ffa450edef68
---
 src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java  | 2 +-
 .../org/apache/maven/shared/filtering/MavenResourcesFiltering.java    | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
index 8fc4a59..a1f8c81 100755
--- a/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
@@ -41,7 +41,7 @@ public interface MavenFileFilter
      * @param to destination file
      * @param filtering enable or not filering
      * @param mavenProject the mavenproject
-     * @param filters {@link List} of properties file
+     * @param filters {@link List} of String which are path to a Property file
      * @throws IOException
      */
     void copyFile( File from, final File to, boolean filtering, MavenProject mavenProject, List filters,
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
index 5acba81..9819db1 100755
--- a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
@@ -36,8 +36,8 @@ public interface MavenResourcesFiltering
      * @param resources {@link List} of {@link Resource}
      * @param outputDirectory parent destination directory
      * @param mavenProject
-     * @param encoding
-     * @param fileFilters {@link List} of Properties file
+     * @param encoding
+     * @param fileFilters {@link List} of String which are path to a Property file
      * @throws MavenFilteringException
      */
     void filterResources( List resources, File outputDirectory, MavenProject mavenProject, String encoding,

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 13/44: add a method which allow users to have their own list of FilterWrappers

hboutemy
In reply to this post by hboutemy
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 0ff416e9b56827c5f62d0c718b5c18b311832341
Author: Oliver Lamy <[hidden email]>
AuthorDate: Sat Feb 9 23:07:04 2008 +0000

    add a method which allow users to have their own list of FilterWrappers
   
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@620211 13f79535-47bb-0310-9956-ffa450edef68
---
 .../shared/filtering/DefaultMavenResourcesFiltering.java | 16 ++++++++++++----
 .../maven/shared/filtering/MavenResourcesFiltering.java  | 12 +++++++++++-
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
index d02f4ec..1d6aecc 100755
--- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
@@ -54,6 +54,14 @@ public class DefaultMavenResourcesFiltering
                                  List fileFilters )
         throws MavenFilteringException
     {
+        List filterWrappers = mavenFileFilter.getDefaultFilterWrappers( mavenProject, fileFilters, true );
+
+        filterResources( resources, outputDirectory, encoding, filterWrappers, mavenProject.getBasedir() );
+    }
+
+    public void filterResources( List resources, File outputDirectory, String encoding, List filterWrappers, File resourcesBaseDirectory )
+        throws MavenFilteringException
+    {
         for ( Iterator i = resources.iterator(); i.hasNext(); )
         {
             Resource resource = (Resource) i.next();
@@ -63,7 +71,7 @@ public class DefaultMavenResourcesFiltering
             File resourceDirectory = new File( resource.getDirectory() );
             if ( !resourceDirectory.isAbsolute() )
             {
-                resourceDirectory = new File( mavenProject.getBasedir(), resourceDirectory.getPath() );
+                resourceDirectory = new File( resourcesBaseDirectory, resourceDirectory.getPath() );
             }
 
             if ( !resourceDirectory.exists() )
@@ -103,8 +111,6 @@ public class DefaultMavenResourcesFiltering
             scanner.scan();
 
             List includedFiles = Arrays.asList( scanner.getIncludedFiles() );
-
-            List filterWrappers = mavenFileFilter.getDefaultFilterWrappers( mavenProject, fileFilters, true );            
             
             for ( Iterator j = includedFiles.iterator(); j.hasNext(); )
             {
@@ -128,7 +134,9 @@ public class DefaultMavenResourcesFiltering
                 mavenFileFilter.copyFile( source, destinationFile, resource.isFiltering(), filterWrappers, encoding );
             }
         }
-
+        
     }
 
+    
+    
 }
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
index 9819db1..8ba557c 100755
--- a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
@@ -33,7 +33,7 @@ public interface MavenResourcesFiltering
 {
 
     /**
-     * @param resources {@link List} of {@link Resource}
+     * @param resources {@link List} of {@link org.apache.maven.model.Resource}
      * @param outputDirectory parent destination directory
      * @param mavenProject
      * @param encoding
@@ -44,4 +44,14 @@ public interface MavenResourcesFiltering
                                  List fileFilters )
         throws MavenFilteringException;
 
+    
+    /**
+     * @param resources {@link List} of {@link org.apache.maven.model.Resource}
+     * @param outputDirectory parent destination directory
+     * @param encoding
+     * @param filterWrappers {@link List} of FileUtils.FilterWrapper
+     * @throws MavenFilteringException
+     */
+    void filterResources( List resources, File outputDirectory, String encoding, List filterWrappers, File resourcesBaseDirectory )
+        throws MavenFilteringException;    
 }

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 14/44: start a simple documentation

hboutemy
In reply to this post by hboutemy
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 4d2cb1414a337c7e2c73954fc4b0f47339e554c2
Author: Oliver Lamy <[hidden email]>
AuthorDate: Sat Feb 9 23:26:31 2008 +0000

    start a simple documentation
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@620216 13f79535-47bb-0310-9956-ffa450edef68
---
 src/site/apt/index.apt                             | 52 ++++++++++++++++++
 src/site/site.xml                                  | 64 ++++++++++++++++++++++
 .../DefaultMavenResourcesFilteringTest.java        |  4 +-
 .../maven-resources-filtering.txt                  |  3 +-
 4 files changed, 121 insertions(+), 2 deletions(-)

diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt
new file mode 100755
index 0000000..5a1354c
--- /dev/null
+++ b/src/site/apt/index.apt
@@ -0,0 +1,52 @@
+ ------
+ Reference
+ ------
+ Olivier Lamy
+ ------
+ 2008-01-01
+ ------
+
+ ~~ 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
+
+  This Plexus components has been build with the filtering process coming from the maven-resources-plugin.
+  
+  The goal is to provide a common way for all plugins which needs to filtering resources.
+  
+* Component MavenResourcesFiltering
+
+  This component will apply filtering on a List of org.apache.maven.model.Resource.
+  The method without the filterWrappers parameter will interpolate the files using the default FileUtils.FilterWrapper.
+
+* Component MavenFileFilter
+
+  This component has a method which returns the default FileUtils.FilterWrapper.
+  This are :
+  
+    * interpolation with token ${ } and values from SystemProps, project.properties, filters, project.filters and project.build.filters
+    
+    * interpolation with token @ @ and values from SystemProps, project.properties, filters, project.filters and project.build.filters
+    
+    * interpolation with token ${ } and values from mavenProject interpolation
+    
+    []
+    
+    <<NOTE>> : The sentence "values from SystemProps, project.properties, filters, project.filters and project.build.filters"
+    means pairs of key/value will be loaded/overriding with this order. The value for key java.version can be overriding
+    with a property in the maven project (yes crazy but possible).
\ No newline at end of file
diff --git a/src/site/site.xml b/src/site/site.xml
new file mode 100755
index 0000000..4afb631
--- /dev/null
+++ b/src/site/site.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+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>
+  <!-- TODO: Most of the stuff in this file should be inherited from the shared parent -->
+  <!-- TODO: banners, skin, publish date, version should be inherited from Maven itself -->
+  <bannerLeft>
+    <name>${project.name}</name>
+    <src>http://maven.apache.org/images/apache-maven-project-2.png</src>
+    <href>http://maven.apache.org/</href>
+  </bannerLeft>
+  <bannerRight>
+    <src>http://maven.apache.org/images/maven-logo-2.gif</src>
+  </bannerRight>
+  <skin>
+    <groupId>org.apache.maven.skins</groupId>
+    <artifactId>maven-stylus-skin</artifactId>
+  </skin>
+  <publishDate format="dd MMM yyyy" position="left" />
+  <version position="left" />
+  <body>
+    <menu name="Overview">
+      <item name="Reference" href="index.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 -->
+    <links>
+      <item name="Apache" href="http://www.apache.org/"/>
+      <item name="Maven 1.x" href="http://maven.apache.org/maven-1.x"/>
+      <item name="Maven 2.x" href="http://maven.apache.org/"/>
+      <item name="Maven 2.x Plugins" href="http://maven.apache.org/plugins/"/>
+      <item name="Continuum" href="http://maven.apache.org/continuum"/>
+      <item name="SCM" href="http://maven.apache.org/scm"/>
+      <item name="Wagon" href="http://maven.apache.org/wagon"/>
+      <item name="JXR" href="http://maven.apache.org/jxr"/>
+      <item name="Doxia" href="http://maven.apache.org/doxia"/>
+    </links>
+    <head>
+      <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
+      </script>
+      <script type="text/javascript">
+        _uacct = "UA-140879-1";
+        urchinTracker();
+      </script>
+    </head>
+    <menu ref="reports" inherit="bottom" />
+  </body>
+</project>
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 b8d3fce..b956042 100755
--- a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
+++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
@@ -60,7 +60,8 @@ public class DefaultMavenResourcesFilteringTest
         mavenProject.setGroupId( "org.apache" );
 
         Properties projectProperties = new Properties();
-        projectProperties.put( "foo", "bar" );    
+        projectProperties.put( "foo", "bar" );
+        projectProperties.put( "java.version", "zloug" );
         mavenProject.setProperties( projectProperties );
         MavenResourcesFiltering mavenResourcesFiltering = (MavenResourcesFiltering) lookup( MavenResourcesFiltering.class
             .getName() );
@@ -88,6 +89,7 @@ public class DefaultMavenResourcesFilteringTest
         
         assertEquals( "@@", result.getProperty( "emptyexpression" ) );
         assertEquals( "${}", result.getProperty( "emptyexpression2" ) );
+        assertEquals( "zloug", result.getProperty( "javaVersion" ) );
     }
     
     public void testNoFiltering()
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 3826b6f..47eaa4e 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
@@ -22,4 +22,5 @@ foo=${foo}
 none=none filtered
 base=${pom.basedir}
 emptyexpression=@@
-emptyexpression2=${}
\ No newline at end of file
+emptyexpression2=${}
+javaVersion=${java.version}
\ No newline at end of file

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 15/44: add a parameter to pass a list of file extensions to not filtering

hboutemy
In reply to this post by hboutemy
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 358ec19757b763643b0bc00a1acf9c65b8f4fa46
Author: Oliver Lamy <[hidden email]>
AuthorDate: Fri Feb 15 22:07:04 2008 +0000

    add a parameter to pass a list of file extensions to not filtering
   
   
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@628188 13f79535-47bb-0310-9956-ffa450edef68
---
 .../shared/filtering/DefaultMavenFileFilter.java   |   7 +-
 .../filtering/DefaultMavenResourcesFiltering.java  |  27 ++++++--
 .../shared/filtering/MavenResourcesFiltering.java  |   9 ++-
 .../DefaultMavenResourcesFilteringTest.java        |  74 +++++++++++++++++++--
 .../maven-resources-filtering/happy_duke.gif       | Bin 0 -> 36092 bytes
 5 files changed, 97 insertions(+), 20 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
index 1467c36..bf7709b 100755
--- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
@@ -98,16 +98,15 @@ public class DefaultMavenFileFilter
         {
             for ( Iterator i = filters.iterator(); i.hasNext(); )
             {
-                String filtersfile = (String) i.next();
+                String filterfile = (String) i.next();
                 try
                 {
-
-                    Properties properties = PropertyUtils.loadPropertyFile( new File( filtersfile ), baseProps );
+                    Properties properties = PropertyUtils.loadPropertyFile( new File( filterfile ), baseProps );
                     filterProperties.putAll( properties );
                 }
                 catch ( IOException e )
                 {
-                    throw new MavenFilteringException( "Error loading property file '" + filtersfile + "'", e );
+                    throw new MavenFilteringException( "Error loading property file '" + filterfile + "'", e );
                 }
             }
         }
diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
index 1d6aecc..8db304f 100755
--- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
@@ -27,6 +27,7 @@ import java.util.List;
 import org.apache.maven.model.Resource;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.FileUtils;
 
 /**
  * @author <a href="mailto:[hidden email]">olamy</a>
@@ -51,15 +52,17 @@ public class DefaultMavenResourcesFiltering
     private MavenFileFilter mavenFileFilter;
     
     public void filterResources( List resources, File outputDirectory, MavenProject mavenProject, String encoding,
-                                 List fileFilters )
+                                 List fileFilters, List nonFilteredFileExtensions )
         throws MavenFilteringException
     {
         List filterWrappers = mavenFileFilter.getDefaultFilterWrappers( mavenProject, fileFilters, true );
 
-        filterResources( resources, outputDirectory, encoding, filterWrappers, mavenProject.getBasedir() );
+        filterResources( resources, outputDirectory, encoding, filterWrappers, mavenProject.getBasedir(),
+                         nonFilteredFileExtensions );
     }
 
-    public void filterResources( List resources, File outputDirectory, String encoding, List filterWrappers, File resourcesBaseDirectory )
+    public void filterResources( List resources, File outputDirectory, String encoding, List filterWrappers,
+                                 File resourcesBaseDirectory, List nonFilteredFileExtensions )
         throws MavenFilteringException
     {
         for ( Iterator i = resources.iterator(); i.hasNext(); )
@@ -69,6 +72,7 @@ public class DefaultMavenResourcesFiltering
             String targetPath = resource.getTargetPath();
 
             File resourceDirectory = new File( resource.getDirectory() );
+
             if ( !resourceDirectory.isAbsolute() )
             {
                 resourceDirectory = new File( resourcesBaseDirectory, resourceDirectory.getPath() );
@@ -111,7 +115,7 @@ public class DefaultMavenResourcesFiltering
             scanner.scan();
 
             List includedFiles = Arrays.asList( scanner.getIncludedFiles() );
-            
+
             for ( Iterator j = includedFiles.iterator(); j.hasNext(); )
             {
                 String name = (String) j.next();
@@ -131,12 +135,23 @@ public class DefaultMavenResourcesFiltering
                 {
                     destinationFile.getParentFile().mkdirs();
                 }
-                mavenFileFilter.copyFile( source, destinationFile, resource.isFiltering(), filterWrappers, encoding );
+                boolean filteredExt = filteredFileExtension( source, nonFilteredFileExtensions );
+                mavenFileFilter.copyFile( source, destinationFile, resource.isFiltering() && filteredExt,
+                                          filterWrappers, encoding );
             }
         }
-        
+
     }
 
     
+    private boolean filteredFileExtension(File file, List nonFilteredFileExtensions)
+    {
+        if (nonFilteredFileExtensions == null)
+        {
+            return true;
+        }
+        return !nonFilteredFileExtensions.contains( FileUtils.extension( file.getName() ) );
+    }
+    
     
 }
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
index 8ba557c..080c9ee 100755
--- a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
@@ -38,20 +38,23 @@ public interface MavenResourcesFiltering
      * @param mavenProject
      * @param encoding
      * @param fileFilters {@link List} of String which are path to a Property file
+     * @param nonFilteredFileExtensions {@link List} of String for non filtered file extensions
      * @throws MavenFilteringException
      */
     void filterResources( List resources, File outputDirectory, MavenProject mavenProject, String encoding,
-                                 List fileFilters )
+                          List fileFilters, List nonFilteredFileExtensions )
         throws MavenFilteringException;
 
-    
     /**
      * @param resources {@link List} of {@link org.apache.maven.model.Resource}
      * @param outputDirectory parent destination directory
      * @param encoding
      * @param filterWrappers {@link List} of FileUtils.FilterWrapper
+     * @param resourcesBaseDirectory baseDirectory of resources
+     * @param nonFilteredFileExtensions {@link List} of String for non filtered file extensions
      * @throws MavenFilteringException
      */
-    void filterResources( List resources, File outputDirectory, String encoding, List filterWrappers, File resourcesBaseDirectory )
+    void filterResources( List resources, File outputDirectory, String encoding, List filterWrappers,
+                          File resourcesBaseDirectory, List nonFilteredFileExtensions )
         throws MavenFilteringException;    
 }
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 b956042..73e396f 100755
--- a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
+++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
@@ -20,13 +20,17 @@ package org.apache.maven.shared.filtering;
  */
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
 
 import org.apache.maven.model.Resource;
 import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
 
 /**
  * @author <a href="mailto:[hidden email]">olamy</a>
@@ -66,14 +70,22 @@ public class DefaultMavenResourcesFilteringTest
         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( getBasedir() + "/src/test/units-files/maven-resources-filtering" );
+        resource.setDirectory( unitFilesDir );
         resource.setFiltering( true );
-        mavenResourcesFiltering.filterResources( resources, outputDirectory, mavenProject, null, null );
+
+        List filtersFile = new ArrayList();
+        filtersFile.add( getBasedir() + "/src/test/units-files/maven-resources-filtering/empty-maven-resources-filtering.txt" );
+        
+        List nonFilteredFileExtensions = Collections.singletonList( "gif" );
+        mavenResourcesFiltering.filterResources( resources, outputDirectory, mavenProject, null, filtersFile, nonFilteredFileExtensions );
       
-        assertEquals( 2, outputDirectory.listFiles().length );
+        assertEquals( 3, outputDirectory.listFiles().length );
         Properties result = PropertyUtils.loadPropertyFile( new File(outputDirectory, "empty-maven-resources-filtering.txt"), null );
         assertTrue (result.isEmpty());
         
@@ -90,6 +102,11 @@ public class DefaultMavenResourcesFilteringTest
         assertEquals( "@@", result.getProperty( "emptyexpression" ) );
         assertEquals( "${}", result.getProperty( "emptyexpression2" ) );
         assertEquals( "zloug", result.getProperty( "javaVersion" ) );
+        
+        File imageFile = new File(outputDirectory, "happy_duke.gif");
+        assertTrue( imageFile.exists() );
+        //assertEquals( initialImageFile.length(), imageFile.length() );
+        assertTrue(filesAreIdentical( initialImageFile, imageFile ));
     }
     
     public void testNoFiltering()
@@ -102,14 +119,19 @@ public class DefaultMavenResourcesFilteringTest
         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( getBasedir() + "/src/test/units-files/maven-resources-filtering" );
+        
+        resource.setDirectory( unitFilesDir );
         resource.setFiltering( false );
-        mavenResourcesFiltering.filterResources( resources, outputDirectory, mavenProject, null, null );
+        mavenResourcesFiltering.filterResources( resources, outputDirectory, mavenProject, null, null,
+                                                 Collections.EMPTY_LIST );
 
-        assertEquals( 2, outputDirectory.listFiles().length );
+        assertEquals( 3, outputDirectory.listFiles().length );
         Properties result = PropertyUtils.loadPropertyFile( new File( outputDirectory,
                                                                       "empty-maven-resources-filtering.txt" ), null );
         assertTrue( result.isEmpty() );
@@ -122,5 +144,43 @@ public class DefaultMavenResourcesFilteringTest
         assertEquals( "${foo}", result.get( "foo" ) );
         assertEquals( "@@", result.getProperty( "emptyexpression" ) );
         assertEquals( "${}", result.getProperty( "emptyexpression2" ) );
-    }    
+        File imageFile = new File(outputDirectory, "happy_duke.gif");
+        assertTrue(filesAreIdentical( initialImageFile, imageFile ));
+    }  
+    
+    public static boolean filesAreIdentical( File expected, File current )
+        throws IOException
+    {
+        if ( expected.length() != current.length() )
+        {
+            return false;
+        }
+        FileInputStream expectedIn = new FileInputStream( expected );
+        FileInputStream currentIn = new FileInputStream( current );
+        try
+        {
+            byte[] expectedBuffer = IOUtil.toByteArray( expectedIn );
+            
+            byte[] currentBuffer = IOUtil.toByteArray( currentIn );
+            if (expectedBuffer.length != currentBuffer.length)
+            {
+                return false;
+            }
+            for (int i = 0,size = expectedBuffer.length;i<size;i++)
+            {
+                if(expectedBuffer[i]!= currentBuffer[i])
+                {
+                    return false;
+                }
+            }
+        }
+        finally
+        {
+            expectedIn.close();
+            currentIn.close();
+        }
+        return true;
+    }
+
+
 }
diff --git a/src/test/units-files/maven-resources-filtering/happy_duke.gif b/src/test/units-files/maven-resources-filtering/happy_duke.gif
new file mode 100755
index 0000000..9784ed6
Binary files /dev/null and b/src/test/units-files/maven-resources-filtering/happy_duke.gif differ

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 16/44: add a predefined list (jpg, jpeg, gif, bmp, png) of known extensions which doesn't support filtering force the extension in lowerCase when testing if the file need filtering

hboutemy
In reply to this post by hboutemy
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 93a7ba9a42dfa154120b9622864e28de05823406
Author: Oliver Lamy <[hidden email]>
AuthorDate: Sun Feb 17 13:57:28 2008 +0000

    add a predefined list (jpg,jpeg,gif,bmp,png) of known extensions which doesn't support filtering
    force the extension in lowerCase when testing if the file need filtering
   
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@628487 13f79535-47bb-0310-9956-ffa450edef68
---
 .../filtering/DefaultMavenResourcesFiltering.java  | 39 +++++++++++++++++++---
 .../shared/filtering/MavenResourcesFiltering.java  |  6 ++++
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
index 8db304f..f9122c5 100755
--- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
@@ -20,14 +20,18 @@ package org.apache.maven.shared.filtering;
  */
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
 import org.apache.maven.model.Resource;
 import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
 import org.codehaus.plexus.util.DirectoryScanner;
 import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.StringUtils;
 
 /**
  * @author <a href="mailto:[hidden email]">olamy</a>
@@ -38,13 +42,32 @@ import org.codehaus.plexus.util.FileUtils;
  *                   role-hint="default"
  */
 public class DefaultMavenResourcesFiltering
-    implements MavenResourcesFiltering
+    implements MavenResourcesFiltering, Initializable
 {
 
     private static final String[] EMPTY_STRING_ARRAY = {};
 
     private static final String[] DEFAULT_INCLUDES = {"**/**"};
     
+    private List defaultNonFilteredFileExtensions;
+    
+    // ------------------------------------------------
+    //  Plexus lifecycle
+    // ------------------------------------------------
+    public void initialize()
+        throws InitializationException
+    {
+        // jpg,jpeg,gif,bmp,png
+        this.defaultNonFilteredFileExtensions = new ArrayList( 5 );
+        this.defaultNonFilteredFileExtensions.add( "jpg" );
+        this.defaultNonFilteredFileExtensions.add( "jpeg" );
+        this.defaultNonFilteredFileExtensions.add( "gif" );
+        this.defaultNonFilteredFileExtensions.add( "bmp" );
+        this.defaultNonFilteredFileExtensions.add( "png" );
+    }    
+    
+    
+    
     /**
      * @plexus.requirement
      *  role-hint="default"
@@ -144,13 +167,19 @@ public class DefaultMavenResourcesFiltering
     }
 
     
-    private boolean filteredFileExtension(File file, List nonFilteredFileExtensions)
+    private boolean filteredFileExtension( File file, List userNonFilteredFileExtensions )
     {
-        if (nonFilteredFileExtensions == null)
+        List nonFilteredFileExtensions = new ArrayList( getDefaultNonFilteredFileExtensions() );
+        if ( userNonFilteredFileExtensions != null )
         {
-            return true;
+            nonFilteredFileExtensions.addAll( userNonFilteredFileExtensions );
         }
-        return !nonFilteredFileExtensions.contains( FileUtils.extension( file.getName() ) );
+        return !nonFilteredFileExtensions.contains( StringUtils.lowerCase( FileUtils.extension( file.getName() ) ) );
+    }
+
+    public List getDefaultNonFilteredFileExtensions()
+    {
+        return this.defaultNonFilteredFileExtensions;
     }
     
     
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
index 080c9ee..be0b638 100755
--- a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
@@ -57,4 +57,10 @@ public interface MavenResourcesFiltering
     void filterResources( List resources, File outputDirectory, String encoding, List filterWrappers,
                           File resourcesBaseDirectory, List nonFilteredFileExtensions )
         throws MavenFilteringException;    
+    
+    /**
+     * return the List of the non filtered extensions (jpg,jpeg,gif,bmp,png)
+     * @return {@link List} of {@link String}
+     */
+    public List getDefaultNonFilteredFileExtensions();
 }

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 17/44: move a method from private to public

hboutemy
In reply to this post by hboutemy
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 b1eca6ce084f95340f85b3bdc7c570fc4aa2794a
Author: Oliver Lamy <[hidden email]>
AuthorDate: Sun Feb 17 21:43:20 2008 +0000

    move a method from private to public
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@628553 13f79535-47bb-0310-9956-ffa450edef68
---
 .../maven/shared/filtering/DefaultMavenResourcesFiltering.java      | 6 +++---
 .../org/apache/maven/shared/filtering/MavenResourcesFiltering.java  | 2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
index f9122c5..3449e2f 100755
--- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
@@ -158,7 +158,7 @@ public class DefaultMavenResourcesFiltering
                 {
                     destinationFile.getParentFile().mkdirs();
                 }
-                boolean filteredExt = filteredFileExtension( source, nonFilteredFileExtensions );
+                boolean filteredExt = filteredFileExtension( source.getName(), nonFilteredFileExtensions );
                 mavenFileFilter.copyFile( source, destinationFile, resource.isFiltering() && filteredExt,
                                           filterWrappers, encoding );
             }
@@ -167,14 +167,14 @@ public class DefaultMavenResourcesFiltering
     }
 
     
-    private boolean filteredFileExtension( File file, List userNonFilteredFileExtensions )
+    public boolean filteredFileExtension( String fileName, List userNonFilteredFileExtensions )
     {
         List nonFilteredFileExtensions = new ArrayList( getDefaultNonFilteredFileExtensions() );
         if ( userNonFilteredFileExtensions != null )
         {
             nonFilteredFileExtensions.addAll( userNonFilteredFileExtensions );
         }
-        return !nonFilteredFileExtensions.contains( StringUtils.lowerCase( FileUtils.extension( file.getName() ) ) );
+        return !nonFilteredFileExtensions.contains( StringUtils.lowerCase( FileUtils.extension( fileName ) ) );
     }
 
     public List getDefaultNonFilteredFileExtensions()
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
index be0b638..843ed86 100755
--- a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
@@ -63,4 +63,6 @@ public interface MavenResourcesFiltering
      * @return {@link List} of {@link String}
      */
     public List getDefaultNonFilteredFileExtensions();
+    
+    boolean filteredFileExtension( String fileName, List userNonFilteredFileExtensions );
 }

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 18/44: update documentation merge duplicate code

hboutemy
In reply to this post by hboutemy
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 9447d00a721cae20e62abed5fbd8bfd91dd8e39a
Author: Oliver Lamy <[hidden email]>
AuthorDate: Mon Feb 18 22:19:43 2008 +0000

    update documentation
    merge duplicate code
   
   
   
    git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@628894 13f79535-47bb-0310-9956-ffa450edef68
---
 .../shared/filtering/DefaultMavenFileFilter.java   | 83 ++++++++--------------
 .../maven/shared/filtering/MavenFileFilter.java    |  1 -
 .../shared/filtering/MavenResourcesFiltering.java  | 14 ++--
 .../maven/shared/filtering/PropertyUtils.java      |  4 ++
 src/site/apt/index.apt                             | 24 +++++--
 5 files changed, 61 insertions(+), 65 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
index bf7709b..a089ab9 100755
--- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
@@ -87,69 +87,20 @@ public class DefaultMavenFileFilter
         filterProperties.putAll( System.getProperties() );
 
         // Project properties
-        filterProperties.putAll( mavenProject.getProperties() == null ? Collections.EMPTY_MAP : mavenProject.getProperties() );
+        filterProperties.putAll( mavenProject.getProperties() == null ? Collections.EMPTY_MAP : mavenProject
+            .getProperties() );
 
         // Take a copy of filterProperties to ensure that evaluated filterTokens are not propagated
         // to subsequent filter files. NB this replicates current behaviour and seems to make sense.
         final Properties baseProps = new Properties();
         baseProps.putAll( filterProperties );
 
-        if ( filters != null )
-        {
-            for ( Iterator i = filters.iterator(); i.hasNext(); )
-            {
-                String filterfile = (String) i.next();
-                try
-                {
-                    Properties properties = PropertyUtils.loadPropertyFile( new File( filterfile ), baseProps );
-                    filterProperties.putAll( properties );
-                }
-                catch ( IOException e )
-                {
-                    throw new MavenFilteringException( "Error loading property file '" + filterfile + "'", e );
-                }
-            }
-        }
-        
-        List buildFilters = mavenProject.getFilters();
-        if ( buildFilters != null )
-        {
-            for ( Iterator iterator = buildFilters.iterator(); iterator.hasNext(); )
-            {
-                String filterFile = (String) iterator.next();
-                try
-                {
+        loadProperties( filterProperties, filters, baseProps );
 
-                    Properties properties = PropertyUtils.loadPropertyFile( new File( filterFile ), baseProps );
-                    filterProperties.putAll( properties );
-                }
-                catch ( IOException e )
-                {
-                    throw new MavenFilteringException( "Error loading property file '" + filterFile + "'", e );
-                }
-            }
-        }
+        loadProperties( filterProperties, mavenProject.getFilters(), baseProps );
 
-        buildFilters = mavenProject.getBuild().getFilters();
-        if ( buildFilters != null )
-        {
-            for ( Iterator iterator = buildFilters.iterator(); iterator.hasNext(); )
-            {
-                String filterFile = (String) iterator.next();
-                try
-                {
+        loadProperties( filterProperties, mavenProject.getBuild().getFilters(), baseProps );
 
-                    Properties properties = PropertyUtils.loadPropertyFile( new File( filterFile ), baseProps );
-                    filterProperties.putAll( properties );
-                }
-                catch ( IOException e )
-                {
-                    throw new MavenFilteringException( "Error loading property file '" + filterFile + "'", e );
-                }
-            }
-        }
-
-      
         List defaultFilterWrappers = new ArrayList( 3 );
 
         // support ${token}
@@ -181,10 +132,32 @@ public class DefaultMavenFileFilter
                 return new InterpolationFilterReader( reader, reflectionProperties, "${", "}" );
             }
         };
-        
+
         defaultFilterWrappers.add( third );
 
         return defaultFilterWrappers;
     }
 
+    private void loadProperties( Properties filterProperties, List /*String*/propertiesFilePaths, Properties baseProps )
+        throws MavenFilteringException
+    {
+        if ( propertiesFilePaths != null )
+        {
+            for ( Iterator iterator = propertiesFilePaths.iterator(); iterator.hasNext(); )
+            {
+                String filterFile = (String) iterator.next();
+                try
+                {
+                    // TODO new File should be new File(mavenProject.getBasedir(), filterfile ) ?
+                    Properties properties = PropertyUtils.loadPropertyFile( new File( filterFile ), baseProps );
+                    filterProperties.putAll( properties );
+                }
+                catch ( IOException e )
+                {
+                    throw new MavenFilteringException( "Error loading property file '" + filterFile + "'", e );
+                }
+            }
+        }
+    }
+
 }
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
index a1f8c81..8c17c08 100755
--- a/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
@@ -20,7 +20,6 @@ package org.apache.maven.shared.filtering;
  */
 
 import java.io.File;
-import java.io.IOException;
 import java.util.List;
 
 import org.apache.maven.project.MavenProject;
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
index 843ed86..498b936 100755
--- a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
@@ -35,8 +35,8 @@ public interface MavenResourcesFiltering
     /**
      * @param resources {@link List} of {@link org.apache.maven.model.Resource}
      * @param outputDirectory parent destination directory
-     * @param mavenProject
-     * @param encoding
+     * @param mavenProject the maven project
+     * @param encoding encoding to use for writing files
      * @param fileFilters {@link List} of String which are path to a Property file
      * @param nonFilteredFileExtensions {@link List} of String for non filtered file extensions
      * @throws MavenFilteringException
@@ -48,7 +48,7 @@ public interface MavenResourcesFiltering
     /**
      * @param resources {@link List} of {@link org.apache.maven.model.Resource}
      * @param outputDirectory parent destination directory
-     * @param encoding
+     * @param encoding encoding to use for writing files
      * @param filterWrappers {@link List} of FileUtils.FilterWrapper
      * @param resourcesBaseDirectory baseDirectory of resources
      * @param nonFilteredFileExtensions {@link List} of String for non filtered file extensions
@@ -62,7 +62,13 @@ public interface MavenResourcesFiltering
      * return the List of the non filtered extensions (jpg,jpeg,gif,bmp,png)
      * @return {@link List} of {@link String}
      */
-    public List getDefaultNonFilteredFileExtensions();
+    List getDefaultNonFilteredFileExtensions();
     
+    /**
+     * @param fileName the file name
+     * @param userNonFilteredFileExtensions an extra list of file extensions
+     * @return true if filtering can be apply to the file (means extensions.lowerCase is in the
+     *         default List or in the user defined extension List)
+     */
     boolean filteredFileExtension( String fileName, List userNonFilteredFileExtensions );
 }
diff --git a/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java b/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
index 8e7ada0..8dff312 100755
--- a/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
+++ b/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
@@ -106,6 +106,7 @@ public final class PropertyUtils
      * @param fail wheter to throw an exception when the file cannot be loaded or to return null
      * @param useSystemProps wheter to incorporate System.getProperties settings into the returned Properties object.
      * @return the loaded and fully resolved Properties object
+     * @throws IOException if profile does not exist, or cannot be read.
      */
     public static Properties loadPropertyFile( File propfile, boolean fail, boolean useSystemProps )
         throws IOException
@@ -149,6 +150,9 @@ public final class PropertyUtils
      * the value of a property contains a key), and will
      * not loop endlessly on a pair like
      * test = ${test}.
+     * @param k
+     * @param p
+     * @return
      */
     private static String getPropertyValue( String k, Properties p )
     {
diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt
index 5a1354c..709d13d 100755
--- a/src/site/apt/index.apt
+++ b/src/site/apt/index.apt
@@ -25,14 +25,17 @@
 
 Maven Filtering Component
 
-  This Plexus components has been build with the filtering process coming from the maven-resources-plugin.
+  This Plexus components has been build with the filtering process/code coming from the maven-resources-plugin.
   
   The goal is to provide a common way for all plugins which needs to filtering resources.
   
 * Component MavenResourcesFiltering
 
   This component will apply filtering on a List of org.apache.maven.model.Resource.
-  The method without the filterWrappers parameter will interpolate the files using the default FileUtils.FilterWrapper.
+  
+  The method without the filterWrappers parameter will interpolate the files using the default List of FileUtils.FilterWrapper (see above).
+  
+  The component will not filtering some predefined file extensions (jpg,jpeg,gif,bmp,png). Note : you can easily add extra file extensions.
 
 * Component MavenFileFilter
 
@@ -47,6 +50,17 @@ Maven Filtering Component
     
     []
     
-    <<NOTE>> : The sentence "values from SystemProps, project.properties, filters, project.filters and project.build.filters"
-    means pairs of key/value will be loaded/overriding with this order. The value for key java.version can be overriding
-    with a property in the maven project (yes crazy but possible).
\ No newline at end of file
+    The values (Properties object) used for interpolation are loaded with the following order :
+    
+    * System Properties
+    
+    * List of properties ( the method has a parameter which accept a List of String -> path properties files )
+    
+    * pom.filters
+    
+    * pom.build.filters
+    
+    []
+    
+    <<NOTE>> : As it's a Properties object, last defined key/value pair wins .
+    The value for key java.version can be overriding with a property in the maven project (yes crazy but possible).
\ No newline at end of file

Reply | Threaded
Open this post in threaded view
|

[maven-filtering] 19/44: add : - unit with adding token - test escaping windows path - usage page with code samples

hboutemy
In reply to this post by hboutemy
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 <[hidden email]>
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:[hidden email]">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}
+pomName=@pom.name@
\ No newline at end of file

123