0

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 ?

Cristiano
  • 1,414
  • 15
  • 22
  • Why not using the existing plugins like maven-assembly-plugin ? – khmarbaise Oct 09 '15 at 15:24
  • Well, because this mojo is part of a plugin that have its own lifecycle and packaging type defined and which goal is not the same as assembly-plugin. This pack mojo is working well, but I need to follow a spec that says some file need include a extra-field for its mime-type. – Cristiano Oct 09 '15 at 17:48

1 Answers1

0

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();
}
Cristiano
  • 1,414
  • 15
  • 22