Skip to content

Commit

Permalink
Fix all Explicit API errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rock3r committed Nov 1, 2023
1 parent 3e2cf64 commit 0a085ce
Show file tree
Hide file tree
Showing 239 changed files with 7,251 additions and 6,777 deletions.
1 change: 1 addition & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ dependencies {
}

tasks {
val mergeSarifReports by registering(MergeSarifTask::class) {
val mergeSarifReports by
registering(MergeSarifTask::class) {
source(configurations.outgoingSarif)
include { it.file.extension == "sarif" }
}
register("check") {
dependsOn(mergeSarifReports)
}
register("check") { dependsOn(mergeSarifReports) }
}
9 changes: 3 additions & 6 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ plugins {

kotlin {
sourceSets {
all {
languageSettings {
optIn("kotlinx.serialization.ExperimentalSerializationApi")
}
}
all { languageSettings { optIn("kotlinx.serialization.ExperimentalSerializationApi") } }
}
}

Expand All @@ -24,7 +20,8 @@ dependencies {
implementation(libs.kotlinx.serialization.json)
implementation(libs.poko.gradlePlugin)

// Enables using type-safe accessors to reference plugins from the [plugins] block defined in version catalogs.
// Enables using type-safe accessors to reference plugins from the [plugins] block defined in
// version catalogs.
// Context: https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}
6 changes: 1 addition & 5 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,5 @@ dependencyResolutionManagement {
gradlePluginPortal()
mavenCentral()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
versionCatalogs { create("libs") { from(files("../gradle/libs.versions.toml")) } }
}
49 changes: 27 additions & 22 deletions buildSrc/src/main/kotlin/IdeaConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,43 @@ import org.gradle.api.provider.Property
import org.gradle.jvm.toolchain.JavaLanguageVersion

enum class SupportedIJVersion {
IJ_232,
IJ_233
IJ_232,
IJ_233
}

private var warned = AtomicBoolean(false)

fun Project.supportedIJVersion(): SupportedIJVersion {
val prop = kotlin.runCatching {
rootProject.findProperty("supported.ij.version")?.toString() ?:
localProperty("supported.ij.version")
}.getOrNull()
val prop =
kotlin
.runCatching {
rootProject.findProperty("supported.ij.version")?.toString()
?: localProperty("supported.ij.version")
}
.getOrNull()

if (prop == null) {
if (!warned.getAndSet(true)) {
logger.warn(
"""
if (prop == null) {
if (!warned.getAndSet(true)) {
logger.warn(
"""
No 'supported.ij.version' property provided. Falling back to IJ 233.
It is recommended to provide it using local.properties file or -Psupported.ij.version to avoid unexpected behavior.
""".trimIndent()
)
}
return SupportedIJVersion.IJ_233
"""
.trimIndent()
)
}
return SupportedIJVersion.IJ_233
}

return when (prop) {
"232" -> SupportedIJVersion.IJ_232
"233" -> SupportedIJVersion.IJ_233
else -> error(
"Invalid 'supported.ij.version' with value '$prop' is provided. " +
"It should be in set of these values: ('232', '233')"
)
}
return when (prop) {
"232" -> SupportedIJVersion.IJ_232
"233" -> SupportedIJVersion.IJ_233
else ->
error(
"Invalid 'supported.ij.version' with value '$prop' is provided. " +
"It should be in set of these values: ('232', '233')"
)
}
}

fun Property<JavaLanguageVersion>.assign(version: Int) =
Expand Down
18 changes: 9 additions & 9 deletions buildSrc/src/main/kotlin/LocalProperties.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import org.gradle.api.Project
import java.util.Properties
import org.gradle.api.Project

internal fun Project.localProperty(propertyName: String): String? {
val localPropertiesFile = rootProject.file("local.properties")
if (!localPropertiesFile.exists()) {
return null
}
val properties = Properties()
localPropertiesFile.inputStream().use { properties.load(it) }
return properties.getProperty(propertyName)
}
val localPropertiesFile = rootProject.file("local.properties")
if (!localPropertiesFile.exists()) {
return null
}
val properties = Properties()
localPropertiesFile.inputStream().use { properties.load(it) }
return properties.getProperty(propertyName)
}
68 changes: 37 additions & 31 deletions buildSrc/src/main/kotlin/MergeSarifTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,45 @@ import org.gradle.api.tasks.TaskAction
@CacheableTask
open class MergeSarifTask : SourceTask() {

init {
group = "verification"
}
init {
group = "verification"
}

@get:OutputFile
val mergedSarifPath: RegularFileProperty = project.objects.fileProperty()
.convention(project.layout.buildDirectory.file("reports/static-analysis.sarif"))
@get:OutputFile
val mergedSarifPath: RegularFileProperty =
project.objects
.fileProperty()
.convention(project.layout.buildDirectory.file("reports/static-analysis.sarif"))

@TaskAction
fun merge() {
val json = Json { prettyPrint = true }
@TaskAction
fun merge() {
val json = Json { prettyPrint = true }

logger.lifecycle("Merging ${source.files.size} SARIF file(s)...")
logger.lifecycle(source.files.joinToString("\n") { " * ~${it.path.removePrefix(project.rootDir.path)}" })
logger.lifecycle("Merging ${source.files.size} SARIF file(s)...")
logger.lifecycle(
source.files.joinToString("\n") { " * ~${it.path.removePrefix(project.rootDir.path)}" }
)

val merged = SarifSchema210(
schema = "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
version = Version.The210,
runs = source.files
.asSequence()
.filter { it.extension == "sarif" }
.map { file -> file.inputStream().use { json.decodeFromStream<SarifSchema210>(it) } }
.flatMap { report -> report.runs }
.groupBy { run -> run.tool.driver.guid ?: run.tool.driver.name }
.values
.asSequence()
.filter { it.isNotEmpty() }
.map { run -> run.first().copy(results = run.flatMap { it.results ?: emptyList() }) }
.toList()
)
logger.lifecycle("Merged SARIF file contains ${merged.runs.size} run(s)")
logger.info("Writing merged SARIF file to $mergedSarifPath...")
mergedSarifPath.asFile.get().outputStream()
.use { json.encodeToStream(merged, it) }
}
val merged =
SarifSchema210(
schema =
"https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
version = Version.The210,
runs =
source.files
.asSequence()
.filter { it.extension == "sarif" }
.map { file -> file.inputStream().use { json.decodeFromStream<SarifSchema210>(it) } }
.flatMap { report -> report.runs }
.groupBy { run -> run.tool.driver.guid ?: run.tool.driver.name }
.values
.asSequence()
.filter { it.isNotEmpty() }
.map { run -> run.first().copy(results = run.flatMap { it.results ?: emptyList() }) }
.toList()
)
logger.lifecycle("Merged SARIF file contains ${merged.runs.size} run(s)")
logger.info("Writing merged SARIF file to $mergedSarifPath...")
mergedSarifPath.asFile.get().outputStream().use { json.encodeToStream(merged, it) }
}
}
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/PublishConfiguration.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("UnstableApiUsage")
@file:Suppress("UnstableApiUsage", "UnusedImports")

import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPom
Expand Down Expand Up @@ -32,4 +32,4 @@ internal fun MavenPom.configureJewelPom() {
developerConnection = "scm:git:https://github.com/JetBrains/jewel.git"
url = "https://github.com/JetBrains/jewel"
}
}
}
Loading

0 comments on commit 0a085ce

Please sign in to comment.