/** * {@inheritDoc} */ @Override protected void decorateContext(SCMSourceContext<?, ?> context) { GitSCMSourceContext<?,?> ctx = (GitSCMSourceContext<?, ?>) context; ctx.wantTags(true); ctx.withAuthority(new TagSCMHeadAuthority()); }
@Override public Set<String> run(GitClient client, String remoteName) throws IOException, InterruptedException { Set<String> revisions = new HashSet<String>(); if (context.wantBranches()) { for (Branch branch : client.getRemoteBranches()) { revisions.add(branch.getName().replaceFirst( "^" + Pattern.quote(context.remoteName()) + "/", "" )); } } if (context.wantTags()) { revisions.addAll(client.getTagNames("*")); } return revisions; } },
@Override public Void run(GitClient client, String remoteName) throws IOException, InterruptedException { final Repository repository = client.getRepository(); try (RevWalk walk = new RevWalk(repository); GitSCMSourceRequest request = context.newRequest(AbstractGitSCMSource.this, listener)) { Map<String, ObjectId> remoteReferences = null; if (context.wantBranches() || context.wantTags()) { listener.getLogger().println("Listing remote references..."); remoteReferences = client.getRemoteReferences( client.getRemoteUrl(remoteName), null, context.wantBranches(), context.wantTags() ); } if (context.wantBranches()) { discoverBranches(repository, walk, request, remoteReferences); } if (context.wantTags()) { discoverTags(repository, walk, request, remoteReferences); } } return null; }
/** * Constructor. * * @param source the source. * @param context the context. * @param listener the (optional) {@link TaskListener}. */ public GitSCMSourceRequest(@NonNull SCMSource source, @NonNull GitSCMSourceContext<?, ?> context, TaskListener listener) { super(source, context, listener); fetchBranches = context.wantBranches(); fetchTags = context.wantTags(); remoteName = context.remoteName(); gitTool = context.gitTool(); refSpecs = Collections.unmodifiableList(context.asRefSpecs()); }
/** * {@inheritDoc} */ @Override protected boolean isCategoryEnabled(@NonNull SCMHeadCategory category) { if (category instanceof TagSCMHeadCategory) { return new GitSCMSourceContext<>(null, SCMHeadObserver.none()).withTraits(getTraits()).wantTags(); } return super.isCategoryEnabled(category); }