in src/main/java/org/apache/jenkins/gitpubsub/ASFGitSCMFileSystem.java [400:445]
public long getTimestamp(@NonNull String remote, StandardCredentials credentials, @NonNull String refOrHash)
throws IOException, InterruptedException {
if (refOrHash.startsWith(Constants.R_TAGS)) {
String tagUrl = 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 {
throw e;
}
}
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 e) {
throw new IOException(
"Unexpected date format, expected RFC 2822, got " + elements.get(1).text());
} catch (IndexOutOfBoundsException e) {
throw new IOException(
"Unexpected response body for page " + tagUrl + ", expecting two timestamps only got " + elements.size());
}
}
}
String commitUrl = 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 e) {
throw new IOException("Unexpected date format, expected RFC 2822, got " + elements.get(1).text());
} catch (IndexOutOfBoundsException e) {
throw new IOException("Unexpected response body, expecting two timestamps only got " + elements.size());
}
}