final File targetDirectory = new File(rootDirectory, TARGET_DIRECTORY);
final String version = project.getVersion();
final String artifactBase = FINALNAME_PREFIX + version;
try {
final File targetFile = new File(distributionDirectory(targetDirectory), artifactBase + ".zip");
final ZipArchiveOutputStream zip = new ZipArchiveOutputStream(targetFile);
try {
zip.setLevel(9);
appendRecursively(sourceDirectory, artifactBase, zip, new byte[8192]);
/*
* At this point, all the "application/sis-console/src/main/artifact" and sub-directories
* have been zipped. Now generate the Pack200 file and zip it directly (without creating
* a temporary "sis.pack.gz" file).
*/
final Packer packer = new Packer(project.getName(), project.getUrl(), version, targetDirectory);
final ZipArchiveEntry entry = new ZipArchiveEntry(
artifactBase + '/' + LIB_DIRECTORY + '/' + FATJAR_FILE + PACK_EXTENSION);
entry.setMethod(ZipArchiveEntry.STORED);
zip.putArchiveEntry(entry);
packer.preparePack200(FATJAR_FILE + ".jar").pack(new FilterOutputStream(zip) {
/*
* Closes the archive entry, not the ZIP file.
*/
@Override
public void close() throws IOException {
zip.closeArchiveEntry();
}
});
} finally {
zip.close();
}
} catch (IOException e) {
throw new MojoExecutionException(e.getLocalizedMessage(), e);
}
}