当前位置: 首页>>代码示例>>Java>>正文


Java PathFilter类代码示例

本文整理汇总了Java中org.eclipse.jgit.treewalk.filter.PathFilter的典型用法代码示例。如果您正苦于以下问题:Java PathFilter类的具体用法?Java PathFilter怎么用?Java PathFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PathFilter类属于org.eclipse.jgit.treewalk.filter包,在下文中一共展示了PathFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLoaderFrom

import org.eclipse.jgit.treewalk.filter.PathFilter; //导入依赖的package包/类
/**
 * Gets the loader for a file from a specified commit and its path
 * 
 * @param commit
 *          - the commit from which to get the loader
 * @param path
 *          - the path to the file
 * @return the loader
 * @throws MissingObjectException
 * @throws IncorrectObjectTypeException
 * @throws CorruptObjectException
 * @throws IOException
 */
public ObjectLoader getLoaderFrom(ObjectId commit, String path)
		throws IOException {
	Repository repository = git.getRepository();
	RevWalk revWalk = new RevWalk(repository);
	RevCommit revCommit = revWalk.parseCommit(commit);
	// and using commit's tree find the path
	RevTree tree = revCommit.getTree();
	TreeWalk treeWalk = new TreeWalk(repository);
	treeWalk.addTree(tree);
	treeWalk.setRecursive(true);
	treeWalk.setFilter(PathFilter.create(path));

	ObjectLoader loader = null;
	if (treeWalk.next()) {
		ObjectId objectId = treeWalk.getObjectId(0);
		loader = repository.open(objectId);
	}

	treeWalk.close();
	revWalk.close();
	return loader;
}
 
开发者ID:oxygenxml,项目名称:oxygen-git-plugin,代码行数:36,代码来源:GitAccess.java

示例2: printFile

import org.eclipse.jgit.treewalk.filter.PathFilter; //导入依赖的package包/类
private static void printFile(Repository repository, RevTree tree) throws IOException {
    // now try to find a specific file
    try (TreeWalk treeWalk = new TreeWalk(repository)) {
        treeWalk.addTree(tree);
        treeWalk.setRecursive(false);
        treeWalk.setFilter(PathFilter.create("README.md"));
        if (!treeWalk.next()) {
            throw new IllegalStateException("Did not find expected file 'README.md'");
        }

        // FileMode specifies the type of file, FileMode.REGULAR_FILE for normal file, FileMode.EXECUTABLE_FILE for executable bit
// set
        FileMode fileMode = treeWalk.getFileMode(0);
        ObjectLoader loader = repository.open(treeWalk.getObjectId(0));
        System.out.println("README.md: " + getFileMode(fileMode) + ", type: " + fileMode.getObjectType() + ", mode: " + fileMode +
                " size: " + loader.getSize());
    }
}
 
开发者ID:alexmy21,项目名称:gmds,代码行数:19,代码来源:GetFileAttributes.java

示例3: hasDiff

import org.eclipse.jgit.treewalk.filter.PathFilter; //导入依赖的package包/类
public static boolean hasDiff(Git git, String base, String name, String ext) 
                                                throws WsSrvException {    
   checkFile(base, name, ext).getAbsolutePath();

   // Prepare path for git save
   String fp = getLocalPath(name);

   List<DiffEntry> diff;
   try {
       diff = git.diff().setPathFilter(PathFilter.create(fp)).call();
   } catch (GitAPIException e) {
     throw new WsSrvException(260, "Unable retrieve git diff", e);
   }

   return diff.size() > 0;
}
 
开发者ID:osbitools,项目名称:OsBiToolsWs,代码行数:17,代码来源:GitUtils.java

示例4: 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;
}
 
开发者ID:jakubplichta,项目名称:git-changelog-maven-plugin,代码行数:18,代码来源:RepositoryProcessor.java

示例5: getObjectId

import org.eclipse.jgit.treewalk.filter.PathFilter; //导入依赖的package包/类
/**
 * TODO: see if performance can be improved
 */
