-
Notifications
You must be signed in to change notification settings - Fork 153
/
build.gradle.kts
398 lines (359 loc) · 13.5 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 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
import org.jetbrains.intellij.tasks.RunPluginVerifierTask
plugins {
alias(libs.plugins.kotlin)
alias(libs.plugins.intellij)
alias(libs.plugins.sonarqube)
java
jacoco
alias(libs.plugins.license)
alias(libs.plugins.artifactory)
idea
signing
alias(libs.plugins.cyclonedx)
}
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 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 "")
val ideaHome: String? = System.getenv("IDEA_HOME")
allprojects {
apply {
plugin("idea")
plugin("java")
plugin("org.jetbrains.intellij")
plugin("org.cyclonedx.bom")
plugin("com.github.hierynomus.license")
}
configurations.archives.get().isCanBeResolved = true
repositories {
maven("https://repox.jfrog.io/repox/sonarsource") {
if (artifactoryUsername.isNotEmpty() && artifactoryPassword.isNotEmpty()) {
credentials {
username = artifactoryUsername
password = artifactoryPassword
}
}
}
mavenCentral {
content {
// avoid dependency confusion
excludeGroupByRegex("com\\.sonarsource.*")
}
}
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
apiVersion = "1.7"
jvmTarget = "17"
}
}
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")
)
strictCheck = true
}
}
subprojects {
tasks {
buildSearchableOptions {
// the only module contributing settings is the root one
enabled = false
}
}
}
intellij {
pluginName.set("sonarlint-intellij")
updateSinceUntilBuild.set(false)
plugins.set(listOf("java", "Git4Idea"))
if (!ideaHome.isNullOrBlank()) {
println("Using local installation of IntelliJ IDEA: $ideaHome")
localPath.set(ideaHome)
localSourcesPath.set(ideaHome)
} else {
println("No local installation of IntelliJ IDEA found, using version $intellijBuildVersion")
version.set(intellijBuildVersion)
}
}
val verifierVersions: String by project
tasks.runPluginVerifier {
if (project.hasProperty("verifierVersions")) {
ideVersions.set(verifierVersions.split(','))
} else {
// Test oldest supported, and latest
ideVersions.set(listOf("IC-2022.3.1", "IC-2024.1.4"))
}
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 CPPToolset.isRemote()
RunPluginVerifierTask.FailureLevel.SCHEDULED_FOR_REMOVAL_API_USAGES
)
)
)
}
tasks.test {
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
}
create("omnisharp")
create("sloop")
}
dependencies {
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(project(":common"))
compileOnly(libs.findbugs.jsr305)
runtimeOnly(project(":clion"))
runtimeOnly(project(":clion-resharper"))
runtimeOnly(project(":rider"))
runtimeOnly(project(":git"))
testImplementation(platform(libs.junit.bom))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation(libs.assertj.core)
testImplementation(libs.mockito.core)
testImplementation(libs.mockito.kotlin)
testImplementation(libs.awaitility)
"sqplugins"(libs.bundles.sonar.analyzers)
if (artifactoryUsername.isNotEmpty() && artifactoryPassword.isNotEmpty()) {
"sqplugins"(libs.sonar.cfamily)
"sqplugins"(libs.sonar.dotnet.enterprise)
"omnisharp"("org.sonarsource.sonarlint.omnisharp:omnisharp-roslyn:$omnisharpVersion:mono@zip")
"omnisharp"("org.sonarsource.sonarlint.omnisharp:omnisharp-roslyn:$omnisharpVersion:net472@zip")
"omnisharp"("org.sonarsource.sonarlint.omnisharp:omnisharp-roslyn:$omnisharpVersion:net6@zip")
}
"sloop"("org.sonarsource.sonarlint.core:sonarlint-backend-cli:${libs.versions.sonarlint.core.get()}:no-arch@zip")
}
tasks {
fun copyPlugins(destinationDir: File, pluginName: Property<String>) {
copy {
from(project.configurations["sqplugins"])
into(file("$destinationDir/${pluginName.get()}/plugins"))
}
}
fun renameCsharpPlugins(destinationDir: File, pluginName: Property<String>) {
val pluginsDir = File("$destinationDir/${pluginName.get()}/plugins")
pluginsDir.listFiles()?.forEach { file ->
if (file.name.matches(Regex("sonar-csharp-enterprise-plugin-.*\\.jar"))) {
file.renameTo(File(pluginsDir, "sonar-csharp-enterprise-plugin.jar"))
} else if (file.name.matches(Regex("sonar-csharp-plugin-.*\\.jar"))) {
file.renameTo(File(pluginsDir, "sonar-csharp-plugin.jar"))
}
}
}
fun copyOmnisharp(destinationDir: File, pluginName: Property<String>) {
configurations["omnisharp"].resolvedConfiguration.resolvedArtifacts.forEach { artifact ->
copy {
from(zipTree(artifact.file))
into(file("$destinationDir/${pluginName.get()}/omnisharp/${artifact.classifier}"))
}
}
}
fun copySloop(destinationDir: File, pluginName: Property<String>) {
configurations["sloop"].resolvedConfiguration.resolvedArtifacts.forEach { artifact ->
copy {
from(zipTree(artifact.file))
into(file("$destinationDir/${pluginName.get()}/sloop/"))
}
}
}
prepareSandbox {
doLast {
copyPlugins(destinationDir, pluginName)
renameCsharpPlugins(destinationDir, pluginName)
copyOmnisharp(destinationDir, pluginName)
copySloop(destinationDir, pluginName)
}
}
prepareTestingSandbox {
doLast {
copyPlugins(destinationDir, pluginName)
copyOmnisharp(destinationDir, pluginName)
copySloop(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)
}
withType<Test> {
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = true
excludes = listOf("jdk.internal.*")
}
}
jacocoTestReport {
classDirectories.setFrom(files("build/instrumented/instrumentCode"))
reports {
xml.required.set(true)
}
}
}
tasks.artifactoryPublish {
mustRunAfter(
getTasksByName("cyclonedxBom", true),
tasks.buildPlugin,
getTasksByName("buildPluginBlockmap", true)
)
}
sonar {
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 {
repository {
setProperty("repoKey", System.getenv("ARTIFACTORY_DEPLOY_REPO"))
setProperty("username", System.getenv("ARTIFACTORY_DEPLOY_USERNAME"))
setProperty("password", System.getenv("ARTIFACTORY_DEPLOY_PASSWORD"))
}
defaults {
setProperties(
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")
)
)
publishConfigs("archives")
setPublishPom(true)
setPublishIvy(false)
}
}
}
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())
}