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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
import de.undercouch.gradle.tasks.download.Download
import de.undercouch.gradle.tasks.download.Verify
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id 'de.undercouch.download' version '3.1.1'
id 'nebula.ospackage' version '3.5.0'
}
ext {
sshKeyfile = new File(System.getProperty('user.home'), '.ssh/id_rsa')
sshKnownHosts = new File(System.getProperty('user.home'), '.ssh/known_hosts')
sshUser = 'yvesf'
sshHost = 'xapek.org'
sshTargetDir = 'public_html/public/debian/files'
sshReindexCommand = 'cd public_html/public/debian && make'
}
allprojects {
configurations {
sshAntTask
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
sshAntTask 'org.apache.ant:ant-jsch:1.9.2'
}
}
final reindex = tasks.create('reindex')
reindex.doLast {
ant.taskdef(
name: 'antSsh',
classname: 'org.apache.tools.ant.taskdefs.optional.ssh.SSHExec',
classpath: configurations.sshAntTask.asPath)
ant.antSsh(
host: sshHost,
username: sshUser,
keyfile: file(sshKeyfile),
knownhosts: file(sshKnownHosts),
command: sshReindexCommand,
verbose: true)
}
subprojects {
group 'org.xapek.yvesf.debian'
apply plugin: 'nebula.ospackage'
ant.taskdef(
name: 'antScp',
classname: 'org.apache.tools.ant.taskdefs.optional.ssh.Scp',
classpath: configurations.sshAntTask.asPath)
ospackage {
user = 'root'
}
// meta task
final download = tasks.create('download')
ext.makeDownloadTask = { Map params ->
final url = params.url
final basename = url.substring(url.lastIndexOf("/") + 1)
.grep { c -> c == '.' || Character.isAlphabetic((int) (c as char)) }
.join('')
final taskname = params.name ?: basename
final dest = new File(buildDir, "download_${basename}")
dest.parentFile.mkdirs()
final downloadTask = tasks.create(name: "download_${taskname}", type: Download)
downloadTask.src url
downloadTask.dest dest
downloadTask.overwrite false
final verifyTask = tasks.create(name: "verify_${taskname}", type: Verify)
verifyTask.src downloadTask.dest
verifyTask.algorithm 'SHA-256'
verifyTask.checksum params.sha256
downloadTask.finalizedBy(verifyTask)
download.dependsOn(downloadTask)
return downloadTask
}
final buildDeb = project.getTasks().getByName('buildDeb')
final upload = tasks.create('upload')
upload.doLast {
ant.antScp(
file: buildDeb.archivePath,
todir: "${sshUser}@${sshHost}:${sshTargetDir}",
keyfile: file(sshKeyfile),
knownhosts: file(sshKnownHosts),
verbose: true)
}
upload.group = 'build'
upload.dependsOn(buildDeb)
project.afterEvaluate {
ospackage.version = project.version
ospackage.release = "${new Date().format("yyyyMMdd")}T${new Date().format("HHmmss")}"
}
final activatorExtension = [
env : [:],
bin : [:],
requirements: []
]
project.extensions.add('activator', activatorExtension)
final activatorTask = task('activator')
activatorTask.doLast {
final activatorDir = new File(project.buildDir, 'activator')
activatorExtension.bin.each { entry ->
final starter = new File(activatorDir, "bin/${entry.key}")
starter.parentFile.mkdirs()
starter.withPrintWriter {
it.append '#!/bin/sh\n'
it.append "${entry.value} \$*"
}
}
project.extensions.getByName('ospackage').from(new File(activatorDir, 'bin')) {
into("/opt/activator/${project.name}/bin")
fileMode = 0555
}
activatorExtension.env.each { entry ->
final envFile = new File(activatorDir, "env/${entry.key}")
envFile.parentFile.mkdirs()
envFile.write(entry.value as String)
}
project.extensions.getByName('ospackage').from(new File(activatorDir, 'env')) {
into("/opt/activator/${project.name}/env")
fileMode = 0444
}
}
tasks.getByName('buildDeb').dependsOn(activatorTask)
tasks.getByName('buildRpm').dependsOn(activatorTask)
}
|