Skip to content

Commit 43c5b90

Browse files
committed
(#109) Build: validate the plugin distribution size
1 parent 0ae8147 commit 43c5b90

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

build.gradle.kts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import de.undercouch.gradle.tasks.download.Download
22
import org.jetbrains.intellij.tasks.PrepareSandboxTask
33
import java.security.MessageDigest
4+
import java.util.zip.ZipFile
45
import kotlin.io.path.deleteExisting
56

67
plugins {
@@ -107,6 +108,8 @@ tasks {
107108
val psScriptAnalyzerOutFile = downloads.file(psScriptAnalyzerFileName)
108109

109110
val downloadPsScriptAnalyzer by register<Download>("downloadPsScriptAnalyzer") {
111+
group = "dependencies"
112+
110113
inputs.property("version", psScriptAnalyzerVersion)
111114
inputs.property("hash", psScriptAnalyzerSha256Hash)
112115

@@ -132,7 +135,9 @@ tasks {
132135
}
133136
}
134137

135-
val getPsScriptAnalyzer by register<Copy>("getPsScriptAnalyzer") {
138+
val getPsScriptAnalyzer by registering(Copy::class) {
139+
group = "dependencies"
140+
136141
val outDir = projectDir.resolve("language_host/current/LanguageHost/modules/PSScriptAnalyzer")
137142
doFirst {
138143
if (!outDir.deleteRecursively()) error("Cannot delete \"$outDir\".")
@@ -155,6 +160,30 @@ tasks {
155160
}
156161
}
157162

163+
val maxUnpackedPluginBytes: String by project
164+
val verifyDistributionSize by registering {
165+
group = "verification"
166+
dependsOn(buildPlugin)
167+
168+
doLast {
169+
val artifact = buildPlugin.flatMap { it.archiveFile }.get().asFile
170+
val unpackedSize = ZipFile(artifact).use { it.entries().asSequence().sumOf { e -> e.size } }
171+
val unpackedSizeMiB = "%.3f".format(unpackedSize / 1024.0 / 1024.0)
172+
if (unpackedSize > maxUnpackedPluginBytes.toLong()) {
173+
error(
174+
"The resulting artifact size is too large. Expected no more than $maxUnpackedPluginBytes, but got" +
175+
" $unpackedSize bytes ($unpackedSizeMiB MiB).\nArtifact path: \"$artifact\"."
176+
)
177+
}
178+
179+
println("Verified unpacked distribution size: $unpackedSizeMiB MiB.")
180+
}
181+
}
182+
183+
check {
184+
dependsOn(verifyDistributionSize)
185+
}
186+
158187
runIde {
159188
jvmArgs("-Dide.plugins.snapshot.on.unload.fail=true", "-XX:+UnlockDiagnosticVMOptions")
160189
autoReloadPlugins.set(true)

gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
kotlin.stdlib.default.dependency=false
22

3+
# 20 MiB:
4+
maxUnpackedPluginBytes=20971520
5+
36
psScriptAnalyzerVersion=1.21.0
47
psScriptAnalyzerSha256Hash=66353f139f4f1ffaa532fdeed965e70afbb8400b4810b6b2b91e091119aa6fad

0 commit comments

Comments
 (0)