You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ke...@apache.org on 2006/11/17 01:31:34 UTC

svn commit: r476000 - in /maven/plugins/trunk/maven-resources-plugin/src: main/java/org/apache/maven/plugin/resources/ResourcesMojo.java test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java

Author: kenney
Date: Thu Nov 16 16:31:34 2006
New Revision: 476000

URL: http://svn.apache.org/viewvc?view=rev&rev=476000
Log:
Fixed broken unit tests - it assumed 100 chars. Now done properly.

Fixed message 'Copying X resources to null'.

Modified:
    maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java
    maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java

Modified: maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java?view=diff&rev=476000&r1=475999&r2=476000
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java (original)
+++ maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java Thu Nov 16 16:31:34 2006
@@ -116,7 +116,7 @@
         }
         else
         {
-            getLog().info( "Using encoding: \'" + encoding + "\' to copy filtered resources." );
+            getLog().info( "Using '" + encoding + "' to copy filtered resources." );
         }
         
         for ( Iterator i = resources.iterator(); i.hasNext(); )
@@ -129,6 +129,7 @@
 
             if ( !resourceDirectory.exists() )
             {
+                getLog().info( "Resource directory does not exist: " + resourceDirectory );
                 continue;
             }
 
@@ -154,6 +155,7 @@
             {
                 scanner.setIncludes( DEFAULT_INCLUDES );
             }
+
             if ( resource.getExcludes() != null && !resource.getExcludes().isEmpty() )
             {
                 scanner.setExcludes( (String[]) resource.getExcludes().toArray( EMPTY_STRING_ARRAY ) );
@@ -163,6 +165,11 @@
             scanner.scan();
 
             List includedFiles = Arrays.asList( scanner.getIncludedFiles() );
+
+            getLog().info( "Copying " + includedFiles.size() + " resource"
+                + ( includedFiles.size() > 1 ? "s" : "" )
+                + ( targetPath == null ? "" : " to " + targetPath ) );
+
             for ( Iterator j = includedFiles.iterator(); j.hasNext(); )
             {
                 String name = (String) j.next();

Modified: maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java?view=diff&rev=476000&r1=475999&r2=476000
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java (original)
+++ maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java Thu Nov 16 16:31:34 2006
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
@@ -313,8 +314,7 @@
         String resourcesDir = project.getOutputDirectory();
         String checkString = "current working directory = " + (String) System.getProperty( "user.dir" );
 
-        assertTrue( FileUtils.fileExists( resourcesDir + "/file4.txt" ) );
-        assertTrue( fileContains( resourcesDir + "/file4.txt", checkString ) );
+        assertContent( resourcesDir + "/file4.txt", checkString );
     }
 
     /**
@@ -345,8 +345,7 @@
         String resourcesDir = project.getOutputDirectory();
         String checkString = "current working directory = FPJ kami!!!";
 
-        assertTrue( FileUtils.fileExists( resourcesDir + "/file4.txt" ) );
-        assertTrue( fileContains( resourcesDir + "/file4.txt", checkString ) );
+        assertContent( resourcesDir + "/file4.txt", checkString );
     }
 
     /**
@@ -380,8 +379,7 @@
         String resourcesDir = project.getOutputDirectory();
         String checkString = "current working directory=c\\:\\\\\\\\org\\\\apache\\\\test";
 
-        assertTrue( FileUtils.fileExists( resourcesDir + "/file4.properties" ) );
-        assertTrue( fileContains( resourcesDir + "/file4.properties", checkString ) );
+        assertContent( resourcesDir + "/file4.properties", checkString );
     }
 
     /**
@@ -414,37 +412,17 @@
         String resourcesDir = project.getOutputDirectory();
         String checkString = "current working directory=testdir";
 
-        assertTrue( FileUtils.fileExists( resourcesDir + "/file4.properties" ) );
-        assertTrue( fileContains( resourcesDir + "/file4.properties", checkString ) );
+        assertContent( resourcesDir + "/file4.properties", checkString );
     }
 
-    // reads the first line of the file and compares it
-    // with data. returns true if equal
-    private boolean fileContains( String fileName, String data )
-    {
-        boolean bRetVal = false;
-
-        try
-        {
-            File file = new File( fileName );
-            FileReader reader = new FileReader( file );
-            char[] readChar = new char[100];
-            String readString;
-            int readSize;
-
-            readSize = reader.read( readChar );
-            readString = new String( readChar, 0, readSize );
-
-            if ( data.equals( readString ) )
-            {
-                bRetVal = true;
-            }
-        }
-        catch ( IOException io )
-        {
-            // TODO: handle exception
-        }
+    /**
+     * Ensures the file exists and its first line equals the given data.
+     */
+    private void assertContent( String fileName, String data )
+        throws IOException
+    {
+        assertTrue( FileUtils.fileExists( fileName ) );
 
-        return bRetVal;
+        assertEquals( data, new BufferedReader( new FileReader( fileName ) ).readLine() );
     }
 }