forked from eclipse-efx/efxclipse-drift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
385 lines (299 loc) · 10.1 KB
/
build.gradle
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.apache.httpcomponents:httpclient:4.5.9'
classpath 'org.apache.httpcomponents:httpmime:4.5.9'
classpath 'org.standardout:bnd-platform:1.7.0'
classpath 'com.squareup.okhttp3:okhttp:4.8.0'
}
}
plugins {
id 'java'
id 'eclipse'
}
apply plugin: 'org.standardout.bnd-platform'
def revision = System.getProperty("revision")
def getGitHash() {
if (System.getenv("CI")) {
System.getenv("GITHUB_SHA")
} else {
getLocalGitHash()
}
}
def getGitTimestamp() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'log', '-1', '--date=iso-strict', '--format=%cd', 'HEAD'
standardOutput = stdout
}
return java.time.OffsetDateTime.parse(stdout.toString().trim()).toInstant()
}
def getLocalShortGitHash() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
def getLocalGitHash() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
def getReleaseTag() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags'
ignoreExitValue true
standardOutput = stdout
}
def tag = stdout.toString().trim()
if (tag.matches('R[0-9]+\\.[0-9]+\\.[0-9]+')) {
return tag
}
return null
}
def getVersion() {
def tag = getReleaseTag()
if (tag != null) {
return tag.substring(1)
} else {
return '999.0.0'
}
}
def getQualifier() {
"${toTimestamp(getGitTimestamp())}-${getLocalShortGitHash()}"
}
def toTimestamp(instant) {
return java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss").withZone( ZoneId.of("UTC") ).format(instant)
}
task showInfo {
doLast {
println "Release Tag: ${getReleaseTag()}"
println "Version: ${getVersion()}"
println "Qualifier: ${getQualifier()}"
println "last commit: ${getGitTimestamp()}"
println " -> ${toTimestamp(getGitTimestamp())}"
}
}
allprojects {
repositories {
mavenCentral()
}
}
subprojects {
}
def test() {
println "executing test()"
"foo bar"
}
def getJava8() {
"${System.getenv('JAVA_HOME_8')}/bin/javac"
}
def getJava11() {
"${System.getenv('JAVA_HOME_11')}/bin/javac"
}
def version = getVersion()
def qualifier = getQualifier()
def fullVersion = "${version}-${qualifier}"
def bundleVersion = "${version}.${qualifier}"
subprojects.each { subproject -> evaluationDependsOn( subproject.path ) }
task buildMrJar(type: Jar, dependsOn: [
subprojects.tasks['classes'],
showInfo
]) {
archiveBaseName = 'org.eclipse.fx.drift'
from project(':org.eclipse.fx.drift').sourceSets.main.output
from project(':org.eclipse.fx.drift.java8').sourceSets.main.output
into('META-INF/versions/11') {
from project(':org.eclipse.fx.drift.java11').sourceSets.main.output
}
// manual header
manifest {
attributes(
"Manifest-Version": "1.0",
'Bundle-ManifestVersion': '2',
'Bundle-SymbolicName': 'org.eclipse.fx.drift',
'Bundle-Version': "${bundleVersion}",
"Multi-Release": true,
'Export-Package': "org.eclipse.fx.drift;version=\"${version}\",org.eclipse.fx.drift.impl;version=\"${version}\"",
'Private-Package': 'org.eclipse.fx.drift.internal',
'Bundle-Activator': 'org.eclipse.fx.drift.internal.OSGiActivator',
'Bundle-NativeCode': 'native/driftfx.dll;osname=Win32;processor=x86-64,native/driftcpp.dll;osname=Win32;processor=x86-64,native/libdriftfx.so;osname=Linux;processor=x86-64,native/libdriftcpp.so;osname=Linux;processor=x86-64,native/libdriftfx.dylib;osname=MacOSX;processor=x86-64,native/libdriftcpp.dylib;osname=MacOSX;processor=x86-64'
)
}
doLast {
println "${version}"
}
}
// TODO declare a task output=?
task downloadGithubArtifact {
doLast {
def owner = 'BestSolution-at'
def repo = 'efxclipse-drift'
def runId = System.getenv('GITHUB_RUN_ID')
def githubToken = System.getenv('GITHUB_ACCESS_TOKEN')
def result = githubGetArtifacts(owner, repo, runId, githubToken)
def artifactUnsigned = result.artifacts.find { it.name == 'artifact-unsigned' }
def url = artifactUnsigned.archive_download_url
println "Downloading: $url"
githubDownloadArtifact(url, "$buildDir/github-artifacts.zip", githubToken)
}
}
task unzipGithubArtifact(type: Copy) {
dependsOn downloadGithubArtifact
from {
zipTree("$buildDir/github-artifacts.zip")
}
into "$buildDir/unsigned"
}
def signFile(infile, outfile) {
def uri = "http://build.eclipse.org:31338/sign"
def conn = new URL(uri).openConnection()
try {
conn.setRequestMethod("POST")
} finally {
conn.disconnect()
}
}
task signJarFiles() {
dependsOn unzipGithubArtifact
doLast {
def sourceFile = "$buildDir/unsigned/org.eclipse.fx.drift.jar"
def targetFile = "$buildDir/signed/org.eclipse.fx.drift.jar"
mkdir "$buildDir/signed"
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'curl', '-sS', '-o', targetFile, '-F', "file=@$sourceFile", 'http://build.eclipse.org:31338/sign'
standardOutput = stdout
}
println "${new File(targetFile)}"
}
}
import org.apache.http.*
import org.apache.http.client.*
import org.apache.http.client.methods.*
import org.apache.http.impl.client.*
import org.apache.http.entity.mime.*
import org.apache.http.entity.mime.content.*
task signJarFilesFoo() {
dependsOn unzipGithubArtifact
doLast {
def signUri = System.getenv("SIGN_SERVICE")
def inputFile = file("$buildDir/unsigned/org.eclipse.fx.drift.jar")
def outputFile = file("$buildDir/signed/org.eclipse.fx.drift.jar")
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE)
reqEntity.addPart('file', new FileBody(inputFile))
HttpClient client = new DefaultHttpClient()
HttpPost post = new HttpPost("http://build.eclipse.org:31338/sign")
post.setEntity(reqEntity)
HttpResponse response = client.execute(post)
println(response)
new File(outputFile).withOutputStream { outStream ->
HttpEntity resEntity = response.getEntity()
resEntity.getContent.with { inStream ->
outStream << inStream
inStream.close()
}
}
}
}
platform {
featureId = 'org.eclipse.fx.drift.feature'
featureName = 'DriftFX'
featureVersion = "${getVersion()}.${getQualifier()}"
featureProvider = "BestSolution"
categoryId = 'org.eclipse.fx.drift'
categoryName = 'DriftFX'
fetchSources = false
useBndHashQualifiers = false
useFeatureHashQualifiers = false
//generatePlatformFeature = false
bundle file("$buildDir/signed/org.eclipse.fx.drift.jar")
/* bundle file("$buildDir/downloaded/org.eclipse.fx.drift.jar"), {
bnd {
version = '2.5.0'
symbolicName = 'the.super.drift'
}
}*/
/*
feature (id: 'org.eclipse.fx.drift.feature', name: 'DriftFX Runtime', version: '') {
plugin file("$buildDir/downloaded/org.eclipse.fx.drift.jar")
}
*/
}
task ghCreateRelease() {
dependsOn updateSiteZip
doLast {
}
}
import okhttp3.*
ext.client = new OkHttpClient()
def githubGetArtifacts(owner, repo, runId, githubToken) {
def JSON = MediaType.get("application/json; charset=utf-8")
def request = new Request.Builder()
.header("Authorization", "token $githubToken")
.header("Content-Type", "application/json")
.url("https://api.github.com/repos/$owner/$repo/actions/runs/$runId/artifacts")
.build()
def response = client.newCall(request).execute()
assert response.code == 200
new groovy.json.JsonSlurperClassic().parseText(response.body.string())
}
def githubDownloadArtifact(url, filename, githubToken) {
def request = new Request.Builder()
.header("Authorization", "token $githubToken")
.url(url)
.build()
def response = client.newCall(request).execute()
def target = File( filename )
if (target.getParent().exists)
new target.withOutputStream { out ->
response.body.byteStream().with { inStream ->
out << inStream
inStream.close()
}
}
}
task notifyJenkins() {
doLast {
def jenkinsToken = System.getenv("JENKINS_ACCESS_TOKEN")
def runId = System.getenv('GITHUB_RUN_ID')
def githubToken = System.getenv('GITHUB_ACCESS_TOKEN')
def request = new Request.Builder()
.url("https://ci.eclipse.org/efxclipse/job/efxclipse_drift_build/buildWithParameters?token=$jenkinsToken&GITHUB_ACCESS_TOKEN=$githubToken&GITHUB_RUN_ID=$runId&GIT_SHA=${getGitHash()}")
.build()
def response = client.newCall(request).execute()
println "notify jenkins: ${response.code}"
}
}
task testghrel2 {
doLast {
def JSON = MediaType.get("application/json; charset=utf-8")
def msg = """{
"tag_name": "test123",
"target_commitish": "${getGitHash()}",
"name": "foo bar",
"body": "some text",
"draft": true,
"prerelease": true
}"""
def requestBody = RequestBody.create(msg, JSON)
def request = new Request.Builder()
.header("Authorization", "token ${System.getenv('GITHUB_ACCESS_TOKEN')}")
.header("Content-Type", "application/json")
.url("https://api.github.com/repos/bestsolution-at/efxclipse-drift/releases")
.post(requestBody)
.build()
def response = client.newCall(request).execute()
println response
println response.code
println response.body.string()
}
}