Search in sources :

Example 26 with TarArchiveOutputStream

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());
}
Also used : Path(java.nio.file.Path) GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) OutputStream(java.io.OutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ArchiveOutputStream(org.apache.commons.compress.archivers.ArchiveOutputStream) GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) File(java.io.File) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ArchiveOutputStream(org.apache.commons.compress.archivers.ArchiveOutputStream) Test(org.junit.Test)

Example 27 with TarArchiveOutputStream

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);
}
Also used : Path(java.nio.file.Path) GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) OutputStream(java.io.OutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ArchiveOutputStream(org.apache.commons.compress.archivers.ArchiveOutputStream) GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) File(java.io.File) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ArchiveOutputStream(org.apache.commons.compress.archivers.ArchiveOutputStream) Test(org.junit.Test)

Example 28 with TarArchiveOutputStream

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());
}
Also used : Path(java.nio.file.Path) GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) ZipEntry(java.util.zip.ZipEntry) OutputStream(java.io.OutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ArchiveOutputStream(org.apache.commons.compress.archivers.ArchiveOutputStream) GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) FrontendVersion(com.vaadin.flow.server.frontend.FrontendVersion) ZipOutputStream(java.util.zip.ZipOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) File(java.io.File) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ArchiveOutputStream(org.apache.commons.compress.archivers.ArchiveOutputStream) Test(org.junit.Test)

Example 29 with TarArchiveOutputStream

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);
}
Also used : FileOutputStream(java.io.FileOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) File(java.io.File) ImageArchiveManifest(io.fabric8.maven.docker.model.ImageArchiveManifest) Test(org.junit.Test)

Example 30 with TarArchiveOutputStream

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);
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ImageArchiveManifest(io.fabric8.maven.docker.model.ImageArchiveManifest) Test(org.junit.Test)

Aggregations

TarArchiveOutputStream (org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)101 File (java.io.File)42 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)42 FileOutputStream (java.io.FileOutputStream)37 GzipCompressorOutputStream (org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream)30 BufferedOutputStream (java.io.BufferedOutputStream)22 IOException (java.io.IOException)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 FileInputStream (java.io.FileInputStream)19 Path (java.nio.file.Path)17 GZIPOutputStream (java.util.zip.GZIPOutputStream)17 ByteArrayInputStream (java.io.ByteArrayInputStream)15 OutputStream (java.io.OutputStream)13 Test (org.junit.Test)12 ArchiveEntry (org.apache.commons.compress.archivers.ArchiveEntry)11 ArchiveOutputStream (org.apache.commons.compress.archivers.ArchiveOutputStream)11 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)9 ZipArchiveOutputStream (org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream)9 ImageArchiveManifest (io.fabric8.maven.docker.model.ImageArchiveManifest)8 InputStream (java.io.InputStream)7