public Iterable getRevisions()

in src/main/java/org/apache/jenkins/gitpubsub/ASFGitSCMFileSystem.java [540:651]


        public Iterable<SCMRevision> getRevisions(@NonNull String remote, StandardCredentials credentials,
                                                  @NonNull Set<ReferenceType> referenceTypes)
                throws IOException, InterruptedException {
            List<String> result = new ArrayList<>();
            List<String> tagRev = new ArrayList<>();
            TYPES:
            for (ReferenceType referenceType : referenceTypes) {
                String actionUrl;
                Document doc;
                Elements elements;
                String prefix;
                switch (referenceType) {
                    case HEAD:
                        actionUrl = buildTemplateWithRemote("{+server}{?p}{;a}", remote)
                                .set("a", "heads")
                                .expand();
                        doc = fetchDocument(actionUrl);
                        elements = doc.select("table.heads tr td a.name");
                        prefix = Constants.R_HEADS;
                        break;
                    case TAG:
                        actionUrl = buildTemplateWithRemote("{+server}{?p}{;a}", remote)
                                .set("a", "tags")
                                .expand();
                        doc = fetchDocument(actionUrl);
                        elements = doc.select("table.tags tr td a.name");
                        prefix = Constants.R_TAGS;
                        break;
                    default:
                        LOGGER.log(Level.WARNING, "Ignoring unexpected reference type {0}", referenceType);
                        continue TYPES;
                }
                for (Element element : elements) {
                    result.add(prefix + element.text());
                    if (referenceType != ReferenceType.TAG) {
                        tagRev.add(null);
                    } else {
                        // resolve the revision of the tag
                        Elements links = element.parent().parent().select("td.selflink a");
                        String href;
                        if (!links.isEmpty()) {
                            // annotated tag
                            href = links.get(0).attr("href");
                        } else {
                            // lightweight tag
                            href = element.attr("href");
                        }
                        if (href != null) {
                            Matcher matcher = URL_EXTRACT_H.matcher(href);
                            if (matcher.matches()) {
                                tagRev.add(matcher.group(1));
                            } else {
                                tagRev.add(null);
                            }
                        } else {
                            tagRev.add(null);
                        }
                    }
                }
            }
            return new AbstractList<SCMRevision>() {
                private final List<SCMRevision> cache = new ArrayList<>(result.size());

                {
                    for (int i = 0; i < result.size(); i++) {
                        cache.add(null);
                    }
                }

                /**
                 * {@inheritDoc}
                 */
                @Override
                public SCMRevision get(int index) {
                    SCMRevision r = cache.get(index);
                    if (r == null) {
                        String hash = tagRev.get(index);
                        if (hash != null) {
                            try {
                                r = new GitTagSCMRevision(
                                        new GitTagSCMHead(
                                                result.get(index).substring(Constants.R_TAGS.length()),
                                                getTimestamp(remote, credentials, result.get(index))
                                        ),
                                        hash
                                );
                            } catch (IOException | InterruptedException e) {
                                throw new RuntimeException("Tag retrieval Exception for " + result.get(index).substring(Constants.R_TAGS.length()), e);
                            }
                            cache.set(index, r);
                        }
                    }
                    if (r == null) {
                        try {
                            r = getRevision(remote, credentials, result.get(index));
                        } catch (IOException | InterruptedException e) {
                            throw new RuntimeException("Annotated Tag retrieval Exception for :" + result.get(index), e);
                        }
                        cache.set(index, r);
                    }
                    return r;
                }

                /**
                 * {@inheritDoc}
                 */
                @Override
                public int size() {
                    return result.size();
                }
            };
        }