List of usage examples for org.eclipse.jgit.lib FileMode EXECUTABLE_FILE
FileMode EXECUTABLE_FILE
To view the source code for org.eclipse.jgit.lib FileMode EXECUTABLE_FILE.
Click Source Link
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. java 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 isFile() { return FileMode.REGULAR_FILE.equals(mode) || FileMode.EXECUTABLE_FILE.equals(mode) || (FileMode.MISSING.equals(mode) && !isSymlink() && !isSubmodule() && !isTree()); }
From source file:com.gitblit.servlet.PtServlet.java
License:Apache License
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {//www . j av a 2 s . c o m response.setContentType("application/octet-stream"); response.setDateHeader("Last-Modified", lastModified); response.setHeader("Cache-Control", "none"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); boolean windows = false; try { String useragent = request.getHeader("user-agent").toString(); windows = useragent.toLowerCase().contains("windows"); } catch (Exception e) { } byte[] pyBytes; File file = runtimeManager.getFileOrFolder("tickets.pt", "${baseFolder}/pt.py"); if (file.exists()) { // custom script pyBytes = readAll(new FileInputStream(file)); } else { // default script pyBytes = readAll(getClass().getResourceAsStream("/pt.py")); } if (windows) { // windows: download zip file with pt.py and pt.cmd response.setHeader("Content-Disposition", "attachment; filename=\"pt.zip\""); OutputStream os = response.getOutputStream(); ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os); // add the Python script ZipArchiveEntry pyEntry = new ZipArchiveEntry("pt.py"); pyEntry.setSize(pyBytes.length); pyEntry.setUnixMode(FileMode.EXECUTABLE_FILE.getBits()); pyEntry.setTime(lastModified); zos.putArchiveEntry(pyEntry); zos.write(pyBytes); zos.closeArchiveEntry(); // add a Python launch cmd file byte[] cmdBytes = readAll(getClass().getResourceAsStream("/pt.cmd")); ZipArchiveEntry cmdEntry = new ZipArchiveEntry("pt.cmd"); cmdEntry.setSize(cmdBytes.length); cmdEntry.setUnixMode(FileMode.REGULAR_FILE.getBits()); cmdEntry.setTime(lastModified); zos.putArchiveEntry(cmdEntry); zos.write(cmdBytes); zos.closeArchiveEntry(); // add a brief readme byte[] txtBytes = readAll(getClass().getResourceAsStream("/pt.txt")); ZipArchiveEntry txtEntry = new ZipArchiveEntry("readme.txt"); txtEntry.setSize(txtBytes.length); txtEntry.setUnixMode(FileMode.REGULAR_FILE.getBits()); txtEntry.setTime(lastModified); zos.putArchiveEntry(txtEntry); zos.write(txtBytes); zos.closeArchiveEntry(); // cleanup zos.finish(); zos.close(); os.flush(); } else { // unix: download a tar.gz file with pt.py set with execute permissions response.setHeader("Content-Disposition", "attachment; filename=\"pt.tar.gz\""); OutputStream os = response.getOutputStream(); CompressorOutputStream cos = new CompressorStreamFactory() .createCompressorOutputStream(CompressorStreamFactory.GZIP, os); TarArchiveOutputStream tos = new TarArchiveOutputStream(cos); tos.setAddPaxHeadersForNonAsciiNames(true); tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); // add the Python script TarArchiveEntry pyEntry = new TarArchiveEntry("pt"); pyEntry.setMode(FileMode.EXECUTABLE_FILE.getBits()); pyEntry.setModTime(lastModified); pyEntry.setSize(pyBytes.length); tos.putArchiveEntry(pyEntry); tos.write(pyBytes); tos.closeArchiveEntry(); // add a brief readme byte[] txtBytes = readAll(getClass().getResourceAsStream("/pt.txt")); TarArchiveEntry txtEntry = new TarArchiveEntry("README"); txtEntry.setMode(FileMode.REGULAR_FILE.getBits()); txtEntry.setModTime(lastModified); txtEntry.setSize(txtBytes.length); tos.putArchiveEntry(txtEntry); tos.write(txtBytes); tos.closeArchiveEntry(); // cleanup tos.finish(); tos.close(); cos.close(); os.flush(); } } catch (Exception e) { e.printStackTrace(); } }
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.JGitUtils.java
License:Apache License
/** * Returns a permissions representation of the mode bits. * * @param mode/*from www . j a v a2 s . c om*/ * @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.gerrit.server.git.SubmoduleOp.java
License:Apache License
void updateSubmoduleSubscriptions(ReviewDb db, Branch.NameKey destBranch) throws SubmoduleException { if (urlProvider.get() == null) { logAndThrowSubmoduleException("Cannot establish canonical web url used " + "to access gerrit. It should be provided in gerrit.config file."); }/*from w w w .j a va 2 s. c o m*/ try (Repository repo = repoManager.openRepository(destBranch.getParentKey()); RevWalk rw = new RevWalk(repo)) { ObjectId id = repo.resolve(destBranch.get()); if (id == null) { logAndThrowSubmoduleException("Cannot resolve submodule destination branch " + destBranch); } RevCommit commit = rw.parseCommit(id); Set<SubmoduleSubscription> oldSubscriptions = Sets .newHashSet(db.submoduleSubscriptions().bySuperProject(destBranch)); Set<SubmoduleSubscription> newSubscriptions; TreeWalk tw = TreeWalk.forPath(repo, GIT_MODULES, commit.getTree()); if (tw != null && (FileMode.REGULAR_FILE.equals(tw.getRawMode(0)) || FileMode.EXECUTABLE_FILE.equals(tw.getRawMode(0)))) { BlobBasedConfig bbc = new BlobBasedConfig(null, repo, commit, GIT_MODULES); String thisServer = new URI(urlProvider.get()).getHost(); newSubscriptions = subSecParserFactory.create(bbc, thisServer, destBranch).parseAllSections(); } else { newSubscriptions = Collections.emptySet(); } Set<SubmoduleSubscription> alreadySubscribeds = new HashSet<>(); for (SubmoduleSubscription s : newSubscriptions) { if (oldSubscriptions.contains(s)) { alreadySubscribeds.add(s); } } oldSubscriptions.removeAll(newSubscriptions); newSubscriptions.removeAll(alreadySubscribeds); if (!oldSubscriptions.isEmpty()) { db.submoduleSubscriptions().delete(oldSubscriptions); } if (!newSubscriptions.isEmpty()) { db.submoduleSubscriptions().insert(newSubscriptions); } } catch (OrmException e) { logAndThrowSubmoduleException( "Database problem at update of subscriptions table from " + GIT_MODULES + " file.", e); } catch (ConfigInvalidException e) { logAndThrowSubmoduleException( "Problem at update of subscriptions table: " + GIT_MODULES + " config file is invalid.", e); } catch (IOException e) { logAndThrowSubmoduleException("Problem at update of subscriptions table from " + GIT_MODULES + ".", e); } catch (URISyntaxException e) { logAndThrowSubmoduleException("Incorrect gerrit canonical web url provided in gerrit.config file.", e); } }
From source file:com.googlesource.gerrit.plugins.findowners.OwnersValidator.java
License:Apache License
private static boolean isFile(TreeWalk tw) { return FileMode.EXECUTABLE_FILE.equals(tw.getRawMode(0)) || FileMode.REGULAR_FILE.equals(tw.getRawMode(0)); }
From source file:com.microsoft.gittf.core.tasks.CreateCommitForChangesetVersionSpecTask.java
License:Open Source License
private void createBlob(final ObjectInserter repositoryInserter, final Map<CommitTreePath, Map<CommitTreePath, CommitTreeEntry>> treeHierarchy, final ChangesetCommitItemReader previousChangesetCommitReader, final Item item, final TaskProgressMonitor progressMonitor) throws Exception { Check.notNull(repositoryInserter, "repositoryInserter"); //$NON-NLS-1$ Check.notNull(treeHierarchy, "treeHierarchy"); //$NON-NLS-1$ Check.notNull(previousChangesetCommitReader, "previousChangesetCommitReader"); //$NON-NLS-1$ Check.notNull(item, "item"); //$NON-NLS-1$ Check.notNull(progressMonitor, "progressMonitor"); //$NON-NLS-1$ if (item.getItemType() == ItemType.FOLDER) { return;/*from ww w. ja v a 2 s . c om*/ } File tempFile = null; InputStream tempInputStream = null; ObjectId blobID = null; try { blobID = previousChangesetCommitReader.getFileObjectId(item.getServerItem(), item.getChangeSetID()); if (blobID == null || ObjectId.equals(blobID, ObjectId.zeroId())) { tempFile = File.createTempFile(GitTFConstants.GIT_TF_NAME, null, tempDir); try { versionControlService.downloadFile(item, tempFile.getAbsolutePath()); } catch (VersionControlException e) { // if the user is denied read permissions on the file an // exception will be thrown here. final String itemName = item.getServerItem() == null ? "" : item.getServerItem(); //$NON-NLS-1$ progressMonitor.displayWarning(Messages.formatString( "CreateCommitForChangesetVersionSpecTask.NoContentDueToPermissionOrDestroyFormat", //$NON-NLS-1$ itemName)); log.error(e); return; } if (tempFile.exists()) { tempInputStream = new FileInputStream(tempFile); blobID = repositoryInserter.insert(OBJ_BLOB, tempFile.length(), tempInputStream); } else { blobID = ObjectId.zeroId(); } } FileMode fileMode = FileMode.REGULAR_FILE; /* handle executable files */ if (item.getPropertyValues() != null) { if (PropertyConstants.EXECUTABLE_ENABLED_VALUE.equals( PropertyUtils.selectMatching(item.getPropertyValues(), PropertyConstants.EXECUTABLE_KEY))) { fileMode = FileMode.EXECUTABLE_FILE; } } createBlob(repositoryInserter, treeHierarchy, item.getServerItem(), blobID, fileMode, progressMonitor); } finally { if (tempInputStream != null) { tempInputStream.close(); } if (tempFile != null) { tempFile.delete(); } } }
From source file:com.microsoft.gittf.core.tasks.CreateCommitForPendingSetsTask.java
License:Open Source License
private void createBlob(final ObjectInserter repositoryInserter, final Map<CommitTreePath, Map<CommitTreePath, CommitTreeEntry>> treeHierarchy, final PendingChange pendingChange, final boolean addBaseContent, final TaskProgressMonitor progressMonitor) throws Exception { if (pendingChange.getItemType() == ItemType.FOLDER) { return;/*from w ww . ja v a 2 s. co m*/ } File tempFile = null; InputStream tempInputStream = null; ObjectId blobID = null; try { tempFile = File.createTempFile(GitTFConstants.GIT_TF_NAME, null, tempDir); if (addBaseContent) { versionControlService.downloadBaseFile(pendingChange, tempFile.getAbsolutePath()); } else { versionControlService.downloadShelvedFile(pendingChange, tempFile.getAbsolutePath()); } if (tempFile.exists()) { tempInputStream = new FileInputStream(tempFile); blobID = repositoryInserter.insert(OBJ_BLOB, tempFile.length(), tempInputStream); } else { blobID = ObjectId.zeroId(); } FileMode fileMode; /* handle executable files */ if (pendingChange.getPropertyValues() != null) { if (PropertyConstants.EXECUTABLE_ENABLED_VALUE.equals(PropertyUtils .selectMatching(pendingChange.getPropertyValues(), PropertyConstants.EXECUTABLE_KEY))) { fileMode = addBaseContent ? FileMode.REGULAR_FILE : FileMode.EXECUTABLE_FILE; } else { fileMode = addBaseContent ? FileMode.EXECUTABLE_FILE : FileMode.REGULAR_FILE; } } else { fileMode = FileMode.MISSING; } String serverItem = pendingChange.getSourceServerItem() != null && addBaseContent ? pendingChange.getSourceServerItem() : pendingChange.getServerItem(); createBlob(repositoryInserter, treeHierarchy, serverItem, blobID, fileMode, progressMonitor); } finally { if (tempInputStream != null) { tempInputStream.close(); } if (tempFile != null) { tempFile.delete(); } } }
From source file:com.microsoft.gittf.core.tasks.pendDiff.PropertyChange.java
License:Open Source License
public boolean isExecutablePropertyChanged() { return (oldMode == FileMode.EXECUTABLE_FILE) != (newMode == FileMode.EXECUTABLE_FILE); }