private ObjectId getObjectId(File file) throws IOException {
    try (TreeWalk treeWalk = new TreeWalk(localRepo)) {
        treeWalk.addTree(new FileTreeIterator(localRepo));

        String path = getRepoPath(file);
        treeWalk.setFilter(PathFilter.create(path));

        while (treeWalk.next()) {
            WorkingTreeIterator workingTreeIterator = treeWalk.getTree(0, WorkingTreeIterator.class);
            if (treeWalk.getPathString().equals(path))
                return workingTreeIterator.getEntryObjectId();
            if (workingTreeIterator.getEntryFileMode().equals(FileMode.TREE))
                treeWalk.enterSubtree();
        }

        return ObjectId.zeroId(); // not found
    }
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:22,代码来源:VersionControlGit.java

示例6: readFromCommit

import org.eclipse.jgit.treewalk.filter.PathFilter; //导入依赖的package包/类
public byte[] readFromCommit(String commitId, String path) throws Exception {
    try (RevWalk revWalk = new RevWalk(localRepo)) {
        RevCommit commit = revWalk.parseCommit(ObjectId.fromString(commitId));
        // use commit's tree find the path
        RevTree tree = commit.getTree();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try (TreeWalk treeWalk = new TreeWalk(localRepo)) {
            treeWalk.addTree(tree);
            treeWalk.setRecursive(true);
            treeWalk.setFilter(PathFilter.create(path));
            if (!treeWalk.next()) {
                return null;
            }

            ObjectId objectId = treeWalk.getObjectId(0);
            ObjectLoader loader = localRepo.open(objectId);

            loader.copyTo(baos);
        }
        revWalk.dispose();
        return baos.toByteArray();
    }
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:24,代码来源:VersionControlGit.java

示例7: filterOutOtherModulesChanges

import org.eclipse.jgit.treewalk.filter.PathFilter; //导入依赖的package包/类
private void filterOutOtherModulesChanges(final String modulePath, final List<String> childModules,
		final RevWalk walk) {
	final boolean isRootModule = ".".equals(modulePath);
	final boolean isMultiModuleProject = !isRootModule || !childModules.isEmpty();
	final List<TreeFilter> treeFilters = new LinkedList<>();
	treeFilters.add(TreeFilter.ANY_DIFF);
	if (isMultiModuleProject) {
		if (!isRootModule) {
			// for sub-modules, look for changes only in the sub-module
			// path...
			treeFilters.add(PathFilter.create(modulePath));
		}

		// ... but ignore any sub-modules of the current sub-module, because
		// they can change independently of the current module
		for (final String childModule : childModules) {
			final String path = isRootModule ? childModule : modulePath + "/" + childModule;
			treeFilters.add(PathFilter.create(path).negate());
		}

	}
	final TreeFilter treeFilter = treeFilters.size() == 1 ? treeFilters.get(0) : AndTreeFilter.create(treeFilters);
	walk.setTreeFilter(treeFilter);
}
 
开发者ID:SourcePond,项目名称:release-maven-plugin-parent,代码行数:25,代码来源:GitRepository.java

示例8: getFileFromCommit

import org.eclipse.jgit.treewalk.filter.PathFilter; //导入依赖的package包/类
public static boolean getFileFromCommit(final OutputStream os, final String file, final Repository repo, final RevTree tree) throws IOException, GitAPIException {
    final TreeWalk treeWalk = new TreeWalk(repo);
    treeWalk.addTree(tree);
    treeWalk.setRecursive(true);
    treeWalk.setFilter(PathFilter.create(file));
    if (!treeWalk.next()) {
        logger.info("Did not find expected file '" + file + "'");
        return false;
    }

    final ObjectId objectId = treeWalk.getObjectId(0);
    final ObjectLoader loader = repo.open(objectId);

    // and then one can the loader to read the file
    loader.copyTo(os);
    return true;
}
 
开发者ID:cobr123,项目名称:VirtaMarketAnalyzer,代码行数:18,代码来源:GitHubPublisher.java

示例9: filterOutOtherModulesChanges

import org.eclipse.jgit.treewalk.filter.PathFilter; //导入依赖的package包/类
private void filterOutOtherModulesChanges(String modulePath, List<String> childModules, RevWalk walk) {
    boolean isRootModule = ".".equals(modulePath);
    boolean isMultiModuleProject = !isRootModule || !childModules.isEmpty();
    List<TreeFilter> treeFilters = new ArrayList<TreeFilter>();
    treeFilters.add(TreeFilter.ANY_DIFF);
    if (isMultiModuleProject) {
        if (!isRootModule) {
            // for sub-modules, look for changes only in the sub-module path...
            treeFilters.add(PathFilter.create(modulePath));
        }

        // ... but ignore any sub-modules of the current sub-module, because they can change independently of the current module
        for (String childModule : childModules) {
            String path = isRootModule ? childModule : modulePath + "/" + childModule;
            treeFilters.add(PathFilter.create(path).negate());
        }

    }
    TreeFilter treeFilter = treeFilters.size() == 1 ? treeFilters.get(0) : AndTreeFilter.create(treeFilters);
    walk.setTreeFilter(treeFilter);
}
 
开发者ID:danielflower,项目名称:multi-module-maven-release-plugin,代码行数:22,代码来源:TreeWalkingDiffDetector.java

示例10: getBlob

import org.eclipse.jgit.treewalk.filter.PathFilter; //导入依赖的package包/类
private Optional<String[]> getBlob(Git git, String fileName, CodeRevision revision)
		throws IOException {
	TreeWalk treeWalk = new TreeWalk(git.getRepository());
	treeWalk.addTree(getTreeIterator(git, revision));
	treeWalk.setFilter(PathFilter.create(fileName));
	treeWalk.setRecursive(true);
	if (!treeWalk.next()) {
		return Optional.empty();
	}
	ObjectId blobId = treeWalk.getObjectId(0);
	String content = new String(git.getRepository().getObjectDatabase().open(blobId).getBytes(),
			Charset.forName("UTF-8"));

	String[] lines = content.split("\n");
	return Optional.of(lines);
}
 
开发者ID:bugminer,项目名称:bugminer,代码行数:17,代码来源:GitStrategy.java

示例11: getDiffString

import org.eclipse.jgit.treewalk.filter.PathFilter; //导入依赖的package包/类
private String getDiffString() throws GitAPIException, IOException {
    ObjectId head = this.repo.resolve("HEAD");
    if(head == null) return "";

    // The following code is largely written by Tk421 on StackOverflow
    //      (http://stackoverflow.com/q/23486483)
    // Thanks! NOTE: comments are mine.
    ByteArrayOutputStream diffOutputStream = new ByteArrayOutputStream();
    DiffFormatter formatter = new DiffFormatter(diffOutputStream);
    formatter.setRepository(this.repo);
    formatter.setPathFilter(PathFilter.create(this.pathFilter.replaceAll("\\\\","/")));

    AbstractTreeIterator commitTreeIterator = prepareTreeParser(this.repo, head.getName());
    FileTreeIterator workTreeIterator = new FileTreeIterator(this.repo);

    // Scan gets difference between the two iterators.
    formatter.format(commitTreeIterator, workTreeIterator);

    return diffOutputStream.toString();
}
 
开发者ID:dmusican,项目名称:Elegit,代码行数:21,代码来源:DiffHelper.java

示例12: execute

import org.eclipse.jgit.treewalk.filter.PathFilter; //导入依赖的package包/类
public Optional<InputStream> execute() {
    try (final TreeWalk tw = new TreeWalk(git.getRepository())) {
        final ObjectId tree = git.getTreeFromRef(treeRef);
        tw.setFilter(PathFilter.create(path));
        tw.reset(tree);
        while (tw.next()) {
            if (tw.isSubtree() && !path.equals(tw.getPathString())) {
                tw.enterSubtree();
                continue;
            }
            return Optional.of(new ByteArrayInputStream(git.getRepository().open(tw.getObjectId(0),
                                                                                 Constants.OBJ_BLOB).getBytes()));
        }
    } catch (final Throwable t) {
        LOG.debug("Unexpected exception, this will trigger a NoSuchFileException.",
                  t);
        throw new NoSuchFileException("Can't find '" + path + "' in tree '" + treeRef + "'");
    }
    throw new NoSuchFileException("Can't find '" + path + "' in tree '" + treeRef + "'");
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:21,代码来源:BlobAsInputStream.java

示例13: getRevisaoMaisRecenteDoBranch

import org.eclipse.jgit.treewalk.filter.PathFilter; //导入依赖的package包/类
public Optional<Revisao> getRevisaoMaisRecenteDoBranch(String branchRef, Path caminhoRelativo) {

        RevCommit commit = comRepositorioAberto(uncheckedFunction(git -> {
            Repository repo = git.getRepository();
            RevWalk revWalk = new RevWalk(repo);

            revWalk.setTreeFilter(AndTreeFilter.create(PathFilter.create(caminhoRelativo.toString()), TreeFilter.ANY_DIFF));
            revWalk.markStart(revWalk.lookupCommit(repo.resolve(branchRef)));

            Iterator<RevCommit> revs = revWalk.iterator();
            if (revs.hasNext()) {
                return revs.next();
            }

            return null;
        }));

        if (commit == null) {
            return empty();
        }

        return of(new Revisao(commit));
    }
 
开发者ID:servicosgovbr,项目名称:editor-de-servicos,代码行数:24,代码来源:RepositorioGit.java

示例14: gitRepoContainsFile

import org.eclipse.jgit.treewalk.filter.PathFilter; //导入依赖的package包/类
public static boolean gitRepoContainsFile(Repository repository, String file) throws IllegalStateException, IOException {
	ObjectId lastCommitId = repository.resolve(Constants.HEAD);

       // a RevWalk allows to walk over commits based on some filtering
       RevWalk revWalk = new RevWalk(repository);
       RevCommit commit = revWalk.parseCommit(lastCommitId);

       // and using commit's tree find the path
       RevTree tree = commit.getTree();
       
       TreeWalk treeWalk = new TreeWalk(repository);
       treeWalk.addTree(tree);
       treeWalk.setRecursive(true);
       treeWalk.setFilter(PathFilter.create(file));
       return treeWalk.next(); 
}
 
开发者ID:jenkinsci,项目名称:openshift-deployer-plugin,代码行数:17,代码来源:TestUtils.java

示例15: formatHtmlDiff

import org.eclipse.jgit.treewalk.filter.PathFilter; //导入依赖的package包/类
private void formatHtmlDiff(OutputStream out,
    Repository repo, RevWalk walk,
    AbstractTreeIterator oldTree, AbstractTreeIterator newTree,
    String path)
    throws IOException {
  DiffFormatter diff = new HtmlDiffFormatter(renderer, out);
  try {
    if (!path.equals("")) {
      diff.setPathFilter(PathFilter.create(path));
    }
    diff.setRepository(repo);
    diff.setDetectRenames(true);
    diff.format(oldTree, newTree);
  } finally {
    diff.release();
  }
}
 
开发者ID:afrojer,项目名称:gitiles,代码行数:18,代码来源:DiffServlet.java


注:本文中的org.eclipse.jgit.treewalk.filter.PathFilter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。