Skip to content

[MASSEMBLY-617] add ability to give a fileSuffix to a AbstractPlexusI… #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public InputStream transform( @Nonnull PlexusIoResource resource, @Nonnull Input
private FileMapper[] fileMappers;

private InputStreamTransformer streamTransformer = identityTransformer;

private String fileSuffix;

protected AbstractPlexusIoResourceCollection()
{
Expand Down Expand Up @@ -245,6 +247,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<PlexusIoResource> iterator()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private void addResources( List<PlexusIoResource> result, String[] resources )
for ( String name : resources )
{
String sourceDir = name.replace( '\\', '/' );
name = addFileNameSuffix( name );
File f = new File( dir, sourceDir );

PlexusIoResourceAttributes attrs = new FileAttributes( f, cache1, cache2 );
Expand Down Expand Up @@ -259,4 +260,32 @@ public boolean isConcurrentAccessSupported()
{
return true;
}

/**
* Add a suffix to fileName (eg : test.xml => testSuffix.xml)
* Warning : the extension of the file is calculated after the first "dot" caracter.
* Example :
* <ul>
* <li>test.tar.gz => testSuffix.tar.gz</li>
* <li>test.any.of.extension => testSuffix.any.of.extension</li>
* </ul>
*/
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;
}
}
Original file line number Diff line number Diff line change
@@ -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() );
}
}
38 changes: 38 additions & 0 deletions src/test/resources/Test-p1.txt
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/test/resources/test.any.of.extension
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
1 change: 1 addition & 0 deletions src/test/resources/test.tar.gz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test