List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveEntry setLinkName
public void setLinkName(String link)
From source file:com.puppetlabs.geppetto.forge.util.TarUtils.java
private static void append(File file, FileFilter filter, int baseNameLen, String addedTopFolder, TarArchiveOutputStream tarOut) throws IOException { String name = file.getAbsolutePath(); if (name.length() <= baseNameLen) name = ""; else//from w w w.ja v a 2s . c o m name = name.substring(baseNameLen); if (File.separatorChar == '\\') name = name.replace('\\', '/'); if (addedTopFolder != null) name = addedTopFolder + '/' + name; if (FileUtils.isSymlink(file)) { String linkTarget = FileUtils.readSymbolicLink(file); if (linkTarget != null) { TarArchiveEntry entry = new TarArchiveEntry(name, TarConstants.LF_SYMLINK); entry.setName(name); entry.setLinkName(linkTarget); tarOut.putArchiveEntry(entry); } return; } ArchiveEntry entry = tarOut.createArchiveEntry(file, name); tarOut.putArchiveEntry(entry); File[] children = file.listFiles(filter); if (children != null) { tarOut.closeArchiveEntry(); // This is a directory. Append its children for (File child : children) append(child, filter, baseNameLen, addedTopFolder, tarOut); return; } // Append the content of the file InputStream input = new FileInputStream(file); try { StreamUtil.copy(input, tarOut); tarOut.closeArchiveEntry(); } finally { StreamUtil.close(input); } }
From source file:com.gitblit.utils.CompressionUtils.java
/** * Compresses/archives the contents of the tree at the (optionally) * specified revision and the (optionally) specified basepath to the * supplied outputstream./*from www . j a v a 2 s . c o m*/ * * @param algorithm * compression algorithm for tar (optional) * @param repository * @param basePath * if unspecified, entire repository is assumed. * @param objectId * if unspecified, HEAD is assumed. * @param os * @return true if repository was successfully zipped to supplied output * stream */ private static boolean tar(String algorithm, Repository repository, String basePath, String objectId, OutputStream os) { RevCommit commit = JGitUtils.getCommit(repository, objectId); if (commit == null) { return false; } OutputStream cos = os; if (!StringUtils.isEmpty(algorithm)) { try { cos = new CompressorStreamFactory().createCompressorOutputStream(algorithm, os); } catch (CompressorException e1) { error(e1, repository, "{0} failed to open {1} stream", algorithm); } } boolean success = false; RevWalk rw = new RevWalk(repository); TreeWalk tw = new TreeWalk(repository); try { tw.reset(); tw.addTree(commit.getTree()); TarArchiveOutputStream tos = new TarArchiveOutputStream(cos); tos.setAddPaxHeadersForNonAsciiNames(true); tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); if (!StringUtils.isEmpty(basePath)) { PathFilter f = PathFilter.create(basePath); tw.setFilter(f); } tw.setRecursive(true); MutableObjectId id = new MutableObjectId(); long modified = commit.getAuthorIdent().getWhen().getTime(); while (tw.next()) { FileMode mode = tw.getFileMode(0); if (mode == FileMode.GITLINK || mode == FileMode.TREE) { continue; } tw.getObjectId(id, 0); ObjectLoader loader = repository.open(id); if (FileMode.SYMLINK == mode) { TarArchiveEntry entry = new TarArchiveEntry(tw.getPathString(), TarArchiveEntry.LF_SYMLINK); ByteArrayOutputStream bos = new ByteArrayOutputStream(); loader.copyTo(bos); entry.setLinkName(bos.toString()); entry.setModTime(modified); tos.putArchiveEntry(entry); tos.closeArchiveEntry(); } else { TarArchiveEntry entry = new TarArchiveEntry(tw.getPathString()); entry.setMode(mode.getBits()); entry.setModTime(modified); entry.setSize(loader.getSize()); tos.putArchiveEntry(entry); loader.copyTo(tos); tos.closeArchiveEntry(); } } tos.finish(); tos.close(); cos.close(); success = true; } catch (IOException e) { error(e, repository, "{0} failed to {1} stream files from commit {2}", algorithm, commit.getName()); } finally { tw.release(); rw.dispose(); } return success; }
From source file:hudson.util.io.TarArchiver.java
@Override public void visitSymlink(File link, String target, String relativePath) throws IOException { TarArchiveEntry e = new TarArchiveEntry(relativePath, LF_SYMLINK); try {/* www. j a va2 s . co m*/ int mode = IOUtils.mode(link); if (mode != -1) { e.setMode(mode); } } catch (PosixException x) { // ignore } e.setLinkName(target); tar.putArchiveEntry(e); tar.closeArchiveEntry(); entriesWritten++; }
From source file:org.apache.karaf.tooling.ArchiveMojo.java
private void addFileToTarGz(TarArchiveOutputStream tOut, Path f, String base) throws IOException { if (Files.isDirectory(f)) { String entryName = base + f.getFileName().toString() + "/"; TarArchiveEntry tarEntry = new TarArchiveEntry(entryName); tOut.putArchiveEntry(tarEntry);//w ww . j a v a 2s . c o m tOut.closeArchiveEntry(); try (DirectoryStream<Path> children = Files.newDirectoryStream(f)) { for (Path child : children) { addFileToTarGz(tOut, child, entryName); } } } else if (useSymLinks && Files.isSymbolicLink(f)) { String entryName = base + f.getFileName().toString(); TarArchiveEntry tarEntry = new TarArchiveEntry(entryName, TarConstants.LF_SYMLINK); tarEntry.setLinkName(Files.readSymbolicLink(f).toString()); tOut.putArchiveEntry(tarEntry); tOut.closeArchiveEntry(); } else { String entryName = base + f.getFileName().toString(); TarArchiveEntry tarEntry = new TarArchiveEntry(entryName); tarEntry.setSize(Files.size(f)); if (entryName.contains("/bin/") || (!usePathPrefix && entryName.startsWith("bin/"))) { if (entryName.endsWith(".bat")) { tarEntry.setMode(0644); } else { tarEntry.setMode(0755); } } tOut.putArchiveEntry(tarEntry); Files.copy(f, tOut); tOut.closeArchiveEntry(); } }
From source file:org.codehaus.plexus.archiver.tar.TarArchiver.java
/** * tar a file//from w w w . j a v a 2s . co m * * @param entry the file to tar * @param tOut the output stream * @param vPath the path name of the file to tar * @throws IOException on error */ protected void tarFile(ArchiveEntry entry, TarArchiveOutputStream tOut, String vPath) throws ArchiverException, IOException { // don't add "" to the archive if (vPath.length() <= 0) { return; } if (entry.getResource().isDirectory() && !vPath.endsWith("/")) { vPath += "/"; } if (vPath.startsWith("/") && !options.getPreserveLeadingSlashes()) { int l = vPath.length(); if (l <= 1) { // we would end up adding "" to the archive return; } vPath = vPath.substring(1, l); } int pathLength = vPath.length(); InputStream fIn = null; try { TarArchiveEntry te; if (!longFileMode.isGnuMode() && pathLength >= org.apache.commons.compress.archivers.tar.TarConstants.NAMELEN) { int maxPosixPathLen = org.apache.commons.compress.archivers.tar.TarConstants.NAMELEN + org.apache.commons.compress.archivers.tar.TarConstants.PREFIXLEN; if (longFileMode.isPosixMode()) { } else if (longFileMode.isPosixWarnMode()) { if (pathLength > maxPosixPathLen) { getLogger().warn("Entry: " + vPath + " longer than " + maxPosixPathLen + " characters."); if (!longWarningGiven) { getLogger().warn("Resulting tar file can only be processed " + "successfully by GNU compatible tar commands"); longWarningGiven = true; } } } else if (longFileMode.isOmitMode()) { getLogger().info("Omitting: " + vPath); return; } else if (longFileMode.isWarnMode()) { getLogger().warn("Entry: " + vPath + " longer than " + org.apache.commons.compress.archivers.tar.TarConstants.NAMELEN + " characters."); if (!longWarningGiven) { getLogger().warn("Resulting tar file can only be processed " + "successfully by GNU compatible tar commands"); longWarningGiven = true; } } else if (longFileMode.isFailMode()) { throw new ArchiverException("Entry: " + vPath + " longer than " + org.apache.commons.compress.archivers.tar.TarConstants.NAMELEN + " characters."); } else { throw new IllegalStateException("Non gnu mode should never get here?"); } } if (entry.getType() == ArchiveEntry.SYMLINK) { final SymlinkDestinationSupplier plexusIoSymlinkResource = (SymlinkDestinationSupplier) entry .getResource(); te = new TarArchiveEntry(vPath, TarArchiveEntry.LF_SYMLINK); te.setLinkName(plexusIoSymlinkResource.getSymlinkDestination()); } else { te = new TarArchiveEntry(vPath); } long teLastModified = entry.getResource().getLastModified(); te.setModTime(teLastModified == PlexusIoResource.UNKNOWN_MODIFICATION_DATE ? System.currentTimeMillis() : teLastModified); if (entry.getType() == ArchiveEntry.SYMLINK) { te.setSize(0); } else if (!entry.getResource().isDirectory()) { final long size = entry.getResource().getSize(); te.setSize(size == PlexusIoResource.UNKNOWN_RESOURCE_SIZE ? 0 : size); } te.setMode(entry.getMode()); PlexusIoResourceAttributes attributes = entry.getResourceAttributes(); te.setUserName((attributes != null && attributes.getUserName() != null) ? attributes.getUserName() : options.getUserName()); te.setGroupName((attributes != null && attributes.getGroupName() != null) ? attributes.getGroupName() : options.getGroup()); final int userId = (attributes != null && attributes.getUserId() != null) ? attributes.getUserId() : options.getUid(); if (userId >= 0) { te.setUserId(userId); } final int groupId = (attributes != null && attributes.getGroupId() != null) ? attributes.getGroupId() : options.getGid(); if (groupId >= 0) { te.setGroupId(groupId); } tOut.putArchiveEntry(te); try { if (entry.getResource().isFile() && !(entry.getType() == ArchiveEntry.SYMLINK)) { fIn = entry.getInputStream(); Streams.copyFullyDontCloseOutput(fIn, tOut, "xAR"); } } catch (Throwable e) { getLogger().warn("When creating tar entry", e); } finally { tOut.closeArchiveEntry(); } } finally { IOUtil.close(fIn); } }
From source file:org.eclipse.jgit.archive.TarFormat.java
public void putEntry(ArchiveOutputStream out, String path, FileMode mode, ObjectLoader loader) throws IOException { if (mode == FileMode.SYMLINK) { final TarArchiveEntry entry = new TarArchiveEntry(path, TarConstants.LF_SYMLINK); entry.setLinkName(new String(loader.getCachedBytes(100), "UTF-8")); //$NON-NLS-1$ out.putArchiveEntry(entry);/*w ww . j ava 2 s . c om*/ out.closeArchiveEntry(); return; } // TarArchiveEntry detects directories by checking // for '/' at the end of the filename. if (path.endsWith("/") && mode != FileMode.TREE) //$NON-NLS-1$ throw new IllegalArgumentException( MessageFormat.format(ArchiveText.get().pathDoesNotMatchMode, path, mode)); if (!path.endsWith("/") && mode == FileMode.TREE) //$NON-NLS-1$ path = path + "/"; //$NON-NLS-1$ final TarArchiveEntry entry = new TarArchiveEntry(path); if (mode == FileMode.TREE) { out.putArchiveEntry(entry); out.closeArchiveEntry(); return; } if (mode == FileMode.REGULAR_FILE) { // ok } else if (mode == FileMode.EXECUTABLE_FILE) { entry.setMode(mode.getBits()); } else { // Unsupported mode (e.g., GITLINK). throw new IllegalArgumentException(MessageFormat.format(ArchiveText.get().unsupportedMode, mode)); } entry.setSize(loader.getSize()); out.putArchiveEntry(entry); loader.copyTo(out); out.closeArchiveEntry(); }
From source file:org.eclipse.tycho.plugins.tar.TarGzArchiver.java
private TarArchiveEntry createTarEntry(File tarRootDir, File source) throws IOException { String pathInTar = slashify(tarRootDir.toPath().relativize(source.toPath())); log.debug("Adding entry " + pathInTar); TarArchiveEntry tarEntry; if (isSymbolicLink(source) && resolvesBelow(source, tarRootDir)) { // only create symlink entry if link target is inside archive tarEntry = new TarArchiveEntry(pathInTar, TarArchiveEntry.LF_SYMLINK); tarEntry.setLinkName(slashify(getRelativeSymLinkTarget(source, source.getParentFile()))); } else {//from w w w . ja v a2 s . c o m tarEntry = new TarArchiveEntry(source, pathInTar); } PosixFileAttributes attrs = getAttributes(source); if (attrs != null) { tarEntry.setUserName(attrs.owner().getName()); tarEntry.setGroupName(attrs.group().getName()); tarEntry.setMode(FilePermissionHelper.toOctalFileMode(attrs.permissions())); } tarEntry.setModTime(source.lastModified()); return tarEntry; }
From source file:org.vafer.jdeb.DataBuilder.java
/** * Build the data archive of the deb from the provided DataProducers * * @param producers// www.j a v a 2 s. c o m * @param output * @param checksums * @param compression the compression method used for the data file * @return * @throws java.security.NoSuchAlgorithmException * @throws java.io.IOException * @throws org.apache.commons.compress.compressors.CompressorException */ BigInteger buildData(Collection<DataProducer> producers, File output, final StringBuilder checksums, Compression compression) throws NoSuchAlgorithmException, IOException, CompressorException { final File dir = output.getParentFile(); if (dir != null && (!dir.exists() || !dir.isDirectory())) { throw new IOException("Cannot write data file at '" + output.getAbsolutePath() + "'"); } final TarArchiveOutputStream tarOutputStream = new TarArchiveOutputStream( compression.toCompressedOutputStream(new FileOutputStream(output))); tarOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); final MessageDigest digest = MessageDigest.getInstance("MD5"); final Total dataSize = new Total(); final List<String> addedDirectories = new ArrayList<String>(); final DataConsumer receiver = new DataConsumer() { public void onEachDir(String dirname, String linkname, String user, int uid, String group, int gid, int mode, long size) throws IOException { dirname = fixPath(dirname); createParentDirectories(dirname, user, uid, group, gid); // The directory passed in explicitly by the caller also gets the passed-in mode. (Unlike // the parent directories for now. See related comments at "int mode =" in // createParentDirectories, including about a possible bug.) createDirectory(dirname, user, uid, group, gid, mode, 0); console.info("dir: " + dirname); } public void onEachFile(InputStream inputStream, String filename, String linkname, String user, int uid, String group, int gid, int mode, long size) throws IOException { filename = fixPath(filename); createParentDirectories(filename, user, uid, group, gid); final TarArchiveEntry entry = new TarArchiveEntry(filename, true); entry.setUserName(user); entry.setUserId(uid); entry.setGroupName(group); entry.setGroupId(gid); entry.setMode(mode); entry.setSize(size); tarOutputStream.putArchiveEntry(entry); dataSize.add(size); digest.reset(); Utils.copy(inputStream, new DigestOutputStream(tarOutputStream, digest)); final String md5 = Utils.toHex(digest.digest()); tarOutputStream.closeArchiveEntry(); console.info("file:" + entry.getName() + " size:" + entry.getSize() + " mode:" + entry.getMode() + " linkname:" + entry.getLinkName() + " username:" + entry.getUserName() + " userid:" + entry.getUserId() + " groupname:" + entry.getGroupName() + " groupid:" + entry.getGroupId() + " modtime:" + entry.getModTime() + " md5: " + md5); // append to file md5 list checksums.append(md5).append(" ").append(entry.getName()).append('\n'); } public void onEachLink(String path, String linkName, boolean symlink, String user, int uid, String group, int gid, int mode) throws IOException { path = fixPath(path); createParentDirectories(path, user, uid, group, gid); final TarArchiveEntry entry = new TarArchiveEntry(path, symlink ? TarArchiveEntry.LF_SYMLINK : TarArchiveEntry.LF_LINK); entry.setLinkName(linkName); entry.setUserName(user); entry.setUserId(uid); entry.setGroupName(group); entry.setGroupId(gid); entry.setMode(mode); tarOutputStream.putArchiveEntry(entry); tarOutputStream.closeArchiveEntry(); console.info("link:" + entry.getName() + " mode:" + entry.getMode() + " linkname:" + entry.getLinkName() + " username:" + entry.getUserName() + " userid:" + entry.getUserId() + " groupname:" + entry.getGroupName() + " groupid:" + entry.getGroupId()); } private void createDirectory(String directory, String user, int uid, String group, int gid, int mode, long size) throws IOException { // All dirs should end with "/" when created, or the test DebAndTaskTestCase.testTarFileSet() thinks its a file // and so thinks it has the wrong permission. // This consistency also helps when checking if a directory already exists in addedDirectories. if (!directory.endsWith("/")) { directory += "/"; } if (!addedDirectories.contains(directory)) { TarArchiveEntry entry = new TarArchiveEntry(directory, true); entry.setUserName(user); entry.setUserId(uid); entry.setGroupName(group); entry.setGroupId(gid); entry.setMode(mode); entry.setSize(size); tarOutputStream.putArchiveEntry(entry); tarOutputStream.closeArchiveEntry(); addedDirectories.add(directory); // so addedDirectories consistently have "/" for finding duplicates. } } private void createParentDirectories(String filename, String user, int uid, String group, int gid) throws IOException { String dirname = fixPath(new File(filename).getParent()); // Debian packages must have parent directories created // before sub-directories or files can be installed. // For example, if an entry of ./usr/lib/foo/bar existed // in a .deb package, but the ./usr/lib/foo directory didn't // exist, the package installation would fail. The .deb must // then have an entry for ./usr/lib/foo and then ./usr/lib/foo/bar if (dirname == null) { return; } // The loop below will create entries for all parent directories // to ensure that .deb packages will install correctly. String[] pathParts = dirname.split("/"); String parentDir = "./"; for (int i = 1; i < pathParts.length; i++) { parentDir += pathParts[i] + "/"; // Make it so the dirs can be traversed by users. // We could instead try something more granular, like setting the directory // permission to 'rx' for each of the 3 user/group/other read permissions // found on the file being added (ie, only if "other" has read // permission on the main node, then add o+rx permission on all the containing // directories, same w/ user & group), and then also we'd have to // check the parentDirs collection of those already added to // see if those permissions need to be similarly updated. (Note, it hasn't // been demonstrated, but there might be a bug if a user specifically // requests a directory with certain permissions, // that has already been auto-created because it was a parent, and if so, go set // the user-requested mode on that directory instead of this automatic one.) // But for now, keeping it simple by making every dir a+rx. Examples are: // drw-r----- fs/fs # what you get with setMode(mode) // drwxr-xr-x fs/fs # Usable. Too loose? int mode = TarArchiveEntry.DEFAULT_DIR_MODE; createDirectory(parentDir, user, uid, group, gid, mode, 0); } } }; try { for (DataProducer data : producers) { data.produce(receiver); } } finally { tarOutputStream.close(); } console.info("Total size: " + dataSize); return dataSize.count; }
From source file:org.vafer.jdeb.maven.DebMojo.java
/** * Main entry point/*from w w w . java2 s.c om*/ * * @throws MojoExecutionException on error */ @Override public void execute() throws MojoExecutionException { final MavenProject project = getProject(); if (skip) { getLog().info("skipping as configured (skip)"); return; } if (skipPOMs && isPOM()) { getLog().info("skipping because artifact is a pom (skipPOMs)"); return; } if (skipSubmodules && isSubmodule()) { getLog().info("skipping submodule (skipSubmodules)"); return; } setData(dataSet); console = new MojoConsole(getLog(), verbose); initializeSignProperties(); final VariableResolver resolver = initializeVariableResolver(new HashMap<String, String>()); final File debFile = new File(Utils.replaceVariables(resolver, deb, openReplaceToken, closeReplaceToken)); final File controlDirFile = new File( Utils.replaceVariables(resolver, controlDir, openReplaceToken, closeReplaceToken)); final File installDirFile = new File( Utils.replaceVariables(resolver, installDir, openReplaceToken, closeReplaceToken)); final File changesInFile = new File( Utils.replaceVariables(resolver, changesIn, openReplaceToken, closeReplaceToken)); final File changesOutFile = new File( Utils.replaceVariables(resolver, changesOut, openReplaceToken, closeReplaceToken)); final File changesSaveFile = new File( Utils.replaceVariables(resolver, changesSave, openReplaceToken, closeReplaceToken)); final File keyringFile = keyring == null ? null : new File(Utils.replaceVariables(resolver, keyring, openReplaceToken, closeReplaceToken)); // if there are no producers defined we try to use the artifacts if (dataProducers.isEmpty()) { if (hasMainArtifact()) { Set<Artifact> artifacts = new HashSet<Artifact>(); artifacts.add(project.getArtifact()); @SuppressWarnings("unchecked") final Set<Artifact> projectArtifacts = project.getArtifacts(); for (Artifact artifact : projectArtifacts) { artifacts.add(artifact); } @SuppressWarnings("unchecked") final List<Artifact> attachedArtifacts = project.getAttachedArtifacts(); for (Artifact artifact : attachedArtifacts) { artifacts.add(artifact); } for (Artifact artifact : artifacts) { final File file = artifact.getFile(); if (file != null) { dataProducers.add(new DataProducer() { @Override public void produce(final DataConsumer receiver) { try { final File path = new File(installDirFile.getPath(), file.getName()); final String entryName = path.getPath(); final boolean symbolicLink = SymlinkUtils.isSymbolicLink(path); final TarArchiveEntry e; if (symbolicLink) { e = new TarArchiveEntry(entryName, TarConstants.LF_SYMLINK); e.setLinkName(SymlinkUtils.readSymbolicLink(path)); } else { e = new TarArchiveEntry(entryName, true); } e.setUserId(0); e.setGroupId(0); e.setUserName("root"); e.setGroupName("root"); e.setMode(TarEntry.DEFAULT_FILE_MODE); e.setSize(file.length()); receiver.onEachFile(new FileInputStream(file), e); } catch (Exception e) { getLog().error(e); } } }); } else { getLog().error("No file for artifact " + artifact); } } } } try { DebMaker debMaker = new DebMaker(console, dataProducers, conffileProducers); debMaker.setDeb(debFile); debMaker.setControl(controlDirFile); debMaker.setPackage(getProject().getArtifactId()); debMaker.setDescription(getProject().getDescription()); debMaker.setHomepage(getProject().getUrl()); debMaker.setChangesIn(changesInFile); debMaker.setChangesOut(changesOutFile); debMaker.setChangesSave(changesSaveFile); debMaker.setCompression(compression); debMaker.setKeyring(keyringFile); debMaker.setKey(key); debMaker.setPassphrase(passphrase); debMaker.setSignPackage(signPackage); debMaker.setSignMethod(signMethod); debMaker.setSignRole(signRole); debMaker.setResolver(resolver); debMaker.setOpenReplaceToken(openReplaceToken); debMaker.setCloseReplaceToken(closeReplaceToken); debMaker.validate(); debMaker.makeDeb(); // Always attach unless explicitly set to false if ("true".equalsIgnoreCase(attach)) { console.info("Attaching created debian package " + debFile); if (!isType()) { projectHelper.attachArtifact(project, type, classifier, debFile); } else { project.getArtifact().setFile(debFile); } } } catch (PackagingException e) { getLog().error("Failed to create debian package " + debFile, e); throw new MojoExecutionException("Failed to create debian package " + debFile, e); } if (!StringUtils.isBlank(propertyPrefix)) { project.getProperties().put(propertyPrefix + "version", getProjectVersion()); project.getProperties().put(propertyPrefix + "deb", debFile.getAbsolutePath()); project.getProperties().put(propertyPrefix + "deb.name", debFile.getName()); project.getProperties().put(propertyPrefix + "changes", changesOutFile.getAbsolutePath()); project.getProperties().put(propertyPrefix + "changes.name", changesOutFile.getName()); project.getProperties().put(propertyPrefix + "changes.txt", changesSaveFile.getAbsolutePath()); project.getProperties().put(propertyPrefix + "changes.txt.name", changesSaveFile.getName()); } }
From source file:org.vafer.jdeb.producers.DataProducerFileSet.java
@Override public void produce(final DataConsumer pReceiver) throws IOException { String user = Producers.ROOT_NAME; int uid = Producers.ROOT_UID; String group = Producers.ROOT_NAME; int gid = Producers.ROOT_UID; int filemode = TarEntry.DEFAULT_FILE_MODE; int dirmode = TarEntry.DEFAULT_DIR_MODE; String prefix = ""; if (fileset instanceof Tar.TarFileSet) { Tar.TarFileSet tarfileset = (Tar.TarFileSet) fileset; user = tarfileset.getUserName(); uid = tarfileset.getUid();//from www .ja v a 2s.c o m group = tarfileset.getGroup(); gid = tarfileset.getGid(); filemode = tarfileset.getMode(); dirmode = tarfileset.getDirMode(tarfileset.getProject()); prefix = tarfileset.getPrefix(tarfileset.getProject()); } final DirectoryScanner scanner = fileset.getDirectoryScanner(fileset.getProject()); scanner.scan(); final File basedir = scanner.getBasedir(); for (String directory : scanner.getIncludedDirectories()) { String name = directory.replace('\\', '/'); pReceiver.onEachDir(prefix + "/" + name, null, user, uid, group, gid, dirmode, 0); } for (String filename : scanner.getIncludedFiles()) { final String name = filename.replace('\\', '/'); final File file = new File(basedir, name); final InputStream inputStream = new FileInputStream(file); try { final String entryName = prefix + "/" + name; final File entryPath = new File(entryName); final boolean symbolicLink = SymlinkUtils.isSymbolicLink(entryPath); final TarArchiveEntry e; if (symbolicLink) { e = new TarArchiveEntry(entryName, TarConstants.LF_SYMLINK); e.setLinkName(SymlinkUtils.readSymbolicLink(entryPath)); } else { e = new TarArchiveEntry(entryName, true); } e.setUserId(uid); e.setGroupId(gid); e.setUserName(user); e.setGroupName(group); e.setMode(filemode); e.setSize(file.length()); pReceiver.onEachFile(inputStream, e); } finally { inputStream.close(); } } }