-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathallure.groovy
More file actions
executable file
·121 lines (105 loc) · 3.76 KB
/
Copy pathallure.groovy
File metadata and controls
executable file
·121 lines (105 loc) · 3.76 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!./lib/runner.groovy
// Generates server-side metadata for Allure
import org.htmlunit.html.HtmlAnchor;
import org.htmlunit.WebClient
import hudson.util.VersionNumber
import org.htmlunit.html.HtmlPage
import java.util.regex.Pattern
import net.sf.json.JSONObject
// HACK HACK HACK HACK - https://github.com/jenkins-infra/crawler/issues/175 (phase 1)
lib.DataWriter.write("ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstaller", JSONObject.fromObject(new File("allure.hack.json").text));
System.exit(0)
// End of HACK HACK HACK HACK
def getList() {
List versions = new ArrayList()
versions.addAll(getCentralVersions())
versions.addAll(getSonatypeVersions())
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)
}
}
}
}
def getCentralVersions() {
String baseUrl = 'https://repo1.maven.org/maven2/io/qameta/allure/allure-commandline/'
URL metaUrl = new URL(baseUrl)
WebClient wc = new WebClient()
wc.setCssErrorHandler(new org.htmlunit.SilentCssErrorHandler());
wc.getOptions().setThrowExceptionOnScriptError(false);
wc.getOptions().setThrowExceptionOnFailingStatusCode(false);
HtmlPage p = wc.getPage(metaUrl);
def versions = []
def pattern = Pattern.compile("^([0-9]+.*)/\$");
p.getAnchors().each {
HtmlAnchor a ->
def m = pattern.matcher(a.hrefAttribute)
if (m.find()) {
def ver = m.group(1)
if (!ver.contains("BETA")) {
versions.add(ver)
}
}
}
return versions.collect() { version ->
return ["id" : version,
"name": version,
"url" : String.format('%s%s/allure-commandline-%s.zip', baseUrl, version, version)
]
}
}
def getSonatypeVersions() {
String baseUrl = 'https://oss.sonatype.org/content/repositories/releases/ru/yandex/qatools/allure/allure-commandline/'
URL metaUrl = new URL(baseUrl)
WebClient wc = new WebClient()
wc.setCssErrorHandler(new org.htmlunit.SilentCssErrorHandler());
wc.getOptions().setThrowExceptionOnScriptError(false);
wc.getOptions().setThrowExceptionOnFailingStatusCode(false);
HtmlPage p = wc.getPage(metaUrl);
def versions = []
def pattern = Pattern.compile("^([0-9]+.*)/\$");
p.getAnchors().each {
HtmlAnchor a ->
def m = pattern.matcher(a.hrefAttribute)
if (m.find()) {
def ver = m.group(1)
if (!ver.contains("RC")) {
versions.add(ver)
}
}
}
return versions.collect() { version ->
return ["id" : version,
"name": version,
"url" : getSonatypeArtifactUrl(baseUrl, version)
]
}
}
def getSonatypeArtifactUrl(String baseUrl, String version) {
def artifactName = getSonatypeArtifactName(version);
return String.format('%s%s/%s', baseUrl, version, artifactName);
}
def getSonatypeArtifactName(String version) {
switch (version) {
case '1.4.17': return String.format('allure-commandline-%s.zip', version)
default: return String.format('allure-commandline-%s-standalone.zip', version)
}
}
def store(key, o) {
JSONObject envelope = JSONObject.fromObject(["list": o])
lib.DataWriter.write(key, envelope)
}
store("ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstaller", getList())