-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbuild.gradle
527 lines (438 loc) · 17.2 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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
import de.itemis.mps.gradle.*
import groovy.xml.XmlSlurper
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
//will pull the groovy classes/types from nexus to the classpath
buildscript {
repositories {
maven { url 'https://artifacts.itemis.cloud/repository/maven-mps/' }
}
dependencies {
classpath 'de.itemis.mps:mps-gradle-plugin:1.23.1.412.a54f29f'
}
}
plugins {
id 'base'
id 'maven-publish'
id "com.github.breadmoirai.github-release" version "2.4.1"
id "org.cyclonedx.bom" version "1.8.2"
}
ext.dependencyRepositories = [
'https://artifacts.itemis.cloud/repository/maven-mps/'
]
repositories {
// we don't use mavenLocal() repo, since it can cause various issues with resolving dependencies,
// see https://docs.gradle.org/current/userguide/declaring_repositories.html#sec:case-for-maven-local
for (repoUrl in project.dependencyRepositories) {
maven {
url repoUrl
}
}
mavenCentral()
}
apply plugin: 'download-jbr'
// configure jbr download
downloadJbr {
jbrVersion = '17.0.11-b1207.30'
}
// detect if we are in a CI build
if (project.hasProperty("forceCI")) {
ext.ciBuild = true
} else {
//on teamcity we are in a CI build
ext.ciBuild = project.hasProperty("teamcity")
}
def forceLocal = project.hasProperty("forceLocalDependencies")
def major = "2024"
def minor = "1"
// Dependency versions
ext.mpsVersion = '2024.1.1'
def mbeddrVersion = "2024.1+"
def mpsQAVersion = "$major.$minor+"
// if building a against a special branch from mbeddr is required add the name here
// the name is enough no trailing "." is required, also the plain name from git can
// be used here. No need to convert "/" the script will take care of that.
def mbeddrBranch = ""
def currentBranch = ""
if (mbeddrBranch != null && !mbeddrBranch.trim().isEmpty()) {
ext.mbeddrVersionSelector = "${mbeddrBranch.replace("/", "-")}.${mbeddrVersion}"
} else {
ext.mbeddrVersionSelector = mbeddrVersion
}
// Project group
group = 'org.iets3'
// Project name cannot be defined here, see settings.gradle#rootProject.name instead
// name = 'opensource'
// Project version
if (project.hasProperty('iets3OpenSourceVersion')) {
version = project.iets3OpenSourceVersion
} else {
if (ciBuild) {
currentBranch = GitBasedVersioning.gitBranch
def buildNumber = System.env.BUILD_COUNTER.toInteger()
if (currentBranch.startsWith("maintenance-")) {
version = "$major.$minor.$buildNumber.${GitBasedVersioning.gitShortCommitHash}"
} else {
def isSnapshot = !(currentBranch.equals("master") || currentBranch.startsWith("datev-loon-staging-") || currentBranch.startsWith("datev-steuer-staging-"))
version = GitBasedVersioning.getVersionWithCount(major, minor, buildNumber) + (isSnapshot ? "-SNAPSHOT" : "")
}
println "##teamcity[buildNumber '${version}']"
} else {
version = "$major.$minor-SNAPSHOT"
println "Local build detected, version will be $version"
}
}
if (project.hasProperty("mbeddrVersion")) {
logger.log(LogLevel.WARN, "mbeddr version externally overwritten to $ext.mbeddrVersion")
ext.mbeddrVersionSelector = ext.mbeddrVersion
}
ext.releaseRepository = 'https://artifacts.itemis.cloud/repository/maven-mps-releases/'
ext.snapshotRepository = 'https://artifacts.itemis.cloud/repository/maven-mps-snapshots'
ext.publishingRepository = version.toString().endsWith("-SNAPSHOT") ? snapshotRepository : releaseRepository
// 'artifacts' is used in the generated ant scripts as build output directory
ext.artifactsDir = new File(buildDir, 'artifacts')
wrapper {
gradleVersion '8.0.2'
distributionType Wrapper.DistributionType.ALL
}
configurations {
mps
languageLibs
junitAnt
pcollections // Synced to org.iets3.core.expr.base.collections.stubs/lib
bigMath // Synced to org.iets3.core.expr.math.interpreter/lib
}
dependencies {
mps "com.jetbrains:mps:$mpsVersion"
languageLibs "org.mpsqa:all-in-one:$mpsQAVersion"
languageLibs "com.mbeddr:platform:$mbeddrVersionSelector"
junitAnt 'org.apache.ant:ant-junit:1.10.6'
pcollections 'org.pcollections:pcollections:4.0.1'
bigMath 'ch.obermuhlner:big-math:2.3.2'
}
task resolveMps(type: Sync) {
dependsOn configurations.mps
from {
configurations.mps.resolve().collect { zipTree(it) }
}
into "$buildDir/mps"
}
task resolveLanguageLibs(type: Sync) {
from {
configurations.languageLibs.resolve().collect { zipTree(it) }
}
into "$buildDir/dependencies"
}
task resolvePcollections(type: Sync) {
from configurations.pcollections
into file('code/languages/org.iets3.opensource/solutions/org.iets3.core.expr.base.collections.stubs/lib')
// Strip version numbers from file names
rename { filename ->
def ra = configurations.pcollections.resolvedConfiguration.resolvedArtifacts.find { ResolvedArtifact ra -> ra.file.name == filename }
String finalName
if (ra.classifier != null) {
finalName = "${ra.name}-${ra.classifier}.${ra.extension}"
} else {
finalName = "${ra.name}.${ra.extension}"
}
return finalName
}
}
task resolveBigMath(type: Sync) {
from configurations.bigMath
into file('code/languages/org.iets3.opensource/solutions/org.iets3.core.expr.math.interpreter/lib')
// Strip version numbers from file names
rename { filename ->
def ra = configurations.bigMath.resolvedConfiguration.resolvedArtifacts.find { ResolvedArtifact ra -> ra.file.name == filename }
String finalName
if (ra.classifier != null) {
finalName = "${ra.name}-${ra.classifier}.${ra.extension}"
} else {
finalName = "${ra.name}.${ra.extension}"
}
return finalName
}
}
task resolveDependencies(dependsOn: ['downloadJbr', resolveMps, resolveLanguageLibs, resolvePcollections, resolveBigMath])
// Default arguments for ant scripts
def defaultScriptArgs = [
'mps.home' : resolveMps.destinationDir,
'iets3.github.opensource.home' : rootDir,
'mps.test.project.path' : "${rootDir}/code/languages/org.iets3.opensource",
'build.jna.library.path' : new File(resolveMps.destinationDir, "lib/jna/${System.getProperty('os.arch')}"),
'build.dir' : buildDir,
'version' : version
]
if (gradle.startParameter.logLevel.toString() != "LIFECYCLE") {
defaultScriptArgs.put('mps.ant.log', gradle.startParameter.logLevel.toString().toLowerCase())
}
// enables https://github.com/mbeddr/mps-gradle-plugin#providing-global-defaults
ext["itemis.mps.gradle.ant.defaultScriptArgs"] = defaultScriptArgs.collect { "-D$it.key=$it.value".toString() }
ext["itemis.mps.gradle.ant.defaultScriptClasspath"] = project.configurations.junitAnt.fileCollection { true }
afterEvaluate {
project.ext["itemis.mps.gradle.ant.defaultJavaExecutable"] = tasks.getByName('downloadJbr').javaExecutable
}
task buildAllScripts(type: BuildLanguages, dependsOn: resolveDependencies) {
script "$buildDir/scripts/build-allScripts.xml"
}
task prebuild(type: BuildLanguages, dependsOn: buildAllScripts) {
script "$buildDir/scripts/prebuild.xml"
targets "clean", "generate"
}
task buildLanguages(type: BuildLanguages, dependsOn: prebuild) {
script "$buildDir/scripts/build-languages.xml"
}
task buildAndRunTests(type: TestLanguages, dependsOn: buildLanguages) {
script "$buildDir/scripts/build-tests.xml"
doLast {
ant.taskdef(name: 'junitreport',
classname: 'org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator',
classpath: configurations.junitAnt.asPath)
ant.junitreport {
fileset(dir: "$buildDir", includes: '**/TEST*.xml', excludes: 'tmp/**')
report(format: 'frames', todir: "$buildDir/junitreport")
}
ant.echo("JUnit report placed into $buildDir/junitreport/index.html")
}
}
task failOnTestError() {
description 'evaluate junit result and fail on error'
doLast {
def juniXml = file('TESTS-TestSuites.xml')
if(juniXml.exists()){
def junitResult = new XmlSlurper().parse(juniXml)
def failures = junitResult.'**'.findAll { it.name() == 'failure' }
def errors = junitResult.'**'.findAll { it.name() == 'error' }
if (failures || errors) {
def amount = failures.size() + errors.size()
throw new GradleException(amount + " JUnit tests failed. Check the test report for details.")
}
}
}
}
buildAndRunTests.configure { finalizedBy failOnTestError }
check.dependsOn buildAndRunTests
apply plugin: 'modelcheck'
File modelcheckresult = new File("$buildDir/TEST-checkProject.xml")
def pluginsList = []
modelcheck {
projectLocation = new File("$projectDir/code")
mpsLocation = new File("$buildDir/mps")
plugins = pluginsList
mpsConfig = configurations.mps
macros = [new Macro("iets3.github.opensource.home", "$projectDir")]
junitFile = modelcheckresult
junitFormat = "message"
errorNoFail = true
debug = false
maxHeap = "4G"
}
afterEvaluate { project ->
/*
check.configure {
dependsOn tasks.named('checkmodels')
}
*/
}
checkmodels {
dependsOn(resolveMps)
}
task packageLanguages(type: Zip, dependsOn: buildLanguages) {
archiveBaseName = 'org.iets3.opensource'
from artifactsDir
include 'org.iets3.opensource/**'
}
task packageTests(type: Zip, dependsOn: buildAndRunTests) {
archiveBaseName = 'org.iets3.opensource.tests'
from artifactsDir
include 'org.iets3.opensource.tests/**'
}
task buildDistroWithDependencies(type: RunAntScript, dependsOn: buildLanguages) {
script "$buildDir/scripts/build-distro.xml"
targets 'clean', 'assemble'
}
task packageDistroWithDependencies(type: Zip, dependsOn: buildDistroWithDependencies) {
archiveBaseName = 'org.iets3.opensource-with-dependencies'
from artifactsDir
include 'org.iets3.opensource.distro/**'
}
assemble.dependsOn packageLanguages, packageTests
static def addDependency(Object pom, Object groupId, Object artifactId, Object version, Object type = null) {
pom.withXml { XmlProvider prov ->
Node root = prov.asNode()
Node deps = root.dependencies[0] ?: root.appendNode("dependencies")
def dep = deps.appendNode("dependency")
dep.appendNode("groupId", groupId)
dep.appendNode("artifactId", artifactId)
dep.appendNode("version", version)
if (type != null) {
dep.appendNode("type", type)
}
}
}
static def addDependency(Object pom, Configuration config) {
config.resolvedConfiguration.firstLevelModuleDependencies.each {
addDependency(pom, it.moduleGroup, it.moduleName, it.moduleVersion, it.moduleArtifacts[0].type)
}
}
ext.additionalPomInfo = {
licenses {
// official SPDX identifier
// see https://spdx.org/licenses/ for list
license {
name = "Apache-2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0"
comments = "Apache License Version 2.0"
distribution = "repo"
}
}
organization {
name = "itemis AG"
url = "https://www.itemis.com"
}
scm {
tag = GitBasedVersioning.getGitCommitHash()
url = "https://github.com/IETS3/iets3.opensource"
}
}
publishing {
repositories {
maven {
url = project.publishingRepository
if (project.hasProperty("artifacts.itemis.cloud.user") && project.hasProperty("artifacts.itemis.cloud.pw")) {
credentials {
username = project.findProperty("artifacts.itemis.cloud.user")
password = project.findProperty("artifacts.itemis.cloud.pw")
}
}
}
if (currentBranch == "master" || currentBranch.startsWith("maintenance") ) {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/IETS3/iets3.opensource")
if (project.hasProperty("gpr.token")) {
credentials {
username = project.findProperty("gpr.user")
password = project.findProperty("gpr.token")
}
}
}
}
}
publications {
opensource(MavenPublication) {
groupId group
artifactId name
artifact packageLanguages
addDependency(pom, configurations.languageLibs)
pom additionalPomInfo
}
tests(MavenPublication) {
groupId 'org.iets3.opensource'
artifactId 'tests'
artifact packageTests
addDependency(pom, 'org.iets3', 'opensource', project.version, 'zip')
pom additionalPomInfo
}
def runtimesDir = new File(artifactsDir, 'org.iets3.opensource/org.iets3.core.os/languages/iets3.core.os')
'org.iets3.core.expr.base.shared.runtime'(MavenPublication) {
groupId 'org.iets3.core.expr.base.shared'
artifactId 'shared-runtime'
artifact(new File(runtimesDir, 'org.iets3.core.expr.base.shared.runtime.jar')) {
builtBy buildLanguages
}
artifact(new File(runtimesDir, 'org.iets3.core.expr.base.shared.runtime-src.jar')) {
builtBy buildLanguages
classifier 'sources'
}
pom additionalPomInfo
}
'org.iets3.core.expr.simpleTypes.runtime'(MavenPublication) {
// GitHub Packages refuse uppercase artifactId (not sure about groupId) so use lower case here
groupId 'org.iets3.core.expr.simpletypes'
artifactId 'simpletypes-runtime'
artifact(new File(runtimesDir, 'org.iets3.core.expr.simpleTypes.runtime.jar')) {
builtBy buildLanguages
}
artifact(new File(runtimesDir, 'org.iets3.core.expr.simpleTypes.runtime-src.jar')) {
builtBy buildLanguages
classifier 'sources'
}
addDependency(pom, 'org.iets3.core.expr.base.shared', 'shared-runtime', project.version)
pom additionalPomInfo
}
'org.iets3.core.expr.datetime.runtime'(MavenPublication) {
groupId 'org.iets3.core.expr.datetime'
artifactId 'datetime-runtime'
artifact(new File(runtimesDir, 'org.iets3.core.expr.datetime.runtime.jar')) {
builtBy buildLanguages
}
artifact(new File(runtimesDir, 'org.iets3.core.expr.datetime.runtime-src.jar')) {
builtBy buildLanguages
classifier 'sources'
}
addDependency(pom, 'org.iets3.core.expr.base.shared', 'shared-runtime', project.version)
pom additionalPomInfo
}
'org.iets3.core.expr.temporal.runtime'(MavenPublication) {
groupId 'org.iets3.core.expr.temporal'
artifactId 'temporal-runtime'
artifact(new File(runtimesDir, 'org.iets3.core.expr.temporal.runtime.jar')) {
builtBy buildLanguages
}
artifact(new File(runtimesDir, 'org.iets3.core.expr.temporal.runtime-src.jar')) {
builtBy buildLanguages
classifier 'sources'
}
addDependency(pom, 'org.iets3.core.expr.datetime', 'datetime-runtime', project.version)
pom additionalPomInfo
}
}
}
defaultTasks 'buildLanguages'
def listMergedPRs = {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'sh', './listMergedPRs.sh'
standardOutput = stdout
}
stdout.toString()
}
def currentDate = LocalDate.now().format(DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL))
def prCommitsList = "${-> listMergedPRs().readLines().collect { line -> "- $line"}.join("\n")}"
def langLibDeps = project.configurations.languageLibs.resolvedConfiguration.lenientConfiguration.allModuleDependencies
def depsList = langLibDeps.collect {"- `${it.moduleGroup}:${it.moduleName}` : `${it.moduleVersion}`"}.join("\n")
def releaseNotes = """Automated Nighly build from ${currentDate}.
Included pull requests since last Nightly build:
${prCommitsList}
Includes dependencies:
${depsList}
"""
githubRelease {
owner = 'IETS3'
repo = 'iets3.opensource'
token = rootProject.findProperty('github.token') ?: 'empty'
tagName = 'nightly-' + version
targetCommitish = GitBasedVersioning.getGitCommitHash()
body = releaseNotes
prerelease = true
releaseAssets = packageDistroWithDependencies.outputs.files.collect {it.path}
dryRun = false
}
tasks.named('githubRelease').configure {
dependsOn packageDistroWithDependencies
}
cyclonedxBom {
// SBOM destination directory
destination = file("build/reports")
// The file name for the generated SBOMs (before the file format suffix)
outputName = "sbom"
// The file format generated, can be xml, json or all for generating both
outputFormat = "json"
// Don't include license texts in generated SBOMs
includeLicenseText = false
}
assemble {
dependsOn('cyclonedxBom')
}