-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathcmake.groovy
executable file
·77 lines (69 loc) · 2.57 KB
/
cmake.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
#!./lib/runner.groovy
// Generates server-side metadata for CMake auto-installation
import org.htmlunit.html.*
import net.sf.json.*
import org.htmlunit.WebClient
import org.htmlunit.BrowserVersion
def baseUrl = 'https://cmake.org/files/'
def wc = new WebClient(
new BrowserVersion.BrowserVersionBuilder(BrowserVersion.BEST_SUPPORTED)
.setApplicationName("JenkinsBackendCrawler")
.setApplicationVersion("1.0")
.build()
)
wc.setCssErrorHandler(new org.htmlunit.SilentCssErrorHandler());
wc.getOptions().setJavaScriptEnabled(false);
wc.getOptions().setThrowExceptionOnScriptError(false);
wc.getOptions().setThrowExceptionOnFailingStatusCode(false);
def releases = [:]
// Gather a list of top dirs
def dirs = []
wc.getPage(baseUrl).getByXPath("//td/a").reverse().each { HtmlAnchor e ->
dirs << e.getHrefAttribute()
}
dirs.each { dir ->
// We only want download dir of v 2.6 (for RHEL7 !) and above
if (!(dir =~ /^v[2]\.[6-9].*/ || dir =~ /^v[3-9]\.\d+.*/)) {
return
}
// gather archive files
def files= []
// get version urls
wc.getPage(baseUrl+ dir).getByXPath("//td/a").reverse().each { HtmlAnchor e ->
files << e.getHrefAttribute()
}
// Build a map of Cmake versions -> platform archives
files.each { file ->
// We only want release archives; ignore source packages, installers and beta/RC versions
if (file =~ /\.src\.tar\.bz2$/ || file =~ /(alpha|beta|rc)\d+\./) {
return
}
if (! (file =~ /\.(zip|tar\.gz)$/)) {
return
}
// Extract the version info from archive filename
// cmake-2.6.4-Darwin-x86_64.tar.gz
// cmake-2.6.4-win32-i386.zip
def parts = (file =~ /^cmake-(\d+\.\d+\.\d+)-(HP-UX|[^-]+)-([^-]+)\.(?:tar\.gz|zip)$/)
if (!parts) {
return
}
// Gather the info for this archive
def variant = [:]
variant.url = baseUrl+ dir+ file;
variant.os = parts[0][2]
variant.arch = parts[0][3]
// Add it to the list of variants for this version of CMake
def version = parts[0][1]
if (!releases[version]) {
releases[version] = []
}
releases[version] << variant
}
}
// Build the JSON structure: a list of release objects, each with its platform-specific variants
def json = [list: releases.collect { key, value ->
[ "id": key, "name": "${key}".toString(),
"variants": value] }]
// Write the JSON update file
lib.DataWriter.write("hudson.plugins.cmake.CmakeInstaller",JSONObject.fromObject(json));