generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
353 lines (299 loc) · 13.6 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
import com.github.gradle.node.npm.task.NpmTask
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.time.Duration
import java.time.temporal.ChronoUnit
import java.util.regex.Pattern
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.grammarkit.tasks.GenerateLexerTask
import org.jetbrains.grammarkit.tasks.GenerateParserTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.*
import kotlin.collections.ArrayList
// Load properties from the external file
val properties = Properties()
file("local.properties").let { localPropertiesFile ->
if (localPropertiesFile.exists() && localPropertiesFile.isFile && localPropertiesFile.canRead()) {
localPropertiesFile.inputStream().use { properties.load(it) }
}
}
// Set the proxy properties
properties.forEach { key, value ->
System.setProperty(key as String, value as String)
}
fun properties(key: String) = providers.gradleProperty(key)
fun environment(key: String) = providers.environmentVariable(key)
plugins {
id("java") // Java support
// from https://github.com/ktorio/ktor-samples/blob/main/sse/build.gradle.kts
id("io.ktor.plugin") version "3.0.3"
alias(libs.plugins.kotlin) // Kotlin support
alias(libs.plugins.gradleIntelliJPlugin) // Gradle IntelliJ Plugin
alias(libs.plugins.changelog) // Gradle Changelog Plugin
alias(libs.plugins.qodana) // Gradle Qodana Plugin
alias(libs.plugins.kover) // Gradle Kover Plugin
// this is for using nodejs in gradle
// TODO maybe later we can do kotlin-multiplatform
// see: https://stackoverflow.com/questions/78493876/kotlin-gradle-multiplatform-not-producing-nodejs-artifact
id("com.github.node-gradle.node") version "7.1.0"
id("org.jetbrains.grammarkit") version "2022.3.2.2"
}
group = properties("pluginGroup").get()
version = properties("pluginVersion").get()
// Configure project's dependencies
repositories {
mavenCentral()
}
// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
dependencies {
// from https://github.com/ktorio/ktor-samples/blob/main/sse/build.gradle.kts
// check https://mbonnin.medium.com/the-different-kotlin-stdlibs-explained-83d7c6bf293
// and https://intellij-support.jetbrains.com/hc/en-us/community/posts/360009759780-Error-while-launching-a-coroutine
// for the exclusion
// for intellij idea plugin it should not include coroutines
// ref: https://github.com/hfhbd/kobol/blob/main/intellij-plugin/build.gradle.kts#L30
// exclusions have been moved to configurations.runtimeClasspath
// TODO weird, even moved to configurations.runtimeClasspath, here it still requires depending the jvm version
// directly
implementation("io.ktor:ktor-server-core-jvm")
implementation("io.ktor:ktor-server-netty-jvm")
implementation("io.ktor:ktor-server-websockets-jvm")
// implementation()
// for the version, see:
// https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#coroutinesLibraries
// this is only for debug
// uncomment the following for debug coroutines
/*implementation("org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.7.3") {
exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core")
exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8")
}*/
/**
* In local unittest got the following error:
* Caused by: java.lang.ExceptionInInitializerError:
* Exception java.lang.UnsatisfiedLinkError:
* Native library (com/sun/jna/linux-x86-64/libjnidispatch.so) not found in resource path
* Hence add this, not saw before on GitHub action
*/
testImplementation("net.java.dev.jna:jna:5.16.0")
}
// Set the JVM language level used to build the project.
kotlin {
jvmToolchain(17)
}
// Configure Gradle IntelliJ Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
// this is copied from https://github.com/redhat-developer/intellij-quarkus/blob/main/build.gradle.kts
intellij {
pluginName = properties("pluginName")
version = properties("platformVersion")
type = properties("platformType")
updateSinceUntilBuild = false
val platformPlugins = ArrayList<Any>()
val localLsp4ij = file("../lsp4ij/build/idea-sandbox/plugins/LSP4IJ").absoluteFile
if (localLsp4ij.isDirectory) {
// In case Gradle fails to build because it can't find some missing jar, try deleting
// ~/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/unzipped.com.jetbrains.plugins/com.redhat.devtools.lsp4ij*
platformPlugins.add(localLsp4ij)
} else {
// When running on CI or when there's no local lsp4ij
val latestLsp4ijNightlyVersion = fetchLatestLsp4ijNightlyVersion()
platformPlugins.add("com.redhat.devtools.lsp4ij:$latestLsp4ijNightlyVersion@nightly")
}
//Uses `platformPlugins` property from the gradle.properties file.
// from https://github.com/mallowigi/permify-jetbrains/blob/de27f901228919ce7eab0c37d8045443283fc4eb/build.gradle.kts
platformPlugins.addAll(properties("platformPlugins").map { it.split(',').map(String::trim).filter(String::isNotEmpty) }.get())
// println("Depends on platformPlugins: $platformPlugins")
plugins = platformPlugins
}
// Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
changelog {
groups.empty()
repositoryUrl = properties("pluginRepositoryUrl")
}
// Configure Gradle Kover Plugin - read more: https://github.com/Kotlin/kotlinx-kover#configuration
kover {
reports {
total {
xml {
onCheck = true
}
}
}
}
sourceSets {
main {
java.srcDirs("src/main/java", "src/gen/java")
kotlin.srcDirs("src/main/kotlin")
}
}
tasks {
wrapper {
gradleVersion = properties("gradleVersion").get()
}
patchPluginXml {
version = properties("pluginVersion")
sinceBuild = properties("pluginSinceBuild")
untilBuild = properties("pluginUntilBuild")
// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
pluginDescription = 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 = properties("pluginVersion").map { pluginVersion ->
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML,
)
}
}
}
// Configure UI tests plugin
// Read more: https://github.com/JetBrains/intellij-ui-test-robot
runIdeForUiTests {
systemProperty("robot-server.port", "8082")
systemProperty("ide.mac.message.dialogs.as.sheets", "false")
systemProperty("jb.privacy.policy.text", "<!--999.999-->")
systemProperty("jb.consents.confirmation.enabled", "false")
}
signPlugin {
certificateChain = environment("CERTIFICATE_CHAIN")
privateKey = environment("PRIVATE_KEY")
password = environment("PRIVATE_KEY_PASSWORD")
}
publishPlugin {
dependsOn("patchChangelog")
token = environment("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 = properties("pluginVersion").map { listOf(it.substringAfter('-', "").substringBefore('.').ifEmpty { "default" }) }
}
register<NpmTask>("npmPackageInstall") {
dependsOn(npmInstall)
args.set(listOf("install"))
}
register<NpmTask>("buildBrowserInfoview") {
dependsOn("npmPackageInstall")
args.set(listOf("run", "build"))
}
register<NpmTask>("runBrowserInfoview") {
args.set(listOf("run", "dev"))
}
buildPlugin {
dependsOn("buildBrowserInfoview")
}
val genLean4Lexer = register<GenerateLexerTask>("genLean4Lexer") {
description = "Generates lexer"
group = "build setup"
sourceFile.set(file("src/main/grammars/Lean4Lexer.flex"))
targetOutputDir.set(file("src/gen/java/lean4ij/language"))
purgeOldFiles.set(true)
}
val genLean4Parser = register<GenerateParserTask>("genLean4Parser") {
description = "Generates parser"
group = "build setup"
sourceFile.set(file("src/main/grammars/Lean4Parser.bnf"))
targetRootOutputDir.set(file("src/gen/java/"))
pathToParser.set("src/gen/java/lean4ij/language/Lean4Parser.java")
pathToPsiRoot.set("src/gen/java/lean4ij/language/")
purgeOldFiles.set(true)
}
val deleteGen = register<Delete>("deleteGen") {
delete("src/gen/java")
}
withType<KotlinCompile>().configureEach {
dependsOn(deleteGen)
dependsOn(genLean4Parser)
dependsOn(genLean4Lexer)
}
}
tasks.test {
// ref: https://intellij-support.jetbrains.com/hc/en-us/community/posts/4407334950290-jarFiles-is-not-set-for-PluginDescriptor
// for resolving error "jarFiles is not set for PluginDescriptor"
systemProperty("idea.force.use.core.classloader", "true")
}
// ref: https://github.com/hfhbd/kobol/blob/main/intellij-plugin/build.gradle.kts#L30
configurations.runtimeClasspath {
exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core")
exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8")
}
fun fetchLatestLsp4ijNightlyVersion(): String {
val client = HttpClient.newBuilder().build();
var onlineVersion = ""
try {
val request: HttpRequest = HttpRequest.newBuilder()
.uri(URI("https://plugins.jetbrains.com/api/plugins/23257/updates?channel=nightly&size=1"))
.GET()
.timeout(Duration.of(10, ChronoUnit.SECONDS))
.build()
val response = client.send(request, HttpResponse.BodyHandlers.ofString());
val pattern = Pattern.compile("\"version\":\"([^\"]+)\"")
val matcher = pattern.matcher(response.body())
if (matcher.find()) {
onlineVersion = matcher.group(1)
println("Depend on the latest approved nightly build of LSP4IJ: $onlineVersion")
}
} catch (e:Exception) {
println("Failed to fetch LSP4IJ nightly build version: ${e.message}")
}
val minVersion = "0.0.1-20231213-012910"
return if (minVersion < onlineVersion) onlineVersion else minVersion
}
val processResources by tasks.existing(ProcessResources::class)
processResources {
from("$rootDir/browser-infoview/dist")
}
node {
// Whether to download and install a specific Node.js version or not
// If false, it will use the globally installed Node.js
// If true, it will download node using above parameters
// Note that npm is bundled with Node.js
download = true
// Version of node to download and install (only used if download is true)
// It will be unpacked in the workDir
version = "18.18.1"
// Version of npm to use
// If specified, installs it in the npmWorkDir
// If empty, the plugin will use the npm command bundled with Node.js
npmVersion = ""
// Version of Yarn to use
// Any Yarn task first installs Yarn in the yarnWorkDir
// It uses the specified version if defined and the latest version otherwise (by default)
yarnVersion = ""
// Base URL for fetching node distributions
// Only used if download is true
// Change it if you want to use a mirror
// Or set to null if you want to add the repository on your own.
distBaseUrl = "https://nodejs.org/dist"
// Specifies whether it is acceptable to communicate with the Node.js repository over an insecure HTTP connection.
// Only used if download is true
// Change it to true if you use a mirror that uses HTTP rather than HTTPS
// Or set to null if you want to use Gradle's default behaviour.
allowInsecureProtocol = null
// The npm command executed by the npmInstall task
// By default it is install but it can be changed to ci
npmInstallCommand = "install"
// The directory where Node.js is unpacked (when download is true)
workDir = file("${project.projectDir}/.gradle/nodejs")
// The directory where npm is installed (when a specific version is defined)
npmWorkDir = file("${project.projectDir}/.gradle/npm")
// The directory where yarn is installed (when a Yarn task is used)
yarnWorkDir = file("${project.projectDir}/.gradle/yarn")
// The Node.js project directory location
// This is where the package.json file and node_modules directory are located
// By default it is at the root of the current project
nodeProjectDir = file("${project.projectDir}/browser-infoview")
}