org.codehaus.plexus.archiver.tar.TarArchiver Java Examples

The following examples show how to use org.codehaus.plexus.archiver.tar.TarArchiver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DockerAssemblyManager.java    From docker-maven-plugin with Apache License 2.0 6 votes vote down vote up
private TarArchiver createBuildArchiver(File outputDir, File archive, AssemblyConfiguration assemblyConfig) throws NoSuchArchiverException {
    TarArchiver archiver = (TarArchiver) archiverManager.getArchiver("tar");
    archiver.setLongfile(TarLongFileMode.posix);

    AssemblyMode mode = assemblyConfig != null ? assemblyConfig.getMode() : null;
    if (mode != null && mode.isArchive()) {
        DefaultArchivedFileSet archiveSet =
                DefaultArchivedFileSet.archivedFileSet(new File(outputDir,  assemblyConfig.getName() + "." + mode.getExtension()));
        archiveSet.setPrefix(assemblyConfig.getName() + "/");
        archiveSet.setIncludingEmptyDirectories(true);
        archiveSet.setUsingDefaultExcludes(false);
        archiver.addArchivedFileSet(archiveSet);
    } else {
        DefaultFileSet fileSet = DefaultFileSet.fileSet(outputDir);
        fileSet.setUsingDefaultExcludes(false);
        archiver.addFileSet(fileSet);
    }
    archiver.setDestFile(archive);
    return archiver;
}
 
Example #2
Source File: TarGzArchive.java    From dropwizard-experiment with MIT License 6 votes vote down vote up
private static File tar(Set<File> files, String folder) throws IOException {
    TarArchiver tarArchive = new TarArchiver();
    tarArchive.enableLogging(new ConsoleLogger(Logger.LEVEL_DISABLED, "console"));
    for (File file : files) {
        // The starting ./ in the folder name is required for Heroku to be able to unpack the files correctly.
        if (file.isFile()) {
            tarArchive.addFile(file, "./" + folder + "/" + file.getName());
        } else if (file.isDirectory()) {
            tarArchive.addDirectory(file, "./" + folder + "/" + file.getName() + "/");
        }
    }

    File tarFile = File.createTempFile("TarGzArchive", ".tar");
    tarArchive.setDestFile(tarFile);
    tarArchive.createArchive();

    return tarFile;
}
 
Example #3
Source File: MavenUtil.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public static void createArchive(File sourceDir, File destinationFile, TarArchiver archiver) throws IOException {
    try {
        archiver.setCompression(TarArchiver.TarCompressionMethod.gzip);
        archiver.setLongfile(TarLongFileMode.posix);
        archiver.addDirectory(sourceDir);
        archiver.setDestFile(destinationFile);
        archiver.createArchive();
    } catch (IOException e) {
        throw new IOException("Failed to create archive " + destinationFile + ": " + e, e);
    }
}
 
Example #4
Source File: AllFilesExecCustomizer.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public TarArchiver customize(TarArchiver archiver) throws IOException {
    log.warn("/--------------------- SECURITY WARNING ---------------------\\");
    log.warn("|You are building a Docker image with normalized permissions.|");
    log.warn("|All files and directories added to build context will have  |");
    log.warn("|'-rwxr-xr-x' permissions. It is recommended to double check |");
    log.warn("|and reset permissions for sensitive files and directories.  |");
    log.warn("\\------------------------------------------------------------/");

    TarArchiver newArchiver = new TarArchiver();
    newArchiver.setDestFile(archiver.getDestFile());
    newArchiver.setLongfile(TarLongFileMode.posix);

    ResourceIterator resources = archiver.getResources();
    while (resources.hasNext()) {
        ArchiveEntry ae = resources.next();
        String fileName = ae.getName();
        PlexusIoResource resource = ae.getResource();
        String name = StringUtils.replace(fileName, File.separatorChar, '/');

        // See docker source:
        // https://github.com/docker/docker/blob/3d13fddd2bc4d679f0eaa68b0be877e5a816ad53/pkg/archive/archive_windows.go#L45
        int mode = ae.getMode() & 0777;
        int newMode = mode;
        newMode &= 0755;
        newMode |= 0111;

        if (newMode != mode) {
            log.debug("Changing permissions of '%s' from %o to %o.", name, mode, newMode);
        }

        newArchiver.addResource(resource, name, newMode);
    }

    archiver = newArchiver;

    return archiver;
}
 
Example #5
Source File: ArchiverCustomizer.java    From docker-maven-plugin with Apache License 2.0 votes vote down vote up
TarArchiver customize(TarArchiver archiver) throws IOException;