-
Notifications
You must be signed in to change notification settings - Fork 67
/
adoptopenjdk.groovy
executable file
·96 lines (83 loc) · 3.55 KB
/
adoptopenjdk.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!./lib/runner.groovy
import org.htmlunit.Page
import org.htmlunit.WebClient
import org.htmlunit.WebResponse
import net.sf.json.JSONArray
import net.sf.json.JSONObject
class ListAdoptOpenJDK {
private final WebClient wc;
private final String API_URL = "https://api.adoptium.net/v3";
ListAdoptOpenJDK() {
wc = new WebClient();
wc.addRequestHeader("accept", "application/json")
wc.getOptions().setThrowExceptionOnFailingStatusCode(false);
wc.getOptions().setPrintContentOnFailingStatusCode(false);
}
void main() throws Exception {
lib.DataWriter.write("io.jenkins.plugins.adoptopenjdk.AdoptOpenJDKInstaller", build());
}
private JSONObject build() throws IOException {
Page p = wc.getPage(API_URL + "/info/available_releases")
WebResponse response = p.getWebResponse();
if (response.statusCode != 200) {
throw new Exception("Could not load available_releases")
}
JSONArray result = new JSONArray()
JSONObject data = JSONObject.fromObject(response.getContentAsString())
result.addAll(getReleases(data.available_releases as JSONArray, "HotSpot"))
return new JSONObject()
.element("version", 2)
.element("data", result);
}
private JSONArray getReleases(JSONArray available_releases, String jvm_impl) {
JSONArray result = new JSONArray()
available_releases.each { feature_version ->
JSONObject r = getRelease(feature_version as String, jvm_impl)
result.add(r)
}
return result
}
private JSONObject getRelease(String feature_version, String jvm_impl){
String openjdk_impl = jvm_impl.toLowerCase()
JSONObject r = new JSONObject()
r.put("name", "OpenJDK " + feature_version + " - " + jvm_impl)
Map<String, JSONObject> releasesMap = new LinkedHashMap<>();
int page = 0
boolean keepGoing = true
while (keepGoing) {
Page a = wc.getPage(API_URL + "/assets/feature_releases/" + feature_version + "/ga?vendor=eclipse&project=jdk&image_type=jdk&sort_method=DEFAULT&sort_order=DESC&page_size=20&page=" + (page++) + "&jvm_impl=" + openjdk_impl)
WebResponse ar = a.getWebResponse()
if (ar.getStatusCode() == 200) {
JSONArray assets = JSONArray.fromObject(ar.getContentAsString())
assets.forEach { JSONObject asset -> releasesMap.merge(asset.release_name as String, asset, { v1, v2 ->
if (v1.version_data?.adopt_build_number > v2.version_data?.adopt_build_number){
v1.binaries.addAll(v2.binaries);
return v1;
} else {
v2.binaries.addAll(v1.binaries);
return v2;
}
})}
} else {
keepGoing = false
}
}
def releases = releasesMap.values().collect {
[
release_name: it.release_name,
openjdk_impl: openjdk_impl,
binaries : it.binaries.collect {
[
architecture: it.architecture,
os : it.os,
openjdk_impl: it.jvm_impl,
binary_link : it.package.link
]
}
]
}
r.put("releases", releases)
return r
}
}
new ListAdoptOpenJDK().main();