-
Notifications
You must be signed in to change notification settings - Fork 20
/
build.gradle.kts
273 lines (233 loc) · 7.84 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
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.tasks.PrepareSandboxTask
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.security.MessageDigest
import java.util.zip.ZipFile
plugins {
id("java")
alias(libs.plugins.changelog)
alias(libs.plugins.gradleJvmWrapper)
alias(libs.plugins.grammarkit)
alias(libs.plugins.intellijPlatform)
alias(libs.plugins.kotlin)
}
sourceSets {
main {
java.srcDir("src/main/gen-parser")
java.srcDir("src/main/gen-lexer")
resources {
exclude("**.bnf")
exclude("**.flex")
}
}
}
val pluginVersion: String by ext.properties
group = "com.intellij.plugin"
version = pluginVersion
repositories {
intellijPlatform {
defaultRepositories()
}
mavenCentral()
ivy {
url = uri("https://github.com/PowerShell/PSScriptAnalyzer/releases/download/")
patternLayout { artifact("v[revision]/[module].[revision].[ext]") }
content { includeGroup("PSScriptAnalyzer") }
metadataSources { artifact() }
}
ivy {
url = uri("https://github.com/PowerShell/PowerShellEditorServices/releases/download/")
patternLayout { artifact("v[revision]/[module].[ext]") }
content { includeGroup("PowerShellEditorServices") }
metadataSources { artifact() }
}
}
val psScriptAnalyzerVersion: String by project
val psScriptAnalyzerSha256Hash: String by project
val psScriptAnalyzer: Configuration by configurations.creating
val psesVersion: String by project
val psesSha256Hash: String by project
val powerShellEditorServices: Configuration by configurations.creating
dependencies {
intellijPlatform {
intellijIdeaCommunity(libs.versions.intellij)
bundledPlugins("org.intellij.intelliLang", "org.jetbrains.plugins.terminal")
instrumentationTools()
testFramework(TestFrameworkType.Bundled)
pluginVerifier()
}
implementation(libs.bundles.junixsocket)
implementation(libs.lsp4j)
implementation(libs.lsp4jdebug)
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
testImplementation(libs.junit)
testImplementation(libs.openTest4J)
psScriptAnalyzer(
group = "PSScriptAnalyzer",
name = "PSScriptAnalyzer",
version = psScriptAnalyzerVersion,
ext = "nupkg"
)
powerShellEditorServices(
group = "PowerShellEditorServices",
name = "PowerShellEditorServices",
version = psesVersion,
ext = "zip"
)
}
intellijPlatform {
pluginConfiguration {
name = "PowerShell"
}
pluginVerification {
ides {
recommended()
}
freeArgs.addAll(
"-mute", "ForbiddenPluginIdPrefix",
"-mute", "TemplateWordInPluginId"
)
failureLevel.add(VerifyPluginTask.FailureLevel.INTERNAL_API_USAGES)
}
}
configurations {
runtimeClasspath {
// NOTE: Newer versions of these libraries are provided by IntelliJ, so let's exclude them from the dependency set
// of org.eclipse.lsp4j:
exclude("com.google.code.gson", "gson")
exclude("com.google.guava", "guava")
}
}
tasks {
val resources = file("src/main/resources")
generateLexer {
val genLexerRoot = file("src/main/gen-lexer")
val genLexerPackageDirectory = genLexerRoot.resolve("com/intellij/plugin/powershell/lang")
purgeOldFiles = true
sourceFile = resources.resolve("_PowerShellLexer.flex")
targetOutputDir = genLexerPackageDirectory
defaultCharacterEncoding = "UTF-8"
}
generateParser {
val genParserRoot = file("src/main/gen-parser")
purgeOldFiles = true
sourceFile = resources.resolve("PowerShell.bnf")
targetRootOutputDir = genParserRoot
pathToParser = "com/intellij/plugin/powershell/lang/parser"
pathToPsiRoot = "com/intellij/plugin/powershell/psi"
defaultCharacterEncoding = "UTF-8"
}
withType<JavaCompile> {
dependsOn(generateLexer, generateParser)
options.apply {
compilerArgs.add("-Werror")
encoding = "UTF-8"
}
sourceCompatibility = "17"
targetCompatibility = "17"
}
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
dependsOn(generateLexer, generateParser)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
allWarningsAsErrors = true
}
}
fun File.verifyHash(expectedHash: String) {
println("Calculating hash for $name...")
val data = readBytes()
val hash = MessageDigest.getInstance("SHA-256").let { sha256 ->
sha256.update(data)
sha256.digest().joinToString("") { "%02X".format(it) }
}
println("Expected hash for $name = $expectedHash")
println("Calculated hash for $name = $hash")
if (!hash.equals(expectedHash, ignoreCase = true)) {
error("$name hash check failed.\n" +
"Please try re-downloading the dependency, or update the expected hash in the gradle.properties file.")
}
}
val verifyPsScriptAnalyzer by registering {
dependsOn(psScriptAnalyzer)
inputs.property("hash", psScriptAnalyzerSha256Hash)
doFirst {
psScriptAnalyzer.singleFile.verifyHash(psScriptAnalyzerSha256Hash)
}
}
fun PrepareSandboxTask.unpackPsScriptAnalyzer(outDir: Provider<String>) {
dependsOn(psScriptAnalyzer, verifyPsScriptAnalyzer)
from(zipTree(psScriptAnalyzer.singleFile)) {
into(outDir.map { "$it/PSScriptAnalyzer" })
// NuGet stuff:
exclude("_manifest/**", "_rels/**", "package/**", "[Content_Types].xml", "*.nuspec")
// Compatibility profiles, see https://github.com/PowerShell/PSScriptAnalyzer/issues/1148
exclude("compatibility_profiles/**")
}
}
val verifyPowerShellEditorServices by registering {
dependsOn(powerShellEditorServices)
inputs.property("hash", psesSha256Hash)
doFirst {
powerShellEditorServices.singleFile.verifyHash(psesSha256Hash)
}
}
fun PrepareSandboxTask.unpackPowerShellEditorServices(outDir: Provider<String>) {
dependsOn(powerShellEditorServices, verifyPowerShellEditorServices)
from(zipTree(powerShellEditorServices.singleFile)) {
into(outDir.map { "$it/" })
// We only need this module and not anything else from the archive:
include("PowerShellEditorServices/**")
}
}
withType<PrepareSandboxTask> {
val outDir = intellijPlatform.pluginConfiguration.name.map { "$it/lib/LanguageHost/modules" }
unpackPsScriptAnalyzer(outDir)
unpackPowerShellEditorServices(outDir)
}
val maxUnpackedPluginBytes: String by project
val verifyDistributionSize by registering {
group = "verification"
dependsOn(buildPlugin)
doLast {
val artifact = buildPlugin.flatMap { it.archiveFile }.get().asFile
val unpackedSize = ZipFile(artifact).use { it.entries().asSequence().sumOf { e -> e.size } }
val unpackedSizeMiB = "%.3f".format(unpackedSize / 1024.0 / 1024.0)
if (unpackedSize > maxUnpackedPluginBytes.toLong()) {
error(
"The resulting artifact size is too large. Expected no more than $maxUnpackedPluginBytes, but got" +
" $unpackedSize bytes ($unpackedSizeMiB MiB).\nArtifact path: \"$artifact\"."
)
}
println("Verified unpacked distribution size: $unpackedSizeMiB MiB.")
}
}
check {
dependsOn(verifyDistributionSize)
dependsOn(verifyPlugin)
}
runIde {
jvmArgs("-Dide.plugins.snapshot.on.unload.fail=true", "-XX:+UnlockDiagnosticVMOptions")
autoReload = true
}
patchPluginXml {
untilBuild.set(provider { null })
changeNotes.set(provider {
changelog.renderItem(
changelog
.getLatest()
.withHeader(false)
.withEmptySections(false),
org.jetbrains.changelog.Changelog.OutputType.HTML
)
})
}
val testPreview by intellijPlatformTesting.testIde.registering {
version = libs.versions.intellijPreview
useInstaller = false
task {
enabled = libs.versions.intellij.get() != libs.versions.intellijPreview.get()
}
}
check { dependsOn(testPreview.name) }
}