diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollection.java index 21eb6af4..8850d52e 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollection.java @@ -64,6 +64,8 @@ public InputStream transform( @Nonnull PlexusIoResource resource, @Nonnull Input private FileMapper[] fileMappers; private InputStreamTransformer streamTransformer = identityTransformer; + + private String fileSuffix; protected AbstractPlexusIoResourceCollection() { @@ -246,6 +248,22 @@ public void setFileMappers( FileMapper[] fileMappers ) { this.fileMappers = fileMappers; } + + /** + * Returns the suffix apply to files, may be empty + */ + public String getFileSuffix() + { + return fileSuffix; + } + + /** + * Add some suffix to file when it's copying + */ + public void setFileSuffix(String fileSuffix) + { + this.fileSuffix = fileSuffix; + } public Iterator iterator() { diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java index fb0d228b..c71cb1a8 100755 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java @@ -149,6 +149,8 @@ private void addResources( List result, String[] resources, for ( String name : resources ) { String sourceDir = name.replace( '\\', '/' ); + + name = addFileNameSuffix( name ); File f = new File( dir, sourceDir ); @@ -185,6 +187,7 @@ private void addResourcesJava7( List result, String[] resource for ( String name : resources ) { String sourceDir = name.replace( '\\', '/' ); + name = addFileNameSuffix( name ); File f = new File( dir, sourceDir ); PlexusIoResourceAttributes attrs = new Java7FileAttributes( f, cache1, cache2 ); @@ -279,4 +282,32 @@ public Iterator getResources() return result.iterator(); } } + + /** + * Add a suffix to fileName (eg : test.xml => testSuffix.xml) + * Warning : the extension of the file is calculated after the first "dot" caracter. + * Example : + *
    + *
  • test.tar.gz => testSuffix.tar.gz
  • + *
  • test.any.of.extension => testSuffix.any.of.extension
  • + *
+ */ + private String addFileNameSuffix( String name ) + { + String nameWithSuffix = name; + if ( StringUtils.isNotBlank( getFileSuffix()) ) + { + if ( name.contains( "." ) ) + { + String beforeExtension = name.substring( 0, name.indexOf('.') ); + String afterExtension = name.substring( name.indexOf('.') + 1) ; + nameWithSuffix = beforeExtension + getFileSuffix() + "." + afterExtension; + } + else + { + nameWithSuffix += getFileSuffix(); + } + } + return nameWithSuffix; + } } diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollectionTest.java new file mode 100644 index 00000000..7cb3ab3d --- /dev/null +++ b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollectionTest.java @@ -0,0 +1,53 @@ +package org.codehaus.plexus.components.io.resources; + +import java.io.File; + +import org.codehaus.plexus.PlexusTestCase; + +public class PlexusIoFileResourceCollectionTest + extends PlexusTestCase +{ + + public void testWithFileSuffix() + throws Exception + { + PlexusIoFileResourceCollection resourceCollection = new PlexusIoFileResourceCollection(); + resourceCollection.setBaseDir(new File("src/test/resources") ); + resourceCollection.setFileSuffix("TEST"); + resourceCollection.setIncludes(new String[] {"Test-p1.txt"}); + final PlexusIoFileResource entry = (PlexusIoFileResource) resourceCollection.getResources().next(); + assertEquals( "Test-p1TEST.txt", entry.getName() ); + } + + public void testWithNoFileSuffix() + throws Exception + { + PlexusIoFileResourceCollection resourceCollection = new PlexusIoFileResourceCollection(); + resourceCollection.setBaseDir(new File("src/test/resources") ); + resourceCollection.setIncludes(new String[] {"Test-p1.txt"}); + final PlexusIoFileResource entry = (PlexusIoFileResource) resourceCollection.getResources().next(); + assertEquals( "Test-p1.txt", entry.getName() ); + } + + public void testWithFileWith2Dot() + throws Exception + { + PlexusIoFileResourceCollection resourceCollection = new PlexusIoFileResourceCollection(); + resourceCollection.setBaseDir(new File("src/test/resources") ); + resourceCollection.setIncludes(new String[] {"test.tar.gz"}); + resourceCollection.setFileSuffix("_2"); + final PlexusIoFileResource entry = (PlexusIoFileResource) resourceCollection.getResources().next(); + assertEquals( "test_2.tar.gz", entry.getName() ); + } + + public void testWithFileWith3Dot() + throws Exception + { + PlexusIoFileResourceCollection resourceCollection = new PlexusIoFileResourceCollection(); + resourceCollection.setBaseDir(new File("src/test/resources") ); + resourceCollection.setIncludes(new String[] {"test.any.of.extension"}); + resourceCollection.setFileSuffix("Suffix"); + final PlexusIoFileResource entry = (PlexusIoFileResource) resourceCollection.getResources().next(); + assertEquals( "testSuffix.any.of.extension", entry.getName() ); + } +} diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoZipFileResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoZipFileResourceCollectionTest.java index 9d12b62c..2d793863 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoZipFileResourceCollectionTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoZipFileResourceCollectionTest.java @@ -24,7 +24,6 @@ public void testNamelessRootFolder() Iterator iterator = resourceCollection.getResources(); PlexusIoURLResource entry = (PlexusIoURLResource) iterator.next(); assertEquals( "/dummy.txt", entry.getName() ); - final URL url = entry.getURL(); BufferedReader d = new BufferedReader( new InputStreamReader( entry.getContents() ) ); assertEquals( "dummy content", d.readLine() ); } @@ -78,7 +77,6 @@ public void testFilesThatAreNotThere() { final PlexusIoResource next = entries.next(); assertTrue( next.getName() + "was not present", seen.remove( next.getName() ) ); - final URL url = next.getURL(); final InputStream contents = next.getContents(); contents.close(); } diff --git a/src/test/resources/test.any.of.extension b/src/test/resources/test.any.of.extension new file mode 100644 index 00000000..6430814e --- /dev/null +++ b/src/test/resources/test.any.of.extension @@ -0,0 +1,38 @@ +/home/bamboo/agent1/xml-data/build-dir/PARALLEL-CH1/checkout/spi/target/classes: +totalt 0 +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 . +drwxr-xr-x 4 1003 1002 80 2010-04-23 11:24 .. +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 org + +/home/bamboo/agent1/xml-data/build-dir/PARALLEL-CH1/checkout/spi/target/classes/org: +totalt 0 +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 . +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 .. +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 chromattic + +/home/bamboo/agent1/xml-data/build-dir/PARALLEL-CH1/checkout/spi/target/classes/org/chromattic: +totalt 0 +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 . +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 .. +drwxr-xr-x 4 1003 1002 80 2010-04-23 11:24 spi +build 23-Apr-2010 11:24:41 +/home/bamboo/agent1/xml-data/build-dir/PARALLEL-CH1/checkout/spi/target/classes/org/chromattic/spi: +totalt 0 +drwxr-xr-x 4 1003 1002 80 2010-04-23 11:24 . +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 .. +drwxr-xr-x 2 1003 1002 100 2010-04-23 11:24 instrument +drwxr-xr-x 2 1003 1002 60 2010-04-23 11:24 jcr +build 23-Apr-2010 11:24:41 +/home/bamboo/agent1/xml-data/build-dir/PARALLEL-CH1/checkout/spi/target/classes/org/chromattic/spi/instrument: +totalt 12 +drwxr-xr-x 2 1003 1002 100 2010-04-23 11:24 . +drwxr-xr-x 4 1003 1002 80 2010-04-23 11:24 .. +-rw-r--r-- 1 1003 1002 432 2010-04-23 11:24 Instrumentor.class +-rw-r--r-- 1 1003 1002 288 2010-04-23 11:24 MethodHandler.class +-rw-r--r-- 1 1003 1002 349 2010-04-23 11:24 ProxyFactory.class +build 23-Apr-2010 11:24:41 +/home/bamboo/agent1/xml-data/build-dir/PARALLEL-CH1/checkout/spi/target/classes/org/chromattic/spi/jcr: +totalt 4 +drwxr-xr-x 2 1003 1002 60 2010-04-23 11:24 . +drwxr-xr-x 4 1003 1002 80 2010-04-23 11:24 .. +-rw-r--r-- 1 1003 1002 508 2010-04-23 11:24 SessionLifeCycle.class diff --git a/src/test/resources/test.tar.gz b/src/test/resources/test.tar.gz new file mode 100644 index 00000000..6430814e --- /dev/null +++ b/src/test/resources/test.tar.gz @@ -0,0 +1,38 @@ +/home/bamboo/agent1/xml-data/build-dir/PARALLEL-CH1/checkout/spi/target/classes: +totalt 0 +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 . +drwxr-xr-x 4 1003 1002 80 2010-04-23 11:24 .. +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 org + +/home/bamboo/agent1/xml-data/build-dir/PARALLEL-CH1/checkout/spi/target/classes/org: +totalt 0 +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 . +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 .. +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 chromattic + +/home/bamboo/agent1/xml-data/build-dir/PARALLEL-CH1/checkout/spi/target/classes/org/chromattic: +totalt 0 +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 . +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 .. +drwxr-xr-x 4 1003 1002 80 2010-04-23 11:24 spi +build 23-Apr-2010 11:24:41 +/home/bamboo/agent1/xml-data/build-dir/PARALLEL-CH1/checkout/spi/target/classes/org/chromattic/spi: +totalt 0 +drwxr-xr-x 4 1003 1002 80 2010-04-23 11:24 . +drwxr-xr-x 3 1003 1002 60 2010-04-23 11:24 .. +drwxr-xr-x 2 1003 1002 100 2010-04-23 11:24 instrument +drwxr-xr-x 2 1003 1002 60 2010-04-23 11:24 jcr +build 23-Apr-2010 11:24:41 +/home/bamboo/agent1/xml-data/build-dir/PARALLEL-CH1/checkout/spi/target/classes/org/chromattic/spi/instrument: +totalt 12 +drwxr-xr-x 2 1003 1002 100 2010-04-23 11:24 . +drwxr-xr-x 4 1003 1002 80 2010-04-23 11:24 .. +-rw-r--r-- 1 1003 1002 432 2010-04-23 11:24 Instrumentor.class +-rw-r--r-- 1 1003 1002 288 2010-04-23 11:24 MethodHandler.class +-rw-r--r-- 1 1003 1002 349 2010-04-23 11:24 ProxyFactory.class +build 23-Apr-2010 11:24:41 +/home/bamboo/agent1/xml-data/build-dir/PARALLEL-CH1/checkout/spi/target/classes/org/chromattic/spi/jcr: +totalt 4 +drwxr-xr-x 2 1003 1002 60 2010-04-23 11:24 . +drwxr-xr-x 4 1003 1002 80 2010-04-23 11:24 .. +-rw-r--r-- 1 1003 1002 508 2010-04-23 11:24 SessionLifeCycle.class