use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project flow by vaadin.
the class DefaultArchiveExtractorTest method extractTarGz_contentsAreExtracted.
@Test
public void extractTarGz_contentsAreExtracted() throws IOException, ArchiveExtractionException {
File archiveFile = new File(baseDir, "archive.tar.gz");
archiveFile.createNewFile();
Path tempArchive = archiveFile.toPath();
try (OutputStream fo = Files.newOutputStream(tempArchive);
OutputStream gzo = new GzipCompressorOutputStream(fo);
ArchiveOutputStream o = new TarArchiveOutputStream(gzo)) {
o.putArchiveEntry(o.createArchiveEntry(new File(ROOT_FILE), ROOT_FILE));
o.closeArchiveEntry();
o.putArchiveEntry(o.createArchiveEntry(new File(SUBFOLDER_FILE), SUBFOLDER_FILE));
o.closeArchiveEntry();
}
new DefaultArchiveExtractor().extract(archiveFile, targetDir);
Assert.assertTrue("Archive root.file was not extracted", new File(targetDir, ROOT_FILE).exists());
Assert.assertTrue("Archive subfolder/folder.file was not extracted", new File(targetDir, SUBFOLDER_FILE).exists());
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project flow by vaadin.
the class DefaultArchiveExtractorTest method extractTarAsZip_ArchiveExtractionExceptionIsThrown.
@Test(expected = ArchiveExtractionException.class)
public void extractTarAsZip_ArchiveExtractionExceptionIsThrown() throws IOException, ArchiveExtractionException {
File archiveFile = new File(baseDir, "archive.zip");
archiveFile.createNewFile();
Path tempArchive = archiveFile.toPath();
try (OutputStream fo = Files.newOutputStream(tempArchive);
OutputStream gzo = new GzipCompressorOutputStream(fo);
ArchiveOutputStream o = new TarArchiveOutputStream(gzo)) {
o.putArchiveEntry(o.createArchiveEntry(new File(ROOT_FILE), ROOT_FILE));
o.closeArchiveEntry();
}
new DefaultArchiveExtractor().extract(archiveFile, targetDir);
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project flow by vaadin.
the class NodeInstallerTest method installNodeFromFileSystem_NodeIsInstalledToTargetDirectory.
@Test
public void installNodeFromFileSystem_NodeIsInstalledToTargetDirectory() throws IOException {
Platform platform = Platform.guess();
String nodeExec = platform.isWindows() ? "node.exe" : "node";
String prefix = String.format("node-%s-%s", FrontendTools.DEFAULT_NODE_VERSION, platform.getNodeClassifier(new FrontendVersion(FrontendTools.DEFAULT_NODE_VERSION)));
File targetDir = new File(baseDir + "/installation");
Assert.assertFalse("Clean test should not contain a installation folder", targetDir.exists());
File downloadDir = tmpDir.newFolder(FrontendTools.DEFAULT_NODE_VERSION);
File archiveFile = new File(downloadDir, prefix + "." + platform.getArchiveExtension());
archiveFile.createNewFile();
Path tempArchive = archiveFile.toPath();
if (platform.getArchiveExtension().equals("zip")) {
try (ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(tempArchive))) {
zipOutputStream.putNextEntry(new ZipEntry(prefix + "/" + nodeExec));
zipOutputStream.closeEntry();
zipOutputStream.putNextEntry(new ZipEntry(prefix + "/node_modules/npm/bin/npm"));
zipOutputStream.closeEntry();
zipOutputStream.putNextEntry(new ZipEntry(prefix + "/node_modules/npm/bin/npm.cmd"));
zipOutputStream.closeEntry();
}
} else {
try (OutputStream fo = Files.newOutputStream(tempArchive);
OutputStream gzo = new GzipCompressorOutputStream(fo);
ArchiveOutputStream o = new TarArchiveOutputStream(gzo)) {
o.putArchiveEntry(o.createArchiveEntry(new File(prefix + "/bin/" + nodeExec), prefix + "/bin/" + nodeExec));
o.closeArchiveEntry();
o.putArchiveEntry(o.createArchiveEntry(new File(prefix + "/bin/npm"), prefix + "/bin/npm"));
o.closeArchiveEntry();
o.putArchiveEntry(o.createArchiveEntry(new File(prefix + "/lib/node_modules/npm/bin/npm"), prefix + "/lib/node_modules/npm/bin/npm"));
o.closeArchiveEntry();
o.putArchiveEntry(o.createArchiveEntry(new File(prefix + "/lib/node_modules/npm/bin/npm.cmd"), prefix + "/lib/node_modules/npm/bin/npm.cmd"));
o.closeArchiveEntry();
}
}
// add a file to node/node_modules_npm that should be cleaned out
File nodeDirectory = new File(targetDir, "node");
File nodeModulesDirectory = new File(nodeDirectory, "node_modules");
File npmDirectory = new File(nodeModulesDirectory, "npm");
File garbage = new File(npmDirectory, "garbage");
FileUtils.forceMkdir(npmDirectory);
Assert.assertTrue("garbage file should be created", garbage.createNewFile());
NodeInstaller nodeInstaller = new NodeInstaller(targetDir, Collections.emptyList()).setNodeVersion(FrontendTools.DEFAULT_NODE_VERSION).setNodeDownloadRoot(new File(baseDir).toPath().toUri());
try {
nodeInstaller.install();
} catch (InstallationException e) {
throw new IllegalStateException("Failed to install Node", e);
}
Assert.assertTrue("npm should have been copied to node_modules", new File(targetDir, "node/" + nodeExec).exists());
Assert.assertTrue("npm should have been copied to node_modules", new File(targetDir, "node/node_modules/npm/bin/npm").exists());
Assert.assertFalse("old npm files should have been removed", garbage.exists());
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project docker-maven-plugin by fabric8io.
the class ImageArchiveUtilTest method readEmptyArchiveFromFile.
@Test
public void readEmptyArchiveFromFile() throws IOException {
File temporaryTar = temporaryFolder.newFile();
try (FileOutputStream fileOutput = new FileOutputStream(temporaryTar);
TarArchiveOutputStream tarOutput = new TarArchiveOutputStream(fileOutput)) {
tarOutput.finish();
}
ImageArchiveManifest manifest = ImageArchiveUtil.readManifest(temporaryTar);
Assert.assertNull(manifest);
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project docker-maven-plugin by fabric8io.
the class ImageArchiveUtilTest method readEmptyCompressedArchive.
@Test
public void readEmptyCompressedArchive() throws IOException {
byte[] emptyTar;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(baos);
TarArchiveOutputStream tarOutput = new TarArchiveOutputStream(gzip)) {
tarOutput.finish();
gzip.finish();
emptyTar = baos.toByteArray();
}
ImageArchiveManifest manifest = ImageArchiveUtil.readManifest(new ByteArrayInputStream(emptyTar));
Assert.assertNull(manifest);
}
Aggregations