org.eclipse.jgit.lib.Repository.getTags()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(91)

本文整理了Java中org.eclipse.jgit.lib.Repository.getTags方法的一些代码示例,展示了Repository.getTags的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Repository.getTags方法的具体详情如下:
包路径:org.eclipse.jgit.lib.Repository
类名称:Repository
方法名:getTags

Repository.getTags介绍

[英]Get mutable map of all tags
[中]获取所有标签的可变映射

代码示例

代码示例来源:origin: jphp-group/jphp

@Signature
public ArrayMemory getTags() {
  Map<String, Ref> tags = getWrappedObject().getRepository().getTags();
  ArrayMemory memory = new ArrayMemory();
  for (Map.Entry<String, Ref> entry : tags.entrySet()) {
    memory.put(entry.getKey(), GitUtils.valueOf(entry.getValue()));
  }
  return memory;
}

代码示例来源:origin: FlowCI/flow-platform

/**
 * List all tag from local git
 *
 * @param repo
 * @return
 * @throws GitException
 */
public static List<String> tags(Repository repo) throws GitException {
  Map<String, Ref> tags = repo.getTags();
  List<Ref> refs = Lists.newArrayList(tags.values());
  Collections.reverse(refs);
  return simpleRef(refs);
}

代码示例来源:origin: bsorrentino/maven-confluence-plugin

public static Set<String> loadVersionTagList(Repository repository, String versionTagNamePattern) {
  Set<String> versionTagList = new HashSet<String>();
  if (versionTagNamePattern != null) {
    versionTagList = new HashSet<String>();
    for (String tagName : repository.getTags().keySet()) {
      if (tagName.matches(versionTagNamePattern)) {
        versionTagList.add(tagName);
      }
    }
  } else {
    versionTagList = repository.getTags().keySet();
  }
  return versionTagList;
}

代码示例来源:origin: io.fabric8/gitective-core

/**
 * Get all the tag references in the given repository.
 *
 * @param repository
 * @return non-null but possibly array of branch reference names
 */
public static Collection<String> getTags(final Repository repository) {
  if (repository == null)
    throw new IllegalArgumentException(
        Assert.formatNotNull("Repository"));
  return repository.getTags().keySet();
}

代码示例来源:origin: gradle.plugin.com.github.frankfarrell.blastradius/blast-radius

protected List<Version> getAllVersionsInRepository() {
  return repository
      .getTags()
      .keySet()
      .stream()
      .map(key -> {
        try {
          return Optional.of(Version.valueOf(key));
        } catch (Exception e) {
          return Optional.<Version>empty();
        }
      })
      .filter(Optional::isPresent)
      .map(Optional::get)
      .sorted()
      .collect(Collectors.toList());
}

代码示例来源:origin: org.eclipse.egit/ui

private List<Ref> getTags() {
  Repository repository = getCommit().getRepository();
  List<Ref> tags = new ArrayList<Ref>(repository.getTags().values());
  Collections.sort(tags, new Comparator<Ref>() {
    public int compare(Ref r1, Ref r2) {
      return Repository.shortenRefName(r1.getName())
          .compareToIgnoreCase(
              Repository.shortenRefName(r2.getName()));
    }
  });
  return tags;
}

代码示例来源:origin: org.eclipse.egit/ui

private String getTagsString() {
  StringBuilder sb = new StringBuilder();
  Map<String, Ref> tagsMap = db.getTags();
  for (Entry<String, Ref> tagEntry : tagsMap.entrySet()) {
    ObjectId target = tagEntry.getValue().getPeeledObjectId();
    if (target == null)
      target = tagEntry.getValue().getObjectId();
    if (target != null && target.equals(commit)) {
      if (sb.length() > 0)
        sb.append(", "); //$NON-NLS-1$
      sb.append(tagEntry.getKey());
    }
  }
  return sb.toString();
}

代码示例来源:origin: com.meltmedia.cadmium/cadmium-core

