Example usage for org.eclipse.jgit.lib FileMode SYMLINK

List of usage examples for org.eclipse.jgit.lib FileMode SYMLINK

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib FileMode SYMLINK.

Prototype

FileMode SYMLINK

To view the source code for org.eclipse.jgit.lib FileMode SYMLINK.

Click Source Link

Document

Mode indicating an entry is a symbolic link.

Usage

From source file:com.buildautomation.jgit.api.GetFileAttributes.java

License:Apache License

private static String getFileMode(FileMode fileMode) {
    if (fileMode.equals(FileMode.EXECUTABLE_FILE)) {
        return "Executable File";
    } else if (fileMode.equals(FileMode.REGULAR_FILE)) {
        return "Normal File";
    } else if (fileMode.equals(FileMode.TREE)) {
        return "Directory";
    } else if (fileMode.equals(FileMode.SYMLINK)) {
        return "Symlink";
    } else {// w  w w . j  a va  2 s. c  o m
        // there are a few others, see FileMode javadoc for details
        throw new IllegalArgumentException("Unknown type of file encountered: " + fileMode);
    }
}

From source file:com.gitblit.models.PathModel.java

License:Apache License

public boolean isSymlink() {
    return FileMode.SYMLINK.equals(mode);
}

From source file:com.gitblit.tests.JGitUtilsTest.java

License:Apache License

@Test
public void testFileModes() throws Exception {
    assertEquals("drwxr-xr-x", JGitUtils.getPermissionsFromMode(FileMode.TREE.getBits()));
    assertEquals("-rw-r--r--", JGitUtils.getPermissionsFromMode(FileMode.REGULAR_FILE.getBits()));
    assertEquals("-rwxr-xr-x", JGitUtils.getPermissionsFromMode(FileMode.EXECUTABLE_FILE.getBits()));
    assertEquals("symlink", JGitUtils.getPermissionsFromMode(FileMode.SYMLINK.getBits()));
    assertEquals("submodule", JGitUtils.getPermissionsFromMode(FileMode.GITLINK.getBits()));
    assertEquals("missing", JGitUtils.getPermissionsFromMode(FileMode.MISSING.getBits()));
}

From source file:com.gitblit.utils.CompressionUtils.java

License:Apache License

/**
 * Compresses/archives the contents of the tree at the (optionally)
 * specified revision and the (optionally) specified basepath to the
 * supplied outputstream./*  ww  w.  java  2s  .co 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, IFilestoreManager filestoreManager,
        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);

                FilestoreModel filestoreItem = null;

                if (JGitUtils.isPossibleFilestoreItem(loader.getSize())) {
                    filestoreItem = JGitUtils.getFilestoreItem(tw.getObjectReader().open(id));
                }

                final long size = (filestoreItem == null) ? loader.getSize() : filestoreItem.getSize();

                entry.setSize(size);
                tos.putArchiveEntry(entry);

                if (filestoreItem == null) {
                    //Copy repository stored file
                    loader.copyTo(tos);
                } else {
                    //Copy filestore file
                    try (FileInputStream streamIn = new FileInputStream(
                            filestoreManager.getStoragePath(filestoreItem.oid))) {

                        IOUtils.copyLarge(streamIn, tos);
                    } catch (Throwable e) {
                        LOGGER.error(
                                MessageFormat.format("Failed to archive filestore item {0}", filestoreItem.oid),
                                e);

                        //Handle as per other errors 
                        throw e;
                    }
                }

                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.close();
        rw.dispose();
    }
    return success;
}

From source file:com.gitblit.utils.JGitUtils.java

License:Apache License

/**
 * Returns a permissions representation of the mode bits.
 *
 * @param mode/*w w  w .  ja  v  a 2  s . co m*/
 * @return string representation of the mode bits
 */
public static String getPermissionsFromMode(int mode) {
    if (FileMode.TREE.equals(mode)) {
        return "drwxr-xr-x";
    } else if (FileMode.REGULAR_FILE.equals(mode)) {
        return "-rw-r--r--";
    } else if (FileMode.EXECUTABLE_FILE.equals(mode)) {
        return "-rwxr-xr-x";
    } else if (FileMode.SYMLINK.equals(mode)) {
        return "symlink";
    } else if (FileMode.GITLINK.equals(mode)) {
        return "submodule";
    }
    return "missing";
}

