Repository navigation
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
478 lines (430 loc) · 16.9 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
478 lines (430 loc) · 16.9 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
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
import com.jetbrains.plugin.blockmap.core.BlockMap
import java.io.BufferedInputStream
import java.io.BufferedOutputStream
import java.io.FileInputStream
import java.io.FileOutputStream
import java.nio.file.Files
import java.nio.file.Paths
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
import java.util.zip.ZipOutputStream
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.models.ProductRelease
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
tasks.matching { it.name == "signArchives" }.configureEach {
dependsOn(":composedJar")
}
plugins {
java
alias(libs.plugins.kotlin)
id("org.jetbrains.intellij.platform")
alias(libs.plugins.sonarqube)
jacoco
alias(libs.plugins.license)
alias(libs.plugins.artifactory)
idea
signing
alias(libs.plugins.cyclonedx)
}
buildscript {
dependencies {
"classpath"("org.jetbrains.intellij:blockmap:1.0.10")
}
}
group = "org.sonarsource.sonarlint.intellij"
description = "SonarLint for IntelliJ IDEA"
val intellijBuildVersion: String by project
val ideaHome: String? = System.getenv("IDEA_HOME")
val runIdeDirectory: String by project
val verifierEnv: String by project
// The environment variables ARTIFACTORY_USERNAME and ARTIFACTORY_ACCESS_TOKEN are used on CI
// On local box, please add artifactoryUrl, artifactoryUsername and artifactoryPassword to ~/.gradle/gradle.properties
val artifactoryUrl = System.getenv("ARTIFACTORY_URL")
?: (if (project.hasProperty("artifactoryUrl")) project.property("artifactoryUrl").toString() else "")
val artifactoryUsername = System.getenv("ARTIFACTORY_USERNAME")
?: System.getenv("ARTIFACTORY_ACCESS_USERNAME")
?: (if (project.hasProperty("artifactoryUsername")) project.property("artifactoryUsername").toString() else "")
val artifactoryPassword = System.getenv("ARTIFACTORY_ACCESS_TOKEN")
?: System.getenv("ARTIFACTORY_PASSWORD")
?: (if (project.hasProperty("artifactoryPassword")) project.property("artifactoryPassword").toString() else "")
configurations {
val sqplugins = create("sqplugins") { isTransitive = false }
register("sqplugins_deps") {
extendsFrom(sqplugins)
isTransitive = true
}
register("sloop")
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
kotlin {
jvmToolchain(21)
}
dependencies {
intellijPlatform {
if (!ideaHome.isNullOrBlank()) {
local(ideaHome)
} else {
intellijIdeaCommunity(intellijBuildVersion)
}
pluginComposedModule(implementation(project(":common")))
pluginComposedModule(runtimeOnly(project(":clion")))
pluginComposedModule(runtimeOnly(project(":clion-resharper")))
pluginComposedModule(runtimeOnly(project(":nodejs")))
pluginComposedModule(runtimeOnly(project(":rider")))
pluginComposedModule(runtimeOnly(project(":git")))
bundledPlugins("com.intellij.java", "Git4Idea", "org.jetbrains.plugins.terminal")
testFramework(TestFrameworkType.Platform)
pluginVerifier(libs.versions.plugin.verifier.get())
}
implementation(libs.sonarlint.java.client.utils)
implementation(libs.sonarlint.rpc.java.client)
implementation(libs.sonarlint.rpc.impl)
implementation(libs.commons.langs3)
implementation(libs.commons.text)
implementation(libs.sentry)
compileOnly(libs.findbugs.jsr305)
testImplementation(libs.junit.four)
testImplementation(libs.junit.jupiter)
testImplementation(libs.assertj.core)
testImplementation(libs.mockito.core)
testImplementation(libs.mockito.kotlin)
testImplementation(libs.awaitility)
testImplementation(testFixtures(project("test-common")))
testRuntimeOnly(libs.junit.launcher)
"sqplugins"(libs.bundles.sonar.analyzers)
"sloop"("org.sonarsource.sonarlint.core:sonarlint-backend-cli:${libs.versions.sonarlint.core.get()}:no-arch@zip")
}
apply(from = "gradle/intellij-dependency-lock.gradle")
license {
header = rootProject.file("HEADER")
mapping(
mapOf(
"java" to "SLASHSTAR_STYLE",
"kt" to "SLASHSTAR_STYLE",
"svg" to "XML_STYLE",
"form" to "XML_STYLE"
)
)
excludes(
listOf("**/*.jar", "**/*.png", "**/README")
)
strictCheck = true
}
intellijPlatform {
pluginConfiguration {
ideaVersion {
sinceBuild = "242.20224.300"
untilBuild = provider { null }
}
}
buildSearchableOptions = true
pluginVerification {
failureLevel = listOf(
VerifyPluginTask.FailureLevel.COMPATIBILITY_PROBLEMS,
VerifyPluginTask.FailureLevel.NON_EXTENDABLE_API_USAGES,
VerifyPluginTask.FailureLevel.OVERRIDE_ONLY_API_USAGES,
VerifyPluginTask.FailureLevel.PLUGIN_STRUCTURE_WARNINGS,
VerifyPluginTask.FailureLevel.INTERNAL_API_USAGES,
VerifyPluginTask.FailureLevel.INVALID_PLUGIN
)
// Ignore expected compatibility problems for optional dependencies
freeArgs = listOf(
"-ignored-problems", "${project.rootDir}/.verifier-ignored-problems.txt"
)
val ideTypes = listOf(
IntelliJPlatformType.AndroidStudio, IntelliJPlatformType.PyCharmCommunity, IntelliJPlatformType.PyCharmProfessional,
IntelliJPlatformType.RubyMine, IntelliJPlatformType.CLion, IntelliJPlatformType.GoLand,
IntelliJPlatformType.WebStorm, IntelliJPlatformType.PhpStorm, IntelliJPlatformType.Rider,
IntelliJPlatformType.IntellijIdeaUltimate, IntelliJPlatformType.IntellijIdeaCommunity
)
ides {
create(IntelliJPlatformType.IntellijIdeaCommunity, "2025.2")
}
if (project.hasProperty("verifierEnv")) {
when (verifierEnv) {
"CI" -> ides {
select {
types = listOf(IntelliJPlatformType.IntellijIdeaCommunity)
channels = listOf(ProductRelease.Channel.RELEASE)
sinceBuild = "242.*"
untilBuild = "242.*"
}
}
"LATEST" -> ides {
select {
types = ideTypes
channels = listOf(ProductRelease.Channel.RELEASE)
sinceBuild = "252.*"
untilBuild = "252.*"
}
}
}
}
}
sonar {
properties {
property("sonar.projectName", "SonarLint for IntelliJ IDEA")
property("sonar.sca.exclusions", "its/projects/**")
// Fix deprecated implicit compilation
property("sonar.gradle.skipCompile", "true")
property("sonar.organization", "sonarsource")
}
}
artifactory {
buildInfo {
buildName = "sonarlint-intellij"
buildNumber = System.getenv("BUILD_NUMBER") ?: ""
addEnvironmentProperty(
"ARTIFACTS_TO_DOWNLOAD",
"org.sonarsource.sonarlint.intellij:sonarlint-intellij:zip,org.sonarsource.sonarlint.intellij:sonarlint-intellij:json:cyclonedx"
)
}
clientConfig.isIncludeEnvVars = true
clientConfig.envVarsExcludePatterns =
"*password*,*PASSWORD*,*secret*,*MAVEN_CMD_LINE_ARGS*,sun.java.command,*token*,*TOKEN*,*LOGIN*,*login*,*key*,*KEY*,*PASSPHRASE*,*signing*"
// Publish always targets SaaS. CI may point ARTIFACTORY_URL at Edge for resolve.
setContextUrl(
System.getenv("ARTIFACTORY_PUBLISH_URL") ?: "https://repox.jfrog.io/artifactory"
)
publish {
repository {
repoKey = System.getenv("ARTIFACTORY_DEPLOY_REPO") ?: ""
username = System.getenv("ARTIFACTORY_DEPLOY_USERNAME") ?: ""
password = System.getenv("ARTIFACTORY_DEPLOY_ACCESS_TOKEN") ?: ""
}
defaults {
setProperties(
mapOf(
"vcs.revision" to (System.getenv("GITHUB_SHA") ?: ""),
"vcs.branch" to (System.getenv("GITHUB_HEAD_REF")
?: System.getenv("GITHUB_REF_NAME") ?: ""),
"build.name" to "sonarlint-intellij",
"build.number" to (System.getenv("BUILD_NUMBER") ?: "")
)
)
this.addDefaultArchiveConfigurations()
setPublishPom(false)
setPublishIvy(false)
}
}
}
}
intellijPlatformTesting {
runIde {
register("runLocalIde") {
if (project.hasProperty("runIdeDirectory")) {
localPath = file(runIdeDirectory)
}
sandboxDirectory = project.layout.buildDirectory.dir("sonarlint-test")
prepareSandboxTask {
doLast {
setupSandbox(destinationDir, pluginName)
}
}
}
}
}
fun setupSandbox(destinationDir: File, pluginName: Property<String>) {
val pluginsDir = file("$destinationDir/${pluginName.get()}/plugins")
copyPlugins(pluginsDir)
copySloop(destinationDir, pluginName)
unzipEslintBridgeBundle(pluginsDir)
}
fun copyPlugins(pluginsDir: File) {
copy {
from(project.configurations["sqplugins"])
into(pluginsDir)
}
}
fun copySloop(destinationDir: File, pluginName: Property<String>) {
configurations["sloop"].resolvedConfiguration.resolvedArtifacts.forEach { artifact ->
copy {
from(zipTree(artifact.file))
into(file("$destinationDir/${pluginName.get()}/sloop/"))
}
}
}
fun unzipEslintBridgeBundle(pluginsDir: File) {
val jarPath = pluginsDir.listFiles()?.find {
it.name.startsWith("sonar-javascript-plugin-") && it.name.endsWith(".jar")
} ?: throw GradleException("sonar-javascript-plugin-* JAR not found in $pluginsDir")
ZipFile(jarPath).use { zipFile ->
val entry = zipFile.entries().asSequence().find { it.name.matches(Regex("sonarjs-.*\\.tgz")) }
?: throw GradleException("eslint bridge server bundle not found in JAR $jarPath")
val outputFolderPath = Paths.get("$pluginsDir/eslint-bridge")
val outputFilePath = outputFolderPath.resolve(entry.name)
Files.createDirectories(outputFolderPath)
zipFile.getInputStream(entry).use { input ->
Files.copy(input, outputFilePath)
}
GzipCompressorInputStream(Files.newInputStream(outputFilePath)).use { gzipInput ->
TarArchiveInputStream(gzipInput).use { tarInput ->
generateSequence { tarInput.nextEntry }
.forEach { tarEntry ->
val outputFile = outputFolderPath.resolve(tarEntry.name).toFile()
if (tarEntry.isDirectory) {
outputFile.mkdirs()
} else {
outputFile.parentFile.mkdirs()
Files.copy(tarInput, outputFile.toPath())
}
}
}
}
Files.deleteIfExists(outputFilePath)
}
}
tasks {
compileKotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_21)
}
}
compileTestKotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_21)
}
}
jar {
archiveClassifier = ""
}
runIde {
systemProperty("sonarlint.telemetry.disabled", "true")
systemProperty("sonarlint.monitoring.disabled", "true")
// uncomment to customize the SonarCloud URL
//systemProperty("sonarlint.internal.sonarcloud.url", "https://sonarcloud.io/")
}
test {
useJUnitPlatform()
javaLauncher.set(
project.the<JavaToolchainService>().launcherFor {
languageVersion.set(JavaLanguageVersion.of(21))
}
)
systemProperty("sonarlint.telemetry.disabled", "true")
systemProperty("sonarlint.monitoring.disabled", "true")
// disable thread leak checker for now as it's raising FPs
systemProperty("junit.jupiter.extensions.autodetection.exclude", "com.intellij.testFramework.junit5.impl.ThreadLeakTrackerExtension")
}
prepareSandbox {
doLast {
setupSandbox(destinationDir, pluginName)
}
}
prepareTestSandbox {
doLast {
setupSandbox(destinationDir, pluginName)
}
}
cyclonedxDirectBom {
includeConfigs = listOf("runtimeClasspath", "sqplugins_deps")
xmlOutput.unsetConvention()
}
cyclonedxBom {
jsonOutput.set(layout.buildDirectory.file("reports/bom.json"))
xmlOutput.unsetConvention()
}
val buildPluginBlockmap by registering {
group = "build"
description = "Generates the blockmap and hash files for the plugin distribution."
inputs.files(buildPlugin.flatMap { it.archiveFile })
.withPropertyName("distribZip")
.skipWhenEmpty()
doLast {
val distribZip = buildPlugin.get().archiveFile.get().asFile
val blockMapBytes =
com.fasterxml.jackson.databind.ObjectMapper().writeValueAsBytes(BlockMap(distribZip.inputStream()))
val blockMapFile = File(distribZip.parentFile, "blockmap.json")
blockMapFile.writeBytes(blockMapBytes)
val blockMapFileZipFile = file(distribZip.absolutePath + ".blockmap.zip")
val blockMapFileZip = ZipOutputStream(BufferedOutputStream(FileOutputStream(blockMapFileZipFile)))
val fi = FileInputStream(blockMapFile)
val origin = BufferedInputStream(fi)
val entry = ZipEntry(blockMapFile.name)
blockMapFileZip.putNextEntry(entry)
origin.copyTo(blockMapFileZip, 1024)
origin.close()
blockMapFileZip.close()
val fileHash = com.fasterxml.jackson.databind.ObjectMapper()
.writeValueAsString(com.jetbrains.plugin.blockmap.core.FileHash(distribZip.inputStream()))
val fileHashJsonFile = file(distribZip.absolutePath + ".hash.json")
fileHashJsonFile.writeText(fileHash)
}
}
buildPlugin {
finalizedBy(buildPluginBlockmap)
}
withType<Test> {
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = true
excludes = listOf("jdk.internal.*")
}
}
jacocoTestReport {
classDirectories.setFrom(files("build/instrumented/instrumentCode"))
reports {
xml.required.set(true)
}
}
artifactoryPublish {
mustRunAfter(
getTasksByName("cyclonedxBom", true),
buildPlugin,
getTasksByName("buildPluginBlockmap", true)
)
}
}
// Register all published artifacts in the 'archives' configuration at configuration time.
// Gradle 9 makes configurations immutable after they are consumed as a variant, so all
// artifact registrations must happen here (not in task doLast blocks).
artifacts {
add("archives", tasks.named<Zip>("buildPlugin").flatMap { it.archiveFile }) {
name = project.name
extension = "zip"
type = "zip"
}
add("archives", tasks.named<Zip>("buildPlugin").flatMap { it.archiveFile }.map {
file(it.asFile.absolutePath + ".blockmap.zip")
}) {
name = project.name
extension = "zip.blockmap.zip"
type = "zip"
builtBy(tasks.named("buildPluginBlockmap"))
}
add("archives", tasks.named<Zip>("buildPlugin").flatMap { it.archiveFile }.map {
file(it.asFile.absolutePath + ".hash.json")
}) {
name = project.name
extension = "zip.hash.json"
type = "json"
builtBy(tasks.named("buildPluginBlockmap"))
}
add("archives", layout.buildDirectory.file("reports/bom.json")) {
name = "sonarlint-intellij"
type = "json"
classifier = "cyclonedx"
builtBy(tasks.named("cyclonedxBom"))
}
}
signing {
setRequired {
val branch = System.getenv("GITHUB_REF_NAME") ?: ""
val pr = System.getenv("GITHUB_HEAD_REF") ?: ""
(branch == "master" || branch.matches("branch-[\\d.]+".toRegex())) &&
pr == "" &&
gradle.taskGraph.hasTask(":artifactoryPublish")
}
val signingKeyId = project.findProperty("signingKeyId") as? String
val signingKey = project.findProperty("signingKey") as? String
val signingPassword = project.findProperty("signingPassword") as? String
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
sign(configurations.archives.get())
}