-
Notifications
You must be signed in to change notification settings - Fork 67
/
sbt.groovy
executable file
·58 lines (50 loc) · 1.74 KB
/
sbt.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
56
57
58
#!./lib/runner.groovy
// Generates server-side metadata for sbt-launch auto-installation
import org.htmlunit.html.*;
import org.htmlunit.WebClient
import org.htmlunit.xml.XmlPage
import hudson.util.VersionNumber
import net.sf.json.*
def listFromMaven() {
String baseUrl = 'https://repo1.maven.org/maven2/org/scala-sbt/sbt'
URL metaUrl = new URL("$baseUrl/maven-metadata.xml")
WebClient wc = new WebClient()
XmlPage meta = wc.getPage(metaUrl)
List<String> versions = meta.getByXPath("//metadata/versioning/versions/version")
.collect() { DomElement e -> e.getTextContent() }
.findAll() { e -> !e.contains('RC') }
.reverse()
return versions.collect() { version ->
return ["id" : version,
"name": version,
"url" : getGithubArtifactUrl(version)
]
}
}
def getGithubArtifactUrl(String version) {
return String.format("https://github.com/sbt/sbt/releases/download/v%s/sbt-%s.zip", version, version)
}
def listAll() {
List versions = new ArrayList()
versions.addAll(listFromMaven())
return versions
.findAll { it != null }
.sort { o1,o2 ->
try {
def v1 = new VersionNumber(o1.id)
try {
new VersionNumber(o2.id).compareTo(v1)
} catch (IllegalArgumentException _2) {
-1
}
} catch (IllegalArgumentException _1) {
try {
new VersionNumber(o2.id)
1
} catch (IllegalArgumentException _2) {
o2.id.compareTo(o1.id)
}
}
}
}
lib.DataWriter.write("org.jvnet.hudson.plugins.SbtPluginBuilder.SbtInstaller",JSONObject.fromObject([list:listAll()]));