Repository navigation
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
346 lines (307 loc) · 11.8 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
346 lines (307 loc) · 11.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
import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.Exec
import org.gradle.api.tasks.TaskAction
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
import java.util.zip.ZipFile
plugins {
java
id("org.jetbrains.intellij.platform")
}
abstract class VerifyPackagedLicense : DefaultTask() {
@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val licenseFile: RegularFileProperty
@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val jarFile: RegularFileProperty
@TaskAction
fun verify() {
val expectedLicense = licenseFile.asFile.get().readText(Charsets.UTF_8).trim()
ZipFile(jarFile.asFile.get()).use { zip ->
val entry = zip.getEntry("META-INF/LICENSE")
?: error("Packaged JAR is missing META-INF/LICENSE: ${jarFile.asFile.get().absolutePath}")
val packagedLicense = zip.getInputStream(entry).bufferedReader(Charsets.UTF_8).use { it.readText() }.trim()
check(packagedLicense == expectedLicense) {
"Packaged META-INF/LICENSE does not match project LICENSE."
}
}
}
}
abstract class GenerateMarketplaceSubmission : DefaultTask() {
@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val templateFile: RegularFileProperty
@get:OutputFile
abstract val outputFile: RegularFileProperty
@get:Input
abstract val pluginVersion: Property<String>
@TaskAction
fun generate() {
val version = pluginVersion.get()
val template = templateFile.asFile.get().readText(Charsets.UTF_8)
check(template.contains("@PLUGIN_VERSION@")) {
"MARKETPLACE_SUBMISSION.md must contain @PLUGIN_VERSION@ placeholders."
}
val generatedFile = outputFile.asFile.get()
generatedFile.parentFile.mkdirs()
generatedFile.writeText(template.replace("@PLUGIN_VERSION@", version), Charsets.UTF_8)
}
}
abstract class VerifyReleaseMetadata : DefaultTask() {
@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val sourcePluginXmlFile: RegularFileProperty
@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val processedPluginXmlFile: RegularFileProperty
@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val generatedMarketplaceSubmissionFile: RegularFileProperty
@get:Input
abstract val pluginVersion: Property<String>
@TaskAction
fun verify() {
val version = pluginVersion.get()
logger.lifecycle("Verifying release metadata for version $version.")
val sourcePluginXml = sourcePluginXmlFile.asFile.get().readText(Charsets.UTF_8)
check(sourcePluginXml.contains("<version>@PLUGIN_VERSION@</version>")) {
"Source plugin.xml must keep @PLUGIN_VERSION@ as the only version placeholder."
}
val processedFile = processedPluginXmlFile.asFile.get()
logger.lifecycle("Checking processed plugin descriptor: ${processedFile.absolutePath}")
val processedPluginXml = processedFile.readText(Charsets.UTF_8)
check(processedPluginXml.contains("<version>$version</version>")) {
"Processed plugin.xml must contain release version $version."
}
check(!processedPluginXml.contains("@PLUGIN_VERSION@")) {
"Processed plugin.xml still contains @PLUGIN_VERSION@."
}
val generatedMarketplace = generatedMarketplaceSubmissionFile.asFile.get().readText(Charsets.UTF_8)
check(generatedMarketplace.contains("Version: `$version`")) {
"Generated Marketplace submission must contain release version $version."
}
check(generatedMarketplace.contains("MarkdownTableEditorIdea-$version.zip")) {
"Generated Marketplace submission must point at the release ZIP for $version."
}
check(!generatedMarketplace.contains("@PLUGIN_VERSION@")) {
"Generated Marketplace submission still contains @PLUGIN_VERSION@."
}
}
}
val pluginVersion = providers.gradleProperty("pluginVersion")
.orElse(providers.provider { file("VERSION").readText(Charsets.UTF_8).trim() })
.map { it.trim() }
val resolvedPluginVersion = pluginVersion.get()
check(Regex("""\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?""").matches(resolvedPluginVersion)) {
"pluginVersion must be a semantic version, got '$resolvedPluginVersion'."
}
val platformVersion = providers.gradleProperty("platformVersion").orElse("2022.3")
val platformLocalPath = providers.gradleProperty("platformLocalPath")
.orElse("")
val verifyRecommendedIdes = providers.gradleProperty("verifyRecommendedIdes")
.map { it.toBoolean() }
.orElse(providers.environmentVariable("GITHUB_ACTIONS").map { it.equals("true", ignoreCase = true) }.orElse(false))
val verifyCurrentIde = providers.gradleProperty("verifyCurrentIde")
.map { it.toBoolean() }
.orElse(false)
val verifyAllJetBrainsIdes = providers.gradleProperty("verifyAllJetBrainsIdes")
.map { it.toBoolean() }
.orElse(false)
val verificationIdeVersion = providers.gradleProperty("verificationIdeVersion").orElse("2022.3.3")
val androidStudioVerificationIdeVersion = providers.gradleProperty("androidStudioVerificationIdeVersion").orElse("2024.2.2.13")
val baselineJetBrainsIdeVerificationTypes = listOf(
IntelliJPlatformType.IntellijIdeaCommunity
)
val allJetBrainsIdeVerificationTypes = listOf(
IntelliJPlatformType.AndroidStudio,
IntelliJPlatformType.IntellijIdeaCommunity,
IntelliJPlatformType.IntellijIdeaUltimate,
IntelliJPlatformType.WebStorm,
IntelliJPlatformType.PyCharmCommunity,
IntelliJPlatformType.PyCharmProfessional,
IntelliJPlatformType.PhpStorm,
IntelliJPlatformType.GoLand,
IntelliJPlatformType.CLion,
IntelliJPlatformType.Rider,
IntelliJPlatformType.RubyMine
)
val jetBrainsIdeVerificationTypes = if (verifyAllJetBrainsIdes.get()) {
allJetBrainsIdeVerificationTypes
} else {
baselineJetBrainsIdeVerificationTypes
}
group = "name.krot"
version = resolvedPluginVersion
base {
archivesName = "MarkdownTableEditorIdea"
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
dependencies {
implementation("name.krot:markdown-table-core:0.3.1")
testImplementation(platform("org.junit:junit-bom:6.1.3"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
intellijPlatform {
if (platformLocalPath.get().isNotBlank()) {
local(platformLocalPath.get())
} else {
// Community, not Ultimate: the plugin only needs com.intellij.modules.platform, and
// compiling against the Community distribution keeps Ultimate-only API out by
// construction. It is also the only variant that release builds can fetch - JetBrains
// answers 451 for Ultimate downloads from Russia, where the release runner lives.
intellijIdeaCommunity(platformVersion)
}
}
}
intellijPlatform {
projectName = "MarkdownTableEditorIdea"
buildSearchableOptions = false
pluginConfiguration {
version = pluginVersion
ideaVersion {
sinceBuild = "223"
untilBuild = provider { null }
}
}
// Marketplace upload. The token is never stored in the repository: supply it as
// ORG_GRADLE_PROJECT_marketplaceToken or JETBRAINS_MARKETPLACE_TOKEN. Uploaded updates still go
// through JetBrains moderation before they become public.
publishing {
token = providers.gradleProperty("marketplaceToken")
.orElse(providers.environmentVariable("JETBRAINS_MARKETPLACE_TOKEN"))
channels = listOf("default")
}
pluginVerification {
ides {
jetBrainsIdeVerificationTypes.forEach {
val version = if (it == IntelliJPlatformType.AndroidStudio) {
androidStudioVerificationIdeVersion.get()
} else {
verificationIdeVersion.get()
}
create(it, version) {
if (it == IntelliJPlatformType.AndroidStudio) {
useInstaller = false
}
if (it == IntelliJPlatformType.Rider) {
useInstaller = false
}
}
}
if (verifyCurrentIde.get()) {
current()
}
if (verifyRecommendedIdes.get()) {
recommended()
}
}
}
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.release = 17
}
val sourcePluginXmlPath = layout.projectDirectory.file("src/main/resources/META-INF/plugin.xml")
val processedPluginXmlPath = layout.buildDirectory.file("resources/main/META-INF/plugin.xml")
val marketplaceSubmissionTemplate = layout.projectDirectory.file("MARKETPLACE_SUBMISSION.md")
val generatedMarketplaceSubmission = layout.buildDirectory.file("release/MARKETPLACE_SUBMISSION.md")
val ideaExecutable = providers.gradleProperty("ideaExecutable")
.orElse("C:\\Program Files\\JetBrains\\IntelliJ IDEA 2026.1.3\\bin\\idea64.exe")
val ideaPlaybackKeepInstalled = providers.gradleProperty("ideaPlaybackKeepInstalled")
.map { it.toBoolean() }
.orElse(false)
val generateMarketplaceSubmission = tasks.register<GenerateMarketplaceSubmission>("generateMarketplaceSubmission") {
group = "distribution"
description = "Generates JetBrains Marketplace submission notes with the resolved plugin version."
templateFile.set(marketplaceSubmissionTemplate)
outputFile.set(generatedMarketplaceSubmission)
pluginVersion.set(resolvedPluginVersion)
}
val verifyReleaseMetadata = tasks.register<VerifyReleaseMetadata>("verifyReleaseMetadata") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Checks generated plugin and Marketplace metadata use the resolved release version."
dependsOn(tasks.named("processResources"))
dependsOn(generateMarketplaceSubmission)
sourcePluginXmlFile.set(sourcePluginXmlPath)
processedPluginXmlFile.set(processedPluginXmlPath)
generatedMarketplaceSubmissionFile.set(generatedMarketplaceSubmission)
pluginVersion.set(resolvedPluginVersion)
}
tasks.named<Test>("test") {
useJUnitPlatform()
include("**/*Smoke.class", "**/*Test.class", "**/*Tests.class")
failOnNoDiscoveredTests = true
systemProperty("pluginVersion", resolvedPluginVersion)
workingDir = projectDir
classpath += fileTree(intellijPlatform.platformPath) {
include("lib/*.jar")
}
}
val corePerformance = tasks.register("corePerformance") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Runs the standalone core module performance benchmarks."
dependsOn(":core:corePerformance")
}
val jarTask = tasks.named<Jar>("jar") {
from(layout.projectDirectory.file("LICENSE")) {
into("META-INF")
}
}
val projectLicenseFile = layout.projectDirectory.file("LICENSE")
val pluginJarArchive = jarTask.flatMap { it.archiveFile }
val verifyPackagedLicense = tasks.register<VerifyPackagedLicense>("verifyPackagedLicense") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Checks that the distributable plugin JAR contains the project license."
dependsOn(jarTask)
licenseFile.set(projectLicenseFile)
jarFile.set(pluginJarArchive)
}
val ideaPlaybackSmoke = tasks.register<Exec>("ideaPlaybackSmoke") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Runs live IntelliJ IDEA UI playback smoke against the packaged plugin ZIP."
dependsOn(tasks.named("buildPlugin"))
val playbackScript = layout.projectDirectory.file("scripts/Invoke-IdeaPlaybackSmoke.ps1")
val pluginZip = layout.buildDirectory.file("distributions/MarkdownTableEditorIdea-$resolvedPluginVersion.zip")
inputs.file(playbackScript)
inputs.file(pluginZip)
outputs.dir(layout.buildDirectory.dir("idea-playback-smoke"))
commandLine(
"powershell",
"-NoProfile",
"-ExecutionPolicy",
"Bypass",
"-File",
playbackScript.asFile.absolutePath,
"-IdeaExe",
ideaExecutable.get(),
"-PluginZip",
pluginZip.get().asFile.absolutePath
)
if (ideaPlaybackKeepInstalled.get()) {
args("-KeepInstalledPlugin")
}
}
tasks.register("jacocoTestReport") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Generates the standalone core module coverage report."
dependsOn(":core:jacocoTestReport")
}
tasks.named("check") {
dependsOn(verifyPackagedLicense)
dependsOn(verifyReleaseMetadata)
dependsOn(":core:check")
}
tasks.named("buildPlugin") {
dependsOn(generateMarketplaceSubmission)
}