use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project nutch by apache.
the class CommonCrawlDataDumper method constructNewStream.
private void constructNewStream(File outputDir) throws IOException {
String archiveName = new SimpleDateFormat("yyyyMMddhhmm'.tar.gz'").format(new Date());
LOG.info("Creating a new gzip archive: " + archiveName);
fileOutput = new FileOutputStream(new File(outputDir + File.separator + archiveName));
bufOutput = new BufferedOutputStream(fileOutput);
gzipOutput = new GzipCompressorOutputStream(bufOutput);
tarOutput = new TarArchiveOutputStream(gzipOutput);
tarOutput.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project winery by eclipse.
the class ScriptPlugin method compressFolderContents.
private void compressFolderContents(final String sourceDirectory, final String tarLocation) {
try (FileOutputStream fos = new FileOutputStream(tarLocation);
GZIPOutputStream gos = new GZIPOutputStream(new BufferedOutputStream(fos));
TarArchiveOutputStream tarOs = new TarArchiveOutputStream(gos)) {
final File folder = new File(sourceDirectory);
final File[] fileNames = folder.listFiles();
if (fileNames != null) {
for (final File file : fileNames) {
addFilesToTarGZ(file, tarOs);
}
}
} catch (final IOException e) {
logger.error("Error while creating tar-ball", e);
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project meecrowave by apache.
the class MeecrowaveBundleMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().warn(getClass().getSimpleName() + " skipped");
return;
}
final File distroFolder = new File(buildDirectory, rootName == null ? artifactId + "-distribution" : rootName);
if (distroFolder.exists()) {
delete(distroFolder);
}
Stream.of("bin", "conf", "logs", "lib").forEach(i -> new File(distroFolder, i).mkdirs());
copyProvidedFiles(distroFolder);
write(new File(distroFolder, "logs/you_can_safely_delete.txt"), DELETE_TEXT);
final Collection<String> includedArtifacts = project.getArtifacts().stream().filter(this::isIncluded).map(a -> {
addLib(distroFolder, a.getFile());
return a.getArtifactId();
}).collect(toList());
if (app.exists()) {
addLib(distroFolder, app);
}
if (webapp != null && webapp.isDirectory()) {
try {
final Path rootSrc = webapp.toPath().toAbsolutePath();
final Path rootTarget = distroFolder.toPath().toAbsolutePath().resolve("docBase");
Files.walkFileTree(rootSrc, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
final Path target = rootTarget.resolve(rootSrc.relativize(file));
target.toFile().getParentFile().mkdirs();
Files.copy(file, target, StandardCopyOption.REPLACE_EXISTING);
return super.visitFile(file, attrs);
}
});
} catch (final IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
if (enforceCommonsCli && !includedArtifacts.contains("commons-cli")) {
addLib(distroFolder, resolve("commons-cli", "commons-cli", "1.4", ""));
}
if (libs != null) {
libs.forEach(l -> {
final boolean transitive = l.endsWith("?transitive");
final String coords = transitive ? l.substring(0, l.length() - "?transitive".length()) : l;
final String[] c = coords.split(":");
if (c.length < 3 || c.length > 5) {
throw new IllegalArgumentException("libs syntax is groupId:artifactId:version[:classifier][:type[?transitive]]");
}
if (!transitive) {
addLib(distroFolder, resolve(c[0], c[1], c[2], c.length == 4 ? c[3] : ""));
} else {
addTransitiveDependencies(distroFolder, includedArtifacts, new Dependency() {
{
setGroupId(c[0]);
setArtifactId(c[1]);
setVersion(c[2]);
if (c.length == 4 && !"-".equals(c[3])) {
setClassifier(c[3]);
}
if (c.length == 5) {
setType(c[4]);
}
}
});
}
});
}
if (enforceMeecrowave && !includedArtifacts.contains("meecrowave-core")) {
addTransitiveDependencies(distroFolder, includedArtifacts, new Dependency() {
{
setGroupId("org.apache.meecrowave");
setArtifactId("meecrowave-core");
setVersion(findVersion());
}
});
}
for (final String ext : asList("sh", "bat")) {
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("bin/meecrowave." + ext)))) {
final File target = new File(distroFolder, "bin/meecrowave." + ext);
if (!target.exists()) {
write(target, new Substitutor(new HashMap<String, String>() {
{
put("main", main);
put("logManager", hasLog4j(distroFolder) ? "org.apache.logging.log4j.jul.LogManager" : "org.apache.juli.ClassLoaderLogManager");
}
}).replace(reader.lines().collect(joining("\n"))));
}
} catch (final IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
if (fakeTomcatScripts) {
Stream.of("catalina.sh", "shutdown.sh", "startup.sh").forEach(script -> {
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("bin/" + script)))) {
final File target = new File(distroFolder, "bin/" + script);
if (!target.exists()) {
write(target, reader.lines().collect(joining("\n")));
}
} catch (final IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
});
}
final Path prefix = skipArchiveRootFolder ? distroFolder.toPath() : distroFolder.getParentFile().toPath();
for (final String format : formats) {
getLog().info(format + "-ing Custom Meecrowave Distribution");
final File output = new File(buildDirectory, artifactId + "-meecrowave-distribution." + format);
switch(format.toLowerCase(ENGLISH)) {
case "tar.gz":
try (final TarArchiveOutputStream tarGz = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(output)))) {
tarGz.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
for (final String entry : distroFolder.list()) {
tarGz(tarGz, new File(distroFolder, entry), prefix);
}
} catch (final IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
break;
case "zip":
try (final ZipArchiveOutputStream zos = new ZipArchiveOutputStream(new FileOutputStream(output))) {
for (final String entry : distroFolder.list()) {
zip(zos, new File(distroFolder, entry), prefix);
}
} catch (final IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
break;
default:
throw new IllegalArgumentException(format + " is not supported");
}
attach(format, output);
}
if (!keepExplodedFolder) {
delete(distroFolder);
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project docker-maven-plugin by fabric8io.
the class ImageArchiveUtilTest method readEmptyArchive.
@Test
public void readEmptyArchive() throws IOException {
byte[] emptyTar;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
TarArchiveOutputStream tarOutput = new TarArchiveOutputStream(baos)) {
tarOutput.finish();
emptyTar = baos.toByteArray();
}
ImageArchiveManifest manifest = ImageArchiveUtil.readManifest(new ByteArrayInputStream(emptyTar));
Assert.assertNull(manifest);
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project docker-maven-plugin by fabric8io.
the class ImageArchiveUtilTest method readInvalidManifestInArchive.
@Test(expected = JsonParseException.class)
public void readInvalidManifestInArchive() throws IOException {
byte[] archiveBytes;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
TarArchiveOutputStream tarOutput = new TarArchiveOutputStream(baos)) {
final byte[] entryData = ("}" + UUID.randomUUID().toString() + "{").getBytes();
TarArchiveEntry tarEntry = new TarArchiveEntry(ImageArchiveUtil.MANIFEST_JSON);
tarEntry.setSize(entryData.length);
tarOutput.putArchiveEntry(tarEntry);
tarOutput.write(entryData);
tarOutput.closeArchiveEntry();
tarOutput.finish();
archiveBytes = baos.toByteArray();
}
ImageArchiveManifest manifest = ImageArchiveUtil.readManifest(new ByteArrayInputStream(archiveBytes));
Assert.assertNull(manifest);
}
Aggregations