Skip to content

[MASSEMBLY-886] Add fileMappers to BaseFileSet #92

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 2 commits 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 @@ -346,6 +346,7 @@ public void addFileSet( @Nonnull final FileSet fileSet )
collection.setCaseSensitive( fileSet.isCaseSensitive() );
collection.setUsingDefaultExcludes( fileSet.isUsingDefaultExcludes() );
collection.setStreamTransformer( fileSet.getStreamTransformer() );
collection.setFileMappers( fileSet.getFileMappers() );

if ( getOverrideDirectoryMode() > -1 || getOverrideFileMode() > -1 )
{
Expand Down Expand Up @@ -737,6 +738,7 @@ protected PlexusIoResourceCollection asResourceCollection( final ArchivedFileSet
proxy.setUsingDefaultExcludes( fileSet.isUsingDefaultExcludes() );
proxy.setFileSelectors( fileSet.getFileSelectors() );
proxy.setStreamTransformer( fileSet.getStreamTransformer() );
proxy.setFileMappers( fileSet.getFileMappers() );

if ( getOverrideDirectoryMode() > -1 || getOverrideFileMode() > -1 )
{
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/codehaus/plexus/archiver/BaseFileSet.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.codehaus.plexus.archiver;

import javax.annotation.CheckForNull;

import org.codehaus.plexus.components.io.filemappers.FileMapper;
import org.codehaus.plexus.components.io.fileselectors.FileSelector;
import org.codehaus.plexus.components.io.functions.InputStreamTransformer;

Expand Down Expand Up @@ -64,5 +66,12 @@ public interface BaseFileSet
* @return The transformers.
*/
InputStreamTransformer getStreamTransformer();

/**
* Returns a set of file mappers, which should be used
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better if the comment explicitly states that only the file names are changed. Otherwise combined with the bit misleading name of FileMapper somebody may get the false impression that the files themselves are changed. Of course a quick look at the FileMapper docs would make that clear but I think it will be more developer friendly if the comment is explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

of course you right, I add more explicit comment

* to change the filename of the included files.
*/
@CheckForNull
FileMapper[] getFileMappers();

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import javax.annotation.Nonnull;
import org.codehaus.plexus.archiver.BaseFileSet;
import org.codehaus.plexus.components.io.filemappers.FileMapper;
import org.codehaus.plexus.components.io.fileselectors.FileSelector;
import org.codehaus.plexus.components.io.functions.InputStreamTransformer;

Expand Down Expand Up @@ -44,6 +45,8 @@ public abstract class AbstractFileSet<T extends AbstractFileSet>
private boolean includingEmptyDirectories = true;

private InputStreamTransformer streamTransformer = null;

private FileMapper[] fileMappers;

/**
* Sets a string of patterns, which excluded files
Expand Down Expand Up @@ -189,5 +192,20 @@ public InputStreamTransformer getStreamTransformer()
{
return streamTransformer;
}

/**
* Sets a set of file mappers, which should be used
* to change the filename of the included files.
*/
public void setFileMappers( FileMapper[] fileMappers )
{
this.fileMappers = fileMappers;
}

@Override
public FileMapper[] getFileMappers()
{
return fileMappers;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributeUtils;
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
import org.codehaus.plexus.components.io.attributes.SimpleResourceAttributes;
import org.codehaus.plexus.components.io.filemappers.FileMapper;
import org.codehaus.plexus.components.io.filemappers.PrefixFileMapper;
import org.codehaus.plexus.components.io.functions.InputStreamTransformer;
import org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection;
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
Expand Down Expand Up @@ -429,6 +431,9 @@ public InputStream transform( @Nonnull PlexusIoResource resource, @Nonnull Input

};
sfd.setStreamTransformer( is );
PrefixFileMapper mapper = new PrefixFileMapper();
mapper.setPrefix( "prefix" );
sfd.setFileMappers( new FileMapper[] { mapper } );
zipArchiver.addArchivedFileSet( sfd );
zipArchiver.createArchive();

Expand All @@ -438,7 +443,7 @@ public InputStream transform( @Nonnull PlexusIoResource resource, @Nonnull Input
zipUnArchiver.setDestFile( destFile );
zipUnArchiver.extract();
File a3byteFile = new File( destFile,
"Users/kristian/lsrc/plexus/plexus-archiver/src/main/java/org/codehaus/plexus/archiver/zip/ZipArchiver.java" );
"prefixUsers/kristian/lsrc/plexus/plexus-archiver/src/main/java/org/codehaus/plexus/archiver/zip/ZipArchiver.java" );
assertTrue( a3byteFile.exists() );
assertTrue( a3byteFile.length() == 3 );
}
Expand Down