-
-
Notifications
You must be signed in to change notification settings - Fork 152
/
build.gradle.kts
402 lines (329 loc) · 11.9 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
import com.github.gradle.node.npm.task.NpmTask
import org.zaproxy.gradle.addon.AddOnPlugin
import org.zaproxy.gradle.addon.AddOnStatus
import org.zaproxy.gradle.addon.internal.model.ProjectInfo
import org.zaproxy.gradle.addon.internal.model.ReleaseState
import org.zaproxy.gradle.addon.internal.tasks.GenerateReleaseStateLastCommit
import org.zaproxy.gradle.addon.misc.ConvertMarkdownToHtml
import org.zaproxy.gradle.addon.misc.CopyAddOn
import org.zaproxy.gradle.tasks.GenerateI18nJsFile
import org.zaproxy.gradle.tasks.ZapDownloadWeekly
import org.zaproxy.gradle.tasks.ZapJavaStart
import org.zaproxy.gradle.tasks.ZapShutdown
import org.zaproxy.gradle.tasks.ZapStart
plugins {
`java-library`
jacoco
id("org.zaproxy.add-on") version "0.11.0"
id("org.zaproxy.crowdin") version "0.4.0"
id("com.diffplug.spotless")
id("org.zaproxy.common")
id("com.github.ben-manes.versions") version "0.51.0"
id("com.github.node-gradle.node")
}
apply(from = "$rootDir/gradle/ci.gradle.kts")
repositories {
mavenCentral()
}
description = "Display information from ZAP in browser."
val generatedI18nJsFileDir = layout.buildDirectory.dir("zapAddOn/i18nJs")
val npmDepsDir = layout.buildDirectory.dir("zapAddOn/npmDeps")
val zapHome = layout.buildDirectory.dir("zapHome").get()
val testZapHome = layout.buildDirectory.dir("testZapHome").get()
val zapDownloadDir = layout.buildDirectory.dir("testZapInstall").get()
val zapInstallDir = zapDownloadDir.dir("zap")
val testResultsDir = layout.buildDirectory.dir("reports/tests/test").get()
val zapPort = 8999
// Use a key just to make sure the HUD works with one
val zapApiKey = "password123"
val hudDevArgs =
listOf(
"-config",
"hud.enabledForDesktop=true",
"-config",
"hud.enabledForDaemon=true",
"-config",
"hud.devMode=true",
"-config",
"hud.unsafeEval=true",
)
val zapCmdlineOpts =
listOf(
"-silent",
"-config",
"hud.tutorialPort=9998",
"-config",
"hud.tutorialTestMode=true",
"-config",
"hud.showWelcomeScreen=false",
"-daemon",
) + hudDevArgs
zapAddOn {
addOnId.set("hud")
addOnName.set("HUD - Heads Up Display")
addOnStatus.set(AddOnStatus.BETA)
zapVersion.set("2.15.0")
releaseLink.set("https://github.com/zaproxy/zap-hud/compare/v@[email protected]@CURRENT_VERSION@")
unreleasedLink.set("https://github.com/zaproxy/zap-hud/compare/v@[email protected]")
manifest {
author.set("ZAP Dev Team")
url.set("https://www.zaproxy.org/docs/desktop/addons/hud/")
repo.set("https://github.com/zaproxy/zap-hud/")
changesFile.set(tasks.named<ConvertMarkdownToHtml>("generateManifestChanges").flatMap { it.html })
files.from(generatedI18nJsFileDir)
files.from(npmDepsDir)
dependencies {
addOns {
register("network") {
version.set(">= 0.1.0")
}
register("websocket")
}
}
extensions {
register("org.zaproxy.zap.extension.hud.launch.ExtensionHUDlaunch") {
classnames {
allowed.set(listOf("org.zaproxy.zap.extension.hud.launch"))
}
dependencies {
addOns {
register("selenium") {
version.set("15.*")
}
}
}
}
}
}
}
crowdin {
credentials {
token.set(System.getenv("CROWDIN_AUTH_TOKEN"))
}
configuration {
file.set(file("gradle/crowdin.yml"))
tokens.set(mutableMapOf("%addOnId%" to zapAddOn.addOnId.get()))
}
}
node {
download.set(true)
version.set("20.13.0")
}
val copyNpmDeps by tasks.registering(Copy::class) {
group = LifecycleBasePlugin.BUILD_GROUP
description = "Copies the (required) npm dependencies for the add-on."
dependsOn(tasks.npmInstall)
from("node_modules/vue/dist/vue.js")
from("node_modules/vue-i18n/dist/vue-i18n.js")
from("node_modules/localforage/dist/localforage.min.js")
into(npmDepsDir.map({ it.file("hud/libraries/") }))
}
sourceSets["main"].output.dir(npmDepsDir, "builtBy" to copyNpmDeps)
val generateI18nJsFile by tasks.creating(GenerateI18nJsFile::class) {
bundleName.set("UIMessages")
srcDir.set(file("src/other/resources/UIMessages/"))
i18nJsFile.set(generatedI18nJsFileDir.map({ it.file("hud/i18n.js") }))
// In review mode all i18n messages are upper case to easily spot untranslated messages.
reviewMode.set(false)
}
sourceSets["main"].output.dir(generatedI18nJsFileDir, "builtBy" to generateI18nJsFile)
tasks.named(AddOnPlugin.GENERATE_MANIFEST_TASK_NAME) {
dependsOn(copyNpmDeps)
dependsOn(generateI18nJsFile)
}
java {
val javaVersion = JavaVersion.VERSION_11
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
dependencies {
compileOnly("org.zaproxy.addon:network:0.1.0")
compileOnly(files(fileTree("lib").files))
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testImplementation("io.github.bonigarcia:selenium-jupiter:4.3.6")
testImplementation("org.seleniumhq.selenium:selenium-java:4.21.0")
testImplementation("org.hamcrest:hamcrest-all:1.3")
testImplementation("org.mockito:mockito-core:5.12.0")
testImplementation("org.zaproxy.addon:network:0.1.0")
testImplementation(files(fileTree("lib").files))
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
val jacocoReportAll by tasks.registering(JacocoReport::class) {
executionData(tasks.named("test").get(), tasks.named("testTutorial").get(), tasks.named("zapStartTest").get())
sourceSets(sourceSets.main.get())
}
val jacocoTestTutorialReport by tasks.registering(JacocoReport::class) {
executionData(tasks.named("testTutorial").get(), tasks.named("zapStartTest").get())
sourceSets(sourceSets.main.get())
}
fun sourcesWithoutLibs(extension: String) =
fileTree("src") {
include("**/*.$extension")
exclude("**/hud/libraries/**")
}
spotless {
format("properties", {
targetExclude(
".gradle/**",
".sonarcloud.properties",
"buildSrc/**",
"**/*Messages_*.properties",
"**/gradle.properties",
"**/gradle-wrapper.properties",
)
})
kotlinGradle {
ktlint()
}
// XXX Don't check for now to not require npm to try the HUD (runZap).
// format("css", {
// target(sourcesWithoutLibs("css"))
// prettier().config(mapOf("parser" to "css"))
// })
}
val addOnGroup = "ZAP Add-On"
tasks.jarZapAddOn { mustRunAfter("zapDownload") }
tasks {
register<Exec>("npmLintStagedHud") {
description = "Runs the XO linter on the staged files."
commandLine("npm", "run", "lint-staged")
}
val npmLintAllHud by registering(NpmTask::class) {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Runs the XO linter on all files."
dependsOn(npmInstall)
npmCommand.set(listOf("run", "lint"))
}
named("check") {
dependsOn(npmLintAllHud)
}
register<Exec>("npmTestHud") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Runs the ava tests."
commandLine("npm", "test")
}
register<Test>("testTutorial") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Runs the tutorial tests (ZAP must be running)."
useJUnitPlatform {
includeTags("tutorial")
}
dependsOn("zapStartTest")
}
register<Test>("testRemote") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Runs the remote tests (ZAP must be running)."
useJUnitPlatform {
includeTags("remote")
}
dependsOn("zapStartTest")
}
register<ZapDownloadWeekly>("zapDownload") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Downloads the latest ZAP weekly release for the unit tests"
onlyIf { !zapInstallDir.asFile.exists() }
into.set(zapDownloadDir.asFile)
zapVersions.set("https://raw.githubusercontent.com/zaproxy/zap-admin/master/ZapVersions.xml")
doLast {
copy {
from(zipTree(fileTree(zapDownloadDir.asFile).matching { include("*.zip") }.singleFile)).eachFile {
path = path.substring(relativePath.segments[0].length)
}
into(zapInstallDir)
includeEmptyDirs = false
}
delete(fileTree(zapInstallDir.dir("plugin")) { include("${zapAddOn.addOnId.get()}-*.zap") })
}
}
register<Copy>("copyHudClientFiles") {
group = addOnGroup
description = "Copies the HUD files to runZap's home directory for use with continuous mode."
from(file("src/main/zapHomeFiles"))
from(sourceSets["main"].output.dirs)
into(zapHome)
}
register<CopyAddOn>("copyAddOnLocalHome") {
into(zapHome.dir("plugin"))
}
register<ZapStart>("runZap") {
group = addOnGroup
description = "Runs ZAP (weekly) with the HUD in dev mode."
dependsOn("zapDownload", "copyAddOnLocalHome", "copyHudClientFiles")
installDir.set(zapInstallDir.asFile)
homeDir.set(zapHome.asFile)
args.set(listOf("-dev", "-config", "start.checkForUpdates=false", "-config", "hud.dir=$zapHome/hud") + hudDevArgs)
}
register<Delete>("deleteTestHome") {
delete(testZapHome)
}
register<CopyAddOn>("copyAddOnTestHome") {
into(testZapHome.dir("plugin"))
dependsOn("deleteTestHome")
}
register<ZapJavaStart>("zapStartTest") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Starts ZAP for the tests."
dependsOn("zapDownload", "copyAddOnTestHome")
finalizedBy("zapStop")
installDir.set(zapInstallDir.asFile)
homeDir.set(testZapHome.asFile)
port.set(zapPort)
apiKey.set(zapApiKey)
args.set(zapCmdlineOpts)
jacoco.applyTo(this)
}
register<ZapStart>("zapStart") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Starts ZAP for manual integration tests."
dependsOn("zapDownload", "copyAddOnTestHome")
installDir.set(zapInstallDir.asFile)
homeDir.set(testZapHome.asFile)
port.set(zapPort)
apiKey.set(zapApiKey)
args.set(zapCmdlineOpts)
}
register<ZapShutdown>("zapStop") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Stops ZAP after the unit tests have been run"
port.set(zapPort)
apiKey.set(zapApiKey)
mustRunAfter(withType<Test>())
}
register("zapRunTests") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Starts ZAP, runs the tests and stops ZAP"
dependsOn("test")
dependsOn("testTutorial")
// These are failing too often on travis, presumably due to timeouts?
// dependsOn("testRemote")
}
}
tasks.test {
useJUnitPlatform {
excludeTags("remote", "tutorial")
}
}
tasks.withType<Test>().configureEach {
systemProperties.putAll(
mapOf(
"wdm.chromeDriverVersion" to "83.0.4103.39",
"wdm.geckoDriverVersion" to "0.34.0",
"wdm.forceCache" to "true",
),
)
}
val projectInfo = ProjectInfo.from(project)
val generateReleaseStateLastCommit by tasks.registering(GenerateReleaseStateLastCommit::class) {
projects.set(listOf(projectInfo))
}
val releaseAddOn by tasks.registering {
if (ReleaseState.read(projectInfo).isNewRelease()) {
dependsOn("createRelease")
dependsOn("handleRelease")
dependsOn("createPullRequestNextDevIter")
dependsOn("crowdinUploadSourceFiles")
}
}