-
Notifications
You must be signed in to change notification settings - Fork 67
/
dependencycheck.groovy
52 lines (45 loc) · 1.77 KB
/
dependencycheck.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
#!./lib/runner.groovy
// Generates server-side metadata for dependencycheck-launch auto-installation
import hudson.util.VersionNumber
import net.sf.json.*
def listFromGithub(int page) {
def url = ("https://api.github.com/repos/jeremylong/dependencycheck/releases?per_page=50&page=" + page).toURL()
def releases = JSONArray.fromObject(url.text)
releases.collect {
release ->
def version = release["tag_name"].substring(1)
["id": version,
"name": "dependency-check ${version}".toString(),
"url": "https://github.com/jeremylong/DependencyCheck/releases/download/v${version}/dependency-check-${version}-release.zip".toString()]
}
}
def listAll() {
Map versions = new HashMap()
for (int page = 0;; page++) {
def releases = listFromGithub(page)
releases.each {version -> versions.put(version["id"], version)}
if (releases.isEmpty()) {
break; // do {} until {}
}
}
return versions.values()
.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.jenkinsci.plugins.DependencyCheck.tools.DependencyCheckInstaller",JSONObject.fromObject([list:listAll()]));