You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by br...@apache.org on 2005/05/26 08:03:12 UTC

svn commit: r178602 - in /maven/components/trunk/maven-plugins/maven-resources-plugin: pom.xml src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java

Author: brett
Date: Wed May 25 23:03:11 2005
New Revision: 178602

URL: http://svn.apache.org/viewcvs?rev=178602&view=rev
Log:
use directory scanner and a sane file copy routine to avoid reading the whole thing into memory first

Modified:
    maven/components/trunk/maven-plugins/maven-resources-plugin/pom.xml
    maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java

Modified: maven/components/trunk/maven-plugins/maven-resources-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-resources-plugin/pom.xml?rev=178602&r1=178601&r2=178602&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-resources-plugin/pom.xml (original)
+++ maven/components/trunk/maven-plugins/maven-resources-plugin/pom.xml Wed May 25 23:03:11 2005
@@ -15,5 +15,10 @@
       <artifactId>maven-model</artifactId>
       <version>2.0-alpha-2</version>
     </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>1.0</version>
+    </dependency>
   </dependencies>
 </model>

Modified: maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java?rev=178602&r1=178601&r2=178602&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java Wed May 25 23:03:11 2005
@@ -16,18 +16,14 @@
  * limitations under the License.
  */
 
+import org.apache.commons.io.FileUtils;
 import org.apache.maven.model.Resource;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
-import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.DirectoryScanner;
 
-import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -45,7 +41,7 @@
 {
     /**
      * The output directory into which to copy the resources.
-     * 
+     *
      * @parameter expression="${project.build.outputDirectory}"
      * @required
      */
@@ -53,12 +49,16 @@
 
     /**
      * The list of resources we want to transfer.
-     * 
+     *
      * @parameter expression="${project.build.resources}"
      * @required
      */
     private List resources;
 
+    private static final String[] EMPTY_STRING_ARRAY = {};
+
+    private static final String[] DEFAULT_INCLUDES = {"**/**"};
+
     public void execute()
         throws MojoExecutionException
     {
@@ -73,7 +73,7 @@
             for ( Iterator i = getJarResources( resources ).entrySet().iterator(); i.hasNext(); )
             {
                 Map.Entry entry = (Map.Entry) i.next();
-                String source = (String) entry.getKey();
+                File source = (File) entry.getKey();
                 String destination = (String) entry.getValue();
 
                 File destinationFile = new File( outputDirectory, destination );
@@ -83,7 +83,7 @@
                     destinationFile.getParentFile().mkdirs();
                 }
 
-                fileCopy( source, destinationFile.getPath() );
+                FileUtils.copyFile( source, destinationFile );
             }
         }
         catch ( Exception e )
@@ -111,34 +111,27 @@
                 continue;
             }
 
-            // If we only have a directory then we want to include
-            // everything we can find within that path.
+            DirectoryScanner scanner = new DirectoryScanner();
+            scanner.addDefaultExcludes();
 
-            String includesAsString = "**/**";
-
-            java.util.List includes = resource.getIncludes();
-            if ( includes != null && includes.size() > 0 )
+            scanner.setBasedir( resource.getDirectory() );
+            if ( resource.getIncludes() != null && !resource.getIncludes().isEmpty() )
             {
-                includesAsString = StringUtils.join( includes.iterator(), "," );
+                scanner.setIncludes( (String[]) resource.getIncludes().toArray( EMPTY_STRING_ARRAY ) );
             }
-
-            List excludes = resource.getExcludes();
-
-            if ( excludes == null )
+            else
             {
-                excludes = resource.getDefaultExcludes();
+                scanner.setIncludes( DEFAULT_INCLUDES );
             }
-            else
+            if ( resource.getExcludes() != null && !resource.getExcludes().isEmpty() )
             {
-                excludes = new ArrayList( excludes );
-                excludes.addAll( resource.getDefaultExcludes() );
+                scanner.setExcludes( (String[]) resource.getExcludes().toArray( EMPTY_STRING_ARRAY ) );
             }
 
-            String excludesAsString = StringUtils.join( excludes.iterator(), "," );
+            scanner.scan();
 
-            List files = FileUtils.getFileNames( resourceDirectory, includesAsString, excludesAsString, false );
-
-            for ( Iterator j = files.iterator(); j.hasNext(); )
+            List includedFiles = Arrays.asList( scanner.getIncludedFiles() );
+            for ( Iterator j = includedFiles.iterator(); j.hasNext(); )
             {
                 String name = (String) j.next();
 
@@ -149,50 +142,11 @@
                     entryName = targetPath + "/" + name;
                 }
 
-                String resourcePath = new File( resource.getDirectory(), name ).getPath();
-
-                resourceEntries.put( resourcePath, entryName );
+                resourceEntries.put( new File( resource.getDirectory(), name ), entryName );
             }
         }
 
         return resourceEntries;
-    }
-
-    public static byte[] fileRead( String fileName )
-        throws IOException
-    {
-        FileInputStream in = new FileInputStream( fileName );
-        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-
-        int count;
-        byte[] b = new byte[512];
-        while ( ( count = in.read( b ) ) > 0 ) // blocking read
-        {
-            buffer.write( b, 0, count );
-        }
-
-        in.close();
-
-        byte[] content = buffer.toByteArray();
-
-        buffer.close();
-
-        return content;
-    }
-
-    public static void fileWrite( String fileName, byte[] data )
-        throws Exception
-    {
-        FileOutputStream out = new FileOutputStream( fileName );
-        out.write( data );
-        out.close();
-    }
-
-    public static void fileCopy( String inFileName, String outFileName )
-        throws Exception
-    {
-        byte[] content = fileRead( inFileName );
-        fileWrite( outFileName, content );
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org