forked from SonarSource/sonarlint-intellij
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
398 lines (362 loc) · 14.8 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
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
import com.jetbrains.plugin.blockmap.core.BlockMap
import de.undercouch.gradle.tasks.download.Download
import groovy.lang.GroovyObject
import org.jetbrains.intellij.tasks.RunPluginVerifierTask
import org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig
import java.io.BufferedInputStream
import java.io.BufferedOutputStream
import java.io.FileInputStream
import java.io.FileOutputStream
import java.util.EnumSet
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
plugins {
kotlin("jvm") version "1.8.10"
id("org.jetbrains.intellij") version "1.15.0"
id("org.sonarqube") version "3.4.0.2513"
java
jacoco
id("com.github.hierynomus.license") version "0.16.1"
id("com.jfrog.artifactory") version "4.30.1"
id("com.google.protobuf") version "0.9.1"
idea
signing
id("de.undercouch.download") version "5.3.0"
id("org.cyclonedx.bom") version "1.7.3"
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
"classpath"(group = "org.jetbrains.intellij", name = "blockmap", version = "1.0.6")
}
}
group = "org.sonarsource.sonarlint.intellij"
description = "SonarLint for IntelliJ IDEA"
val sonarlintCoreVersion: String by project
val protobufVersion: String by project
val intellijBuildVersion: String by project
val omnisharpVersion: String by project
// The environment variables ARTIFACTORY_PRIVATE_USERNAME and ARTIFACTORY_PRIVATE_PASSWORD are used on CI env
// On local box, please add artifactoryUsername and artifactoryPassword to ~/.gradle/gradle.properties
val artifactoryUsername = System.getenv("ARTIFACTORY_PRIVATE_USERNAME")
?: (if (project.hasProperty("artifactoryUsername")) project.property("artifactoryUsername").toString() else "")
val artifactoryPassword = System.getenv("ARTIFACTORY_PRIVATE_PASSWORD")
?: (if (project.hasProperty("artifactoryPassword")) project.property("artifactoryPassword").toString() else "")
allprojects {
apply {
plugin("idea")
plugin("java")
plugin("org.jetbrains.intellij")
plugin("org.cyclonedx.bom")
plugin("com.github.hierynomus.license")
}
repositories {
mavenCentral {
content {
excludeGroupByRegex("com\\.sonarsource.*")
}
}
maven("https://repox.jfrog.io/repox/sonarsource") {
if (artifactoryUsername.isNotEmpty() && artifactoryPassword.isNotEmpty()) {
credentials {
username = artifactoryUsername
password = artifactoryPassword
}
}
}
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
apiVersion = "1.7"
jvmTarget = "11"
}
}
tasks.cyclonedxBom {
setIncludeConfigs(listOf("runtimeClasspath", "sqplugins_deps"))
inputs.files(configurations.runtimeClasspath, configurations.archives.get())
mustRunAfter(
getTasksByName("buildPluginBlockmap", true)
)
}
val bomFile = layout.buildDirectory.file("reports/bom.json")
artifacts.add("archives", bomFile.get().asFile) {
name = "sonarlint-intellij"
type = "json"
classifier = "cyclonedx"
builtBy("cyclonedxBom")
}
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", "**/proto/*.java")
)
strictCheck = true
}
}
intellij {
version.set(intellijBuildVersion)
pluginName.set("sonarlint-intellij")
updateSinceUntilBuild.set(false)
plugins.set(listOf("java", "git4idea"))
}
tasks.runPluginVerifier {
// Test oldest supported, and latest
ideVersions.set(listOf("IC-2021.3", "IC-2023.2.1"))
failureLevel.set(
EnumSet.complementOf(
EnumSet.of(
// these are the only issues we tolerate
RunPluginVerifierTask.FailureLevel.DEPRECATED_API_USAGES,
RunPluginVerifierTask.FailureLevel.EXPERIMENTAL_API_USAGES,
RunPluginVerifierTask.FailureLevel.NOT_DYNAMIC,
RunPluginVerifierTask.FailureLevel.OVERRIDE_ONLY_API_USAGES,
// TODO Workaround for CLion
RunPluginVerifierTask.FailureLevel.MISSING_DEPENDENCIES,
// needed because of UpdateInBackground usages in recent versions, replacement is available from 2022.2
RunPluginVerifierTask.FailureLevel.SCHEDULED_FOR_REMOVAL_API_USAGES,
)
)
)
}
protobuf {
// Configure the protoc executable
protoc {
// Download from repositories. Must be the same as the one used in sonarlint-core
artifact = "com.google.protobuf:protoc:$protobufVersion"
}
}
tasks.test {
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
useJUnitPlatform()
systemProperty("sonarlint.telemetry.disabled", "true")
}
val runIdeDirectory: String by project
tasks.runIde {
systemProperty("sonarlint.telemetry.disabled", "true")
// uncomment to customize the SonarCloud URL
//systemProperty("sonarlint.internal.sonarcloud.url", "https://sonarcloud.io/")
if (project.hasProperty("runIdeDirectory")) {
ideDir.set(File(runIdeDirectory))
}
maxHeapSize = "2g"
}
configurations {
val sqplugins = create("sqplugins") { isTransitive = false }
create("sqplugins_deps") {
extendsFrom(sqplugins)
isTransitive = true
}
}
dependencies {
implementation("org.sonarsource.sonarlint.core:sonarlint-core:$sonarlintCoreVersion")
implementation("commons-lang:commons-lang:2.6")
implementation(project(":common"))
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
runtimeOnly(project(":clion"))
runtimeOnly(project(":rider"))
runtimeOnly(project(":git"))
testImplementation(platform("org.junit:junit-bom:5.9.2"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation(libs.assertj.core)
testImplementation(libs.mockito.core)
testImplementation("com.squareup.okhttp3:mockwebserver:4.11.0") {
exclude(module = "junit")
}
testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0")
"sqplugins"("org.sonarsource.java:sonar-java-plugin:7.24.0.32100")
"sqplugins"("org.sonarsource.javascript:sonar-javascript-plugin:10.5.1.22382")
"sqplugins"("org.sonarsource.php:sonar-php-plugin:3.32.0.10180")
"sqplugins"("org.sonarsource.python:sonar-python-plugin:4.7.0.12181")
"sqplugins"("org.sonarsource.kotlin:sonar-kotlin-plugin:2.17.0.2902")
"sqplugins"("org.sonarsource.slang:sonar-ruby-plugin:1.14.0.4481")
"sqplugins"("org.sonarsource.html:sonar-html-plugin:3.9.0.3600")
"sqplugins"("org.sonarsource.xml:sonar-xml-plugin:2.10.0.4108")
"sqplugins"("org.sonarsource.sonarlint.omnisharp:sonarlint-omnisharp-plugin:1.13.0.76953")
"sqplugins"("org.sonarsource.text:sonar-text-plugin:2.3.0.1632")
"sqplugins"("org.sonarsource.slang:sonar-go-plugin:1.14.0.4481")
"sqplugins"("org.sonarsource.iac:sonar-iac-plugin:1.20.0.5654")
if (artifactoryUsername.isNotEmpty() && artifactoryPassword.isNotEmpty()) {
"sqplugins"("com.sonarsource.cpp:sonar-cfamily-plugin:6.48.0.62520")
}
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
// workaround for light tests in 2020.3, might remove later
testRuntimeOnly("org.jetbrains.kotlin:kotlin-reflect")
constraints {
testImplementation("com.squareup.okio:okio-jvm:3.4.0") {
because("this transitive dependency of okhttp3 has a high severity vulnerability not yet patched")
}
}
}
tasks {
val downloadOmnisharpMonoZipFile by registering(Download::class) {
src("https://repox.jfrog.io/artifactory/sonarsource/org/sonarsource/sonarlint/omnisharp/omnisharp-roslyn/$omnisharpVersion/omnisharp-roslyn-$omnisharpVersion-mono.zip")
dest(File(buildDir, "omnisharp-$omnisharpVersion-mono.zip"))
overwrite(false)
}
val downloadOmnisharpWinZipFile by registering(Download::class) {
src("https://repox.jfrog.io/artifactory/sonarsource/org/sonarsource/sonarlint/omnisharp/omnisharp-roslyn/$omnisharpVersion/omnisharp-roslyn-$omnisharpVersion-net472.zip")
dest(File(buildDir, "omnisharp-$omnisharpVersion-net472.zip"))
overwrite(false)
}
val downloadOmnisharpNet6ZipFile by registering(Download::class) {
src("https://repox.jfrog.io/artifactory/sonarsource/org/sonarsource/sonarlint/omnisharp/omnisharp-roslyn/$omnisharpVersion/omnisharp-roslyn-$omnisharpVersion-net6.zip")
dest(File(buildDir, "omnisharp-$omnisharpVersion-net6.zip"))
overwrite(false)
}
fun copyPlugins(destinationDir: File, pluginName: Property<String>) {
copy {
from(project.configurations["sqplugins"])
into(file("$destinationDir/${pluginName.get()}/plugins"))
}
}
fun copyOmnisharp(destinationDir: File, pluginName: Property<String>) {
copy {
from(zipTree(downloadOmnisharpMonoZipFile.get().dest))
into(file("$destinationDir/${pluginName.get()}/omnisharp/mono"))
}
copy {
from(zipTree(downloadOmnisharpWinZipFile.get().dest))
into(file("$destinationDir/${pluginName.get()}/omnisharp/win"))
}
copy {
from(zipTree(downloadOmnisharpNet6ZipFile.get().dest))
into(file("$destinationDir/${pluginName.get()}/omnisharp/net6"))
}
}
prepareSandbox {
dependsOn(downloadOmnisharpMonoZipFile, downloadOmnisharpWinZipFile, downloadOmnisharpNet6ZipFile)
doLast {
copyPlugins(destinationDir, pluginName)
copyOmnisharp(destinationDir, pluginName)
}
}
prepareTestingSandbox {
dependsOn(downloadOmnisharpMonoZipFile, downloadOmnisharpWinZipFile, downloadOmnisharpNet6ZipFile)
doLast {
copyPlugins(destinationDir, pluginName)
copyOmnisharp(destinationDir, pluginName)
}
}
val buildPluginBlockmap by registering {
inputs.file(buildPlugin.get().archiveFile)
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()
artifacts.add("archives", blockMapFileZipFile) {
name = project.name
extension = "zip.blockmap.zip"
type = "zip"
builtBy("buildPluginBlockmap")
}
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)
artifacts.add("archives", fileHashJsonFile) {
name = project.name
extension = "zip.hash.json"
type = "json"
builtBy("buildPluginBlockmap")
}
}
}
buildPlugin {
finalizedBy(buildPluginBlockmap)
}
jacocoTestReport {
classDirectories.setFrom(files("build/instrumented/instrumentCode"))
reports {
xml.required.set(true)
}
dependsOn(check)
}
}
tasks.artifactoryPublish {
mustRunAfter(
getTasksByName("cyclonedxBom", true),
tasks.buildPlugin,
getTasksByName("buildPluginBlockmap", true)
)
}
sonarqube {
properties {
property("sonar.projectName", "SonarLint for IntelliJ IDEA")
}
}
artifactory {
clientConfig.info.buildName = "sonarlint-intellij"
clientConfig.info.buildNumber = System.getenv("BUILD_ID")
clientConfig.isIncludeEnvVars = true
clientConfig.envVarsExcludePatterns = "*password*,*PASSWORD*,*secret*,*MAVEN_CMD_LINE_ARGS*,sun.java.command,*token*,*TOKEN*,*LOGIN*,*login*,*key*,*KEY*,*PASSPHRASE*,*signing*"
clientConfig.info.addEnvironmentProperty(
"ARTIFACTS_TO_DOWNLOAD",
"org.sonarsource.sonarlint.intellij:sonarlint-intellij:zip,org.sonarsource.sonarlint.intellij:sonarlint-intellij:json:cyclonedx"
)
setContextUrl(System.getenv("ARTIFACTORY_URL"))
publish(delegateClosureOf<PublisherConfig> {
repository(delegateClosureOf<GroovyObject> {
setProperty("repoKey", System.getenv("ARTIFACTORY_DEPLOY_REPO"))
setProperty("username", System.getenv("ARTIFACTORY_DEPLOY_USERNAME"))
setProperty("password", System.getenv("ARTIFACTORY_DEPLOY_PASSWORD"))
})
defaults(delegateClosureOf<GroovyObject> {
setProperty(
"properties", mapOf(
"vcs.revision" to System.getenv("CIRRUS_CHANGE_IN_REPO"),
"vcs.branch" to (System.getenv("CIRRUS_BASE_BRANCH")
?: System.getenv("CIRRUS_BRANCH")),
"build.name" to "sonarlint-intellij",
"build.number" to System.getenv("BUILD_ID")
)
)
invokeMethod("publishConfigs", "archives")
setProperty("publishPom", true) // Publish generated POM files to Artifactory (true by default)
setProperty("publishIvy", false) // Publish generated Ivy descriptor files to Artifactory (true by default)
})
})
}
signing {
setRequired {
val branch = System.getenv("CIRRUS_BRANCH") ?: ""
val pr = System.getenv("CIRRUS_PR") ?: ""
(branch == "master" || branch.matches("branch-[\\d.]+".toRegex())) &&
pr == "" &&
gradle.taskGraph.hasTask(":artifactoryPublish")
}
val signingKeyId: String? by project
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
sign(configurations.archives.get())
}