final GZipArchiver gzip = new GZipArchiver();
gzip.setDestFile(metadataGz);
gzip.addFile(metadata, "metadata.gz");
gzip.createArchive();
final TarArchiver tar = new TarArchiver();
// turn off logging
tar.enableLogging(new AbstractLogger(0, "nologging") {
public void warn(final String message, final Throwable throwable) {
}
public void info(final String message, final Throwable throwable) {
}
public Logger getChildLogger(final String name) {
return null;
}
public void fatalError(final String message,
final Throwable throwable) {
}
public void error(final String message,
final Throwable throwable) {
}
public void debug(final String message,
final Throwable throwable) {
}
});
final TarCompressionMethod compression = new TarCompressionMethod();
File dataTarGz = null;
if (!gem.getGemFiles().isEmpty()) {
// tar.gz the content into data.tar.gz
dataTarGz = new File(gemWorkdir, "data.tar.gz");
compression.setValue("gzip");
tar.setCompression(compression);
tar.setDestFile(dataTarGz);
for (final GemFileEntry entry : gem.getGemFiles()) {
if (entry.getSource().isFile()) {
tar.addFile(entry.getSource(), entry.getPathInGem());
}
else if (entry.getSource().isDirectory()) {
tar.addDirectory(entry.getSource(),
entry.getPathInGem());
}
}
tar.createArchive();
}
// and finally create gem by tar.gz-ing data.tar.gz and metadata.gz
final File gemFile = new File(target, gem.getGemFilename());
tar.setDestFile(gemFile);
compression.setValue("none");
tar.setCompression(compression);
if (dataTarGz != null) {
tar.addFile(dataTarGz, dataTarGz.getName());
}
tar.addFile(metadataGz, metadataGz.getName());
tar.createArchive();
return gemFile;
}
catch (final ArchiverException e) {
final IOException ioe = new IOException(e.getMessage());