-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathflyway.groovy
executable file
·78 lines (65 loc) · 2.13 KB
/
flyway.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!./lib/runner.groovy
import org.htmlunit.WebClient
import org.htmlunit.html.HtmlAnchor
import org.htmlunit.html.HtmlPage
import hudson.util.VersionNumber
import net.sf.json.JSONObject
import java.util.regex.Pattern
// Generates server-side metadata for Flyway command-line
def webclient (){
def wc = new WebClient()
wc.setCssErrorHandler(new org.htmlunit.SilentCssErrorHandler());
wc.getOptions().setThrowExceptionOnScriptError(false);
wc.getOptions().setThrowExceptionOnFailingStatusCode(false);
return wc
}
def listFromMavenRepo() {
def json = []
def url = "https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/";
def wc=webclient();
HtmlPage p = wc.getPage(url);
def pattern = Pattern.compile("^([0-9]+.*)/\$");
p.getAnchors().collect { HtmlAnchor a ->
m = pattern.matcher(a.hrefAttribute)
if (m.find()) {
ver = m.group(1)
json.addAll( os_versions(url + ver, ver, wc))
}
}
return json
}
def os_versions(url, version, wc) {
json=[]
HtmlPage page= wc.getPage(url)
def pattern = Pattern.compile("flyway-commandline-" + ver + "(\\.tar\\.gz|-([a-z]+)-x64(\\.zip|\\.tar.gz))\$")
page.getAnchors().collect { HtmlAnchor a ->
m = pattern.matcher(a.hrefAttribute)
if (m.find()) {
installer_url=page.getFullyQualifiedUrl(m.group(0))
def parsed_platform = m.group(2)
platform = parsed_platform ? " (" + parsed_platform + ")": " (without JRE)"
id = version + ( parsed_platform ? "_" + parsed_platform : "nojre")
json << ["id": id, "name": ver + platform, "url": installer_url.toExternalForm()]
}
}
return json
}
def flyway_distributions = listFromMavenRepo()
flyway_distributions.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("sp.sd.flywayrunner.installation.FlywayInstaller", JSONObject.fromObject([list: flyway_distributions]));