maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From belling...@apache.org
Subject svn commit: r553475 - in /maven/plugins/trunk/maven-assembly-plugin/src: main/java/org/apache/maven/plugin/assembly/archive/task/ main/java/org/apache/maven/plugin/assembly/format/ main/java/org/apache/maven/plugin/assembly/utils/ test/java/org/apache/...
Date Thu, 05 Jul 2007 12:28:21 GMT
Author: bellingard
Date: Thu Jul  5 05:28:20 2007
New Revision: 553475

URL: http://svn.apache.org/viewvc?view=rev&rev=553475
Log:
[MASSEMBLY-154] FileSet does not support filtering
Based on patch provided by Mikhail Krangach + Unit test added

Modified:
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddFileSetsTask.java
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileSetFormatter.java
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java
    maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java

Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddFileSetsTask.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddFileSetsTask.java?view=diff&rev=553475&r1=553474&r2=553475
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddFileSetsTask.java
(original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddFileSetsTask.java
Thu Jul  5 05:28:20 2007
@@ -121,7 +121,9 @@
             task.setDirectoryMode( TypeConversionUtils.modeToInt( fileSet.getDirectoryMode(),
logger ) );
             task.setFileMode( TypeConversionUtils.modeToInt( fileSet.getFileMode(), logger
) );
             task.setUseDefaultExcludes( fileSet.isUseDefaultExcludes() );
-            task.setExcludes( fileSet.getExcludes() );
+            List excludes = fileSet.getExcludes();
+            excludes.add( "**/*.filtered" );
+            task.setExcludes( excludes );
             task.setIncludes( fileSet.getIncludes() );
             task.setOutputDirectory( destDirectory );
 

Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java?view=diff&rev=553475&r1=553474&r2=553475
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java
(original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java
Thu Jul  5 05:28:20 2007
@@ -49,9 +49,13 @@
     public File format( File source, boolean filter, String lineEnding )
         throws AssemblyFormattingException
     {
-        File result = source;
+        return format ( source, filter, lineEnding, configSource.getTemporaryRootDirectory()
);
+    }
 
-        File tempRoot = configSource.getTemporaryRootDirectory();
+    public File format( File source, boolean filter, String lineEnding, File tempRoot )
+        throws AssemblyFormattingException
+    {
+        File result = source;
         
         AssemblyFileUtils.verifyTempDirectoryAvailability( tempRoot, logger );
 

Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileSetFormatter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileSetFormatter.java?view=diff&rev=553475&r1=553474&r2=553475
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileSetFormatter.java
(original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileSetFormatter.java
Thu Jul  5 05:28:20 2007
@@ -37,8 +37,9 @@
         
         String lineEnding = AssemblyFileUtils.getLineEndingCharacters( lineEndingHint );
 
-        if ( lineEnding != null )
+        if ( lineEnding != null || set.isFiltered() )
         {
+            
             FileSet fileSet = new FileSet();
             fileSet.setLineEnding( lineEnding );
             fileSet.setDirectory( set.getDirectory() );
@@ -65,6 +66,7 @@
                 return archiveBaseDir;
             }
             
+            FileFormatter fileFormatter = new FileFormatter( configSource, logger );
             for ( int i = 0; i < files.length; i++ )
             {
                 String file = files[i];
@@ -74,18 +76,8 @@
                 targetFile.getParentFile().mkdirs();
 
                 File sourceFile = new File( archiveBaseDir, file );
-                
-                Reader sourceReader = null;
-                try
-                {
-                    sourceReader = new BufferedReader( new FileReader( sourceFile ) );
-                    
-                    AssemblyFileUtils.convertLineEndings( sourceReader, targetFile, lineEnding
);
-                }
-                finally
-                {
-                    IOUtil.close( sourceReader );
-                }
+                sourceFile = fileFormatter.format( sourceFile, set.isFiltered(), lineEndingHint,
formattedDir );
+                AssemblyFileUtils.copyFile(sourceFile,targetFile);
             }
         }
 

Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java?view=diff&rev=553475&r1=553474&r2=553475
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java
(original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java
Thu Jul  5 05:28:20 2007
@@ -1,5 +1,14 @@
 package org.apache.maven.plugin.assembly.utils;
 
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.io.Reader;
+import java.nio.channels.FileChannel;
+
 import org.apache.maven.plugin.assembly.archive.ArchiveExpansionException;
 import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
 import org.codehaus.plexus.archiver.ArchiverException;
@@ -9,13 +18,6 @@
 import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.util.IOUtil;
 
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Reader;
-
 public final class AssemblyFileUtils
 {
 
@@ -133,4 +135,19 @@
 
         return value;
     }
+    
+    public static void copyFile( File src, File dst ) throws IOException
+    {
+        FileChannel c1 = new RandomAccessFile( src, "r" ).getChannel();
+        FileChannel c2 = new RandomAccessFile( dst, "rw" ).getChannel();
+
+        long tCount = 0, size = c1.size();
+        while ( ( tCount += c2.transferFrom( c1, 0, size - tCount ) ) < size )
+            ;
+
+        c1.close();
+        c2.force( true );
+        c2.close();
+    }   
+    
 }

Modified: maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java?view=diff&rev=553475&r1=553474&r2=553475
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java
(original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java
Thu Jul  5 05:28:20 2007
@@ -2,14 +2,19 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 
 import junit.framework.TestCase;
 
+import org.apache.maven.model.Model;
 import org.apache.maven.plugin.assembly.AssemblerConfigurationSource;
 import org.apache.maven.plugin.assembly.model.FileSet;
 import org.apache.maven.plugin.assembly.testutils.MockManager;
 import org.apache.maven.plugin.assembly.testutils.TestFileManager;
 import org.apache.maven.plugin.assembly.utils.AssemblyFileUtils;
+import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.logging.console.ConsoleLogger;
 import org.easymock.MockControl;
@@ -202,4 +207,55 @@
         fileManager.assertFileExistence( result, filename2, false );
     }
 
+    public void testShouldFilterSeveralFiles() throws IOException, AssemblyFormattingException
+    {
+        File basedir = fileManager.createTempDir();
+
+        String filename1 = "one.txt";
+        String filename2 = "two.txt";
+
+        // this file will be filtered with a project expression
+        fileManager.createFile( basedir, filename1, "This is the filtered artifactId: ${project.artifactId}."
);
+        // this one fill be filtered with a filter file
+        fileManager.createFile( basedir, filename2, "This is the filtered 'foo' property:
${foo}." );
+        File filterProps = fileManager.createFile( basedir, "filter.properties", "foo=bar"
);
+
+        FileSet fs = new FileSet();
+        fs.setFiltered( true );
+        fs.setDirectory( basedir.getCanonicalPath() );
+        fs.addInclude( "**/*.txt" );
+
+        enableBasicFilteringConfiguration( basedir, Collections.singletonList( filterProps.getCanonicalPath()
) );
+
+        mockManager.replayAll();
+
+        FileSetFormatter formatter = new FileSetFormatter( configSource, logger );
+        File result = formatter.formatFileSetForAssembly( basedir, fs );
+
+        fileManager.assertFileContents( result, filename1, "This is the filtered artifactId:
artifact." );
+        fileManager.assertFileContents( result, filename2, "This is the filtered 'foo' property:
bar." );
+
+        mockManager.verifyAll();
+    }
+
+    private void enableBasicFilteringConfiguration( File basedir, List filterFilenames )
+    {
+        configSource.getTemporaryRootDirectory();
+        configSourceControl.setReturnValue( basedir );
+
+        Model model = new Model();
+        model.setArtifactId( "artifact" );
+        model.setGroupId( "group" );
+        model.setVersion( "version" );
+
+        MavenProject project = new MavenProject( model );
+
+        configSource.getProject();
+        configSourceControl.setReturnValue( project, MockControl.ONE_OR_MORE );
+
+        // list of filenames that contain filter definitions.
+        configSource.getFilters();
+        configSourceControl.setReturnValue( filterFilenames );
+    }
+    
 }



Mime
View raw message