Custom Maven Plugin Development Archiving Files

160 Views Asked by At

I am developing my own custom Maven plugin and I want to archive the files. I followed this example: http://www.sonatype.com/books/mvnref-book/reference/writing-plugins-sect-mojo-params.html and could archive the elements with zip format. However I want to use other formats too (user will indicate it). How can I set the archive type?

ZipArchiver works like that:

/**
* The Zip archiver.
* @parameter \
expression="${component.org.codehaus.plexus.archiver.Archiver#zip}"
*/
private ZipArchiver zipArchiver;
...
zipArchiver.addDirectory( buildDirectory, includes, excludes );
zipArchiver.setDestFile( new File( baseDirectory, "output.zip" ) );
zipArchiver.createArchive();
1

There are 1 best solutions below

2
On

You need to add a format property to your plugin and use the relevant archiver depending on your format:

Archiver archiver = null;
if("zip".equals(format)){
    archiver = new ZipArchiver(...);
}
else if("tar".equals(format)){
    archiver = new TarArchiver(...);
}
else (...){
    ...
}