-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathgroovy.groovy
executable file
·37 lines (30 loc) · 1.35 KB
/
groovy.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!./lib/runner.groovy
// Generates server-side metadata for Groovy auto-installation
import org.htmlunit.html.*;
import net.sf.json.*
import org.htmlunit.WebClient
import org.htmlunit.BrowserVersion
final String applicationName = "crawler";
final String applicationVersion = "1.0";
final String userAgent = "jenkins-project-crawler";
final BrowserVersion browser =
new BrowserVersion.BrowserVersionBuilder(BrowserVersion.BEST_SUPPORTED)
.setApplicationName(applicationName)
.setApplicationVersion(applicationVersion)
.setUserAgent(userAgent)
.build();
// Set a custom user agent so the server won't redirect to https://groovy.jfrog.io/ui/native/dist-release-local/groovy-zips/
// which contains a script with the unsuppported JS function `fetch`
def wc = new WebClient(browser);
def baseUrl = 'https://groovy.jfrog.io/artifactory/dist-release-local/groovy-zips/'
HtmlPage p = wc.getPage(baseUrl);
def json = [];
p.getByXPath("//a[@href]").reverse().collect { HtmlAnchor e ->
def url = baseUrl + e.getHrefAttribute()
println url
def m = (url =~ /groovy-binary-(\d+.\d+.\d+).zip$/)
if (m) {
json << ["id":m[0][1], "name": "Groovy ${m[0][1]}".toString(), "url":url];
}
}
lib.DataWriter.write("hudson.plugins.groovy.GroovyInstaller",JSONObject.fromObject([list:json.sort { it.id }.reverse()]));