-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.gradle.kts
470 lines (396 loc) · 15.3 KB
/
build.gradle.kts
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
import com.adarshr.gradle.testlogger.theme.ThemeType
import de.undercouch.gradle.tasks.download.Download
import groovy.json.JsonSlurper
import org.commonmark.parser.Parser
import org.commonmark.renderer.html.HtmlRenderer
import org.gradle.api.JavaVersion.VERSION_17
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.tasks.InstrumentCodeTask
import org.jetbrains.intellij.platform.gradle.tasks.PrepareSandboxTask
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask.FailureLevel
buildscript {
dependencies {
classpath("org.commonmark:commonmark:0.22.0")
}
repositories {
mavenCentral()
}
}
plugins {
idea
id("org.jetbrains.kotlin.jvm") version "1.9.24"
id("org.jetbrains.intellij.platform") version "2.1.0"
id("org.jetbrains.changelog") version "1.3.1"
id("com.adarshr.test-logger") version "3.2.0"
id("de.undercouch.download") version "5.6.0"
kotlin("plugin.lombok") version "1.9.24"
}
val pluginVersionString = prop("pluginVersion")
val lombokVersion = prop("lombokVersion")
val ideVersion = prop("ideVersion")
group = "appland.appmap"
version = pluginVersionString
val platformVersion = when {
// e.g. '2024.1'
ideVersion.length == 6 -> ideVersion.replace(".", "").substring(2).toInt()
// e.g. '243.16718.32'
else -> ideVersion.substringBefore(".").toInt()
}
val isCI = System.getenv("CI") == "true"
val agentOutputPath = rootProject.layout.buildDirectory.asFile.get()
.resolve("appmap-java-agent")
.resolve("appmap-agent.jar")
val githubToken = System.getenv("GITHUB_TOKEN").takeUnless(String::isNullOrEmpty)
allprojects {
apply {
plugin("org.jetbrains.kotlin.jvm")
plugin("org.jetbrains.kotlin.plugin.lombok")
plugin("idea")
plugin("com.adarshr.test-logger")
plugin("org.jetbrains.intellij.platform.module")
}
repositories {
mavenCentral()
intellijPlatform {
defaultRepositories()
}
}
val testOutput = configurations.create("testOutput")
dependencies {
intellijPlatform {
intellijIdeaCommunity(ideVersion)
// using "Bundled" to gain access to the Java plugin's test classes
testFramework(TestFrameworkType.Bundled)
// org.jetbrains.intellij.platform requires to bundledModules for 2024.2+
if (platformVersion >= 242) {
bundledModule("intellij.platform.collaborationTools")
bundledModule("intellij.platform.vcs.impl")
}
// 2024.3 extracted JSON support into a plugin
if (platformVersion >= 243) {
bundledPlugin("com.intellij.modules.json")
}
}
// added because org.jetbrains.intellij.platform resolves to an older version bundled with the SDK
compileOnly("org.jetbrains:annotations:24.1.0")
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
// Jackson JSON is missing from 2023.1+
implementation("com.fasterxml.jackson.core:jackson-core:2.14.2")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.2")
implementation("org.yaml:snakeyaml:1.33")
// https://mvnrepository.com/artifact/junit/junit
testImplementation("junit:junit:4.13.2")
// http://wiremock.org, Apache 2 license
testImplementation("org.wiremock:wiremock:3.5.4")
// Project Lombok, only for compilation
compileOnly("org.projectlombok:lombok:$lombokVersion")
annotationProcessor("org.projectlombok:lombok:$lombokVersion")
// share test classes of plugin-core with other Gradle modules
testOutput(sourceSets.getByName("test").output)
if (project.name != "plugin-core") {
testImplementation(project(":plugin-core", "testOutput"))
}
// workaround for https://github.com/JetBrains/intellij-platform-gradle-plugin/issues/1663
testImplementation("org.opentest4j:opentest4j:1.3.0")
// Subproject test-integration must not get our additional test dependencies
// because mockserver is conflicting with the SDK's bundled library versions.
// See https://github.com/getappmap/appmap-intellij-plugin/pull/794.
if (!project.name.startsWith("tests-")) {
// https://mvnrepository.com/artifact/org.mock-server/mockserver-junit-rule
testImplementation("org.mock-server:mockserver-junit-rule:5.15.0")
}
}
intellijPlatform {
instrumentCode = false
}
configure<JavaPluginExtension> {
sourceCompatibility = VERSION_17
targetCompatibility = VERSION_17
}
tasks {
compileKotlin {
kotlinOptions.jvmTarget = "17"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "17"
}
processTestResources {
dependsOn(":copyPluginAssets")
from(rootProject.layout.buildDirectory.dir("appmap-assets")) {
into("")
include("**/*")
}
}
named("verifyPluginProjectConfiguration") {
dependsOn(":copyPluginAssets")
onlyIf { project == rootProject }
}
withType<PrepareSandboxTask>().configureEach {
dependsOn(":copyPluginAssets")
from(rootProject.layout.buildDirectory.dir("appmap-assets")) {
into(rootProject.name)
include("**/*")
}
}
withType<InstrumentCodeTask>().configureEach {
onlyIf { false }
}
// Target to execute tests, which are incompatible with the AppMap agent.
// Only tests with category "appland.WithoutAppMapAgent" are executed.
val testWithoutAgent by intellijPlatformTesting.testIde.registering {
type = IntelliJPlatformType.IntellijIdeaCommunity
version = ideVersion
task {
useJUnit {
includeCategories("appland.WithoutAppMapAgent")
}
}
}
named("check") {
dependsOn(testWithoutAgent.name)
}
withType<Test>().configureEach {
// all our tests need the jar, even if the agent is disabled
dependsOn(":downloadAppMapAgent")
systemProperty("idea.test.execution.policy", "appland.AppLandTestExecutionPolicy")
systemProperty("appland.testDataPath", rootProject.rootDir.resolve("src/test/data").path)
if (isCI && githubToken != null) {
systemProperty("appland.github_token", githubToken)
}
// to allow tests to access the custom Java 11 JDK
systemProperties["NO_FS_ROOTS_ACCESS_CHECK"] = true
// always execute tests, don't skip by Gradle's up-to-date checks in development
outputs.upToDateWhen { false }
// logging setup
testLogging {
setEvents(listOf(TestLogEvent.FAILED, TestLogEvent.STANDARD_OUT, TestLogEvent.STANDARD_ERROR))
}
testlogger {
theme = ThemeType.PLAIN
}
}
// only run the default test target with the AppMap agent
named<Test>("test") {
val logFileName = "appmap-agent-${System.currentTimeMillis()}.log"
// attach AppMap agent, but only if Gradle is online
jvmArgs(
"-javaagent:$agentOutputPath",
"-Dappmap.config.file=${rootProject.file("appmap.yml")}",
"-Dappmap.debug.file=${project.layout.buildDirectory.asFile.get().resolve(logFileName)}",
"-Dappmap.output.directory=${rootProject.file("tmp/appmap")}"
)
systemProperty("appmap.test.withAgent", "true")
useJUnit {
excludeCategories("appland.WithoutAppMapAgent")
}
}
withType<Zip>().configureEach {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}
}
project(":") {
apply {
plugin("org.jetbrains.intellij.platform")
}
dependencies {
intellijPlatform {
pluginModule(implementation(project(":plugin-core")))
pluginModule(implementation(project(":plugin-gradle")))
pluginModule(implementation(project(":plugin-java")))
pluginModule(implementation(project(":plugin-maven")))
pluginModule(implementation(project(":plugin-copilot")))
// adding this for runIde support
plugin("com.github.copilot", prop("copilotPluginVersion"))
pluginVerifier()
zipSigner()
}
}
intellijPlatform {
pluginConfiguration {
version = pluginVersionString
description.set(provider {
file("${rootDir}/description.md").readText().renderMarkdown()
})
ideaVersion {
sinceBuild.set(prop("sinceBuild"))
untilBuild.set(prop("untilBuild"))
}
changeNotes.set(provider {
when {
pluginVersionString.endsWith("-SNAPSHOT") -> changelog.getUnreleased().toHTML()
else -> changelog.get(pluginVersionString).toHTML()
}
})
}
pluginVerification {
ides {
ides(prop("ideVersionVerifier").split(","))
}
failureLevel.set(
listOf(
FailureLevel.INTERNAL_API_USAGES,
FailureLevel.COMPATIBILITY_PROBLEMS,
FailureLevel.OVERRIDE_ONLY_API_USAGES,
FailureLevel.NON_EXTENDABLE_API_USAGES,
FailureLevel.PLUGIN_STRUCTURE_WARNINGS,
)
)
}
}
changelog {
path.set("${project.projectDir}/CHANGELOG.md")
}
tasks {
buildPlugin {
dependsOn(":copyPluginAssets")
from(rootProject.layout.buildDirectory.dir("appmap-assets")) {
into("")
include("**/*")
}
}
runIde {
systemProperty("appmap.sandbox", "true")
jvmArgs("-Xmx2048m")
}
verifyPlugin {
mustRunAfter("check")
}
task<Copy>("copyPluginAssets") {
dependsOn(":downloadAppMapAgent")
inputs.file("${project.rootDir}/NOTICE.txt")
inputs.file(agentOutputPath)
inputs.dir("${project.rootDir}/appland")
inputs.dir("${project.rootDir}/appland-install-guide")
inputs.dir("${project.rootDir}/appland-findings")
inputs.dir("${project.rootDir}/appland-signin")
destinationDir = project.layout.buildDirectory.asFile.get()
from(project.rootDir) {
into("appmap-assets")
include("NOTICE.txt")
}
from(agentOutputPath.parentFile) {
into("appmap-assets/appmap-java-agent")
include("*.jar")
}
from("${project.rootDir}/appland") {
into("appmap-assets/appmap")
include("index.html")
include("dist/**")
}
from("${project.rootDir}/appland-install-guide") {
into("appmap-assets/appland-install-guide")
include("index.html")
include("dist/**")
}
from("${project.rootDir}/appland-findings") {
into("appmap-assets/appland-findings")
include("index.html")
include("dist/**")
}
from("${project.rootDir}/appland-signin") {
into("appmap-assets/appland-signin")
include("index.html")
include("dist/**")
}
from("${project.rootDir}/appland-navie") {
into("appmap-assets/appland-navie")
include("index.html")
include("dist/**")
}
processResources {
dependsOn("copyPluginAssets")
}
jar {
dependsOn("copyPluginAssets")
}
}
patchPluginXml {
dependsOn(":copyPluginAssets")
}
@Suppress("UNCHECKED_CAST")
task<Download>("downloadAppMapAgent") {
src("https://api.github.com/repos/getappmap/appmap-java/releases/latest")
dest(project.layout.buildDirectory.file("appmap-java.json"))
overwrite(true)
quiet(true)
if (isCI && githubToken != null) {
header("Authorization", "Bearer $githubToken")
}
doLast {
val json = JsonSlurper().parseText(dest.readText()) as Map<*, *>
val jarAsset = (json["assets"] as List<Map<*, *>>)
.filter { (it["name"] as? String)?.endsWith(".jar") == true }
.map { it["browser_download_url"]!! }
.firstOrNull()
download.run {
src(jarAsset)
dest(agentOutputPath)
overwrite(false)
if (isCI && githubToken != null) {
header("Authorization", "Bearer $githubToken")
}
}
}
}
}
}
project(":plugin-copilot") {
dependencies {
implementation(project(":plugin-core"))
implementation("com.knuddels:jtokkit:1.1.0")
// Unfortunately, we can't use the Copilot plugin in test mode. In test mode with version 1.5.30-231, it throws:
// java.lang.ClassNotFoundException: com.github.copilot.lang.agent.CopilotAgentProcessTestService
/*intellijPlatform {
plugin("com.github.copilot", prop("copilotPluginVersion"))
}*/
}
}
project(":plugin-java") {
dependencies {
implementation(project(":plugin-core"))
intellijPlatform {
bundledPlugin("com.intellij.java")
bundledPlugin("com.intellij.properties")
}
}
}
project(":plugin-gradle") {
dependencies {
implementation(project(":plugin-core"))
implementation(project(":plugin-java"))
intellijPlatform {
bundledPlugin("com.intellij.java")
bundledPlugin("com.intellij.gradle")
bundledPlugin("com.intellij.properties")
}
}
}
project(":plugin-maven") {
dependencies {
implementation(project(":plugin-core"))
implementation(project(":plugin-java"))
intellijPlatform {
bundledPlugin("com.intellij.java")
bundledPlugin("org.jetbrains.idea.maven")
bundledPlugin("com.intellij.properties")
}
}
}
project(":tests-integration") {
dependencies {
implementation(project(":plugin-core"))
}
}
// https://github.com/commonmark/commonmark-java
fun String.renderMarkdown(): String {
val parser = Parser.builder().build()
val document = parser.parse(this)
val renderer = HtmlRenderer.builder().build()
return renderer.render(document).trim()
}
fun prop(name: String): String {
return extra.properties[name] as? String ?: error("Property `$name` is not defined in gradle.properties")
}