public long lastModified()

in src/main/java/org/apache/jenkins/gitpubsub/ASFGitSCMFile.java [112:177]


    public long lastModified() throws IOException, InterruptedException {
        if (isRoot()) {
            if (refOrHash.startsWith(Constants.R_TAGS)) {
                String tagUrl = ASFGitSCMFileSystem.buildTemplateWithRemote("{+server}{?p}{;a,h}", remote)
                        .set("a", "tag")
                        .set("h", refOrHash)
                        .expand();
                Document doc;
                try {
                    doc = fetchDocument(tagUrl);
                } catch (HttpStatusException e) {
                    if (e.getStatusCode() == 404) {
                        // must be a lightweight tag
                        doc = null;
                    } else {
                        return 0L;
                    }
                }
                if (doc != null) {
                    Elements elements = doc.select("table.object_header tr td span.datetime");
                    try {
                        return new SimpleDateFormat(RFC_2822).parse(elements.get(0).text())
                                .getTime();
                    } catch (ParseException | IndexOutOfBoundsException e) {
                        return 0L;
                    }
                }
            }
            String commitUrl = ASFGitSCMFileSystem.buildTemplateWithRemote("{+server}{?p}{;a,h}", remote)
                    .set("a", "commit")
                    .set("h", refOrHash)
                    .expand();
            Document doc = fetchDocument(commitUrl);
            Elements elements = doc.select("table.object_header tr td span.datetime");
            try {
                return new SimpleDateFormat(RFC_2822).parse(elements.get(1).text()).getTime();
            } catch (ParseException | IndexOutOfBoundsException e) {
                return 0L;
            }
        }
        String historyUrl = ASFGitSCMFileSystem.buildTemplateWithRemote("{+server}{?p}{;a,hb,f}", remote)
                .set("a", "history")
                .set("hb", refOrHash)
                .set("f", getPath())
                .expand();
        Document doc = fetchDocument(historyUrl);
        Elements elements = doc.select("table.history tr td a.subject");
        if (elements.isEmpty()) {
            return 0L;
        }
        Matcher href = ASFGitSCMFileSystem.URL_EXTRACT_H.matcher(elements.get(0).attr("href"));
        if (!href.matches()) {
            return 0L;
        }
        String commitUrl = ASFGitSCMFileSystem.buildTemplateWithRemote("{+server}{?p}{;a,h}", remote)
                .set("a", "commit")
                .set("h", href.group(1))
                .expand();
        doc = fetchDocument(commitUrl);
        elements = doc.select("table.object_header tr td span.datetime");
        try {
            return new SimpleDateFormat(RFC_2822).parse(elements.get(1).text()).getTime();
        } catch (ParseException | IndexOutOfBoundsException e) {
            return 0L;
        }
    }