-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
453 lines (389 loc) · 17.8 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
453 lines (389 loc) · 17.8 KB
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
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.gradle.process.CommandLineArgumentProvider
import java.time.Duration
val commonTestJvmArgs = listOf(
"-Djava.awt.headless=true",
"-Didea.force.use.core.classloader=true",
"-Didea.use.core.classloader.for.plugin.path=true"
)
val commonTestModuleOpens = listOf(
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.base/java.lang.reflect=ALL-UNNAMED",
"--add-opens=java.base/java.util=ALL-UNNAMED"
)
plugins {
id("java") // Java support
alias(libs.plugins.kotlin) // Kotlin support
alias(libs.plugins.kotlinx.serialization) // Kotlin Serialization Plugin
alias(libs.plugins.intelliJPlatform) // IntelliJ Platform Gradle Plugin
alias(libs.plugins.changelog) // Gradle Changelog Plugin
alias(libs.plugins.qodana) // Gradle Qodana Plugin
alias(libs.plugins.kover) // Gradle Kover Plugin
}
group = providers.gradleProperty("pluginGroup").get()
version = providers.gradleProperty("pluginVersion").get()
// Set the JVM language level used to build the project.
kotlin {
jvmToolchain(21)
}
// Configure project's dependencies
repositories {
mavenCentral()
// IntelliJ Platform Gradle Plugin Repositories Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-repositories-extension.html
intellijPlatform {
defaultRepositories()
}
}
// Changelog configuration (inlined to avoid DSL resolution issues in applied scripts)
changelog {
groups.empty()
repositoryUrl.set(providers.gradleProperty("pluginRepositoryUrl"))
}
// Kover configuration
kover {
reports {
total {
xml { onCheck = true }
// Exclude UI/adapters from coverage report
filters {
excludes {
// Entire UI/adapter packages
packages(
"org.zhongmiao.interceptwave.ui",
"org.zhongmiao.interceptwave.listeners",
"org.zhongmiao.interceptwave.startup",
"org.zhongmiao.interceptwave.events"
)
// UI-facing service (wraps IDE Console UI)
classes(
"org.zhongmiao.interceptwave.services.ConsoleService"
)
}
}
}
}
}
// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
dependencies {
constraints {
testImplementation("org.assertj:assertj-core:3.27.7") {
because("3.27.7 fixes CVE-2026-24400 in older assertj-core versions")
}
}
implementation(libs.kotlinx.serialization.json)
implementation("org.java-websocket:Java-WebSocket:1.6.0")
testImplementation(libs.junit)
testImplementation(libs.opentest4j)
// JUnit 5 (Jupiter) for UI tests
testImplementation("org.junit.jupiter:junit-jupiter-api:6.1.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:6.1.0")
// JUnit Vintage Engine to run JUnit 4 tests on JUnit Platform
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:6.1.0")
// JUnit Platform Launcher (required for test execution)
testRuntimeOnly("org.junit.platform:junit-platform-launcher:6.1.0")
// UI Testing with Remote Robot
testImplementation("com.intellij.remoterobot:remote-robot:0.11.23")
testImplementation("com.intellij.remoterobot:remote-fixtures:0.11.23")
testImplementation("com.squareup.okhttp3:okhttp:5.4.0") // Required by remote-robot
// IntelliJ Platform Gradle Plugin Dependencies Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html
intellijPlatform {
create(providers.gradleProperty("platformType"), providers.gradleProperty("platformVersion"))
// Plugin Dependencies. Uses `platformBundledPlugins` property from the gradle.properties file for bundled IntelliJ Platform plugins.
bundledPlugins(providers.gradleProperty("platformBundledPlugins").map { it.split(',') })
// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file for plugin from JetBrains Marketplace.
plugins(providers.gradleProperty("platformPlugins").map { it.split(',') })
// Module Dependencies. Uses `platformBundledModules` property from the gradle.properties file for bundled IntelliJ Platform modules.
bundledModules(providers.gradleProperty("platformBundledModules").map { it.split(',') })
testFramework(TestFrameworkType.Platform)
}
}
// Configure IntelliJ Platform Gradle Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html
intellijPlatform {
pluginConfiguration {
name = providers.gradleProperty("pluginName")
version = providers.gradleProperty("pluginVersion")
// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
description = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"
with(it.lines()) {
if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
}
subList(indexOf(start) + 1, indexOf(end)).joinToString("\n").let(::markdownToHTML)
}
}
val changelog = project.changelog // local variable for configuration cache compatibility
// Get the latest available change notes from the changelog file
changeNotes = providers.gradleProperty("pluginVersion").map { pluginVersion ->
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML,
)
}
}
ideaVersion {
sinceBuild = providers.gradleProperty("pluginSinceBuild")
}
}
signing {
certificateChain = providers.environmentVariable("CERTIFICATE_CHAIN")
privateKey = providers.environmentVariable("PRIVATE_KEY")
password = providers.environmentVariable("PRIVATE_KEY_PASSWORD")
}
publishing {
token = providers.environmentVariable("PUBLISH_TOKEN")
// The pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3
// Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more:
// https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel
channels = providers.gradleProperty("pluginVersion").map { listOf(it.substringAfter('-', "").substringBefore('.').ifEmpty { "default" }) }
}
pluginVerification {
ides {
create(IntelliJPlatformType.CLion, "2023.1.7")
create(IntelliJPlatformType.DataGrip, "2023.1.2")
create(IntelliJPlatformType.DataSpell, "2023.1.6")
create(IntelliJPlatformType.GoLand, "2023.1.6")
create(IntelliJPlatformType.IntellijIdeaCommunity, "2023.1.7")
create(IntelliJPlatformType.IntellijIdeaUltimate, "2023.1.7")
create(IntelliJPlatformType.PhpStorm, "2023.1.6")
create(IntelliJPlatformType.PyCharmCommunity, "2023.1.6")
create(IntelliJPlatformType.PyCharmProfessional, "2023.1.6")
create(IntelliJPlatformType.Rider, "2023.1.7") {
useInstaller = false
}
create(IntelliJPlatformType.RubyMine, "2023.1.7")
create(IntelliJPlatformType.WebStorm, "2023.1.6")
create(IntelliJPlatformType.WebStorm, "2026.1")
}
}
}
// Ensure tests run on JUnit Platform (Jupiter + Vintage) and support tag filtering
tasks.withType<Test>().configureEach {
useJUnitPlatform {
val include = System.getProperty("includeTags")?.takeIf { it.isNotBlank() }
val exclude = System.getProperty("excludeTags")?.takeIf { it.isNotBlank() }
include?.let { vals ->
val arr = vals.split(',').map(String::trim).filter(String::isNotEmpty).toTypedArray()
if (arr.isNotEmpty()) includeTags(*arr)
}
exclude?.let { vals ->
val arr = vals.split(',').map(String::trim).filter(String::isNotEmpty).toTypedArray()
if (arr.isNotEmpty()) excludeTags(*arr)
}
// Note: JUnit4 Categories (Vintage) are exposed as tags via their fully qualified names.
}
// Remote Robot + Gson on JDK 21 needs these packages opened for reflective
// access when deserializing server-side errors and fixture payloads.
jvmArgs(commonTestJvmArgs + commonTestModuleOpens)
}
tasks.withType<JavaCompile>().configureEach {
options.release.set(17)
}
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
// Configure UI testing with robot-server plugin
// See: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-faq.html#how-to-configure-ui-tests
val runIdeForUiTests by intellijPlatformTesting.runIde.registering {
val uiProjectDir = layout.buildDirectory.dir("ui-test-project/intercept-wave-ui-project")
task {
dependsOn(prepareUiTestProject)
jvmArgumentProviders += CommandLineArgumentProvider {
listOf(
"-Drobot-server.port=8082",
"-Dide.mac.message.dialogs.as.sheets=false",
"-Djb.privacy.policy.text=<!--999.999-->",
"-Djb.consents.confirmation.enabled=false",
"-Xshare:off", // 关闭 CDS
)
}
args(uiProjectDir.get().asFile.absolutePath)
}
plugins { robotServerPlugin() }
}
val prepareUiTestProject = tasks.register("prepareUiTestProject") {
val uiProjectDir = layout.buildDirectory.dir("ui-test-project/intercept-wave-ui-project")
val uiProjectTemplateDir = layout.projectDirectory.dir("src/test/resources/ui-test-project-template")
outputs.dir(uiProjectDir)
doLast {
val dir = uiProjectDir.get().asFile
if (dir.exists()) {
dir.deleteRecursively()
}
dir.mkdirs()
val templateDir = uiProjectTemplateDir.asFile
if (!templateDir.exists()) {
throw GradleException("Missing UI test project template: ${templateDir.absolutePath}")
}
templateDir.walkTopDown().forEach { source ->
val relativePath = source.relativeTo(templateDir).path
val target = dir.resolve(relativePath)
if (source.isDirectory) {
target.mkdirs()
} else {
target.parentFile.mkdirs()
source.copyTo(target, overwrite = true)
}
}
}
}
val prepareUiTestWelcomeState = tasks.register("prepareUiTestWelcomeState") {
val platformType = providers.gradleProperty("platformType")
val platformVersion = providers.gradleProperty("platformVersion")
val uiProjectDir = layout.buildDirectory.dir("ui-test-project/intercept-wave-ui-project")
val projectName = "intercept-wave-ui-project"
val userHome = System.getProperty("user.home")
val optionsDir = layout.buildDirectory.dir(
platformType.zip(platformVersion) { type, version ->
"idea-sandbox/$type-$version/config/options"
}
)
outputs.dir(optionsDir)
dependsOn(prepareUiTestProject)
doLast {
val projectPath = uiProjectDir.get().asFile.absolutePath
val projectPathForIde = projectPath.replace(userHome, "${'$'}USER_HOME${'$'}")
val type = platformType.get()
val version = platformVersion.get()
val optionDirs = listOf(
optionsDir.get().asFile,
layout.projectDirectory
.dir(".intellijPlatform/sandbox/intercept-wave/$type-$version/config_runIdeForUiTests/options")
.asFile
).distinctBy { it.absolutePath }
fun writeUiState(dir: File) {
dir.mkdirs()
dir.resolve("trusted-paths.xml").writeText(
"""
<application>
<component name="Trusted.Paths">
<option name="TRUSTED_PROJECT_PATHS">
<map>
<entry key="$projectPathForIde" value="true" />
</map>
</option>
</component>
</application>
""".trimIndent()
)
dir.resolve("trace_license_storage.xml").writeText(
"""
<application>
<component name="TraceLicenseStorage">
<option name="lastUsedLicenseData" value="" />
</component>
</application>
""".trimIndent()
)
dir.resolve("AIOnboardingPromoWindowAdvisor.xml").writeText(
"""
<application>
<component name="AIOnboardingPromoWindowAdvisor">
<option name="attempts" value="0" />
<option name="shouldShowNextTime" value="NO" />
</component>
</application>
""".trimIndent()
)
dir.resolve("recentProjects.xml").writeText(
"""
<application>
<component name="RecentProjectsManager">
<option name="additionalInfo">
<map>
<entry key="$projectPathForIde">
<value>
<RecentProjectMetaInfo frameTitle="$projectName" projectWorkspaceId="ui-tests-$projectName">
<option name="activationTimestamp" value="1760000000000" />
<option name="binFolder" value="${'$'}APPLICATION_HOME_DIR${'$'}/bin" />
<option name="build" value="${platformType.get()}-${platformVersion.get()}" />
<option name="productionCode" value="${platformType.get()}" />
<option name="projectOpenTimestamp" value="1760000000000" />
</RecentProjectMetaInfo>
</value>
</entry>
</map>
</option>
<option name="lastOpenedProject" value="$projectPathForIde" />
</component>
</application>
""".trimIndent()
)
}
optionDirs.forEach(::writeUiState)
}
}
tasks {
wrapper {
gradleVersion = providers.gradleProperty("gradleVersion").get()
}
publishPlugin {
dependsOn(patchChangelog)
}
// Tests configuration
test {
// Use JUnit Platform for both JUnit 4 and JUnit 5 tests
useJUnitPlatform()
// Set test timeout to prevent hanging
timeout.set(Duration.ofMinutes(10))
// Configure JVM args for headless testing
// Increase heap size for tests
maxHeapSize = "1024m"
// IntelliJ Platform tests must run in a single forked JVM to avoid
// VFS/index initialization failures and leaking thread checks.
// Running with multiple forks can cause "Index data initialization failed".
maxParallelForks = 1
// Mark task as not compatible with Gradle Configuration Cache to avoid
// capturing IntelliJ test initialization state that breaks VFS startup.
notCompatibleWithConfigurationCache("IntelliJ Platform tests require fresh IDE boot per run")
// Exclude Remote Robot UI tests from the regular test task.
exclude("**/*UiTest.class")
// In CI environment, exclude Platform tests that require IDE instance
if (System.getenv("CI") == "true") {
exclude("**/MockServerServiceTest.class", "**/ConfigServiceTest.class", "**/ProjectCloseListenerTest.class")
}
}
// Separate UI test task
register<Test>("testUi") {
description = "Runs UI tests with a running IDE instance"
group = "ui verification"
val testSourceSet = sourceSets.named("test").get()
// Use JUnit Platform for JUnit 5 tests
useJUnitPlatform()
testClassesDirs = testSourceSet.output.classesDirs
classpath = testSourceSet.runtimeClasspath
systemProperty("intercept.wave.ui.projectDir", layout.buildDirectory.dir("ui-test-project/intercept-wave-ui-project").get().asFile.absolutePath)
systemProperty("intercept.wave.ui.projectName", "intercept-wave-ui-project")
systemProperty("intercept.wave.ui.fixtureResource", "/fixtures/diverse-config.json")
// Include only Remote Robot UI tests that require a separately launched IDE.
include("**/*UiTest.class")
// Use the same JVM configuration as regular tests
jvmArgs(
*commonTestJvmArgs.toTypedArray(),
*commonTestModuleOpens.toTypedArray()
)
maxHeapSize = "2048m" // UI tests may need more memory
timeout.set(Duration.ofMinutes(20)) // UI tests take longer
notCompatibleWithConfigurationCache("Remote Robot UI tests require a live IDE and runtime-only gating")
dependsOn(prepareUiTestProject)
shouldRunAfter(named<Test>("test"))
onlyIf {
System.getProperty("runUiTests") == "true" ||
System.getenv("RUN_UI_TESTS") == "true"
}
}
named("runIdeForUiTests") {
dependsOn(prepareUiTestWelcomeState)
}
}