-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathchromedriver.groovy
executable file
·55 lines (51 loc) · 1.96 KB
/
chromedriver.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!./lib/runner.groovy
// Generates server-side metadata for chromedriver auto-installation
import net.sf.json.*
import groovy.util.XmlSlurper
def baseUrl = 'https://chromedriver.storage.googleapis.com/'
def json = []
def map = [:].withDefault {[:].withDefault {[:]}}
def xml = new XmlSlurper().parseText(new URL(baseUrl).text)
xml.Contents.each {
def key = it.Key.text()
def m = key =~ /(.*)\/chromedriver_(.*?)(\d+)\.zip/
if (m) {
def (_, version, os, arch) = m[0]
map[os][arch][version] = key
json << ["id":"${os}${arch}_${version}".toString(), "url":baseUrl + key];
}
}
map.each { os, arch ->
if (arch.size() == 1) {
def latest = arch.find().value.max { a, b ->
List verA = a.key.tokenize('.')
List verB = b.key.tokenize('.')
def commonIndices = Math.min(verA.size(), verB.size())
for (int i = 0; i < commonIndices; ++i) {
def numA = verA[i].toInteger()
def numB = verB[i].toInteger()
if (numA != numB) {
return numA <=> numB
}
}
verA.size() <=> verB.size() }
json << ["id":os, "url":baseUrl + latest.value];
} else {
arch.each { k, v ->
def latest = v.max { a, b ->
List verA = a.key.tokenize('.')
List verB = b.key.tokenize('.')
def commonIndices = Math.min(verA.size(), verB.size())
for (int i = 0; i < commonIndices; ++i) {
def numA = verA[i].toInteger()
def numB = verB[i].toInteger()
if (numA != numB) {
return numA <=> numB
}
}
verA.size() <=> verB.size() }
json << ["id":os + k, "url":baseUrl + latest.value];
}
}
}
lib.DataWriter.write("org.jenkins-ci.plugins.chromedriver.ChromeDriver",JSONObject.fromObject([list:json]));