[MSHARED-161] DefaultMavenFileFilter.getDefaultFilterWrappers loads filters from the current directory instead of using basedir

git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1566347 13f79535-47bb-0310-9956-ffa450edef68
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 7fbf119..f1de523 100644
--- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
@@ -202,7 +202,9 @@
 
         final Properties filterProperties = new Properties();
 
-        loadProperties( filterProperties, request.getFileFilters(), baseProps );
+        File basedir = request.getMavenProject() != null ? request.getMavenProject().getBasedir() : new File( "." ); 
+
+        loadProperties( filterProperties, basedir, request.getFileFilters(), baseProps );
         if ( filterProperties.size() < 1 )
         {
             filterProperties.putAll( baseProps );
@@ -221,7 +223,7 @@
                     buildFilters.removeAll( request.getFileFilters() );
                 }
 
-                loadProperties( filterProperties, buildFilters, baseProps );
+                loadProperties( filterProperties, basedir, buildFilters, baseProps );
             }
 
             // Project properties
@@ -266,9 +268,9 @@
     }
 
     /**
-     * protected only for testing reason !
+     * default visibility only for testing reason !
      */
-    protected void loadProperties( Properties filterProperties, List<String> propertiesFilePaths, Properties baseProps )
+    void loadProperties( Properties filterProperties, File basedir, List<String> propertiesFilePaths, Properties baseProps )
         throws MavenFilteringException
     {
         if ( propertiesFilePaths != null )
@@ -285,8 +287,8 @@
                 }
                 try
                 {
-                    // TODO new File should be new File(mavenProject.getBasedir(), filterfile ) ?
-                    Properties properties = PropertyUtils.loadPropertyFile( new File( filterFile ), workProperties );
+                    File propFile = FileUtils.resolveFile( basedir, filterFile );
+                    Properties properties = PropertyUtils.loadPropertyFile( propFile, workProperties );
                     filterProperties.putAll( properties );
                     workProperties.putAll( properties );
                 }
diff --git a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java
index 44e35fd..92311cb 100644
--- a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java
+++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java
@@ -20,12 +20,18 @@
  */
 
 import java.io.File;
+import java.io.Reader;
+import java.io.StringReader;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
 
-import org.codehaus.plexus.PlexusTestCase;
+import org.apache.maven.project.MavenProject;
 import org.apache.maven.shared.utils.io.FileUtils;
+import org.apache.maven.shared.utils.io.FileUtils.FilterWrapper;
+import org.apache.maven.shared.utils.io.IOUtil;
+import org.codehaus.plexus.PlexusTestCase;
 
 /**
  * @author Olivier Lamy
@@ -34,6 +40,8 @@
 public class DefaultMavenFileFilterTest
     extends PlexusTestCase
 {
+    
+    
 
     File to = new File( getBasedir(), "target/reflection-test.properties" );
 
@@ -108,7 +116,7 @@
     {
         DefaultMavenFileFilter mavenFileFilter = new DefaultMavenFileFilter();
 
-        File testDir = new File(getBasedir(), "src/test/units-files/MSHARED-177");
+        File testDir = new File( getBasedir(), "src/test/units-files/MSHARED-177" );
 
         List<String> filters = new ArrayList<String>();
 
@@ -118,8 +126,31 @@
 
         final Properties filterProperties = new Properties();
 
-        mavenFileFilter.loadProperties(filterProperties, filters, new Properties() );
+        mavenFileFilter.loadProperties( filterProperties, new File( getBasedir() ), filters, new Properties() );
 
         assertTrue( filterProperties.getProperty( "third_filter_key" ).equals( "first and second" ) );
     }
+    
+
+    // MSHARED-161: DefaultMavenFileFilter.getDefaultFilterWrappers loads
+    // filters from the current directory instead of using basedir
+    public void testMavenBasedir()
+        throws Exception
+    {
+        MavenFileFilter mavenFileFilter = (MavenFileFilter) lookup( MavenFileFilter.class.getName(), "default" );
+
+        AbstractMavenFilteringRequest req = new AbstractMavenFilteringRequest();
+        req.setFileFilters( Collections.singletonList( "src/main/filters/filefilter.properties" ) );
+
+        MavenProject mavenProject = new StubMavenProject( new File( "src/test/units-files/MSHARED-161" ) );
+        mavenProject.getBuild().setFilters( Collections.singletonList( "src/main/filters/buildfilter.properties" ) );
+        req.setMavenProject( mavenProject );
+        req.setInjectProjectBuildFilters( true );
+
+        List<FilterWrapper> wrappers = mavenFileFilter.getDefaultFilterWrappers( req );
+        
+        Reader reader = wrappers.get(0).getReader( new StringReader( "${filefilter} ${buildfilter}" ) );
+        
+        assertEquals( "true true", IOUtil.toString( reader ) );
+    }
 }
diff --git a/src/test/units-files/MSHARED-161/src/main/filters/buildfilter.properties b/src/test/units-files/MSHARED-161/src/main/filters/buildfilter.properties
new file mode 100644
index 0000000..76e25e8
--- /dev/null
+++ b/src/test/units-files/MSHARED-161/src/main/filters/buildfilter.properties
@@ -0,0 +1,19 @@
+#/*

+# * 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.

+# */

+buildfilter=true
\ No newline at end of file
diff --git a/src/test/units-files/MSHARED-161/src/main/filters/filefilter.properties b/src/test/units-files/MSHARED-161/src/main/filters/filefilter.properties
new file mode 100644
index 0000000..50a71e6
--- /dev/null
+++ b/src/test/units-files/MSHARED-161/src/main/filters/filefilter.properties
@@ -0,0 +1,19 @@
+#/*

+# * 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.

+# */

+filefilter=true
\ No newline at end of file