From source file:com.google.gitiles.PathServletTest.java

License:Open Source License

@Test
public void symlinkHtml() throws Exception {
    final RevBlob link = repo.blob("foo");
    repo.branch("master").commit().add("foo", "contents").edit(new PathEdit("bar") {
        @Override//from w w  w .  j av a  2s.c  om
        public void apply(DirCacheEntry ent) {
            ent.setFileMode(FileMode.SYMLINK);
            ent.setObjectId(link);
        }
    }).create();

    Map<String, ?> data = buildData("/repo/+/master/bar");
    assertEquals("SYMLINK", data.get("type"));
    assertEquals("foo", getBlobData(data).get("target"));
}

From source file:com.google.gitiles.PathServletTest.java

License:Open Source License

@Test
public void symlinkText() throws Exception {
    final RevBlob link = repo.blob("foo");
    repo.branch("master").commit().edit(new PathEdit("baz") {
        @Override//  w w  w  .  j  a v a  2 s. co m
        public void apply(DirCacheEntry ent) {
            ent.setFileMode(FileMode.SYMLINK);
            ent.setObjectId(link);
        }
    }).create();
    String text = buildText("/repo/+/master/baz?format=TEXT", "120000");
    assertEquals("foo", decodeBase64(text));
}

From source file:eu.trentorise.opendata.josman.Josmans.java

License:Open Source License

/**
 * Returns a string representation of the provided git file mode
 *///www. j  ava 2  s .c  o m
static String gitFileModeToString(FileMode fileMode) {
    if (fileMode.equals(FileMode.EXECUTABLE_FILE)) {
        return "Executable File";
    } else if (fileMode.equals(FileMode.REGULAR_FILE)) {
        return "Normal File";
    } else if (fileMode.equals(FileMode.TREE)) {
        return "Directory";
    } else if (fileMode.equals(FileMode.SYMLINK)) {
        return "Symlink";
    } else if (fileMode.equals(FileMode.GITLINK)) {
        return "submodule link";
    } else {
        return fileMode.toString();
    }

}

From source file:jenkins.plugins.git.GitSCMFile.java

License:Open Source License

@NonNull
@Override/*from  w ww  .j  a v a2 s.  c om*/
protected Type type() throws IOException, InterruptedException {
    return fs.invoke(new GitSCMFileSystem.FSFunction<Type>() {
        @Override
        public Type invoke(Repository repository) throws IOException, InterruptedException {
            try (RevWalk walk = new RevWalk(repository)) {
                RevCommit commit = walk.parseCommit(fs.getCommitId());
                RevTree tree = commit.getTree();
                try (TreeWalk tw = TreeWalk.forPath(repository, getPath(), tree)) {
                    if (tw == null) {
                        return SCMFile.Type.NONEXISTENT;
                    }
                    FileMode fileMode = tw.getFileMode(0);
                    if (fileMode == FileMode.MISSING) {
                        return SCMFile.Type.NONEXISTENT;
                    }
                    if (fileMode == FileMode.EXECUTABLE_FILE) {
                        return SCMFile.Type.REGULAR_FILE;
                    }
                    if (fileMode == FileMode.REGULAR_FILE) {
                        return SCMFile.Type.REGULAR_FILE;
                    }
                    if (fileMode == FileMode.SYMLINK) {
                        return SCMFile.Type.LINK;
                    }
                    if (fileMode == FileMode.TREE) {
                        return SCMFile.Type.DIRECTORY;
                    }
                    return SCMFile.Type.OTHER;
                }
            }
        }
    });
}

From source file:svnserver.repository.git.GitDeltaConsumer.java

License:GNU General Public License

@Nullable
public GitObject<ObjectId> getObjectId() throws IOException, SVNException {
    if ((originalId != null) && originalId.equals(objectId) && (newFilter == null)) {
        this.newFilter = oldFilter;
        this.objectId = originalId;
        if (oldFilter == null) {
            throw new IllegalStateException("Original object ID defined, but original Filter is not defined");
        }//from   w w  w  . j  a  v a2s.co m
        migrateFilter(writer.getRepository().getFilter(
                props.containsKey(SVNProperty.SPECIAL) ? FileMode.SYMLINK : FileMode.REGULAR_FILE,
                entry.getRawProperties()));
    }
    return objectId;
}