本文整理汇总了Java中org.eclipse.jgit.treewalk.filter.PathFilter.create方法的典型用法代码示例。如果您正苦于以下问题:Java PathFilter.create方法的具体用法?Java PathFilter.create怎么用?Java PathFilter.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.treewalk.filter.PathFilter
的用法示例。
在下文中一共展示了PathFilter.create方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RepositoryProcessor
import org.eclipse.jgit.treewalk.filter.PathFilter; //导入方法依赖的package包/类
public RepositoryProcessor(boolean deduplicateChildCommits, String toRef, String nextRelease, String gitHubUrl,
Predicate<RevCommit> commitFilter, List<CommitHandler> commitHandlers, String pathFilter,
String tagPrefix, Log log) {
this.deduplicateChildCommits = deduplicateChildCommits;
this.toRef = toRef;
this.nextRelease = nextRelease;
this.gitHubUrl = gitHubUrl;
this.commitFilter = commitFilter;
if (!isBlank(pathFilter) && !"/".equals(pathFilter)) {
this.pathFilter = PathFilter.create(pathFilter);
} else {
this.pathFilter = PathFilter.ALL;
}
this.commitHandlers.addAll(commitHandlers);
tagPattern = Pattern.compile(tagPrefix + "-([^-]+?)$");
this.log = log;
}
示例2: forPath
import org.eclipse.jgit.treewalk.filter.PathFilter; //导入方法依赖的package包/类
@Nonnull
private TreeWalk forPath(String path) throws IOException {
TreeWalk tw = prepareTreeWalk(false);
PathFilter filter = PathFilter.create(path.charAt(0) == '/' ? path.substring(1) : path);
tw.setFilter(filter);
tw.setRecursive(false);
while(tw.next()) {
if(filter.isDone(tw))
return tw;
if(tw.isSubtree())
tw.enterSubtree();
}
throw new IllegalStateException();
}
示例3: streamFromRepo
import org.eclipse.jgit.treewalk.filter.PathFilter; //导入方法依赖的package包/类
protected boolean streamFromRepo(HttpServletRequest request, HttpServletResponse response, Repository repository, RevCommit commit,
String requestedPath) throws IOException {
boolean served = false;
RevWalk rw = new RevWalk(repository);
TreeWalk tw = new TreeWalk(repository);
try {
tw.reset();
tw.addTree(commit.getTree());
PathFilter f = PathFilter.create(requestedPath);
tw.setFilter(f);
tw.setRecursive(true);
MutableObjectId id = new MutableObjectId();
ObjectReader reader = tw.getObjectReader();
while (tw.next()) {
FileMode mode = tw.getFileMode(0);
if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
continue;
}
tw.getObjectId(id, 0);
String filename = StringUtils.getLastPathElement(requestedPath);
try {
String userAgent = request.getHeader("User-Agent");
if (userAgent != null && userAgent.indexOf("MSIE 5.5") > -1) {
response.setHeader("Content-Disposition", "filename=\"" + URLEncoder.encode(filename, Constants.ENCODING) + "\"");
} else if (userAgent != null && userAgent.indexOf("MSIE") > -1) {
response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(filename, Constants.ENCODING) + "\"");
} else {
response.setHeader("Content-Disposition", "attachment; filename=\""
+ new String(filename.getBytes(Constants.ENCODING), "latin1") + "\"");
}
} catch (UnsupportedEncodingException e) {
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
}
long len = reader.getObjectSize(id, org.eclipse.jgit.lib.Constants.OBJ_BLOB);
setContentType(response, "application/octet-stream");
response.setIntHeader("Content-Length", (int) len);
ObjectLoader ldr = repository.open(id);
ldr.copyTo(response.getOutputStream());
served = true;
}
} finally {
tw.close();
rw.dispose();
}
response.flushBuffer();
return served;
}
示例4: getFilesInPath
import org.eclipse.jgit.treewalk.filter.PathFilter; //导入方法依赖的package包/类
/**
* Returns the list of files in the specified folder at the specified commit. If the repository does not exist or is empty, an empty list is
* returned.
*
* @param repository
* @param path
* if unspecified, root folder is assumed.
* @param commit
* if null, HEAD is assumed.
* @return list of files in specified path
*/
public static List<PathModel> getFilesInPath(Repository repository, String path, RevCommit commit) {
List<PathModel> list = new ArrayList<PathModel>();
if (!hasCommits(repository)) {
return list;
}
if (commit == null) {
commit = getCommit(repository, null);
}
try (TreeWalk tw = new TreeWalk(repository)) {
tw.addTree(commit.getTree());
if (!StringUtils.isEmpty(path)) {
PathFilter f = PathFilter.create(path);
tw.setFilter(f);
tw.setRecursive(false);
boolean foundFolder = false;
while (tw.next()) {
if (!foundFolder && tw.isSubtree()) {
tw.enterSubtree();
}
if (tw.getPathString().equals(path)) {
foundFolder = true;
continue;
}
if (foundFolder) {
list.add(getPathModel(tw, path, commit));
}
}
} else {
tw.setRecursive(false);
while (tw.next()) {
list.add(getPathModel(tw, null, commit));
}
}
} catch (IOException e) {
error(e, repository, "{0} failed to get files for commit {1}", commit.getName());
}
Collections.sort(list);
return list;
}
示例5: getFilesInPath2
import org.eclipse.jgit.treewalk.filter.PathFilter; //导入方法依赖的package包/类
/**
* Returns the list of files in the specified folder at the specified commit. If the repository does not exist or is empty, an empty list is
* returned.
*
* This is modified version that implements path compression feature.
*
* @param repository
* @param path
* if unspecified, root folder is assumed.
* @param commit
* if null, HEAD is assumed.
* @return list of files in specified path
*/
public static List<PathModel> getFilesInPath2(Repository repository, String path, RevCommit commit) {
List<PathModel> list = new ArrayList<PathModel>();
if (!hasCommits(repository)) {
return list;
}
if (commit == null) {
commit = getCommit(repository, null);
}
try (TreeWalk tw = new TreeWalk(repository)) {
tw.addTree(commit.getTree());
final boolean isPathEmpty = Strings.isNullOrEmpty(path);
if (!isPathEmpty) {
PathFilter f = PathFilter.create(path);
tw.setFilter(f);
}
tw.setRecursive(true);
List<String> paths = new ArrayList<>();
while (tw.next()) {
String child = isPathEmpty ? tw.getPathString() : tw.getPathString().replaceFirst(String.format("%s/", path), "");
paths.add(child);
}
for (String p : PathUtils.compressPaths(paths)) {
String pathString = isPathEmpty ? p : String.format("%s/%s", path, p);
list.add(getPathModel(repository, pathString, path, commit));
}
} catch (IOException e) {
error(e, repository, "{0} failed to get files for commit {1}", commit.getName());
}
Collections.sort(list);
return list;
}
示例6: zip
import org.eclipse.jgit.treewalk.filter.PathFilter; //导入方法依赖的package包/类
/**
* Zips the contents of the tree at the (optionally) specified revision and the (optionally) specified basepath to the supplied outputstream.
*
* @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
*/
public static boolean zip(Repository repository, String basePath, String objectId, OutputStream os) {
RevCommit commit = JGitUtils.getCommit(repository, objectId);
if (commit == null) {
return false;
}
boolean success = false;
RevWalk rw = new RevWalk(repository);
TreeWalk tw = new TreeWalk(repository);
try {
tw.reset();
tw.addTree(commit.getTree());
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
zos.setComment("Generated by Gitblit");
if (!StringUtils.isEmpty(basePath)) {
PathFilter f = PathFilter.create(basePath);
tw.setFilter(f);
}
tw.setRecursive(true);
MutableObjectId id = new MutableObjectId();
ObjectReader reader = tw.getObjectReader();
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);
ZipArchiveEntry entry = new ZipArchiveEntry(tw.getPathString());
entry.setSize(reader.getObjectSize(id, Constants.OBJ_BLOB));
entry.setComment(commit.getName());
entry.setUnixMode(mode.getBits());
entry.setTime(modified);
zos.putArchiveEntry(entry);
ObjectLoader ldr = repository.open(id);
ldr.copyTo(zos);
zos.closeArchiveEntry();
}
zos.finish();
success = true;
} catch (IOException e) {
error(e, repository, "{0} failed to zip files from commit {1}", commit.getName());
} finally {
tw.close();
rw.close();
rw.dispose();
}
return success;
}
示例7: zip
import org.eclipse.jgit.treewalk.filter.PathFilter; //导入方法依赖的package包/类
/**
* Zips the contents of the tree at the (optionally) specified revision and
* the (optionally) specified basepath to the supplied outputstream.
*
* @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
*/
public static boolean zip(Repository repository, String basePath, String objectId,
OutputStream os) {
RevCommit commit = JGitUtils.getCommit(repository, objectId);
if (commit == null) {
return false;
}
boolean success = false;
RevWalk rw = new RevWalk(repository);
TreeWalk tw = new TreeWalk(repository);
try {
tw.reset();
tw.addTree(commit.getTree());
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
zos.setComment("Generated by Gitblit");
if (!StringUtils.isEmpty(basePath)) {
PathFilter f = PathFilter.create(basePath);
tw.setFilter(f);
}
tw.setRecursive(true);
MutableObjectId id = new MutableObjectId();
ObjectReader reader = tw.getObjectReader();
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);
ZipArchiveEntry entry = new ZipArchiveEntry(tw.getPathString());
entry.setSize(reader.getObjectSize(id, Constants.OBJ_BLOB));
entry.setComment(commit.getName());
entry.setUnixMode(mode.getBits());
entry.setTime(modified);
zos.putArchiveEntry(entry);
ObjectLoader ldr = repository.open(id);
ldr.copyTo(zos);
zos.closeArchiveEntry();
}
zos.finish();
success = true;
} catch (IOException e) {
error(e, repository, "{0} failed to zip files from commit {1}", commit.getName());
} finally {
tw.release();
rw.dispose();
}
return success;
}
示例8: getFilesInPath
import org.eclipse.jgit.treewalk.filter.PathFilter; //导入方法依赖的package包/类
/**
* Returns the list of files in the specified folder at the specified
* commit. If the repository does not exist or is empty, an empty list is
* returned.
*
* @param repository
* @param path
* if unspecified, root folder is assumed.
* @param commit
* if null, HEAD is assumed.
* @return list of files in specified path
*/
public static List<PathModel> getFilesInPath(Repository repository, String path,
RevCommit commit) {
List<PathModel> list = new ArrayList<PathModel>();
if (!hasCommits(repository)) {
return list;
}
if (commit == null) {
commit = getCommit(repository, null);
}
final TreeWalk tw = new TreeWalk(repository);
try {
tw.addTree(commit.getTree());
if (!StringUtils.isEmpty(path)) {
PathFilter f = PathFilter.create(path);
tw.setFilter(f);
tw.setRecursive(false);
boolean foundFolder = false;
while (tw.next()) {
if (!foundFolder && tw.isSubtree()) {
tw.enterSubtree();
}
if (tw.getPathString().equals(path)) {
foundFolder = true;
continue;
}
if (foundFolder) {
list.add(getPathModel(tw, path, commit));
}
}
} else {
tw.setRecursive(false);
while (tw.next()) {
list.add(getPathModel(tw, null, commit));
}
}
} catch (IOException e) {
error(e, repository, "{0} failed to get files for commit {1}", commit.getName());
} finally {
tw.release();
}
Collections.sort(list);
return list;
}
示例9: create
import org.eclipse.jgit.treewalk.filter.PathFilter; //导入方法依赖的package包/类
/**
* Create a new tree filter for a user supplied path.
* <p>
* Path strings are relative to the root of the repository. If the user's
* input should be assumed relative to a subdirectory of the repository the
* caller must prepend the subdirectory's path prior to creating the filter.
* <p>
* Path strings use '/' to delimit directories on all platforms.
*
* @param path
* the path to filter on. Must not be the empty string. All
* trailing '/' characters will be trimmed before string's length
* is checked or is used as part of the constructed filter.
* @param cfg
* diff config specifying rename detection options.
* @return a new filter for the requested path.
* @throws IllegalArgumentException
* the path supplied was the empty string.
* @since 3.0
*/
public static FollowFilter create(String path, DiffConfig cfg) {
return new FollowFilter(PathFilter.create(path), cfg);
}