-
Notifications
You must be signed in to change notification settings - Fork 51
/
build.gradle
565 lines (475 loc) · 18.9 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
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
plugins {
id 'de.itemis.mps.gradle.common' version '1.28.0.+'
id "com.github.breadmoirai.github-release" version "2.5.2"
id 'maven-publish'
id 'base'
id 'de.itemis.mps.gradle.launcher' version '2.5.2.+'
}
import de.itemis.mps.gradle.*
import de.itemis.mps.gradle.tasks.MpsMigrate
import de.itemis.mps.gradle.tasks.Remigrate
import de.itemis.mps.gradle.downloadJBR.DownloadJbrForPlatform
import groovy.xml.XmlSlurper
import java.time.LocalDateTime
apply plugin: 'download-jbr'
downloadJbr {
jbrVersion = '17.0.8.1-b1000.32'
}
// detect if we are in a CI build
if (project.hasProperty("forceCI")) {
ext.ciBuild = true
} else {
//on teamcity we are in a CI build
if (project.hasProperty("teamcity") && !project.hasProperty('mpsHomeDir')) {
ext.ciBuild = true
} else {
ext.ciBuild = false
}
}
// Default repository credentials
if (!project.hasProperty('nexusUsername')) {
ext.nexusUsername = ''
ext.nexusPassword = ''
}
logger.info 'Repository username: {}', project.nexusUsername
// Dependency versions
// major version, e.g. '2021.1', '2021.2'
ext.mpsMajor = '9999.9'
// optional minor/bugfix number (not added to the final build version)
ext.mpsMinor = ''
// e.g. Beta, EAP, RC
ext.mpsReleaseType = ''
def appendOpt = { str,pre -> !str.isEmpty() ? "${pre}${str}" : "" }
ext.mpsVersion = "$mpsMajor" + appendOpt(mpsMinor, '.') + appendOpt(mpsReleaseType, '-')
if (ciBuild) {
String branch = GitBasedVersioning.gitBranch
def buildMajor = mpsMajor.split("\\.").first()
def buildMinor = mpsMajor.split("\\.").last()
def buildNumber = System.env.BUILD_NUMBER.toInteger()
if (branch.matches(/(maintenance|mps)[\/-](mps)?\d+(\.\d+)*/)) {
version = "$buildMajor.$buildMinor.$buildNumber.${GitBasedVersioning.gitShortCommitHash}"
} else {
version = GitBasedVersioning.getVersionWithCount(buildMajor, buildMinor, buildNumber) + "-SNAPSHOT"
}
println "##teamcity[buildNumber '${version}']"
} else {
version = ext.mpsMajor + appendOpt(ext.mpsMinor , '.') + "-SNAPSHOT"
println "Local build detected, version will be $version"
}
def userHome = System.properties['user.home']
def mpsPluginsDirPattern
if (System.properties['os.name'].toLowerCase().contains('mac')) {
mpsPluginsDirPattern = "$userHome/Library/Application Support/%s"
} else {
mpsPluginsDirPattern = "$userHome/.%s/config/plugins"
}
if (project.hasProperty("MPS_PATHS_SELECTOR")) {
ext.mpsPluginsDir = sprintf(mpsPluginsDirPattern, project.getProperty("MPS_PATHS_SELECTOR"))
} else {
ext.mpsPluginsDir = sprintf(mpsPluginsDirPattern, "MPS$mpsMajor")
}
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
configurations {
mps
}
dependencies {
// For published releases adjust ext.mpsMajor and ext.mpsMinor above and use this dependency:
// mps "com.jetbrains:mps:$mpsVersion"
mps "com.jetbrains.mps:mps-prerelease:241.19072.10583"
}
repositories {
maven { url 'https://artifacts.itemis.cloud/repository/maven-mps/' }
}
ext.skipResolveMps = project.hasProperty('mpsHomeDir')
ext.mpsHomeDir = rootProject.file(project.findProperty('mpsHomeDir') ?: "$buildDir/mps")
if (project.skipResolveMps) {
task resolveMps {
doLast {
logger.info "MPS resolution skipped"
logger.info "MPS home: " + mpsHomeDir.getAbsolutePath()
}
}
} else {
task resolveMps(type: Copy) {
dependsOn configurations.mps
from {
configurations.mps.resolve().collect { zipTree(it) }
}
into mpsHomeDir
}
}
// -------- Model API ----------------------
configurations {
modelApi
}
dependencies {
def modelixCoreVersion = "2.1.9"
modelApi("org.modelix:model-api:$modelixCoreVersion")
}
task copyModelApi() {
dependsOn configurations.modelApi
doLast {
// copy transitive dependencies without version in the file name
// otherwise each new version would require a change of the MPS solution
def libFolder = file("$projectDir/code/model-api/org.modelix.model.api/lib")
libFolder.deleteDir()
libFolder.mkdir()
def versionsFile = file("$libFolder/versions.txt")
for (final def artifact in configurations.modelApi.resolvedConfiguration.resolvedArtifacts) {
// these libs are part of MPS
if (
artifact.moduleVersion.id.name.startsWith("log4j")
|| artifact.moduleVersion.id.name.startsWith("annotations")
|| artifact.moduleVersion.id.name.startsWith("slf4j-api")
) {
versionsFile.append("already part of mps: " + artifact.file.name + "\n")
continue
}
def sourceFile = java.nio.file.Path.of(artifact.file.absolutePath)
def targetFile = java.nio.file.Path.of(libFolder.absolutePath).resolve(artifact.moduleVersion.id.name + "." + artifact.extension)
java.nio.file.Files.copy(sourceFile, targetFile)
versionsFile.append(artifact.file.name + "\n")
}
}
}
// -----------------------------------------
configurations {
ant_lib
diagram_lib {
exclude(group: 'com.google.guava')
attributes.attribute(Attribute.of('org.gradle.jvm.environment', String), 'standard-jvm')
}
batik {
exclude(group: 'xml-apis')
exclude(group: 'commons-io')
exclude(group: 'commons-logging')
}
}
dependencies {
ant_lib "org.apache.ant:ant-junit:1.10.15"
def elkVersion = "0.9.1"
diagram_lib ("org.eclipse.elk:org.eclipse.elk.alg.common:$elkVersion")
diagram_lib ("org.eclipse.elk:org.eclipse.elk.alg.layered:$elkVersion")
diagram_lib ("org.eclipse.elk:org.eclipse.elk.alg.mrtree:$elkVersion")
diagram_lib ("org.eclipse.elk:org.eclipse.elk.alg.radial:$elkVersion")
diagram_lib ("org.eclipse.elk:org.eclipse.elk.alg.force:$elkVersion")
diagram_lib ("org.eclipse.elk:org.eclipse.elk.alg.disco:$elkVersion")
diagram_lib ("org.eclipse.elk:org.eclipse.elk.alg.rectpacking:$elkVersion")
diagram_lib ("org.eclipse.elk:org.eclipse.elk.alg.spore:$elkVersion")
diagram_lib ("org.eclipse.elk:org.eclipse.elk.alg.topdownpacking:$elkVersion")
diagram_lib ("org.eclipse.elk:org.eclipse.elk.core:$elkVersion")
diagram_lib ("org.eclipse.elk:org.eclipse.elk.graph:$elkVersion")
diagram_lib ("org.eclipse.emf:org.eclipse.emf.common:2.31.0")
diagram_lib ("org.eclipse.emf:org.eclipse.emf.ecore:2.37.0")
diagram_lib ("org.eclipse.emf:org.eclipse.emf.ecore.xmi:2.38.0")
batik ("org.apache.xmlgraphics:batik-svggen:1.18")
batik ("org.apache.xmlgraphics:batik-dom:1.18")
}
ext.buildScriptClasspath = project.configurations.ant_lib.fileCollection({
true
})
def artifactsDir = new File(rootDir, 'artifacts')
ext.mps_home = '-Dmps.home=' + mpsHomeDir.getAbsolutePath()
ext.build_dir = '-Dbuild.dir=' + file(rootProject.projectDir.absolutePath).getAbsolutePath()
ext.artifacts_dir = '-Dartifacts.root=' + artifactsDir
ext.pluginVersion = "-DversionNumber=" + version
ext.buildDate = "-DbuildDate=" + new Date().toString()
ext.extensions_home = '-Dextensions.home=' + rootDir
// ___________________ utilities ___________________
File scriptFile(String relativePath) {
new File("$rootDir/build/generated/$relativePath")
}
def defaultScriptArgs = [mps_home, build_dir, artifacts_dir, ext.buildDate, ext.pluginVersion,
'-Dbuild.jna.library.path=' + new File(mpsHomeDir, 'lib/jna/' + System.getProperty('os.arch'))]
afterEvaluate {
project.ext["itemis.mps.gradle.ant.defaultJavaExecutable"] = tasks.getByName('downloadJbr').javaExecutable
def jdk_home = null
if (ext.has('java17_home')) {
jdk_home = ext.get('java17_home')
} else if (System.getenv('JB_JAVA17_HOME') != null) {
jdk_home = System.getenv('JB_JAVA17_HOME')
}
if(jdk_home != null) {
if (!new File(jdk_home, "lib").exists()) {
throw new GradleException("Unable to locate JDK home folder. Detected folder is: $jdk_home")
} else {
ext["itemis.mps.gradle.ant.defaultJavaExecutable"] = new File(jdk_home, 'bin/java')
}
}
}
// enables https://github.com/mbeddr/mps-gradle-plugin#providing-global-defaults
ext["itemis.mps.gradle.ant.defaultScriptArgs"] = defaultScriptArgs
ext["itemis.mps.gradle.ant.defaultScriptClasspath"] = buildScriptClasspath
task resolved_diagram_dependencies(type: Copy) {
from configurations.diagram_lib
into file('code/diagram/solutions/de.itemis.mps.editor.diagram.runtime/lib')
// Strip version numbers from file names
rename { filename ->
def ra = configurations.diagram_lib.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 resolved_batik_dependencies(type: Sync) {
from configurations.batik
into file('code/batik/solutions/lib')
// Strip version numbers from file names
rename { filename ->
def ra = configurations.batik.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
}
}
tasks.register('build_allScripts', BuildLanguages) {
dependsOn 'downloadJbr', resolveMps, copyModelApi, resolved_diagram_dependencies, resolved_batik_dependencies
script "$rootDir/scripts/build.xml"
}
task copyChangelog(type: Copy) {
from "$rootDir/code/solutions/de.itemis.mps.extensions.changelog/source_gen/de/itemis/mps/extensions/changelog"
into "$rootDir"
include "*.md"
}
task build_languages(type: BuildLanguages, dependsOn: [build_allScripts]) {
script scriptFile('languages/build.xml')
}
task build_tests(type: BuildLanguages, dependsOn: build_languages) {
description "Will execute all tests from command line"
script scriptFile('tests/build.xml')
}
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.")
}
}
}
}
task run_tests(type: TestLanguages, dependsOn: build_tests) {
description "Will execute all tests from command line"
script scriptFile('tests/build.xml')
targets 'check'
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')
report(format: 'frames', todir: "$buildDir/junitreport")
}
ant.echo("JUnit report placed into $buildDir/junitreport/index.html")
}
}
run_tests.configure { finalizedBy failOnTestError }
task install_nativelibs(type: Copy, dependsOn: build_languages) {
from "$rootDir/artifacts/de.itemis.mps.extensions/"
include "de.itemis.mps.nativelibs.loader/"
into "$mpsPluginsDir"
}
task install(dependsOn: install_nativelibs) {
description "Install the required plugins into the MPS plugin repository"
group "Build Setup"
doFirst {
// check parent gradle file for definition of the variables
println "Installing required mbeddr plugins to '$mpsPluginsDir'"
if (!project.hasProperty("MPS_PATHS_SELECTOR")) {
println "To change 'MPS<>' part, pass MPS_PATHS_SELECTOR property to gradle with -PMPS_PATHS_SELECTOR=<custom path selector>"
println "The path selector only contains the the actual selector for instance \"MPS2017.3\" not the full qualifies path to the user plugin directory."
}
}
}
//
// Ant <junit> task support
repositories {
mavenCentral()
}
configurations {
junitAnt
}
dependencies {
junitAnt 'junit:junit:4.13.2'
junitAnt('org.apache.ant:ant-junit:1.10.15') {
transitive = false
}
junitAnt('org.apache.ant:ant-junit4:1.10.15') {
transitive = false
}
}
task packageAllScripts(type: Zip, dependsOn: run_tests) {
archiveBaseName = 'de.itemis.mps.extensions.allScripts'
from artifactsDir
include 'de.itemis.mps.extensions.allScripts/**'
}
task packageExtensions(type: Zip, dependsOn: run_tests) {
archiveBaseName = 'de.itemis.mps.extensions'
from artifactsDir
include 'de.itemis.mps.extensions/**'
//remove workaround which is required for mbeddr.platform build
exclude 'de.itemis.mps.extensions/MPS.ThirdParty.jar'
}
task cleanMps(type: Delete) {
delete fileTree(dir: projectDir, include: ["**/classes_gen/**", "**/source_gen/**", "**/source_gen.caches/**", "tmp/**", "artifacts/**"])
}
clean.dependsOn cleanMps
assemble.dependsOn packageExtensions
allprojects {
apply plugin: 'maven-publish'
publishing {
repositories {
if (rootProject.hasProperty("artifacts.itemis.cloud.user") && rootProject.hasProperty("artifacts.itemis.cloud.pw")) {
maven {
name = "itemisCloud"
url = project.publishingRepository
credentials {
username = rootProject.findProperty("artifacts.itemis.cloud.user")
password = rootProject.findProperty("artifacts.itemis.cloud.pw")
}
}
}
if (rootProject.hasProperty("gpr.token")) {
maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/JetBrains/MPS-extensions"
credentials {
username = rootProject.findProperty("gpr.user")
password = rootProject.findProperty("gpr.token")
}
}
}
}
}
}
def additionalPomInfo = {
licenses {
// official SPDX identifier
// see https://spdx.org/licenses/ for list
license {
name = "Apache-2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
comments = "A business-friendly OSS license"
distribution = "repo"
}
}
organization {
name = "JetBrains s.r.o"
url = "https://www.jetbrains.com"
}
}
publishing {
publications {
extensions(MavenPublication) {
groupId 'de.itemis.mps'
artifactId 'extensions'
artifact packageExtensions
//Pom.withProvidedDep pom, configurations.mps
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.mps.resolvedConfiguration.firstLevelModuleDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.moduleGroup)
dependencyNode.appendNode('artifactId', it.moduleName)
dependencyNode.appendNode('version', it.moduleVersion)
dependencyNode.appendNode('type', it.moduleArtifacts[0].type)
dependencyNode.appendNode('scope', 'provided')
}
}
pom additionalPomInfo
}
}
}
task pipInstall(type: Exec) {
inputs.file("requirements.txt")
commandLine "python3", "-m", "pip", "install", "-r", "requirements.txt"
}
task previewDocs(type: Exec, dependsOn: pipInstall) {
commandLine "mkdocs", "serve"
}
task deployDocs(type: Exec, dependsOn: pipInstall) {
commandLine "mkdocs", "gh-deploy", "--clean", "-r", "gh-pages", "--force"
}
defaultTasks 'build_languages'
task test(dependsOn: run_tests)
build_languages.mustRunAfter clean
task rebuild(dependsOn:[clean, build_languages])
def releaseNotes
def releaseName
def releaseTagName
if (rootProject.hasProperty("nightly_build")) {
releaseName = 'Nightly Build ' + version
releaseTagName = 'nightly-' + version
releaseNotes = """Automated Nightly build from ${LocalDateTime.now() as String}."""
} else {
releaseNotes = rootProject.findProperty("releaseNotes")
releaseTagName = 'release-' + version
releaseName = version
}
githubRelease {
owner = 'jetbrains'
repo = 'MPS-extensions'
token = rootProject.findProperty("github.token") ?: "empty"
tagName = releaseTagName
targetCommitish = GitBasedVersioning.getGitCommitHash()
body = releaseNotes
prerelease = rootProject.hasProperty("nightly_build")
releaseAssets = packageExtensions.outputs.files.files.collect {it.path}
dryRun = false
}
tasks.named('githubRelease').configure {
dependsOn packageExtensions
}
configurations {
rerunMigrationsBackend
}
dependencies {
rerunMigrationsBackend("de.itemis.mps.build-backends:rerun-migrations:0.0.3.+")
}
def usedPluginRoots = [
new File(mpsHomeDir, 'plugins/mps-build'),
new File(mpsHomeDir, 'plugins/mps-console'),
new File(mpsHomeDir, 'plugins/mps-tooltips'),
new File(mpsHomeDir, 'plugins/mps-vcs'),
new File(mpsHomeDir, 'plugins/mps-git4idea'),
new File(mpsHomeDir, 'plugins/mps-httpsupport'),
new File(mpsHomeDir, 'plugins/mps-testing'),
new File(mpsHomeDir, 'plugins/mps-spellcheck')
]
tasks.register('migrate', MpsMigrate) {
dependsOn(resolveMps, 'downloadJbr', 'build_languages', 'build_tests')
javaLauncher = tasks.named('downloadJbr', DownloadJbrForPlatform).flatMap { it.javaLauncher }
haltOnPrecheckFailure = true
haltOnDependencyError = true
mpsHome = mpsHomeDir
projectDirectories.from('code')
pluginRoots.from(usedPluginRoots)
maxHeapSize = '4G'
}
tasks.register('remigrate', Remigrate) {
mustRunAfter('migrate')
mustRunAfter('build_languages', 'build_tests')
dependsOn(resolveMps, 'downloadJbr')
javaLauncher = tasks.named('downloadJbr', DownloadJbrForPlatform).flatMap { it.javaLauncher }
mpsHome = mpsHomeDir
projectDirectories.from('code')
pluginRoots.from(usedPluginRoots)
maxHeapSize = '4G'
// diagram migration from version 0 is currently not rerunnable, although it claims to be
excludeModuleMigration("de.itemis.mps.editor.diagram", 0)
}