public boolean isTag(String tagname) throws Exception {
 Map<String, Ref> allRefs = git.getRepository().getTags();
 for(String key : allRefs.keySet()) {
  Ref ref = allRefs.get(key);
  log.trace("Checking tag key{}, ref{}", key, ref.getName());
  if(key.equals(tagname) && ref.getName().equals("refs/tags/" + tagname)) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: com.centurylink.mdw/mdw-common

public void checkoutTag(String tag) throws Exception {
  if (localRepo.getTags().get(tag) != null)
    git.checkout().setName(localRepo.getTags().get(tag).getName()).call();
}

代码示例来源:origin: airlift/airship

private Ref getLatestTag(String component)
{
  Map<String, Ref> forComponent = Maps.filterKeys(git.getRepository().getTags(), startsWith(component + "-"));
  if (!forComponent.isEmpty()) {
    String latest = Ordering.from(new VersionTagComparator()).max(forComponent.keySet());
    return forComponent.get(latest);
  }
  return null;
}

代码示例来源:origin: gradle.plugin.io.apioo.versioning/versioning-plugin

protected static Map<String, Ref> getTagsFromRepo(File projectDir) throws IOException {
  Repository repository = getRepository(getRepositoryLocation(projectDir));
  return repository.getTags();
}

代码示例来源:origin: gradle.plugin.com.github.frankfarrell.blastradius/blast-radius

protected List<String> getTagsOnHead() throws IOException {
  final ObjectId head = repository.resolve(Constants.HEAD);
  logger.info("Head is {}", head.toString());
  return repository.getTags().entrySet().stream()
      .filter(entry -> {
        final Boolean value = entry.getValue().getPeeledObjectId() != null &&
            entry.getValue().getPeeledObjectId().compareTo(head) == 0;
        logger.debug("Comparing {} to {} : result {}", entry.getValue().getPeeledObjectId(), head, value);
        return value;
      })
      .map(Map.Entry::getKey)
      .collect(Collectors.toList());
}

代码示例来源:origin: org.hudsonci.plugins/git

public List<Tag> getTagsOnCommit(String revName) throws GitException, IOException {
  Repository db = getRepository();
  ObjectId commit = db.resolve(revName);
  List<Tag> result = new ArrayList<Tag>();
  if (null != commit) {
    for (final Map.Entry<String, Ref> tag : db.getTags().entrySet()) {
      Ref ref = tag.getValue();
      if (ref.getObjectId().equals(commit)) {
        result.add(new Tag(tag.getKey(), ref.getObjectId()));
      }
    }
  }
  return result;
}

代码示例来源:origin: jenkinsci/git-client-plugin

/** {@inheritDoc} */
@Deprecated
public List<Tag> getTagsOnCommit(String revName) throws GitException, IOException {
  try (Repository db = getRepository()) {
    final ObjectId commit = db.resolve(revName);
    final List<Tag> ret = new ArrayList<>();
    for (final Map.Entry<String, Ref> tag : db.getTags().entrySet()) {
      Ref value = tag.getValue();
      if (value != null) {
        final ObjectId tagId = value.getObjectId();
        if (commit != null && commit.equals(tagId))
          ret.add(new Tag(tag.getKey(), tagId));
      }
    }
    return ret;
  }
}

代码示例来源:origin: danielflower/maven-gitlog-plugin

private Map<String, List<RevTag>> createCommitIDToTagsMap(Repository repository, RevWalk revWalk) throws IOException {
  Map<String, Ref> allTags = repository.getTags();
  Map<String, List<RevTag>> revTags = new HashMap<String, List<RevTag>>();
  for (Ref ref : allTags.values()) {
    try {
      RevTag revTag = revWalk.parseTag(ref.getObjectId());
      String commitID = revTag.getObject().getId().getName();
      if (!revTags.containsKey(commitID)) {
        revTags.put(commitID, new ArrayList<RevTag>());
      }
      revTags.get(commitID).add(revTag);
    } catch (IncorrectObjectTypeException e) {
      log.debug("Light-weight tags not supported. Skipping " + ref.getName());
    }
  }
  return revTags;
}

代码示例来源:origin: io.github.svndump-to-git/git-importer

private RevTree extractTag(String tagName) throws MissingObjectException, IncorrectObjectTypeException, IOException {
  RevWalk walk = new RevWalk(repository);
  
  Map<String, Ref> tags = repository.getTags();
  
  Ref tag = tags.get(tagName);
  RevTree target = walk.parseTree(tag.getObjectId());
  
  walk.close();
  return target;
}

代码示例来源:origin: org.eclipse.egit/ui

/**
 * @param event
 * @return the tags
 * @throws ExecutionException
 */
protected List<RevTag> getRevTags(ExecutionEvent event)
    throws ExecutionException {
  Repository repo = getRepository(event);
  Collection<Ref> revTags = repo.getTags().values();
  List<RevTag> tags = new ArrayList<RevTag>();
  RevWalk walk = new RevWalk(repo);
  for (Ref ref : revTags) {
    try {
      tags.add(walk.parseTag(repo.resolve(ref.getName())));
    } catch (IOException e) {
      throw new ExecutionException(e.getMessage(), e);
    }
  }
  return tags;
}

代码示例来源:origin: jenkinsci/git-client-plugin

/** {@inheritDoc} */
@Override
public Set<String> getTagNames(String tagPattern) throws GitException {
  if (tagPattern == null) tagPattern = "*";
  Set<String> tags = new HashSet<>();
  try (Repository repo = getRepository()) {
    FileNameMatcher matcher = new FileNameMatcher(tagPattern, null);
    Map<String, Ref> tagList = repo.getTags();
    for (String name : tagList.keySet()) {
      matcher.reset();
      matcher.append(name);
      if (matcher.isMatch()) tags.add(name);
    }
  } catch (InvalidPatternException e) {
    throw new GitException(e);
  }
  return tags;
}

代码示例来源:origin: gradle.plugin.com.palantir.gradle.gitversion/gradle-git-version

private Map<String, RefWithTagName> mapCommitsToTags(Git git) {
  RefWithTagNameComparator comparator = new RefWithTagNameComparator(git);
  // Maps commit hash to list of all refs pointing to given commit hash.
  // All keys in this map should be same as commit hashes in 'git show-ref --tags -d'
  Map<String, RefWithTagName> commitHashToTag = new HashMap<>();
  for (Map.Entry<String, Ref> entry : git.getRepository().getTags().entrySet()) {
    RefWithTagName refWithTagName = new RefWithTagName(entry.getValue(), entry.getKey());
    ObjectId peeledRef = refWithTagName.getRef().getPeeledObjectId();
    if (peeledRef == null) {
      // lightweight tag (commit object)
      updateCommitHashMap(commitHashToTag, comparator, entry.getValue().getObjectId(), refWithTagName);
    } else {
      // annotated tag (tag object)
      updateCommitHashMap(commitHashToTag, comparator, peeledRef, refWithTagName);
    }
  }
  return commitHashToTag;
}

代码示例来源:origin: airlift/airship

public Map<String, ByteSource> getEntries(Bundle bundle)
    throws IOException
{
  Ref ref;
  if (bundle.isSnapshot()) {
    // TODO: what does it mean to get entries for an old snapshot version?
    ref = getBranch(git.getRepository(), bundle.getName());
  }
  else {
    ref = git.getRepository().getTags().get(bundle.getName() + "-" + bundle.getVersionString());
    Preconditions.checkNotNull(ref, "cannot find tag for bundle %s:%s", bundle.getName(), bundle.getVersionString());
  }
  RevCommit commit = GitUtils.getCommit(git.getRepository(), ref);
  return Maps.transformValues(GitUtils.getEntries(git.getRepository(), commit.getTree()), byteSourceFunction(git.getRepository()));
}

相关文章

Repository类方法