Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -64,6 +64,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 @@ -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<PlexusIoResource> iterator()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ private void addResources( List<PlexusIoResource> result, String[] resources,
for ( String name : resources )
{
String sourceDir = name.replace( '\\', '/' );

name = addFileNameSuffix(name);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the whitespace please


File f = new File( dir, sourceDir );

Expand Down Expand Up @@ -185,6 +187,7 @@ private void addResourcesJava7( List<PlexusIoResource> result, String[] resource
for ( String name : resources )
{
String sourceDir = name.replace( '\\', '/' );
name = addFileNameSuffix(name);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

File f = new File( dir, sourceDir );

PlexusIoResourceAttributes attrs = new Java7FileAttributes( f, cache1, cache2 );
Expand Down Expand Up @@ -279,4 +282,26 @@ public Iterator<PlexusIoResource> getResources()
return result.iterator();
}
}

/**
* Add a suffix to fileName (eg : test.xml => testSuffix.xml)
*/
private String addFileNameSuffix(String name)
{
String nameWithSuffix = name;
if (getFileSuffix() != null && getFileSuffix() != "")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use StringUtils from Plexus Utils here.

{
if (name.contains("."))
{
String[] split = name.split("\\.");
String extension = "." + split[split.length-1];
nameWithSuffix = name.replace(extension, getFileSuffix() + extension);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is not reliable. What about tar.gz or similar?

Copy link
Author

@tcollignon tcollignon Jun 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'll fix this, but I must write a rule, I add javadoc explanation

}
else
{
nameWithSuffix += getFileSuffix();
}
}
return nameWithSuffix;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
Expand Down Expand Up @@ -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();
}
Expand Down