I'm working with a maven plugin that is using plexus-archiver in order to create a zip file. Basically, I'm getting the component inject by Sisu, then I'm traversing a specified fileSet and registering the ones required:
zipArchiver.addFile(from_file, to_file);
And the zip are being generated properly.
But I need to include an extra-field for the file mime-type in some of those files that are being added to the zip.
how can I do that with plexus-archiver ?
It seems that the current plexus-archiver (3.0) doesn't support extra-fields. I have to hack a bit in order to keep using plexus-archive.
The solution was to extend ZipArchiver class and override the method initZipOutputStream that provides an object from ZipArchiveOutputStream class.
With it I could create the entry and its extra-field:
@Override
protected void initZipOutputStream(ZipArchiveOutputStream pZOut)
throws ArchiverException, IOException {
super.initZipOutputStream(pZOut);
ZipArchiveEntry ae = new ZipArchiveEntry(pFile,
pFile.getName());
ZipExtraField zef = new ContentTypeExtraField(
Constants.MIME_STRING);
ae.addExtraField(zef);
pZOut.putArchiveEntry(ae);
pZOut.write(content);
pZOut.closeArchiveEntry();
}